Scrolling a Card?

Frank Leahy frank at backtalk.com
Sat Feb 21 19:02:42 EST 2004


On Saturday, February 21, 2004, at 10:56  PM, 
use-revolution-request at lists.runrev.com wrote:

> -----------
> Nope. The group has normal scrollbars (checked in Inspector for the 
> group).
> I'm faking a 'grab' of the content of the group by setting 
> hScroll/vScroll
> relative to mouseMove coordinates in a max/min bounding expression. 
> You hold
> down the mouse inside the card and 'grab' it (the fake, because a real 
> grab
> in Rev can't pass messages nor bound itself, and would end  up moving 
> the
> entire group, scrollbars and all, which is no good), move it in any
> direction you want, but when it reaches the scroll limits, it wont go 
> any
> further in that direction. Since I'm setting hScroll/vScroll via 
> mouseMove,
> the scrollbars react like their supposed to, but that's not the
> problem...read on.
>

Ken,

Here's code I use to scroll an image in the direction that the mouse is 
moving.

I have a group named "Image Group" with scrollbars.  Inside of that 
group is a single image.  I first display the photo by setting the 
fileName property of the image.  Then when I get a mouseDown in the 
image I call this routine:

on ScrollImage
     if the vScrollbar of group "Image Group" is true or \
         the hScrollbar of group "Image Group" is true then
       put the mouseLoc into lastLoc
       set the itemDelimiter to ","
       repeat while the mouse is down
         put the mouseLoc into curLoc
         put item 1 of lastLoc - item 1 of curLoc into deltaX
         put item 2 of lastLoc - item 2 of curLoc into deltaY
         if the vScrollbar of group "Image Group" is true then
           put the vScroll of group "Image Group" into curVScroll
           add deltaY to curVScroll
           set the vScroll of group "Image Group" to curVScroll
         end if
         if the hScrollbar of group "Image Group" is true then
           put the hScroll of group "Image Group" into curHScroll
           add deltaX to curHScroll
           set the hScroll of group "Image Group" to curHScroll
         end if
         put curLoc into lastLoc
       end repeat
     end if
end ScrollImage

It would be easy to add acceleration (by using a geometric multiplier 
factor on deltaX and deltaY) so that if you have a very large image the 
user doesn't have to keep mousing up and down in order to see the whole 
image.

Hope this helps.

-- Frank 



More information about the use-livecode mailing list