Scrolling a Card? MouseMove solution

Ken Norris pixelbird at interisland.net
Tue Feb 24 00:58:49 EST 2004


Hi Frank, Scott, et al...

> Date: Mon, 23 Feb 2004 01:27:20 +0000
> From: Frank Leahy <frank at backtalk.com>
> Subject: Re: Scrolling a Card?

> Unless you have a background process that needs time in your app, it
> doesn't really matter if the processor gets hogged for a bit (and OSX
> should take care of other processes ok) -- but it might be interesting
> to code it that way.
----------
Exactly right. It could easily be an issue, if the user's machine is online
doing something besides idle.
---------- 
>> 2) It doesn't appear to have bounds. What happens if you try to drag
>> the
>> image past the hScroll or vScroll limits of the scrollbars? Does the
>> engine
>> stop it automatically? Does it throw an error?

> Setting the scroll negative will pin it to zero, and setting it > max
> will pin it to max.  Notice too I get the current value of the scroll
> each time through the loop, so that once it's pinned mouse movement in
> the opposite direction will start scrolling right away.
----------
Thanks so much. I was trying to set limits in the handler, but, as you say,
it isn't necessary because setting scroll values beyond scroll limits just
returns valid limits on either end.
----------
> From: Scott Rossi <scott at tactilemedia.com>
> Subject: Re: Scrolling a Card?
 
> In the past, another important concern for constructs such as "repeat while
> the mouse is down" or "repeat until the mouse is up" was that the mouseup
> event would sometimes get overlooked in the repeat handler.
----------
Oh yeah...that too. Occasionally "the mouse" events in a repeat structure
used to cough. I _also_ don't know if it's been fixed.

Anyway, here's my solution which works *the Rev way*. Many thanks to Frank
Leahy for a working script, Thomas McGrath III for time and thoughts, and
Scott Rossi for ongoing advice. The skinny form, thoroughly tested (watch
linewraps):

on mouseDown
  global gTX,gTY
  put item 1 of mouseLoc() into gTX
  put item 2 of mouseLoc() into gTY
  set the allowMove of me to true ## automatically creates a custom prop
end mouseDown

on mouseMove x,y
  global gTX,gTY
  if the allowMove of me then
     ## substitute your group name or id:
     set hScroll(group id 1006) to hScroll(group id 1006)+(gTX-x)
     set vScroll(group id 1006) to vScroll(group id 1006)+(gTY-y)
     put x into gTX
     put y into gTY
   end if
end mouseMove

on mouseUp
  global gAllowMove
  set the allowMove of me to false
end mouseUp

That about does it -- have fun ;-)

Ken N.





More information about the use-livecode mailing list