@@ -19,22 +19,20 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
1919This widget is a push button that dispatches mouse events to its script object.
2020This widget has three properties that can be set: theme; buttonStyle and label.
2121*/
22-
22+
2323-- declaring the extension as a widget, followed by the identifier
2424widget com.livecode.extensions.livecode.button
2525--
2626
27- -- adding metadata to ensure the extension displays correctly in livecode
28- metadata author is "LiveCode"
29- metadata version is "1.0.2"
30- metadata title is "Cross Platform Button"
31- --
32-
3327-- dependancy declarations
3428use com.livecode.canvas
3529use com.livecode.widget
3630use com.livecode.engine
37- --
31+
32+ -- metadata
33+ metadata author is "LiveCode"
34+ metadata version is "1.0.2"
35+ metadata title is "Cross Platform Button"
3836
3937-- property declarations
4038property theme get mTheme set setTheme
@@ -56,9 +54,7 @@ constant kWhite is [1,1,1]
5654constant kBlack is [0,0,0]
5755--
5856
59- ----------
60- -- this handler is called when the widget is saved
61- public handler OnSave(out rProperties as array)
57+ public handler OnSave(out rProperties as Array)
6258 put the empty array into rProperties
6359
6460 put mTheme into rProperties["theme"]
@@ -67,29 +63,20 @@ public handler OnSave(out rProperties as array)
6763
6864 return rProperties
6965end handler
70- ----------
7166
72- ----------
73- -- this handler is called when the widget is loaded
74- public handler OnLoad(in pProperties as array)
67+ public handler OnLoad(in pProperties as Array)
7568 put pProperties["theme"] into mTheme
7669 put pProperties["buttonstyle"] into mStyle
7770 put pProperties["label"] into mLabel
7871end handler
79- ----------
8072
81- ----------
82- -- this handler is called when the widget is created
8373public handler OnCreate() as undefined
8474 put "ios-8" into mTheme
8575 put "Button" into mLabel
8676 put "default" into mStyle
8777 put "none" into mState
8878end handler
89- ----------
9079
91- ----------
92- -- this handler is called whenever the widget is drawn
9380public handler OnPaint() as undefined
9481
9582 // Draw the shadow
@@ -111,10 +98,7 @@ public handler OnPaint() as undefined
11198 set the paint of this canvas to getPaint_TextFill()
11299 fill text mLabel at center of my bounds on this canvas
113100end handler
114- ----------
115101
116- ----------
117- -- the following handlers are for mouse actions
118102public handler OnMouseDown() as undefined
119103 put "pressed" into mState
120104 redraw all
@@ -140,18 +124,12 @@ public handler OnMouseLeave() as undefined
140124 redraw all
141125 end if
142126end handler
143- ----------
144127
145- ----------
146- -- this handler returns the stroke width
147- private handler getStrokeWidth() as integer
128+ private handler getStrokeWidth() as Integer
148129 return 1
149130end handler
150- ----------
151131
152- ----------
153- -- this handler returns the corner radius
154- private handler getCornerRadius() as integer
132+ private handler getCornerRadius() as Integer
155133 if mTheme is "ios-8" then
156134 return 9
157135 else if mTheme is "macos-10.10" then
@@ -160,22 +138,16 @@ private handler getCornerRadius() as integer
160138
161139 return 10
162140end handler
163- ----------
164141
165- ----------
166- -- this handler returns a font name as a string
167- private handler getFontName() as string
142+ private handler getFontName() as String
168143 if mTheme is "ios-8" then
169144 return "Helvetica Neue"
170145 end if
171146
172147 return the name of the font of this canvas
173148end handler
174- ----------
175149
176- ----------
177- -- this handler returns the font size
178- private handler getFontSize() as integer
150+ private handler getFontSize() as Integer
179151 if mTheme is "ios-8" then
180152 if my height >= kMaxHeight then
181153 return 42
@@ -188,10 +160,7 @@ private handler getFontSize() as integer
188160
189161 return 11
190162end handler
191- ----------
192163
193- ----------
194- -- this handler returns a paint for the background fill
195164private handler getPaint_BackgroundFill() as Paint
196165 if mTheme is "ios-8" then
197166 if mState is "pressed" then
@@ -201,7 +170,7 @@ private handler getPaint_BackgroundFill() as Paint
201170 end if
202171
203172 else if mTheme is "macos-10.10" then
204- variable tStops as list
173+ variable tStops as List
205174 if mStyle is "default" and mState is "pressed" then
206175 put [ gradient stop at 0.0 with color [76/255,150/255,252/255], gradient stop at 1.0 with color [16/255,103/255,227/255] ] into tStops
207176 else if mStyle is "default" then
@@ -224,15 +193,12 @@ private handler getPaint_BackgroundFill() as Paint
224193
225194 return solid paint with color kWhite
226195end handler
227- ----------
228196
229- ----------
230- -- this handler returns a paint for the background stroke
231197private handler getPaint_BackgroundStrokeFill() as Paint
232198 if mTheme is "ios-8" then
233199 return solid paint with color kWhite
234200 else if mTheme is "macos-10.10" then
235- variable tStops as list
201+ variable tStops as List
236202 if mStyle is "default" and mState is "pressed" then
237203 put [ gradient stop at 0.0 with color [40/255,125/255,253/255], gradient stop at 1.0 with color [8/255,63/255,220/255] ] into tStops
238204 else if mStyle is "default" then
@@ -255,10 +221,7 @@ private handler getPaint_BackgroundStrokeFill() as Paint
255221
256222 return solid paint with color kWhite
257223end handler
258- ----------
259224
260- ----------
261- -- this handler returns a paint for the text
262225private handler getPaint_TextFill() as Paint
263226 if mTheme is "ios-8" then
264227 return solid paint with color [51/255,153/255,1]
@@ -275,63 +238,22 @@ private handler getPaint_TextFill() as Paint
275238
276239 return solid paint with color kBlack
277240end handler
278- ----------
279-
280- ----------
281- -- this handler sets the theme of the button
282-
283- /*
284- Summary: Sets the theme of the button
285241
286- Parameters:
287- pThemeName: The name of the theme.
288-
289- Description:
290- Sets the theme property of the button to either "macos-10" or "ios-8".
291- */
292-
293- public handler setTheme(in pThemeName as string) as undefined
242+ public handler setTheme(in pThemeName as String) as undefined
294243 put pThemeName into mTheme
295244 redraw all
296245end handler
297- ----------
298246
299- /*
300- Summary: Sets the label of the button
301-
302- Parameters:
303- pLabel: The text of the label.
304-
305- Description:
306- Sets the text of the label property to any string.
307- */
308-
309- ----------
310- -- this handler sets the label of the button
311- private handler setLabel(in pLabel as string) as undefined
247+ private handler setLabel(in pLabel as String) as undefined
312248 put pLabel into mLabel
313249 redraw all
314250end handler
315- ----------
316-
317- /*
318- Summary: Sets the style of the button
319-
320- Parameters:
321- pStyle: The name of the style.
322-
323- Description:
324- Sets the style property of the button to either "standard" or "default".
325- */
326251
327- ----------
328- -- this handler sets the style of the button
329- private handler setStyle(in pStyle as string) as undefined
252+ private handler setStyle(in pStyle as String) as undefined
330253 if pStyle is in ["standard","default"] then
331254 put pStyle into mStyle
332255 redraw all
333256 end if
334257end handler
335- ----------
336258
337259end widget
0 commit comments