is it posible to change gadget colours? i.e. have a lime green panelgadget with purple textgadgets?
changing gadget colours?
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Kale.
DOH! just found this:
viewtopic.php?t=2078
and this:
viewtopic.php?t=2393
DOH! just found this:
viewtopic.php?t=2078
and this:
viewtopic.php?t=2393
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by fweil.
Hello Kale,
Just for a further help you will find hereafter a sample code showing how to paint panels and strings. Read comments to know more about the used method.
Hope this help.
Francois Weil
14, rue Douer
F64100 Bayonne
Hello Kale,
Just for a further help you will find hereafter a sample code showing how to paint panels and strings. Read comments to know more about the used method.
Hope this help.
Code: Select all
;
; This sample code shows how to have colored panel gadgets containing colored strings (foreground + background)
;
; 2 panels contain each 2 strings.
;
; Painting the panels is done using an ImageGadget. The strings cannot be painted except using #WM_CTLCOLOREDIT API signal
; in a callback procedure
;
#yellow = #red + #green ; #red #green #blue #cyan are known from Purebasic
#Panel1 = 1 ; following constants are there for a clear understanding of following code
#Panel2 = 2
#Panel1_GroundImage = #Panel1
#Panel2_GroundImage = #Panel2
#Panel_Gadget = 25
#Panel1_Image_Gadget = #Panel_Gadget + #Panel1
#Panel2_Image_Gadget = #Panel_Gadget + #Panel2
#Panel1_String1_Gadget = #Panel_Gadget + #Panel1 + 10
#Panel1_String2_Gadget = #Panel_Gadget + #Panel1 + 11
#Panel2_String1_Gadget = #Panel_Gadget + #Panel2 + 20
#Panel2_String2_Gadget = #Panel_Gadget + #Panel2 + 21
#BackGround_11 = #blue
#ForeGround_11 = #red
#BackGround_12 = #cyan
#ForeGround_12 = #yellow
#BackGround_21 = #green
#ForeGround_21 = #blue
#BackGround_22 = #red
#ForeGround_22 = #cyan
Global hStringGadget_11, hStringGadget_12, hStringGadget_21, hStringGadget_22
Global ColorBrush_11, ColorBrush_12, ColorBrush_21, ColorBrush_22
Procedure MyWindowCallBack(WindowID.l, Message.l, wParam.l, lParam.l)
Result.l
Result = #PB_ProcessPureBasicEvents
Select Message
Case #WM_CTLCOLOREDIT
Select lParam
Case hStringGadget_11
SetTextColor_(wParam, #Foreground_11)
SetBkMode_(wParam, #TRANSPARENT)
Result = ColorBrush_11
Case hStringGadget_12
SetTextColor_(wParam, #Foreground_12)
SetBkMode_(wParam, #TRANSPARENT)
Result = ColorBrush_12
Case hStringGadget_21
SetTextColor_(wParam, #Foreground_21)
SetBkMode_(wParam, #TRANSPARENT)
Result = ColorBrush_21
Case hStringGadget_22
SetTextColor_(wParam, #Foreground_22)
SetBkMode_(wParam, #TRANSPARENT)
Result = ColorBrush_22
EndSelect
EndSelect
ProcedureReturn Result
EndProcedure
;
;
;
Quit.l = #FALSE
ColorBrush_11 = CreateSolidBrush_(#Background_11)
ColorBrush_12 = CreateSolidBrush_(#Background_12)
ColorBrush_21 = CreateSolidBrush_(#Background_21)
ColorBrush_22 = CreateSolidBrush_(#Background_22)
If OpenWindow(0, 0, 0, 320, 200, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered, "")
AddKeyboardShortcut(0, #PB_Shortcut_Escape, 99)
If CreateGadgetList(WindowID())
PanelGadget(#Panel_Gadget, 10, 10, 280, 150)
AddGadgetItem(#Panel_Gadget, -1, "Panel1")
If CreateImage(#Panel1_GroundImage, 280, 130)
StartDrawing(ImageOutput())
Box(0, 0, 280, 130, #green)
StopDrawing()
EndIf
ImageGadget(#Panel1_Image_Gadget, 0, 0, 280, 130, UseImage(#Panel1_GroundImage))
hStringGadget_11 = StringGadget(#Panel1_String1_Gadget, 10, 10, 80, 20, "Panel1.String1")
hStringGadget_12 = StringGadget(#Panel1_String2_Gadget, 10, 30, 80, 20, "Panel1.String2")
AddGadgetItem(#Panel_Gadget, -1, "Panel2")
If CreateImage(#Panel2_GroundImage, 280, 130)
StartDrawing(ImageOutput())
Box(0, 0, 280, 130, #yellow)
StopDrawing()
EndIf
ImageGadget(#Panel2_Image_Gadget, 0, 0, 280, 130, UseImage(#Panel2_GroundImage))
hStringGadget_21 = StringGadget(#Panel2_String1_Gadget, 10, 10, 80, 20, "Panel2.String1")
hStringGadget_22 = StringGadget(#Panel2_String2_Gadget, 10, 30, 80, 20, "Panel2.String2")
ClosePanelGadget()
EndIf
SetWindowCallback(@MyWindowCallBack())
SetGadgetState(#Panel_Gadget, 0)
Repeat
Select WaitWindowEvent()
Case #PB_EventCloseWindow
Quit = #TRUE
Case #PB_EventMenu
Select EventMenuID()
Case 99
Quit = #TRUE
EndSelect
EndSelect
Until Quit
EndIf
End
14, rue Douer
F64100 Bayonne
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by fweil.
...,
by using another ImageGadget ! I am not a specialist about but look at the following updated code. If you play with it, you will notice that depending on the place you put this "background" gadget, it will cover or not other gadgets. I also did not find the way to paint the panel gadget tabs ... Maybe someone else knows ?
Francois Weil
14, rue Douer
F64100 Bayonne
...,
Code: Select all
;
; This sample code shows how to have colored panel gadgets containing colored strings (foreground + background)
;
; 2 panels contain each 2 strings.
;
; Painting the panels is done using an ImageGadget. The strings cannot be painted except using #WM_CTLCOLOREDIT API signal
; in a callback procedure
;
#Background_Image = 0
#Background_Image_Gadget = 0
#BackgroundColor = $602020
#yellow = #red + #green ; #red #green #blue #cyan are known from Purebasic
#Panel1 = 1 ; following constants are there for a clear understanding of following code
#Panel2 = 2
#Panel1_GroundImage = #Panel1
#Panel2_GroundImage = #Panel2
#Panel_Gadget = 25
#Panel1_Image_Gadget = #Panel_Gadget + #Panel1
#Panel2_Image_Gadget = #Panel_Gadget + #Panel2
#Panel1_String1_Gadget = #Panel_Gadget + #Panel1 + 10
#Panel1_String2_Gadget = #Panel_Gadget + #Panel1 + 11
#Panel2_String1_Gadget = #Panel_Gadget + #Panel2 + 20
#Panel2_String2_Gadget = #Panel_Gadget + #Panel2 + 21
#BackGround_11 = #blue
#ForeGround_11 = #red
#BackGround_12 = #cyan
#ForeGround_12 = #yellow
#BackGround_21 = #green
#ForeGround_21 = #blue
#BackGround_22 = #red
#ForeGround_22 = #cyan
Global hStringGadget_11, hStringGadget_12, hStringGadget_21, hStringGadget_22
Global ColorBrush_11, ColorBrush_12, ColorBrush_21, ColorBrush_22
Procedure MyWindowCallBack(WindowID.l, Message.l, wParam.l, lParam.l)
Result.l
Result = #PB_ProcessPureBasicEvents
Select Message
Case #WM_CTLCOLOREDIT
Select lParam
Case hStringGadget_11
SetTextColor_(wParam, #Foreground_11)
SetBkMode_(wParam, #TRANSPARENT)
Result = ColorBrush_11
Case hStringGadget_12
SetTextColor_(wParam, #Foreground_12)
SetBkMode_(wParam, #TRANSPARENT)
Result = ColorBrush_12
Case hStringGadget_21
SetTextColor_(wParam, #Foreground_21)
SetBkMode_(wParam, #TRANSPARENT)
Result = ColorBrush_21
Case hStringGadget_22
SetTextColor_(wParam, #Foreground_22)
SetBkMode_(wParam, #TRANSPARENT)
Result = ColorBrush_22
EndSelect
EndSelect
ProcedureReturn Result
EndProcedure
;
;
;
Quit.l = #FALSE
ColorBrush_11 = CreateSolidBrush_(#Background_11)
ColorBrush_12 = CreateSolidBrush_(#Background_12)
ColorBrush_21 = CreateSolidBrush_(#Background_21)
ColorBrush_22 = CreateSolidBrush_(#Background_22)
If OpenWindow(0, 0, 0, 320, 200, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered, "")
AddKeyboardShortcut(0, #PB_Shortcut_Escape, 99)
If CreateGadgetList(WindowID())
PanelGadget(#Panel_Gadget, 10, 10, 280, 150)
AddGadgetItem(#Panel_Gadget, -1, "Panel1")
If CreateImage(#Panel1_GroundImage, 280, 130)
StartDrawing(ImageOutput())
Box(0, 0, 280, 130, #green)
StopDrawing()
EndIf
ImageGadget(#Panel1_Image_Gadget, 0, 0, 280, 130, UseImage(#Panel1_GroundImage))
hStringGadget_11 = StringGadget(#Panel1_String1_Gadget, 10, 10, 80, 20, "Panel1.String1")
hStringGadget_12 = StringGadget(#Panel1_String2_Gadget, 10, 30, 80, 20, "Panel1.String2")
AddGadgetItem(#Panel_Gadget, -1, "Panel2")
If CreateImage(#Panel2_GroundImage, 280, 130)
StartDrawing(ImageOutput())
Box(0, 0, 280, 130, #yellow)
StopDrawing()
EndIf
ImageGadget(#Panel2_Image_Gadget, 0, 0, 280, 130, UseImage(#Panel2_GroundImage))
hStringGadget_21 = StringGadget(#Panel2_String1_Gadget, 10, 10, 80, 20, "Panel2.String1")
hStringGadget_22 = StringGadget(#Panel2_String2_Gadget, 10, 30, 80, 20, "Panel2.String2")
ClosePanelGadget()
If CreateImage(#Background_Image, 320, 200)
StartDrawing(ImageOutput())
Box(0, 0, 320, 200, #BackgroundColor)
StopDrawing()
EndIf
ImageGadget(#Background_Image_Gadget, 0, 0, 320, 200, UseImage(#Background_Image))
EndIf
SetWindowCallback(@MyWindowCallBack())
SetGadgetState(#Panel_Gadget, 0)
Repeat
Select WaitWindowEvent()
Case #PB_EventCloseWindow
Quit = #TRUE
Case #PB_EventMenu
Select EventMenuID()
Case 99
Quit = #TRUE
EndSelect
EndSelect
Until Quit
EndIf
End
14, rue Douer
F64100 Bayonne