-
Notifications
You must be signed in to change notification settings - Fork 0
/
bevelbutton.pb
187 lines (162 loc) · 4.97 KB
/
bevelbutton.pb
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
; BevelButton Menu
DeclareModule BevelButton
Structure button
gadget.l
width.i
height.i
text.s
font.i
color.i
flags.i
clickable.i
EndStructure
Global NewMap Gadget2BevelButton()
Declare New(x, y, width, height, image, text.s, font = 0, flags = 0)
Declare Delete(*button.button)
Declare Redraw(*button.button)
Declare Enable(*button.button)
Declare ColorDark(*button.button)
Declare ColorNormal(*button.button)
Declare Disable(*button.button)
Declare GetGadgetID(*button.button)
Declare SetText(*button.button, text.s, font = 0)
Declare.s GetText(*button.button)
Declare SetFont(*button.button, font)
Declare GetButton(gadget)
Declare GetState(*button.button)
Declare SetState(*button.button, state)
Declare Hide(*button.button)
Declare Show(*button.button)
Declare Clickable(*button.button, status)
EndDeclareModule
Module BevelButton
Procedure New(x, y, width, height, image, text.s, font = 0, flags = 0)
Protected *button.button
*button = AllocateMemory(SizeOf(button))
*button\gadget = ButtonImageGadget(#PB_Any, x, y, width, height, image, flags)
*button\width = width
*button\height = height
*button\font = font
*button\text = text
*button\color = RGB(0, 255, 0)
*button\flags = flags
*button\clickable = #True
Redraw(*button)
Gadget2BevelButton(Str(*button\gadget)) = *button
ProcedureReturn *button
EndProcedure
Procedure Delete(*button.button)
FreeMemory(*button)
EndProcedure
Procedure Redraw(*button.button)
Protected color, image
; Clickable
If *button\clickable = #False
ProcedureReturn
EndIf
; Button state
If GetGadgetState(*button\gadget) = #True
color = *button\color
Else
color = GetSysColor_(#COLOR_BTNFACE)
EndIf
; Draw button-image
image = CreateImage(#PB_Any, *button\width, *button\height)
StartDrawing(ImageOutput(image))
DrawingMode(#PB_2DDrawing_Transparent)
; Background
Box(0, 0, *button\width, *button\height, color)
; Text
If *button\font <> 0
DrawingFont(*button\font)
EndIf
FrontColor(GetSysColor_(#COLOR_BTNTEXT))
DrawText((*button\width - TextWidth(*button\text)) / 2, (*button\height - TextHeight(*button\text)) / 2, *button\text)
StopDrawing()
SetGadgetAttribute(*button\gadget, #PB_Button_Image, ImageID(image))
EndProcedure
Procedure Enable(*button.button)
SetGadgetState(*button\gadget, #True)
Redraw(*button)
EndProcedure
Procedure ColorDark(*button.button)
*button\color = RGB(0, 150, 0)
Redraw(*button)
EndProcedure
Procedure ColorNormal(*button.button)
*button\color = RGB(0, 255, 0)
Redraw(*button)
EndProcedure
Procedure Disable(*button.button)
SetGadgetState(*button\gadget, #False)
Redraw(*button)
EndProcedure
Procedure GetGadgetID(*button.button)
ProcedureReturn *button\gadget
EndProcedure
Procedure SetText(*button.button, text.s, font = 0)
*button\text = text
If font <> 0
*button\font = font
EndIf
Redraw(*button)
EndProcedure
Procedure.s GetText(*button.button)
ProcedureReturn *button\text
EndProcedure
Procedure SetFont(*button.button, font)
*button\font = font
Redraw(*button)
EndProcedure
Procedure GetButton(gadget)
ProcedureReturn Gadget2BevelButton(Str(gadget))
EndProcedure
Procedure GetState(*button.button)
ProcedureReturn GetGadgetState(*button\gadget)
EndProcedure
Procedure SetState(*button.button, state)
If state = #True
Enable(*button)
Else
Disable(*button)
EndIf
EndProcedure
Procedure Hide(*button.button)
HideGadget(*button\gadget, 1)
Redraw(*button)
EndProcedure
Procedure Show(*button.button)
HideGadget(*button\gadget, 0)
Redraw(*button)
EndProcedure
Procedure Clickable(*button.button, status)
If status = *button\clickable
ProcedureReturn
EndIf
x = GadgetX(*button\gadget)
y = GadgetY(*button\gadget)
visible = IsWindowVisible_(GadgetID(*button\gadget))
DeleteMapElement(Gadget2BevelButton(), Str(*button\gadget))
FreeGadget(*button\gadget)
; Draw disabled button or BevelButton
If status
*button\gadget = ButtonImageGadget(#PB_Any, x, y, *button\width, *button\height, 0, *button\flags)
Else
*button\gadget = ButtonGadget(#PB_Any, x, y, *button\width, *button\height, *button\text, *button\flags)
If *button\font <> 0
SetGadgetFont(*button\gadget, *button\font)
EndIf
DisableGadget(*button\gadget, #True)
EndIf
Gadget2BevelButton(Str(*button\gadget)) = *button
*button\clickable = status
; Hide or Show
If visible
Show(*button)
Else
Hide(*button)
EndIf
; Redraw
Redraw(*button)
EndProcedure
EndModule