Constraining the pointer
Cubist at aol.com
Cubist at aol.com
Fri Apr 22 18:57:10 EDT 2005
sez wouter.abraham at scarlet.be:
>On 22 Apr 2005, at 11:53, David Glasgow wrote:
>> I have an assessment that may be used with people with significant
>> motor skills problems. At a point when they have to use a rating
>> scale I constrain the pointer so it can't 'fall' of the scale.
>I don't know in which kind of control structure you used the code above,
>but I changed it a bit and put it inside a mousemove handler.
>The code seems to work without jerks or delayed mousemovements or extra
>overhead:
>
>on mousemove x,y
> get rect of fld "container"
> if x,y is not within it then
> if x < item 1 of it then put (item 1 of it + 4) into tX --left
>of field "container"
> else if x > item 3 of it then put (item 3 of it - 4) into tX
>--right of field "container"
> else put x into tX
> if y > item 4 of it then put (item 4 of it - 4) into tY
>--bottom of field "container"
> else if y < item 2 of it then put (item 2 of it + 4) into tY
>--top of field "container"
> else put y into tY
> put (left of this stack) + tX into item 1 of tLoc
> put (top of this stack) + tY into item 2 of tLoc
> set the screenmouseloc to tLoc
> end if
>end mousemove
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...
More information about the use-livecode
mailing list