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 223
Expand file tree
/
Copy pathwidget-utils.lcb
More file actions
388 lines (300 loc) · 20.5 KB
/
Copy pathwidget-utils.lcb
File metadata and controls
388 lines (300 loc) · 20.5 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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
/*
Copyright (C) 2015 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 library of utility handlers for functions commonly needed by widgets.
*/
module com.livecode.library.widgetutils
use com.livecode.canvas
use com.livecode.engine
metadata version is "1.0.0"
metadata author is "LiveCode"
metadata title is "Widget Utilities"
/**
Summary: Scales and translates a path to fit within a rectangle
Parameters:
pTargetRect: The rectangle to fit the path within
xPath: The path to transform
Example:
use com.livecode.library.iconsvg
public handler OnPaint() returns nothing
-- get the 'shopping cart' icon from the icon library
variable tPathString as String
put iconSVGPathFromName("shopping cart") into tPathString
-- create the path
variable tPath as Path
put path tPathString into tPath
-- scale the path to fit within the bounds of the widget
constrainPathToRect(my bounds, tPath)
-- fill the path
fill tPath on this canvas
end handler
Description:
Scales and transforms <xPath> so that it fits within <pTargetRect> whilst maintaining its
aspect ratio.
*/
public handler constrainPathToRect(in pTargetRect as Rectangle, inout xPath as Path)
// Scale the icon
variable tBounds
put the bounding box of xPath into tBounds
// Scale appropriately
variable tXScale as Real
variable tYScale as Real
put the width of pTargetRect / the width of tBounds into tXScale
put the height of pTargetRect / the height of tBounds into tYScale
if tXScale > tYScale then
put tYScale into tXScale
else
put tXScale into tYScale
end if
scale xPath by [tXScale, tYScale]
variable tXTranslate as Real
variable tYTranslate as Real
put the bounding box of xPath into tBounds
put the left of pTargetRect - the left of tBounds into tXTranslate
put the top of pTargetRect - the top of tBounds into tYTranslate
variable tXDiff as Real
variable tYDiff as Real
put the width of pTargetRect - the width of tBounds into tXDiff
put the height of pTargetRect - the height of tBounds into tYDiff
// align center
divide tXDiff by 2
divide tYDiff by 2
translate xPath by [tXTranslate + tXDiff, tYTranslate + tYDiff]
end handler
/**
Summary: Formats an integer as a string
Parameters:
pNumber: The integer to format
Example:
log 5 formatted as string -- logs 5.000000
log intToString(5) -- logs 5
Description:
<intToString> formats an integer as a string, removing the decimal place and any zeros
thereafter.
*/
public handler intToString(in pNumber as Number) returns String
variable tFormatted as String
put pNumber formatted as string into tFormatted
variable tDotIndex as Number
put the index of "." in tFormatted into tDotIndex
if tDotIndex is 0 then
return tFormatted
end if
return char 1 to tDotIndex - 1 of tFormatted
end handler
/**
Summary: Removes any superfluous zeros and decimal places.
Parameters:
pString: The string to remove zeros from
Example:
log stripZeros("5.0000000") -- logs 5
log stripZeros("5.432100") -- logs 5.4321
Description:
Use <stripZeros> to remove any superfluous zeros and decimal places from <pString>
which have been added by the
`tNumber formatted as string`
syntax.
*/
public handler stripZeros(in pString as String) returns String
if "." is in pString then
repeat while ((the last char of pString) is in ".0")
if the last char of pString is "." then
delete the last char of pString
exit repeat
else
delete the last char of pString
end if
end repeat
end if
return pString
end handler
private handler colorComponentToString(in pComponent as Number)
return intToString(the rounded of (pComponent * 255))
end handler
/**
Summary: Converts a color to a string representing the color
Parameters:
pColor: A value of type com.livecode.canvas.Color
pIncludeAlpha: Whether to include the alpha value in the string or not
Example:
property widgetColor get getColor
metadata widgetColor.editor is "com.livecode.pi.colorwithalpha"
private variable mColor as Color
public handler OnSave(out rProperties as Array)
put colorToString(mColor, true) into rProperties["color with alpha"]
end handler
public handler getColor() returns String
-- the editor used for the widgetColor property expects the alpha value to be included
return colorToString(mColor, true)
end handler
Example:
log colorToString(color [0.4,0.4,0.4,0.4]) -- logs "102,102,102,102"
Description:
Use the <colorToString> handler when logging colors, returning them to LiveCode script
via a property getter, or serialising them in the widget's stored properties array for saving.
*/
public handler colorToString(in pColor as Color, in pIncludeAlpha as Boolean) returns String
variable tComponents as List
variable tString as String
put [] into tComponents
push colorComponentToString(the red of pColor) onto tComponents
push colorComponentToString(the green of pColor) onto tComponents
push colorComponentToString(the blue of pColor) onto tComponents
if pIncludeAlpha then
push colorComponentToString(the alpha of pColor) onto tComponents
end if
combine tComponents with "," into tString
return tString
end handler
private handler stringToColorComponent(in pComponent as String)
return (pComponent parsed as number) / 255
end handler
/**
Summary: Converts a string to a color
Parameters:
pString: A comma delimited string representing a color in RGB / RGBA format
Example:
property widgetColor get getColor set setColor
metadata widgetColor.editor is "com.livecode.pi.colorwithalpha"
private variable mColor as Color
public handler OnLoad(in pProperties as Array)
setColor(pProperties["color"])
end handler
public handler setColor(in pColor as String)
put stringToColor(pColor) into mColor
redraw all
end handler
Description:
Use the <stringToColor> handler when receiving colors from LiveCode script
via a property setter, or from the widget's stored properties array when loading.
*/
public handler stringToColor(in pString as String) returns Color
variable tComponentList as List
split pString by "," into tComponentList
variable tColor as List
put [] into tColor
variable tColorComponent as String
repeat for each element tColorComponent in tComponentList
push stringToColorComponent(tColorComponent) onto tColor
end repeat
return color tColor
end handler
/**
Summary: Get the canonical name of the current "native" mobile theme
Example:
variable tNativeTheme as String
put getNativeThemeName() into tNativeTheme
if tNativeTheme is "android" then
-- Draw Android themed UI
else
-- Draw iOS themed UI
end if
Description:
Returns the name of the current theme that should be used when the theme is
"native".
Currently, this will return either "iOS" or "Android".
*/
public handler getNativeThemeName() returns String
variable tOS as String
put the operating system into tOS
if tOS is in ["ios","mac"] then
return "iOS"
else
return "Android"
end if
end handler
constant kWidgetUtilsPlaceholderIcons is { \
"mac": "M14.926,0.656H1.067C0.478,0.656,0,1.137,0,1.73v9.844c0,0.594,0.478,1.074,1.067,1.074h5.316 c0,0-0.934,2.149-3.493,2.149v0.537h1.88h4.568h3.493v-0.537c-2.631,0-3.226-2.149-3.226-2.149h5.32 c0.588,0,1.065-0.48,1.065-1.074V1.73C15.992,1.137,15.514,0.656,14.926,0.656z M7.996,12.427c-0.331,0-0.599-0.268-0.599-0.599 c0-0.33,0.268-0.598,0.599-0.598c0.33,0,0.599,0.268,0.599,0.598C8.594,12.159,8.326,12.427,7.996,12.427z M14.849,10.906H1.143 V1.798H14.85L14.849,10.906L14.849,10.906zM6.824,9.133c0.393-0.016,0.542-0.255,1.017-0.255c0.476,0,0.609,0.255,1.024,0.247 C9.288,9.117,9.556,8.74,9.814,8.363c0.3-0.438,0.423-0.862,0.431-0.883c-0.01-0.005-0.824-0.317-0.833-1.255 c-0.008-0.786,0.642-1.163,0.67-1.182C9.718,4.51,9.149,4.437,8.947,4.429C8.465,4.38,8.005,4.713,7.759,4.713 c-0.244,0-0.623-0.277-1.023-0.27C6.209,4.451,5.724,4.75,5.452,5.221c-0.547,0.95-0.14,2.356,0.393,3.127 C6.105,8.725,6.416,9.148,6.824,9.133z M8.953,2.928c-0.312,0.013-0.689,0.208-0.914,0.47c-0.2,0.233-0.376,0.604-0.329,0.96 c0.349,0.027,0.704-0.177,0.921-0.439C8.847,3.656,8.993,3.292,8.953,2.928z", \
"ios": "M4.621 6.965c0 1.368-.833 2.38-2.262 2.38-1.19 0-2.083-1.012-2.083-2.38 0-1.31.952-2.381 2.202-2.381 1.31 0 2.143 1.071 2.143 2.381zM1.327 78.5V23.78H3.57V78.5H1.327zM78.174 39.512c0 27.588-15.315 40.129-32.079 40.129-17.125 0-30.993-13.565-30.993-38.988C15.102 14.549 29.453.526 47.301.526 64.787.524 78.174 14.318 78.174 39.512zm-60.799.57C17.375 61 27.513 77.25 46.201 77.25c18.818 0 29.611-16.75 29.611-37.406 0-19.155-8.648-36.636-28.382-36.636S17.375 19.667 17.375 40.082zM86.406 72.571c3.763 2.508 10.258 4.93 15.844 4.93 10.602 0 20.031-7.417 20.031-18.334 0-10.131-6.281-15.417-16.945-19.958-9.544-4.064-18.125-8.475-18.125-19.305 0-11.285 8.891-19.267 20.975-19.267 6.498 0 11.4 1.824 13.68 3.42l-.906 1.968c-1.938-1.367-7.176-3.109-12.874-3.109-12.771 0-18.334 9.65-18.334 16.754 0 9.812 7.606 13.093 17.41 17.767 11.399 5.585 17.44 10.51 17.44 21.227 0 11.514-8.207 20.86-22.799 20.86-6.043 0-12.996-2.051-16.416-4.674l1.019-2.279z", \
"android": "M493 615Q509 615 520.5 603.5 532 592 532 576 532 560 520.5 548.5 509 537 493 537 477 537 466 548.5 455 560 455 576 455 592 466 603.5 477 615 493 615ZM915 615Q931 615 942 603.5 953 592 953 576 953 560 942 548.5 931 537 915 537 899 537 887.5 548.5 876 560 876 576 876 592 887.5 603.5 899 615 915 615ZM103 799Q145 799 175 829 205 859 205 901L205 1331Q205 1374 175.5 1404 146 1434 103 1434 60 1434 30 1404 0 1374 0 1331L0 901Q0 859 30 829 60 799 103 799ZM1163 818L1163 1484Q1163 1530 1131 1562 1099 1594 1054 1594L979 1594 979 1821Q979 1864 949 1894 919 1924 876 1924 833 1924 803 1894 773 1864 773 1821L773 1594 635 1594 635 1821Q635 1864 605 1894 575 1924 532 1924 490 1924 460 1894 430 1864 430 1821L429 1594 355 1594Q309 1594 277 1562 245 1530 245 1484L245 818 1163 818ZM931 413Q1038 468 1102 566.5 1166 665 1166 782L241 782Q241 665 305 566.5 369 468 477 413L406 282Q399 269 411 262 424 256 431 268L503 400Q598 358 704 358 810 358 905 400L977 268Q984 256 997 262 1009 269 1002 282ZM1408 901L1408 1331Q1408 1374 1378 1404 1348 1434 1305 1434 1263 1434 1233 1404 1203 1374 1203 1331L1203 901Q1203 858 1233 828.5 1263 799 1305 799 1348 799 1378 828.5 1408 858 1408 901Z", \
"windows": "M682 1134L682 1785 0 1691 0 1134 682 1134ZM682 391L682 1050 0 1050 0 485ZM1664 1134L1664 1920 757 1795 757 1134 1664 1134ZM1664 256L1664 1050 757 1050 757 381Z", \
"linux": "M663 671Q652 672 647.5 681.5 643 691 639 691 634 692 634 686 634 674 653 671L663 671ZM750 685Q746 686 738.5 678.5 731 671 721 674 745 663 753 676 756 682 750 685ZM399 1112Q395 1111 393 1115 391 1119 388.5 1127.5 386 1136 383 1141 380 1146 373 1154 366 1164 372 1166 376 1167 384.5 1159 393 1151 397 1141 398 1138 399 1134 400 1130 401 1128 402 1126 402.5 1123.5 403 1121 403 1119.5L403 1116.5Q402 1114 402 1114 402 1114 399 1112ZM1254 1471Q1254 1453 1199 1429 1203 1414 1206.5 1401.5 1210 1389 1211.5 1375.5 1213 1362 1214.5 1354 1216 1346 1215 1331.5 1214 1317 1214 1312 1214 1307 1210.5 1290 1207 1273 1206.5 1269.5 1206 1266 1201.5 1244.5 1197 1223 1196 1218 1186 1170 1149 1115 1112 1060 1077 1040 1101 1060 1134 1123 1221 1285 1188 1401 1177 1441 1138 1443 1107 1447 1099.5 1424.5 1092 1402 1091.5 1341 1091 1280 1080 1234 1071 1195 1060.5 1165 1050 1135 1041 1119.5 1032 1104 1025.5 1095 1019 1086 1012.5 1080 1006 1074 1005 1073 991 1011 974 970 957 929 944.5 914 932 899 921 881 910 863 906 841 902 820 912 787.5 922 755 916.5 738 911 721 872 713 857 710 827.5 695 798 680 792 679 784 678 781 653 778 628 789 602 800 576 825 575 862 572 876 605 890 638 880 663 869 682 878 689.5 887 697 908 690 921 686 921 654L921 617Q916 587 907.5 567 899 547 886.5 536.5 874 526 863 521.5 852 517 836 514 729 522 747 648 747 663 746 663 737 654 716.5 652.5 696 651 683.5 653 671 655 668 648 669 591 652 558 635 525 607 524 580 523 565.5 551.5 551 580 549 611 548 626 552.5 648 557 670 565.5 685.5 574 701 581 699 591 696 597 685 601 676 590 677 583 677 574.5 662.5 566 648 565 629 564 607 574 592 584 577 608 578 625 578 635 599 645 620 644.5 638 644 656 643 660 621 675 612 689 604 701 584.5 712.5 565 724 564 725 551 739 548.5 752 546 765 556 770 570 778 581 789.5 592 801 597 808.5 602 816 615.5 821.5 629 827 651 828 698 830 753 813 755 812 776 806 797 800 810.5 795.5 824 791 840 782.5 856 774 861 765 870 751 881 757 886 760 887.5 765.5 889 771 884.5 777.5 880 784 868 787 848 793 811.5 808.5 775 824 766 828 722 847 696 851 671 856 617 849 607 847 608 851 609 855 625 870 650 893 692 892 709 891 728 885 747 879 764 871 781 863 797.5 853.5 814 844 827.5 836.5 841 829 852 824.5 863 820 869.5 822 876 824 878 833 878 835 877 837.5 876 840 873 842.5 870 845 867 847 864 849 858.5 852 853 855 849.5 856.5 846 858 839.5 861.5 833 865 830 866 802 880 762.5 910 723 940 696 953 669 966 647 954 626 943 584 881 562 850 559 859 558 862 558 869 558 894 543 925.5 528 957 513.5 981 499 1005 492.5 1039 486 1073 504 1102 481 1108 441.5 1192 402 1276 394 1333 392 1351 392.5 1402 393 1453 387 1461 379 1485 358 1464 326 1433 322 1370 320 1342 326 1314 330 1295 325 1296L321 1301Q285 1366 331 1467 336 1479 356 1495 376 1511 380 1515 400 1538 484 1605.5 568 1673 577 1682 593 1697 594.5 1720 596 1743 580.5 1763 565 1783 535 1786 543 1801 564 1830.5 585 1860 592 1884.5 599 1909 599 1955 645 1931 606 1863 602 1855 595.5 1847 589 1839 586 1835 583 1831 584 1829 587 1824 597 1819.5 607 1815 617 1822 663 1874 783 1858 916 1843 960 1771 983 1733 994 1741 1006 1747 1004 1793 1003 1818 981 1885 972 1908 975 1922.5 978 1937 999 1938 1002 1919 1013.5 1861 1025 1803 1027 1771 1029 1750 1020.5 1697.5 1012 1645 1013 1600.5 1014 1556 1036 1530 1051 1512 1087 1512 1088 1475 1121.5 1459 1155 1443 1194 1448.5 1233 1454 1254 1471ZM626 644Q629 627 623.5 614 618 601 612 599 603 597 603 606 605 611 608 612 618 612 615 627 612 647 623 647 626 647 626 644ZM1045 841Q1043 833 1038.5 829.5 1034 826 1025.5 824.5 1017 823 1011 819 1006 816 1001.5 811 997 806 994.5 803 992 800 989 796.5 986 793 985 792.5 984 792 981 794 967 810 988 837.5 1009 865 1027 869 1036 870 1041.5 861 1047 852 1045 841ZM867 628Q867 617 862 608.5 857 600 851 596 845 592 842 593 828 594 835 600L839 602Q853 606 857 633 857 636 865 631ZM921 395Q921 393 918.5 390 916 387 909.5 383 903 379 900 377 885 362 876 362 867 363 864.5 369.5 862 376 863.5 382.5 865 389 863 395 862 399 857 405.5 852 412 851 414.5 850 417 854 423 858 426 862 423 866 420 873 414 880 408 888 405 889 404 897 404 905 404 912 402 919 400 921 395ZM1486 1736Q1506 1748 1517 1760.5 1528 1773 1529 1784.5 1530 1796 1526.5 1807 1523 1818 1511 1829 1499 1840 1487.5 1848.5 1476 1857 1457.5 1867 1439 1877 1426 1883.5 1413 1890 1394 1899 1375 1908 1367 1912 1329 1931 1281.5 1968 1234 2005 1206 2032 1189 2048 1138 2051.5 1087 2055 1049 2037 1031 2028 1019.5 2013.5 1008 1999 1003 1988 998 1977 981 1968.5 964 1960 934 1959 890 1958 804 1958 785 1958 747 1959.5 709 1961 689 1962 645 1963 609.5 1977 574 1991 556 2007 538 2023 512.5 2035.5 487 2048 459 2047 430 2046 348 2016 266 1986 202 1973 183 1969 151 1963.5 119 1958 101 1954.5 83 1951 61.5 1945 40 1939 28 1930.5 16 1922 11 1911 1 1888 18 1844.5 35 1801 36 1790 37 1774 32 1750 27 1726 22 1707.5 17 1689 17.5 1671 18 1653 28 1644 42 1632 85 1630 128 1628 145 1618 175 1600 187 1583 199 1566 199 1532 220 1605 167 1638 135 1658 84 1653 50 1650 41 1663 28 1678 46 1720 48 1726 54 1738 60 1750 62.5 1756 65 1762 67 1773 69 1784 68 1795 68 1810 51 1844 34 1878 37 1892 40 1909 74 1918 94 1924 158.5 1936.5 223 1949 258 1957 282 1963 332 1979 382 1995 414.5 2002 447 2009 470 2006 513 2000 534.5 1978 556 1956 557.5 1930 559 1904 550 1871.5 541 1839 531 1819.5 521 1800 511 1783 390 1593 342 1541 274 1467 229 1501 218 1510 214 1486 211 1470 212 1448 213 1419 222 1396 231 1373 246 1349 261 1325 268 1307 276 1286 294.5 1235 313 1184 324 1157 335 1130 354 1096 373 1062 393 1042 503 899 517 847 505 735 501 537 499 447 525 385.5 551 324 631 281 670 260 735 260 788 259 841 273.5 894 288 930 315 987 357 1021.5 436.5 1056 516 1051 584 1046 679 1081 798 1115 911 1214 1016 1269 1075 1313.5 1179 1358 1283 1373 1370 1381 1419 1378 1454.5 1375 1490 1366 1510 1357 1530 1346 1532 1336 1534 1322.5 1551 1309 1568 1295.5 1586.5 1282 1605 1255 1620 1228 1635 1194 1634 1176 1633 1162.5 1629 1149 1625 1140 1615.5 1131 1606 1126.5 1600 1122 1594 1115 1579.5 1108 1565 1106 1560 1084 1523 1065 1530 1046 1537 1037 1579 1028 1621 1044 1676 1064 1746 1045 1871 1035 1936 1063 1971.5 1091 2007 1136 2004.5 1181 2002 1221 1969 1280 1920 1310.5 1902.5 1341 1885 1414 1860 1467 1842 1491 1823.5 1515 1805 1509.5 1789 1504 1773 1484.5 1760.5 1465 1748 1433 1737 1400 1726 1383.5 1689 1367 1652 1368.5 1616.5 1370 1581 1384 1569 1385 1600 1392 1625.5 1399 1651 1406.5 1666 1414 1681 1427 1694.5 1440 1708 1448 1713.5 1456 1719 1469.5 1726.5 1483 1734 1486 1736Z", \
"emscripten": "M1130 661L1146 486 262 486 309 1020 921 1020 899 1248 702 1301 506 1248 493 1108 318 1108 340 1386 702 1486 706 1486 706 1485 1065 1386 1115 842 471 842 456 661 1130 661ZM0 192L1408 192 1280 1630 702 1792 128 1630Z" \
}
/**
Summary: Returns a placeholder icon for a given operating system
Parameters:
pOS (enum): The operating system.
- "mac"
- "ios"
- "android"
- "windows"
- "linux"
- "emscripten"
Description: Use <placeholderIcon> to fetch an SVG icon that can be
used as the placeholder image for a widget that is native to, and
therefore only available on, a given operating system.
*/
public handler placeholderIcon(in pOS as String) returns String
if pOS is not among the keys of kWidgetUtilsPlaceholderIcons then
throw "no placeholder icon for" && pOS && "operating system"
end if
return kWidgetUtilsPlaceholderIcons[pOS]
end handler
/**
Summary: Paint a placeholder image using an SVG icon and name
Parameters:
pCanvas: The canvas on which to draw the placeholder
pBounds: The rectangle in which to draw the placeholder on the canvas
pSVGIcon: The placeholder icon to use
pLabel: The label to use
pFont: A font to draw the label with. If none specified, Arial 14pt is used.
pColor: A color to draw the label with. If none specified, #404040 is used
Description:
Use the <paintPlaceHolder> image handler to draw a placeholder on the
given canvas when, for example, the widget shouldn't be displayed as
active in browse mode, or is not available on the current platform.
*/
constant kBorderWidth is 5
public handler paintPlaceholderImage(in pCanvas as Canvas, in pBounds as Rectangle, \
in pSVGIcon as String, in pLabel as String, in pFont as optional Font, \
in pColor as optional Color)
save state of pCanvas
// Draw placeholder image - the browser icon
variable tFillPaint as Paint
variable tStrokePaint as Paint
put solid paint with color [0.875, 0.875, 0.875] into tFillPaint
put solid paint with color [0.75, 0.75, 0.75] into tStrokePaint
set the paint of pCanvas to tFillPaint
fill rectangle path of pBounds on this canvas
set the paint of this canvas to tStrokePaint
set the stroke width of this canvas to kBorderWidth
set the join style of this canvas to "bevel"
stroke rectangle path of expandRectangle(pBounds, -kBorderWidth / 2) on this canvas
variable tPath as Path
put path pSVGIcon into tPath
constrainPathToRect(expandRectangle(pBounds, -2 * kBorderWidth), tPath)
fill tPath on this canvas
// Draw the control name
put solid paint with color [1, 1, 1] into tFillPaint
if pFont is nothing then
put font "Arial" at size 14 into pFont
end if
if pColor is nothing then
put color [0.25, 0.25, 0.25] into pColor
end if
put solid paint with pColor into tStrokePaint
variable tTextBounds as Rectangle
put the image bounds of text pLabel on pCanvas into tTextBounds
translate pCanvas by [ the width of pBounds / 2, the height of pBounds / 2]
translate pCanvas by [ -(the width of tTextBounds / 2), the height of tTextBounds / 2]
set the paint of pCanvas to tFillPaint
fill rounded rectangle path of expandRectangle(tTextBounds, kBorderWidth) with radius 5 on pCanvas
set the paint of pCanvas to tStrokePaint
fill text pLabel at point [0, 0] on pCanvas
restore state of pCanvas
end handler
private handler expandRectangle(in pRect as Rectangle, in pExp as Number) returns Rectangle
return rectangle [ the left of pRect - pExp, the top of pRect - pExp, the right of pRect + pExp, the bottom of pRect + pExp]
end handler
end module