-
Notifications
You must be signed in to change notification settings - Fork 0
/
bevelbutton.pb
119 lines (101 loc) · 3.15 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
; BevelButton Menu
DeclareModule BevelButton
Structure button
gadget.l
width.i
height.i
text.s
font.i
color.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)
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)
Redraw(*button)
Gadget2BevelButton(Str(*button\gadget)) = *button
ProcedureReturn *button
EndProcedure
Procedure Delete(*button.button)
FreeMemory(*button)
EndProcedure
Procedure Redraw(*button.button)
Protected color, image
; 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
EndModule