Help with scrolling image + buttons

Just starting out? Need help? Post your questions and find answers here.
Lykaestria
User
User
Posts: 76
Joined: Wed Sep 17, 2008 3:10 am
Location: New Zealand

Help with scrolling image + buttons

Post by Lykaestria »

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.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Quickest way would be to use an image gadget to host the image and then place the image gadget within a scrollarea gadget.

I'm sure there are examples of doing this in the forums.
I may look like a mule, but I'm not a complete ass.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

agree, that would be quickest and easiest.

a more gamelike way would be to use buttons for step-scrolling and use a smaller Imagegadget to draw the bigger image into.
oh... and have a nice day.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

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.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

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.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

please alter the header... ;)
oh... and have a nice day.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Kaeru Gaman wrote:please alter the header... ;)
Still your demo Kaeru. I didn't have time to create the whole code so I just pinched yours! :)
I may look like a mule, but I'm not a complete ass.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

well.. ok :D
oh... and have a nice day.
Lykaestria
User
User
Posts: 76
Joined: Wed Sep 17, 2008 3:10 am
Location: New Zealand

Post by Lykaestria »

Thanks guys, I'll see what I can come with using those 2 examples as a starting point :)
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.
Post Reply