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