-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.lua
More file actions
5064 lines (3683 loc) · 108 KB
/
functions.lua
File metadata and controls
5064 lines (3683 loc) · 108 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
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
--
-- Project: CareControlPortal
-- Description:
--
-- Version: 1.0
-- Managed with http://CoronaProjectManager.com
--
-- Copyright 2014 . All Rights Reserved.
--
local widget = require( "widget" )
local storyboard = require( "storyboard" )
local http = require("httpwork")
local date = require("date")
local url = require("socket.url")
local lfs = require("lfs")
--local CCDB = require("Offline")
local ReturnTable={}
local OverlayShow
local DrawLine
local CreateListView
local StandardTextBox
local StandardImage
local FadeScreen
local SmallButton
local PushBackEntry
local GoBack
local PopBackEntry
local LoadScreen
local WideButton2
local _loading
local _loadingStatus
local fdScreen
local AlertWindow
local ShowSimpleAlert
local OffGrp
system.activate( "multitouch" )
local isDevice = false -- (system.getInfo("model") == "iPhone")
function lengthOf( a, b )
local width, height = b.x-a.x, b.y-a.y
return (width*width + height*height)^0.5
end
-- returns the degrees between (0,0) and pt
-- note: 0 degrees is 'east'
function angleOfPoint( pt )
local x, y = pt.x, pt.y
local radian = math.atan2(y,x)
local angle = radian*180/math.pi
if angle < 0 then angle = 360 + angle end
return angle
end
-- returns the degrees between two points
-- note: 0 degrees is 'east'
function angleBetweenPoints( a, b )
local x, y = b.x - a.x, b.y - a.y
return angleOfPoint( { x=x, y=y } )
end
-- returns the smallest angle between the two angles
-- ie: the difference between the two angles via the shortest distance
function smallestAngleDiff( target, source )
local a = target - source
if (a > 180) then
a = a - 360
elseif (a < -180) then
a = a + 360
end
return a
end
-- rotates a point around the (0,0) point by degrees
-- returns new point object
function rotatePoint( point, degrees )
local x, y = point.x, point.y
local theta = math.rad( degrees )
local pt = {
x = x * math.cos(theta) - y * math.sin(theta),
y = x * math.sin(theta) + y * math.cos(theta)
}
return pt
end
-- rotates point around the centre by degrees
-- rounds the returned coordinates using math.round() if round == true
-- returns new coordinates object
function rotateAboutPoint( point, centre, degrees, round )
local pt = { x=point.x - centre.x, y=point.y - centre.y }
pt = rotatePoint( pt, degrees )
pt.x, pt.y = pt.x + centre.x, pt.y + centre.y
if (round) then
pt.x = math.round(pt.x)
pt.y = math.round(pt.y)
end
return pt
end
-- calculates the average centre of a list of points
local function calcAvgCentre( points )
local x, y = 0, 0
for i=1, #points do
local pt = points[i]
x = x + pt.x
y = y + pt.y
end
return { x = x / #points, y = y / #points }
end
-- calculate each tracking dot's distance and angle from the midpoint
local function updateTracking( centre, points )
for i=1, #points do
local point = points[i]
point.prevAngle = point.angle
point.prevDistance = point.distance
point.angle = angleBetweenPoints( centre, point )
point.distance = lengthOf( centre, point )
end
end
-- calculates rotation amount based on the average change in tracking point rotation
local function calcAverageRotation( points )
local total = 0
for i=1, #points do
local point = points[i]
total = total + smallestAngleDiff( point.angle, point.prevAngle )
end
return total / #points
end
-- calculates scaling amount based on the average change in tracking point distances
local function calcAverageScaling( points )
local total = 0
for i=1, #points do
local point = points[i]
total = total + point.distance / point.prevDistance
end
return total / #points
end
-- creates an object to be moved
function newTrackDot(e)
local circle = display.newCircle( e.x, e.y, 50 )
circle.alpha = .5
local rect = e.target
-- standard multi-touch event listener
function circle:touch(e)
-- get the object which received the touch event
local target = circle
-- store the parent object in the event
e.parent = rect
-- handle each phase of the touch event life cycle...
if (e.phase == "began") then
-- tell corona that following touches come to this display object
display.getCurrentStage():setFocus(target, e.id)
-- remember that this object has the focus
target.hasFocus = true
-- indicate the event was handled
return true
elseif (target.hasFocus) then
-- this object is handling touches
if (e.phase == "moved") then
-- move the display object with the touch (or whatever)
target.x, target.y = e.x, e.y
else -- "ended" and "cancelled" phases
-- stop being responsible for touches
display.getCurrentStage():setFocus(target, nil)
-- remember this object no longer has the focus
target.hasFocus = false
end
-- send the event parameter to the rect object
rect:touch(e)
-- indicate that we handled the touch and not to propagate it
return true
end
-- if the target is not responsible for this touch event return false
return false
end
-- listen for touches starting on the touch layer
circle:addEventListener("touch")
-- listen for a tap when running in the simulator
function circle:tap(e)
if (e.numTaps == 2) then
-- set the parent
e.parent = rect
-- call touch to remove the tracking dot
rect:touch(e)
end
return true
end
-- only attach tap listener in the simulator
-- pass the began phase to the tracking dot
circle:touch(e)
-- return the object for use
return circle
end
function touch(self, e)
-- get the object which received the touch event
local target = e.target
-- get reference to self object
local rect = self
-- handle began phase of the touch event life cycle...
if (e.phase == "began") then
--print( e.phase, e.x, e.y )
-- create a tracking dot
local dot = newTrackDot(e)
-- add the new dot to the list
rect.dots[ #rect.dots+1 ] = dot
-- pre-store the average centre position of all touch points
rect.prevCentre = calcAvgCentre( rect.dots )
-- pre-store the tracking dot scale and rotation values
updateTracking( rect.prevCentre, rect.dots )
-- we handled the began phase
return true
elseif (e.parent == rect) then
if (e.phase == "moved") then
--print( e.phase, e.x, e.y )
-- declare working variables
local centre, scale, rotate = {}, 1, 0
-- calculate the average centre position of all touch points
centre = calcAvgCentre( rect.dots )
-- refresh tracking dot scale and rotation values
updateTracking( rect.prevCentre, rect.dots )
-- if there is more than one tracking dot, calculate the rotation and scaling
if (#rect.dots > 1) then
-- calculate the average rotation of the tracking dots
rotate = calcAverageRotation( rect.dots )
-- calculate the average scaling of the tracking dots
scale = calcAverageScaling( rect.dots )
-- apply rotation to rect
--rect.rotation = rect.rotation + rotate
-- apply scaling to rect
rect.xScale, rect.yScale = rect.xScale * scale, rect.yScale * scale
end
-- declare working point for the rect location
local pt = {}
-- translation relative to centre point move
pt.x = rect.x + (centre.x - rect.prevCentre.x)
pt.y = rect.y + (centre.y - rect.prevCentre.y)
-- scale around the average centre of the pinch
-- (centre of the tracking dots, not the rect centre)
pt.x = centre.x + ((pt.x - centre.x) * scale)
pt.y = centre.y + ((pt.y - centre.y) * scale)
-- rotate the rect centre around the pinch centre
-- (same rotation as the rect is rotated!)
--pt = rotateAboutPoint( pt, centre, rotate, false )
-- apply pinch translation, scaling and rotation to the rect centre
rect.x, rect.y = pt.x, pt.y
-- store the centre of all touch points
rect.prevCentre = centre
else -- "ended" and "cancelled" phases
--print( e.phase, e.x, e.y )
-- remove the tracking dot from the list
if (_G.PinchMode == "Yes" or e.numTaps == 2) then --isdevice
-- get index of dot to be removed
local index = table.indexOf( rect.dots, e.target )
-- remove dot from list
table.remove( rect.dots, index )
-- remove tracking dot from the screen
e.target:removeSelf()
-- store the new centre of all touch points
rect.prevCentre = calcAvgCentre( rect.dots )
-- refresh tracking dot scale and rotation values
updateTracking( rect.prevCentre, rect.dots )
end
end
return true
end
return false
end
local function split(pString, pPattern)
local Table = {} -- NOTE: use {n = 0} in Lua-5.0
local fpat = "(.-)" .. pPattern
local last_end = 1
local s, e, cap = pString:find(fpat, 1)
while s do
-- if s ~= 1 or cap ~= "" then
table.insert(Table,cap)
-- end
last_end = e+1
s, e, cap = pString:find(fpat, last_end)
end
if last_end <= #pString then
cap = pString:sub(last_end)
table.insert(Table, cap)
end
return Table
end
local function StandardNumericField(centrex, centrey,widthx, inputType)
local isAndroid = "Android" == system.getInfo( "platformName" )
local inputFontSize = 18
local tHeight = 30
if ( isAndroid ) then
inputFontSize = inputFontSize - 4
tHeight = tHeight + 10
end
local codeField = native.newTextField( centrex, centrey, widthx, tHeight )
codeField.align = "right"
codeField.inputType = inputType
codeField.hasBackground = true
codeField.font=native.newFont("arial", inputFontSize )
codeField:setTextColor(20/255, 20/255, 20/255)
return codeField
end
local function StandardTextField(centrex, centrey,widthx,fontSize, tHeight)
local isAndroid = "Android" == system.getInfo( "platformName" )
local inputFontSize
if fontSize ~= nil then
inputFontSize = fontSize
else
inputFontSize = 17
end
if tHeight == nil then
tHeight = inputFontSize + 13
end
if ( isAndroid ) then
inputFontSize = inputFontSize - 4
tHeight = tHeight + 15
end
local codeField = native.newTextField( centrex, centrey, widthx, tHeight )
codeField.hasBackground = true
codeField.font=native.newFont("arial", inputFontSize )
codeField:setTextColor(20/255, 20/255, 20/255)
return codeField
end
local function StandardTextBox2(centrex, centrey,widthx)
local isAndroid = "Android" == system.getInfo( "platformName" )
local inputFontSize = 17
local tHeight = 30
if ( isAndroid ) then
inputFontSize = inputFontSize - 4
tHeight = tHeight + 15
end
local codeField = native.newTextBox( centrex, centrey, widthx, tHeight )
codeField.hasBackground = true
codeField.font=native.newFont("arial", inputFontSize )
codeField:setTextColor(20/255, 20/255, 20/255)
return codeField
end
local function CreateBox(centrex, centrey,widthx, heightx, listener, id, stWidth)
local fieldBox = display.newRect( centrex, centrey,widthx, heightx )
if stWidth ~= nil then
fieldBox.strokeWidth = stWidth + 1
else
fieldBox.strokeWidth = 2
end
fieldBox:setFillColor( 1 )
if listener ~= nil then
fieldBox:addEventListener("touch",listener)
end
if id ~= nil then
fieldBox.id = id
end
fieldBox:setStrokeColor( 166/255, 166/255, 166/255 )
return fieldBox
end
local function CreateBox2(centrex, centrey,widthx, heightx, red, green, blue,clear, swidth, sred, sgreen, sblue, alpha, listener, id)
local paint = { red, green, blue}
local paintTransparent = {red, green, blue, 0}
local rect = display.newRect( centrex, centrey,widthx, heightx )
rect.x = centrex + widthx/2
if swidth == nil then
swidth = 1
end
if clear == nil then
rect.strokeWidth = swidth+1
rect.fill = paint
if sred == nil then
rect:setStrokeColor( 166/255, 166/255, 166/255 )
else
rect:setStrokeColor( sred, sgreen, sblue )
end
else
rect.fill = paintTransparent
rect.strokeWidth = swidth + 1
rect:setStrokeColor( red, green, blue )
end
if id ~= nil then
rect.id = id
end
if listener ~= nil then
rect:addEventListener("touch",listener)
end
if alpha ~= nil then
rect.alpha = alpha
end
return rect
end
local function CreateRoundBox(centrex, centrey,widthx, heightx, red, green, blue,clear, swidth, corners, listener, id,fred,fgreen,fblue)
local cn
if corners == nil then
cn = 6
else
cn = corners
end
local paint = { red, green, blue }
local rect = display.newRoundedRect( centrex, centrey,widthx, heightx,cn )
rect.x = centrex + widthx/2
if clear == nil then
rect.strokeWidth = swidth + 1
rect.fill = paint
rect:setStrokeColor( 166/255, 166/255, 166/255 )
else
rect.strokeWidth = swidth + 1
rect:setStrokeColor( red, green, blue )
end
if fred ~= nil then
rect:setFillColor(fred,fgreen,fblue)
end
if id ~= nil then
rect.id = id
end
if listener ~= nil then
rect:addEventListener("touch",listener)
end
return rect
end
StandardTextBox = function (centrex, centrey,widthx, heightx, inputListener)
local isAndroid = "Android" == system.getInfo( "platformName" )
local inputFontSize = 27
local tHeight = heightx
if ( isAndroid ) then
inputFontSize = inputFontSize - 2
tHeight = tHeight + 10
end
local codeField = native.newTextBox( centrex, centrey, widthx, tHeight, inputListener )
-- codeField.hasBackground = true
codeField.isEditable = true
-- codeField:setReturnKey("done")
codeField.font=native.newFont("arial", inputFontSize )
codeField:setTextColor(20/255, 20/255, 20/255)
return codeField
end
local function StandardLabel(LabelText, FontSize)
local lb7 = display.newText( LabelText,0, 0, "arial",FontSize )
lb7:setFillColor( 120/255, 0/255, 4/255)
return lb7
end
local function StandardLabel2(LabelText, posX, posY, FontSize, red, green, blue, listener)
if LabelText == nil then
LabelText = ""
end
local lb7 = display.newText( LabelText,0, 0, "arial",FontSize )
lb7.x = posX + (lb7.contentWidth / 2)
lb7.y = posY
if red ~= nil then
lb7:setFillColor(red,green, blue)
else
lb7:setFillColor(135/255,122/255, 123/255)
end
if listener ~= nil then
lb7:addEventListener("touch",listener)
end
return lb7
end
local function StandardLabel2w(LabelText, posX, posY, width, FontSize, red, green, blue, listener, id)
if LabelText == nil then
LabelText = ""
end
local lb7 = display.newText( LabelText,0, 0,width,0, "arial",FontSize)
lb7.x = posX + (lb7.contentWidth / 2)
lb7.y = posY --+ (lb7.contentHeight / 2) - 10
if red ~= nil then
lb7:setFillColor(red,green, blue)
else
lb7:setFillColor(135/255,122/255, 123/255)
end
if listener ~= nil then
lb7:addEventListener("touch",listener)
if id ~= nil then
lb7.id = id
end
end
return lb7
end
local function StandardLabelBold(LabelText, posX, posY, FontSize, red, green, blue, listener, id, centreText)
local isAndroid = "Android" == system.getInfo( "platformName" )
-- if ( isAndroid ) then
-- FontSize = FontSize - 2
-- end
local lb7 = display.newText( LabelText,0, 0, native.systemFontBold,FontSize )
if posX < 0 then -- this means centre the text
lb7.x = display.contentWidth/ 2
elseif centreText == nil then
lb7.x = posX + (lb7.contentWidth / 2)
else
lb7.x = posX
end
lb7.y = posY
-- print("colour of red" .. red)
if red ~= nil then
if red > 1.1 then
red = red / 255
green = green / 255
blue = blue / 255
end
lb7:setFillColor(red,green, blue)
else
lb7:setFillColor(1,1, 1)
end
if listener ~= nil then
lb7:addEventListener("touch",listener)
end
if id ~= nil then
lb7.id = id
end
return lb7
end
local function StandardLabelBoldW(LabelText, posX, posY, width, FontSize, red, green, blue, listener, id,centre)
local lb7 = display.newText( LabelText,0, 0, width,0,native.systemFontBold,FontSize )
if centre ~= nil then
lb7.x = posX --+ (lb7.contentWidth / 2)
else
lb7.x = posX + (lb7.contentWidth / 2)
end
lb7.y = posY
if red ~= nil then
lb7:setFillColor(red,green, blue)
else
lb7:setFillColor(1,1, 1)
end
if listener ~= nil then
lb7:addEventListener("touch",listener)
end
if id ~= nil then
lb7.id = id
end
return lb7
end
local function StandardLabelBoldWNew(LabelText, posX, posY, width, FontSize,align, red, green, blue, listener, id)
local al
if align == nil then
al = "left"
else
al = align
end
local options =
{
text = LabelText,
x = posX,
y = posY,
width = width,
font = native.systemFont,
fontSize = FontSize,
align = al
}
local myText = display.newText( options )
if red ~= nil then
myText:setFillColor(red,green, blue)
else
myText:setFillColor(1,1, 1)
end
if listener ~= nil then
myText:addEventListener("touch",listener)
end
if id ~= nil then
myText.id = id
end
return myText
end
local function MultilineLabel(LabelText, posX, posY, width, height, FontSize, red, green, blue, withScroll,listener, pid)
local isAndroid = "Android" == system.getInfo( "platformName" )
if ( isAndroid ) then
FontSize = FontSize - 1
end
local lb7