Canvas Gadget - How is this code?
Posted: Wed Jan 04, 2012 1:58 am
Hi all,
Just wondering if you could let me know if this code looks ok as a basic start? It's been a while since I used PB so I've very rusty.
Basically this code will be the basis for a simple program launcher, i.e It'll read a directory and populate the window with buttons. This code is just a test of that functionality on a very basic level. It should highlight the dummy button when the mouse is over it etc.
I just wanted to check the code looked ok to the professionals on here....
Just wondering if you could let me know if this code looks ok as a basic start? It's been a while since I used PB so I've very rusty.
Basically this code will be the basis for a simple program launcher, i.e It'll read a directory and populate the window with buttons. This code is just a test of that functionality on a very basic level. It should highlight the dummy button when the mouse is over it etc.
I just wanted to check the code looked ok to the professionals on here....
Code: Select all
#Window = 0
Global myGadgetHeight = 50, myGadgetWidth = 100
If OpenWindow(#Window, 0, 0, 100, 300, "Test")
; Create some canvas areas to draw our custom buttons on
For buttonContainer = 1 To 5
CanvasGadget(buttonContainer, 0, ypos, 100, 50)
ypos = ypos + 51
Next
; Draw our custom buttons
For buttonBox = 1 To 5
StartDrawing(CanvasOutput(buttonBox))
Box(0, 0, myGadgetWidth, myGadgetHeight, RGB($44, $00, $00))
StopDrawing()
Next
EndIf
Procedure mouseEntered (thisGadget)
StartDrawing(CanvasOutput(thisGadget))
Box(0,0,myGadgetWidth,myGadgetHeight,RGB($00, $44, $00))
StopDrawing()
EndProcedure
Procedure mouseLeft (thisGadget)
StartDrawing(CanvasOutput(thisGadget))
Box(0,0,myGadgetWidth,myGadgetHeight,RGB($44, $00, $00))
StopDrawing()
EndProcedure
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
thisGadget = EventGadget()
If EventType() = #PB_EventType_MouseEnter
mouseEntered(thisGadget)
ElseIf EventType() = #PB_EventType_MouseLeave
mouseLeft(thisGadget)
EndIf
EndSelect
Until Event = #PB_Event_CloseWindow