It is currently Sat May 25, 2013 1:06 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Changing ScrollAreaGadget area on the fly
PostPosted: Mon May 14, 2012 1:49 pm 
Offline
PureBasic Protozoa
PureBasic Protozoa
User avatar

Joined: Fri Apr 25, 2003 3:08 pm
Posts: 3011
I'm loading images into a scrollareagadget as an image preview area that I need and am not sure that I am calculating something right.

Using SetGadgetAttribute, I am trying to 'lengthen' the available area after each image added but it doesn't seem to happen as I have no idea what I am doing here (as usual).

Could someone please have a look at the following code and tell me what I am doing wrong?

Code:
;----------------------------------------------------------
; Load our image decoders
;----------------------------------------------------------

UseJPEGImageDecoder()
UsePNGImageDecoder()

;----------------------------------------------------------
; Window constant
;----------------------------------------------------------

Enumeration 1
  #Window_Scrolla
EndEnumeration

#WindowIndex = #PB_Compiler_EnumerationValue

;----------------------------------------------------------
; Gadget constants
;----------------------------------------------------------

Enumeration 1
  ; Window_Scrolla
  #Gadget_Scrolla_sPreview
  #Gadget_Scrolla_Area18
  #Gadget_Scrolla_cControl
  #Gadget_Scrolla_Area22
  #Gadget_Scrolla_Load
  #Gadget_Scrolla_Exit
EndEnumeration

#GadgetIndex = #PB_Compiler_EnumerationValue

;----------------------------------------------------------
; Image constants
;----------------------------------------------------------

Enumeration 1
  #Image_Scrolla_Temp      ; Temporary image variable for full scan
EndEnumeration

#ImageIndex = #PB_Compiler_EnumerationValue

;----------------------------------------------------------
; Static constants for other things
;----------------------------------------------------------

#PreviewWidth   = 175
#PreviewHeight  = 175

;----------------------------------------------------------
; Main window
;----------------------------------------------------------

Procedure.l Window_Scrolla()
  If OpenWindow(#Window_Scrolla,84,60,197,655,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_Invisible)
    SetWindowColor(#Window_Scrolla,$A2A2A2)
    ScrollAreaGadget(#Gadget_Scrolla_sPreview,5,5,185,575,143,575,5,#PB_ScrollArea_Flat|#PB_ScrollArea_BorderLess)
      SetGadgetColor(#Gadget_Scrolla_sPreview,#PB_Gadget_BackColor,$BFBFBF)
    CloseGadgetList()
    ContainerGadget(#Gadget_Scrolla_cControl,5,585,185,65,#PB_Container_Flat|#PB_Container_BorderLess)
      SetGadgetColor(#Gadget_Scrolla_cControl,#PB_Gadget_BackColor,$BFBFBF)
    ButtonGadget(#Gadget_Scrolla_Load,10,10,60,45,"Load image",#PB_Button_MultiLine)
      SetGadgetFont(#Gadget_Scrolla_Load,LoadFont(#Gadget_Scrolla_Load,"Comic Sans MS",10,0))
    ButtonGadget(#Gadget_Scrolla_Exit,115,10,60,45,"Exit program",#PB_Button_MultiLine)
      SetGadgetFont(#Gadget_Scrolla_Exit,LoadFont(#Gadget_Scrolla_Exit,"Comic Sans MS",10,0))
    CloseGadgetList()
    HideWindow(#Window_Scrolla,0)
    ProcedureReturn WindowID(#Window_Scrolla)
  EndIf
EndProcedure

;----------------------------------------------------------
; Program variables
;----------------------------------------------------------

Structure ProgramData
  QuitFlag.i          ; Program quit semaphore
  CurrentDir.s        ; The current directory we are working in
  ProgramVersion.s    ; Keep track of program version and compile version
  PreviewPosition.i   ; Keep track of the number of preview images added to the scroll area
  AvailableScroll.i   ; Available scroll length to add gadgets to
  ImageCounter.i      ; Number of preview images in the scroll area before having to expand area
EndStructure

;----------------------------------------------------------
; Declare your global structures
;----------------------------------------------------------

Global Program.ProgramData

;----------------------------------------------------------
; Setup directory variables
;----------------------------------------------------------

Program\CurrentDir      = GetCurrentDirectory()

;----------------------------------------------------------
; Initial scrollgadget positions
;----------------------------------------------------------

Program\PreviewPosition =   5     ; Initial position from top
Program\AvailableScroll = 575     ; Total initial scroll space

;----------------------------------------------------------
; Load a picture into the scrollareagadget dynamically
;----------------------------------------------------------

Procedure LoadAnotherImage()      ; Ration calculation code by Infratec
  NewPicture.s = OpenFileRequester("Select picture to load", "", "Jpeg (*.jpg *.jpeg *.jfif)|*.jpg;*.jpeg;*.jfif|Bitmap (*.bmp)|*.bmp|Png (*.png)|*.png|", 0)
  If NewPicture.s
    CreateImage(#Image_Scrolla_Temp, #PreviewWidth, #PreviewHeight) ; Create blank image, the size of the preview, grey
    If StartDrawing(ImageOutput(#Image_Scrolla_Temp))               ; Start drawing on the temporary image
      Box(0, 0, #PreviewWidth, #PreviewHeight, #Black)             ; Draw a grey box in the temporary image
      StopDrawing()                                                 ; Stop drawing on the temporary image
    EndIf                                                           ; Set the grey box to the imagegadget below
    NewImageNumber.i = LoadImage(#PB_Any, NewPicture.s)             ; Load the temp scan image from Temporary\ dir
    If NewImageNumber
      NewImageWidth   = ImageWidth(NewImageNumber)
      NewImageHeight  = ImageHeight(NewImageNumber)
      If StartDrawing(ImageOutput(#Image_Scrolla_Temp))
        RatioW.f = 1.0
        RatioH.f = 1.0
        If NewImageWidth > #PreviewWidth
          RatioW = NewImageWidth / #PreviewWidth
        Else
          NewWidth = NewImageWidth
        EndIf
        If NewImageHeight > #PreviewHeight
          RatioH = NewImageHeight / #PreviewHeight
        Else
          NewHeight = NewImageHeight
        EndIf
        If RatioW <> RatioH
          If RatioW > RatioH
            NewWidth = #PreviewWidth
            NewHeight = NewImageHeight / RatioW
          Else
            NewWidth = NewImageWidth / RatioH
            NewHeight = #PreviewHeight
          EndIf
        Else
          NewWidth = NewImageWidth / RatioW
          NewHeight = NewImageHeight / RatioH
        EndIf
        DrawImage(ImageID(NewImageNumber), (#PreviewWidth - NewWidth) / 2, (#PreviewHeight - NewHeight) / 2, NewWidth, NewHeight)
        StopDrawing()
        ; Now open the gadget list to add a new image preview to it
        OpenGadgetList(#Gadget_Scrolla_sPreview)
        ; Create a new imagegadget in the scrollarea list
        NewGadget.i = ImageGadget(#PB_Any, 5, Program\PreviewPosition, #PreviewWidth, #PreviewHeight, ImageID(#Image_Scrolla_Temp))
        ; Add the preview to it
        SetGadgetState(NewGadget.i, ImageID(#Image_Scrolla_Temp))
        ; Increment the position counter for the next preview
        Program\PreviewPosition + #PreviewHeight + 5    ; Height of image plus space
        ; Keep track of number of preview images in the scroll area. Add size of image after page 4 + space
        Program\ImageCounter + 1
        If Program\ImageCounter >= 4
          Program\AvailableScroll + #PreviewHeight + 5    ; Height of image plus space
          SetGadgetAttribute(#Gadget_Scrolla_sPreview, #PB_ScrollArea_InnerHeight, Program\AvailableScroll)
        EndIf
        ; Close the scroll area gadget list
        CloseGadgetList()
        ;
      Else
        Debug "Can't draw the new image to the imagegadget"
      EndIf
    Else
      Debug "Cannot get new image number"
    EndIf
  Else
    Debug "Cannot load a picture or user cancelled" 
  EndIf
EndProcedure

;----------------------------------------------------------
; Main Loop
;----------------------------------------------------------

If Window_Scrolla()

  Program\QuitFlag = 0
 
  Repeat
    EventID  = WaitWindowEvent()
    MenuID   = EventMenu()
    GadgetID = EventGadget()
    WindowID = EventWindow()
    Select EventID
      Case #PB_Event_CloseWindow
        Select WindowID
          Case  #Window_Scrolla         : Program\QuitFlag = 1
        EndSelect
      Case #PB_Event_Gadget
        Select GadgetID
          Case #Gadget_Scrolla_Load     : LoadAnotherImage()
          Case #Gadget_Scrolla_Exit     : Program\QuitFlag = 1
        EndSelect
    EndSelect
  Until Program\QuitFlag
  CloseWindow(#Window_Scrolla)
EndIf
End


The code above has been corrected but the other problem is that images sometimes disappear from the scroll area when I scroll up and down.

_________________
Resist FaceBorg or have your ass laminated!


Last edited by Fangbeast on Mon May 14, 2012 3:00 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Changing ScrollAreaGadget area on the fly
PostPosted: Mon May 14, 2012 1:58 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Tue Mar 02, 2004 1:20 pm
Posts: 684
Location: Cologne / Germany
you forgot to set the new inner height of the ScrollArea (#PB_ScrollArea_InnerHeight).

Greetings ... Kiffi

_________________
Sorry for my weird english


Top
 Profile  
 
 Post subject: Re: Changing ScrollAreaGadget area on the fly
PostPosted: Mon May 14, 2012 2:20 pm 
Offline
PureBasic Protozoa
PureBasic Protozoa
User avatar

Joined: Fri Apr 25, 2003 3:08 pm
Posts: 3011
Kiffi wrote:
you forgot to set the new inner height of the ScrollArea (#PB_ScrollArea_InnerHeight).

Greetings ... Kiffi


I thought I was doing it with this???

Quote:
SetGadgetAttribute(#Gadget_Scrolla_sPreview, #PB_ScrollArea_Y, Program\AvailableScroll)


Hmm, must be going mad.. ooooh, I've seriously misunderstood this command. Must bash myself now.

Oh bugger, when I scroll up and down now, previous images i've put in there disappear. Arrrrghggh!

_________________
Resist FaceBorg or have your ass laminated!


Top
 Profile  
 
 Post subject: Re: Changing ScrollAreaGadget area on the fly
PostPosted: Mon May 14, 2012 3:46 pm 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 1447
Location: Germany
Hi,

try this:
Code:
;----------------------------------------------------------
; Load our image decoders
;----------------------------------------------------------

UseJPEGImageDecoder()
UsePNGImageDecoder()

;----------------------------------------------------------
; Window constant
;----------------------------------------------------------

Enumeration 1
  #Window_Scrolla
EndEnumeration

#WindowIndex = #PB_Compiler_EnumerationValue

;----------------------------------------------------------
; Gadget constants
;----------------------------------------------------------

Enumeration 1
  ; Window_Scrolla
  #Gadget_Scrolla_sPreview
  #Gadget_Scrolla_Area18
  #Gadget_Scrolla_cControl
  #Gadget_Scrolla_Area22
  #Gadget_Scrolla_Load
  #Gadget_Scrolla_Exit
EndEnumeration

#GadgetIndex = #PB_Compiler_EnumerationValue

;----------------------------------------------------------
; Image constants
;----------------------------------------------------------

Enumeration 1
  #Image_Scrolla_Temp      ; Temporary image variable for full scan
EndEnumeration

#ImageIndex = #PB_Compiler_EnumerationValue

;----------------------------------------------------------
; Static constants for other things
;----------------------------------------------------------

#PreviewWidth   = 175
#PreviewHeight  = 175

;----------------------------------------------------------
; Main window
;----------------------------------------------------------

Procedure.l Window_Scrolla()
  If OpenWindow(#Window_Scrolla,84,60,197,655,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_Invisible)
    SetWindowColor(#Window_Scrolla,$A2A2A2)
    ScrollAreaGadget(#Gadget_Scrolla_sPreview,5,5,185,575,143,575,5,#PB_ScrollArea_Flat|#PB_ScrollArea_BorderLess)
      SetGadgetColor(#Gadget_Scrolla_sPreview,#PB_Gadget_BackColor,$BFBFBF)
    CloseGadgetList()
    ContainerGadget(#Gadget_Scrolla_cControl,5,585,185,65,#PB_Container_Flat|#PB_Container_BorderLess)
      SetGadgetColor(#Gadget_Scrolla_cControl,#PB_Gadget_BackColor,$BFBFBF)
    ButtonGadget(#Gadget_Scrolla_Load,10,10,60,45,"Load image",#PB_Button_MultiLine)
      SetGadgetFont(#Gadget_Scrolla_Load,LoadFont(#Gadget_Scrolla_Load,"Comic Sans MS",10,0))
    ButtonGadget(#Gadget_Scrolla_Exit,115,10,60,45,"Exit program",#PB_Button_MultiLine)
      SetGadgetFont(#Gadget_Scrolla_Exit,LoadFont(#Gadget_Scrolla_Exit,"Comic Sans MS",10,0))
    CloseGadgetList()
    HideWindow(#Window_Scrolla,0)
    ProcedureReturn WindowID(#Window_Scrolla)
  EndIf
EndProcedure

;----------------------------------------------------------
; Program variables
;----------------------------------------------------------

Structure ProgramData
  QuitFlag.i          ; Program quit semaphore
  CurrentDir.s        ; The current directory we are working in
  ProgramVersion.s    ; Keep track of program version and compile version
  PreviewPosition.i   ; Keep track of the number of preview images added to the scroll area
  AvailableScroll.i   ; Available scroll length to add gadgets to
  ImageCounter.i      ; Number of preview images in the scroll area before having to expand area
EndStructure

;----------------------------------------------------------
; Declare your global structures
;----------------------------------------------------------

Global Program.ProgramData

;----------------------------------------------------------
; Setup directory variables
;----------------------------------------------------------

Program\CurrentDir      = GetCurrentDirectory()

;----------------------------------------------------------
; Initial scrollgadget positions
;----------------------------------------------------------

Program\PreviewPosition =   5     ; Initial position from top
Program\AvailableScroll = 575     ; Total initial scroll space

;----------------------------------------------------------
; Load a picture into the scrollareagadget dynamically
;----------------------------------------------------------

Procedure LoadAnotherImage()      ; Ration calculation code by Infratec
 
  NewPicture.s = OpenFileRequester("Select picture to load", "", "Jpeg (*.jpg *.jpeg *.jfif)|*.jpg;*.jpeg;*.jfif|Bitmap (*.bmp)|*.bmp|Png (*.png)|*.png|", 0)
 
  If NewPicture.s
   
    CreateImage(#Image_Scrolla_Temp, #PreviewWidth, #PreviewHeight) ; Create blank image, the size of the preview, grey
   
    If StartDrawing(ImageOutput(#Image_Scrolla_Temp))               ; Start drawing on the temporary image
     
      Box(0, 0, #PreviewWidth, #PreviewHeight, $BFBFBF)             ; Draw a grey box in the temporary image
     
      StopDrawing()                                                 ; Stop drawing on the temporary image
     
    EndIf                                                           ; Set the grey box to the imagegadget below
   
    NewImageNumber.i = LoadImage(#PB_Any, NewPicture.s)             ; Load the temp scan image from Temporary\ dir
   
    If NewImageNumber
     
      NewImageWidth   = ImageWidth(NewImageNumber)
     
      NewImageHeight  = ImageHeight(NewImageNumber)
     
      ;If StartDrawing(ImageOutput(#Image_Scrolla_Temp))
       
        RatioW.f = 1.0
        RatioH.f = 1.0
       
        If NewImageWidth > #PreviewWidth : RatioW = NewImageWidth / #PreviewWidth : Else         
          NewWidth = NewImageWidth
        EndIf
       
        If NewImageHeight > #PreviewHeight : RatioH = NewImageHeight / #PreviewHeight : Else
          NewHeight = NewImageHeight
        EndIf
       
        If RatioW <> RatioH
          If RatioW > RatioH
            NewWidth = #PreviewWidth
            NewHeight = NewImageHeight / RatioW
          Else
            NewWidth = NewImageWidth / RatioH
            NewHeight = #PreviewHeight
          EndIf
        Else
          NewWidth = NewImageWidth / RatioW
          NewHeight = NewImageHeight / RatioH
        EndIf
       
;        DrawImage(ImageID(NewImageNumber), (#PreviewWidth - NewWidth) / 2, (#PreviewHeight - NewHeight) / 2, NewWidth, NewHeight)
       
        ;StopDrawing()
       
        ResizeImage(NewImageNumber, NewWidth, NewHeight)
       
        ; Now open the gadget list to add a new image preview to it
        OpenGadgetList(#Gadget_Scrolla_sPreview)
       
        ; Create a new imagegadget in the scrollarea list
        ;NewGadget.i = ImageGadget(#PB_Any, 5, Program\PreviewPosition, #PreviewWidth, #PreviewHeight, ImageID(#Image_Scrolla_Temp))
        NewGadget.i = ImageGadget(#PB_Any, 5, Program\PreviewPosition, #PreviewWidth, #PreviewHeight, ImageID(NewImageNumber))
       
        ; Increment the position counter for the next preview
        Program\PreviewPosition + #PreviewHeight + 5    ; Height of image plus space
       
        ; Keep track of number of preview images in the scroll area. Add size of image after page 4 + space
        Program\ImageCounter + 1
       
        If Program\ImageCounter >= 4
          Program\AvailableScroll + #PreviewHeight + 5    ; Height of image plus space
          SetGadgetAttribute(#Gadget_Scrolla_sPreview, #PB_ScrollArea_InnerHeight, Program\AvailableScroll)
        EndIf
       
        ; Close the scroll area gadget list
        CloseGadgetList()
       
      ;Else       
;        Debug "Can't draw the new image to the imagegadget"
;      EndIf
     
    Else
      Debug "Cannot get new image number"
    EndIf
   
  Else
    Debug "Cannot load a picture or user cancelled"
  EndIf
 
EndProcedure

;----------------------------------------------------------
; Main Loop
;----------------------------------------------------------

If Window_Scrolla()

  Program\QuitFlag = 0
 
  Repeat
    EventID  = WaitWindowEvent()
    MenuID   = EventMenu()
    GadgetID = EventGadget()
    WindowID = EventWindow()
    Select EventID
      Case #PB_Event_CloseWindow
        Select WindowID
          Case  #Window_Scrolla         : Program\QuitFlag = 1
        EndSelect
      Case #PB_Event_Gadget
        Select GadgetID
          Case #Gadget_Scrolla_Load     : LoadAnotherImage()
          Case #Gadget_Scrolla_Exit     : Program\QuitFlag = 1
        EndSelect
    EndSelect
  Until Program\QuitFlag
  CloseWindow(#Window_Scrolla)
EndIf
End
In your code, the image itself is not longer existant.
That's the reason why it disappears.

If you want to keep the original picture, than you need to copy the picture.

Bernd


Top
 Profile  
 
 Post subject: Re: Changing ScrollAreaGadget area on the fly
PostPosted: Tue May 15, 2012 2:02 am 
Offline
PureBasic Protozoa
PureBasic Protozoa
User avatar

Joined: Fri Apr 25, 2003 3:08 pm
Posts: 3011
Damn, didn't know what. Thought once you set it to the imagegadget that it would stay there each time.

Oh well, more to learn. Thanks Bernd, my old brain is happy to learn.

_________________
Resist FaceBorg or have your ass laminated!


Top
 Profile  
 
 Post subject: Re: Changing ScrollAreaGadget area on the fly
PostPosted: Tue May 15, 2012 7:45 am 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 1447
Location: Germany
Hi,

yes, it's not really clear written in the helpfile.
But with this code you can test it:
Code:
CreateImage(0, 300, 300)
StartDrawing(ImageOutput(0))
Box(0, 0, 400, 300, $00FF00)
StopDrawing()

CreateImage(1, 300, 300)
StartDrawing(ImageOutput(1))
Box(0, 0, 400, 300, $0000FF)
StopDrawing()

OpenWindow(0, 0, 0, 600, 300, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

ImageGadget(0, 0, 0, 1, 1, ImageID(0))
ImageGadget(1, 300, 0, 1, 1, ImageID(1))

FreeImage(0)

Exit = #False
Repeat
 
  Event = WaitWindowEvent()
  Select Event
    Case #PB_Event_CloseWindow
      Exit = #True
  EndSelect
 
Until Exit
If you bring an other window on top of it and move it away again, everything is still fine.
But if you move the window a bit below the screen and move it up again, you can see, that the first image is damaged.

Bernd


Top
 Profile  
 
 Post subject: Re: Changing ScrollAreaGadget area on the fly
PostPosted: Tue May 15, 2012 9:51 am 
Offline
PureBasic Protozoa
PureBasic Protozoa
User avatar

Joined: Fri Apr 25, 2003 3:08 pm
Posts: 3011
Thanks to your help, I whacked up an image strip viewer with labels. (very basic).

This is meant to be added to my stand alone twain scanner (that everyone helped me with) which was a subprogram to test that it worked which then gets added to my document manager.

There is never any rest for the wicked. There are other things I could add instead of sleeping (and I will eventually) but here is what I ended up with thanks to you (turns out I didn't need the ratio calculation except for the main image in the other subprogram).
Code:
;----------------------------------------------------------
; Load our image decoders
;----------------------------------------------------------

UseJPEGImageDecoder()
UsePNGImageDecoder()

;----------------------------------------------------------
; Window constant
;----------------------------------------------------------

Enumeration 1
  #Window_Scrolla
EndEnumeration

#WindowIndex = #PB_Compiler_EnumerationValue

;----------------------------------------------------------
; Gadget constants
;----------------------------------------------------------

Enumeration 1
  ; Window_Scrolla
  #Gadget_Scrolla_sPreview
  #Gadget_Scrolla_Area18
  #Gadget_Scrolla_cControl
  #Gadget_Scrolla_Area22
  #Gadget_Scrolla_Load
  #Gadget_Scrolla_Exit
EndEnumeration

#GadgetIndex = #PB_Compiler_EnumerationValue

;----------------------------------------------------------
; Image constants
;----------------------------------------------------------

Enumeration 1
  #Image_Scrolla_Temp      ; Temporary image variable for full scan
EndEnumeration

#ImageIndex = #PB_Compiler_EnumerationValue

;----------------------------------------------------------
; Main window
;----------------------------------------------------------

Procedure.l Window_Scrolla()
  If OpenWindow(#Window_Scrolla,84,60,157,655,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_Invisible)
    SetWindowColor(#Window_Scrolla,$A2A2A2)
      ScrollAreaGadget(#Gadget_Scrolla_sPreview,5,5,145,575,126,575,5,#PB_ScrollArea_Flat|#PB_ScrollArea_BorderLess)
        SetGadgetColor(#Gadget_Scrolla_sPreview,#PB_Gadget_BackColor,$BFBFBF)
      CloseGadgetList()
      ContainerGadget(#Gadget_Scrolla_cControl,5,585,145,65,#PB_Container_Flat|#PB_Container_BorderLess)
        SetGadgetColor(#Gadget_Scrolla_cControl,#PB_Gadget_BackColor,$BFBFBF)
      ButtonGadget(#Gadget_Scrolla_Load,10,10,60,45,"Load image",#PB_Button_MultiLine)
        SetGadgetFont(#Gadget_Scrolla_Load,LoadFont(#Gadget_Scrolla_Load,"Comic Sans MS",10,0))
      ButtonGadget(#Gadget_Scrolla_Exit,70,10,60,45,"Exit program",#PB_Button_MultiLine)
        SetGadgetFont(#Gadget_Scrolla_Exit,LoadFont(#Gadget_Scrolla_Exit,"Comic Sans MS",10,0))
      CloseGadgetList()
      HideWindow(#Window_Scrolla,0)
      ProcedureReturn WindowID(#Window_Scrolla)
  EndIf
EndProcedure

;----------------------------------------------------------
; Program variables
;----------------------------------------------------------

Structure ProgramData
  QuitFlag.i          ; Program quit semaphore
  CurrentDir.s        ; The current directory we are working in
  ProgramVersion.s    ; Keep track of program version and compile version
 
  PreviewTop.i        ; Keep track of the horizontal preview position per image
  PreviewLeft.i       ; Keep track of the Preview left position
  AvailableScroll.i   ; Available scroll length to add gadgets to
  ImageCounter.i      ; Number of preview images in the scroll area before having to expand area
 
  PreviewWidth.i      ;
  PreviewHeight.i     ;

EndStructure

;----------------------------------------------------------
; Declare your global structures
;----------------------------------------------------------

Global Program.ProgramData

;----------------------------------------------------------
; Setup directory variables
;----------------------------------------------------------

Program\CurrentDir      = GetCurrentDirectory()

;----------------------------------------------------------
; Initial scrollgadget positions
;----------------------------------------------------------

Program\PreviewTop      = 10      ; Initial position from top
Program\PreviewLeft     = 10      ; Preview left position
Program\AvailableScroll = 575     ; Total initial scroll space

Program\PreviewWidth    = 105     ; Preview image width
Program\PreviewHeight   = 105     ; Preview image height
 
;----------------------------------------------------------
; Load a picture into the scrollareagadget dynamically
;----------------------------------------------------------

Procedure LoadAnotherImage()
 
  ; Ask to load a new picture into the image strip
 
  NewPicture.s = OpenFileRequester("Select picture to load", "", "Jpeg (*.jpg *.jpeg *.jfif)|*.jpg;*.jpeg;*.jfif|Bitmap (*.bmp)|*.bmp|Png (*.png)|*.png|", 0)
 
  ; Only proceed if we got a new picture
 
  If NewPicture.s
   
    ; Create blank image, the size of the preview, grey
   
    CreateImage(#Image_Scrolla_Temp, Program\PreviewWidth, Program\PreviewHeight)
   
    ; Start drawing on the temporary image
   
    If StartDrawing(ImageOutput(#Image_Scrolla_Temp))
     
      ; Draw a grey box in the temporary image
     
      Box(0, 0, Program\PreviewWidth, Program\PreviewHeight, $BFBFBF)
     
      ; Stop drawing on the temporary image
     
      StopDrawing()
     
    EndIf
   
    ; Load a new picture into the image strip from any directory
   
    NewImageNumber.i = LoadImage(#PB_Any, NewPicture.s)
   
    ; Only proceed if we got a new image handle
   
    If NewImageNumber
       
      ; Resize the image to the needed preview size
     
      ResizeImage(NewImageNumber, Program\PreviewWidth, Program\PreviewHeight)
     
      ; Now open the gadget list to add a new image preview to it
     
      OpenGadgetList(#Gadget_Scrolla_sPreview)
     
        ; Create a new imagegadget in the scrollarea list 5 across, Program\PreviewWidth down
       
        NewImageGadget.i = ImageGadget(#PB_Any, Program\PreviewLeft, Program\PreviewTop, Program\PreviewWidth, Program\PreviewHeight, ImageID(NewImageNumber))
       
        ; Create a new label gadget at the bottom of the picture
       
        NewLabelGadget.i =  TextGadget(#PB_Any, Program\PreviewLeft, Program\PreviewTop + Program\PreviewHeight, Program\PreviewWidth, 20, "", #PB_Text_Center)
       
        ; Add the scroll gadget colour as the label background
 
        SetGadgetColor(NewLabelGadget.i, #PB_Gadget_BackColor, $BFBFBF)
       
        ;SetGadgetFont(NewLabelGadget.i, LoadFont(#PB_Any, "Comic Sans MS", 8, 0))
       
        SetGadgetText(NewLabelGadget.i, "Scan Image #" + Str(Program\ImageCounter + 1))
       
        ; Increment the position counter for the next preview    ; Height of image plus space plus label plus space
       
        Program\PreviewTop + Program\PreviewHeight + 5 + 15
       
        ; Keep track of number of preview images in the scroll area. Add size of image after page 4 + space
       
        Program\ImageCounter + 1
         
        ; If there are 5 previews in the list, time to start expanding the view area
       
        If Program\ImageCounter > = 5
         
          ; Height of the last image plus space
         
          Program\AvailableScroll + Program\PreviewHeight + 5
         
          ; Expand the scrolled area
         
          SetGadgetAttribute(#Gadget_Scrolla_sPreview, #PB_ScrollArea_InnerHeight, Program\AvailableScroll)
         
          ; Always keep the last image visible added
         
          SetGadgetAttribute(#Gadget_Scrolla_sPreview, #PB_ScrollArea_Y, Program\AvailableScroll)
         
        EndIf
       
        ; Close the scroll area gadget list
     
      CloseGadgetList()
       
    Else
 
      Debug "Cannot get new image number"
 
    EndIf
   
  Else
   
    Debug "Cannot load a picture or user cancelled"
   
  EndIf
 
EndProcedure

;----------------------------------------------------------
; Main Loop
;----------------------------------------------------------

If Window_Scrolla()

  Program\QuitFlag = 0
 
  Repeat
    EventID  = WaitWindowEvent()
    MenuID   = EventMenu()
    GadgetID = EventGadget()
    WindowID = EventWindow()
    Select EventID
      Case #PB_Event_CloseWindow
        Select WindowID
          Case  #Window_Scrolla         : Program\QuitFlag = 1
        EndSelect
      Case #PB_Event_Gadget
        Select GadgetID
          Case #Gadget_Scrolla_Load     : LoadAnotherImage()
          Case #Gadget_Scrolla_Exit     : Program\QuitFlag = 1
        EndSelect
    EndSelect
  Until Program\QuitFlag
  CloseWindow(#Window_Scrolla)
EndIf
End

_________________
Resist FaceBorg or have your ass laminated!


Top
 Profile  
 
 Post subject: Re: Changing ScrollAreaGadget area on the fly
PostPosted: Wed May 16, 2012 1:52 am 
Offline
Enthusiast
Enthusiast

Joined: Mon May 14, 2007 2:13 am
Posts: 734
Location: Darling River
Good coding Fangbeast and nicely documented too. :)

_________________
PureBasic Rocks! Even More! And More!
PureBasic 5, Now We're Really Rockin!


Top
 Profile  
 
 Post subject: Re: Changing ScrollAreaGadget area on the fly
PostPosted: Wed May 16, 2012 4:01 am 
Offline
PureBasic Protozoa
PureBasic Protozoa
User avatar

Joined: Fri Apr 25, 2003 3:08 pm
Posts: 3011
electrochrisso wrote:
Good coding Fangbeast and nicely documented too. :)


I bet srod will turn up soon and tell me my coding smells like a sheep's underpants and then idle will turn up to claim the used sheep!!!

_________________
Resist FaceBorg or have your ass laminated!


Top
 Profile  
 
 Post subject: Re: Changing ScrollAreaGadget area on the fly
PostPosted: Thu May 17, 2012 12:41 am 
Offline
PureBasic Protozoa
PureBasic Protozoa
User avatar

Joined: Fri Apr 25, 2003 3:08 pm
Posts: 3011
Now that this works, I have added it to the stand alone twain scan to prove that it works and then added that to my document manager which is nearly finished.

Yahoo!

_________________
Resist FaceBorg or have your ass laminated!


Top
 Profile  
 
 Post subject: Re: Changing ScrollAreaGadget area on the fly
PostPosted: Thu May 17, 2012 2:22 am 
Offline
Enthusiast
Enthusiast

Joined: Mon May 14, 2007 2:13 am
Posts: 734
Location: Darling River
Quote:
I bet srod will turn up soon and tell me my coding smells like a sheep's underpants and then idle will turn up to claim the used sheep!!!

:lol:
I was also thinking the PB gurus probably think I would not know good code if I fell over it. :)

_________________
PureBasic Rocks! Even More! And More!
PureBasic 5, Now We're Really Rockin!


Top
 Profile  
 
 Post subject: Re: Changing ScrollAreaGadget area on the fly
PostPosted: Thu May 17, 2012 6:58 am 
Offline
PureBasic Protozoa
PureBasic Protozoa
User avatar

Joined: Fri Apr 25, 2003 3:08 pm
Posts: 3011
electrochrisso wrote:
Quote:
I bet srod will turn up soon and tell me my coding smells like a sheep's underpants and then idle will turn up to claim the used sheep!!!

:lol:
I was also thinking the PB gurus probably think I would not know good code if I fell over it. :)


Code, code???? I used message sticks, glue and sheep's testicles to put this stuff together!! I wouldn't know code if I fell over it last Tuesday and arrived next monday with a compiled exe made from duct tape (complete with feral duckst!!)

_________________
Resist FaceBorg or have your ass laminated!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: AgManiX, Exabot [Bot] and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye