-
Notifications
You must be signed in to change notification settings - Fork 2
/
cftGui.monkey
executable file
·779 lines (694 loc) · 24.7 KB
/
cftGui.monkey
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
#rem
Title: fantomEngine
Description: A 2D game framework for the Monkey programming language
Author: Michael Hartlef
Contact: [email protected]
Repository: http://code.google.com/p/fantomengine/
License: MIT
#End
Strict
Import fantomEngine
'nav:<blockquote><nav><b>fantomEngine documentation</b> | <a href="index.html">Home</a> | <a href="classes.html">Classes</a> | <a href="3rdpartytools.html">3rd party tools</a> | <a href="examples.html">Examples</a> | <a href="changes.html">Changes</a></nav></blockquote>
#Rem
'header:The class [b]ftGuiGadget[/b] is the base class for each gui object/gadget.
#End
'***************************************
Class ftGuiGadget Extends ftObject
'#DOCOFF#
Field gotHit:Bool = False
Field vjMng:ftGuiMng = Null
Field listNode:list.Node<ftObject> = Null
Field smoothFactor:Float = .9
Field alphaVal:Float = 0.0
Field state:Bool = True
Field hitCount:Int = 0
'-----------------------------------------------------------------------------
Method _GetLastHitState:Bool()
Local retVal:Bool = False
If Self.gotHit = True
retVal = True
Self.gotHit = False
Endif
Return retVal
End
'-----------------------------------------------------------------------------
Method _Reset:Void()
Self.alphaVal *= Self.smoothFactor
Self.SetAlpha(1.0-Self.alphaVal)
Self.hitCount -= 1
If Self.hitCount < 0 Then Self.hitCount = 0
End
'#DOCON#
'-----------------------------------------------------------------------------
'summery:Returns the state of the control.
Method GetState:Bool()
Return Self.state
End
'-----------------------------------------------------------------------------
'summery:Sets the smoothness factor for the control.
Method SetSmoothness:Void(smoothFactor:Float = 0.9)
Self.smoothFactor = smoothFactor
End
'-----------------------------------------------------------------------------
'summery:Sets the state of the control.
Method SetState:Void(newState:Bool)
Self.state = newState
End
End
'***************************************
Class ftGuiButton Extends ftGuiGadget
'-----------------------------------------------------------------------------
' Overriding the default method so it will handle the fading effect.
Method CheckTouchHit:Bool(px:Float, py:Float)
Local retVal:Bool = Super.CheckTouchHit(px, py)
If retVal = True
Self.alphaVal = 0.8
Self.gotHit = True
Else
Self.alphaVal *= Self.smoothFactor
Self.gotHit = False
Endif
Self.SetAlpha(1.0-Self.alphaVal)
Return retVal
End
'-----------------------------------------------------------------------------
'summery:Returns TRUE if the button just got pressed.
Method GetPressed:Bool()
Return Self.gotHit
End
End
'***************************************
Class ftGuiCheckbox Extends ftGuiGadget
'-----------------------------------------------------------------------------
' Overriding the default method so it will handle the fading effect.
Method CheckTouchHit:Bool(px:Float, py:Float)
Local retVal:Bool = Super.CheckTouchHit(px, py)
If retVal = True And hitCount = 0
Self.state = Not Self.state
If Self.state = True
Self.SetCurrImage(1,1)
Else
Self.SetCurrImage(2,1)
Endif
Self.alphaVal = 0.8
Self.gotHit = True
Self.hitCount = 2
Elseif retVal = True And hitCount > 0
Self.alphaVal = 0.8
hitCount = 2
Else
'
Endif
Self.SetAlpha(1.0-Self.alphaVal)
Return retVal
End
'-----------------------------------------------------------------------------
'summery:Sets the check state of the checkbox. TRUE means it is checked.
Method SetState:Void(checkState:Bool)
Super.SetState(checkState)
If Self.state = True
Self.SetCurrImage(1,1)
Else
Self.SetCurrImage(2,1)
Endif
End
End
'***************************************
Class ftGuiJoystick Extends ftGuiGadget
'#DOCOFF#
Field xStickOff:Float = 0.0
Field yStickOff:Float = 0.0
Field stick:ftObject = Null
Field deadZone:Float = 0.1
Field maxZone:Float = 1.0
Field distance:Float = 0.0
'-----------------------------------------------------------------------------
'summery:Resets the stick to the center
Method _Reset:Void()
Self.xStickOff *= Self.smoothFactor
Self.yStickOff *= Self.smoothFactor
Self.stick.SetPos(Self.xPos + xStickOff, Self.yPos + yStickOff)
End
'#DOCON#
'-----------------------------------------------------------------------------
' Overriding the default method so the X/Y offset of the stick will be stored and its
' object will be positioned automatically.
Method CheckTouchHit:Bool(px:Float, py:Float)
Local retVal:Bool = Super.CheckTouchHit(px, py)
If retVal = True
Self.xStickOff = px - Self.xPos
If Abs(Self.GetJoyX())< Self.deadZone Then Self.xStickOff = 0.0
If Abs(Self.GetJoyX())> Self.maxZone Then Self.xStickOff = Self.maxZone * (Self.GetWidth()/2.0) * Sgn(Self.xStickOff)
Self.yStickOff = py - Self.yPos
If Abs(Self.GetJoyY())< Self.deadZone Then Self.yStickOff = 0.0
If Abs(Self.GetJoyY())> Self.maxZone Then Self.yStickOff = Self.maxZone * (Self.GetHeight()/2.0) * Sgn(Self.yStickOff)
Self.gotHit = True
Self.distance = Self.GetVectorDist(px, py)
Else
Self.xStickOff *= Self.smoothFactor
Self.yStickOff *= Self.smoothFactor
Self.gotHit = False
Endif
Self.stick.SetPos(Self.xPos + xStickOff, Self.yPos + yStickOff)
Return retVal
End
'-----------------------------------------------------------------------------
'summery:Returns the X offset of the joystick
Method GetJoyX:Float(raw:Bool = False)
Local retval:Float
If raw = True
Return Self.xStickOff
Else
retval = Self.xStickOff/(Self.GetWidth()/2.0) * 10
If retval>0.0
retval = Floor ( retval + 0.5 ) / 10.0
Else
retval = Ceil ( retval - 0.5 ) / 10.0
Endif
Return retval
Endif
End
'-----------------------------------------------------------------------------
'summery:Returns the Y offset of the joystick
Method GetJoyY:Float(raw:Bool = False)
Local retval:Float
If raw = True
Return Self.yStickOff
Else
'Return Self.yStickOff/(Self.GetHeight()/2.0)
retval = Self.yStickOff/(Self.GetHeight()/2.0) * 10
If retval>0.0
retval = Floor ( retval + 0.5 ) / 10.0
Else
retval = Ceil ( retval - 0.5 ) / 10.0
Endif
Return retval
Endif
End
'-----------------------------------------------------------------------------
'summery:Returns the hit state of the joystick
Method isHit:Bool()
Return Self.gotHit
End
'-----------------------------------------------------------------------------
'summery:Sets the deadzone of the joystick. Affects relative values less or equal the deadzone value.
Method SetDeadZone:Void(deadZone:Float = 0.1)
Self.deadZone = deadZone
End
'-----------------------------------------------------------------------------
'summery:Sets the deadzone of the joystick. Affects relative values less or equal the deadzone value.
Method SetMaxZone:Void(maxZone:Float = 0.9)
Self.maxZone = maxZone
End
End
'***************************************
Class ftGuiLabel Extends ftGuiGadget
Field hasShadow:Bool = False
Field shadowX:Float = 2.0
Field shadowY:Float = 2.0
'-----------------------------------------------------------------------------
Method Render:Void(xoff:Float=0.0, yoff:Float=0.0)
Local xAlpha:Float = Self.GetAlpha()
Local xColor:Float[]
If Self.hasShadow = True
xAlpha = Self.GetAlpha()
xColor = Self.GetColor()
Self.SetColor(50,50,50)
Self.SetAlpha(xAlpha-0.3)
Super.Render(xoff+Self.shadowX, yoff+Self.shadowY)
Self.SetColor(xColor[0],xColor[1],xColor[2])
Self.SetAlpha(xAlpha)
Endif
Super.Render(xoff, yoff)
End
'-----------------------------------------------------------------------------
Method SetShadowOffset:Void(xOff:Float, yOff:Float)
Self.shadowX = xOff
Self.shadowY = yOff
End
End
'***************************************
Class ftGuiListviewItem
Field text:String = ""
Field img:ftImage = Null
'-----------------------------------------------------------------------------
Method GetImage:ftImage()
Return Self.img
End
'-----------------------------------------------------------------------------
Method GetText:String()
Return Self.text
End
'-----------------------------------------------------------------------------
Method SetText:Void(lviText:String)
Self.text = lviText
End
'-----------------------------------------------------------------------------
Method SetImage:Void(lviImage:ftImage)
Self.img = lviImage
End
End
'***************************************
Class ftGuiListview Extends ftGuiGadget
Field itemList:= New List<ftGuiListviewItem>
Field scrollX:Float = 0.0
Field scrollY:Float = 0.0
Field selItem:Int = -1
Field font:ftFont = Null
'-----------------------------------------------------------------------------
Method AddItem:ftGuiListviewItem(t:string)
Local newItem:= New ftGuiListviewItem
newItem.SetText(t)
itemList.AddLast(newItem)
Return newItem
End
'-----------------------------------------------------------------------------
' Overriding the default method so it will handle the fading effect.
Method CheckTouchHit:Bool(px:Float, py:Float)
Local retVal:Bool = Super.CheckTouchHit(px, py)
If retVal = True And hitCount = 0
Self.state = Not Self.state
Self.alphaVal = 0.8
Self.gotHit = True
Self.hitCount = 2
Self.selItem = Int((py - (Self.yPos-Self.GetHeight()/2.0))/Self.vjMng.font1.Height())
'Print(py +":"+(Self.yPos-Self.GetHeight()/2.0)+"="+Self.selLine)
Elseif retVal = True And hitCount > 0
Self.alphaVal = 0.8
hitCount = 2
Else
'
Endif
Self.SetAlpha(1.0-Self.alphaVal)
Return retVal
End
'-----------------------------------------------------------------------------
Method GetItem:ftGuiListviewItem(index:Int = 0)
Local retItem:ftGuiListviewItem = Null
If index >= 0
Local i:Int = 0
For Local item := Eachin Self.itemList
If i = index
retItem = item
Exit
Endif
i += 1
Next
Endif
Return retItem
End
'-----------------------------------------------------------------------------
Method GetSelected:Int()
Return Self.selItem
End
'-----------------------------------------------------------------------------
Method GetItemText:String(index:Int)
Local retval:String = ""
Local i:Int = 0
For Local item :ftGuiListviewItem = Eachin Self.itemList
If i = index
retval = item.GetText()
Exit
Endif
i += 1
Next
Return retval
End
'-----------------------------------------------------------------------------
Method SetSelected:Void(selectedID:Int = -1)
Self.selItem = selectedID
End
'-----------------------------------------------------------------------------
Method Render:Void(xoff:Float=0.0, yoff:Float=0.0)
Local _fE:ftEngine = Self.vjMng.engine
Local sfx:Float = _fE.scaleX
Local sfy:Float = _fE.scaleY
Local i:Int = 1
Super.Render(xoff, yoff)
Local sc:Float[] = GetScissor()
SetScissor(_fE.GetLocalX(Self.xPos-Self.GetWidth()/2), _fE.GetLocalY(Self.yPos-Self.GetHeight()/2), Self.GetWidth()*sfx, Self.GetHeight()*sfy)
mojo.SetColor(255,255,255)
mojo.SetAlpha(1.0)
For Local item:= Eachin Self.itemList
Self.vjMng.font1.Draw(item.GetText(), xoff+Self.xPos-Self.GetWidth()/2-Self.scrollX, yoff+Self.yPos+(i-1)*Self.vjMng.font1.Height()-Self.GetHeight()/2-Self.scrollY)
i += 1
Next
SetScissor(sc[0],sc[1],sc[2],sc[3])
Self.vjMng.engine.RestoreAlpha()
Self.vjMng.engine.RestoreColor()
End
'-----------------------------------------------------------------------------
Method SetLines:Void(newLines:String)
Local lines:string[] = newLines.Split("~n")
For Local is:String = Eachin lines
Self.AddItem(is)
Next
End
'-----------------------------------------------------------------------------
Method SetLines:Void(newLines:String[])
Local lines:String[] = newLines
For Local is:String = Eachin lines
Self.AddItem(is)
Next
End
'-----------------------------------------------------------------------------
'summery:Set the X/Y offset position of the list items.
Method SetScrollXY:Void (sx:Float, sy:Float, relative:Int = False )
If relative = True
Self.scrollX += sx
Self.scrollY += sy
Else
Self.scrollX = sx
Self.scrollY = sy
Endif
End
End
'***************************************
Class ftGuiMng Extends ftObject
'Field engine:ftEngine
Field objList := New List<ftObject>
Field font1:ftFont = Null
Const idJoyStick:Int = 1111
Const idButton:Int = 1112
Const idSwitch:Int = 1113
Const idChkBox:Int = 1114
Const idListview:Int = 1115
Const idLabel:Int = 1116
'Const idGroup:Int = 1117
'Const idRadioBtn:Int = 1118
Const idSlider:Int = 1119
'Const idProgessbar:Int = 1120
Const idTextfield:Int = 1121
'Const idTextbox:Int = 1122
'Const idListbox:Int = 1123
'Const idComboBox:Int = 1124
'Const idTreeview:Int = 1125
'Const idTooltip:Int = 1126
'Const idGroup:Int = 1127
'Const idSpinner:Int = 1128
'Const idHyperlink:Int = 1129
'Const idScrollbar:Int = 1130
Const slHorizontal:Int = 1
Const slVertical:Int = 2
'------------------------------------------
'summery:Creates a new joypad manager.
Method New(eng:ftEngine)
Self.engine = eng
End
'------------------------------------------
'summery:Creates a new joypad button.
Method CreateButton:ftGuiButton(imgBtn:String)
Local obj:ftObject = engine.CreateImage(imgBtn, Self.engine.GetCanvasWidth()/2, Self.engine.GetCanvasHeight()/2, New ftGuiButton)
obj.SetTouchMode(ftEngine.tmBox)
ftGuiButton(obj).vjMng = Self
'ftGuiButton(vb).listNode = Self.objList.AddLast(vb)
obj.SetID(Self.idButton)
obj.SetLayer(Self.GetLayer())
obj.SetParent(Self)
Return ftGuiButton(obj)
End
'------------------------------------------
'summery:Creates a new checkbox.
Method CreateCheckbox:ftGuiCheckbox(imgChecked:String,imgUnchecked:String, checkState:Bool = True)
Local obj:ftObject = engine.CreateImage(imgChecked, Self.engine.GetCanvasWidth()/2, Self.engine.GetCanvasHeight()/2, New ftGuiCheckbox)
obj.SetTouchMode(ftEngine.tmBox)
obj.AddImage(imgUnchecked)
ftGuiCheckbox(obj).vjMng = Self
'ftGuiCheckbox(obj).listNode = Self.objList.AddLast(obj)
obj.SetID(Self.idChkBox)
ftGuiCheckbox(obj).SetState(checkState)
obj.SetLayer(Self.GetLayer())
obj.SetParent(Self)
Return ftGuiCheckbox(obj)
End
'------------------------------------------
'summery:Creates a new label.
Method CreateLabel:ftGuiLabel(txt:String, shadowed:Bool = False)
Local obj:ftObject = engine.CreateText(Self.font1, txt, Self.engine.GetCanvasWidth()/2, Self.engine.GetCanvasHeight()/2,ftEngine.taTopLeft, New ftGuiLabel)
ftGuiLabel(obj).hasShadow = shadowed
ftGuiLabel(obj).vjMng = Self
'ftGuiLabel(obj).listNode = Self.objList.AddLast(obj)
obj.SetID(Self.idLabel)
obj.SetLayer(Self.GetLayer())
obj.SetParent(Self)
Return ftGuiLabel(obj)
End
'------------------------------------------
'summery:Creates a new listview.
Method CreateListview:ftGuiListview(x:Float, y:Float, w:Float, h:Float, newLines:String)
Local obj:ftObject = engine.CreateBox(w,h,x,y, New ftGuiListview)
obj.SetTouchMode(ftEngine.tmBox)
ftGuiListview(obj).SetLines(newLines)
ftGuiListview(obj).vjMng = Self
'ftGuiListview(obj).listNode = Self.objList.AddLast(obj)
obj.SetID(Self.idListview)
obj.SetLayer(Self.GetLayer())
obj.SetParent(Self)
Return ftGuiListview(obj)
End
'------------------------------------------
'summery:Creates a new analog joystick.
Method CreateJoyStick:ftGuiJoystick(imgRing:String, imgStick:String)
Local obj:ftObject = engine.CreateImage(imgRing, Self.engine.GetCanvasWidth()/2, Self.engine.GetCanvasHeight()/2, New ftGuiJoystick)
ftGuiJoystick(obj).stick = engine.CreateImage(imgStick, Self.engine.GetCanvasWidth()/2, Self.engine.GetCanvasHeight()/2)
ftGuiJoystick(obj).stick.SetParent(obj)
obj.SetTouchMode(ftEngine.tmCircle)
ftGuiJoystick(obj).vjMng = Self
'ftGuiJoystick(vj).listNode = Self.objList.AddLast(vj)
obj.SetID(Self.idJoyStick)
obj.SetLayer(Self.GetLayer())
obj.SetParent(Self)
Return ftGuiJoystick(obj)
End
'------------------------------------------
'summery:Creates a slider.
Method CreateSlider:ftGuiSlider(imgSliderBar:String, imgSliderKnob:String, startVal:Float, rangeVal:Float, orientation:Int = ftGuiMng.slHorizontal)
Local obj:ftObject = engine.CreateImage(imgSliderBar, Self.engine.GetCanvasWidth()/2, Self.engine.GetCanvasHeight()/2, New ftGuiSlider)
ftGuiSlider(obj).knob = engine.CreateImage(imgSliderKnob, Self.engine.GetCanvasWidth()/2, Self.engine.GetCanvasHeight()/2)
ftGuiSlider(obj).knob.SetParent(obj)
obj.SetTouchMode(ftEngine.tmBox)
ftGuiSlider(obj).SetRange(startVal, rangeVal)
ftGuiSlider(obj).orientation = orientation
If ftGuiSlider(obj).orientation = ftGuiMng.slVertical
ftGuiSlider(obj).SetAngle(90.0)
Endif
ftGuiSlider(obj).vjMng = Self
'ftGuiSlider(obj).listNode = Self.objList.AddLast(obj)
obj.SetID(Self.idSlider)
obj.SetLayer(Self.GetLayer())
obj.SetParent(Self)
Return ftGuiSlider(obj)
End
'------------------------------------------
'summery:Creates a new switch.
Method CreateSwitch:ftGuiSwitch(imgSwitchOn:String,imgSwitchOff:String, switchState:Bool = True)
Local obj:ftObject = engine.CreateImage(imgSwitchOn, Self.engine.GetCanvasWidth()/2, Self.engine.GetCanvasHeight()/2, New ftGuiSwitch)
obj.SetTouchMode(ftEngine.tmBox)
obj.AddImage(imgSwitchOff)
ftGuiSwitch(obj).vjMng = Self
'ftGuiSwitch(obj).listNode = Self.objList.AddLast(obj)
obj.SetID(Self.idSwitch)
ftGuiSwitch(obj).SetState(switchState)
obj.SetLayer(Self.GetLayer())
obj.SetParent(Self)
Return ftGuiSwitch(obj)
End
'------------------------------------------
'summery:Creates a new textfield.
Method CreateTextfield:ftGuiTextfield(txt:String, shadowed:Bool = False)
Local obj:ftObject = engine.CreateText(Self.font1, txt, Self.engine.GetCanvasWidth()/2, Self.engine.GetCanvasHeight()/2,ftEngine.taTopLeft, New ftGuiTextfield)
ftGuiTextfield(obj).hasShadow = shadowed
ftGuiTextfield(obj).vjMng = Self
'ftGuiLabel(obj).listNode = Self.objList.AddLast(obj)
obj.SetID(Self.idTextfield)
obj.SetLayer(Self.GetLayer())
obj.SetParent(Self)
Return ftGuiTextfield(obj)
End
'------------------------------------------
'summery:Updates all states of gui elements.
Method Update:Void(delta:Float=1.0)
Super.Update(delta)
'For Local obj:= Eachin Self.objList
For Local obj:= Eachin Self.childObjList
Select obj.GetID()
Case Self.idJoyStick
If ftGuiJoystick(obj)._GetLastHitState() = False
ftGuiJoystick(obj)._Reset()
Endif
Case Self.idButton
If ftGuiButton(obj)._GetLastHitState() = False
ftGuiButton(obj)._Reset()
Endif
Case Self.idSwitch
If ftGuiSwitch(obj)._GetLastHitState() = False
ftGuiSwitch(obj)._Reset()
Endif
Case Self.idChkBox
If ftGuiCheckbox(obj)._GetLastHitState() = False
ftGuiCheckbox(obj)._Reset()
Endif
Case Self.idListview
If ftGuiListview(obj)._GetLastHitState() = False
ftGuiListview(obj)._Reset()
Endif
End
Next
End
End
'***************************************
Class ftGuiSlider Extends ftGuiGadget
'#DOCOFF#
Field xKnobOff:Float = 0.0
Field yKnobOff:Float = 0.0
Field knob:ftObject = Null
Field startValue:Float = 0.0
Field range:Float = 0.0
Field currValue:Float = 0.0
Field orientation:Int = ftGuiMng.slHorizontal
Field idxx:Int= 0
'#DOCON#
'-----------------------------------------------------------------------------
' Overriding the default method so the X offset of the knob will be stored and its
' object will be positioned automatically.
Method CheckTouchHit:Bool(px:Float, py:Float)
Local retVal:Bool = Super.CheckTouchHit(px, py)
If retVal = True
If Self.orientation = ftGuiMng.slHorizontal
Self.xKnobOff = px - Self.xPos + Self.GetWidth()/2.0
Self.currValue = (Self.range/Self.GetWidth()) * Self.xKnobOff + Self.startValue
Self.currValue = Clamp(Self.currValue, Self.startValue,Self.startValue+Self.range)
Self.gotHit = True
Self.knob.SetPos(Self.xPos + xKnobOff - Self.GetWidth()/2.0, Self.yPos)
Else
Self.yKnobOff = py - Self.yPos + Self.GetWidth()/2.0
'Print ("Self.yKnobOff = "+Self.yKnobOff+" Self.GetWidth()="+Self.GetWidth())
Self.currValue = (Self.range/Self.GetWidth()) * Self.yKnobOff + Self.startValue
Self.currValue = Clamp(Self.currValue, Self.startValue,Self.startValue+Self.range)
Self.gotHit = True
Self.knob.SetPos(Self.xPos, Self.yPos + yKnobOff - Self.GetWidth()/2.0)
Endif
If Self.currValue>0.0
Self.currValue = Floor ( Self.currValue + 0.5 )
Else
Self.currValue = Ceil ( Self.currValue - 0.5 )
Endif
Endif
Return retVal
End
'-----------------------------------------------------------------------------
'summery:Returns the current value of the slider
Method GetValue:Float()
Return Self.currValue
End
'-----------------------------------------------------------------------------
'summery:Returns the hit state of the slider
Method isHit:Bool()
Return Self.gotHit
End
'-----------------------------------------------------------------------------
'summery:Sets the range of the slider.
Method SetRange:Void(startVal:Float, rangeVal:Float)
Self.startValue = startVal
Self.range = rangeVal
Self.currValue = (rangeVal/2.0)+startVal
'Print ("Self.currValue="+Self.currValue)
End
End
'***************************************
Class ftGuiSwitch Extends ftGuiGadget
'-----------------------------------------------------------------------------
' Overriding the default method so it will handle the fading effect.
Method CheckTouchHit:Bool(px:Float, py:Float)
Local retVal:Bool = Super.CheckTouchHit(px, py)
If retVal = True And hitCount = 0
Self.state = Not Self.state
If Self.state = True
Self.SetCurrImage(1,1)
Else
Self.SetCurrImage(2,1)
Endif
Self.alphaVal = 0.8
Self.gotHit = True
Self.hitCount = 2
Elseif retVal = True And hitCount > 0
Self.alphaVal = 0.8
hitCount = 2
Else
'
Endif
Self.SetAlpha(1.0-Self.alphaVal)
Return retVal
End
'-----------------------------------------------------------------------------
'summery:Sets the switch state of the switch. TRUE means it is ON.
Method SetState:Void(switchState:Bool)
Super.SetState(switchState)
If Self.state = True
Self.SetCurrImage(1,1)
Else
Self.SetCurrImage(2,1)
Endif
End
End
'***************************************
Class ftGuiTextfield Extends ftGuiGadget
Field hasShadow:Bool = False
Field shadowX:Float = 2.0
Field shadowY:Float = 2.0
Field hasFocus:Bool = True
'-----------------------------------------------------------------------------
Method GetFocus:bool()
Return Self.hasFocus
End
'-----------------------------------------------------------------------------
Method Render:Void(xoff:Float=0.0, yoff:Float=0.0)
Local xAlpha:Float = Self.GetAlpha()
Local xColor:Float[]
If Self.hasShadow = True
xAlpha = Self.GetAlpha()
xColor = Self.GetColor()
Self.SetColor(50,50,50)
Self.SetAlpha(xAlpha-0.3)
Super.Render(xoff+Self.shadowX, yoff+Self.shadowY)
Self.SetColor(xColor[0],xColor[1],xColor[2])
Self.SetAlpha(xAlpha)
Endif
Super.Render(xoff, yoff)
End
'-----------------------------------------------------------------------------
Method SetFocus:Void(focus:Bool = True)
Self.hasFocus = focus
End
'-----------------------------------------------------------------------------
Method SetShadowOffset:Void(xOff:Float, yOff:Float)
Self.shadowX = xOff
Self.shadowY = yOff
End
'------------------------------------------
Method Update:Void(delta:Float=1.0)
Super.Update(delta)
If Self.GetFocus()= False Then Return
Local char:Int
Local s:string
Repeat
char=GetChar()
If Not char Exit
'Print char
s = Self.GetText()
If char = 8
Self.SetText(s[0..(s.Length()-1)])
Elseif char>=32
Self.SetText(s+String.FromChar( char ))
Endif
Forever
End
End
#rem
footer:This fantomEngine framework is released under the MIT license:
[quote]Copyright (c) 2011-2016 Michael Hartlef
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the software, and to permit persons to whom the software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
[/quote]
#end