This repository was archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 220
Expand file tree
/
Copy pathtile.lcb
More file actions
314 lines (244 loc) · 7.7 KB
/
Copy pathtile.lcb
File metadata and controls
314 lines (244 loc) · 7.7 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
/*
Copyright (C) 2018 LiveCode Ltd.
This file is part of LiveCode.
LiveCode is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License v3 as published by the Free
Software Foundation.
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
/**
A tile widget with icon and label
Name: mouseUp
Summary: Sent when the tile is clicked
Syntax: mouseUp
Type: message
Name: mouseEnter
Summary: Sent when the mouse enters the tile
Syntax: mouseEnter
Type: message
Name: mouseLeave
Summary: Sent when the mouse leaves the tile
Syntax: mouseLeave
Type: message
*/
widget com.livecode.widget.tile
use com.livecode.canvas
use com.livecode.widget
use com.livecode.engine
use com.livecode.library.iconsvg
use com.livecode.library.widgetutils
metadata title is "Tile"
metadata author is "LiveCode"
metadata version is "1.0.0"
metadata preferredSize is "200,200"
metadata userVisible is "false"
metadata _ide is "true"
metadata sourceColor.editor is "com.livecode.pi.color"
metadata sourceColor.default is "blue"
metadata tileLabel.editor is "com.livecode.pi.string"
metadata tileLabel.default is "Label"
metadata colorStep.editor is "com.livecode.pi.string"
metadata colorStep.default is "0"
// Properties
/**
The label to display
Syntax:
set the titleLabel of <widget> to <pLabel>
get the titleLabel of <widget>
Value:
The label string
*/
property tileLabel get mTileLabel set setTileLabel
/**
The name of the icon to display
Syntax:
set the iconName of <widget> to <pName>
get the iconName of <widget>
Value:
The icon name
*/
property iconName get mIconName set setIconName
/**
The name of the icon to display when hovering over the tile
Syntax:
set the hoverIconName of <widget> to <pName>
get the hoverIconName of <widget>
Value:
The icon name
*/
property hoverIconName get mHoverIconName set setHoverIconName
/**
The hover state of the tile
Syntax:
set the hoverState of <widget> to { true | false }
get the hoverState of <widget>
*/
property hoverState get mHover set setHover
/**
The foreground color of the tile
Syntax:
set the fgColor of <widget> to <pColor>
get the fgColor of <widget>
Value:
A color in RGB form - comma separated values from 0 - 255
*/
property fgColor get mForegroundColor set setForegroundColor
/**
The foreground hover color of the tile
Syntax:
set the fgHoverColor of <widget> to <pColor>
get the fgHoverColor of <widget>
Value:
A color in RGB form - comma separated values from 0 - 255
*/
property fgHoverColor get mForegroundHoverColor set setForegroundHoverColor
/**
The background color of the tile
Syntax:
set the bgColor of <widget> to <pColor>
get the bgColor of <widget>
Value:
A color in RGB form - comma separated values from 0 - 255
*/
property bgColor get mBackgroundColor set setBackgroundColor
/**
The background hover color of the tile
Syntax:
set the bgHoverColor of <widget> to <pColor>
get the bgHoverColor of <widget>
Value:
A color in RGB form - comma separated values from 0 - 255
*/
property bgHoverColor get mBackgroundHoverColor set setBackgroundHoverColor
//Local variables
private variable mTileLabel as String
private variable mIconName as String
private variable mIconPath as String
private variable mHoverIconName as String
private variable mHoverIconPath as String
private variable mHover as Boolean
private variable mForegroundColor as Color
private variable mForegroundHoverColor as Color
private variable mBackgroundColor as Color
private variable mBackgroundHoverColor as Color
public handler onCreate()
put "Label" into mTileLabel
put false into mHover
put "star" into mIconName
put "sun" into mHoverIconName
put iconSVGPathFromName(mIconName) into mIconPath
put iconSVGPathFromName(mHoverIconName) into mHoverIconPath
put color [1,1,1] into mForegroundColor
put color [0,0,0] into mForegroundHoverColor
put color [0,0,1] into mBackgroundColor
put color [1,1,1] into mBackgroundHoverColor
end handler
public handler OnPaint()
variable tHeight as Real
variable tWidth as Real
put my width into tWidth
put my height into tHeight
// Tile
variable tSquarePath as Path
variable tBounds as Rectangle
put rectangle path of rectangle [0, 0, tWidth, tHeight] into tSquarePath
if mHover is true then
set the paint of this canvas to solid paint with mBackgroundHoverColor
else
set the paint of this canvas to solid paint with mBackgroundColor
end if
fill tSquarePath on this canvas
//Label
if mHover is true then
set the paint of this canvas to solid paint with mForegroundHoverColor
else
set the paint of this canvas to solid paint with mForegroundColor
end if
fill text mTileLabel at center of rectangle [0, (tHeight*0.7)-5, tWidth, tHeight-5] on this canvas
variable tTextBounds as Rectangle
variable tTextHeight
variable tTextTop
variable tTextGap
measure mTileLabel on this canvas
put the result into tTextBounds
put the height of tTextBounds into tTextHeight
put ((tHeight*0.3) - (tTextHeight))/2 into tTextGap
put (tHeight*0.7) + (tTextGap) into tTextTop
//Icon
variable tIconPath as Path
if mHover is true then
set the paint of this canvas to solid paint with mForegroundHoverColor
put path mHoverIconPath into tIconPath
else
set the paint of this canvas to solid paint with mForegroundColor
put path mIconPath into tIconPath
end if
variable tIconBounds as Rectangle
variable tIconSpace
put the minimum of (tHeight*0.4) and (tWidth*0.4) into tIconSpace
put rectangle [0, 0, tIconSpace, tIconSpace] into tIconBounds
constrainPathToRect(tIconBounds, tIconPath)
variable tIconWidth
variable tIconHeight
variable tIconX
variable tIconY
put the bounding box of tIconPath into tBounds
put the width of tBounds into tIconWidth
put the height of tBounds into tIconHeight
put the left of tBounds into tIconX
put the top of tBounds into tIconY
translate tIconPath by [(tWidth - tIconWidth)/2 - tIconx, ((tTextTop)-tIconHeight)/2 - tIconY]
fill tIconPath on this canvas
end handler
public handler setTileLabel(in pLabel as String) returns nothing
put pLabel into mTileLabel
redraw all
end handler
public handler OnMouseUp()
post "mouseUp"
end handler
public handler OnMouseEnter()
put true into mHover
post "mouseEnter"
redraw all
end handler
public handler OnMouseLeave()
put false into mHover
post "mouseLeave"
redraw all
end handler
public handler setIconName(in pName as String) returns nothing
put iconSVGPathFromName(pName) into mIconPath
put pName into mIconName
redraw all
end handler
public handler setHoverIconName(in pName as String) returns nothing
put iconSVGPathFromName(pName) into mHoverIconPath
put pName into mHoverIconName
redraw all
end handler
public handler setForegroundColor(in pColor as String) returns nothing
put stringToColor(pColor) into mForegroundColor
redraw all
end handler
public handler setForegroundHoverColor(in pColor as String) returns nothing
put stringToColor(pColor) into mForegroundHoverColor
redraw all
end handler
public handler setBackgroundColor(in pColor as String) returns nothing
put stringToColor(pColor) into mBackgroundColor
redraw all
end handler
public handler setBackgroundHoverColor(in pColor as String) returns nothing
put stringToColor(pColor) into mBackgroundHoverColor
redraw all
end handler
public handler setHover(in pValue as Boolean) returns nothing
put pValue into mHover
redraw all
end handler
end widget