You are right Demivec, my code had some problems.
here is another try.
Code:
EnableExplicit
#Window = 0
Define myGadgetHeight = 30, myGadgetWidth = 100
Define fontHeight = 16 ;this is just a guess, it should be calculated somehow
Define colorNormal = RGB($60, $40, $40) ; normal button color
Define colorHighlight = RGB($80, $B0, $40) ; highlighted button color
Define xorColorToggle = colorNormal ! colorHighlight ;used to toggle between the two colors
Define Event, text$, buttonBox, buttonContainer, ypos = 5, boxRadius = myGadgetHeight / 2
Procedure ToggleButtonHighlight()
Shared xorColorToggle, boxRadius, myGadgetHeight, myGadgetWidth
If StartDrawing(CanvasOutput(EventGadget()))
DrawingMode(#PB_2DDrawing_XOr)
RoundBox(0, 0, myGadgetWidth, myGadgetHeight, boxRadius, boxRadius, xorColorToggle)
DrawingMode(#PB_2DDrawing_Default)
StopDrawing()
EndIf
EndProcedure
If OpenWindow(#Window, 0, 0, 400, 300, "Canvas Buttons",#PB_Window_ScreenCentered | #PB_Window_SystemMenu)
; Create some canvas areas to draw our custom buttons on
For buttonContainer = 1 To 5
CanvasGadget(buttonContainer, 5, ypos, myGadgetWidth, myGadgetHeight)
ypos = ypos + myGadgetHeight + 10
Next
; grab the window background color
If StartDrawing(WindowOutput(#Window))
Define winColor = Point(0,0)
StopDrawing()
EndIf
Define colorOutline = winColor ! $FFFFFF ; button outline color
; Draw our custom buttons with captions
Define offset = myGadgetHeight/2 - fontHeight/2
For buttonBox = 1 To 5
If StartDrawing(CanvasOutput(buttonBox))
Box(0, 0, myGadgetWidth, myGadgetHeight, winColor)
RoundBox(0, 0, myGadgetWidth, myGadgetHeight, boxRadius, boxRadius, colorOutline)
RoundBox(2, 2, myGadgetWidth-4, myGadgetHeight-4, boxRadius-2, boxRadius-2, colorNormal)
text$ = " Button " + Str(buttonBox)
DrawText(5, offset, text$ , colorHighlight, colorNormal )
StopDrawing()
EndIf
Next
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
Select EventType()
Case #PB_EventType_MouseEnter, #PB_EventType_MouseLeave
If EventGadget() > 0 Or EventGadget() < 6
ToggleButtonHighlight()
EndIf
Case #PB_EventType_LeftButtonDown
Select EventGadget()
Case 1 ;capture button 1 event
Debug "button 1 was clicked."
Case 2 ;capture button 2 event
Debug "button 2 was clicked."
Case 3 ; capture button 3 event
Debug "button 3 was clicked."
Case 4 ; capture button 4 event
Debug "button 4 was clicked."
Case 5 ; capture button 5 event
Debug "button 5 was clicked."
EndSelect
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow
EndIf