Updating canvas while dragging the scrollbars
Updating canvas while dragging the scrollbars
I have added scrollbars to the canvas but when I tried to bind an event to it it wouldn't allow me to pass a parameter. How do you code a canvas that moves while you move the scrollbar? If you can't pass parameters then what's the point of the bound event?
Re: Updating canvas while dragging the scrollbars
It depends exactly what you are trying to achieve.
If you just want the canvas to be slightly larger than the available screen area then it might be easier to put the canvas inside a scroll area gadget.
On the other hand if you want the canvas to represent a drawing area significantly larger than the screen size, say to represent an A0 size CAD drawing or an infinite drawing space then you would need to treat the canvas as a viewport to a virtual surface. The Event(), EventType(), EventGadget(), GetGadgetAttribute() functions are available inside the bound procedures to determine the current status. You'd need to scale these settings and the gadget/window sizes to determine the relationship between the screen co-ordinates and the virtual co-ordinates and draw the appropriate section of the virtual surface in the viewport canvas...
If you just want the canvas to be slightly larger than the available screen area then it might be easier to put the canvas inside a scroll area gadget.
Code: Select all
Procedure BindScrollDatas()
SetWindowTitle(0, "ScrollAreaGadget " +
"(" +
GetGadgetAttribute(0, #PB_ScrollArea_X) +
"," +
GetGadgetAttribute(0, #PB_ScrollArea_Y) +
")" )
EndProcedure
If OpenWindow(0, 0, 0, 405, 240, "ScrollAreaGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ScrollAreaGadget(0, 10, 10, 390,220, 1500, 1500, 30)
CanvasGadget(1, 2, 2, 1500, 1500)
CloseGadgetList()
StartDrawing(CanvasOutput(1))
DrawingMode(#PB_2DDrawing_Gradient)
BackColor($00FFFF)
FrontColor($FF0000)
BoxedGradient(0,0, 1500, 1500)
Box(0,0,1998,1998)
BindGadgetEvent(0, @ BindScrollDatas())
StopDrawing()
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
End
Case #PB_Event_Gadget
Select EventGadget()
Case 0
MessageRequester("Info","A Scroll has been used ! (" +
GetGadgetAttribute(0, #PB_ScrollArea_X) +
"," +
GetGadgetAttribute(0, #PB_ScrollArea_Y) +
")" ,#PB_MessageRequester_Ok)
EndSelect
EndSelect
ForEver
EndIf
Re: Updating canvas while dragging the scrollbars
I'm making an image editor so I want to have scrollbars that can pan an image within the canvas. It takes a huge amount of variables to display the image in the canvas, do I have to make everything global?
Re: Updating canvas while dragging the scrollbars
Use CanvasGadget() inside ScrollAreaGadget()
Egypt my love
Re: Updating canvas while dragging the scrollbars
It would slow down too much when zooming. I've optimised the canvas to show just the zoomed portion of the image.
Re: Updating canvas while dragging the scrollbars
I have put all my application variables into a global structure, and it works. I really wish there was another solution
Re: Updating canvas while dragging the scrollbars
You can use SetGadgetData() to bind a structure to a gadget
Re: Updating canvas while dragging the scrollbars
I can store a value using that method (is that what you mean?), but my main loop doesn't seem to be running while dragging a scroll bar so I can't update the contents in real time.
Anyone know how to run code while dragging a scroll bar or does it lock up your program?
Anyone know how to run code while dragging a scroll bar or does it lock up your program?
Re: Updating canvas while dragging the scrollbars
This value can be the address of a structure.coco2 wrote:I can store a value using that method (is that what you mean?)
So you don't need to make the structure global.
Re: Updating canvas while dragging the scrollbars
Use BindEventGadget() on the scrollbars. You can get live scrolling events this way - albeit in a 'blanket' fashion.coco2 wrote:Anyone know how to run code while dragging a scroll bar or does it lock up your program?
I may look like a mule, but I'm not a complete ass.
Re: Updating canvas while dragging the scrollbars
I'm not quite sure how to do that. Can you complete this code?
Code: Select all
Structure TestStructure
A.i
B.i
C.i
EndStructure
Procedure BindScrollBar()
SetWindowTitle(0, "Scrollbar: " + GetGadgetState(0))
; how do you get access to variable A here?
EndProcedure
Define Quit.i
Define Test.TestStructure
Quit = 0
Test\A = 70
Test\B = 80
Test\C = 90
OpenWindow(0, 0, 0, 400, 300, "Scrollbar Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ScrollBarGadget(0, 20, 260, 360, 20, 0, 255, 64)
BindGadgetEvent(0, @BindScrollbar())
SetGadgetData(0, Test)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
EndSelect
Until Quit
Re: Updating canvas while dragging the scrollbars
All kinds of ways. As someone stated above, you can use SetGadgetData()/GetGadgetData().
Code: Select all
Structure TestStructure
A.i
B.i
C.i
EndStructure
Procedure BindScrollBar()
Protected *ptrTest.TestStructure
*ptrTest = GetGadgetData(0)
SetWindowTitle(0, "Scrollbar: " + GetGadgetState(0) + ", Test\A = " + Str(*ptrTest\A))
EndProcedure
Define Quit.i
Define Test.TestStructure
Quit = 0
Test\A = 70
Test\B = 80
Test\C = 90
OpenWindow(0, 0, 0, 400, 300, "Scrollbar Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ScrollBarGadget(0, 20, 260, 360, 20, 0, 255, 64)
SetGadgetData(0, @Test)
BindGadgetEvent(0, @BindScrollbar())
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
EndSelect
Until Quit
I may look like a mule, but I'm not a complete ass.
Re: Updating canvas while dragging the scrollbars
Thank you srod that works well.