.. Macro
.. Default/optional parameter values (poor example)
.. Swap
.. Not
.. Colouring in
Code: Select all
; PureBasic 4 - Hey Ma, look what I can do!
; Showing:
Enumeration ; WINDOWS
#_winMain
EndEnumeration
Enumeration ; GADGETS
#_gTxtLookAtMe
#_gBtnToggleWindow
#_gBtnToggleText
EndEnumeration
; Macro to set all PureBasic colour properties for gadget
Macro colorGadget(gadgetNum, backColor=$FFFFFF, foreColor=0, lineColor=0)
If IsGadget(gadgetNum)
SetGadgetColor(gadgetNum,#PB_Gadget_BackColor,backColor)
SetGadgetColor(gadgetNum,#PB_Gadget_FrontColor,foreColor)
SetGadgetColor(gadgetNum,#PB_Gadget_LineColor,lineColor)
EndIf
EndMacro
; Procedure to do same as Macro.
Procedure gadgetColoring(gadgetNum, backColor=$FFFFFF, foreColor=0, lineColor=0)
If IsGadget(gadgetNum)
SetGadgetColor(gadgetNum,#PB_Gadget_BackColor,backColor)
SetGadgetColor(gadgetNum,#PB_Gadget_FrontColor,foreColor)
SetGadgetColor(gadgetNum,#PB_Gadget_LineColor,lineColor)
EndIf
EndProcedure
windowBG_now.l = RGB($FF,$FF,$E0)
windowBG_later.l = RGB($E0,$F0,$FF)
textBG_now.l = RGB($FF,$00,$00)
textFG_now.l = RGB($FF,$FF,$00)
textBG_later.l = RGB($FF,$FF,$00)
textFG_later.l = RGB($FF,$00,$00)
; Let's Not and say we did!
If Not OpenWindow(#_winMain, 0,0, 200,200, #PB_Window_Invisible|#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"Hey Ma!")
MessageRequester("ERROR", "Could not open the main window. :(", #MB_ICONERROR)
End
EndIf
If Not CreateGadgetList(WindowID(#_winmain))
MessageRequester("ERROR", "Could not create gadget list. :(", #MB_ICONERROR)
CloseWindow(#_winMain)
End
EndIf
; Colouring in.
SetWindowColor(#_winMain,windowBG_now)
TextGadget(#_gTxtLookAtMe, 5,20, 190,18, "L O O K A T M E",#PB_Text_Center)
colorGadget(#_gTxtLookAtMe, textBG_now, textFG_now) ; Macro used, 2 of 3 parameters
ButtonGadget(#_gBtnToggleText, 50,60, 100,20, "TOGGLE TEXT")
ButtonGadget(#_gBtnToggleWindow, 50,100, 100,20, "TOGGLE WINDOW")
HideWindow(#_winMain,#False)
Repeat
EventID.l=WaitWindowEvent()
If EventID=#PB_Event_CloseWindow
Quit = 1
ElseIf EventID=#PB_Event_Gadget
Select EventGadget() ; Whup! No longer has ID suffix
Case #_gBtnToggleText
Swap textBG_now, textBG_later ; Swap!
Swap textFG_now, textFG_later
GadgetColoring(#_gTxtLookAtMe, textBG_now, textFG_now) ; Proc, no third param
Case #_gBtnToggleWindow
Swap windowBG_now, windowBG_later ; Swap!
SetWindowColor(#_winMain,windowBG_now)
EndSelect
EndIf
Until Quit = 1
CloseWindow(#_winMain)
End