-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreactiveWidgets.dog
More file actions
797 lines (742 loc) · 34 KB
/
reactiveWidgets.dog
File metadata and controls
797 lines (742 loc) · 34 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
// Some Reactive Widgets
struct GLOBAL{
me fontSpec: editFont
me Map<int32, int>: charWidths
me GUI_Scalar: drawWrappedText(our dashDrawing: dr, me int: posX, me int: posY, me int: width, me string: text, their fontSpec: font) <- {
me int: curY <- posY + font.headerY
while(text!=""){
me int: chOnLine <- font.getCharPosFromWidth(text, width)
if(text.size()<chOnLine){chOnLine<-text.size()}
dr.addTF(cmdRenderText, posX, curY, text.subStr(0, chOnLine), font)
text <- text.subStr(chOnLine)
curY <- curY + font.height
}
return(curY-posY-font.headerY)
}
me GUI_Scalar: WrappedTextHeight(me int: width, me string: text, their fontSpec: font) <- {
me int: curY <- 0
while(text!=""){
me int: chOnLine <- font.getCharPosFromWidth(text, width)
if(text.size()<chOnLine){chOnLine<-text.size()}
text <- text.subStr(chOnLine)
curY <- curY + font.height
}
return(curY)
}
}
struct WindowControl: inherits=ReactiveControl{
void: drawHeader(our dashDrawing: dr, our ParamRec: PR) <- {
// dragging header
if(proactiveGUI.guiModelManager.isPovTopWindow(PR.sourcePov)){dr.addC(cmdSetColor, topTextColr)}
else{dr.addC(cmdSetColor, surfaceBkgnd)}
me GuiCoords:HedrRectXYWH{PR.posX, PR.posY, PR.posW, headerHeight-2}
// Block click-under
our ProactEvent:: blockEvents;
blockEvents.setTrigger(tPrimaryClick, HedrRectXYWH, PR.topPov); blockEvents.setGUI_Event1(eBlockEvents)
proactiveGUI.presenter.registerEvent(blockEvents)
dr.addRAA(cmdRoundTopRect, HedrRectXYWH, 15)
dr.add1(cmdFill)
dr.addC(cmdSetColor, titleTextColr)
dr.addTF(cmdRenderTextCentered, PR.posX+(PR.posW/2), PR.posY+(headerHeight/2)+(styler.smallFont.height/2-3), PR.title, styler.smallFont)
if(PR.screenPos!=NULL){
our ProactEvent:: dragEvent
dragEvent.setTrigger(tDragStart, HedrRectXYWH); dragEvent.setInfonEvent(eGUI_SetXY, PR.xPov, PR.yPov)
proactiveGUI.presenter.registerEvent(dragEvent)
}
}
}
struct TimeView: inherits=ReactiveControl{
void: draw(our dashDrawing: dr, our ParamRec: PR) <- {
me string: itemID <- PR.sourcePov.mySymbol()
me string: timeIdxID <- itemID+"/timeIdx"
me int: timeIdx <- proactiveGUI.presenter.modelMgr.getInt64(timeIdxID, 0)
//print("TIME_DRAW idx:",timeIdx,"\n")
me int: height <- 200
me int: width <- 300
me GuiCoords:RA{PR.posX, PR.posY, width, height}
me GuiCoords:RA1{PR.posX+(width/2)-50, PR.posY+height-25, 16, 16}
proactiveGUI.presenter.drawCircleButton(dr, RA1.X, RA1.Y, 10, 2, "<", itemID+"/prev")
our ProactEvent:: prevTimeEvent;
prevTimeEvent.setTrigger(tPrimaryClick, RA1, PR.sourcePov)
prevTimeEvent.setGUI_Store_Int1(timeIdxID, max(0, timeIdx-1))
proactiveGUI.presenter.registerEvent(prevTimeEvent)
me GuiCoords:RA2{PR.posX+(width/2)+50, PR.posY+height-25, 16, 16}
proactiveGUI.presenter.drawCircleButton(dr, RA2.X, RA2.Y, 10, 2, ">", itemID+"/next")
our ProactEvent:: nextTimeEvent;
nextTimeEvent.setTrigger(tPrimaryClick, RA2, PR.sourcePov)
me int: minIdx <- max(0, PR.sourcePov.pItem.value.items.size()-1)
nextTimeEvent.setGUI_Store_Int1(timeIdxID, min(minIdx, timeIdx+1))
proactiveGUI.presenter.registerEvent(nextTimeEvent)
our POV: displayPov <- PR.sourcePov.pItem.value.items.at(timeIdx)
//print("\nTIME pov: "+displayPov.stringify())
if(displayPov!=NULL){
our ParamRec:: innerPR; innerPR.init(displayPov, PR.posX, PR.posY, width, height)
if(proactiveGUI.presenter.itemIsThing(PR.sourcePov.pItem.value.listSpec)){innerPR.viewStyleTag <- "3DThing"}
else{innerPR.viewStyleTag <- proactiveGUI.presenter.chooseviewStyleTag(innerPR)}
proactiveGUI.presenter.drawItem(dr, innerPR)
}
}
}
struct StuffView: inherits=WindowControl{
void: draw(our dashDrawing: dr, our ParamRec: PR) <- {
me int: height <- 200
me int: width <- 300
me GuiCoords:RA{PR.posX, PR.posY, width, height}
dr.addC(cmdSetColor, surfaceBkgnd)
dr.addRAA(cmdRoundRect, RA, 15)
dr.add1(cmdFill)
PR.posW <- width
PR.posH <- height
PR.title <- PR.sourcePov.pItem.type.asGiven
drawHeader(dr, PR)
//print("\n____________________________\nSTUFF pov: "+PR.sourcePov.stringify()+"\n____________________________")
proactiveGUI.presenter.draw_X_stack_XYwh(dr, PR)
}
}
struct KanbanView: inherits=WindowControl{
void: draw(our dashDrawing: dr, our ParamRec: PR) <- {
// Draw Columns
our ParamRec:: listPR; listPR.init(PR.dataPov, PR.posX, PR.posY+headerHeight, 0, 0)
listPR.topPov <- PR.sourcePov
listPR.viewStyleTagArg <- "headeredVList"
proactiveGUI.presenter.draw_X_stack_XYwh(dr, listPR)
PR.posW <- listPR.posW
PR.posH <- listPR.posH+headerHeight
drawHeader(dr, PR)
me GuiCoords:RA1{PR.posX+listPR.posW-25, PR.posY+3, 16, 16}
proactiveGUI.presenter.drawCircleButton(dr, RA1.X, RA1.Y, RA1.W/2, 3, "+", PR.sourcePov.mySymbol()+"AddItem")
our ProactEvent:: addListEvent;
addListEvent.setTrigger(tPrimaryClick, RA1, PR.topPov); addListEvent.setInfonEvent(eAddInfon, PR.dataPov, NULL) // ADD New Column
proactiveGUI.presenter.registerEvent(addListEvent)
}
}
struct GLOBAL{ // Temp code to do rotating cube
me int: frameNumber
}
struct Scene3D: inherits=ReactiveControl{
void: tmp_colorCube(our Thing3D: result, me float: arg, me cdColor: top, me cdColor: front, me cdColor: right, me cdColor: bottom, me cdColor: back, me cdColor: left) <- {
me Triangle3D: t1;
our Thing3D: t3d
our Mesh: mesh
me double: hArg <- arg/2
me double: nArg <- -hArg
Allocate(t3d); Allocate(mesh)
t3d.thingMatx.makeIdentity()
t1.INIT(nArg, nArg, nArg, nArg, hArg, nArg, hArg, hArg, nArg); t1.setColor(front); mesh.tris.append(t1)
t1.INIT(nArg, nArg, nArg, hArg, hArg, nArg, hArg, nArg, nArg); mesh.tris.append(t1); t3d.meshes.append(mesh)
result.addPart(t3d)
Allocate(t3d); Allocate(mesh)
t3d.thingMatx.makeIdentity()
t1.INIT(hArg, nArg, nArg, hArg, hArg, nArg, hArg, hArg, hArg); t1.setColor(right); mesh.tris.append(t1)
t1.INIT(hArg, nArg, nArg, hArg, hArg, hArg, hArg, nArg, hArg); mesh.tris.append(t1); t3d.meshes.append(mesh)
result.addPart(t3d)
Allocate(t3d); Allocate(mesh)
t3d.thingMatx.makeIdentity()
t1.INIT(hArg, nArg, hArg, hArg, hArg, hArg, nArg, hArg, hArg); t1.setColor(back); mesh.tris.append(t1)
t1.INIT(hArg, nArg, hArg, nArg, hArg, hArg, nArg, nArg, hArg); mesh.tris.append(t1); t3d.meshes.append(mesh)
result.addPart(t3d)
Allocate(t3d); Allocate(mesh)
t3d.thingMatx.makeIdentity()
t1.INIT(nArg, nArg, hArg, nArg, hArg, hArg, nArg, hArg, nArg); t1.setColor(left); mesh.tris.append(t1)
t1.INIT(nArg, nArg, hArg, nArg, hArg, nArg, nArg, nArg, nArg); mesh.tris.append(t1); t3d.meshes.append(mesh)
result.addPart(t3d)
Allocate(t3d); Allocate(mesh)
t3d.thingMatx.makeIdentity()
t1.INIT(nArg, hArg, nArg, nArg, hArg, hArg, hArg, hArg, hArg); t1.setColor(top); mesh.tris.append(t1)
t1.INIT(nArg, hArg, nArg, hArg, hArg, hArg, hArg, hArg, nArg); mesh.tris.append(t1); t3d.meshes.append(mesh)
result.addPart(t3d)
Allocate(t3d); Allocate(mesh)
t3d.thingMatx.makeIdentity()
t1.INIT(hArg, nArg, hArg, nArg, nArg, hArg, nArg, nArg, nArg); t1.setColor(bottom); mesh.tris.append(t1)
t1.INIT(hArg, nArg, hArg, nArg, nArg, nArg, hArg, nArg, nArg); mesh.tris.append(t1); t3d.meshes.append(mesh)
result.addPart(t3d)
}
me cdColor: getColorFromHue(our POV: huePov) <- {
me cdColor: retColor <- Styler.Gray
if(huePov){
me int: hue <- huePov.pItem.fetchInt()
switch(hue){
case 0:{retColor <- Styler.Red}
case 4:{retColor <- Styler.Blue}
case 30:{retColor <- Styler.Orange}
case 55:{retColor <- Styler.Yellow}
case 110:{retColor <- Styler.Green}
case 185:{retColor <- Styler.Cyan}
case 160:{retColor <- Styler.Purple}
case 300:{retColor <- Styler.Magenta}
case 345:{retColor <- Styler.Pink}
}
}
return(retColor)
}
our Thing3D: attempt3DDraw(our POV:stuffPov, our ParamRec: PR, our Window3D: win3D) <- {
me string: objType <- stuffPov.pItem.getTypeStr()
//if(!proactiveGUI.presenter.itemIsThing(stuffPov.pItem)){return(NULL)}
//print("\n\n3D objType: "+objType)
//print("\n\n3D pov: "+stuffPov.stringify())
me int: height <- 200
me int: width <- 300
win3D.setUpMatrixes(90.0, PR.posX, PR.posY, width, height)
win3D.lightSources <- lightSources
our Thing3D::thing
our POV: thingPov <- fetchField(stuffPov, "thing")
// Get Location
our POV: locationPov <- fetchField(thingPov, "location")
me double: xLoc; me double: yLoc; me double: zLoc;
if(locationPov){
our POV: xLocPov <- fetchField(locationPov, "xloc")
our POV: yLocPov <- fetchField(locationPov, "yloc")
our POV: zLocPov <- fetchField(locationPov, "zloc")
if(xLocPov){xLoc <- fetchDblFloatField(xLocPov)}
if(yLocPov){yLoc <- fetchDblFloatField(yLocPov)}
if(zLocPov){zLoc <- fetchDblFloatField(zLocPov)}
//print("\nLOC: x:", xLoc," y:",yLoc," z:",zLoc,"\n")
}
// Get Color
our POV: colorPov <- fetchField(stuffPov, "color")
if(colorPov==NULL and thingPov!=NULL){colorPov <- fetchField(thingPov, "color")}
if(colorPov){
our POV: huePov <- fetchField(colorPov, "hue")
if(huePov){
thing.color <- getColorFromHue(huePov)
}
}else{
thing.color <- Styler.Gray
}
// Get orientation
our POV: orientationPov <- fetchField(thingPov, "orientation")
me double: xOri; me double: yOri; me double: zOri;
if(orientationPov){
our POV: xRot <- fetchField(orientationPov, "xrot")
our POV: yRot <- fetchField(orientationPov, "yrot")
our POV: zRot <- fetchField(orientationPov, "zrot")
if(xRot){xOri <- fetchDblFloatField(xRot)}
if(yRot){yOri <- fetchDblFloatField(yRot)}
if(zRot){zOri <- fetchDblFloatField(zRot)}
//print("\nORIENT: x:", xOri," y:",yOri," z:",zOri,"\n")
}
our infon:: item
our WordUse:: word
item.type <- word
word.setAsGiven("rubixstate")
if(stuffPov.pItem.type!=NULL and stuffPov.pItem.isCompatibleWith(item, false)){
xOri <+- frameNumber * 0.03
yOri <+- frameNumber * 0.06
zOri <+- frameNumber * 0.00
frameNumber <+- 1
}
thing.name <- objType // TODO: This could be a better name. It's for debugging.
thing.setScale(1.0, 1.0, 1.0)
thing.rotateX(xOri)
thing.rotateY(yOri)
thing.rotateZ(zOri)
thing.setLocation(xLoc, yLoc, zLoc)
thing.calcThingMatx(mat4ID)
me int: strLen <- objType.size()
if(strLen>4){if(objType.subStr(strLen-4)=="cube"){objType<-"colorcube"}}
switch(objType){
case "rectangle":{}
case "cube":{
our Mesh:: cubeMesh; meshGenerator.generateMesh(cubeMesh, "cube", 2, 0)
thing.meshes.append(cubeMesh)
}
case "colorcube":{
our POV: sides <- fetchListField(stuffPov, "side")
me cdColor: topColor <- thing.color
me cdColor: bottomColor <- thing.color
me cdColor: leftColor <- thing.color
me cdColor: rightColor <- thing.color
me cdColor: frontColor <- thing.color
me cdColor: backColor <- thing.color
if(sides!=NULL){
our POV: side <- sides.pItem.value.items.head
me int: count <- 0
while(side != NULL){
our POV: colorPov <- fetchField(side, "color")
if(colorPov){
our POV: huePov <- fetchField(colorPov, "hue")
me cdColor: sideColor
if(huePov){
me cdColor: color <- getColorFromHue(huePov)
switch(count){
case 0: {topColor <- color}
case 1: {frontColor <- color}
case 2: {rightColor <- color}
case 3: {bottomColor <- color}
case 4: {backColor <- color}
case 5: {leftColor <- color}
}
}
}
count <+- 1
side <- side.next
}
}
tmp_colorCube(thing, 1, topColor, frontColor, rightColor, bottomColor, backColor, leftColor)
}
case "pipe":{}
case "cone":{}
case "cylinder":{
our Mesh:: cylinderMesh; meshGenerator.genCylinder(cylinderMesh, 1.56, 0.07, 0.07, 20, true, true)
thing.meshes.append(cylinderMesh)
}
case "pyramid":{}
default:{
our POV: p <- stuffPov.pItem.value.items.head
while(p != NULL){
our Thing3D: object <- attempt3DDraw(p, PR, win3D)
if(object!=NULL){
thing.addPart(object)
}
p <- p.next
}
}
}
return(thing)
}
me bool: keyTyped(their GUI_KeyboardEvent: event) <- {
print("KEYTPED:\n")
me int32: cmd <- event.keyval
if((event.state & CONTROL_MASK) or cmd == 127 or cmd > 255){
me bool: cmdHandled <- false;
if(!cmdHandled){
if(event.state & CONTROL_MASK) {
switch(cmd){
case KEY_a: {} // CTRL-A - Select all
case KEY_c: {} // CTRL-C - Copy
case KEY_v: {}
}
} else {
switch(cmd){
case KEY_w: {}// win3D.matProj.makeRotationX(xRot); xRot <+- 0.1}
case KEY_s: {}
case KEY_a: {}
case KEY_d: {}
case KEY_LEFT: {}
case KEY_RIGHT: {}
case KEY_HOME: {}
case KEY_END: {}
case KEY_DELETE: {}
case KEY_RETURN: {}
case KP_LEFT: {}
case KP_RIGHT: {}
case KP_HOME: {}
case KP_END: {}
case KP_DELETE: {}
case KP_ENTER: {}
case KEY_BACKSPACE: {}
case KEY_ESCAPE: {}
}
}
}
}
slipView.requestRedraw()
//print("KEY_PRESS:",event.keyval, " ==>", crntLine, "\n")
return(true)
}
void: draw(our dashDrawing: dr, our ParamRec: PR) <- {
our Window3D:: win3D
our Thing3D: object <- attempt3DDraw(PR.sourcePov, PR, win3D)
if(object!=NULL){dr.add3D(object, win3D)}
}
}
struct TextEditBox: inherits=ReactiveControl{
me bool: multiLineMode
our ParamRec: thisPR
me string: crntLine
me int: widthToCur
me int: charsToCur
me int: curMax // Most recent width to cursor
their strBuf: inputBuf // The buffer for this
me bool: overwriteMode // False = InsertMode
const int: leftXPad <- 10
void: setMetrics(our ParamRec: PR) <- {
me string: text <- PR.sourcePov.pItem.value.str
me deltaSize: DSize <- getTextSize(text, PR.font)
PR.posW <- DSize.width + Yborder*2
PR.posH <- DSize.height + 10*2 // 10 px on top and bottom
}
me int: calcWidthToCursor(me string: line, me int: charsToCur) <- {
me int: wtc <- 0
withEach p in range 0 .. charsToCur {
wtc <+- thisPR.font.getCharWidthX1024(line[p])
}
return(wtc/1024)
}
me void: setCursorByWidth(me string: line, me int: maxWidthToCur) <- {
me int32: wtc <- 0
me int: p <- 0
if(line.size()==0){charsToCur<-0; widthToCur<-0; return();}
withEach count in range 0 .. line.size() {
me int: chrWidth <- thisPR.font.getCharWidth(line[p])
if(wtc+(chrWidth/2) >= maxWidthToCur){break()}
wtc <+- chrWidth
p <+- 1
}
charsToCur<-p
widthToCur<-wtc
}
void: insertChar(me int32: chr) <- {
if (!overwriteMode){
me string: S; S <+- chr
crntLine.insert(charsToCur, S)
charsToCur <+- 1
widthToCur <+- thisPR.font.getCharWidth(chr)
if(inputBuf.interactiveMode){
//if(thisPR.parentCtrlsData!=NULL){
inputBuf.putTentativeStr(S)
//}
}
} else {} // TODO: Overwrite mode
curMax<-widthToCur
}
void: moveLeft() <- {
if(charsToCur>0){
charsToCur <-- 1
widthToCur <-- thisPR.font.getCharWidth(crntLine[charsToCur])
curMax <- widthToCur
} /*else if(!isFirstInSet(currentLine)){
moveUp();
moveEnd();
}*/
}
void: moveRight() <- {
if(charsToCur < crntLine.size()){
widthToCur <+- thisPR.font.getCharWidth(crntLine[charsToCur])
charsToCur <+- 1
curMax<-widthToCur
} /*else if(!isLastInSet(currentLine)){
moveDown()
moveHome()
}*/
}
void: moveHome() <- {
charsToCur<-0
widthToCur<-0
curMax<-widthToCur
}
void: moveEnd() <- {
charsToCur<-crntLine.size()
widthToCur<-calcWidthToCursor(crntLine, charsToCur)
curMax<-widthToCur
}
void: doDelete() <- {
if(charsToCur==crntLine.size()){return()}
crntLine.erase(charsToCur,1)
widthToCur <- calcWidthToCursor(crntLine, charsToCur)
curMax <- widthToCur
}
void: backspc() <- {if(charsToCur>0){moveLeft(); doDelete();}}
void: revert() <- {
crntLine <- thisPR.sourcePov.pItem.value.str
moveEnd()
}
void: draw(our dashDrawing: dr, our ParamRec: PR) <- {
dr.addC(cmdSetColor, styler.White)
me string: text
me string: prompt
if(PR.title!=""){
prompt<-PR.title
if(prompt=="NO_PROMPT"){prompt<-""}
} else if(PR.sourcePov.pItem.type!=NULL){
prompt <- PR.sourcePov.pItem.type.asGiven+": "
prompt <- deCamelCase(prompt)
}
text <- PR.dataPov.pItem.value.str
me int: labelY_offset <- 0
me int: labelX_offset <- 0
me string: GDR_ID <- PR.dataPov.mySymbol()+"/editBox"
our GuiDataRec: textBoxGDR <- proactiveGUI.presenter.modelMgr.fetchGuiData(GDR_ID)
if(textBoxGDR!=NULL){isActive <- textBoxGDR.isActive}
else{
Allocate(textBoxGDR); proactiveGUI.presenter.modelMgr.guiData[GDR_ID]<-textBoxGDR
if(PR.startActive) {isActive<-1; proactiveGUI.presenter.grabFocus(GDR_ID)} else {isActive<-0}
}
if(isActive==0){
dr.addC(cmdSetColor, cdColor(200,200,200,200))
me GuiCoords:myCoords{PR.posX, PR.posY, PR.posW, PR.posH}
dr.addRA(cmdDrawRect, myCoords)
dr.add1(cmdFill)
// Draw the label
if(prompt!=""){
labelY_offset <- 10
labelX_offset <- leftXPad
dr.addC(cmdSetColor, styler.Black)
dr.addTF(cmdRenderText, PR.posX+labelX_offset/2, PR.posY+PR.posH/2+(styler.smallFont.height/2)-4-8, prompt, styler.smallFont)
dr.add1(cmdFill)
}
// Draw the text
dr.addC(cmdSetColor, styler.Black)
dr.addTF(cmdRenderText, PR.posX+labelX_offset, PR.posY+PR.posH/2+(PR.font.height/2)-4+labelY_offset, text, PR.font)
dr.add1(cmdFill)
our ProactEvent:: clickEvent;
clickEvent.setTrigger(tPrimaryClick, myCoords); clickEvent.setGUI_SetActiveFlag(GDR_ID, 1)
proactiveGUI.presenter.registerEvent(clickEvent)
} else {
our TextEditBox: TEBox
if(prompt!=""){labelX_offset <- leftXPad}
if(isActive==1){ // This is first time; init GDR
textBoxGDR.isActive <- 2 // Set 'not first time'
textBoxGDR.str1 <- prompt
Allocate(TEBox)
textBoxGDR.ctrl <- TEBox
TEBox.thisPR <- PR
TEBox.inputBuf<- asClass(TerminalApp, PR.parentCtrlsData.ctrl).iStream.source.inputBuf
TEBox.inputBuf.interactiveMode <- true
TEBox.inputBuf.pre_parse_only <- true
TEBox.crntLine <- text
TEBox.moveEnd()
} else {TEBox <- asClass(TextEditBox, textBoxGDR.ctrl)}
dr.addC(cmdSetColor, cdColor(200,230,200,200))
me GuiCoords:myCoords{PR.posX, PR.posY, PR.posW, PR.posH}
dr.addRA(cmdDrawRect, myCoords)
dr.add1(cmdFill)
me GUI_Scalar: xPos <- PR.posX+labelX_offset
me GUI_Scalar: yPos <- PR.posY+PR.posH/2+(PR.font.height/2)-4
dr.addC(cmdSetColor, PR.foreGnd)
dr.addTF(cmdRenderText, xPos, yPos, TEBox.crntLine, PR.font)
dr.add1(cmdFill)
me GUI_Scalar: cursorPos <- xPos + TEBox.widthToCur
drawACursor(dr, cursorPos, yPos, PR.font.height)
our ProactEvent:: clickEvent;
clickEvent.setTrigger(tPrimaryClick, myCoords); clickEvent.setGUI_CallFunc(ePrimaryClick, GDR_ID)
proactiveGUI.presenter.registerEvent(clickEvent)
}
}
void: saveBack() <- {
thisPR.dataPov.pItem.value.str <- crntLine
isActive<-false
inputBuf.pre_parse_only <- false
if(inputBuf.interactiveMode){inputBuf.notifyWaitingThread()}
// If parent exists, send buffer to it.
if(thisPR.parentCtrlsData!=NULL){
thisPR.parentCtrlsData.ctrl.processEntry(crntLine)
}
}
me int32: newLine <- 10
void: handleEnter() <- {
if(inputBuf.interactiveMode){
insertChar(newLine)
}
saveBack()
}
me bool: expandsX()<-{return(true)}
me bool: expandsY()<-{return(false)}
me bool: mouseMoved(me GUI_Scalar:posX, me GUI_Scalar:posY) <- {
return(true)
}
me bool: primaryClick(me GUI_Scalar:posX, me GUI_Scalar:posY) <- {
setCursorByWidth(crntLine, posX-(thisPR.posX+leftXPad))
print("TEXTEDIT_BOX_CLICK!:",posX-(thisPR.posX+leftXPad), "\n")
return(true)
}
me bool: keyTyped(their GUI_KeyboardEvent: event) <- {
me int32: cmd <- event.keyval
if((event.state & CONTROL_MASK) or cmd == 127 or cmd > 255){
me bool: cmdHandled <- false;
if(multiLineMode){} // handle multiline cmds then set cmdHandled<-true
if(!cmdHandled){
if(event.state & CONTROL_MASK) {
switch(cmd){
case KEY_a: {} // CTRL-A - Select all
case KEY_c: {} // CTRL-C - Copy
case KEY_v: { // CTRL-V - Paste
our string: pText <- getClipboardAsText()
if(pText!=NULL){
me int: txtSz <- pText.size()
withEach pos in range 0 .. txtSz {
me int32: chAtPos <- pText[pos]
insertChar(chAtPos)
}
}
}
case KEY_m: {inputBuf.pre_parse_only <- false; inputBuf.notifyWaitingThread()} // CTRL-M submit
case KEY_s: {thisPR.sourcePov.pItem.value.str <- crntLine} // CTRL-S - Save back
case 23: {} // CTRL-W - Toggle word-wrap Mode
case 24: {} // CTRL-X - Cut
case 25: {} // CTRL-Y - Redo
case 26: {} // CTRL-Z - Undo
}
} else {
switch(cmd){
case KEY_LEFT: {moveLeft()}
case KEY_RIGHT: {moveRight()}
case KEY_HOME: {moveHome()}
case KEY_END: {moveEnd()}
case KEY_DELETE: {doDelete()}
case KEY_RETURN: {handleEnter()}
case KP_LEFT: {moveLeft()}
case KP_RIGHT: {moveRight()}
case KP_HOME: {moveHome()}
case KP_END: {moveEnd()}
case KP_DELETE: {doDelete()}
case KP_ENTER: {handleEnter()}
case KEY_BACKSPACE: {backspc()}
case KEY_ESCAPE: {revert()}
}
}
}
} else {
insertChar(event.keyval)
}
slipView.requestRedraw()
//print("KEY_PRESS:",event.keyval, " ==>", crntLine, "\n")
return(true)
}
void: INIT() <- {
widthToCur<-0
charsToCur<-0
multiLineMode <- false
}
}
///////////////////////// TerminalApp
struct TerminalApp: inherits=WindowControl{
our GuiDataRec: GDR
our InfonStream: iStream
our ParamRec: thisPR
// checkParseStatus: // THESE ARE DUPLICATES FROM PARSER AND MUST MATCH!
const int: valid_EOB <- -1
const int: valid_notDone <- 1
const int: valid_maybeDone <- 2
const int: valid_done <- 3
const int: syntax_error <- 4
const int: other_error <- 5
void: draw(our dashDrawing: dr, our ParamRec: PR) <- {
me int: height <- 400
me int: width <- 500
me GuiCoords:RA{PR.posX, PR.posY, width, height}
dr.addC(cmdSetColor, surfaceBkgnd)
dr.addRAA(cmdRoundRect, RA, 15)
dr.add1(cmdFill)
// Block click-under
our ProactEvent:: blockEvents;
blockEvents.setTrigger(tPrimaryClick, RA, PR.topPov); blockEvents.setGUI_Event1(eBlockEvents)
proactiveGUI.presenter.registerEvent(blockEvents)
PR.posW <- width
PR.posH <- height
drawHeader(dr, PR)
// Fetch App Streams
me string: GDR_ID <- PR.sourcePov.mySymbol()+"/terminalApp"
our GuiDataRec: termBoxGDR <- proactiveGUI.presenter.modelMgr.fetchGuiData(GDR_ID)
isActive <- 0
our TerminalApp: TermApp
if(termBoxGDR!=NULL){isActive <- termBoxGDR.isActive}
else{Allocate(termBoxGDR); proactiveGUI.presenter.modelMgr.guiData[GDR_ID]<-termBoxGDR}
if(isActive==0){ // This is first time; init GDR
log("DRAW_TERM_INIT()")
Allocate(TermApp)
termBoxGDR.isActive <- 1 // Set 'not first time'
termBoxGDR.ctrl <- TermApp
log("DRAW_TERM_CONNECTOR:"+drctLocator)
TermApp.iStream <- CORE.connectionMgr.user.appendAnInfonAndLoad(CORE.connectionMgr, drctLocator)
TermApp.thisPR <- PR
TermApp.GDR <- termBoxGDR
our DrctConnector: DConn <- asClass(DrctConnector, TermApp.iStream.source)
DConn.termToConnect <- TermApp
} else {TermApp <- asClass(TerminalApp, termBoxGDR.ctrl)}
// Calc which entries appear in window
me int64: editWidth <- width
me int64: lineHeight <- styler.smallFont.height
me int64: heightACC <- headerHeight
their PovList: dataItems <- PR.dataPov.pItem.value.items
if(dataItems.isEmpty()){
our POV: newPov <- PR.dataPov.tryAddingTentativeChild()
newPov.pItem.infCharPos <- 0
}
our POV: pov <- dataItems.back()
while(pov){
our POV: dataInf <- safeFetchField(pov, "data")
me string: entryText <- fetchStringField(dataInf)
me GUI_Scalar: textHeight <- WrappedTextHeight(PR.posW-10,shortedStr(entryText,295), styler.smallFont)
heightACC <+- textHeight
if(heightACC>=height-headerHeight){break()}
pov <- pov.prev
}
if(pov==NULL){pov <- dataItems.front()}
// Draw contents
me int: xCur <- PR.posX+5
me int: yCur <- PR.posY+headerHeight
me int: crntLineNum <- 0
while(pov!=NULL and pov!==dataItems.back()){
our POV: propertiesInf <- safeFetchField(pov, "properties")
our POV: dataInf <- safeFetchField(pov, "data")
me string: sourceID <- fetchStringField(safeFetchField(propertiesInf, "sourceid"))
me int64: entryWidth <- fetchIntField(safeFetchField(propertiesInf, "width"))
me int64: numLines <- entryWidth/editWidth+1
me string: entryText <- fetchStringField(dataInf)
// log(" ENTRY_TEXT:[" + entryText + "]")
if(sourceID=="agent:RESULT"){dr.addC(cmdSetColor, styler.Yellow)}
else if(sourceID=="agent:SYSERR"){dr.addC(cmdSetColor, styler.Red)}
else if(sourceID=="agent:SYNERR"){dr.addC(cmdSetColor, styler.Pink)}
else if(sourceID=="agent:NRMERR"){dr.addC(cmdSetColor, styler.Green)}
else {dr.addC(cmdSetColor, titleTextColr)}
me GUI_Scalar: textHeight <- drawWrappedText(dr, xCur, yCur, PR.posW-10, shortedStr(entryText,295), styler.smallFont)
yCur <+- textHeight
crntLineNum <+- numLines
pov <- pov.next
}
// Draw the currently-being-edited line
our ParamRec:: innerPR; innerPR.init(dataItems.back(), xCur, yCur, width-10, lineHeight)
innerPR.topPov <- PR.topPov
innerPR.font <- styler.smallFont
innerPR.title <- "NO_PROMPT"
innerPR.parentCtrlsData <- termBoxGDR
innerPR.viewStyleTagArg <- "_edit"
innerPR.viewStyleTag <- "genericstring_edit"
innerPR.viewStyleCtrl <- widgetMngr.getviewStyleTagCtrl("genericstring_edit")
me int64: parseStatus <- 0
if(TermApp.iStream!=NULL){parseStatus <- TermApp.iStream.source.inputBuf.consumerStatus}
//print("PARSE_STATUS:",parseStatus,"\n")
switch(parseStatus){
case valid_notDone: {innerPR.foreGnd <- styler.Magenta}
case valid_maybeDone:{innerPR.foreGnd <- styler.Blue}
case valid_done: {innerPR.foreGnd <- styler.DarkGreen}
case syntax_error: {innerPR.foreGnd <- styler.Red}
case other_error: {innerPR.foreGnd <- styler.Red}
default: {innerPR.foreGnd <- styler.Black}
}
if(proactiveGUI.presenter.modelMgr.isPovTopWindow(PR.topPov)){innerPR.startActive <- true}
proactiveGUI.presenter.drawItem(dr, innerPR)
}
void: processResult(me string: buffer) <- { // Process result messages from parse / extract / normalize
log("PROCESS_RESULT:" + buffer + "\n")
// Extract result-type, charPos, mesg
me string: resultType <- buffer.subStr(0,6)
buffer <- buffer.subStr(7)
me int: colonPos <- buffer.find(":")
me uint64: charPos <- stol(buffer.subStr(0,colonPos))
buffer <- buffer.subStr(colonPos+1)
our infon: newInfon <- thisPR.dataPov.makePotentialMemberInfon()
newInfon.infCharPos <- charPos // Remember our position in the stream
// Now search backwards to find the correct slot to insert this.
our POV: prevPov <- thisPR.dataPov.pItem.value.items.back()
while(prevPov!=NULL and prevPov.pItem.infCharPos > charPos){
prevPov <- prevPov.prev
}
our POV: newPov <- thisPR.dataPov.pItem.value.items.insertAfter(prevPov, newInfon, 2000)
if(newPov!=NULL){
our POV: newProps <- safeFetchField(newPov, "properties")
our POV: dataInf <- safeFetchField(newPov, "data")
our POV: newSrcID <- safeFetchField(newProps, "sourceid")
dataInf.pItem.value.format <- fLiteral
dataInf.pItem.value.str <- buffer
newSrcID.pItem.value.format <- fLiteral
newSrcID.pItem.value.str <- "agent:"+resultType
}
}
void: processEntry(me string: buffer) <- {
// This runs when user hits Enter: submits text on terminal.
if(iStream!=NULL and !iStream.source.inputBuf.interactiveMode){
iStream.pushParserInputBuf(buffer+"\n")
}
our POV: newPov <- thisPR.dataPov.tryAddingTentativeChild()
if(newPov!=NULL){
newPov.pItem.infCharPos <- iStream.source.inputBuf.crntStreamSize
our POV: newProps <- safeFetchField(newPov, "properties")
our POV: newSrcID <- fetchField(newProps, "sourceid")
if(newSrcID==NULL){} //DO_NOW: MAKE AND PLACE SourceID
newSrcID.pItem.value.format <- fLiteral
newSrcID.pItem.value.str <- "user"
}
}
}