-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglui.h
2606 lines (2201 loc) · 92.4 KB
/
glui.h
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
/****************************************************************************
GLUI User Interface Toolkit
---------------------------
glui.h - Main (and only) external header for
GLUI User Interface Toolkit
--------------------------------------------------
Copyright (c) 1998 Paul Rademacher
WWW: http://sourceforge.net/projects/glui/
Forums: http://sourceforge.net/forum/?group_id=92496
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*****************************************************************************/
#ifndef GLUI_GLUI_H
#define GLUI_GLUI_H
// Having stdlib here first fixes some 'exit() redefined' errors on MSVC.NET
// that come from old GLUT headers.
#include <cstdlib>
#if defined(GLUI_FREEGLUT)
// FreeGLUT does not yet work perfectly with GLUI
// - use at your own risk.
#include <GL/freeglut.h>
#elif defined(GLUI_OPENGLUT)
// OpenGLUT does not yet work properly with GLUI
// - use at your own risk.
#include <GL/openglut.h>
#else
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#endif
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
/* GLUI API shared library export/import declarations. */
#if defined(_WIN32)
# ifdef GLUI_BUILDING_LIB
# ifdef GLUIDLL
# define GLUIAPI __declspec(dllexport)
# else
# define GLUIAPI
# endif
# else
# ifdef GLUIDLL
# define GLUIAPI __declspec(dllimport)
# else
# define GLUIAPI
# endif
# endif
#else
#define GLUIAPI
#endif
#define GLUI_VERSION 2.36f /********** Current version **********/
#if defined(_WIN32)
# if !defined(GLUI_NO_LIB_PRAGMA) && !defined(GLUI_BUILDING_LIB)
// Link automatically with GLUI library
# if defined GLUIDLL // define this when using glui dynamic library
# pragma comment(lib, "glui32dll.lib")
# else
# pragma comment(lib, "glui32.lib")
# endif
# endif
#endif
/********** List of GLUT callbacks ********/
enum GLUI_Glut_CB_Types
{
GLUI_GLUT_RESHAPE,
GLUI_GLUT_KEYBOARD,
GLUI_GLUT_DISPLAY,
GLUI_GLUT_MOUSE,
GLUI_GLUT_MOTION,
GLUI_GLUT_SPECIAL,
GLUI_GLUT_PASSIVE_MOTION,
GLUI_GLUT_ENTRY,
GLUI_GLUT_VISIBILITY
};
/********* Constants for window placement **********/
#define GLUI_XOFF 6
#define GLUI_YOFF 6
#define GLUI_ITEMSPACING 3
#define GLUI_CHECKBOX_SIZE 13
#define GLUI_RADIOBUTTON_SIZE 13
#define GLUI_BUTTON_SIZE 20
#define GLUI_STATICTEXT_SIZE 13
#define GLUI_SEPARATOR_HEIGHT 8
#define GLUI_DEFAULT_CONTROL_WIDTH 100
#define GLUI_DEFAULT_CONTROL_HEIGHT 13
#define GLUI_EDITTEXT_BOXINNERMARGINX 3
#define GLUI_EDITTEXT_HEIGHT 20
#define GLUI_EDITTEXT_WIDTH 130
#define GLUI_EDITTEXT_MIN_INT_WIDTH 35
#define GLUI_EDITTEXT_MIN_TEXT_WIDTH 50
#define GLUI_PANEL_NAME_DROP 8
#define GLUI_PANEL_EMBOSS_TOP 4
/* #define GLUI_ROTATION_WIDTH 60 */
/* #define GLUI_ROTATION_HEIGHT 78 */
#define GLUI_ROTATION_WIDTH 50
#define GLUI_ROTATION_HEIGHT (GLUI_ROTATION_WIDTH+18)
#define GLUI_MOUSE_INTERACTION_WIDTH 50
#define GLUI_MOUSE_INTERACTION_HEIGHT (GLUI_MOUSE_INTERACTION_WIDTH)+18
/** Different panel control types **/
#define GLUI_PANEL_NONE 0
#define GLUI_PANEL_EMBOSSED 1
#define GLUI_PANEL_RAISED 2
/** Max # of els in control's float_array **/
#define GLUI_DEF_MAX_ARRAY 30
/********* The control's 'active' behavior *********/
#define GLUI_CONTROL_ACTIVE_MOUSEDOWN 1
#define GLUI_CONTROL_ACTIVE_PERMANENT 2
/********* Control alignment types **********/
#define GLUI_ALIGN_CENTER 1
#define GLUI_ALIGN_RIGHT 2
#define GLUI_ALIGN_LEFT 3
/********** Limit types - how to limit spinner values *********/
#define GLUI_LIMIT_NONE 0
#define GLUI_LIMIT_CLAMP 1
#define GLUI_LIMIT_WRAP 2
/********** Translation control types ********************/
#define GLUI_TRANSLATION_XY 0
#define GLUI_TRANSLATION_Z 1
#define GLUI_TRANSLATION_X 2
#define GLUI_TRANSLATION_Y 3
#define GLUI_TRANSLATION_LOCK_NONE 0
#define GLUI_TRANSLATION_LOCK_X 1
#define GLUI_TRANSLATION_LOCK_Y 2
/********** How was a control activated? *****************/
#define GLUI_ACTIVATE_MOUSE 1
#define GLUI_ACTIVATE_TAB 2
/********** What type of live variable does a control have? **********/
#define GLUI_LIVE_NONE 0
#define GLUI_LIVE_INT 1
#define GLUI_LIVE_FLOAT 2
#define GLUI_LIVE_TEXT 3
#define GLUI_LIVE_STRING 6
#define GLUI_LIVE_DOUBLE 4
#define GLUI_LIVE_FLOAT_ARRAY 5
/************* Textbox and List Defaults - JVK ******************/
#define GLUI_TEXTBOX_HEIGHT 130
#define GLUI_TEXTBOX_WIDTH 130
#define GLUI_LIST_HEIGHT 130
#define GLUI_LIST_WIDTH 130
#define GLUI_DOUBLE_CLICK 1
#define GLUI_SINGLE_CLICK 0
#define GLUI_TAB_WIDTH 50 /* In pixels */
#define GLUI_TEXTBOX_BOXINNERMARGINX 3
#define GLUI_TEXTBOX_MIN_TEXT_WIDTH 50
#define GLUI_LIST_BOXINNERMARGINX 3
#define GLUI_LIST_MIN_TEXT_WIDTH 50
/*********************** TreePanel Defaults - JVK *****************************/
#define GLUI_TREEPANEL_DEFAULTS 0 // bar, standard bar color
#define GLUI_TREEPANEL_ALTERNATE_COLOR 1 // Alternate between 8 different bar colors
#define GLUI_TREEPANEL_ENABLE_BAR 2 // enable the bar
#define GLUI_TREEPANEL_DISABLE_BAR 4 // disable the bar
#define GLUI_TREEPANEL_DISABLE_DEEPEST_BAR 8 // disable only the deepest bar
#define GLUI_TREEPANEL_CONNECT_CHILDREN_ONLY 16 // disable only the bar of the last child of each root
#define GLUI_TREEPANEL_DISPLAY_HIERARCHY 32 // display some sort of hierachy in the tree node title
#define GLUI_TREEPANEL_HIERARCHY_NUMERICDOT 64 // display hierarchy in 1.3.2 (etc... ) format
#define GLUI_TREEPANEL_HIERARCHY_LEVEL_ONLY 128 // display hierarchy as only the level depth
/******************* GLUI Scrollbar Defaults - JVK ***************************/
#define GLUI_SCROLL_ARROW_WIDTH 16
#define GLUI_SCROLL_ARROW_HEIGHT 16
#define GLUI_SCROLL_BOX_MIN_HEIGHT 5
#define GLUI_SCROLL_BOX_STD_HEIGHT 16
#define GLUI_SCROLL_STATE_NONE 0
#define GLUI_SCROLL_STATE_UP 1
#define GLUI_SCROLL_STATE_DOWN 2
#define GLUI_SCROLL_STATE_BOTH 3
#define GLUI_SCROLL_STATE_SCROLL 4
#define GLUI_SCROLL_DEFAULT_GROWTH_EXP 1.05f
#define GLUI_SCROLL_VERTICAL 0
#define GLUI_SCROLL_HORIZONTAL 1
/** Size of the character width hash table for faster lookups.
Make sure to keep this a power of two to avoid the slow divide.
This is also a speed/memory tradeoff; 128 is enough for low ASCII.
*/
#define CHAR_WIDTH_HASH_SIZE 128
/********** Translation codes **********/
enum TranslationCodes
{
GLUI_TRANSLATION_MOUSE_NONE = 0,
GLUI_TRANSLATION_MOUSE_UP,
GLUI_TRANSLATION_MOUSE_DOWN,
GLUI_TRANSLATION_MOUSE_LEFT,
GLUI_TRANSLATION_MOUSE_RIGHT,
GLUI_TRANSLATION_MOUSE_UP_LEFT,
GLUI_TRANSLATION_MOUSE_UP_RIGHT,
GLUI_TRANSLATION_MOUSE_DOWN_LEFT,
GLUI_TRANSLATION_MOUSE_DOWN_RIGHT
};
/************ A string type for us to use **********/
typedef std::string GLUI_String;
GLUIAPI GLUI_String& glui_format_str(GLUI_String &str, const char* fmt, ...);
/********* Pre-declare classes as needed *********/
class GLUI;
class GLUI_Control;
class GLUI_Listbox;
class GLUI_StaticText;
class GLUI_EditText;
class GLUI_Panel;
class GLUI_Spinner;
class GLUI_RadioButton;
class GLUI_RadioGroup;
class GLUI_Glut_Window;
class GLUI_TreePanel;
class GLUI_Scrollbar;
class GLUI_List;
class Arcball;
/*** Flags for GLUI class constructor ***/
#define GLUI_SUBWINDOW ((long)(1<<1))
#define GLUI_SUBWINDOW_TOP ((long)(1<<2))
#define GLUI_SUBWINDOW_BOTTOM ((long)(1<<3))
#define GLUI_SUBWINDOW_LEFT ((long)(1<<4))
#define GLUI_SUBWINDOW_RIGHT ((long)(1<<5))
/*** Codes for different type of edittext boxes and spinners ***/
#define GLUI_EDITTEXT_TEXT 1
#define GLUI_EDITTEXT_INT 2
#define GLUI_EDITTEXT_FLOAT 3
#define GLUI_SPINNER_INT GLUI_EDITTEXT_INT
#define GLUI_SPINNER_FLOAT GLUI_EDITTEXT_FLOAT
#define GLUI_SCROLL_INT GLUI_EDITTEXT_INT
#define GLUI_SCROLL_FLOAT GLUI_EDITTEXT_FLOAT
// This is only for deprecated interface
#define GLUI_EDITTEXT_STRING 4
/*** Definition of callbacks ***/
typedef void (*GLUI_Update_CB) (int id);
typedef void (*GLUI_Control_CB)(GLUI_Control *);
typedef void (*Int1_CB) (int);
typedef void (*Int2_CB) (int, int);
typedef void (*Int3_CB) (int, int, int);
typedef void (*Int4_CB) (int, int, int, int);
/************************************************************/
/**
Callback Adapter Class
Allows us to support different types of callbacks;
like a GLUI_Update_CB function pointer--which takes an int;
and a GLUI_Control_CB function pointer--which takes a GUI_Control object.
*/
class GLUIAPI GLUI_CB
{
public:
GLUI_CB() : idCB(0),objCB(0) {}
GLUI_CB(GLUI_Update_CB cb) : idCB(cb),objCB(0) {}
GLUI_CB(GLUI_Control_CB cb) : idCB(0),objCB(cb) {}
// (Compiler generated copy constructor)
/** This control just activated. Fire our callback.*/
void operator()(GLUI_Control *ctrl) const;
bool operator!() const { return !idCB && !objCB; }
operator bool() const { return !(!(*this)); }
private:
GLUI_Update_CB idCB;
GLUI_Control_CB objCB;
};
/************************************************************/
/* */
/* Base class, for hierarchical relationships */
/* */
/************************************************************/
class GLUI_Control;
/**
GLUI_Node is a node in a sort of tree of GLUI controls.
Each GLUI_Node has a list of siblings (in a circular list)
and a linked list of children.
Everything onscreen is a GLUI_Node--windows, buttons, etc.
The nodes are traversed for event processing, sizing, redraws, etc.
*/
class GLUIAPI GLUI_Node
{
friend class GLUI_Tree; /* JVK */
friend class GLUI_Rollout;
friend class GLUI_Main;
public:
GLUI_Node();
virtual ~GLUI_Node() {}
GLUI_Node *first_sibling();
GLUI_Node *last_sibling();
GLUI_Node *prev();
GLUI_Node *next();
GLUI_Node *first_child() { return child_head; }
GLUI_Node *last_child() { return child_tail; }
GLUI_Node *parent() { return parent_node; }
/** Link in a new child control */
virtual int add_control( GLUI_Control *control );
void link_this_to_parent_last (GLUI_Node *parent );
void link_this_to_parent_first(GLUI_Node *parent );
void link_this_to_sibling_next(GLUI_Node *sibling );
void link_this_to_sibling_prev(GLUI_Node *sibling );
void unlink();
void dump( FILE *out, const char *name );
protected:
static void add_child_to_control(GLUI_Node *parent,GLUI_Control *child);
GLUI_Node *parent_node;
GLUI_Node *child_head;
GLUI_Node *child_tail;
GLUI_Node *next_sibling;
GLUI_Node *prev_sibling;
};
/************************************************************/
/* */
/* Standard Bitmap stuff */
/* */
/************************************************************/
enum GLUI_StdBitmaps_Codes
{
GLUI_STDBITMAP_CHECKBOX_OFF = 0,
GLUI_STDBITMAP_CHECKBOX_ON,
GLUI_STDBITMAP_RADIOBUTTON_OFF,
GLUI_STDBITMAP_RADIOBUTTON_ON,
GLUI_STDBITMAP_UP_ARROW,
GLUI_STDBITMAP_DOWN_ARROW,
GLUI_STDBITMAP_LEFT_ARROW,
GLUI_STDBITMAP_RIGHT_ARROW,
GLUI_STDBITMAP_SPINNER_UP_OFF,
GLUI_STDBITMAP_SPINNER_UP_ON,
GLUI_STDBITMAP_SPINNER_DOWN_OFF,
GLUI_STDBITMAP_SPINNER_DOWN_ON,
GLUI_STDBITMAP_CHECKBOX_OFF_DIS, /*** Disactivated control bitmaps ***/
GLUI_STDBITMAP_CHECKBOX_ON_DIS,
GLUI_STDBITMAP_RADIOBUTTON_OFF_DIS,
GLUI_STDBITMAP_RADIOBUTTON_ON_DIS,
GLUI_STDBITMAP_SPINNER_UP_DIS,
GLUI_STDBITMAP_SPINNER_DOWN_DIS,
GLUI_STDBITMAP_LISTBOX_UP,
GLUI_STDBITMAP_LISTBOX_DOWN,
GLUI_STDBITMAP_LISTBOX_UP_DIS,
GLUI_STDBITMAP_NUM_ITEMS
};
/************************************************************/
/* */
/* Class GLUI_Bitmap */
/* */
/************************************************************/
/**
GLUI_Bitmap is a simple 2D texture map. It's used
to represent small textures like checkboxes, arrows, etc.
via the GLUI_StdBitmaps class.
*/
class GLUIAPI GLUI_Bitmap
{
friend class GLUI_StdBitmaps;
public:
GLUI_Bitmap();
~GLUI_Bitmap();
/** Create bitmap from greyscale byte image */
void init_grey(unsigned char *array);
/** Create bitmap from color int image */
void init(int *array);
private:
/** RGB pixel data */
unsigned char *pixels;
int w, h;
};
/************************************************************/
/* */
/* Class GLUI_StdBitmap */
/* */
/************************************************************/
/**
Keeps an array of GLUI_Bitmap objects to represent all the
images used in the UI: checkboxes, arrows, etc.
*/
class GLUIAPI GLUI_StdBitmaps
{
public:
GLUI_StdBitmaps();
~GLUI_StdBitmaps();
/** Return the width (in pixels) of the n'th standard bitmap. */
int width (int n) const;
/** Return the height (in pixels) of the n'th standard bitmap. */
int height(int n) const;
/** Draw the n'th standard bitmap (one of the enums
listed in GLUI_StdBitmaps_Codes) at pixel corner (x,y).
*/
void draw(int n, int x, int y) const;
private:
GLUI_Bitmap bitmaps[GLUI_STDBITMAP_NUM_ITEMS];
};
/************************************************************/
/* */
/* Master GLUI Class */
/* */
/************************************************************/
/**
The master manages our interaction with GLUT.
There's only one GLUI_Master_Object.
*/
class GLUIAPI GLUI_Master_Object
{
friend void glui_idle_func();
public:
GLUI_Master_Object();
~GLUI_Master_Object();
GLUI_Node gluis;
GLUI_Control *active_control, *curr_left_button_glut_menu;
GLUI *active_control_glui;
int glui_id_counter;
GLUI_Glut_Window *find_glut_window( int window_id );
void set_glutIdleFunc(void (*f)(void));
/**************
void (*glut_keyboard_CB)(unsigned char, int, int);
void (*glut_reshape_CB)(int, int);
void (*glut_special_CB)(int, int, int);
void (*glut_mouse_CB)(int,int,int,int);
void (*glut_passive_motion_CB)(int,int);
void (*glut_visibility_CB)(int);
void (*glut_motion_CB)(int,int);
void (*glut_display_CB)(void);
void (*glut_entry_CB)(int);
**********/
void set_left_button_glut_menu_control( GLUI_Control *control );
/********** GLUT callthroughs **********/
/* These are the glut callbacks that we do not handle */
void set_glutReshapeFunc (void (*f)(int width, int height));
void set_glutKeyboardFunc(void (*f)(unsigned char key, int x, int y));
void set_glutSpecialFunc (void (*f)(int key, int x, int y));
void set_glutMouseFunc (void (*f)(int, int, int, int ));
void set_glutDisplayFunc(void (*f)(void)) {glutDisplayFunc(f);}
void set_glutTimerFunc(unsigned int millis, void (*f)(int value), int value)
{ ::glutTimerFunc(millis,f,value);}
void set_glutOverlayDisplayFunc(void(*f)(void)){glutOverlayDisplayFunc(f);}
void set_glutSpaceballMotionFunc(Int3_CB f) {glutSpaceballMotionFunc(f);}
void set_glutSpaceballRotateFunc(Int3_CB f) {glutSpaceballRotateFunc(f);}
void set_glutSpaceballButtonFunc(Int2_CB f) {glutSpaceballButtonFunc(f);}
void set_glutTabletMotionFunc(Int2_CB f) {glutTabletMotionFunc(f);}
void set_glutTabletButtonFunc(Int4_CB f) {glutTabletButtonFunc(f);}
/* void set_glutWindowStatusFunc(Int1_CB f) {glutWindowStatusFunc(f);} */
void set_glutMenuStatusFunc(Int3_CB f) {glutMenuStatusFunc(f);}
void set_glutMenuStateFunc(Int1_CB f) {glutMenuStateFunc(f);}
void set_glutButtonBoxFunc(Int2_CB f) {glutButtonBoxFunc(f);}
void set_glutDialsFunc(Int2_CB f) {glutDialsFunc(f);}
GLUI *create_glui( const char *name, long flags=0, int x=-1, int y=-1 );
GLUI *create_glui_subwindow( int parent_window, long flags=0 );
GLUI *find_glui_by_window_id( int window_id );
void get_viewport_area( int *x, int *y, int *w, int *h );
void auto_set_viewport();
void close_all();
void sync_live_all();
void reshape();
float get_version() { return GLUI_VERSION; }
void glui_setIdleFuncIfNecessary(void);
private:
GLUI_Node glut_windows;
void (*glut_idle_CB)(void);
void add_cb_to_glut_window(int window,int cb_type,void *cb);
};
/**
This is the only GLUI_Master_Object in existence.
*/
extern GLUIAPI GLUI_Master_Object GLUI_Master;
/************************************************************/
/* */
/* Class for managing a GLUT window */
/* */
/************************************************************/
/**
A top-level window. The GLUI_Master GLUT callback can route events
to the callbacks in this class, for arbitrary use by external users.
(see GLUI_Master_Object::set_glutKeyboardFunc).
This entire approach seems to be superceded by the "subwindow" flavor
of GLUI.
*/
class GLUIAPI GLUI_Glut_Window : public GLUI_Node
{
public:
GLUI_Glut_Window();
int glut_window_id;
/*********** Pointers to GLUT callthrough functions *****/
void (*glut_keyboard_CB)(unsigned char, int, int);
void (*glut_special_CB)(int, int, int);
void (*glut_reshape_CB)(int, int);
void (*glut_passive_motion_CB)(int,int);
void (*glut_mouse_CB)(int,int,int,int);
void (*glut_visibility_CB)(int);
void (*glut_motion_CB)(int,int);
void (*glut_display_CB)(void);
void (*glut_entry_CB)(int);
};
/************************************************************/
/* */
/* Main Window GLUI class (not user-level) */
/* */
/************************************************************/
/**
A GLUI_Main handles GLUT events for one window, routing them to the
appropriate controls. The central user-visible "GLUI" class
inherits from this class; users should not allocate GLUT_Main objects.
There's a separate GLUI_Main object for:
- Each top-level window with GUI stuff in it.
- Each "subwindow" of another top-level window.
All the GLUI_Main objects are listed in GLUI_Master.gluis.
A better name for this class might be "GLUI_Environment";
this class provides the window-level context for every control.
*/
class GLUIAPI GLUI_Main : public GLUI_Node
{
/********** Friend classes *************/
friend class GLUI_Control;
friend class GLUI_Rotation;
friend class GLUI_Translation;
friend class GLUI;
friend class GLUI_Master_Object;
/*********** Friend functions **********/
friend void glui_mouse_func(int button, int state, int x, int y);
friend void glui_keyboard_func(unsigned char key, int x, int y);
friend void glui_special_func(int key, int x, int y);
friend void glui_passive_motion_func(int x, int y);
friend void glui_reshape_func( int w, int h );
friend void glui_visibility_func(int state);
friend void glui_motion_func(int x, int y);
friend void glui_entry_func(int state);
friend void glui_display_func( void );
friend void glui_idle_func(void);
friend void glui_parent_window_reshape_func( int w, int h );
friend void glui_parent_window_keyboard_func( unsigned char, int, int );
friend void glui_parent_window_special_func( int, int, int );
friend void glui_parent_window_mouse_func( int, int, int, int );
protected:
/*** Variables ***/
int main_gfx_window_id;
int mouse_button_down;
int glut_window_id;
int top_level_glut_window_id;
GLUI_Control *active_control;
GLUI_Control *mouse_over_control;
GLUI_Panel *main_panel;
enum buffer_mode_t {
buffer_front=1, ///< Draw updated controls directly to screen.
buffer_back=2 ///< Double buffering: postpone updates until next redraw.
};
buffer_mode_t buffer_mode; ///< Current drawing mode
int curr_cursor;
int w, h;
long flags;
bool closing;
int parent_window;
int glui_id;
/********** Misc functions *************/
GLUI_Control *find_control( int x, int y );
GLUI_Control *find_next_control( GLUI_Control *control );
GLUI_Control *find_next_control_rec( GLUI_Control *control );
GLUI_Control *find_next_control_( GLUI_Control *control );
GLUI_Control *find_prev_control( GLUI_Control *control );
void create_standalone_window( const char *name, int x=-1, int y=-1 );
void create_subwindow( int parent,int window_alignment );
void setup_default_glut_callbacks( void );
void mouse(int button, int state, int x, int y);
void keyboard(unsigned char key, int x, int y);
void special(int key, int x, int y);
void passive_motion(int x, int y);
void reshape( int w, int h );
void visibility(int state);
void motion(int x, int y);
void entry(int state);
void display( void );
void idle(void);
int needs_idle(void);
void (*glut_mouse_CB)(int, int, int, int);
void (*glut_keyboard_CB)(unsigned char, int, int);
void (*glut_special_CB)(int, int, int);
void (*glut_reshape_CB)(int, int);
/*********** Controls ************/
virtual int add_control( GLUI_Node *parent, GLUI_Control *control );
/********** Constructors and Destructors ***********/
GLUI_Main( void );
public:
GLUI_StdBitmaps std_bitmaps;
GLUI_String window_name;
unsigned char bkgd_color[3];
float bkgd_color_f[3];
void *font;
int curr_modifiers;
void adjust_glut_xy( int &x, int &y ) { y = h-y; }
void activate_control( GLUI_Control *control, int how );
void align_controls( GLUI_Control *control );
void deactivate_current_control( void );
/** Draw a 3D-look pushed-out box around this rectangle */
void draw_raised_box( int x, int y, int w, int h );
/** Draw a 3D-look pushed-in box around this rectangle */
void draw_lowered_box( int x, int y, int w, int h );
/** Return true if this control should redraw itself immediately (front buffer);
Or queue up a redraw and return false if it shouldn't (back buffer).
*/
bool should_redraw_now(GLUI_Control *ctl);
/** Switch to the appropriate draw buffer now. Returns the old draw buffer.
This routine should probably only be called from inside the GLUI_DrawingSentinal,
in glui_internal_control.h
*/
int set_current_draw_buffer();
/** Go back to using this draw buffer. Undoes set_current_draw_buffer. */
void restore_draw_buffer( int buffer_state );
/** Pack, resize the window, and redraw all the controls. */
void refresh();
/** Redraw the main graphics window */
void post_update_main_gfx();
/** Recompute the sizes and positions of all controls */
void pack_controls();
void close_internal();
void check_subwindow_position();
void set_ortho_projection();
void set_viewport();
int get_glut_window_id( void ) { return glut_window_id; } /* JVK */
};
/************************************************************/
/* */
/* GLUI_Control: base class for all controls */
/* */
/************************************************************/
/**
All the GUI objects inherit from GLUI_Control: buttons,
checkboxes, labels, edit boxes, scrollbars, etc.
Most of the work of this class is in routing events,
like keystrokes, mouseclicks, redraws, and sizing events.
Yes, this is a huge and hideous class. It needs to be
split up into simpler subobjects. None of the data members
should be directly accessed by users (they should be protected,
not public); only subclasses.
*/
class GLUIAPI GLUI_Control : public GLUI_Node
{
public:
/** Onscreen coordinates */
int w, h; /* dimensions of control */
int x_abs, y_abs;
int x_off, y_off_top, y_off_bot; /* INNER margins, by which child
controls are indented */
int contain_x, contain_y;
int contain_w, contain_h;
/* if this is a container control (e.g.,
radiogroup or panel) this indicated dimensions
of inner area in which controls reside */
/** "activation" for tabbing between controls. */
int active_type; ///< "GLUI_CONTROL_ACTIVE_..."
bool active; ///< If true, we've got the focus
bool can_activate; ///< If false, remove from tab order.
bool spacebar_mouse_click; ///< Spacebar simulates click.
/** Callbacks */
long user_id; ///< Integer to pass to callback function.
GLUI_CB callback; ///< User callback function, or NULL.
/** Variable value storage */
float float_val; /**< Our float value */
int int_val; /**< Our integer value */
float float_array_val[GLUI_DEF_MAX_ARRAY];
int float_array_size;
GLUI_String text; /**< The text inside this control */
/** "Live variable" updating */
void *ptr_val; /**< A pointer to the user's live variable value */
int live_type;
bool live_inited;
/* These variables store the last value that live variable was known to have. */
int last_live_int;
float last_live_float;
GLUI_String last_live_text;
float last_live_float_array[GLUI_DEF_MAX_ARRAY];
/** Properties of our control */
GLUI *glui; /**< Our containing event handler (NEVER NULL during event processing!) */
bool is_container; /**< Is this a container class (e.g., panel) */
int alignment;
bool enabled; /**< Is this control grayed out? */
GLUI_String name; /**< The name of this control */
void *font; /**< Our glutbitmap font */
bool collapsible, is_open;
GLUI_Node collapsed_node;
bool hidden; /* Collapsed controls (and children) are hidden */
int char_widths[CHAR_WIDTH_HASH_SIZE][2]; /* Character width hash table */
public:
/*** Get/Set values ***/
virtual void set_name( const char *string );
virtual void set_int_val( int new_int ) { int_val = new_int; output_live(true); }
virtual void set_float_val( float new_float ) { float_val = new_float; output_live(true); }
virtual void set_ptr_val( void *new_ptr ) { ptr_val = new_ptr; output_live(true); }
virtual void set_float_array_val( float *array_ptr );
virtual float get_float_val( void ) { return float_val; }
virtual int get_int_val( void ) { return int_val; }
virtual void get_float_array_val( float *array_ptr );
virtual int get_id( void ) const { return user_id; }
virtual void set_id( int id ) { user_id=id; }
virtual int mouse_down_handler( int local_x, int local_y ) { return false; }
virtual int mouse_up_handler( int local_x, int local_y, bool inside ) { return false; }
virtual int mouse_held_down_handler( int local_x, int local_y, bool inside) { return false; }
virtual int key_handler( unsigned char key, int modifiers ) { return false; }
virtual int special_handler( int key,int modifiers ) { return false; }
virtual void update_size( void ) { }
virtual void idle( void ) { }
virtual int mouse_over( int state, int x, int y ) { return false; }
virtual void enable( void );
virtual void disable( void );
virtual void activate( int how ) { active = true; }
virtual void deactivate( void ) { active = false; }
/** Hide (shrink into a rollout) and unhide (expose from a rollout) */
void hide_internal( int recurse );
void unhide_internal( int recurse );
/** Return true if it currently makes sense to draw this class. */
int can_draw( void ) { return (glui != NULL && hidden == false); }
/** Redraw this control.
In single-buffering mode (drawing to GL_FRONT), this is just
a call to translate_and_draw_front (after a can_draw() check).
In double-buffering mode (drawing to GL_BACK), this queues up
a redraw and returns false, since you shouldn't draw yet.
*/
void redraw(void);
/** Redraw everybody in our window. */
void redraw_window(void);
virtual void align( void );
void pack( int x, int y ); /* Recalculate positions and offsets */
void pack_old( int x, int y );
void draw_recursive( int x, int y );
int set_to_glut_window( void );
void restore_window( int orig );
void translate_and_draw_front( void );
void translate_to_origin( void )
{glTranslatef((float)x_abs+.5,(float)y_abs+.5,0.0);}
virtual void draw( int x, int y )=0;
void set_font( void *new_font );
void *get_font( void );
int string_width( const char *text );
int string_width( const GLUI_String &str )
{ return string_width(str.c_str()); }
int char_width( char c );
void draw_name( int x, int y );
void draw_box_inwards_outline( int x_min, int x_max,
int y_min, int y_max );
void draw_box( int x_min, int x_max, int y_min, int y_max,
float r, float g, float b );
void draw_bkgd_box( int x_min, int x_max, int y_min, int y_max );
void draw_emboss_box( int x_min, int x_max,int y_min,int y_max);
void draw_string( const char *text );
void draw_string( const GLUI_String &s )
{ draw_string(s.c_str()); }
void draw_char( char c );
void draw_active_box( int x_min, int x_max, int y_min, int y_max );
void set_to_bkgd_color( void );
void set_w( int new_w );
void set_h( int new_w );
void set_alignment( int new_align );
void sync_live( int recurse, int draw ); /* Reads live variable */
void init_live( void );
void output_live( int update_main_gfx ); /** Writes live variable **/
virtual void set_text( const char *t ) {}
void execute_callback( void );
void get_this_column_dims( int *col_x, int *col_y,
int *col_w, int *col_h,
int *col_x_off, int *col_y_off );
virtual bool needs_idle( void ) const;
virtual bool wants_tabs() const { return false; }
GLUI_Control(void)
{
x_off = GLUI_XOFF;
y_off_top = GLUI_YOFF;
y_off_bot = GLUI_YOFF;
x_abs = GLUI_XOFF;
y_abs = GLUI_YOFF;
active = false;
enabled = true;
int_val = 0;
last_live_int = 0;
float_array_size = 0;
glui_format_str(name, "Control: %p", this);
float_val = 0.0;
last_live_float = 0.0;
ptr_val = NULL;
glui = NULL;
w = GLUI_DEFAULT_CONTROL_WIDTH;
h = GLUI_DEFAULT_CONTROL_HEIGHT;
font = NULL;
active_type = GLUI_CONTROL_ACTIVE_MOUSEDOWN;
alignment = GLUI_ALIGN_LEFT;
is_container = false;
can_activate = true; /* By default, you can activate a control */
spacebar_mouse_click = true; /* Does spacebar simulate a mouse click? */
live_type = GLUI_LIVE_NONE;
text = "";
last_live_text = "";
live_inited = false;
collapsible = false;
is_open = true;
hidden = false;
memset(char_widths, -1, sizeof(char_widths)); /* JVK */
int i;
for( i=0; i<GLUI_DEF_MAX_ARRAY; i++ )
float_array_val[i] = last_live_float_array[i] = 0.0;
}
virtual ~GLUI_Control();
};
/************************************************************/
/* */
/* Button class (container) */
/* */
/************************************************************/
/**
An onscreen, clickable button--an outlined label that
can be clicked. When clicked, a button
calls its GLUI_CB callback with its ID.
*/
class GLUIAPI GLUI_Button : public GLUI_Control
{
public:
bool currently_inside;
int mouse_down_handler( int local_x, int local_y );
int mouse_up_handler( int local_x, int local_y, bool inside );
int mouse_held_down_handler( int local_x, int local_y, bool inside );
int key_handler( unsigned char key,int modifiers );
void draw( int x, int y );
void draw_pressed( void );
void draw_text( int sunken );
void update_size( void );
/**
Create a new button.
@param parent The panel our object is inside; or the main GLUI object.
@param name The text inside the button.
@param id Optional ID number, to pass to the optional callback function.
@param callback Optional callback function, taking either the int ID or control.
*/
GLUI_Button( GLUI_Node *parent, const char *name,
int id=-1, GLUI_CB cb=GLUI_CB() );
GLUI_Button( void ) { common_init(); };
protected:
void common_init(void) {
glui_format_str(name, "Button: %p", this );
h = GLUI_BUTTON_SIZE;
w = 100;