-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathObjectTheme_Demo.pb
More file actions
330 lines (287 loc) · 14.1 KB
/
ObjectTheme_Demo.pb
File metadata and controls
330 lines (287 loc) · 14.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
;- Top
; -------------------------------------------------------------------------------------------------------------------------------------------------
; Title: Demo for Object Theme Library (for Dark or Light Theme)
; Description: This library will add and apply a theme color for All Windows and Gadgets.
; And for All possible color attributes (BackColor, FrontColor, TitleBackColor,...) for each of them
; All gadgets will still work in the same way as PureBasic Gadget
; Source Name: ObjectTheme_Demo.pb
; Author: ChrisR
; Creation Date: 2023-11-06
; modification Date: 2026-03-24
; Version: 1.6.6
; PB-Version: 6.0 or other
; OS: Windows Only
; Forum: https://www.purebasic.fr/english/viewtopic.php?t=82890
; -------------------------------------------------------------------------------------------------------------------------------------------------
EnableExplicit
;- ---> Add XIncludeFile "ObjectTheme.pbi"
XIncludeFile "ObjectTheme.pbi"
;- ---> UseModule ObjectTheme (Mandatory)
; To call macros directly (e.g. ButtonGadget) without having to change existing code and use ObjectTheme::ButtonGadget
UseModule ObjectTheme
UseJPEGImageDecoder()
UsePNGImageDecoder()
Enumeration Window
#Window_1
#Window_2
EndEnumeration
Enumeration Gadgets
#Edit_1
#ExpList_1
#ExpTree_1
#Date_1
#Frame_1
#ListIcon_1
#ListView_1
#Hyper_1
#Progres_1
#Check_3
#Spin_1
#String_1
#Txt_1
#Scrlbar_1
#Splitter_1
#Splitter_2
#Track_1
#Tree_1
#String_2
#Panel_1
#ScrlArea_1
#Cont_2
#Calend_1
#Combo_1
#Combo_2
#Combo_3
#Cont_1
#Txt_2
#Check_1
#Check_2
#Opt_1
#Opt_2
#ApplyTheme_1
#ApplyTheme_2
EndEnumeration
#Max_DisableGadget = #Cont_1 - 1
Enumeration Font
#Font
EndEnumeration
LoadFont(#Font, "Consolas", 9)
Enumeration Image
#Imag
#Imag_Wood
#Imag_clouds
EndEnumeration
LoadImage(#Imag_Wood, #PB_Compiler_Home + "Examples\3D\Data\Textures\Wood.jpg")
LoadImage(#Imag_clouds, #PB_Compiler_Home + "Examples\3D\Data\Textures\clouds.jpg")
LoadImage(#Imag, #PB_Compiler_Home + "examples/sources/Data/world.png")
Procedure CreateComboBox(OwnerDraw = #False)
Protected Flags, State, I
If OwnerDraw = #True
Flags = #CBS_HASSTRINGS | #CBS_OWNERDRAWFIXED
EndIf
OpenGadgetList(#Panel_1, 0)
State = GetGadgetState(#Combo_1)
ComboBoxGadget(#Combo_1, GadgetX(#Combo_1), GadgetY(#Combo_1), GadgetWidth(#Combo_1), GadgetHeight(#Combo_1), #PB_ComboBox_Editable | Flags)
SendMessage_(GadgetID(#Combo_1), #CB_SETMINVISIBLE, 5, 0) ; Only 5 elements visible to display the ScrollBar for the Dark or Explorer theme
For I = 1 To 10 : AddGadgetItem(#Combo_1, -1, "Combo Editable Element " + Str(I)) : Next
SetGadgetState(#Combo_1, State)
CloseGadgetList()
OpenGadgetList(#ScrlArea_1)
State = GetGadgetState(#Combo_3)
ComboBoxGadget(#Combo_3, GadgetX(#Combo_3), GadgetY(#Combo_3), GadgetWidth(#Combo_3), GadgetHeight(#Combo_3), Flags)
SendMessage_(GadgetID(#Combo_3), #CB_SETMINVISIBLE, 5, 0) ; Only 5 elements visible to display the ScrollBar for the Dark or Explorer theme
For I = 1 To 10 : AddGadgetItem(#Combo_3, -1, "Combo Element " + Str(I)) : Next
SetGadgetState(#Combo_3, State)
CloseGadgetList()
EndProcedure
Procedure Open_Window_1(X = 20, Y = 20, Width = 580, Height = 460)
Protected I
If OpenWindow(#Window_1, X, Y, Width, Height, "Demo ObjectTheme Window_1", #PB_Window_MinimizeGadget | #PB_Window_SystemMenu)
ResizeImage(#Imag_Wood, DesktopScaledX(Width), DesktopScaledY(Height))
ButtonGadget(#ApplyTheme_1, 20, 390, 540, 50, "Apply Dark Blue Theme", #PB_Button_Default)
ContainerGadget(#Cont_1, 20, 20, 320, 75, #PB_Container_Flat)
TextGadget(#Txt_2, 5, 5, 180, 20, "Customize the display:")
CheckBoxGadget(#Check_1, 20, 25, 160, 20, "Add Image Background")
CheckBoxGadget(#Check_2, 20, 45, 160, 20, "Disable Gadgets")
OptionGadget(#Opt_1, 190, 25, 120, 20, "Object Theme")
OptionGadget(#Opt_2, 190, 45, 120, 20, "Default Theme")
SetGadgetState(#Opt_1, #True)
CloseGadgetList() ; #Cont_1
EditorGadget(#Edit_1, 360, 20, 200, 70)
For I = 1 To 5 : AddGadgetItem(#Edit_1, -1, "Editor Line " + Str(I)) : Next
ListViewGadget(#ListView_1, 360, 80, 200, 80)
For I = 1 To 5 : AddGadgetItem(#ListView_1, -1, "ListView Element " + Str(I)) : Next
SplitterGadget(#Splitter_1, 360, 20, 200, 160, #Edit_1, #ListView_1, #PB_Splitter_Separator)
SetGadgetState(#Splitter_1, 70)
FrameGadget(#Frame_1, 20, 110, 150, 60, "Frame_1"); : DisableGadget(#Frame_1, #True)
TextGadget(#Txt_1, 40, 135, 100, 20, "This is a Text"); : DisableGadget(#Txt_1, #True)
HyperLinkGadget(#Hyper_1, 190, 110, 160, 20, "https://www.purebasic.com/", $FF2600, #PB_HyperLink_Underline)
DateGadget(#Date_1, 190, 140, 110, 30, "%yyyy-%mm-%dd", 0)
CalendarGadget(#Calend_1, 20, 195, 240, 180)
PanelGadget(#Panel_1, 280, 195, 280, 180)
AddGadgetItem(#Panel_1, -1, "Tab_0", ImageID(#Imag))
ProgressBarGadget(#Progres_1, 20, 20, 140, 16, 0, 100)
CheckBoxGadget(#Check_3, 180, 20, 90, 20, "CheckBox")
SetGadgetState(#Progres_1, 66)
SpinGadget(#Spin_1, 20, 56, 80, 26, 0, 100, #PB_Spin_Numeric) ; #PB_Spin_ReadOnly
SetGadgetState(#Spin_1, 66)
StringGadget(#String_1, 110, 56, 150, 26, "String_1")
ComboBoxGadget(#Combo_1, 20, 102, 180, 28, #PB_ComboBox_Editable) ; #CBS_HASSTRINGS | #CBS_OWNERDRAWFIXED flags will be auto added with SetObjectTheme() done before the combobox creation
SendMessage_(GadgetID(#Combo_1), #CB_SETMINVISIBLE, 5, 0) ; Only 5 elements visible to display the ScrollBar for the Dark or Explorer theme
For I = 1 To 10 : AddGadgetItem(#Combo_1, -1, "Combo Editable Element " + Str(I)) : Next
SetGadgetState(#Combo_1, 0)
AddGadgetItem(#Panel_1, -1, "Tab_1", ImageID(#Imag))
AddGadgetItem(#Panel_1, -1, "Tab_2", ImageID(#Imag))
CloseGadgetList() ; #Panel_1
EndIf
EndProcedure
Procedure Open_Window_2(X = 620, Y = 20, Width = 420, Height = 460)
Protected I
If OpenWindow(#Window_2, X, Y, Width, Height, "Demo ObjectTheme Window_2", #PB_Window_MinimizeGadget | #PB_Window_SystemMenu)
ResizeImage(#Imag_clouds, DesktopScaledX(Width), DesktopScaledY(Height))
ButtonGadget(#ApplyTheme_2, 20, 390, 380, 50, "Apply Auto Theme With Selected Color", #PB_Button_Default)
ListIconGadget(#ListIcon_1, 20, 20, 180, 90, "ListIcon", 120)
AddGadgetColumn(#ListIcon_1, 1, "Column 2", 240)
For I = 1 To 5 : AddGadgetItem(#ListIcon_1, -1, "ListIcon Element " + Str(I) +Chr(10)+ "Column 2 Element " + Str(I)) : Next
ExplorerListGadget(#ExpList_1, 220, 20, 180, 90, "")
SplitterGadget(#Splitter_2, 20, 20, 380, 90, #ListIcon_1, #ExpList_1, #PB_Splitter_Vertical | #PB_Splitter_Separator)
SetGadgetState(#Splitter_2, 180)
ExplorerTreeGadget(#ExpTree_1, 20, 120, 180, 60, "")
ComboBoxGadget(#Combo_2, 220, 137, 180, 28, #PB_ComboBox_Image) ; Partially Draw: Only the selected item is drawn but not the drop-down list
SendMessage_(GadgetID(#Combo_2), #CB_SETMINVISIBLE, 5, 0)
For I = 1 To 10 : AddGadgetItem(#Combo_2, -1, "Combo Image Elem " + Str(I), ImageID(#Imag)) : Next
SetGadgetState(#Combo_2, 0)
ScrollAreaGadget(#ScrlArea_1, 20, 195, 380, 180, 540, 300, 10, #PB_ScrollArea_Flat)
ContainerGadget(#Cont_2, 10, 15, 340, 50, #PB_Container_Flat)
TrackBarGadget(#Track_1, 10, 10, 150, 30, 0, 100)
SetGadgetState(#Track_1, 66)
ScrollBarGadget(#Scrlbar_1, 170, 10, 150, 20, 0, 100, 10)
CloseGadgetList() ; #Cont_2
TreeGadget(#Tree_1, 10, 80, 180, 60)
AddGadgetItem(#Tree_1, -1, "Element 1", 0, 0)
AddGadgetItem(#Tree_1, -1, "Node", 0, 0)
AddGadgetItem(#Tree_1, -1, "Sub-element", 0, 1)
AddGadgetItem(#Tree_1, -1, "Element 2", 0, 0)
SetGadgetItemState(#Tree_1, 1, #PB_Tree_Expanded)
StringGadget(#String_2, 200, 80, 150, 25, "String_2")
ComboBoxGadget(#Combo_3, 200, 112, 150, 28) ; #CBS_HASSTRINGS | #CBS_OWNERDRAWFIXED flags will be auto added with SetObjectTheme() done before the combobox creation
SendMessage_(GadgetID(#Combo_3), #CB_SETMINVISIBLE, 5, 0) ; Only 5 elements visible to display the ScrollBar for the Dark or Explorer theme
For I = 1 To 10 : AddGadgetItem(#Combo_3, -1, "Combo Element " + Str(I)) : Next
SetGadgetState(#Combo_3, 0)
CloseGadgetList() ; #ScrlArea_1
EndIf
EndProcedure
Define Brush_Imag_Wood, Brush_Imag_clouds, Disable, I
; Uncomment for Testing with a Font
; SetGadgetFont(#PB_Default, FontID(#Font))
;- ---> Add SetObjectTheme()
; It can be positioned anywhere in the code
; If it is at the beginning before the combobox creation, you don't need to add the 2 constants #CBS_HASSTRINGS | #CBS_OWNERDRAWFIXED for ComboBoxGadget()
SetObjectTheme(#ObjectTheme_LightBlue)
Open_Window_1()
Open_Window_2()
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
CloseWindow(EventWindow())
If Not (IsWindow(#Window_1) Or IsWindow(#Window_2))
Break
EndIf
Case #PB_Event_Gadget
Select EventGadget()
Case #Check_1
If GetGadgetState(#Check_1)
Brush_Imag_Wood = CreatePatternBrush_(ImageID(#Imag_Wood))
If Brush_Imag_Wood
SetClassLongPtr_(WindowID(#Window_1), #GCL_HBRBACKGROUND, Brush_Imag_Wood)
InvalidateRect_(WindowID(#Window_1), #Null, #True)
EndIf
Brush_Imag_clouds = CreatePatternBrush_(ImageID(#Imag_clouds))
If Brush_Imag_clouds
SetClassLongPtr_(WindowID(#Window_2), #GCL_HBRBACKGROUND, Brush_Imag_clouds)
InvalidateRect_(WindowID(#Window_2), #Null, #True)
EndIf
SetObjectThemeAttribute(#PB_WindowType, #PB_Gadget_BrushBackground, #True)
Else
If Brush_Imag_Wood
DeleteObject_(Brush_Imag_Wood)
SetClassLongPtr_(WindowID(#Window_1), #GCL_HBRBACKGROUND, #NULL_BRUSH)
InvalidateRect_(WindowID(#Window_1), #Null, #True)
EndIf
If Brush_Imag_clouds
DeleteObject_(Brush_Imag_clouds)
SetClassLongPtr_(WindowID(#Window_2), #GCL_HBRBACKGROUND, #NULL_BRUSH)
InvalidateRect_(WindowID(#Window_2), #Null, #True)
EndIf
SetObjectThemeAttribute(#PB_WindowType, #PB_Gadget_BrushBackground, #False)
EndIf
; For Testing
;DisableGadget(#Spin_1, GetGadgetState(#Check_1))
;SetObjectThemeAttribute(0, #PB_Gadget_BackColor, #Red)
;SetWindowColor(#Window_1, #Red)
;SetObjectTypeColor(#PB_GadgetType_Button, #PB_Gadget_FrontColor, #Red)
;SetObjectColor(#Progres_1, #PB_Gadget_BackColor, #Yellow)
;SetObjectColor(#Progres_1, #PB_Gadget_FrontColor, #Red)
;SetGadgetColor(#Progres_1, #PB_Gadget_BackColor, #Yellow)
;SetGadgetColor(#Progres_1, #PB_Gadget_FrontColor, #Red)
Case #Check_2
Disable = GetGadgetState(#Check_2)
For I = 0 To #Max_DisableGadget
DisableGadget(I, Disable)
Next
Case #Opt_1
Select GetGadgetText(#ApplyTheme_1)
Case "Apply Dark Blue Theme"
SetObjectTheme(#ObjectTheme_LightBlue)
Case "Apply Light Blue Theme"
SetObjectTheme(#ObjectTheme_DarkRed)
Case "Apply Dark Red Theme"
SetObjectTheme(#ObjectTheme_DarkBlue)
EndSelect
CreateComboBox(#True) ; Recreate ComboBoxGadget with the #CBS_OWNERDRAWFIXED flag to paint its drop-down list
If GetGadgetState(#Check_1)
SetObjectThemeAttribute(#PB_WindowType, #PB_Gadget_BrushBackground, #True)
Else
SetObjectThemeAttribute(#PB_WindowType, #PB_Gadget_BrushBackground, #False)
EndIf
Case #Opt_2
SetObjectTheme(#PB_Default)
CreateComboBox() ; Recreate ComboBoxGadget without the #CBS_OWNERDRAWFIXED flag to paint its drop-down list with default value
Case #ApplyTheme_1
If GetGadgetState(#Opt_2)
SetGadgetState(#Opt_1, #True)
EndIf
Select GetGadgetText(#ApplyTheme_1)
Case "Apply Dark Blue Theme"
SetGadgetText(#ApplyTheme_1, "Apply Dark Red Theme")
SetObjectTheme(#ObjectTheme_DarkBlue)
Case "Apply Light Blue Theme"
SetGadgetText(#ApplyTheme_1, "Apply Dark Blue Theme")
SetObjectTheme(#ObjectTheme_LightBlue)
Case "Apply Dark Red Theme"
SetGadgetText(#ApplyTheme_1, "Apply Light Blue Theme")
SetObjectTheme(#ObjectTheme_DarkRed)
EndSelect
If GetGadgetState(#Check_1)
SetObjectThemeAttribute(#PB_WindowType, #PB_Gadget_BrushBackground, #True)
Else
SetObjectThemeAttribute(#PB_WindowType, #PB_Gadget_BrushBackground, #False)
EndIf
Case #ApplyTheme_2
;SetObjectTheme(#PB_Default, GetSysColor_(#COLOR_WINDOW)) ; For Testing ObjectTheme() with default Window Color
;SetObjectTheme(#ObjectTheme_Custom) ; For Testing your Custom theme
If GetGadgetState(#Opt_2)
SetGadgetState(#Opt_1, #True)
EndIf
Define Color = ColorRequester(GetWindowColor(#Window_2))
SetObjectTheme(#ObjectTheme_Auto, Color)
If IsGadget(#Check_1) And GetGadgetState(#Check_1)
SetObjectThemeAttribute(#PB_WindowType, #PB_Gadget_BrushBackground, #True)
Else
SetObjectThemeAttribute(#PB_WindowType, #PB_Gadget_BrushBackground, #False)
EndIf
EndSelect
EndSelect
ForEver
If Brush_Imag_Wood : DeleteObject_(Brush_Imag_Wood) : EndIf
If Brush_Imag_clouds : DeleteObject_(Brush_Imag_clouds) : EndIf