Constraining the pointer

Wouter wouter.abraham at scarlet.be
Fri Apr 22 08:01:17 EDT 2005


On 22 Apr 2005, at 11:53, David Glasgow wrote:

>
> Revlistas,
>
> This is a fairly lengthy preamble, so be patient.
>
> 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 
> know this is contrary to the HIG gospel, but it works very well.   As 
> soon as they have made a legitimate rating, the pointer is released.  
> I suspect they don't even notice what happens, because of course they 
> don't *want* to move off the scale, it just sometimes happens with a 
> muscular jerk or difficulty stopping a purposeful move one way or the 
> other.
>
> Anyway, the build using 1.1.1 worked fine on Win & Mac classic.  I 
> downloaded the latest Rev, and tried a build of the assessment stack.  
> I was disappointed with how many things broke, including the first 
> effort at an OSX build.
>
> Among the many glitches, I found that the constraining script resulted 
> in horribly jerky and delayed mouse movements.  The scale is unusable 
> on OSX (10.3.8 - or maybe 7) but fine in classic and win.  Is this an 
> OS X thang?  Well obviously it is, but is it at the Rev or OS end?
>
> The script is below:  Yes it is a hack, but it works OK.  (By way of 
> explanation the field 'container' is contiguous with the scale & the 
> +4 and - 4 are just my way of adjusting the margin of error around the 
> scale.
>
> Any suggestions as to what might be happening would be gratefully 
> received - or any alternative suggestions as to how to obtain the same 
> effect....
>
> if within (field "container",mouseloc()) = false
>     then
>       get the mouseloc
>
>       switch
>       case item 2 of the mouseloc > the bottom of field "container"
>         put (the bottom of field "container" -4) into item 2 of it
>         break
>       case item 2 of the mouseloc < the top of field "container"
>         put (the top of field "container" +4)into item 2 of it
>       end switch
>
>       switch
>       case item 1 of the mouseloc < the left of field "container"
>         put (the left of field "container" + 4) into item 1 of it
>         break
>       case item 1 of the mouseloc > the right of field "container"
>         put (the right of field "container"- 4) into item 1 of it
>       end switch
>
>       put (item 1 of the topleft of this stack) + (item 1 of it) into 
> item 1 of it
>       put (item 2 of the topleft of this stack) + (item 2 of it) into 
> item 2 of it
>
>       set the screenmouseloc to it
>     end if
>
> Best Wishes,
>
> David Glasgow
>

Hi David,

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

Hope this works for you.
Greetings,
Wouter



More information about the use-livecode mailing list