On Jan 28, 2007, at 12:44 PM, Steve Roy wrote:
Hi everyone,
After all this time using RB canvases I have always done my own
computation and repainting instead of using Scroll, so now today
I'm playing around trying to figure out how Scroll can help me out.
I'm not sure I get it. It does scroll, but it doesn't scroll the
entire image like the docs say. Only the size of the canvas is
scrolled, leaving some artifacts not repainted. Here's a screen
shot of what I mean.
<http://homepage.mac.com/sroy/ScrollTest.png>
Here's an example. I set the Backdrop property of a canvas to some
image (much bigger than the canvas size). Then in the canvas event
handlers I have this code:
Function MouseDown(X as Integer, Y as Integer) as Boolean
AnchorX = x
AnchorY = y
return true
End Function
Sub MouseDrag(X as Integer, Y as Integer)
me.Scroll(x - AnchorX, y - AnchorY)
AnchorX = x
AnchorY = y
End Sub
Running it, the image does move when I drag the mouse on the
canvas, but only the portion of the image that was visible is
repainted. The result is the screen shot I linked above.
Calling the Scroll method fires the Paint event. Your code in Paint
should redraw the entire image because only the pixels that actually
move get redrawn in order to avoid flicker and the edges will be
automatically filled in. Typically you would subclass your canvas and
add some properties: AnchorX, AnchorY, both set in MouseDown as you
have done and MyLeft and MyTop set in MouseDrag. Draw the image in
Paint using DrawPicture in terms of MyLeft and MyTop. In the canvas's
MouseDrag event set up an If...Then loop that checks for movement
(eg., x <> AnchorX or y<> anchorY), then sets a DeltaX and DeltaY
using the differences x - AnchorX, y - AnchorY, set MyLeft = MyLeft +
DeltaX and MyTop = MyTop + DeltaY, set AnchorX = x and AnchorY = y,
then call Scroll(DeltaX, DeltaY). Untested code, something like this
in MouseDrag:
dim DeltaX, DeltaY as integer
If x <> me.AnchorX or y <> me.AnchorY then
DeltaX = x - me.AnchorX
DeltaY = y - me.AnchorY
me.MyLeft = me.MyLeft + DeltaX
me.MyTop = me.MyTop + DeltaY
AnchorX = x
AnchorY = y
me.Scroll DeltaX, DeltaY
End
In Paint you would have something like:
g.DrawPicture MyImage, me.MyLeft, me.MyTop
Best,
Jack
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>