Help with scrolling image + buttons
-
- User
- Posts: 76
- Joined: Wed Sep 17, 2008 3:10 am
- Location: New Zealand
Help with scrolling image + buttons
I'd like to be able to make a simple application where a large picture is able to be scrolled in a window, with buttons on one side for changing the picture that appears in the scrolling window. I think I understand button gadgets well enough to be able to send instructions to change picture, but I don't have the foggiest idea on how to make large picture appear in a scrollable window... can anyone please help me out?
Give a man a fire, and he’ll be warm for a day. Set a man on fire, and he’ll be warm for the rest of his life.
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
lil' demo:
Code: Select all
; *** Image-Scroll Demo
; *** Kaeru Gaman, Dec.9 2008
; *** PB 4.20
EnableExplicit
#Window1 = 0
Enumeration
#Button_Up
#Button_Right
#Button_Down
#Button_Left
#Image_Area
EndEnumeration
#Image_Big = 0
#Image_Show = 1
Define n.l , t.l , Color.l
Define EvID.l , EvGD.l, EvScrl.l, EXIT.l
Define AreaX.l, AreaY.l
CreateImage( #Image_Show, 256, 256 )
CreateImage( #Image_Big, 2048, 2048 )
StartDrawing( ImageOutput( #Image_Big ) )
DrawingMode( #PB_2DDrawing_Transparent )
For t=0 To 31
For n=0 To 31
Color = Random( $FFFFFF )
Box( n*64, t*64, 64, 64, Color )
DrawText( n*64 + 8, t*64 + 16, Str(n)+","+Str(t), Color ! $FFFFFF )
Next
Next
StopDrawing()
StartDrawing( ImageOutput( #Image_Show ) )
DrawImage( ImageID( #Image_Big ), -AreaX, -AreaY )
StopDrawing()
OpenWindow( 0, #PB_Ignore, #PB_Ignore, 352, 352, "Image Scroller" )
CreateGadgetList(WindowID(0))
ButtonGadget( #Button_Up , 48, 16, 256, 24, "^" )
ButtonGadget( #Button_Right , 312, 48, 24, 256, ">" )
ButtonGadget( #Button_Down , 48, 312, 256, 24, "v" )
ButtonGadget( #Button_Left , 16, 48, 24, 256, "<" )
ImageGadget( #Image_Area , 48, 48, 256, 256, ImageID( #Image_Show ) )
Repeat
EvID = WaitWindowEvent()
EvGD = EventGadget()
EvScrl = 0
Select EvID
Case #PB_Event_Gadget
Select EvGD
Case #Button_Up
EvScrl = 1
AreaY - 16
If AreaY < 0
AreaY = 0
EndIf
Case #Button_Right
EvScrl = 1
AreaX + 16
If AreaX > 1792 ; 2048-256
AreaX = 1792
EndIf
Case #Button_Down
EvScrl = 1
AreaY + 16
If AreaY > 1792 ; 2048-256
AreaY = 1792
EndIf
Case #Button_Left
EvScrl = 1
AreaX - 16
If AreaX < 0
AreaX = 0
EndIf
EndSelect
Case #PB_Event_CloseWindow
EXIT = 1
EndSelect
If EvScrl
EvScrl = 0
StartDrawing( ImageOutput( #Image_Show ) )
DrawImage( ImageID( #Image_Big ), -AreaX, -AreaY )
StopDrawing()
SetGadgetState( #Image_Area, ImageID( #Image_Show ) )
EndIf
Until EXIT
oh... and have a nice day.
Same demo, but with a ScrollArea gadget :
Code: Select all
; *** Image-Scroll Demo
; *** Kaeru Gaman, Dec.9 2008
; *** PB 4.20
EnableExplicit
#Window1 = 0
Enumeration
#ScrollArea
#Image_Area
EndEnumeration
#Image_Big = 0
Define n.l , t.l , Color.l
Define EvID.l , EvGD.l, EvScrl.l, EXIT.l
Define AreaX.l, AreaY.l
CreateImage( #Image_Big, 2048, 2048 )
StartDrawing( ImageOutput( #Image_Big ) )
DrawingMode( #PB_2DDrawing_Transparent )
For t=0 To 31
For n=0 To 31
Color = Random( $FFFFFF )
Box( n*64, t*64, 64, 64, Color )
DrawText( n*64 + 8, t*64 + 16, Str(n)+","+Str(t), Color ! $FFFFFF )
Next
Next
StopDrawing()
OpenWindow( 0, #PB_Ignore, #PB_Ignore, 352, 352, "Image Scroller" )
CreateGadgetList(WindowID(0))
ScrollAreaGadget(#ScrollArea, 0, 0, 352, 352, ImageWidth(#Image_Big), ImageHeight(#Image_Big), 10)
ImageGadget(#Image_Area, 0, 0, ImageWidth(#Image_Big), ImageHeight(#Image_Big), ImageID( #Image_Big ) )
CloseGadgetList()
Repeat
EvID = WaitWindowEvent()
EvGD = EventGadget()
EvScrl = 0
Select EvID
Case #PB_Event_CloseWindow
EXIT = 1
EndSelect
Until EXIT
I may look like a mule, but I'm not a complete ass.
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
-
- User
- Posts: 76
- Joined: Wed Sep 17, 2008 3:10 am
- Location: New Zealand