Code: Select all
; ButtonEx example:
; Select one button and set it in 'Toggle' (pressed) mode, but release other buttons which were toggled/pressed before...
; by André
; last update: 20th May 2020
XIncludeFile "ButtonExModule.pbi"
UsePNGImageDecoder()
#Window = 0
Enumeration 1
#ButtonImg1
#ButtonImg2
#ButtonImg3
#Image
#Font
EndEnumeration
LoadFont(#Font, "Arial", 9, #PB_Font_Bold)
LoadImage(#Image, "Delete.png")
If OpenWindow(#Window, 0, 0, 450, 80, "ButtonEx: Select one button...", #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_SizeGadget)
ButtonEx::Gadget(#ButtonImg1, 10, 20, 100, 25, "Delete 1", ButtonEx::#MacOS, #Window) ; ButtonEx::#Toggle|ButtonEx::#MacOS
ButtonEx::AddImage(#ButtonImg1, #Image, 16, 16, ButtonEx::#Left)
ButtonEx::Gadget(#ButtonImg2, 120, 20, 100, 25, "Delete 2", ButtonEx::#MacOS, #Window) ; ButtonEx::#Toggle|ButtonEx::#MacOS
ButtonEx::AddImage(#ButtonImg2, #Image, 16, 16, ButtonEx::#Right)
ButtonEx::SetFont(#ButtonImg2, #Font)
ButtonEx::Gadget(#ButtonImg3, 230, 20, 100, 25, "Delete 3", 0, #Window) ; ButtonEx::#Toggle|ButtonEx::#MacOS
ButtonEx::AddImage(#ButtonImg3, #Image, 16, 16, ButtonEx::#Right)
ButtonEx::SetFont(#ButtonImg3, #Font)
ButtonEx::SetColor(#ButtonImg3, ButtonEx::#BackColor, $AADDDD)
ButtonEx::SetColor(#ButtonImg3, ButtonEx::#BorderColor, $FF0000)
Repeat
Event = WaitWindowEvent()
Select Event
Case ButtonEx::#Event_Gadget ; works with or without EventType()
Select EventGadget()
Case #ButtonImg1
Debug "Delete1 button pressed"
If ActiveButton > 0
;Debug "Last selected button: " + ActiveButton
;Debug "State of this button: " + ButtonEx::GetState(ActiveButton)
ButtonEx::SetState(ActiveButton, 0) ; reset the 'Toggle' state for the last selected button
EndIf
ButtonEx::SetState(#ButtonImg1, ButtonEx::#Toggle)
ActiveButton = #ButtonImg1
Case #ButtonImg2
Debug "Delete2 button pressed"
If ActiveButton > 0
;Debug "Last selected button: " + ActiveButton
;Debug "State of this button: " + ButtonEx::GetState(ActiveButton)
ButtonEx::SetState(ActiveButton, 0) ; reset the 'Toggle' state for the last selected button
EndIf
ButtonEx::SetState(#ButtonImg2, ButtonEx::#Toggle)
ActiveButton = #ButtonImg2
Case #ButtonImg3
Debug "Delete3 button pressed"
If ActiveButton > 0
;Debug "Last selected button: " + ActiveButton
;Debug "State of this button: " + ButtonEx::GetState(ActiveButton)
ButtonEx::SetState(ActiveButton, 0) ; reset the 'Toggle' state for the last selected button
EndIf
ButtonEx::SetState(#ButtonImg3, ButtonEx::#Toggle)
ActiveButton = #ButtonImg3
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow
CloseWindow(#Window)
EndIf