-
Notifications
You must be signed in to change notification settings - Fork 5
/
gedialog_gadgets.cpp
1416 lines (1149 loc) · 38.5 KB
/
gedialog_gadgets.cpp
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
#include "c4d.h"
#include "main.h"
#include "c4d_symbols.h"
//----------------------------------------------------------------------------------------
/// This example shows how to create a GeDialog and how to handle different types of GUI elements.
//----------------------------------------------------------------------------------------
// custom gui headers
#include "customgui_priority.h"
#include "customgui_hyperlink.h"
#include "customgui_inexclude.h"
#include "c4d_graphview.h"
#include "customgui_datetime.h"
#include "customgui_quicktab.h"
#define ID_MENU_COMMAND 500
#define ID_COMBOBOX 1100
#define ID_BUTTON 1101
#define ID_CONSOLE 1102
#define ID_DYNAMIC_GROUP 2000
#define ID_DYMAMIC_GADGET 1500
// defines for QuickTab example
#define QUICKTAB_NUM_TABS 4 // max 100
// some more IDs for QuickTab example
#define ID_QUICKTAB_GROUP 3000
#define ID_QUICKTAB_SUBDIALOGS 3100
#define ID_QUICKTAB_SUBDIALOG_TITLE 3200
#define ID_QUICKTAB_SUBDIALOG_MAIN_GROUP 3300
#define ID_QUICKTAB_SUBDIALOG_SUBGROUP_TITLE 3400
#define ID_QUICKTAB_SUBDIALOG_SUBGROUP 3500
#define ID_QUICKTAB_SUBDIALOG_SUBGROUP_TEXT 3600
enum DIALOGELEMENTS
{
CHECKBOX = 0,
BUTTON,
STATIC_TEXT,
EDIT_TEXT,
MULTILINE_TEXT,
EDIT_NUMBER,
EDIT_NUMBER_ARROWS,
EDIT_SLIDER,
SLIDER,
COLORFIELD,
COLOR_CHOOSER,
RADIO_BUTTON,
RADIO_TEXT,
RADIO_GROUP,
COMBO_BOX,
COMBO_BUTTON,
POPUP_BUTTON,
// Custom GUIs
CUSTOM_GUI_SPLINE = 100,
CUSTOM_GUI_GRADIENT,
CUSTOM_GUI_PRIORITY,
CUSTOM_GUI_DESCRIPTION,
CUSTOM_GUI_BITMAPBUTTON,
CUSTOM_GUI_HYPERLINK,
CUSTOM_GUI_INEXCLUDE,
CUSTOM_GUI_LINKBOX,
CUSTOM_GUI_DATETIME,
CUSTOM_GUI_QUICKTAB,
// Xpresso GUI
NODEGUI = 200,
// etc.
SCROLLGROUP = 300,
TABGROUPS,
SUBDIALOG,
USERAREA,
DIALOGGROUP,
DUMMY
};
//---------------------------
/// A User Area
//---------------------------
class ExampleUserArea : public GeUserArea
{
public:
virtual Bool GetMinSize(Int32& w, Int32& h);
virtual void DrawMsg(Int32 x1, Int32 y1, Int32 x2, Int32 y2, const BaseContainer& msg);
};
Bool ExampleUserArea::GetMinSize(Int32& w, Int32& h)
{
w = 400;
h = 300;
return true;
}
void ExampleUserArea::DrawMsg(Int32 x1, Int32 y1, Int32 x2, Int32 y2, const BaseContainer& msg)
{
OffScreenOn();
SetClippingRegion(x1, y1, x2, y2);
// background
DrawSetPen(Vector(1.0));
DrawRectangle(x1, y1, x2, y2);
// text
DrawSetTextCol(Vector(0.0f), COLOR_TRANS);
DrawText("This is a GeUserArea"_s, 0, 0, DRAWTEXT_HALIGN_LEFT);
}
//---------------------------
/// A Subdialog
//---------------------------
class ExampleSubDialog: public SubDialog
{
public:
virtual Bool CreateLayout();
};
Bool ExampleSubDialog::CreateLayout()
{
AddStaticText(100, BFH_SCALEFIT | BFV_TOP, 0, 20, "This is a Sub-Dialog"_s, BORDER_ROUND);
return true;
}
//---------------------------
/// Subdialogs displayed in QuickTab
//---------------------------
class QuickTabSubDialog: public SubDialog
{
private:
Bool _flagSubgroupClosed; // this flag is used to track the "folded state" of the subgroup
QuickTabCustomGui* _quickTabSubgroup;
public:
Int32 _dialogIdx;
QuickTabSubDialog();
virtual Bool CreateLayout();
virtual Bool Command(Int32 id, const BaseContainer & msg);
};
QuickTabSubDialog::QuickTabSubDialog()
{
_flagSubgroupClosed = false;
}
Bool QuickTabSubDialog::CreateLayout()
{
BaseContainer bc;
// create a new QuickTab, which is used as title bar for the subdialog
bc.SetInt32(QUICKTAB_BAR, 1);
bc.SetString(QUICKTAB_BARTITLE, "QuickTab #" + String::IntToString(_dialogIdx) + " Subdialog");
QuickTabCustomGui* quickTabGUIBar = static_cast<QuickTabCustomGui*>(AddCustomGui(ID_QUICKTAB_SUBDIALOG_TITLE + _dialogIdx, CUSTOMGUI_QUICKTAB, String(), BFH_SCALEFIT | BFV_TOP, 100, 5, bc));
if (!quickTabGUIBar)
return false;
// a group containing all content of the subdialog (used for easy layout refresh)
GroupBegin(ID_QUICKTAB_SUBDIALOG_MAIN_GROUP + _dialogIdx, BFH_SCALEFIT | BFV_TOP, 1, 0, String(), 0, 400);
GroupBorderSpace(0, 0, 0, 0);
bc.FlushAll();
// another QuickTab, this time it's used as a subgroup title bar (with fold arrow icon)
bc.SetInt32(QUICKTAB_BAR, 1);
bc.SetString(QUICKTAB_BARTITLE, "Subgroup in Subdialog #" + String::IntToString(_dialogIdx));
bc.SetBool(QUICKTAB_BARSUBGROUP, true);
_quickTabSubgroup = static_cast<QuickTabCustomGui*>(AddCustomGui(ID_QUICKTAB_SUBDIALOG_SUBGROUP_TITLE + _dialogIdx, CUSTOMGUI_QUICKTAB, String(), BFH_SCALEFIT | BFV_TOP, 100, 5, bc));
if (!_quickTabSubgroup)
return false;
// group all content of the subgroup (in order to easily hide and unfide the subgroup)
GroupBegin(ID_QUICKTAB_SUBDIALOG_SUBGROUP + _dialogIdx, BFH_SCALEFIT | BFV_TOP, 1, 0, String(), 0, 400);
GroupBorderSpace(10, 0, 10, 0);
// subgroup content
AddStaticText(ID_QUICKTAB_SUBDIALOG_SUBGROUP_TEXT + _dialogIdx, BFH_SCALEFIT | BFV_TOP, 0, 20, "Your content..."_s, 0);
GroupEnd(); // end subgroup
GroupEnd(); // end main group
// finally syncronize "folded state" according to our flag, so arrow direction matches our display state
HideElement(GadgetPtr(ID_QUICKTAB_SUBDIALOG_SUBGROUP + _dialogIdx), _flagSubgroupClosed);
_quickTabSubgroup->Select(0, _flagSubgroupClosed);
return true;
}
Bool QuickTabSubDialog::Command(Int32 id, const BaseContainer & msg)
{
// if the subgroup title bar gets clicked, the subgroup's visibility gets toggled
if (id == (ID_QUICKTAB_SUBDIALOG_SUBGROUP_TITLE + _dialogIdx))
{
_flagSubgroupClosed = !_flagSubgroupClosed;
HideElement(GadgetPtr(ID_QUICKTAB_SUBDIALOG_SUBGROUP + _dialogIdx), _flagSubgroupClosed);
LayoutChanged(ID_QUICKTAB_SUBDIALOG_MAIN_GROUP + _dialogIdx);
}
return SubDialog::Command(id, msg);
}
//---------------------------
/// The example dialog
//---------------------------
class ExampleDialog: public GeDialog
{
private:
// Xpresso Node GUI data
GvShape* _shape;
GvShape* _group;
GvNodeGUI* _nodeGUI;
// Subdialog
ExampleSubDialog _subDialog;
// User Area
ExampleUserArea _userArea;
// QuickTab
QuickTabCustomGui* _quickTabGUI;
QuickTabSubDialog _quickTabSubDialogs[QUICKTAB_NUM_TABS];
Int32 _lastcoremsg_change;
public:
ExampleDialog();
virtual ~ExampleDialog();
virtual Bool CreateLayout();
virtual Bool Command(Int32 id, const BaseContainer & msg);
virtual Bool CoreMessage(Int32 id, const BaseContainer &msg);
private:
void UpdateDialog();
void EnableButton(const int selection);
void AddDynamicElement(const int selection);
void ReadData();
void DataToConsole(const int id);
void HandleQuickTabCommand();
};
ExampleDialog::ExampleDialog()
{
_nodeGUI = nullptr;
_lastcoremsg_change = NOTOK;
};
ExampleDialog::~ExampleDialog()
{
GvWorld* world = GvGetWorld();
if (!world)
return;
if (_shape)
world->FreeShape(_shape);
if (_group)
world->FreeShape(_group);
if (_nodeGUI)
world->FreeNodeGUI(_nodeGUI);
}
Bool ExampleDialog::CreateLayout()
{
SetTitle("Example Dialog"_s);
// Menu
MenuFlushAll();
MenuSubBegin("Menu"_s);
// using Cinema 4D commands
MenuAddCommand(12218);
MenuAddCommand(12098);
MenuAddSeparator();
// custom command
MenuAddString(ID_MENU_COMMAND, "Custom Command"_s);
MenuSubEnd();
MenuFinished();
// Dialog
GroupBegin(1000, BFH_SCALEFIT | BFV_FIT, 2, 0, String(), BFV_BORDERGROUP_FOLD_OPEN, 400);
GroupBorderSpace(10, 10, 10, 0);
AddComboBox(ID_COMBOBOX, BFH_SCALEFIT, 100, 10, false, true);
AddChild(ID_COMBOBOX, (Int32)DIALOGELEMENTS::CHECKBOX, "Checkbox"_s);
AddChild(ID_COMBOBOX, (Int32)DIALOGELEMENTS::BUTTON, "Button"_s);
AddChild(ID_COMBOBOX, (Int32)DIALOGELEMENTS::STATIC_TEXT, "Static Text"_s);
AddChild(ID_COMBOBOX, (Int32)DIALOGELEMENTS::EDIT_TEXT, "Edit Text"_s);
AddChild(ID_COMBOBOX, (Int32)DIALOGELEMENTS::MULTILINE_TEXT, "Multiline Text"_s);
AddChild(ID_COMBOBOX, (Int32)DIALOGELEMENTS::EDIT_NUMBER, "Edit Number"_s);
AddChild(ID_COMBOBOX, (Int32)DIALOGELEMENTS::EDIT_NUMBER_ARROWS, "Edit Number Arrows"_s);
AddChild(ID_COMBOBOX, (Int32)DIALOGELEMENTS::EDIT_SLIDER, "Edit Slider"_s);
AddChild(ID_COMBOBOX, (Int32)DIALOGELEMENTS::SLIDER, "Slider"_s);
AddChild(ID_COMBOBOX, (Int32)DIALOGELEMENTS::COLORFIELD, "Colorfield"_s);
AddChild(ID_COMBOBOX, (Int32)DIALOGELEMENTS::COLOR_CHOOSER, "Color Chooser"_s);
AddChild(ID_COMBOBOX, (Int32)DIALOGELEMENTS::RADIO_BUTTON, "Radio Button"_s);
AddChild(ID_COMBOBOX, (Int32)DIALOGELEMENTS::RADIO_TEXT, "Radio Text"_s);
AddChild(ID_COMBOBOX, (Int32)DIALOGELEMENTS::RADIO_GROUP, "Radio Group"_s);
AddChild(ID_COMBOBOX, (Int32)DIALOGELEMENTS::COMBO_BOX, "Combo Box"_s);
AddChild(ID_COMBOBOX, (Int32)DIALOGELEMENTS::COMBO_BUTTON, "Combo Button"_s);
AddChild(ID_COMBOBOX, (Int32)DIALOGELEMENTS::POPUP_BUTTON, "Popup Botton"_s);
AddChild(ID_COMBOBOX, -1, "..."_s);
AddChild(ID_COMBOBOX, (Int32)DIALOGELEMENTS::CUSTOM_GUI_SPLINE, "CustomGUI Spline"_s);
AddChild(ID_COMBOBOX, (Int32)DIALOGELEMENTS::CUSTOM_GUI_GRADIENT, "CustomGUI Gradient"_s);
AddChild(ID_COMBOBOX, (Int32)DIALOGELEMENTS::CUSTOM_GUI_PRIORITY, "CustomGUI Priority"_s);
AddChild(ID_COMBOBOX, (Int32)DIALOGELEMENTS::CUSTOM_GUI_DESCRIPTION, "CustomGUI Description"_s);
AddChild(ID_COMBOBOX, (Int32)DIALOGELEMENTS::CUSTOM_GUI_BITMAPBUTTON, "CustomGUI BitmapButton"_s);
AddChild(ID_COMBOBOX, (Int32)DIALOGELEMENTS::CUSTOM_GUI_HYPERLINK, "CustomGUI Hyperlink"_s);
AddChild(ID_COMBOBOX, (Int32)DIALOGELEMENTS::CUSTOM_GUI_INEXCLUDE, "CustomGUI InExclude"_s);
AddChild(ID_COMBOBOX, (Int32)DIALOGELEMENTS::CUSTOM_GUI_LINKBOX, "CustomGUI Linkbox"_s);
AddChild(ID_COMBOBOX, (Int32)DIALOGELEMENTS::CUSTOM_GUI_DATETIME, "CustomGUI DateTime"_s);
AddChild(ID_COMBOBOX, (Int32)DIALOGELEMENTS::CUSTOM_GUI_QUICKTAB, "CustomGUI QuickTab"_s);
AddChild(ID_COMBOBOX, -1, "..."_s);
AddChild(ID_COMBOBOX, (Int32)DIALOGELEMENTS::NODEGUI, "Node GUI"_s);
AddChild(ID_COMBOBOX, -1, "..."_s);
AddChild(ID_COMBOBOX, (Int32)DIALOGELEMENTS::SCROLLGROUP, "Scrollgroup"_s);
AddChild(ID_COMBOBOX, (Int32)DIALOGELEMENTS::TABGROUPS, "Tabgroups"_s);
AddChild(ID_COMBOBOX, (Int32)DIALOGELEMENTS::SUBDIALOG, "Subdialog"_s);
AddChild(ID_COMBOBOX, (Int32)DIALOGELEMENTS::USERAREA, "Userarea"_s);
AddChild(ID_COMBOBOX, (Int32)DIALOGELEMENTS::DIALOGGROUP, "Dialog Group"_s);
// Button
AddButton(ID_BUTTON, BFH_LEFT | BFV_TOP, 100, 10, "Read Data"_s);
GroupEnd();
AddSeparatorH(400, BFH_SCALEFIT);
GroupBegin(ID_DYNAMIC_GROUP + 99, BFH_SCALEFIT | BFV_SCALEFIT, 1, 0, "Dynamic Group"_s, 0, 400);
GroupBorderSpace(10, 10, 10, 10);
// the content of this group will be changed dynamically
GroupBegin(ID_DYNAMIC_GROUP, BFH_SCALEFIT|BFV_SCALEFIT, 1, 0, "Dynamic Group"_s, 0, 400);
GroupBorderSpace(20, 10, 20, 10);
GroupBorder(BORDER_BLACK | BORDER_WITH_TITLE_BOLD);
GroupEnd(); // Dynamic Group with border
GroupEnd();
// console
GroupBegin(1000, BFH_SCALEFIT | BFV_FIT, 2, 0, String(), BFV_BORDERGROUP_FOLD_OPEN, 400);
GroupBorderSpace(10, 10, 10, 10);
AddMultiLineEditText(ID_CONSOLE, BFH_SCALEFIT | BFV_FIT, 0, 100, DR_MULTILINE_WORDWRAP | DR_MULTILINE_MONOSPACED | DR_MULTILINE_READONLY);
SetString(ID_CONSOLE, "console"_s);
GroupEnd();
this->UpdateDialog();
return true;
}
void ExampleDialog::HandleQuickTabCommand()
{
// before attaching the needed subdialogs, flush the parent group
LayoutFlushGroup(ID_QUICKTAB_GROUP);
// now attach the subdialogs depending on QuickTab selection state
GroupBegin(ID_QUICKTAB_GROUP, BFH_SCALEFIT | BFV_TOP, 1, 0, String(), 0);
for (Int32 idx = 0; idx < QUICKTAB_NUM_TABS; ++idx)
{
// Note on alternative implementation:
// Instead of using SubDialogs, you could also use groups and hide them accordingly
// Like so:
// HideElement(GadgetPtr(ID_QUICKTAB_SUBGROUPS + idx), !_quickTabGUI->IsSelected(idx));
if (_quickTabGUI->IsSelected(idx))
{
if (!AddSubDialog(ID_QUICKTAB_SUBDIALOGS + idx, BFH_SCALEFIT | BFV_TOP))
break;
if (!AttachSubDialog(&_quickTabSubDialogs[idx], ID_QUICKTAB_SUBDIALOGS + idx))
break;
}
}
GroupEnd();
// in the end, don't forget to inform C4D about layout changes
LayoutChanged(GadgetPtr(ID_QUICKTAB_GROUP));
}
Bool ExampleDialog::Command(Int32 id, const BaseContainer & msg)
{
switch (id)
{
case ID_COMBOBOX:
{
this->UpdateDialog();
break;
}
case ID_BUTTON:
{
this->ReadData();
break;
}
case ID_MENU_COMMAND:
{
SetString(ID_CONSOLE, "Custom Command called!"_s);
break;
}
case ID_DYMAMIC_GADGET:
{
Int32 selection = -1;
GetInt32(ID_COMBOBOX, selection);
if (selection == (Int32)DIALOGELEMENTS::CUSTOM_GUI_QUICKTAB)
HandleQuickTabCommand();
break;
}
}
return GeDialog::Command(id, msg);
}
//----------------------------------------------------------------------------------------
/// Updates the dialog after the gadet type was changed.
//----------------------------------------------------------------------------------------
void ExampleDialog::UpdateDialog()
{
// get current selection
Int32 selection = -1;
GetInt32(ID_COMBOBOX, selection);
if (selection < 0)
return;
// enable/disable button
this->EnableButton(selection);
// clear the group
LayoutFlushGroup(ID_DYNAMIC_GROUP);
// free any children of the dynamic gadget
FreeChildren(ID_DYMAMIC_GADGET);
// add gadget
this->AddDynamicElement(selection);
// update group
LayoutChanged(ID_DYNAMIC_GROUP);
}
//----------------------------------------------------------------------------------------
/// Enables or disables the "Read Data" button depending on the selected gadget type.
/// @param[in] selection The ID of the currently displayed gadget type.
//----------------------------------------------------------------------------------------
void ExampleDialog::EnableButton(const int selection)
{
switch (selection)
{
case DIALOGELEMENTS::CHECKBOX:
case DIALOGELEMENTS::EDIT_TEXT:
case DIALOGELEMENTS::MULTILINE_TEXT:
case DIALOGELEMENTS::COLORFIELD:
case DIALOGELEMENTS::COLOR_CHOOSER:
case DIALOGELEMENTS::RADIO_GROUP:
case DIALOGELEMENTS::COMBO_BOX:
case DIALOGELEMENTS::COMBO_BUTTON:
case DIALOGELEMENTS::RADIO_BUTTON:
case DIALOGELEMENTS::RADIO_TEXT:
case DIALOGELEMENTS::EDIT_NUMBER:
case DIALOGELEMENTS::EDIT_NUMBER_ARROWS:
case DIALOGELEMENTS::EDIT_SLIDER:
case DIALOGELEMENTS::SLIDER:
case DIALOGELEMENTS::CUSTOM_GUI_GRADIENT:
case DIALOGELEMENTS::CUSTOM_GUI_SPLINE:
case DIALOGELEMENTS::CUSTOM_GUI_PRIORITY:
case DIALOGELEMENTS::CUSTOM_GUI_INEXCLUDE:
case DIALOGELEMENTS::CUSTOM_GUI_DESCRIPTION:
case DIALOGELEMENTS::CUSTOM_GUI_LINKBOX:
case DIALOGELEMENTS::CUSTOM_GUI_DATETIME:
Enable(ID_BUTTON, true);
break;
default:
Enable(ID_BUTTON, false);
break;
}
}
//----------------------------------------------------------------------------------------
/// Creates the dynamic gadget.
/// @param[in] selection The ID of the gadget type.
//----------------------------------------------------------------------------------------
void ExampleDialog::AddDynamicElement(const int selection)
{
switch (selection)
{
// Checkbox
case DIALOGELEMENTS::CHECKBOX:
{
AddCheckbox(ID_DYMAMIC_GADGET, BFH_SCALEFIT | BFV_TOP, 0, 10, "Checkbox"_s);
break;
}
// Button
case DIALOGELEMENTS::BUTTON:
{
AddButton(ID_DYMAMIC_GADGET, BFH_SCALEFIT | BFV_TOP, 0, 10, "Button"_s);
break;
}
// StaticText
case DIALOGELEMENTS::STATIC_TEXT:
{
AddStaticText(ID_DYMAMIC_GADGET, BFH_SCALEFIT | BFV_TOP, 0, 20, "Static Text"_s, BORDER_ROUND);
break;
}
// EditText
case DIALOGELEMENTS::EDIT_TEXT:
{
AddEditText(ID_DYMAMIC_GADGET, BFH_SCALEFIT, 0, 10, 0);
break;
}
// MultiLineEditText
case DIALOGELEMENTS::MULTILINE_TEXT:
{
AddMultiLineEditText(ID_DYMAMIC_GADGET, BFH_SCALEFIT | BFV_SCALEFIT, 0, 200, DR_MULTILINE_STATUSBAR | DR_MULTILINE_HIGHLIGHTLINE | DR_MULTILINE_WORDWRAP | DR_MULTILINE_MONOSPACED);
break;
}
// EditNumber
case DIALOGELEMENTS::EDIT_NUMBER:
{
AddEditNumber(ID_DYMAMIC_GADGET, BFH_LEFT, 80, 10);
SetFloat(ID_DYMAMIC_GADGET, 123.45);
break;
}
// EditNumberArrows
case DIALOGELEMENTS::EDIT_NUMBER_ARROWS:
{
AddEditNumberArrows(ID_DYMAMIC_GADGET, BFH_LEFT, 70, 10);
SetFloat(ID_DYMAMIC_GADGET, 123.45);
break;
}
// EditSlider
case DIALOGELEMENTS::EDIT_SLIDER:
{
AddEditSlider(ID_DYMAMIC_GADGET, BFH_SCALEFIT, 0, 10);
SetPercent(ID_DYMAMIC_GADGET, 0.5);
break;
}
// Slider
case DIALOGELEMENTS::SLIDER:
{
AddSlider(ID_DYMAMIC_GADGET, BFH_SCALEFIT, 0, 10);
SetPercent(ID_DYMAMIC_GADGET, 0.5);
break;
}
// ColorField
case DIALOGELEMENTS::COLORFIELD:
{
AddColorField(ID_DYMAMIC_GADGET, BFH_LEFT, 20, 20, DR_COLORFIELD_ICC_BASEDOC);
SetColorField(ID_DYMAMIC_GADGET, Vector(0, 0, 1), 1.0, 1.0, DR_COLORFIELD_NO_BRIGHTNESS);
break;
}
// RadioButton
case DIALOGELEMENTS::RADIO_BUTTON:
{
AddRadioButton(ID_DYMAMIC_GADGET, BFH_LEFT, 200, 20, String("RadioButton"));
break;
}
// ColorChooser
case DIALOGELEMENTS::COLOR_CHOOSER:
{
AddColorChooser(ID_DYMAMIC_GADGET, BFH_LEFT, 40, 20, DR_COLORFIELD_ICC_BASEDOC);
SetColorField(ID_DYMAMIC_GADGET, Vector(0, 0, 1), 1.0, 1.0, DR_COLORFIELD_NO_BRIGHTNESS);
break;
}
// RadioText
case DIALOGELEMENTS::RADIO_TEXT:
{
AddRadioText(ID_DYMAMIC_GADGET, BFH_LEFT, 100, 10, "RadioText"_s);
break;
}
// RadioGroup
case DIALOGELEMENTS::RADIO_GROUP:
{
AddRadioGroup(ID_DYMAMIC_GADGET, BFH_LEFT, 1);
AddChild(ID_DYMAMIC_GADGET, 0, "Child 0"_s);
AddChild(ID_DYMAMIC_GADGET, 1, "Child 1"_s);
AddChild(ID_DYMAMIC_GADGET, 2, "Child 2"_s);
break;
}
// ComboBox
case DIALOGELEMENTS::COMBO_BOX:
{
AddComboBox(ID_DYMAMIC_GADGET, BFH_LEFT, 100, 10, false);
AddChild(ID_DYMAMIC_GADGET, 0, "Child 0"_s);
AddChild(ID_DYMAMIC_GADGET, 1, "Child 1"_s);
AddChild(ID_DYMAMIC_GADGET, 2, "Child 2"_s);
break;
}
// ComboButton
case DIALOGELEMENTS::COMBO_BUTTON:
{
AddComboButton(ID_DYMAMIC_GADGET, BFH_LEFT, 100, 10, false);
AddChild(ID_DYMAMIC_GADGET, 0, "Child 0"_s);
AddChild(ID_DYMAMIC_GADGET, 1, "Child 1"_s);
AddChild(ID_DYMAMIC_GADGET, 2, "Child 2"_s);
break;
}
// PopupButton
case DIALOGELEMENTS::POPUP_BUTTON:
{
AddPopupButton(ID_DYMAMIC_GADGET, BFH_LEFT, 10, 10);
AddChild(ID_DYMAMIC_GADGET, 0, "Child 0"_s);
AddChild(ID_DYMAMIC_GADGET, 1, "Child 1"_s);
AddChild(ID_DYMAMIC_GADGET, 2, "Child 2"_s);
break;
}
// SplineCustomGui
case DIALOGELEMENTS::CUSTOM_GUI_SPLINE:
{
BaseContainer settings;
settings.SetBool(SPLINECONTROL_GRID_H, true);
settings.SetBool(SPLINECONTROL_GRID_V, true);
settings.SetBool(SPLINECONTROL_VALUE_EDIT_H, true);
settings.SetBool(SPLINECONTROL_VALUE_EDIT_V, true);
settings.SetBool(SPLINECONTROL_NO_FLOATING_WINDOW, true);
settings.SetBool(SPLINECONTROL_NO_PRESETS, false);
SplineCustomGui* splineGUI = (SplineCustomGui*)AddCustomGui(ID_DYMAMIC_GADGET, CUSTOMGUI_SPLINE, String(), BFH_SCALEFIT, 100, 100, settings);
if (splineGUI != nullptr)
{
SplineData* splineData = SplineData::Alloc();
if (splineData != nullptr)
{
// set data
splineData->SetRange(0.0, 50, 0.1, 0.0, 100, 0.0);
splineData->InsertKnot(0, 0);
splineData->InsertKnot(50, 100);
// add data
splineGUI->SetSpline(splineData);
}
}
break;
}
// GradientCustomGui
case DIALOGELEMENTS::CUSTOM_GUI_GRADIENT:
{
GradientCustomGui* gradientGUI = (GradientCustomGui*)AddCustomGui(ID_DYMAMIC_GADGET, CUSTOMGUI_GRADIENT, "Gradient"_s, BFH_SCALEFIT, 100, 20, BaseContainer());
if (gradientGUI != nullptr)
{
Gradient* gradient = gradientGUI->GetGradient();
if (gradient != nullptr)
{
{
maxon::GradientKnot knot;
knot.pos = 0.1;
knot.col = maxon::Color(1, 0, 0);
gradient->InsertKnot(knot);
}
{
maxon::GradientKnot knot;
knot.pos = 0.9;
knot.col = maxon::Color(0, 1, 0);
gradient->InsertKnot(knot);
}
}
}
break;
}
// PriorityCustomGui
case DIALOGELEMENTS::CUSTOM_GUI_PRIORITY:
{
AddCustomGui(ID_DYMAMIC_GADGET, CUSTOMGUI_PRIORITY, String(), BFH_SCALEFIT, 100, 20, BaseContainer());
break;
}
// DescriptionCustomGui
case DIALOGELEMENTS::CUSTOM_GUI_DESCRIPTION:
{
BaseObject* activeObject = GetActiveDocument()->GetActiveObject();
if (activeObject == nullptr)
{
AddStaticText(ID_DYMAMIC_GADGET, BFH_SCALEFIT | BFH_LEFT, 0, 10, "Please select an object."_s, BORDER_NONE);
}
else
{
BaseContainer customgui;
customgui.SetBool(DESCRIPTION_ALLOWFOLDING, true);
DescriptionCustomGui* descriptionGUI = (DescriptionCustomGui*)AddCustomGui(ID_DYMAMIC_GADGET, CUSTOMGUI_DESCRIPTION, String(), BFH_SCALEFIT | BFV_SCALEFIT, 400, 200, customgui);
if (descriptionGUI != nullptr)
descriptionGUI->SetObject(activeObject);
}
break;
}
// BitmapButtonCustomGui
case DIALOGELEMENTS::CUSTOM_GUI_BITMAPBUTTON:
{
BaseContainer settings;
settings.SetBool(BITMAPBUTTON_BUTTON, true);
settings.SetInt32(BITMAPBUTTON_BORDER, BORDER_BLACK);
settings.SetString(BITMAPBUTTON_TOOLTIP, "This is a BitmapButton"_s);
BitmapButtonCustomGui* bitmapButtonGUI = (BitmapButtonCustomGui*)AddCustomGui(ID_DYMAMIC_GADGET, CUSTOMGUI_BITMAPBUTTON, String(), BFH_SCALEFIT, 100, 50, settings);
if (bitmapButtonGUI != nullptr)
{
IconData data;
GetIcon(5159, &data);
// set Icon
bitmapButtonGUI->SetImage(&data);
}
break;
}
// HyperLinkCustomGui
case DIALOGELEMENTS::CUSTOM_GUI_HYPERLINK:
{
BaseContainer settings;
settings.SetBool(HYPERLINK_IS_LINK, true);
HyperLinkCustomGui* linkGUI = (HyperLinkCustomGui*)AddCustomGui(ID_DYMAMIC_GADGET, CUSTOMGUI_HYPER_LINK_STATIC, String(), BFH_SCALEFIT, 100, 50, settings);
if (linkGUI != nullptr)
{
const String link = "http://www.maxon.net";
const String text = "Maxon Homepage";
linkGUI->SetLinkString(&link, &text);
}
break;
}
// InExcludeCustomGui
case DIALOGELEMENTS::CUSTOM_GUI_INEXCLUDE:
{
// list of accepted elements
// in this case only accept objects
BaseContainer acceptedObjects;
acceptedObjects.InsData(Obase, String());
// settings container
BaseContainer settings;
settings.SetData(DESC_ACCEPT, acceptedObjects);
// create
InExcludeCustomGui* inexGUI = (InExcludeCustomGui*)AddCustomGui(ID_DYMAMIC_GADGET, CUSTOMGUI_INEXCLUDE_LIST, String(), BFH_SCALEFIT | BFV_SCALEFIT, 100, 50, settings);
if (inexGUI != nullptr)
{
// get data
TriState<GeData> data = inexGUI->GetData();
GeData dataCopy = data.GetValue();
InExcludeData* ieData = dataCopy.GetCustomDataTypeWritable<InExcludeData>();
if (ieData != nullptr)
{
// add the active object to the list
ieData->InsertObject(GetActiveDocument()->GetActiveObject(), 0);
inexGUI->SetData(data);
}
}
break;
}
// LinkBoxGui
case DIALOGELEMENTS::CUSTOM_GUI_LINKBOX:
{
// list of accepted elements
// in this case only accept objects
BaseContainer acceptedObjects;
acceptedObjects.InsData(Obase, String());
// settings container
BaseContainer settings;
settings.SetData(DESC_ACCEPT, acceptedObjects);
// create
LinkBoxGui* linkboxGUI = (LinkBoxGui*)AddCustomGui(ID_DYMAMIC_GADGET, CUSTOMGUI_LINKBOX, String(), BFH_SCALEFIT | BFV_SCALEFIT, 100, 50, settings);
if (linkboxGUI != nullptr)
{
linkboxGUI->SetLink(GetActiveDocument()->GetActiveObject());
}
break;
}
// DateTimeControl
case DIALOGELEMENTS::CUSTOM_GUI_DATETIME:
{
// create
DateTimeControl* dateTimeGUI = (DateTimeControl*)AddCustomGui(ID_DYMAMIC_GADGET, DATETIME_GUI, String(), BFH_SCALEFIT | BFV_SCALEFIT, 100, 50, BaseContainer());
if (dateTimeGUI != nullptr)
{
DateTime time;
GetDateTimeNow(time);
dateTimeGUI->SetDateTime(time);
}
break;
}
// QuickTab
case DIALOGELEMENTS::CUSTOM_GUI_QUICKTAB:
{
// create
_quickTabGUI = static_cast<QuickTabCustomGui*>(AddCustomGui(ID_DYMAMIC_GADGET, CUSTOMGUI_QUICKTAB, String(), BFH_SCALEFIT | BFV_TOP, 100, 5, BaseContainer()));
if (_quickTabGUI)
{
// one group, which contains all groups/subdialogs, needed for proper layout updates
GroupBegin(ID_QUICKTAB_GROUP, BFH_SCALEFIT | BFV_TOP, 1, 0, String(), 0, 400); // BFV_BORDERGROUP_FOLD_OPEN
GroupBorderSpace(0, 0, 0, 0);
for (Int32 idx = 0; idx < QUICKTAB_NUM_TABS; ++idx)
{
// add a new tab
_quickTabGUI->AppendString(idx, "Tab " + String::IntToString(idx), idx ? false : true);
_quickTabSubDialogs[idx]._dialogIdx = idx;
_quickTabSubDialogs[idx].SetTitle("Test"_s);
if (_quickTabGUI->IsSelected(idx))
{
AddSubDialog(ID_QUICKTAB_SUBDIALOGS + idx, BFH_SCALEFIT | BFV_TOP); // Add error handling
AttachSubDialog(&_quickTabSubDialogs[idx], ID_QUICKTAB_SUBDIALOGS + idx);
}
// Note on alternative implementation:
// Instead of using SubDialogs, you could also use groups and hide them accordingly.
// Like so (see also HandleQuickTabCommand()):
// Add an example group, its visibility will be changed according to tab state (see Command())
// GroupBegin(ID_QUICKTAB_SUBGROUPS + idx, BFH_SCALEFIT | BFV_TOP, 1, 0, String(), 0, 400); // BFV_BORDERGROUP_FOLD_OPEN
// GroupBorderSpace(0, 0, 0, 0);
// AddStaticText(ID_QUICKTAB_SUBGROUP_TEXT + idx, BFH_SCALEFIT | BFV_TOP, 0, 20, "Text in tab #" + String::IntToString(idx), BORDER_NONE);
// GroupEnd();
// switch visibility of groups according to tabs
// HideElement(GadgetPtr(ID_QUICKTAB_SUBGROUPS + idx), idx ? true : false);
}
GroupEnd();
}
break;
}
// GvNodeGUI
case DIALOGELEMENTS::NODEGUI:
{
if (_nodeGUI == nullptr)
{
_shape = GvGetWorld()->AllocShape();
_group = GvGetWorld()->AllocGroupShape();
_nodeGUI = GvGetWorld()->AllocNodeGUI(_shape, _group, ID_DYMAMIC_GADGET);
}
BaseObject* activeObject = GetActiveDocument()->GetActiveObject();
if (activeObject != nullptr)
{
BaseTag* tag = activeObject->GetTag(Texpresso);
if (tag != nullptr)
{
XPressoTag* xpTag = static_cast<XPressoTag*>(tag);
GvNodeMaster* nodeMaster = xpTag->GetNodeMaster();
if (nodeMaster != nullptr)
{
_nodeGUI->Attach(this, nodeMaster);
GroupBegin(ID_DYMAMIC_GADGET + 100, BFH_SCALEFIT | BFV_SCALEFIT, 1, 0, String(), BFV_BORDERGROUP_FOLD_OPEN, 400, 200);
AddUserArea(ID_DYMAMIC_GADGET, BFH_SCALEFIT | BFV_SCALEFIT, 400, 200);
AttachUserArea(*_nodeGUI->GetUserArea(), ID_DYMAMIC_GADGET, USERAREAFLAGS::TABSTOP | USERAREAFLAGS::HANDLEFOCUS);
GroupEnd();
}
}
else
{
AddStaticText(ID_DYMAMIC_GADGET, BFH_SCALEFIT | BFH_LEFT, 0, 10, "Please select an object with an Xpresso tag."_s, BORDER_NONE);
}
}
else
{
AddStaticText(ID_DYMAMIC_GADGET, BFH_SCALEFIT | BFH_LEFT, 0, 10, "Please select an object with an Xpresso tag."_s, BORDER_NONE);
}
break;
}
// ScrollGroup
case DIALOGELEMENTS::SCROLLGROUP:
{
ScrollGroupBegin(ID_DYMAMIC_GADGET, BFH_SCALEFIT | BFV_SCALEFIT, SCROLLGROUP_VERT | SCROLLGROUP_NOBLIT | SCROLLGROUP_STATUSBAR | SCROLLGROUP_STATUSBAR_EXT_GROUP, 400, 200);
GroupBegin(ID_DYMAMIC_GADGET + 100, BFH_SCALEFIT | BFV_SCALEFIT, 1, 0, String(), BFV_BORDERGROUP_FOLD_OPEN, 400);
// fill scrollgroup with stuff
for (Int32 i = 0; i < 40; ++i)
{
AddCheckbox(ID_DYMAMIC_GADGET + i, BFH_SCALEFIT | BFV_TOP, 0, 10, "Checkbox "+String::IntToString(i));
}
GroupEnd();
GroupEnd();
// adding static text to the subgroup ID_SCROLLGROUP_STATUSBAR_EXTLEFT_GROUP
LayoutFlushGroup(ID_SCROLLGROUP_STATUSBAR_EXTLEFT_GROUP);
GroupBorderSpace(2, 2, 2, 2);
AddStaticText(ID_DYMAMIC_GADGET + 200, BFH_SCALEFIT | BFH_LEFT, 0, 10, "Scroll Group Status Bar"_s, BORDER_NONE);
LayoutChanged(ID_SCROLLGROUP_STATUSBAR_EXTLEFT_GROUP);
break;
}
// TabGroup
case DIALOGELEMENTS::TABGROUPS:
{
TabGroupBegin(ID_DYMAMIC_GADGET, BFH_SCALEFIT | BFV_SCALEFIT);
GroupBegin(ID_DYMAMIC_GADGET + 1, BFH_SCALEFIT | BFV_SCALEFIT, 1, 0, "Tab 1"_s, BFV_BORDERGROUP_FOLD_OPEN, 400, 300);
AddStaticText(ID_DYMAMIC_GADGET + 10, BFH_SCALEFIT | BFH_LEFT, 0, 10, "Tab 1"_s, BORDER_NONE);
GroupEnd();
GroupBegin(ID_DYMAMIC_GADGET + 2, BFH_SCALEFIT | BFV_SCALEFIT, 1, 0, "Tab 2"_s, BFV_BORDERGROUP_FOLD_OPEN, 400, 300);
AddStaticText(ID_DYMAMIC_GADGET + 11, BFH_SCALEFIT| BFH_LEFT, 0, 10, "Tab 2"_s, BORDER_NONE);
GroupEnd();
GroupBegin(ID_DYMAMIC_GADGET + 3, BFH_SCALEFIT | BFV_SCALEFIT, 1, 0, "Tab 3"_s, BFV_BORDERGROUP_FOLD_OPEN, 400, 300);
AddStaticText(ID_DYMAMIC_GADGET + 12, BFH_SCALEFIT | BFH_LEFT, 0, 10, "Tab 3"_s, BORDER_NONE);
GroupEnd();
GroupEnd();
break;
}
// SubDialog
case DIALOGELEMENTS::SUBDIALOG:
{
AddSubDialog(ID_DYMAMIC_GADGET, BFH_SCALEFIT | BFV_SCALEFIT);
AttachSubDialog(&_subDialog, ID_DYMAMIC_GADGET);
break;
}
// GeUserArea
case DIALOGELEMENTS::USERAREA:
{
AddUserArea(ID_DYMAMIC_GADGET, BFH_SCALEFIT | BFV_SCALEFIT, 400, 300);
AttachUserArea(_userArea, ID_DYMAMIC_GADGET);
break;
}
// DlgGroup