Hi,
I'm using DBPro and BlueGUI and I have a question about scrollbars on resizable windows. What I aim to get is a simple resizable window that holds a larger image and then use the scrollbars to browse over it.
Currently I'm doing some tests based on this source code I found somewhere in this forum:
` Main source file
startBlue "***","******"
sync off
#include "gui.dba"
` Declare Global Variables For Windows Gadget Handles
global mainWin
global mainMenu
global fileMenu
global editMenu
global viewMenu
global imageMenu
global helpMenu
global popupMenu
global mainStatusBar
global fileName as string
global fileType as string="BMP (Windows bitmap)|*.bmp|JPG (JPEG file interchange format)|*.jpg|PNG (Portable network graphics)|*.png|TGA (Targa file format)|*.tga"
global currentImage
global sliderX
global sliderY
global fillPanel
createUI()
do
setStatusText mainStatusBar,0,str$(mousePosx())+", "+str$(mousePosY())
getEvent
processEvents()
loop
function createUI()
local Title as string="Image Autographer v1.0"
proWin=createGadgetFromWindow(mainWindow())
setGadgetVisible proWin,0
desktopWin=createGadgetFromWindow(desktopWindow())
mainWin=createWindow(0,0,gadgetWidth(desktopWin),gadgetHeight(desktopWin),Title,WINDOW_NORMAL,0,0,0)
mainMenu=createMenu(mainWin)
mainStatusBar=createStatusBar(mainWin)
popupMenu=createPopupMenu()
addMenuItem mainMenu,"File",5
addMenuItem mainMenu,"Edit",1
addMenuItem mainMenu,"View",2
addMenuItem mainMenu,"Image",3
addMenuItem mainMenu,"Help",4
fileMenu=createSubMenu(mainMenu,5)
editMenu=createSubMenu(mainMenu,1)
viewMenu=createSubMenu(mainMenu,2)
imageMenu=createSubMenu(mainMenu,3)
helpMenu=createSubMenu(mainMenu,4)
addMenuItem fileMenu,"Open",6
addMenuSplitter fileMenu
addMenuItem fileMenu,"Save",7
addmenuItem fileMenu,"Save As",8
addMenuSplitter fileMenu
addMenuItem fileMenu,"Batch Process",9
addMenuSplitter fileMenu
addMenuItem fileMenu,"Close",10
addMenuItem fileMenu,"Exit",11
addMenuItem editMenu,"Undo",12
addMenuItem editMenu,"Redo",13
addMenuSplitter editMenu
addMenuItem editMenu,"Cut",14
addMenuItem editMenu,"Copy",15
addMenuItem editMenu,"Paste",16
addMenuItem helpMenu,"About",17
addMenuItem popupMenu,"Item 16",18
addMenuItem popupMenu,"Item 17",19
addMenuItem popupMenu,"Item 18",20
blockMenuOptions()
endfunction
Function processEvents()
if eventType()=MENU_CLICK
select eventData()
case 6 `Load single image file
openSingleFile()
endcase
case 7 `Save single image file
saveSingleFile(0)
endcase
case 8 `Save image file as
saveSingleFile(1)
endcase
case 9 `Batch Process
batchProcess()
endcase
case 10 `Close file
closeSingleFile()
endcase
case 11 `Exit
savePrompt():end
endcase
endselect
activateGadget mainWin
endif
if mouseclick()=2
`Show Popup Menu
result=showPopupMenu(popupMenu)
message "You clicked item " + str$(result)
endif
if eventSource()=sliderX
moveGadget currentImage,0-getScrollbarPosition(sliderX),gadgetY(currentImage)
endif
if eventSource()=sliderY
moveGadget currentImage,gadgetX(currentImage),0-getScrollbarPosition(sliderY)
endif
if eventSource()=mainWin and eventType()=WINDOW_CLOSE
savePrompt():end
endif
endfunction
Function openSingleFile()
savePrompt()
fileName=openDialog("Open Image File",fileType)
if fileName<>""
if file exist(fileName)=1
load bitmap fileName,1
imageSizeX=bitmap width(1)-1
imageSizeY=bitmap height(1)-1
get image 1,0,0,imageSizeX,imageSizeY,1
delete bitmap 1
currentImage=createCanvas(0,0,imageSizeX,imageSizeY,mainWin)
setCanvasImage(currentImage,1,1)
canvasWidth=gadgetWidth(currentImage)
canvasHeight=gadgetHeight(currentImage)
mainWidth=gadgetClientWidth(mainWin)
mainHeight=gadgetClientHeight(mainWin)
if canvasWidth>mainWidth
sliderX=createScrollBar(0,mainHeight-40,mainWidth,20,0,mainWin)
maxScrollX=canvasWidth-mainWidth
setScrollbarRange sliderX,0,maxScrollX
setScrollbarThumbSize sliderX,1
bringToFront sliderX
endif
if canvasHeight>mainHeight-20
if sliderX=0
sliderY=createScrollBar(mainWidth-20,0,20,mainHeight-20,1,mainWin)
maxScrollY=canvasHeight-mainHeight+20
setScrollbarRange sliderY,0,maxScrollY
setScrollbarThumbSize sliderY,1
bringToFront sliderY
else
sliderY=createScrollBar(mainWidth-20,0,20,mainHeight-40,1,mainWin)
maxScrollY=canvasHeight-(mainHeight-gadgetHeight(sliderX))+20
setScrollbarRange sliderY,0,maxScrollY
setScrollbarThumbSize sliderY,1
bringToFront sliderY
resizeGadget sliderX,gadgetWidth(sliderX)-gadgetWidth(sliderY),gadgetHeight(sliderX),0
maxScrollX=canvasWidth-(mainWidth-gadgetWidth(sliderY))
setScrollbarRange sliderX,0,maxScrollX
setScrollbarThumbSize sliderX,1
fillPanel=createPanel(gadgetWidth(sliderX),gadgetHeight(sliderY),mainWidth,mainHeight-20,mainWin)
bringToFront fillPanel
endif
endif
setMenuItemEnabled fileMenu,7,1
setMenuItemEnabled fileMenu,8,1
setMenuItemEnabled fileMenu,10,1
else
errorMessage "File Not Found!"
endif
endif
endfunction
Function saveSingleFile(saveAsOption)
if saveAsOption=1
saveFile:fileName=saveDialog("Save Image File As",fileType)
if fileName="" then exitfunction
if file exist(fileName)=1
option=questionMessage("Do you wish to over-write file?","FILE ALREADY EXISTS")
if option=0 then goto saveFile
endif
endif
getCanvasImage currentImage,2
save image fileName,2
delete image 2
if file exist(fileName)=0 then errorMessage "Could not write file: "+filename
endfunction
Function closeSingleFile()
if sliderX<>0 then sliderX=deleteGadget(sliderX):sliderX=0
if sliderY<>0 then sliderY=deleteGadget(sliderY):sliderY=0
if fillPanel<>0 then fillPanel=deleteGadget(fillPanel):fillPanel=0
currentImage=deleteGadget(currentImage):currentImage=0
blockMenuOptions()
endfunction
Function SavePrompt()
if currentImage<>0
option=questionMessage("Do you wish to save the current project?","Save Project")
if option=0 then closeSingleFile()
if option=1 then saveSingleFile(1)
endif
endfunction
Function batchProcess()
local dim fileBatch(1000) as string
local fileFolder as string
local fileFormat as string
fileFolder=folderDialog()
if fileFolder<>""
set dir fileFolder
perform checklist for files
for f=1 to checklist quantity()
fileFormat=right$(checklist string$(f),4)
if fileFormat=".bmp" or fileFormat=".jpg" or fileFormat=".png" or fileFormat=".tga"
inc fileCount
fileBatch(fileCount)=checklist string$(f)
endif
next f
if fileCount>0
option=questionMessage("Do you wish to proceed with batch processing?",str$(filecount)+" IMAGE FILES FOUND!")
if option=0 then exitfunction
else
message "No compatible files where found."
endif
endif
endfunction
Function blockMenuOptions()
setMenuItemEnabled fileMenu,7,0
setMenuItemEnabled fileMenu,8,0
setMenuItemEnabled fileMenu,10,0
endfunction
Function setCanvasImage(gadgetNumber,imageNumber,memBlok)
make memblock from image memBlok,imageNumber
MbcXSize=memblock dword(memBlok,0)
MbcYSize=memblock dword(memBlok,4)
Depth=memblock dword(memBlok,8)/8
GadXSize=gadgetWidth(gadgetNumber)
GadYSize=gadgetHeight(gadgetNumber)
if GadXSize<XSize
XSize=GadXSize
else
XSize=MbcXSize
endif
if GadYSize<YSize
YSize=GadYSize
else
YSize=MbcYSize
endif
for YLoop=0 To YSize-1
for XLoop=0 to XSize-1
if Depth=4
_Ink=memblock dword(memBlok,12+(Depth*XLoop)+(YLoop*MbcXSize*Depth))
else
_Ink=memblock word(memBlok,12+(Depth*XLoop)+(YLoop*MbcXSize*Depth))
endif
drawPoint gadgetNumber,XLoop,YLoop,_Ink
next XLoop
next YLoop
paintGadget gadgetNumber
delete memblock memBlok
endFunction
This code is not mine, but from D Ogre. I hope he won't mind me using it as a starting point.. The thing is I'd like to know if there's a way to update the scrollbars' size and position whenever the window is resized, much like regular Win apps behave. Currently they get stuck at their original position, much to my despair.
I've tried catching up gadget events (GADGET_SIZING and GADGET_SIZE - what's the difference btw?) to trigger updates on sliderX and sliderY but failed miserably.
Any ideas/suggestions?
Cheers