1
/****************************************************************************
3
GLUI User Interface Toolkit (LGPL)
4
----------------------------------
6
glui.h - Main (and only) external header for
7
GLUI User Interface Toolkit
9
--------------------------------------------------
11
Copyright (c) 1998 Paul Rademacher
13
WWW: http://sourceforge.net/projects/glui/
14
Forums: http://sourceforge.net/forum/?group_id=92496
16
This library is free software; you can redistribute it and/or
17
modify it under the terms of the GNU Lesser General Public
18
License as published by the Free Software Foundation; either
19
version 2.1 of the License, or (at your option) any later version.
21
This library is distributed in the hope that it will be useful,
22
but WITHOUT ANY WARRANTY; without even the implied warranty of
23
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24
Lesser General Public License for more details.
26
You should have received a copy of the GNU Lesser General Public
27
License along with this library; if not, write to the Free Software
28
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30
*****************************************************************************/
36
#include <GLUT/glut.h>
38
#include "freeglut/freeglut.h"
47
#define GLUI_VERSION 2.3f /********** Current version **********/
50
#if !defined(GLUI_NO_LIB_PRAGMA)
51
//#pragma comment(lib, "glui32.lib") // Link automatically with GLUI library
55
/********** Do some basic defines *******/
58
#define Byte unsigned char
66
void set(Byte r,Byte g,Byte b) {this->r=r;this->g=g;this->b=b;}
69
RGBc( Byte r, Byte g, Byte b ) { set( r, g, b ); }
74
/********** List of GLUT callbacks ********/
76
enum GLUI_Glut_CB_Types
84
GLUI_GLUT_PASSIVE_MOTION,
89
/********* Constants for window placement **********/
93
#define GLUI_ITEMSPACING 3
94
#define GLUI_CHECKBOX_SIZE 13
95
#define GLUI_RADIOBUTTON_SIZE 13
96
#define GLUI_BUTTON_SIZE 20
97
#define GLUI_STATICTEXT_SIZE 13
98
#define GLUI_SEPARATOR_HEIGHT 8
99
#define GLUI_DEFAULT_CONTROL_WIDTH 100
100
#define GLUI_DEFAULT_CONTROL_HEIGHT 13
101
#define GLUI_EDITTEXT_BOXINNERMARGINX 3
102
#define GLUI_EDITTEXT_HEIGHT 20
103
#define GLUI_EDITTEXT_WIDTH 130
104
#define GLUI_EDITTEXT_MIN_INT_WIDTH 35
105
#define GLUI_EDITTEXT_MIN_TEXT_WIDTH 50
106
#define GLUI_PANEL_NAME_DROP 8
107
#define GLUI_PANEL_EMBOSS_TOP 4
108
/* #define GLUI_ROTATION_WIDTH 60 */
109
/* #define GLUI_ROTATION_HEIGHT 78 */
110
#define GLUI_ROTATION_WIDTH 50
111
#define GLUI_ROTATION_HEIGHT (GLUI_ROTATION_WIDTH+18)
112
#define GLUI_MOUSE_INTERACTION_WIDTH 50
113
#define GLUI_MOUSE_INTERACTION_HEIGHT (GLUI_MOUSE_INTERACTION_WIDTH)+18
115
/** Different panel control types **/
116
#define GLUI_PANEL_NONE 0
117
#define GLUI_PANEL_EMBOSSED 1
118
#define GLUI_PANEL_RAISED 2
120
/** Max # of els in control's float_array **/
121
#define GLUI_DEF_MAX_ARRAY 30
123
/********* The control's 'active' behavior *********/
124
#define GLUI_CONTROL_ACTIVE_MOUSEDOWN 1
125
#define GLUI_CONTROL_ACTIVE_PERMANENT 2
127
/********* Control alignment types **********/
128
#define GLUI_ALIGN_CENTER 1
129
#define GLUI_ALIGN_RIGHT 2
130
#define GLUI_ALIGN_LEFT 3
132
/********** Limit types - how to limit spinner values *********/
133
#define GLUI_LIMIT_NONE 0
134
#define GLUI_LIMIT_CLAMP 1
135
#define GLUI_LIMIT_WRAP 2
137
/********** Translation control types ********************/
138
#define GLUI_TRANSLATION_XY 0
139
#define GLUI_TRANSLATION_Z 1
140
#define GLUI_TRANSLATION_X 2
141
#define GLUI_TRANSLATION_Y 3
143
#define GLUI_TRANSLATION_LOCK_NONE 0
144
#define GLUI_TRANSLATION_LOCK_X 1
145
#define GLUI_TRANSLATION_LOCK_Y 2
147
/********** How was a control activated? *****************/
148
#define GLUI_ACTIVATE_MOUSE 1
149
#define GLUI_ACTIVATE_TAB 2
151
/********** What type of live variable does a control have? **********/
152
#define GLUI_LIVE_NONE 0
153
#define GLUI_LIVE_INT 1
154
#define GLUI_LIVE_FLOAT 2
155
#define GLUI_LIVE_TEXT 3
156
#define GLUI_LIVE_STRING 6
157
#define GLUI_LIVE_DOUBLE 4
158
#define GLUI_LIVE_FLOAT_ARRAY 5
160
/************* Textbox and List Defaults - JVK ******************/
161
#define GLUI_TEXTBOX_HEIGHT 130
162
#define GLUI_TEXTBOX_WIDTH 130
163
#define GLUI_LIST_HEIGHT 130
164
#define GLUI_LIST_WIDTH 130
165
#define GLUI_DOUBLE_CLICK 1
166
#define GLUI_SINGLE_CLICK 0
167
#define GLUI_TAB_WIDTH 50 /* In pixels */
168
#define GLUI_TEXTBOX_BOXINNERMARGINX 3
169
#define GLUI_TEXTBOX_MIN_TEXT_WIDTH 50
170
#define GLUI_LIST_BOXINNERMARGINX 3
171
#define GLUI_LIST_MIN_TEXT_WIDTH 50
173
/*********************** TreePanel Defaults - JVK *****************************/
174
#define GLUI_TREEPANEL_DEFAULTS 0 // bar, standard bar color
175
#define GLUI_TREEPANEL_ALTERNATE_COLOR 1 // Alternate between 8 different bar colors
176
#define GLUI_TREEPANEL_ENABLE_BAR 2 // enable the bar
177
#define GLUI_TREEPANEL_DISABLE_BAR 4 // disable the bar
178
#define GLUI_TREEPANEL_DISABLE_DEEPEST_BAR 8 // disable only the deepest bar
179
#define GLUI_TREEPANEL_CONNECT_CHILDREN_ONLY 16 // disable only the bar of the last child of each root
180
#define GLUI_TREEPANEL_DISPLAY_HIERARCHY 32 // display some sort of hierachy in the tree node title
181
#define GLUI_TREEPANEL_HIERARCHY_NUMERICDOT 64 // display hierarchy in 1.3.2 (etc... ) format
182
#define GLUI_TREEPANEL_HIERARCHY_LEVEL_ONLY 128 // display hierarchy as only the level depth
184
/******************* GLUI Scrollbar Defaults - JVK ***************************/
185
#define GLUI_SCROLL_ARROW_WIDTH 16
186
#define GLUI_SCROLL_ARROW_HEIGHT 16
187
#define GLUI_SCROLL_BOX_MIN_HEIGHT 5
188
#define GLUI_SCROLL_BOX_STD_HEIGHT 16
189
#define GLUI_SCROLL_STATE_NONE 0
190
#define GLUI_SCROLL_STATE_UP 1
191
#define GLUI_SCROLL_STATE_DOWN 2
192
#define GLUI_SCROLL_STATE_BOTH 3
193
#define GLUI_SCROLL_STATE_SCROLL 4
194
#define GLUI_SCROLL_DEFAULT_GROWTH_EXP 1.05f
195
#define GLUI_SCROLL_VERTICAL 0
196
#define GLUI_SCROLL_HORIZONTAL 1
199
/** Size of the character width hash table for faster lookups.
200
Make sure to keep this a power of two to avoid the slow divide.
201
This is also a speed/memory tradeoff; 128 is enough for low ASCII.
203
#define CHAR_WIDTH_HASH_SIZE 128
205
/********** Translation codes **********/
207
enum TranslationCodes
209
GLUI_TRANSLATION_MOUSE_NONE = 0,
210
GLUI_TRANSLATION_MOUSE_UP,
211
GLUI_TRANSLATION_MOUSE_DOWN,
212
GLUI_TRANSLATION_MOUSE_LEFT,
213
GLUI_TRANSLATION_MOUSE_RIGHT,
214
GLUI_TRANSLATION_MOUSE_UP_LEFT,
215
GLUI_TRANSLATION_MOUSE_UP_RIGHT,
216
GLUI_TRANSLATION_MOUSE_DOWN_LEFT,
217
GLUI_TRANSLATION_MOUSE_DOWN_RIGHT
220
/************ A string type for us to use **********/
222
typedef std::string GLUI_String;
223
GLUI_String& glui_format_str(GLUI_String &str, const char* fmt, ...);
225
/********* Pre-declare classes as needed *********/
230
class GLUI_StaticText;
234
class GLUI_RadioButton;
235
class GLUI_RadioGroup;
236
class GLUI_Glut_Window;
237
class GLUI_TreePanel;
238
class GLUI_Scrollbar;
243
/*** Flags for GLUI class constructor ***/
244
#define GLUI_SUBWINDOW ((long)(1<<1))
245
#define GLUI_SUBWINDOW_TOP ((long)(1<<2))
246
#define GLUI_SUBWINDOW_BOTTOM ((long)(1<<3))
247
#define GLUI_SUBWINDOW_LEFT ((long)(1<<4))
248
#define GLUI_SUBWINDOW_RIGHT ((long)(1<<5))
250
/*** Codes for different type of edittext boxes and spinners ***/
251
#define GLUI_EDITTEXT_TEXT 1
252
#define GLUI_EDITTEXT_INT 2
253
#define GLUI_EDITTEXT_FLOAT 3
254
#define GLUI_SPINNER_INT GLUI_EDITTEXT_INT
255
#define GLUI_SPINNER_FLOAT GLUI_EDITTEXT_FLOAT
256
#define GLUI_SCROLL_INT GLUI_EDITTEXT_INT
257
#define GLUI_SCROLL_FLOAT GLUI_EDITTEXT_FLOAT
258
// This is only for deprecated interface
259
#define GLUI_EDITTEXT_STRING 4
261
/*** Definition of callbacks ***/
262
typedef void (*GLUI_Update_CB) (int id);
263
typedef void (*GLUI_Control_CB)(GLUI_Control *);
264
typedef void (*Int1_CB) (int);
265
typedef void (*Int2_CB) (int, int);
266
typedef void (*Int3_CB) (int, int, int);
267
typedef void (*Int4_CB) (int, int, int, int);
269
/************************************************************/
271
Callback Adapter Class
272
Allows us to support different types of callbacks;
273
like a GLUI_Update_CB function pointer--which takes an int;
274
and a GLUI_Control_CB function pointer--which takes a GUI_Control object.
279
GLUI_CB() : idCB(0),objCB(0) {}
280
GLUI_CB(GLUI_Update_CB cb) : idCB(cb),objCB(0) {}
281
GLUI_CB(GLUI_Control_CB cb) : idCB(0),objCB(cb) {}
282
// (Compiler generated copy constructor)
284
/** This control just activated. Fire our callback.*/
285
void operator()(GLUI_Control *ctrl) const;
286
bool operator!() const { return !idCB && !objCB; }
287
operator bool() const { return !(!(*this)); }
290
GLUI_Control_CB objCB;
293
/************************************************************/
295
/* Base class, for hierarchical relationships */
297
/************************************************************/
302
GLUI_Node is a node in a sort of tree of GLUI controls.
303
Each GLUI_Node has a list of siblings (in a circular list)
304
and a linked list of children.
306
Everything onscreen is a GLUI_Node--windows, buttons, etc.
307
The nodes are traversed for event processing, sizing, redraws, etc.
311
friend class GLUI_Tree; /* JVK */
312
friend class GLUI_Rollout;
313
friend class GLUI_Main;
317
virtual ~GLUI_Node() {}
319
GLUI_Node *first_sibling();
320
GLUI_Node *last_sibling();
324
GLUI_Node *first_child() { return child_head; }
325
GLUI_Node *last_child() { return child_tail; }
326
GLUI_Node *parent() { return parent_node; }
328
/** Link in a new child control */
329
virtual int add_control( GLUI_Control *control );
331
void link_this_to_parent_last (GLUI_Node *parent );
332
void link_this_to_parent_first(GLUI_Node *parent );
333
void link_this_to_sibling_next(GLUI_Node *sibling );
334
void link_this_to_sibling_prev(GLUI_Node *sibling );
337
void dump( FILE *out, const char *name );
340
static void add_child_to_control(GLUI_Node *parent,GLUI_Control *child);
341
GLUI_Node *parent_node;
342
GLUI_Node *child_head;
343
GLUI_Node *child_tail;
344
GLUI_Node *next_sibling;
345
GLUI_Node *prev_sibling;
349
/************************************************************/
351
/* Standard Bitmap stuff */
353
/************************************************************/
355
enum GLUI_StdBitmaps_Codes
357
GLUI_STDBITMAP_CHECKBOX_OFF = 0,
358
GLUI_STDBITMAP_CHECKBOX_ON,
359
GLUI_STDBITMAP_RADIOBUTTON_OFF,
360
GLUI_STDBITMAP_RADIOBUTTON_ON,
361
GLUI_STDBITMAP_UP_ARROW,
362
GLUI_STDBITMAP_DOWN_ARROW,
363
GLUI_STDBITMAP_LEFT_ARROW,
364
GLUI_STDBITMAP_RIGHT_ARROW,
365
GLUI_STDBITMAP_SPINNER_UP_OFF,
366
GLUI_STDBITMAP_SPINNER_UP_ON,
367
GLUI_STDBITMAP_SPINNER_DOWN_OFF,
368
GLUI_STDBITMAP_SPINNER_DOWN_ON,
369
GLUI_STDBITMAP_CHECKBOX_OFF_DIS, /*** Disactivated control bitmaps ***/
370
GLUI_STDBITMAP_CHECKBOX_ON_DIS,
371
GLUI_STDBITMAP_RADIOBUTTON_OFF_DIS,
372
GLUI_STDBITMAP_RADIOBUTTON_ON_DIS,
373
GLUI_STDBITMAP_SPINNER_UP_DIS,
374
GLUI_STDBITMAP_SPINNER_DOWN_DIS,
375
GLUI_STDBITMAP_LISTBOX_UP,
376
GLUI_STDBITMAP_LISTBOX_DOWN,
377
GLUI_STDBITMAP_LISTBOX_UP_DIS,
378
GLUI_STDBITMAP_NUM_ITEMS
381
/************************************************************/
383
/* Class GLUI_Bitmap */
385
/************************************************************/
388
GLUI_Bitmap is a simple 2D texture map. It's used
389
to represent small textures like checkboxes, arrows, etc.
390
via the GLUI_StdBitmaps class.
394
friend class GLUI_StdBitmaps;
400
/** Create bitmap from greyscale byte image */
401
void init_grey(unsigned char *array);
403
/** Create bitmap from color int image */
404
void init(int *array);
407
/** RGB pixel data */
408
unsigned char *pixels;
413
/************************************************************/
415
/* Class GLUI_StdBitmap */
417
/************************************************************/
420
Keeps an array of GLUI_Bitmap objects to represent all the
421
images used in the UI: checkboxes, arrows, etc.
423
class GLUI_StdBitmaps
429
/** Return the width (in pixels) of the n'th standard bitmap. */
430
int width (int n) const;
431
/** Return the height (in pixels) of the n'th standard bitmap. */
432
int height(int n) const;
434
/** Draw the n'th standard bitmap (one of the enums
435
listed in GLUI_StdBitmaps_Codes) at pixel corner (x,y).
437
void draw(int n, int x, int y) const;
440
GLUI_Bitmap bitmaps[GLUI_STDBITMAP_NUM_ITEMS];
443
/************************************************************/
445
/* Master GLUI Class */
447
/************************************************************/
450
The master manages our interaction with GLUT.
451
There's only one GLUI_Master_Object.
453
class GLUI_Master_Object
456
friend void glui_idle_func();
460
GLUI_Master_Object();
461
~GLUI_Master_Object();
464
GLUI_Control *active_control, *curr_left_button_glut_menu;
465
GLUI *active_control_glui;
468
GLUI_Glut_Window *find_glut_window( int window_id );
470
void set_glutIdleFunc(void (*f)(void));
473
void (*glut_keyboard_CB)(unsigned char, int, int);
474
void (*glut_reshape_CB)(int, int);
475
void (*glut_special_CB)(int, int, int);
476
void (*glut_mouse_CB)(int,int,int,int);
478
void (*glut_passive_motion_CB)(int,int);
479
void (*glut_visibility_CB)(int);
480
void (*glut_motion_CB)(int,int);
481
void (*glut_display_CB)(void);
482
void (*glut_entry_CB)(int);
485
void set_left_button_glut_menu_control( GLUI_Control *control );
487
/********** GLUT callthroughs **********/
488
/* These are the glut callbacks that we do not handle */
490
void set_glutReshapeFunc (void (*f)(int width, int height));
491
void set_glutKeyboardFunc(void (*f)(unsigned char key, int x, int y));
492
void set_glutSpecialFunc (void (*f)(int key, int x, int y));
493
void set_glutMouseFunc (void (*f)(int, int, int, int ));
495
void set_glutDisplayFunc(void (*f)(void)) {glutDisplayFunc(f);}
496
void set_glutTimerFunc(unsigned int millis, void (*f)(int value), int value)
497
{ ::glutTimerFunc(millis,f,value);}
498
void set_glutOverlayDisplayFunc(void(*f)(void)){glutOverlayDisplayFunc(f);}
499
void set_glutSpaceballMotionFunc(Int3_CB f) {glutSpaceballMotionFunc(f);}
500
void set_glutSpaceballRotateFunc(Int3_CB f) {glutSpaceballRotateFunc(f);}
501
void set_glutSpaceballButtonFunc(Int2_CB f) {glutSpaceballButtonFunc(f);}
502
void set_glutTabletMotionFunc(Int2_CB f) {glutTabletMotionFunc(f);}
503
void set_glutTabletButtonFunc(Int4_CB f) {glutTabletButtonFunc(f);}
504
/* void set_glutWindowStatusFunc(Int1_CB f) {glutWindowStatusFunc(f);} */
505
void set_glutMenuStatusFunc(Int3_CB f) {glutMenuStatusFunc(f);}
506
void set_glutMenuStateFunc(Int1_CB f) {glutMenuStateFunc(f);}
507
void set_glutButtonBoxFunc(Int2_CB f) {glutButtonBoxFunc(f);}
508
void set_glutDialsFunc(Int2_CB f) {glutDialsFunc(f);}
511
GLUI *create_glui( const char *name, long flags=0, int x=-1, int y=-1 );
512
GLUI *create_glui_subwindow( int parent_window, long flags=0 );
513
GLUI *find_glui_by_window_id( int window_id );
514
void get_viewport_area( int *x, int *y, int *w, int *h );
515
void auto_set_viewport();
517
void sync_live_all();
521
float get_version() { return GLUI_VERSION; }
523
void glui_setIdleFuncIfNecessary(void);
526
GLUI_Node glut_windows;
527
void (*glut_idle_CB)(void);
529
void add_cb_to_glut_window(int window,int cb_type,void *cb);
533
This is the only GLUI_Master_Object in existence.
535
extern GLUI_Master_Object GLUI_Master;
537
/************************************************************/
539
/* Class for managing a GLUT window */
541
/************************************************************/
544
A top-level window. The GLUI_Master GLUT callback can route events
545
to the callbacks in this class, for arbitrary use by external users.
546
(see GLUI_Master_Object::set_glutKeyboardFunc).
548
This entire approach seems to be superceded by the "subwindow" flavor
551
class GLUI_Glut_Window : public GLUI_Node
558
/*********** Pointers to GLUT callthrough functions *****/
559
void (*glut_keyboard_CB)(unsigned char, int, int);
560
void (*glut_special_CB)(int, int, int);
561
void (*glut_reshape_CB)(int, int);
562
void (*glut_passive_motion_CB)(int,int);
563
void (*glut_mouse_CB)(int,int,int,int);
564
void (*glut_visibility_CB)(int);
565
void (*glut_motion_CB)(int,int);
566
void (*glut_display_CB)(void);
567
void (*glut_entry_CB)(int);
570
/************************************************************/
572
/* Main Window GLUI class (not user-level) */
574
/************************************************************/
577
A GLUI_Main handles GLUT events for one window, routing them to the
578
appropriate controls. The central user-visible "GLUI" class
579
inherits from this class; users should not allocate GLUT_Main objects.
581
There's a separate GLUI_Main object for:
582
- Each top-level window with GUI stuff in it.
583
- Each "subwindow" of another top-level window.
585
All the GLUI_Main objects are listed in GLUI_Master.gluis.
586
A better name for this class might be "GLUI_Environment";
587
this class provides the window-level context for every control.
589
class GLUI_Main : public GLUI_Node
591
/********** Friend classes *************/
593
friend class GLUI_Control;
594
friend class GLUI_Rotation;
595
friend class GLUI_Translation;
597
friend class GLUI_Master_Object;
599
/*********** Friend functions **********/
601
friend void glui_mouse_func(int button, int state, int x, int y);
602
friend void glui_keyboard_func(unsigned char key, int x, int y);
603
friend void glui_special_func(int key, int x, int y);
604
friend void glui_passive_motion_func(int x, int y);
605
friend void glui_reshape_func( int w, int h );
606
friend void glui_visibility_func(int state);
607
friend void glui_motion_func(int x, int y);
608
friend void glui_entry_func(int state);
609
friend void glui_display_func( void );
610
friend void glui_idle_func(void);
612
friend void glui_parent_window_reshape_func( int w, int h );
613
friend void glui_parent_window_keyboard_func( unsigned char, int, int );
614
friend void glui_parent_window_special_func( int, int, int );
615
friend void glui_parent_window_mouse_func( int, int, int, int );
619
int main_gfx_window_id;
620
int mouse_button_down;
622
int top_level_glut_window_id;
623
GLUI_Control *active_control;
624
GLUI_Control *mouse_over_control;
625
GLUI_Panel *main_panel;
627
buffer_front=1, ///< Draw updated controls directly to screen.
628
buffer_back=2 ///< Double buffering: postpone updates until next redraw.
630
buffer_mode_t buffer_mode; ///< Current drawing mode
638
/********** Misc functions *************/
640
GLUI_Control *find_control( int x, int y );
641
GLUI_Control *find_next_control( GLUI_Control *control );
642
GLUI_Control *find_next_control_rec( GLUI_Control *control );
643
GLUI_Control *find_next_control_( GLUI_Control *control );
644
GLUI_Control *find_prev_control( GLUI_Control *control );
645
void create_standalone_window( const char *name, int x=-1, int y=-1 );
646
void create_subwindow( int parent,int window_alignment );
647
void setup_default_glut_callbacks( void );
649
void mouse(int button, int state, int x, int y);
650
void keyboard(unsigned char key, int x, int y);
651
void special(int key, int x, int y);
652
void passive_motion(int x, int y);
653
void reshape( int w, int h );
654
void visibility(int state);
655
void motion(int x, int y);
656
void entry(int state);
657
void display( void );
659
int needs_idle(void);
661
void (*glut_mouse_CB)(int, int, int, int);
662
void (*glut_keyboard_CB)(unsigned char, int, int);
663
void (*glut_special_CB)(int, int, int);
664
void (*glut_reshape_CB)(int, int);
667
/*********** Controls ************/
669
virtual int add_control( GLUI_Node *parent, GLUI_Control *control );
672
/********** Constructors and Destructors ***********/
677
GLUI_StdBitmaps std_bitmaps;
678
GLUI_String window_name;
680
float bkgd_color_f[3];
685
void adjust_glut_xy( int &x, int &y ) { x; y = h-y; }
686
void activate_control( GLUI_Control *control, int how );
687
void align_controls( GLUI_Control *control );
688
void deactivate_current_control( void );
690
/** Draw a 3D-look pushed-out box around this rectangle */
691
void draw_raised_box( int x, int y, int w, int h );
692
/** Draw a 3D-look pushed-in box around this rectangle */
693
void draw_lowered_box( int x, int y, int w, int h );
695
/** Return true if this control should redraw itself immediately (front buffer);
696
Or queue up a redraw and return false if it shouldn't (back buffer).
698
bool should_redraw_now(GLUI_Control *ctl);
700
/** Switch to the appropriate draw buffer now. Returns the old draw buffer.
701
This routine should probably only be called from inside the GLUI_DrawingSentinal,
702
in glui_internal_control.h
704
int set_current_draw_buffer();
705
/** Go back to using this draw buffer. Undoes set_current_draw_buffer. */
706
void restore_draw_buffer( int buffer_state );
708
/** Pack, resize the window, and redraw all the controls. */
711
/** Redraw the main graphics window */
712
void post_update_main_gfx();
714
/** Recompute the sizes and positions of all controls */
715
void pack_controls();
717
void close_internal();
718
void check_subwindow_position();
719
void set_ortho_projection();
721
int get_glut_window_id( void ) { return glut_window_id; } /* JVK */
724
/************************************************************/
726
/* GLUI_Control: base class for all controls */
728
/************************************************************/
731
All the GUI objects inherit from GLUI_Control: buttons,
732
checkboxes, labels, edit boxes, scrollbars, etc.
733
Most of the work of this class is in routing events,
734
like keystrokes, mouseclicks, redraws, and sizing events.
736
Yes, this is a huge and hideous class. It needs to be
737
split up into simpler subobjects. None of the data members
738
should be directly accessed by users (they should be protected,
739
not public); only subclasses.
741
class GLUI_Control : public GLUI_Node
745
/** Onscreen coordinates */
746
int w, h; /* dimensions of control */
748
int x_off, y_off_top, y_off_bot; /* INNER margins, by which child
749
controls are indented */
750
int contain_x, contain_y;
751
int contain_w, contain_h;
752
/* if this is a container control (e.g.,
753
radiogroup or panel) this indicated dimensions
754
of inner area in which controls reside */
756
/** "activation" for tabbing between controls. */
757
int active_type; ///< "GLUI_CONTROL_ACTIVE_..."
758
bool active; ///< If true, we've got the focus
759
bool can_activate; ///< If false, remove from tab order.
760
bool spacebar_mouse_click; ///< Spacebar simulates click.
763
long user_id; ///< Integer to pass to callback function.
764
GLUI_CB callback; ///< User callback function, or NULL.
766
/** Variable value storage */
767
float float_val; /**< Our float value */
768
int int_val; /**< Our integer value */
769
float float_array_val[GLUI_DEF_MAX_ARRAY];
770
int float_array_size;
771
GLUI_String text; /**< The text inside this control */
773
/** "Live variable" updating */
774
void *ptr_val; /**< A pointer to the user's live variable value */
777
/* These variables store the last value that live variable was known to have. */
779
float last_live_float;
780
GLUI_String last_live_text;
781
float last_live_float_array[GLUI_DEF_MAX_ARRAY];
783
/** Properties of our control */
784
GLUI *glui; /**< Our containing event handler (NEVER NULL during event processing!) */
785
bool is_container; /**< Is this a container class (e.g., panel) */
787
bool enabled; /**< Is this control grayed out? */
788
GLUI_String name; /**< The name of this control */
789
void *font; /**< Our glutbitmap font */
790
bool collapsible, is_open;
791
GLUI_Node collapsed_node;
792
bool hidden; /* Collapsed controls (and children) are hidden */
793
int char_widths[CHAR_WIDTH_HASH_SIZE][2]; /* Character width hash table */
796
/*** Get/Set values ***/
797
virtual void set_name( const char *string );
798
virtual void set_int_val( int new_int ) { int_val = new_int; output_live(true); }
799
virtual void set_float_val( float new_float ) { float_val = new_float; output_live(true); }
800
virtual void set_ptr_val( void *new_ptr ) { ptr_val = new_ptr; output_live(true); }
801
virtual void set_float_array_val( float *array_ptr );
803
virtual float get_float_val( void ) { return float_val; }
804
virtual int get_int_val( void ) { return int_val; }
805
virtual void get_float_array_val( float *array_ptr );
806
virtual int get_id( void ) const { return int(user_id); }
807
virtual void set_id( int id ) { user_id=id; }
809
virtual int mouse_down_handler( int local_x, int local_y ) { local_x; local_y; return false; }
810
virtual int mouse_up_handler( int local_x, int local_y, bool inside ) { local_x; local_y; inside; return false; }
811
virtual int mouse_held_down_handler( int local_x, int local_y, bool inside) { local_x; local_y; inside; return false; }
812
virtual int key_handler( unsigned char key, int modifiers ) { key; modifiers; return false; }
813
virtual int special_handler( int key,int modifiers ) { key; modifiers; return false; }
815
virtual void update_size( void ) { }
816
virtual void idle( void ) { }
817
virtual int mouse_over( int state, int x, int y ) { state; x; y; return false; }
819
virtual void enable( void );
820
virtual void disable( void );
821
virtual void activate( int how ) { how; active = true; }
822
virtual void deactivate( void ) { active = false; }
824
/** Hide (shrink into a rollout) and unhide (expose from a rollout) */
825
void hide_internal( int recurse );
826
void unhide_internal( int recurse );
828
/** Return true if it currently makes sense to draw this class. */
829
int can_draw( void ) { return (glui != NULL && hidden == false); }
831
/** Redraw this control.
832
In single-buffering mode (drawing to GL_FRONT), this is just
833
a call to translate_and_draw_front (after a can_draw() check).
834
In double-buffering mode (drawing to GL_BACK), this queues up
835
a redraw and returns false, since you shouldn't draw yet.
839
/** Redraw everybody in our window. */
840
void redraw_window(void);
842
virtual void align( void );
843
void pack( int x, int y ); /* Recalculate positions and offsets */
844
void pack_old( int x, int y );
845
void draw_recursive( int x, int y );
846
int set_to_glut_window( void );
847
void restore_window( int orig );
848
void translate_and_draw_front( void );
849
void translate_to_origin( void )
850
{glTranslatef((float)x_abs+.5f,(float)y_abs+.5f,0.0f);}
851
virtual void draw( int x, int y )=0;
852
void set_font( void *new_font );
853
void *get_font( void );
854
int string_width( const char *text );
855
int string_width( const GLUI_String &str )
856
{ return string_width(str.c_str()); }
857
int char_width( char c );
859
void draw_name( int x, int y );
860
void draw_box_inwards_outline( int x_min, int x_max,
861
int y_min, int y_max );
862
void draw_box( int x_min, int x_max, int y_min, int y_max,
863
float r, float g, float b );
864
void draw_bkgd_box( int x_min, int x_max, int y_min, int y_max );
865
void draw_emboss_box( int x_min, int x_max,int y_min,int y_max);
866
void draw_string( const char *text );
867
void draw_string( const GLUI_String &s )
868
{ draw_string(s.c_str()); }
869
void draw_char( char c );
870
void draw_active_box( int x_min, int x_max, int y_min, int y_max );
871
void set_to_bkgd_color( void );
873
void set_w( int new_w );
874
void set_h( int new_w );
875
void set_alignment( int new_align );
876
void sync_live( int recurse, int draw ); /* Reads live variable */
877
void init_live( void );
878
void output_live( int update_main_gfx ); /** Writes live variable **/
879
virtual void set_text( const char *t ) { t; }
880
void execute_callback( void );
881
void get_this_column_dims( int *col_x, int *col_y,
882
int *col_w, int *col_h,
883
int *col_x_off, int *col_y_off );
884
virtual bool needs_idle( void ) const;
885
virtual bool wants_tabs() const { return false; }
890
y_off_top = GLUI_YOFF;
891
y_off_bot = GLUI_YOFF;
898
float_array_size = 0;
899
glui_format_str(name, "Control: %p", this);
901
last_live_float = 0.0;
904
w = GLUI_DEFAULT_CONTROL_WIDTH;
905
h = GLUI_DEFAULT_CONTROL_HEIGHT;
907
active_type = GLUI_CONTROL_ACTIVE_MOUSEDOWN;
908
alignment = GLUI_ALIGN_LEFT;
909
is_container = false;
910
can_activate = true; /* By default, you can activate a control */
911
spacebar_mouse_click = true; /* Does spacebar simulate a mouse click? */
912
live_type = GLUI_LIVE_NONE;
914
last_live_text == "";
919
memset(char_widths, -1, sizeof(char_widths)); /* JVK */
921
for( i=0; i<GLUI_DEF_MAX_ARRAY; i++ )
922
float_array_val[i] = last_live_float_array[i] = 0.0;
925
virtual ~GLUI_Control();
928
/************************************************************/
930
/* Button class (container) */
932
/************************************************************/
934
An onscreen, clickable button--an outlined label that
935
can be clicked. When clicked, a button
936
calls its GLUI_CB callback with its ID.
938
class GLUI_Button : public GLUI_Control
941
bool currently_inside;
943
int mouse_down_handler( int local_x, int local_y );
944
int mouse_up_handler( int local_x, int local_y, bool inside );
945
int mouse_held_down_handler( int local_x, int local_y, bool inside );
946
int key_handler( unsigned char key,int modifiers );
948
void draw( int x, int y );
949
void draw_pressed( void );
950
void draw_text( int sunken );
952
void update_size( void );
957
@param parent The panel our object is inside; or the main GLUI object.
958
@param name The text inside the button.
959
@param id Optional ID number, to pass to the optional callback function.
960
@param callback Optional callback function, taking either the int ID or control.
962
GLUI_Button( GLUI_Node *parent, const char *name,
963
int id=-1, GLUI_CB cb=GLUI_CB() );
964
GLUI_Button( void ) { common_init(); };
967
void common_init(void) {
968
glui_format_str(name, "Button: %p", this );
969
h = GLUI_BUTTON_SIZE;
971
alignment = GLUI_ALIGN_CENTER;
977
/************************************************************/
979
/* Checkbox class (container) */
981
/************************************************************/
984
A checkbox, which can be checked on or off. Can be linked
985
to an int value, which gets 1 for on and 0 for off.
987
class GLUI_Checkbox : public GLUI_Control
991
bool currently_inside;
994
int mouse_down_handler( int local_x, int local_y );
995
int mouse_up_handler( int local_x, int local_y, bool inside );
996
int mouse_held_down_handler( int local_x, int local_y, bool inside );
997
int key_handler( unsigned char key,int modifiers );
999
void update_size( void );
1001
void draw( int x, int y );
1003
void draw_active_area( void );
1004
void draw_empty_box( void );
1005
void set_int_val( int new_val );
1008
Create a new checkbox object.
1010
@param parent The panel our object is inside; or the main GLUI object.
1011
@param name Label next to our checkbox.
1012
@param value_ptr Optional integer value to attach to this checkbox. When the
1013
checkbox is checked or unchecked, *value_ptr will also be changed. ("Live Vars").
1014
@param id Optional ID number, to pass to the optional callback function.
1015
@param callback Optional callback function, taking either the int ID or control.
1017
GLUI_Checkbox(GLUI_Node *parent, const char *name, int *value_ptr=NULL,
1018
int id=-1, GLUI_CB callback=GLUI_CB());
1019
GLUI_Checkbox( void ) { common_init(); }
1022
void common_init(void) {
1023
glui_format_str( name, "Checkbox: %p", this );
1025
h = GLUI_CHECKBOX_SIZE;
1028
can_activate = true;
1029
live_type = GLUI_LIVE_INT; /* This control has an 'int' live var */
1033
/************************************************************/
1037
/************************************************************/
1040
A GLUI_Column object separates all previous controls
1041
from subsequent controls with a vertical bar.
1043
class GLUI_Column : public GLUI_Control
1046
void draw( int x, int y );
1049
Create a new column, which separates the previous controls
1050
from subsequent controls.
1052
@param parent The panel our object is inside; or the main GLUI object.
1053
@param draw_bar If true, draw a visible bar between new and old controls.
1055
GLUI_Column( GLUI_Node *parent, int draw_bar = true );
1056
GLUI_Column( void ) { common_init(); }
1059
void common_init() {
1063
can_activate = false;
1068
/************************************************************/
1070
/* Panel class (container) */
1072
/************************************************************/
1075
A GLUI_Panel contains a group of related controls.
1077
class GLUI_Panel : public GLUI_Control
1082
Create a new panel. A panel groups together a set of related controls.
1084
@param parent The outer panel our panel is inside; or the main GLUI object.
1085
@param name The string name at the top of our panel.
1086
@param type Optional style to display the panel with--GLUI_PANEL_EMBOSSED by default.
1087
GLUI_PANEL_RAISED causes the panel to appear higher than the surroundings.
1088
GLUI_PANEL_NONE causes the panel's outline to be invisible.
1090
GLUI_Panel( GLUI_Node *parent, const char *name,
1091
int type=GLUI_PANEL_EMBOSSED );
1092
GLUI_Panel() { common_init(); }
1094
void draw( int x, int y );
1095
void set_name( const char *text );
1096
void set_type( int new_type );
1098
void update_size( void );
1101
void common_init( void ) {
1103
h = GLUI_DEFAULT_CONTROL_HEIGHT + 7;
1104
int_val = GLUI_PANEL_EMBOSSED;
1105
alignment = GLUI_ALIGN_CENTER;
1106
is_container = true;
1107
can_activate = false;
1112
/************************************************************/
1114
/* File Browser class (container) */
1116
/************************************************************/
1119
A list of files the user can select from.
1121
class GLUI_FileBrowser : public GLUI_Panel
1125
Create a new list of files the user can select from.
1127
@param parent The panel our object is inside; or the main GLUI object.
1128
@param name Prompt to give to the user at the top of the file browser.
1129
@param frame_type Optional style to display the panel with--GLUI_PANEL_EMBOSSED by default.
1130
GLUI_PANEL_RAISED causes the panel to appear higher than the surroundings.
1131
GLUI_PANEL_NONE causes the panel's outline to be invisible.
1132
@param id Optional ID number, to pass to the optional callback function.
1133
@param callback Optional callback function, taking either the int ID or control.
1135
GLUI_FileBrowser( GLUI_Node *parent,
1137
int frame_type = GLUI_PANEL_EMBOSSED,
1139
GLUI_CB callback = GLUI_CB());
1142
GLUI_String current_dir;
1144
void fbreaddir(const char *);
1145
static void dir_list_callback(GLUI_Control*);
1149
const char* get_file() { return file.c_str(); }
1150
void set_allow_change_dir(int c) { allow_change_dir = c; }
1155
w = GLUI_DEFAULT_CONTROL_WIDTH;
1156
h = GLUI_DEFAULT_CONTROL_HEIGHT;
1157
int_val = GLUI_PANEL_EMBOSSED;
1158
alignment = GLUI_ALIGN_CENTER;
1159
is_container = true;
1160
can_activate = false;
1161
allow_change_dir = true;
1172
int allow_change_dir;
1176
/************************************************************/
1178
/* Rollout class (container) */
1180
/************************************************************/
1182
A rollout contains a set of controls,
1183
like a panel, but can be collapsed to just the name.
1185
class GLUI_Rollout : public GLUI_Panel
1190
Create a new rollout. A rollout contains a set of controls,
1191
like a panel, but can be collapsed to just the name.
1193
@param parent The panel our object is inside; or the main GLUI object.
1194
@param name String to show at the top of the rollout.
1195
@param open Optional boolean. If true (the default), the rollout's controls are displayed.
1196
If false, the rollout is closed to display only the name.
1197
@param type Optional style to display the panel with--GLUI_PANEL_EMBOSSED by default.
1198
GLUI_PANEL_RAISED causes the panel to appear higher than the surroundings.
1199
GLUI_PANEL_NONE causes the panel's outline to be invisible.
1201
GLUI_Rollout( GLUI_Node *parent, const char *name, int open=true,
1202
int type=GLUI_PANEL_EMBOSSED );
1203
GLUI_Rollout( void ) { common_init(); }
1206
bool currently_inside, initially_inside;
1209
void draw( int x, int y );
1210
void draw_pressed( void );
1211
int mouse_down_handler( int local_x, int local_y );
1212
int mouse_up_handler( int local_x, int local_y, bool inside );
1213
int mouse_held_down_handler( int local_x, int local_y, bool inside );
1218
void update_size( void );
1221
void common_init() {
1222
currently_inside = false;
1223
initially_inside = false;
1224
can_activate = true;
1225
is_container = true;
1226
h = GLUI_DEFAULT_CONTROL_HEIGHT + 7;
1227
w = GLUI_DEFAULT_CONTROL_WIDTH;
1234
/************************************************************/
1236
/* Tree Panel class (container) */
1238
/************************************************************/
1241
One collapsible entry in a GLUI_TreePanel.
1243
class GLUI_Tree : public GLUI_Panel
1246
GLUI_Tree(GLUI_Node *parent, const char *name,
1247
int open=false, int inset=0);
1250
int level; // how deep is this node
1251
float red; //Color coding of column line
1254
float lred; //Color coding of level name
1258
GLUI_Column *column;
1259
int is_current; // Whether this tree is the
1260
// current root in a treePanel
1265
bool currently_inside, initially_inside;
1267
GLUI_String level_name; // level name, eg: 1.1.2, III, or 3
1268
GLUI_TreePanel *panel;
1270
void draw( int x, int y );
1271
void draw_pressed( void );
1272
int mouse_down_handler( int local_x, int local_y );
1273
int mouse_up_handler( int local_x, int local_y, bool inside );
1274
int mouse_held_down_handler( int local_x, int local_y, bool inside );
1275
void set_column(GLUI_Column *c) { column = c; }
1279
/* void set_name( const char *text ) { panel.set_name( text ); }; */
1280
void update_size( void );
1281
void set_id(int i) { id = i; }
1282
void set_level(int l) { level = l; }
1283
void set_format(int f) { format = f; }
1284
void set_current(int c) { is_current = c; }
1285
int get_id() { return id; }
1286
int get_level() { return level; }
1287
int get_child_number() { return child_number; }
1288
void enable_bar() { if (column) { column->int_val = 1; set_color(red, green, blue); } }
1289
void disable_bar() { if (column) { column->int_val = 0; } }
1290
void set_child_number(int c) { child_number = c; }
1291
void set_level_color(float r, float g, float b) {
1296
void set_color(float r, float g, float b) {
1304
currently_inside = false;
1305
initially_inside = false;
1306
can_activate = true;
1307
is_container = true;
1308
h = GLUI_DEFAULT_CONTROL_HEIGHT + 7;
1309
w = GLUI_DEFAULT_CONTROL_WIDTH;
1331
/************************************************************/
1333
/* TreePanel class (container) JVK */
1335
/************************************************************/
1338
Manages, maintains, and formats a tree of GLUI_Tree objects.
1339
These are shown in a heirarchical, collapsible display.
1341
FIXME: There's an infinite loop in the traversal code (OSL 2006/06)
1343
class GLUI_TreePanel : public GLUI_Panel
1346
GLUI_TreePanel(GLUI_Node *parent, const char *name,
1347
bool open=false, int inset=0);
1359
/* These variables allow the tree panel to traverse the tree
1360
using only two function calls. (Well, four, if you count
1363
GLUI_Tree *curr_branch; /* Current Branch */
1364
GLUI_Panel *curr_root; /* Current Root */
1367
void set_color(float r, float g, float b);
1368
void set_level_color(float r, float g, float b);
1369
void set_format(int f) { format = f; }
1371
/* Adds branch to curr_root */
1372
GLUI_Tree * ab(const char *name, GLUI_Tree *root = NULL);
1373
/* Goes up one level, resets curr_root and curr_branch to parents*/
1374
void fb(GLUI_Tree *branch= NULL);
1375
/* Deletes the curr_branch, goes up one level using fb */
1376
void db(GLUI_Tree *branch = NULL);
1377
/* Finds the very last branch of curr_root, resets vars */
1378
void descendBranch(GLUI_Panel *root = NULL);
1379
/* Resets curr_root and curr branch to TreePanel and lastChild */
1380
void resetToRoot(GLUI_Panel *new_root = NULL);
1382
void refresh( void );
1383
void expand_all( void );
1384
void collapse_all( void );
1385
void update_all( void );
1386
void initNode(GLUI_Tree *temp);
1387
void formatNode(GLUI_Tree *temp);
1390
int uniqueID( void ) { next_id++; return next_id - 1; }
1404
/************************************************************/
1406
/* User-Level GLUI class */
1408
/************************************************************/
1410
class GLUI_Rotation;
1411
class GLUI_Translation;
1414
The main user-visible interface object to GLUI.
1417
class GLUI : public GLUI_Main
1420
/** DEPRECATED interface for creating new GLUI objects */
1421
int add_control( GLUI_Control *control ) { return main_panel->add_control(control); }
1423
void add_column( int draw_bar = true );
1424
void add_column_to_panel( GLUI_Panel *panel, int draw_bar = true );
1426
void add_separator( void );
1427
void add_separator_to_panel( GLUI_Panel *panel );
1430
*add_radiogroup( int *live_var=NULL,
1431
int user_id=-1,GLUI_CB callback=GLUI_CB());
1434
*add_radiogroup_to_panel( GLUI_Panel *panel,
1436
int user_id=-1, GLUI_CB callback=GLUI_CB() );
1438
*add_radiobutton_to_group( GLUI_RadioGroup *group,
1441
GLUI_Listbox *add_listbox( const char *name, int *live_var=NULL,
1442
int id=-1, GLUI_CB callback=GLUI_CB() );
1443
GLUI_Listbox *add_listbox_to_panel( GLUI_Panel *panel,
1444
const char *name, int *live_var=NULL,
1445
int id=-1, GLUI_CB callback=GLUI_CB());
1447
GLUI_Rotation *add_rotation( const char *name, float *live_var=NULL,
1448
int id=-1, GLUI_CB callback=GLUI_CB() );
1449
GLUI_Rotation *add_rotation_to_panel( GLUI_Panel *panel,
1450
const char *name, float *live_var=NULL,
1451
int id=-1, GLUI_CB callback=GLUI_CB());
1453
GLUI_Translation *add_translation( const char *name,
1454
int trans_type, float *live_var=NULL,
1455
int id=-1, GLUI_CB callback=GLUI_CB() );
1456
GLUI_Translation *add_translation_to_panel(
1457
GLUI_Panel *panel, const char *name,
1458
int trans_type, float *live_var=NULL,
1459
int id=-1, GLUI_CB callback=GLUI_CB());
1461
GLUI_Checkbox *add_checkbox( const char *name,
1463
int id=-1, GLUI_CB callback=GLUI_CB());
1464
GLUI_Checkbox *add_checkbox_to_panel( GLUI_Panel *panel, const char *name,
1465
int *live_var=NULL, int id=-1,
1466
GLUI_CB callback=GLUI_CB());
1468
GLUI_Button *add_button( const char *name, int id=-1,
1469
GLUI_CB callback=GLUI_CB());
1470
GLUI_Button *add_button_to_panel( GLUI_Panel *panel, const char *name,
1471
int id=-1, GLUI_CB callback=GLUI_CB() );
1473
GLUI_StaticText *add_statictext( const char *name );
1474
GLUI_StaticText *add_statictext_to_panel( GLUI_Panel *panel, const char *name );
1476
GLUI_EditText *add_edittext( const char *name,
1477
int data_type=GLUI_EDITTEXT_TEXT,
1479
int id=-1, GLUI_CB callback=GLUI_CB() );
1480
GLUI_EditText *add_edittext_to_panel( GLUI_Panel *panel,
1482
int data_type=GLUI_EDITTEXT_TEXT,
1483
void *live_var=NULL, int id=-1,
1484
GLUI_CB callback=GLUI_CB() );
1485
GLUI_EditText *add_edittext( const char *name, GLUI_String& live_var,
1486
int id=-1, GLUI_CB callback=GLUI_CB() );
1487
GLUI_EditText *add_edittext_to_panel( GLUI_Panel *panel, const char *name,
1488
GLUI_String& live_var, int id=-1,
1489
GLUI_CB callback=GLUI_CB() );
1491
GLUI_Spinner *add_spinner( const char *name,
1492
int data_type=GLUI_SPINNER_INT,
1493
void *live_var=NULL,
1494
int id=-1, GLUI_CB callback=GLUI_CB() );
1495
GLUI_Spinner *add_spinner_to_panel( GLUI_Panel *panel,
1497
int data_type=GLUI_SPINNER_INT,
1498
void *live_var=NULL,
1500
GLUI_CB callback=GLUI_CB() );
1502
GLUI_Panel *add_panel( const char *name, int type=GLUI_PANEL_EMBOSSED );
1503
GLUI_Panel *add_panel_to_panel( GLUI_Panel *panel, const char *name,
1504
int type=GLUI_PANEL_EMBOSSED );
1507
GLUI_Rollout *add_rollout( const char *name, int open=true,
1508
int type=GLUI_PANEL_EMBOSSED);
1509
GLUI_Rollout *add_rollout_to_panel( GLUI_Panel *panel, const char *name,
1511
int type=GLUI_PANEL_EMBOSSED);
1514
/** Set the window where our widgets should be displayed. */
1515
void set_main_gfx_window( int window_id );
1516
int get_glut_window_id( void ) { return glut_window_id; }
1518
void enable( void ) { main_panel->enable(); }
1519
void disable( void );
1521
void sync_live( void );
1528
/***** GLUT callback setup functions *****/
1530
void set_glutDisplayFunc(void (*f)(void));
1531
void set_glutReshapeFunc(void (*f)(int width, int height));
1532
void set_glutKeyboardFunc(void (*f)(unsigned char key, int x, int y));
1533
void set_glutSpecialFunc(void (*f)(int key, int x, int y));
1534
void set_glutMouseFunc(void (*f)(int button, int state, int x, int y));
1535
void set_glutMotionFunc(void (*f)(int x, int y));
1536
void set_glutPassiveMotionFunc(void (*f)(int x, int y));
1537
void set_glutEntryFunc(void (*f)(int state));
1538
void set_glutVisibilityFunc(void (*f)(int state));
1539
void set_glutInit( int *argcp, const char **argv );
1540
void set_glutInitWindowSize(int width, int height);
1541
void set_glutInitWindowPosition(int x, int y);
1542
void set_glutInitDisplayMode(unsigned int mode);
1543
int set_glutCreateWindow(const char *name);
1546
/***** Constructors and desctructors *****/
1548
int init( const char *name, long flags, int x, int y, int parent_window );
1550
virtual int add_control( GLUI_Node *parent, GLUI_Control *control ) {
1551
return GLUI_Main::add_control( parent, control );
1555
/************************************************************/
1557
/* EditText class */
1559
/************************************************************/
1561
class GLUI_EditText : public GLUI_Control
1566
GLUI_String orig_text;
1570
int substring_start; /*substring that gets displayed in box*/
1572
int sel_start, sel_end; /* current selection */
1574
int last_insertion_pt;
1575
float float_low, float_high;
1576
int int_low, int_high;
1577
GLUI_Spinner *spinner;
1582
int mouse_down_handler( int local_x, int local_y );
1583
int mouse_up_handler( int local_x, int local_y, bool inside );
1584
int mouse_held_down_handler( int local_x, int local_y, bool inside );
1585
int key_handler( unsigned char key,int modifiers );
1586
int special_handler( int key, int modifiers );
1588
void activate( int how );
1589
void deactivate( void );
1591
void draw( int x, int y );
1593
int mouse_over( int state, int x, int y );
1595
int find_word_break( int start, int direction );
1596
int substring_width( int start, int end );
1597
void clear_substring( int start, int end );
1598
int find_insertion_pt( int x, int y );
1599
int update_substring_bounds( void );
1600
void update_and_draw_text( void );
1601
void draw_text( int x, int y );
1602
void draw_insertion_pt( void );
1603
void set_numeric_text( void );
1604
void update_x_offsets( void );
1605
void update_size( void );
1607
void set_float_limits( float low,float high,int limit_type=GLUI_LIMIT_CLAMP);
1608
void set_int_limits( int low, int high, int limit_type=GLUI_LIMIT_CLAMP );
1609
void set_float_val( float new_val );
1610
void set_int_val( int new_val );
1611
void set_text( const char *text );
1612
void set_text( const GLUI_String &s) { set_text(s.c_str()); }
1613
const char *get_text() { return text.c_str(); }
1615
void dump( FILE *out, const char *text );
1617
// Constructor, no live variable
1618
GLUI_EditText( GLUI_Node *parent, const char *name,
1619
int text_type=GLUI_EDITTEXT_TEXT,
1620
int id=-1, GLUI_CB callback=GLUI_CB() );
1621
// Constructor, int live variable
1622
GLUI_EditText( GLUI_Node *parent, const char *name,
1624
int id=-1, GLUI_CB callback=GLUI_CB() );
1625
// Constructor, float live variable
1626
GLUI_EditText( GLUI_Node *parent, const char *name,
1628
int id=-1, GLUI_CB callback=GLUI_CB() );
1629
// Constructor, char* live variable
1630
GLUI_EditText( GLUI_Node *parent, const char *name,
1632
int id=-1, GLUI_CB callback=GLUI_CB() );
1633
// Constructor, std::string live variable
1634
GLUI_EditText( GLUI_Node *parent, const char *name,
1635
std::string &live_var,
1636
int id=-1, GLUI_CB callback=GLUI_CB() );
1638
// Deprecated constructor, only called internally
1639
GLUI_EditText( GLUI_Node *parent, const char *name,
1640
int text_type, void *live_var,
1641
int id, GLUI_CB callback );
1642
// Deprecated constructor, only called internally
1643
GLUI_EditText( void ) { common_init(); }
1646
void common_init( void ) {
1647
h = GLUI_EDITTEXT_HEIGHT;
1648
w = GLUI_EDITTEXT_WIDTH;
1652
last_insertion_pt = -1;
1654
substring_start = 0;
1655
data_type = GLUI_EDITTEXT_TEXT;
1658
has_limits = GLUI_LIMIT_NONE;
1661
active_type = GLUI_CONTROL_ACTIVE_PERMANENT;
1662
can_activate = true;
1663
spacebar_mouse_click = false;
1666
draw_text_only = false;
1668
void common_construct( GLUI_Node *parent, const char *name,
1669
int data_type, int live_type, void *live_var,
1670
int id, GLUI_CB callback );
1673
/************************************************************/
1675
/* CommandLine class */
1677
/************************************************************/
1679
class GLUI_CommandLine : public GLUI_EditText
1682
typedef GLUI_EditText Super;
1684
enum { HIST_SIZE = 100 };
1685
std::vector<GLUI_String> hist_list;
1692
int key_handler( unsigned char key,int modifiers );
1693
int special_handler( int key,int modifiers );
1694
void deactivate( void );
1696
virtual const char *get_history( int command_number ) const
1697
{ return hist_list[command_number - oldest_hist].c_str(); }
1698
virtual GLUI_String& get_history_str( int command_number )
1699
{ return hist_list[command_number - oldest_hist]; }
1700
virtual const GLUI_String& get_history_str( int command_number ) const
1701
{ return hist_list[command_number - oldest_hist]; }
1702
virtual void recall_history( int history_number );
1703
virtual void scroll_history( int direction );
1704
virtual void add_to_history( const char *text );
1705
virtual void reset_history( void );
1707
void dump( FILE *out, const char *text );
1710
GLUI_CommandLine( GLUI_Node *parent, const char *name, void *live_var=NULL,
1711
int id=-1, GLUI_CB callback=GLUI_CB() );
1712
GLUI_CommandLine( void ) { common_init(); }
1714
void common_init() {
1715
hist_list.resize(HIST_SIZE);
1719
commit_flag = false;
1723
/************************************************************/
1725
/* RadioGroup class (container) */
1727
/************************************************************/
1729
class GLUI_RadioGroup : public GLUI_Control
1734
void draw( int x, int y );
1735
void set_name( const char *text );
1736
void set_int_val( int int_val );
1737
void set_selected( int int_val );
1739
void draw_group( int translate );
1741
GLUI_RadioGroup( GLUI_Node *parent, int *live_var=NULL,
1742
int user_id=-1,GLUI_CB callback=GLUI_CB() );
1743
GLUI_RadioGroup( void ) { common_init(); }
1746
void common_init( void ) {
1750
is_container = true;
1755
can_activate = false;
1756
live_type = GLUI_LIVE_INT;
1760
/************************************************************/
1762
/* RadioButton class (container) */
1764
/************************************************************/
1766
class GLUI_RadioButton : public GLUI_Control
1770
bool currently_inside;
1773
int mouse_down_handler( int local_x, int local_y );
1774
int mouse_up_handler( int local_x, int local_y, bool inside );
1775
int mouse_held_down_handler( int local_x, int local_y, bool inside );
1777
void draw( int x, int y );
1778
void update_size( void );
1780
void draw_active_area( void );
1781
void draw_checked( void );
1782
void draw_unchecked( void );
1783
void draw_O( void );
1785
GLUI_RadioButton( GLUI_RadioGroup *group, const char *name );
1786
GLUI_RadioGroup *group;
1791
glui_format_str( name, "RadioButton: %p", (void *) this );
1792
h = GLUI_RADIOBUTTON_SIZE;
1796
can_activate = true;
1801
/************************************************************/
1803
/* Separator class (container) */
1805
/************************************************************/
1807
class GLUI_Separator : public GLUI_Control
1810
void draw( int x, int y );
1812
GLUI_Separator( GLUI_Node *parent );
1813
GLUI_Separator( void ) { common_init(); }
1816
void common_init() {
1818
h = GLUI_SEPARATOR_HEIGHT;
1819
can_activate = false;
1823
#define GLUI_SPINNER_ARROW_WIDTH 12
1824
#define GLUI_SPINNER_ARROW_HEIGHT 8
1825
#define GLUI_SPINNER_ARROW_Y 2
1827
#define GLUI_SPINNER_STATE_NONE 0
1828
#define GLUI_SPINNER_STATE_UP 1
1829
#define GLUI_SPINNER_STATE_DOWN 2
1830
#define GLUI_SPINNER_STATE_BOTH 3
1832
#define GLUI_SPINNER_DEFAULT_GROWTH_EXP 1.05f
1834
/************************************************************/
1836
/* Spinner class (container) */
1838
/************************************************************/
1840
class GLUI_Spinner : public GLUI_Control
1843
// Constructor, no live var
1844
GLUI_Spinner( GLUI_Node* parent, const char *name,
1845
int data_type=GLUI_SPINNER_INT, int id=-1, GLUI_CB callback=GLUI_CB() );
1846
// Constructor, int live var
1847
GLUI_Spinner( GLUI_Node* parent, const char *name,
1848
int *live_var, int id=-1, GLUI_CB callback=GLUI_CB() );
1849
// Constructor, float live var
1850
GLUI_Spinner( GLUI_Node* parent, const char *name,
1851
float *live_var, int id=-1, GLUI_CB callback=GLUI_CB() );
1852
// Deprecated constructor
1853
GLUI_Spinner( GLUI_Node* parent, const char *name,
1856
int id=-1, GLUI_CB callback=GLUI_CB() );
1857
// Deprecated constructor
1858
GLUI_Spinner( void ) { common_init(); }
1860
bool currently_inside;
1862
float growth, growth_exp;
1867
float last_float_val;
1871
GLUI_EditText *edittext;
1873
int mouse_down_handler( int local_x, int local_y );
1874
int mouse_up_handler( int local_x, int local_y, bool inside );
1875
int mouse_held_down_handler( int local_x, int local_y, bool inside );
1876
int key_handler( unsigned char key,int modifiers );
1877
int special_handler( int key,int modifiers );
1879
void draw( int x, int y );
1880
void draw_pressed( void );
1881
void draw_unpressed( void );
1882
void draw_text( int sunken );
1884
void update_size( void );
1886
void set_float_limits( float low,float high,int limit_type=GLUI_LIMIT_CLAMP);
1887
void set_int_limits( int low, int high,int limit_type=GLUI_LIMIT_CLAMP);
1888
int find_arrow( int local_x, int local_y );
1889
void do_drag( int x, int y );
1890
void do_callbacks( void );
1891
void do_click( void );
1893
bool needs_idle( void ) const;
1895
const char *get_text( void );
1897
void set_float_val( float new_val );
1898
void set_int_val( int new_val );
1899
float get_float_val( void );
1900
int get_int_val( void );
1901
void increase_growth( void );
1902
void reset_growth( void );
1904
void set_speed( float speed ) { user_speed = speed; }
1907
void common_init() {
1908
glui_format_str( name, "Spinner: %p", this );
1909
h = GLUI_EDITTEXT_HEIGHT;
1910
w = GLUI_EDITTEXT_WIDTH;
1914
can_activate = true;
1915
state = GLUI_SPINNER_STATE_NONE;
1917
growth_exp = GLUI_SPINNER_DEFAULT_GROWTH_EXP;
1919
first_callback = true;
1922
void common_construct( GLUI_Node* parent, const char *name,
1923
int data_type, void *live_var,
1924
int id, GLUI_CB callback );
1927
/************************************************************/
1929
/* StaticText class */
1931
/************************************************************/
1933
class GLUI_StaticText : public GLUI_Control
1936
void set_text( const char *text );
1937
void draw( int x, int y );
1938
void draw_text( void );
1939
void update_size( void );
1940
void erase_text( void );
1942
GLUI_StaticText(GLUI_Node *parent, const char *name);
1943
GLUI_StaticText( void ) { common_init(); }
1946
void common_init() {
1947
h = GLUI_STATICTEXT_SIZE;
1949
can_activate = false;
1953
/************************************************************/
1955
/* TextBox class - JVK */
1957
/************************************************************/
1959
class GLUI_TextBox : public GLUI_Control
1962
/* GLUI Textbox - JVK */
1963
GLUI_TextBox(GLUI_Node *parent, GLUI_String &live_var,
1964
bool scroll = false, int id=-1, GLUI_CB callback=GLUI_CB() );
1965
GLUI_TextBox( GLUI_Node *parent,
1966
bool scroll = false, int id=-1,
1967
GLUI_CB callback=GLUI_CB() );
1969
GLUI_String orig_text;
1971
int substring_start; /*substring that gets displayed in box*/
1973
int sel_start, sel_end; /* current selection */
1974
int last_insertion_pt;
1982
int insert_x; /* Similar to "insertion_pt", these variables keep */
1983
int insert_y; /* track of where the ptr is, but in pixels */
1984
int keygoal_x; /* where up down keys would like to put insertion pt*/
1985
GLUI_Scrollbar *scrollbar;
1987
int mouse_down_handler( int local_x, int local_y );
1988
int mouse_up_handler( int local_x, int local_y, bool inside );
1989
int mouse_held_down_handler( int local_x, int local_y, bool inside );
1990
int key_handler( unsigned char key,int modifiers );
1991
int special_handler( int key,int modifiers );
1993
void activate( int how );
1994
void deactivate( void );
1996
void enable( void );
1997
void disable( void );
1999
void draw( int x, int y );
2001
int mouse_over( int state, int x, int y );
2003
int get_box_width();
2004
int find_word_break( int start, int direction );
2005
int substring_width( int start, int end, int initial_width=0 );
2006
void clear_substring( int start, int end );
2007
int find_insertion_pt( int x, int y );
2008
int update_substring_bounds( void );
2009
void update_and_draw_text( void );
2010
void draw_text( int x, int y );
2011
void draw_insertion_pt( void );
2012
void update_x_offsets( void );
2013
void update_size( void );
2015
void set_text( const char *text );
2016
const char *get_text( void ) { return text.c_str(); }
2018
void dump( FILE *out, char *text );
2019
void set_tab_w(int w) { tab_width = w; }
2020
void set_start_line(int l) { start_line = l; }
2021
static void scrollbar_callback(GLUI_Control*);
2023
bool wants_tabs( void ) const { return true; }
2028
h = GLUI_TEXTBOX_HEIGHT;
2029
w = GLUI_TEXTBOX_WIDTH;
2030
tab_width = GLUI_TAB_WIDTH;
2038
last_insertion_pt = -1;
2040
substring_start = 0;
2044
active_type = GLUI_CONTROL_ACTIVE_PERMANENT;
2045
can_activate = true;
2046
spacebar_mouse_click = false;
2049
draw_text_only = false;
2051
void common_construct(
2052
GLUI_Node *parent, GLUI_String *live_var,
2053
bool scroll, int id, GLUI_CB callback);
2056
/************************************************************/
2058
/* List class - JVK */
2060
/************************************************************/
2062
class GLUI_List_Item : public GLUI_Node
2069
/************************************************************/
2071
/* List class - JVK */
2073
/************************************************************/
2075
class GLUI_List : public GLUI_Control
2078
/* GLUI List - JVK */
2079
GLUI_List( GLUI_Node *parent, bool scroll = false,
2080
int id=-1, GLUI_CB callback=GLUI_CB() );
2081
/*, GLUI_Control *object = NULL
2082
,GLUI_InterObject_CB obj_cb = NULL);*/
2084
GLUI_List( GLUI_Node *parent,
2085
GLUI_String& live_var, bool scroll = false,
2087
GLUI_CB callback=GLUI_CB()
2088
/*,GLUI_Control *object = NULL */
2089
/*,GLUI_InterObject_CB obj_cb = NULL*/);
2092
GLUI_String orig_text;
2099
GLUI_Scrollbar *scrollbar;
2100
GLUI_List_Item items_list;
2101
GLUI_Control *associated_object;
2105
int last_click_time;
2107
int mouse_down_handler( int local_x, int local_y );
2108
int mouse_up_handler( int local_x, int local_y, bool inside );
2109
int mouse_held_down_handler( int local_x, int local_y, bool inside );
2110
int key_handler( unsigned char key,int modifiers );
2111
int special_handler( int key,int modifiers );
2113
void activate( int how );
2114
void deactivate( void );
2116
void draw( int x, int y );
2118
int mouse_over( int state, int x, int y );
2120
int get_box_width();
2121
int find_word_break( int start, int direction );
2122
int substring_width( const char *t, int start, int end );
2123
int find_line( int x, int y );
2124
void update_and_draw_text( void );
2125
void draw_text( const char *t, int selected, int x, int y );
2126
void update_size( void );
2129
int add_item( int id, const char *text );
2130
int delete_item( const char *text );
2131
int delete_item( int id );
2134
GLUI_List_Item *get_item_ptr( const char *text );
2135
GLUI_List_Item *get_item_ptr( int id );
2137
void dump( FILE *out, const char *text );
2138
void set_start_line(int l) { start_line = l; }
2139
static void scrollbar_callback(GLUI_Control*);
2140
int get_current_item() { return curr_line; }
2141
void set_click_type(int d) {
2142
cb_click_type = d; }
2143
void set_object_callback(GLUI_CB cb=GLUI_CB(), GLUI_Control*obj=NULL)
2144
{ obj_cb=cb; associated_object=obj; }
2149
h = GLUI_LIST_HEIGHT;
2150
w = GLUI_LIST_WIDTH;
2156
active_type = GLUI_CONTROL_ACTIVE_PERMANENT;
2157
can_activate = true;
2158
spacebar_mouse_click = false;
2161
draw_text_only = false;
2162
cb_click_type = GLUI_SINGLE_CLICK;
2164
last_click_time = 0;
2165
associated_object = NULL;
2167
void common_construct(
2169
GLUI_String* live_var, bool scroll,
2172
/*,GLUI_Control *object*/
2173
/*,GLUI_InterObject_CB obj_cb*/);
2176
/************************************************************/
2178
/* Scrollbar class - JVK */
2180
/************************************************************/
2182
class GLUI_Scrollbar : public GLUI_Control
2185
// Constructor, no live var
2186
GLUI_Scrollbar( GLUI_Node *parent,
2188
int horz_vert=GLUI_SCROLL_HORIZONTAL,
2189
int data_type=GLUI_SCROLL_INT,
2190
int id=-1, GLUI_CB callback=GLUI_CB()
2191
/*,GLUI_Control *object = NULL*/
2192
/*,GLUI_InterObject_CB obj_cb = NULL*/
2195
// Constructor, int live var
2196
GLUI_Scrollbar( GLUI_Node *parent, const char *name, int horz_vert,
2198
int id=-1, GLUI_CB callback=GLUI_CB()
2199
/*,GLUI_Control *object = NULL*/
2200
/*,GLUI_InterObject_CB obj_cb = NULL*/
2203
// Constructor, float live var
2204
GLUI_Scrollbar( GLUI_Node *parent, const char *name, int horz_vert,
2206
int id=-1, GLUI_CB callback=GLUI_CB()
2207
/*,GLUI_Control *object = NULL*/
2208
/*,GLUI_InterObject_CB obj_cb = NULL*/
2211
bool currently_inside;
2213
float growth, growth_exp;
2217
int last_int_val; ///< Used to prevent repeated callbacks.
2218
float last_float_val;
2221
float float_min, float_max;
2222
int int_min, int_max;
2224
double last_update_time; ///< GLUI_Time() we last advanced scrollbar.
2225
double velocity_limit; ///< Maximum distance to advance per second.
2227
int box_start_position;
2228
int box_end_position;
2232
/* Rather than directly access an Editbox or Textbox for
2233
changing variables, a pointer to some object is defined
2234
along with a static callback in the form func(void *, int) -
2235
the int is the new value, the void * must be cast to that
2236
particular object type before use.
2238
void * associated_object; /* Lets the Spinner manage it's own callbacks */
2239
GLUI_CB object_cb; /* function pointer to object call_back */
2241
int mouse_down_handler( int local_x, int local_y );
2242
int mouse_up_handler( int local_x, int local_y, bool inside );
2243
int mouse_held_down_handler( int local_x, int local_y, bool inside );
2244
int key_handler( unsigned char key,int modifiers );
2245
int special_handler( int key,int modifiers );
2247
void draw( int x, int y );
2248
void draw_pressed( void );
2249
void draw_unpressed( void );
2250
void draw_text( int sunken );
2252
void update_size( void );
2254
void set_int_limits( int low, int high,int limit_type=GLUI_LIMIT_CLAMP);
2255
void set_float_limits( float low,float high,int limit_type=GLUI_LIMIT_CLAMP);
2256
int find_arrow( int local_x, int local_y );
2257
void do_drag( int x, int y );
2258
void do_callbacks( void );
2259
void draw_scroll( void );
2260
void do_click( void );
2262
bool needs_idle( void ) const;
2263
void set_int_val( int new_val );
2264
void set_float_val( float new_val );
2265
void increase_growth( void );
2266
void reset_growth( void );
2268
void set_speed( float speed ) { user_speed = speed; };
2269
void update_scroll_parameters();
2270
void set_object_callback(GLUI_CB cb=GLUI_CB(), GLUI_Control*obj=NULL)
2271
{ object_cb=cb; associated_object=obj; }
2274
void common_init ( void );
2275
void common_construct(
2279
int data_type, void* live_var,
2280
int id, GLUI_CB callback
2281
/*,GLUI_Control *object
2282
,GLUI_InterObject_CB obj_cb*/
2285
virtual void draw_scroll_arrow(int arrowtype, int x, int y);
2286
virtual void draw_scroll_box(int x, int y, int w, int h);
2289
/************************************************************/
2293
/************************************************************/
2295
class GLUI_Listbox_Item : public GLUI_Node
2302
class GLUI_Listbox : public GLUI_Control
2305
GLUI_String curr_text;
2306
GLUI_Listbox_Item items_list;
2310
bool currently_inside;
2311
int text_x_offset, title_x_offset;
2314
int mouse_down_handler( int local_x, int local_y );
2315
int mouse_up_handler( int local_x, int local_y, bool inside );
2316
int mouse_held_down_handler( int local_x, int local_y, bool inside );
2317
int key_handler( unsigned char key,int modifiers );
2318
int special_handler( int key,int modifiers );
2320
void update_size( void );
2321
void draw( int x, int y );
2322
int mouse_over( int state, int x, int y );
2324
void set_int_val( int new_val );
2325
void dump( FILE *output );
2327
int add_item( int id, const char *text );
2328
int delete_item( const char *text );
2329
int delete_item( int id );
2330
int sort_items( void );
2332
int do_selection( int item );
2334
GLUI_Listbox_Item *get_item_ptr( const char *text );
2335
GLUI_Listbox_Item *get_item_ptr( int id );
2338
GLUI_Listbox( GLUI_Node *parent,
2339
const char *name, int *live_var=NULL,
2340
int id=-1, GLUI_CB callback=GLUI_CB() );
2341
GLUI_Listbox( void ) { common_init(); }
2344
/** Change w and return true if we need to be widened to fit the current item. */
2345
bool recalculate_item_width( void );
2346
void common_init() {
2347
glui_format_str( name, "Listbox: %p", this );
2348
w = GLUI_EDITTEXT_WIDTH;
2349
h = GLUI_EDITTEXT_HEIGHT;
2353
can_activate = true;
2355
live_type = GLUI_LIVE_INT; /* This has an integer live var */
2363
/************************************************************/
2365
/* Mouse_Interaction class */
2367
/************************************************************/
2370
This is the superclass of translation and rotation widgets.
2372
class GLUI_Mouse_Interaction : public GLUI_Control
2375
/*int get_main_area_size( void ) { return MIN( h-18, */
2376
int draw_active_area_only;
2378
int mouse_down_handler( int local_x, int local_y );
2379
int mouse_up_handler( int local_x, int local_y, bool inside );
2380
int mouse_held_down_handler( int local_x, int local_y, bool inside );
2381
int special_handler( int key, int modifiers );
2382
void update_size( void );
2383
void draw( int x, int y );
2384
void draw_active_area( void );
2386
/*** The following methods (starting with "iaction_") need to
2388
virtual int iaction_mouse_down_handler( int local_x, int local_y ) = 0;
2389
virtual int iaction_mouse_up_handler( int local_x, int local_y, bool inside )=0;
2390
virtual int iaction_mouse_held_down_handler( int local_x, int local_y, bool inside )=0;
2391
virtual int iaction_special_handler( int key, int modifiers )=0;
2392
virtual void iaction_draw_active_area_persp( void )=0;
2393
virtual void iaction_draw_active_area_ortho( void )=0;
2394
virtual void iaction_dump( FILE *output )=0;
2395
virtual void iaction_init( void ) = 0;
2397
GLUI_Mouse_Interaction( void ) {
2398
glui_format_str( name, "Mouse_Interaction: %p", this );
2399
w = GLUI_MOUSE_INTERACTION_WIDTH;
2400
h = GLUI_MOUSE_INTERACTION_HEIGHT;
2401
can_activate = true;
2402
live_type = GLUI_LIVE_NONE;
2403
alignment = GLUI_ALIGN_CENTER;
2404
draw_active_area_only = false;
2408
/************************************************************/
2410
/* Rotation class */
2412
/************************************************************/
2415
An onscreen rotation controller--allows the user to interact with
2416
a 3D rotation via a spaceball-like interface.
2418
class GLUI_Rotation : public GLUI_Mouse_Interaction
2422
GLUquadricObj *quadObj;
2423
bool can_spin, spinning;
2426
int iaction_mouse_down_handler( int local_x, int local_y );
2427
int iaction_mouse_up_handler( int local_x, int local_y, bool inside );
2428
int iaction_mouse_held_down_handler( int local_x, int local_y, bool inside );
2429
int iaction_special_handler( int key, int modifiers );
2430
void iaction_init( void ) { init_ball(); }
2431
void iaction_draw_active_area_persp( void );
2432
void iaction_draw_active_area_ortho( void );
2433
void iaction_dump( FILE *output );
2435
/* void update_size( void ); */
2436
/* void draw( int x, int y ); */
2437
/* int mouse_over( int state, int x, int y ); */
2439
void setup_texture( void );
2440
void setup_lights( void );
2441
void draw_ball( float radius );
2443
void init_ball( void );
2447
bool needs_idle( void ) const;
2450
void copy_float_array_to_ball( void );
2451
void copy_ball_to_float_array( void );
2453
void set_spin( float damp_factor );
2455
GLUI_Rotation( GLUI_Node *parent, const char *name, float *live_var=NULL,
2456
int id=-1, GLUI_CB callback=GLUI_CB() );
2457
GLUI_Rotation(void) { common_init(); }
2463
/************************************************************/
2465
/* Translation class */
2467
/************************************************************/
2470
An onscreen translation controller--allows the user to interact with
2473
class GLUI_Translation : public GLUI_Mouse_Interaction
2476
int trans_type; /* Is this an XY or a Z controller? */
2479
GLUquadricObj *quadObj;
2480
int trans_mouse_code;
2481
float orig_x, orig_y, orig_z;
2484
int iaction_mouse_down_handler( int local_x, int local_y );
2485
int iaction_mouse_up_handler( int local_x, int local_y, bool inside );
2486
int iaction_mouse_held_down_handler( int local_x, int local_y, bool inside );
2487
int iaction_special_handler( int key, int modifiers );
2488
void iaction_init( void ) { }
2489
void iaction_draw_active_area_persp( void );
2490
void iaction_draw_active_area_ortho( void );
2491
void iaction_dump( FILE *output );
2493
void set_speed( float s ) { scale_factor = s; }
2495
void setup_texture( void );
2496
void setup_lights( void );
2497
void draw_2d_arrow( int radius, int filled, int orientation );
2498
void draw_2d_x_arrows( int radius );
2499
void draw_2d_y_arrows( int radius );
2500
void draw_2d_z_arrows( int radius );
2501
void draw_2d_xy_arrows( int radius );
2503
int get_mouse_code( int x, int y );
2505
/* Float array is either a single float (for single-axis controls),
2506
or two floats for X and Y (if an XY controller) */
2508
float get_z( void ) { return float_array_val[0]; }
2509
float get_x( void ) { return float_array_val[0]; }
2510
float get_y( void ) {
2511
if ( trans_type == GLUI_TRANSLATION_XY ) return float_array_val[1];
2512
else return float_array_val[0];
2515
void set_z( float val );
2516
void set_x( float val );
2517
void set_y( float val );
2518
void set_one_val( float val, int index );
2520
GLUI_Translation( GLUI_Node *parent, const char *name,
2521
int trans_type, float *live_var=NULL,
2522
int id=-1, GLUI_CB callback=GLUI_CB() );
2523
GLUI_Translation( void ) { common_init(); }
2526
void common_init() {
2527
locked = GLUI_TRANSLATION_LOCK_NONE;
2528
glui_format_str( name, "Translation: %p", this );
2529
w = GLUI_MOUSE_INTERACTION_WIDTH;
2530
h = GLUI_MOUSE_INTERACTION_HEIGHT;
2531
can_activate = true;
2532
live_type = GLUI_LIVE_FLOAT_ARRAY;
2533
float_array_size = 0;
2534
alignment = GLUI_ALIGN_CENTER;
2535
trans_type = GLUI_TRANSLATION_XY;
2538
trans_mouse_code = GLUI_TRANSLATION_MOUSE_NONE;
2542
/********** Misc functions *********************/
2543
int _glutBitmapWidthString( void *font, const char *s );
2544
void _glutBitmapString( void *font, const char *s );
2546
/********** Our own callbacks for glut *********/
2547
/* These are the callbacks that we pass to glut. They take
2548
some action if necessary, then (possibly) call the user-level
2552
void glui_display_func( void );
2553
void glui_reshape_func( int w, int h );
2554
void glui_keyboard_func(unsigned char key, int x, int y);
2555
void glui_special_func(int key, int x, int y);
2556
void glui_mouse_func(int button, int state, int x, int y);
2557
void glui_motion_func(int x, int y);
2558
void glui_passive_motion_func(int x, int y);
2559
void glui_entry_func(int state);
2560
void glui_visibility_func(int state);
2561
void glui_idle_func(void);
2563
void glui_parent_window_reshape_func( int w, int h );
2564
void glui_parent_window_keyboard_func(unsigned char key, int x, int y);
2565
void glui_parent_window_mouse_func(int, int, int, int );
2566
void glui_parent_window_special_func(int key, int x, int y);