Hello:
I'm playing with mouse events, particulary with #onMouseMoved:, but I need to detect when the mouse moves out of the selected view. How can I achieve that?. I looked at MouseTracker, but I didn't understand how to use it, at least at first glance. Thanks. -- Esteban. |
I haven't verified this even works.. but you could do something like
onMouseMoved: aMouseEvent (self view rectangle contains: aMouseEvent screenPosition) ifFalse: [ "its moved out of the view area" ] "Esteban A. Maringolo" <[hidden email]> wrote in message news:[hidden email]... > Hello: > > I'm playing with mouse events, particulary with #onMouseMoved:, but I > need to detect when the mouse moves out of the selected view. How can I > achieve that?. > I looked at MouseTracker, but I didn't understand how to use it, at > least at first glance. > > Thanks. > > -- > Esteban. > > > |
In reply to this post by Esteban A. Maringolo-2
Esteban,
> I'm playing with mouse events, particulary with #onMouseMoved:, but I > need to detect when the mouse moves out of the selected view. How can I > achieve that?. > I looked at MouseTracker, but I didn't understand how to use it, at > least at first glance. MouseTracker is probably what you want. The code below (hopefully) gives you a generic/pluggable target for a mouse tracker. With a suitable target created, something like ( MouseTracker forPresenter:aPresenter startingAt:aMouseEvent screenPosition ) origin:aMouseEvent position; startTracking:target. should get you going. Before that, take a look at the scribble sample app, and then browse for references to MouseTracker. Have a good one, Bill ================================= Object subclass: #MouseTrackerTarget instanceVariableNames: 'mousePoint startBlock continueBlock endBlock constrainPointBlock' classVariableNames: '' poolDictionaries: '' classInstanceVariableNames: ''! MouseTrackerTarget guid: (GUID fromString: '{6DD585C0-6CD9-11D4-8596-0000B49D2CF2}')! MouseTrackerTarget comment: 'A simple target for a MouseTracker, useful if you want to know where the mouse ended up, but it can also be given blocks to make it much more powerful.'! !MouseTrackerTarget categoriesForClass!Unclassified! ! !MouseTrackerTarget methodsFor! endTrackingAt:aPoint "Private - End position tracking for the new position of the receiver. Part of the MouseTracker target protocol." mousePoint := constrainPointBlock value:aPoint. endBlock value:mousePoint. ^mousePoint "mousePoint := aPoint. endBlock value:aPoint. ^constrainPointBlock value:aPoint" ! ! !MouseTrackerTarget categoriesFor: #endTrackingAt:!private!tracking! ! !MouseTrackerTarget methodsFor! mousePoint "Last know tracking location of the mouse cursor." ^mousePoint! ! !MouseTrackerTarget categoriesFor: #mousePoint!accessing!public! ! !MouseTrackerTarget methodsFor! continueTrackingAt:aPoint from:aPreviousPoint "Private - Continue position tracking for the associated view at aPoint when the previous tracking position was at aPreviousPoint. Part of the MouseTracker target protocol. Answers the actual position achieved" mousePoint := constrainPointBlock value:aPoint. continueBlock value:mousePoint value:aPreviousPoint. ^mousePoint "mousePoint := aPoint. continueBlock value:aPreviousPoint value:aPoint. ^constrainPointBlock value:aPoint" ! ! !MouseTrackerTarget categoriesFor: #continueTrackingAt:from:!private!tracking! ! !MouseTrackerTarget methodsFor! cancelTrackingAt: arg1 "This is an auto-generated target implementation for the protocol <mouseTrackerTarget> and remains to be correctly implemented." "Not sure what to do here"! ! !MouseTrackerTarget categoriesFor: #cancelTrackingAt:!public! ! !MouseTrackerTarget methodsFor! constrainPointBlock:aMonadicBlock "Private - Set monadic block that constrains points during mouse tracking." constrainPointBlock := aMonadicBlock ! ! !MouseTrackerTarget categoriesFor: #constrainPointBlock:!accessing!private! ! !MouseTrackerTarget methodsFor! mousePoint:aPoint "Last know tracking location of the mouse cursor. We usually want to set this to be the starting point of the mouse; our MouseTracker will not send tracking messages if the mouse remains (reasona still." mousePoint := aPoint! ! !MouseTrackerTarget categoriesFor: #mousePoint:!accessing!private! ! !MouseTrackerTarget methodsFor! startBlock:monadicStartBlock continueBlock:dyadicContinueBlock endBlock:monadicEndBlock "Set the blocks" startBlock := monadicStartBlock. continueBlock := dyadicContinueBlock. endBlock := monadicEndBlock. ! ! !MouseTrackerTarget categoriesFor: #startBlock:continueBlock:endBlock:!accessing!public! ! !MouseTrackerTarget methodsFor! startTrackingAt:aPoint "Private - Start position tracking for the associated view at aPoint. Part of the MouseTracker target protocol. Answers the actual position achieved." mousePoint := constrainPointBlock value:aPoint. startBlock value:mousePoint. ^mousePoint "mousePoint := aPoint. startBlock value:aPoint. ^constrainPointBlock value:aPoint" ! ! !MouseTrackerTarget categoriesFor: #startTrackingAt:!private!tracking! ! !MouseTrackerTarget methodsFor! initialize "Set default blocks for start/continue/end tracking." startBlock := [ :aPoint | ]. continueBlock := [ :toPoint :fromPoint | ]. endBlock := [ :aPoint | ]. constrainPointBlock := [ :aPoint | aPoint ]. ! ! !MouseTrackerTarget categoriesFor: #initialize!initializing!private! ! !MouseTrackerTarget class methodsFor! atPoint:aPoint startBlock:monadicStartBlock continueBlock:dyadicContinueBlock endBlock:monadicEndBlock constrainPointBlock:anotherMonadicBlock "Answer a new instance with the indicated starting point and blocks." ^( self atPoint:aPoint startBlock:monadicStartBlock continueBlock:dyadicContinueBlock endBlock:monadicEndBlock ) constrainPointBlock:anotherMonadicBlock; yourself ! ! !MouseTrackerTarget class categoriesFor: #atPoint:startBlock:continueBlock:endBlock:constrainPointBlock:!instance creation!public! ! !MouseTrackerTarget class methodsFor! atPoint:aPoint "Answer a new instance with the indicated starting point." ^self new mousePoint:aPoint; yourself! ! !MouseTrackerTarget class categoriesFor: #atPoint:!instance creation!public! ! !MouseTrackerTarget class methodsFor! atPoint:aPoint startBlock:monadicStartBlock continueBlock:dyadicContinueBlock endBlock:monadicEndBlock "Answer a new instance with the indicated starting point and blocks." ^( self atPoint:aPoint ) startBlock:monadicStartBlock continueBlock:dyadicContinueBlock endBlock:monadicEndBlock; yourself ! ! !MouseTrackerTarget class categoriesFor: #atPoint:startBlock:continueBlock:endBlock:!instance creation!public! ! !MouseTrackerTarget class methodsFor! new "Answer a new instance" ^self basicNew initialize; yourself ! ! !MouseTrackerTarget class categoriesFor: #new!instance creation!public! ! !MouseTrackerTarget class methodsFor! icon "Answers an Icon that can be used to represent this class" ^MouseTracker icon! ! !MouseTrackerTarget class categoriesFor: #icon!constants!public! ! -- Wilhelm K. Schwab, Ph.D. [hidden email] |
In reply to this post by Sean Malloy-6
"Sean Malloy" <[hidden email]> escribió en el mensaje
news:<416f6292$[hidden email]>... > I haven't verified this even works.. but you could do something like > onMouseMoved: aMouseEvent > (self view rectangle contains: aMouseEvent screenPosition) ifFalse: [ > "its moved out of the view area" > ] That's the approach i've choosen, but it doesn't work, because the #onMouseMoved: message is sent only when the mouse is over the view, once the mouse cursor left the view, the view stops receiving that message -which, AFAIK, is the correct behavior. BTW, i've used "self view screenRectangle" instead of "self view rectangle". Regards. -- Esteban. |
Esteban,
> That's the approach i've choosen, but it doesn't work, because the > #onMouseMoved: message is sent only when the mouse is over the view, once > the mouse cursor left the view, the view stops receiving that > message -which, AFAIK, is the correct behavior. You might want to take a look at my EditableListView goodie: http://www.solutionsoft.co.uk/widgets/index.htm This includes an EmulatedCheckBox class which uses a Windows api call to detect loosing the mouse cursor, in order to unhighlight itself. See references to View>>requestTrackMouseLeave and implementors of wmMouseLeave:wParam:lParam. Best regards, John Aspinall Solutions Software |
Hi John,
>> That's the approach i've choosen, but it doesn't work, because the >> #onMouseMoved: message is sent only when the mouse is over the view, once >> the mouse cursor left the view, the view stops receiving that >> message -which, AFAIK, is the correct behavior. > You might want to take a look at my EditableListView goodie: > This includes an EmulatedCheckBox class which uses a Windows api call to > detect > loosing the mouse cursor, in order to unhighlight itself. See references > to > View>>requestTrackMouseLeave and implementors of > wmMouseLeave:wParam:lParam. Thanks a lot, it worked fine. I've added some methods to View and Presenter classes, so they can handle the event in the usual way, like other events such as onMouseMoved:, etc. What happens now, is that i want to track the mouse over a container view, to change the backcolor when the mouse is over the container. But when the mouse cursor is over a subview within that container, the mouseLeave event got triggered, which, again, seems to be the right behavior, but not what I want. I'm getting closer, but i'm not there yet :-), any hints or clues? Thanks. Best regards. -- Esteban. |
Esteban,
> What happens now, is that i want to track the mouse over a container view, > to change the backcolor when the mouse is over the container. But when the > mouse cursor is over a subview within that container, the mouseLeave event > got triggered, which, again, seems to be the right behavior, but not what I > want. > > I'm getting closer, but i'm not there yet :-), any hints or clues? Try something like this: wmMouseLeave: message wParam: wParam lParam: lParam (self clientRectangle containsPoint: self cursorPosition) ifFalse: [self interactor onMouseLeft: (MouseEvent message: message handle: handle wParam: wParam lParam: lParam)] ...assuming implementations of onMouseLeft: similar to onMouseMoved: etc. in Presenter and View. Best regards, John Aspinall Solutions Software |
Free forum by Nabble | Edit this page |