Constraining the pointer
Wouter
wouter.abraham at scarlet.be
Fri Apr 22 21:05:24 EDT 2005
On 23 Apr 2005, at 00:57, Cubist at aol.com wrote:
> I don't believe that mega-IF statement is truly necessary. Try this
> instead:
>
> on mouseMove X,Y
> put the rect of fld "container" into Fred
> put min (item 3 of Fred - 4, max (item 1 of Fred + 4, X)) into X
> put min (item 4 of Fred - 4, max (item 2 of Fred + 4, Y)) into Y
> set the screenMouseLoc to (X,Y)
> end mouseMove
>
> If the mouseLoc is within the specified rectangle, the mouse's X
> co-ord
> will be less than item 3 of the rect, and greater than item 1 of the
> rect. Thus,
> max (item 1 of rect, the mouse X) will always result in a number *at
> least*
> as large as that item 1, and min (item 3 of rect, the mouse Y) will
> always
> result in a number *no greater than* that item 3. Plug the results of
> the max into
> a min (sorry about how that sounds, but you get the idea, right?), and
> you
> end up with a number that *must* be somewhere between item 1 of the
> rect and
> item 3 of the rect.
> Something similar applies to the mouse's Y co-ord, and items 2 and
> 4 of
> the rect.
>
> Hope this helps...
>
Yeah it is a nice idea.
But to make it work fluently you'll have to add at least 1 if statement
and adjust the screenmouseloc coordinates by adding the left and top of
the stack to x,y respectively. Otherwise you'll end up with a
"constrain out of the card by jump off the left side", which people
with significant motor skills problems won't really appreciate.
Without the if statement the x,y coordinates will be set continuously
which makes it very slow and jerky, at least on my slowbook.
on mouseMove X,Y
put the rect of fld "container" into Fred
if x,y is not within Fred then
put min (item 3 of Fred - 4, max (item 1 of Fred + 4, X)) into X
put min (item 4 of Fred - 4, max (item 2 of Fred + 4, Y)) into Y
set the screenMouseLoc to (left of this stack +X,top of this
stack + Y)
end if
end mouseMove
Greetings,
Wouter
More information about the use-livecode
mailing list