Constraining the pointer within a rect

Scott Morrow scott at elementarysoftware.com
Fri Aug 18 00:29:36 EDT 2006


Peter ,
Neat.  That works really well.  Alas, the stack I'm needing this for  
has a custom window shape and needs drag regions and images in  
buttons that are up against or overlapping the edge of the card, thus  
providing a path for the mouse to "escape."  It is probably possible  
to rework my use of buttons but the lost convenience is too great.   
Sigh.
-Scott

On Aug 17, 2006, at 3:32 PM, Peter T. Evensen wrote:

> Actually, if you put the following in the card or stack and do  
> you're constraining, it should work:
>
> on mouseLeave
>   if the target is me then
>       --- constrain here
>   end if
> end mouseLeave
>
> The issue is, if you put this in the card or stack script, and a  
> control doesn't trap mouseLeave, the control will pass it's  
> mouseLeave up to the stack or card.
>
> I did a test with this in the card script with a button on it, and  
> only got "mouse left" when I moved outside the window, and not when  
> I moved over a control in the window:
>
> on mouseLeave
>   if the target is me then put "Mouse Left"
> end mouseLeave
>
> on mouseEnter
>   if the target is me then put "mouse entered"
> end mouseEnter
>
> At 05:13 PM 8/17/2006, you wrote:
>> Ah, trapping the mouseLeave is much more elegant from a "number- 
>> of- messages-needed" standpoint.  I just tried it.  Unfortunately,  
>> in my
>> situation, because a mouseLeave object only works for the portion
>> that is not covered by another object (and it can't be transparent)
>> this makes it awkward to use any controls underneath.
>>
>> On Aug 17, 2006, at 1:20 PM, Peter T. Evensen wrote:
>>
>>> Perhaps you could just create an object and trap the mouseLeave
>>> message and move the pointer in that?
>>>
>>> At 03:14 PM 8/17/2006, you wrote:
>>>> I found that using a "send in time" structure to check the mouseLoc
>>>> rather than waiting for the mouseMove message was slightly more
>>>> reliable (OSX) and better kept it from going outside the bounding
>>>> area.
>>>>
>>>> on MouseTrap
>>>>    -- keep the mouse pointer inside the window
>>>>     if the optionkey is NOT "down" then -- but overide this  
>>>> behavior
>>>> with the "optionKey"
>>>>         put item 1 of globalLoc(the mouseLoc) into x
>>>>         put item 2 of globalLoc(the mouseLoc) into y
>>>>         put the top of this stack into tTopEdge
>>>>         put the bottom of this stack into tBottomEdge
>>>>         put the right of this stack into tRightEdge
>>>>         put the left of this stack into tLeftEdge
>>>>         if x < tLeftEdge then put tLeftEdge +1 into x
>>>>         if x > tRightEdge then put tRightEdge -1 into x
>>>>         if y < tTopEdge then put tTopEdge +1 into y
>>>>         if y > tBottomEdge then put tBottomEdge-1 into y
>>>>         set the screenmouseloc to x,y
>>>>     end if
>>>>   send MouseTrap to me in 40 millisec
>>>> end MouseTrap
>>>>
>>>>
>>>> -Scott Morrow
>>>>
>>>> Elementary Software
>>>> (Now with 20% less chalk dust !)
>>>> web     http://elementarysoftware.com/
>>>> email   scott at elementarysoftware.com
>>>>
>>>> -----------------------------------------------------------------
>>>>
>>>> On Aug 17, 2006, at 8:40 AM, Howard Bornstein wrote:
>>>>
>>>>> This script seems to work with adequate performance:
>>>>>
>>>>> on mousemove mh,mv
>>>>>  if the hilite of btn "constrain" is true then
>>>>>
>>>>>    if mh <= the left of fld "container" then
>>>>>      set the screenmouseloc to the globalloc of (the left of fld
>>>>> "container", mv)
>>>>>    end if
>>>>>
>>>>>    if mh >= the right of fld "container" then
>>>>>      set the screenmouseloc to the globalloc of (the right of fld
>>>>> "container", mv)
>>>>>    end if
>>>>>
>>>>>    if mv <= the top of fld "container" then
>>>>>      set the screenmouseloc to the globalloc of (mh,the top of fld
>>>>> "container")
>>>>>    end if
>>>>>
>>>>>    if mv >= the bottom of fld "container" then
>>>>>      set the screenmouseloc to the globalloc of (mh,the bottom of
>>>>> fld
>>>>> "container")
>>>>>    end if
>>>>>
>>>>>  end if
>>>>> end mousemove
>>>>>
>>>>>
>>>>> Note two things:
>>>>>
>>>>> 1) The button "Constrain" needs to be within the field "Container"
>>>>> or you'll
>>>>> never be able to get out. :-)
>>>>>
>>>>> 2) It is possible to move the mouse out of the rect for brief
>>>>> moments, but
>>>>> then it pops back into the rectangle. I'm assuming it's a
>>>>> function of
>>>>> slipping out between a mousemove scan.
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Regards,
>>>>>
>>>>> Howard Bornstein
>>>>> -----------------------
>>>>> www.designeq.com
>>>>> _______________________________________________
>>>>> use-revolution mailing list
>>>>> use-revolution at lists.runrev.com
>>>>> Please visit this url to subscribe, unsubscribe and manage your
>>>>> subscription preferences:
>>>>> http://lists.runrev.com/mailman/listinfo/use-revolution
>>>>
>>>> _______________________________________________
>>>> use-revolution mailing list
>>>> use-revolution at lists.runrev.com
>>>> Please visit this url to subscribe, unsubscribe and manage your
>>>> subscription preferences:
>>>> http://lists.runrev.com/mailman/listinfo/use-revolution
>>>
>>> Peter T. Evensen
>>> http://www.PetersRoadToHealth.com
>>> 314-629-5248 or 888-682-4588
>>>
>>> _______________________________________________
>>> use-revolution mailing list
>>> use-revolution at lists.runrev.com
>>> Please visit this url to subscribe, unsubscribe and manage your
>>> subscription preferences:
>>> http://lists.runrev.com/mailman/listinfo/use-revolution
>>
>> _______________________________________________
>> use-revolution mailing list
>> use-revolution at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your  
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-revolution
>
> Peter T. Evensen
> http://www.PetersRoadToHealth.com
> 314-629-5248 or 888-682-4588  
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your  
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
>




More information about the use-livecode mailing list