-
Notifications
You must be signed in to change notification settings - Fork 0
/
big.main.lua
1465 lines (1096 loc) · 33.3 KB
/
big.main.lua
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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
----------------------------------
-- ETK 4.0 test project --
-- --
-- (C) 2015 Jim Bauwens --
-- Licensed under the GNU GPLv3 --
----------------------------------
--------------------------------------
-- Start of extra/lua_additions.lua --
--------------------------------------
-- The following defines/macros are supposed to be used for simple cases only
-- (within simple syntax constructs that wouldn't confuse the "parser". See examples.)
--Lua variable pattern
--Lambda style!
--Indexing of strings, string:sub(index, index)
--Increment/Decrement (Note: just use that in a "standalone way", not like: print(a = a + 1) etc.)
--Compound assignment operators
------------------------------------
-- End of extra/lua_additions.lua --
------------------------------------
--------------------------
-- Start of etk/etk.lua --
--------------------------
----------------------------------
-- ETK 4.0 --
-- --
-- (C) 2015 Jim Bauwens --
-- Licensed under the GNU GPLv3 --
----------------------------------
etk = {}
do
local etk = etk
------------------------------
-- Start of etk/helpers.lua --
------------------------------
----------------------------------
-- ETK Helper Classes --
-- make stuff more easy --
-- --
-- (C) 2015 Jim Bauwens --
-- Licensed under the GNU GPLv3 --
----------------------------------
------------------
-- Enumerations --
------------------
Enum = function(enumTable)
for k,v in ipairs(enumTable) do
enumTable[v] = k
end
return enumTable
end
-------------
-- Logging --
-------------
do Logger = {}
Logger.Log = function (message, ...)
print(message:format(...))
end
Logger.Warn = function (message, ...)
Logger.Log("Warning: " .. message, ...)
end
end
-----------------------------------------------
-- Handle different types of user unit input --
-----------------------------------------------
do UnitCalculator = {}
UnitCalculator.GetAbsoluteValue = function (value, referenceValue)
local numberValue, unit = string.match(tostring(value), "([-%d.]+)(.*)")
local number = tonumber(numberValue)
if not number then
Logger.Warn("UnitCalculator.GetAbsoluteValue - Invalid number value, returning 0")
return 0
end
local isPercent = unit == "%"
if number < 0 then
print(number, "from")
number = (isPercent and 100 or referenceValue) + number
print(number, "to")
end
if isPercent then
return referenceValue / 100 * number
else
return number
end
end
end
-------------------------------------------------
-- Keep dimensions in a nice to handle wrapper --
-------------------------------------------------
do Dimension = class()
function Dimension:init(width, height)
self.width = width
self.height = height
end
function Dimension:get(parentWidth, parentHeight, dirty)
if self.width then
if dirty or not self.cachedWidth then
self.cachedWidth = UnitCalculator.GetAbsoluteValue(self.width, parentWidth)
self.cachedHeight = UnitCalculator.GetAbsoluteValue(self.height, parentHeight)
end
return self.cachedWidth, self.cachedHeight
else
self.cachedWidth = parentWidth
self.cachedHeight = parentHeight
return parentWidth, parentHeight
end
end
function Dimension:getCachedDimension()
return self.cachedWidth or 0, self.cachedHeight or 0
end
function Dimension:invalidate()
self.cachedWidth = nil
self.cachedHeight = nil
end
end
do Position = class()
Position.Type = Enum { "Absolute", "Relative" }
Position.Sides = Enum { "Left", "Right", "Top", "Bottom" }
function Position:init(arg)
arg = arg or {}
self.left = arg.left
self.top = arg.top
self.bottom = arg.bottom
self.right = arg.right
self.alignment = arg.alignment or {}
if not (self.left or self.right) then
self.left = 0
end
if not (self.top or self.bottom) then
self.top = 0
end
end
function Position:get(parentX, parentY, parentWidth, parentHeight, width, height, dirty)
if dirty or not self.cachedX then
local x, y
local originX = parentX
local originY = parentY
if self.right then
originX = originX + parentWidth
end
if self.bottom then
originY = originY + parentHeight
end
for _, alignment in ipairs(self.alignment) do
local side = alignment.side
local ref = alignment.ref
local refWidth, refHeight = ref:getDimension()
local refX, refY = ref:getPosition()
if side == Position.Sides.Left then
originX = refX
elseif side == Position.Sides.Right then
originX = refX + refWidth
elseif side == Position.Sides.Top then
originY = refY
elseif side == Position.Sides.Bottom then
originY = refY + refHeight
else
Logger.Warn("Invalid side specified")
end
end
if self.left then
x = originX + UnitCalculator.GetAbsoluteValue(self.left, parentWidth)
elseif self.right then
x = originX - UnitCalculator.GetAbsoluteValue(self.right, parentWidth) - width
end
if self.top then
y = originY + UnitCalculator.GetAbsoluteValue(self.top, parentHeight)
elseif self.bottom then
y = originY - UnitCalculator.GetAbsoluteValue(self.bottom, parentHeight) - height
end
self.cachedX = x
self.cachedY = y
end
return self.cachedX, self.cachedY
end
function Position:invalidate()
self.cachedX = nil
self.cachedY = nil
end
function Position:getCachedPosition()
return self.cachedX or 0, self.cachedY or 0
end
end
-----------
-- Color --
-----------
local function unpackColor(col)
return col[1] or 0, col[2] or 0, col[3] or 0
end
-------------------
-- Event calling --
-------------------
local CallEvent = function(object, event, ...)
local handler = object[event]
if handler then
return handler, handler(object, ...)
end
end
----------------------------
-- End of etk/helpers.lua --
----------------------------
-------------------------------
-- Start of etk/graphics.lua --
-------------------------------
----------------------------------
-- ETK Graphics --
-- Some flags and functions --
-- for painting and more --
-- --
-- (C) 2015 Jim Bauwens --
-- Licensed under the GNU GPLv3 --
----------------------------------
do
etk.graphics = {}
local eg = etk.graphics
eg.needsFullRedraw = true
eg.dimensionsChanged = true
eg.isColor = platform.isColorDisplay()
eg.viewPortWidth = 318
eg.viewPortHeight = 212
eg.areaToRedraw = {0, 0, 0, 0}
------------------------------------------------
-- Replacement for platform.window:invalidate --
------------------------------------------------
eg.invalidate = function (x, y, w, h)
platform.window:invalidate(x, y, w, h)
if x then
eg.needsFullRedraw = false
eg.areaToRedraw = {x, y, w, h}
end
end
----------------------------------------------
-- Replacement for graphicalContex:clipRect --
----------------------------------------------
local clipRectData = {}
local clipRects = 0
local gc_clipRect = function (gc, what, x, y, w, h)
if what == "set" then
clipRects = clipRects + 1
clipRectData[clipRects] = {x, y, w, h}
elseif what == "subset" and clipRects > 0 then
local old = clipRectData[clipRects]
x = old[1] < x and x or old[1]
y = old[2] < y and y or old[2]
h = old[2] + old[4] > y + h and h or old[2] + old[4] - y
w = old[1] + old[3] > x + w and w or old[1] + old[3] - x
what = "set"
clipRects = clipRects + 1
clipRectData[clipRects] = {x, y, w, h}
elseif what == "restore" and clipRects > 0 then
what = "set"
clipRectData[clipRects] = nil
clipRects = clipRects - 1
local old = clipRectData[clipRects]
x, y, w, h = old[1], old[2], old[3], old[4]
elseif what == "restore" then
what = "reset"
end
gc:clipRect(what, x, y, w, h)
end
--------------------------------------
-- platform.withGC for apiLevel < 2 --
--------------------------------------
if not platform.withGC then
platform.withGC = function (func, ...)
local gc = platform.gc()
gc:begin()
func(..., gc) -- BUG: if you have a parameter after ..., you will only select the first parameter from the list, <- func({...}[1], gc)
end
end
---------------------------------
-- Patch the Graphical Context --
---------------------------------
local addToGC = function (name, func)
local gcMeta = platform.withGC(getmetatable)
gcMeta[name] = func
end
------------------------
-- Apply some patches --
------------------------
addToGC("smartClipRect", gc_clipRect)
end
-----------------------------
-- End of etk/graphics.lua --
-----------------------------
------------------------------------
-- Start of etk/screenmanager.lua --
------------------------------------
----------------------------------
-- ETK Screenmanager --
-- stuff and stuff I guess --
-- cookies --
-- --
-- (C) 2015 Jim Bauwens --
-- Licensed under the GNU GPLv3 --
----------------------------------
do etk.RootScreen = {}
local RootScreen = etk.RootScreen
local eg = etk.graphics
local x, y = 0, 0
---------------------
-- Screen handling --
---------------------
RootScreen.screens = {}
local screens = RootScreen.screens
function RootScreen:pushScreen(screen, args)
screen:onPushed(args)
table.insert(screens, screen)
screen.parent = self
end
function RootScreen:popScreen(args)
local index = #screens
screens[index]:onPopped(args)
return table.remove(screens, index)
end
function RootScreen:peekScreen()
return screens[#screens] or RootScreen
end
----------------------------
-- Dimension and position --
----------------------------
function RootScreen:getDimension()
return eg.viewPortWidth, eg.viewPortHeight
end
function RootScreen:getPosition()
return x, y
end
-------------------
-- Draw children --
-------------------
function RootScreen:paint(gc)
for k, screen in ipairs(self.screens) do
screen:paint(gc)
end
end
----------------
-- Invalidate --
----------------
function RootScreen:invalidate()
eg.invalidate()
end
end
------------------
-- Screen class --
------------------
do etk.Screen = class()
local Screen = etk.Screen
local eg = etk.graphics
function Screen:init(position, dimension)
self.parent = parent
self.position = position
self.dimension = dimension
self.children = {}
end
--------------------------------
-- Dimension helper functions --
--------------------------------
function Screen:getDimension()
local parentWidth, parentHeight = self.parent:getDimension()
return self.dimension:get(parentWidth, parentHeight, eg.dimensionsChanged)
end
function Screen:getPosition()
local parentX, parentY = self.parent:getPosition()
local parentWidth, parentHeight = self.parent:getDimension()
local width, height = self:getDimension()
return self.position:get(parentX, parentY, parentWidth, parentHeight, width, height, eg.dimensionsChanged)
end
function Screen:containsPosition(x, y)
local cachedX, cachedY = self.position:getCachedPosition()
local cachedWidth, cachedHeight = self.dimension:getCachedDimension()
return x >= cachedX and y >= cachedY and x < cachedX + cachedWidth and y < cachedY + cachedHeight
end
---------------------
-- Manage children --
---------------------
function Screen:addChild(child)
table.insert(self.children, child)
child.parent = self
end
function Screen:addChildren(...)
for k, child in ipairs{...} do
self:addChild(child)
end
end
----------------
-- Invalidate --
----------------
function Screen:invalidate()
local cachedX, cachedY = self.position:getCachedPosition()
local cachedWidth, cachedHeight = self.dimension:getCachedDimension()
eg.invalidate(cachedX, cachedY, cachedWidth, cachedHeight)
end
-------------------
-- Screen events --
-------------------
function Screen:onPushed(args)
-- when pushed
end
function Screen:onPopped(args)
-- when popped
end
--------------------
-- Drawing events --
--------------------
function Screen:paint(gc)
self:prepare(gc)
local width, height = self:getDimension()
local x, y = self:getPosition()
--debug draw bouding boxes
--gc:drawRect(x, y, width, height)
self:draw(gc, x, y, width, height, eg.isColor)
for k, screen in ipairs(self.children) do
screen:paint(gc)
-- Reset color to default
-- Possibly this should also be done with the pen and the font
gc:setColorRGB(0,0,0)
end
self:postDraw(gc, x, y, width, height, eg.isColor)
end
function Screen:prepare(gc)
-- use this callback to calculate dimensions
end
function Screen:draw(gc, x, y, width, height, isColor)
-- all drawing should happen here
-- called before drawing children
end
function Screen:postDraw(gc, x, y, width, height, isColor)
-- all drawing should happen here
-- called after drawing children
end
end
----------------------------------
-- End of etk/screenmanager.lua --
----------------------------------
----------------------------------
-- Start of etk/viewmanager.lua --
----------------------------------
----------------
-- View class --
----------------
do etk.View = class(etk.Screen)
local View = etk.View
local Screen = etk.Screen
local eg = etk.graphics
function View:init(args)
args = args or {}
local dimension = args.dimension or Dimension()
local position = args.position or Position()
Screen.init(self, position, dimension)
self.focusIndex = 0
end
-----------------
-- Focus logic --
-----------------
function View:switchFocus(direction, isChildView, counter)
local children = self.children
local focusIndex = self.focusIndex
local currentChild = children[focusIndex]
local continue = true
if currentChild and currentChild.focusIndex then
continue = not currentChild:switchFocus(direction, true, 0) -- do we need to handle the focus change
end
if continue then
if counter > #children then
return
else
counter = counter + 1
end
self:removeFocusFromChild(currentChild)
local nextFocusIndex = focusIndex + direction
local childrenCount = #self.children
local wrapped = false
if nextFocusIndex > childrenCount then
nextFocusIndex = 1
wrapped = true
elseif nextFocusIndex <= 0 then
nextFocusIndex = childrenCount
wrapped = true
end
if wrapped and isChildView then
return false -- we are not handling the focus change due to wrapping, the parent focus manager needs to handle it
else
return self:giveFocusToChildAtIndex(nextFocusIndex, direction, isChildView, counter)
end
end
end
function View:removeFocusFromChild(child)
if child then
self.focusIndex = 0
child.hasFocus = false
CallEvent(child, "onBlur")
end
end
function View:removeFocusFromChildAtIndex(index)
self:removeFocusFromChild(self:getFocusedChild())
end
function View:giveFocusToChildAtIndex(index, direction, isChildView, counter)
local nextChild = self.children[index]
self.focusIndex = index
if nextChild then
if nextChild.ignoreFocus and direction and counter then
self:switchFocus(direction, false, counter)
else
nextChild.hasFocus = true
CallEvent(nextChild, "onFocus")
end
end
end
function View:getFocusedChild()
return self.children[self.focusIndex]
end
-------------------------------------
-- Link tab events to focus change --
-------------------------------------
function View:tabKey()
self:switchFocus(1, false, 0)
eg.invalidate()
end
function View:backtabKey()
self:switchFocus(-1, false, 0)
eg.invalidate()
end
-----------------------------------
-- Link touch event focus change --
-- and propagete the event --
-----------------------------------
View.lastChildMouseDown = nil
View.lastChildMouseOver = nil
function View:getChildIn(x, y)
local lastChildIndex = View.lastChildMouseDown
if lastChildIndex then
local lastChild = self.children[lastChildIndex]
if lastChild and lastChild:containsPosition(x, y) then
return lastChildIndex, lastChild
end
end
for index, child in pairs(self.children) do
if child:containsPosition(x, y) then
return index, child
end
end
end
function View:mouseDown(x, y)
local index, child = self:getChildIn(x, y)
local lastChild = self:getFocusedChild()
if child ~= lastChild then
self:removeFocusFromChild(lastChild)
if index then
self:giveFocusToChildAtIndex(index)
end
end
View.lastChildMouseDown = index
if child then
CallEvent(child, "onMouseDown", x, y)
end
self:invalidate()
end
function View:mouseUp(x, y)
local lastChildIndex = View.lastChildMouseDown
if lastChildIndex then
local lastChild = self.children[lastChildIndex]
CallEvent(lastChild, "onMouseUp", x, y, lastChild:containsPosition(x, y))
end
self:invalidate()
end
---------------------------------------------
-- Propagate other events to focused child --
---------------------------------------------
function View:onEvent(event, eventHandler, ...)
Logger.Log("View %q - event %q - eventHandler %q", tostring(self), tostring(event), tostring(eventHandler))
local child = self:getFocusedChild()
--if not eventHandler and child then -- TODO: ADD event propogation block support
if child then
CallEvent(child, "onEvent", event, child[event], ...)
CallEvent(child, event, ...)
end
end
end
--------------------------------
-- End of etk/viewmanager.lua --
--------------------------------
-----------------------------------
-- Start of etk/eventmanager.lua --
-----------------------------------
----------------------------------
-- ETK Event Manager --
-- Handle the events! --
-- --
-- (C) 2015 Jim Bauwens --
-- Licensed under the GNU GPLv3 --
----------------------------------
do
etk.eventmanager = {}
etk.eventhandlers = {}
local em = etk.eventmanager
local eh = etk.eventhandlers
local eg = etk.graphics
local rs = etk.RootScreen
-----------
-- TOOLS --
-----------
-- We will use this function when calling events
local callEventHandler = function (func, ...)
if func then
func(...)
end
end
-------------------
-- EVENT LINKING --
-------------------
local eventLinker = {}
local triggeredEvent
local eventDistributer = function (...)
local currentScreen = rs:peekScreen()
local eventHandler = currentScreen[triggeredEvent]
local genericEventHandler = currentScreen.onEvent
if genericEventHandler then
genericEventHandler(currentScreen, triggeredEvent, eventHandler, ...)
end
if eventHandler then
eventHandler(currentScreen, ...)
end
end
eventLinker.__index = function (on, event)
triggeredEvent = event
return eventDistributer
end
setmetatable(on, eventLinker)
on.activate = function ()
eg.needsFullRedraw = true
end
on.getFocus = function ()
eg.needsFullRedraw = true
end
on.resize = function (width, height)
Logger.Log("Viewport dimensions changed to %dx%d", width, height)
eg.dimensionsChanged = true
eg.needsFullRedraw = true
eg.viewPortWidth = width
eg.viewPortHeight = height
end
on.paint = function(gc)
gc:smartClipRect("set", 0, 0, eg.viewPortWidth, eg.viewPortHeight)
--eventLinker.__index(on, "paint")(gc)
rs:paint(gc, 0, 0, eg.viewPortWidth, eg.viewPortHeight)
eg.dimensionsChanged = false
end
end
---------------------------------
-- End of etk/eventmanager.lua --
---------------------------------
------------------------------------
-- Start of etk/widgetmanager.lua --
------------------------------------
------------
-- Widget --
------------
etk.Widgets = {}
do etk.Widget = class(etk.Screen)
local Widget = etk.Widget
local Screen = etk.Screen
function Widget:init(position, dimension)
Screen.init(self, position, dimension)
self.hasFocus = false;
end
end
do Box = class(etk.Widget)
local Widget = etk.Widget
function Box:init(position, dimension, text)
Widget.init(self, position, dimension)
self.text = text
end
function Box:draw(gc, x, y, width, height, isColor)
Logger.Log("In Box:draw %d, %d, %d, %d", x, y, width, height)
gc:setColorRGB(0, 0, 0)
if self.hasFocus then
gc:fillRect(x, y, width, height)
else
-- No, draw only the outline
gc:drawRect(x, y, width, height)
end
gc:setColorRGB(128, 128, 128)
gc:setFont("sansserif", "r", 7)
if self.text then
gc:drawString(self.text, x+2, y, "top")
gc:drawString(width .. "," .. height, x+2, y+9, "top")
end
end
end
-------------------------------------
-- Start of etk/widgets/button.lua --
-------------------------------------
do
local Widget = etk.Widget
local Widgets = etk.Widgets
do Widgets.Button = class(Widget)
local Widget = etk.Widget
local Button = Widgets.Button
Button.defaultStyle = {
textColor = {{000,000,000},{000,000,000}},
backgroundColor = {{248,252,248},{248,252,248}},
borderColor = {{136,136,136},{160,160,160}},
focusColor = {{040,148,184},{000,000,000}},
defaultWidth = 48,
defaultHeight = 27,
font = {
serif="sansserif",
style="r",
size=10
}
}
function Button:init(arg)
self.text = arg.text or "Button"
local style = arg.style or Button.defaultStyle
self.style = style
local dimension = Dimension(style.defaultWidth, style.defaultHeight)
Widget.init(self, arg.position, dimension)
end
function Button:prepare(gc)
local font = self.style.font
gc:setFont(font.serif, font.style, font.size)
self.dimension.width = gc:getStringWidth(self.text) + 10
self.dimension:invalidate()
self.position:invalidate()
end
function Button:draw(gc, x, y, width, height, isColor)
if self.meDown then
y = y + 1
end
local color = isColor and 1 or 2
local style = self.style
gc:setColorRGB(unpackColor(style.backgroundColor[color]))
gc:fillRect(x + 2, y + 2, width - 4, height - 4)
gc:setColorRGB(unpackColor(style.textColor[color]))
gc:drawString(self.text, x + 5, y + 3, "top")
if self.hasFocus then
gc:setColorRGB(unpackColor(style.focusColor[color]))
gc:setPen("medium", "smooth")
else
gc:setColorRGB(unpackColor(style.borderColor[color]))
gc:setPen("thin", "smooth")
end
gc:fillRect(x + 2, y, width - 4, 2)
gc:fillRect(x + 2, y + height - 2, width - 4, 2)
gc:fillRect(x, y + 2, 1, height - 4)
gc:fillRect(x + 1, y + 1, 1, height - 2)
gc:fillRect(x + width - 1, y + 2, 1, height - 4)
gc:fillRect(x + width - 2, y + 1, 1, height - 2)