~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tests/box2d/glui/glui.h

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
 
 
3
  GLUI User Interface Toolkit (LGPL)
 
4
  ----------------------------------
 
5
 
 
6
     glui.h - Main (and only) external header for 
 
7
        GLUI User Interface Toolkit
 
8
 
 
9
          --------------------------------------------------
 
10
 
 
11
  Copyright (c) 1998 Paul Rademacher
 
12
 
 
13
  WWW:    http://sourceforge.net/projects/glui/
 
14
  Forums: http://sourceforge.net/forum/?group_id=92496
 
15
 
 
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.
 
20
 
 
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.
 
25
 
 
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
 
29
 
 
30
*****************************************************************************/
 
31
 
 
32
#ifndef GLUI_GLUI_H
 
33
#define GLUI_GLUI_H
 
34
 
 
35
#ifdef __APPLE__
 
36
        #include <GLUT/glut.h>
 
37
#else
 
38
        #include "freeglut/freeglut.h"
 
39
#endif
 
40
 
 
41
#include <cstdlib>
 
42
#include <cstdio>
 
43
#include <cstring>
 
44
#include <string>
 
45
#include <vector>
 
46
 
 
47
#define GLUI_VERSION 2.3f    /********** Current version **********/
 
48
 
 
49
#if defined(_WIN32)
 
50
#if !defined(GLUI_NO_LIB_PRAGMA)
 
51
//#pragma comment(lib, "glui32.lib")  // Link automatically with GLUI library
 
52
#endif
 
53
#endif
 
54
 
 
55
/********** Do some basic defines *******/
 
56
 
 
57
#ifndef Byte
 
58
#define Byte unsigned char
 
59
#endif
 
60
 
 
61
#ifndef _RGBC_
 
62
class RGBc {
 
63
public:
 
64
  Byte r, g, b;
 
65
    
 
66
  void set(Byte r,Byte g,Byte b) {this->r=r;this->g=g;this->b=b;}
 
67
    
 
68
  RGBc( void ) {}
 
69
  RGBc( Byte r, Byte g, Byte b ) { set( r, g, b ); }
 
70
};
 
71
#define _RGBC_
 
72
#endif
 
73
 
 
74
/********** List of GLUT callbacks ********/
 
75
 
 
76
enum GLUI_Glut_CB_Types 
 
77
 
78
    GLUI_GLUT_RESHAPE,
 
79
    GLUI_GLUT_KEYBOARD,
 
80
    GLUI_GLUT_DISPLAY,
 
81
    GLUI_GLUT_MOUSE,
 
82
    GLUI_GLUT_MOTION,
 
83
    GLUI_GLUT_SPECIAL,
 
84
    GLUI_GLUT_PASSIVE_MOTION,  
 
85
    GLUI_GLUT_ENTRY,
 
86
    GLUI_GLUT_VISIBILITY  
 
87
};
 
88
 
 
89
/********* Constants for window placement **********/
 
90
 
 
91
#define GLUI_XOFF                       6
 
92
#define GLUI_YOFF                       6
 
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
 
114
 
 
115
/** Different panel control types **/
 
116
#define GLUI_PANEL_NONE      0
 
117
#define GLUI_PANEL_EMBOSSED  1
 
118
#define GLUI_PANEL_RAISED    2
 
119
 
 
120
/**  Max # of els in control's float_array  **/
 
121
#define GLUI_DEF_MAX_ARRAY  30
 
122
 
 
123
/********* The control's 'active' behavior *********/
 
124
#define GLUI_CONTROL_ACTIVE_MOUSEDOWN       1
 
125
#define GLUI_CONTROL_ACTIVE_PERMANENT       2
 
126
 
 
127
/********* Control alignment types **********/
 
128
#define GLUI_ALIGN_CENTER   1
 
129
#define GLUI_ALIGN_RIGHT    2
 
130
#define GLUI_ALIGN_LEFT     3
 
131
 
 
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
 
136
 
 
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
 
142
 
 
143
#define GLUI_TRANSLATION_LOCK_NONE 0
 
144
#define GLUI_TRANSLATION_LOCK_X    1
 
145
#define GLUI_TRANSLATION_LOCK_Y    2
 
146
 
 
147
/********** How was a control activated? *****************/
 
148
#define GLUI_ACTIVATE_MOUSE 1
 
149
#define GLUI_ACTIVATE_TAB   2
 
150
 
 
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
 
159
 
 
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
 
172
 
 
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
 
183
 
 
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
 
197
 
 
198
 
 
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.
 
202
*/
 
203
#define CHAR_WIDTH_HASH_SIZE 128
 
204
 
 
205
/**********  Translation codes  **********/
 
206
 
 
207
enum TranslationCodes  
 
208
{
 
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
 
218
};
 
219
 
 
220
/************ A string type for us to use **********/
 
221
 
 
222
typedef std::string GLUI_String;
 
223
GLUI_String& glui_format_str(GLUI_String &str, const char* fmt, ...);
 
224
 
 
225
/********* Pre-declare classes as needed *********/
 
226
 
 
227
class GLUI;
 
228
class GLUI_Control;
 
229
class GLUI_Listbox;
 
230
class GLUI_StaticText;
 
231
class GLUI_EditText;
 
232
class GLUI_Panel;
 
233
class GLUI_Spinner;
 
234
class GLUI_RadioButton;
 
235
class GLUI_RadioGroup;
 
236
class GLUI_Glut_Window;
 
237
class GLUI_TreePanel;
 
238
class GLUI_Scrollbar;
 
239
class GLUI_List;
 
240
 
 
241
class Arcball;
 
242
 
 
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))
 
249
 
 
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
 
260
 
 
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);
 
268
 
 
269
/************************************************************/
 
270
/**
 
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.
 
275
*/
 
276
class GLUI_CB
 
277
{
 
278
public:
 
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)
 
283
 
 
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)); }
 
288
private:
 
289
  GLUI_Update_CB idCB;
 
290
  GLUI_Control_CB objCB;
 
291
};
 
292
 
 
293
/************************************************************/
 
294
/*                                                          */
 
295
/*          Base class, for hierarchical relationships      */
 
296
/*                                                          */
 
297
/************************************************************/
 
298
 
 
299
class GLUI_Control;
 
300
 
 
301
/**
 
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.
 
305
 
 
306
 Everything onscreen is a GLUI_Node--windows, buttons, etc.
 
307
 The nodes are traversed for event processing, sizing, redraws, etc.
 
308
*/
 
309
class GLUI_Node 
 
310
{
 
311
    friend class GLUI_Tree;     /* JVK */
 
312
    friend class GLUI_Rollout;
 
313
    friend class GLUI_Main;
 
314
 
 
315
public:
 
316
    GLUI_Node();
 
317
    virtual ~GLUI_Node() {}
 
318
 
 
319
    GLUI_Node *first_sibling();
 
320
    GLUI_Node *last_sibling();
 
321
    GLUI_Node *prev();
 
322
    GLUI_Node *next();
 
323
 
 
324
    GLUI_Node *first_child()   { return child_head; }
 
325
    GLUI_Node *last_child()    { return child_tail; }
 
326
    GLUI_Node *parent()        { return parent_node; }
 
327
 
 
328
    /** Link in a new child control */
 
329
    virtual int  add_control( GLUI_Control *control );
 
330
 
 
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 );
 
335
    void unlink();
 
336
 
 
337
    void dump( FILE *out, const char *name );
 
338
 
 
339
protected:
 
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;
 
346
};
 
347
 
 
348
 
 
349
/************************************************************/
 
350
/*                                                          */
 
351
/*                  Standard Bitmap stuff                   */
 
352
/*                                                          */
 
353
/************************************************************/
 
354
 
 
355
enum GLUI_StdBitmaps_Codes 
 
356
{
 
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
 
379
};
 
380
 
 
381
/************************************************************/
 
382
/*                                                          */
 
383
/*                  Class GLUI_Bitmap                       */
 
384
/*                                                          */
 
385
/************************************************************/
 
386
 
 
387
/**
 
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.
 
391
*/
 
392
class GLUI_Bitmap 
 
393
{
 
394
    friend class GLUI_StdBitmaps;
 
395
 
 
396
public:
 
397
    GLUI_Bitmap();
 
398
    ~GLUI_Bitmap();
 
399
 
 
400
    /** Create bitmap from greyscale byte image */
 
401
    void init_grey(unsigned char *array);
 
402
    
 
403
    /** Create bitmap from color int image */
 
404
    void init(int *array);
 
405
 
 
406
private:
 
407
    /** RGB pixel data */
 
408
    unsigned char *pixels;
 
409
    int            w, h;
 
410
};
 
411
 
 
412
 
 
413
/************************************************************/
 
414
/*                                                          */
 
415
/*                  Class GLUI_StdBitmap                    */
 
416
/*                                                          */
 
417
/************************************************************/
 
418
 
 
419
/**
 
420
 Keeps an array of GLUI_Bitmap objects to represent all the 
 
421
 images used in the UI: checkboxes, arrows, etc.
 
422
*/
 
423
class GLUI_StdBitmaps
 
424
{
 
425
public:
 
426
    GLUI_StdBitmaps(); 
 
427
    ~GLUI_StdBitmaps();
 
428
 
 
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;
 
433
 
 
434
    /** Draw the n'th standard bitmap (one of the enums
 
435
       listed in GLUI_StdBitmaps_Codes) at pixel corner (x,y). 
 
436
    */
 
437
    void draw(int n, int x, int y) const;
 
438
 
 
439
private:
 
440
    GLUI_Bitmap bitmaps[GLUI_STDBITMAP_NUM_ITEMS];
 
441
};
 
442
 
 
443
/************************************************************/
 
444
/*                                                          */
 
445
/*                     Master GLUI Class                    */
 
446
/*                                                          */
 
447
/************************************************************/
 
448
 
 
449
/**
 
450
 The master manages our interaction with GLUT.
 
451
 There's only one GLUI_Master_Object.
 
452
*/
 
453
class GLUI_Master_Object 
 
454
{
 
455
 
 
456
    friend void glui_idle_func();
 
457
  
 
458
public:
 
459
 
 
460
    GLUI_Master_Object();
 
461
    ~GLUI_Master_Object();
 
462
 
 
463
    GLUI_Node     gluis;
 
464
    GLUI_Control *active_control, *curr_left_button_glut_menu;
 
465
    GLUI         *active_control_glui;
 
466
    int           glui_id_counter;
 
467
 
 
468
    GLUI_Glut_Window   *find_glut_window( int window_id );
 
469
 
 
470
    void           set_glutIdleFunc(void (*f)(void));
 
471
 
 
472
    /**************
 
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);
 
477
 
 
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);
 
483
    **********/
 
484
 
 
485
    void  set_left_button_glut_menu_control( GLUI_Control *control );
 
486
 
 
487
    /********** GLUT callthroughs **********/
 
488
    /* These are the glut callbacks that we do not handle */
 
489
 
 
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 ));
 
494
 
 
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);}  
 
509
  
 
510
 
 
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();
 
516
    void           close_all();
 
517
    void           sync_live_all();
 
518
 
 
519
    void           reshape();
 
520
 
 
521
    float          get_version() { return GLUI_VERSION; }
 
522
 
 
523
    void glui_setIdleFuncIfNecessary(void);
 
524
 
 
525
private:
 
526
    GLUI_Node     glut_windows;
 
527
    void (*glut_idle_CB)(void);
 
528
 
 
529
    void          add_cb_to_glut_window(int window,int cb_type,void *cb);
 
530
};
 
531
 
 
532
/**
 
533
 This is the only GLUI_Master_Object in existence.
 
534
*/
 
535
extern GLUI_Master_Object GLUI_Master;
 
536
 
 
537
/************************************************************/
 
538
/*                                                          */
 
539
/*              Class for managing a GLUT window            */
 
540
/*                                                          */
 
541
/************************************************************/
 
542
 
 
543
/**
 
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).
 
547
 
 
548
 This entire approach seems to be superceded by the "subwindow" flavor
 
549
 of GLUI.
 
550
*/
 
551
class GLUI_Glut_Window : public GLUI_Node 
 
552
{
 
553
public:
 
554
    GLUI_Glut_Window();
 
555
 
 
556
    int    glut_window_id;
 
557
 
 
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);
 
568
};
 
569
 
 
570
/************************************************************/
 
571
/*                                                          */
 
572
/*       Main Window GLUI class (not user-level)            */
 
573
/*                                                          */
 
574
/************************************************************/
 
575
 
 
576
/**
 
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.
 
580
  
 
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.
 
584
 
 
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.
 
588
*/
 
589
class GLUI_Main : public GLUI_Node 
 
590
{
 
591
    /********** Friend classes *************/
 
592
 
 
593
    friend class GLUI_Control;
 
594
    friend class GLUI_Rotation;
 
595
    friend class GLUI_Translation;
 
596
    friend class GLUI;
 
597
    friend class GLUI_Master_Object;
 
598
 
 
599
    /*********** Friend functions **********/
 
600
 
 
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);
 
611
 
 
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 );
 
616
 
 
617
protected:
 
618
    /*** Variables ***/
 
619
    int           main_gfx_window_id;
 
620
    int           mouse_button_down;
 
621
    int           glut_window_id;
 
622
    int           top_level_glut_window_id;
 
623
    GLUI_Control *active_control;
 
624
    GLUI_Control *mouse_over_control;
 
625
    GLUI_Panel   *main_panel;
 
626
    enum buffer_mode_t {
 
627
      buffer_front=1, ///< Draw updated controls directly to screen.
 
628
      buffer_back=2   ///< Double buffering: postpone updates until next redraw.
 
629
    };
 
630
    buffer_mode_t buffer_mode; ///< Current drawing mode
 
631
    int           curr_cursor;
 
632
    int           w, h;
 
633
    long          flags; 
 
634
    bool          closing;
 
635
    int           parent_window;
 
636
    int           glui_id;
 
637
 
 
638
    /********** Misc functions *************/
 
639
 
 
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 );
 
648
 
 
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 );
 
658
    void           idle(void);
 
659
    int            needs_idle(void);
 
660
 
 
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);
 
665
 
 
666
 
 
667
    /*********** Controls ************/
 
668
 
 
669
    virtual int    add_control( GLUI_Node *parent, GLUI_Control *control );
 
670
 
 
671
 
 
672
    /********** Constructors and Destructors ***********/
 
673
 
 
674
    GLUI_Main( void );
 
675
 
 
676
public:
 
677
    GLUI_StdBitmaps  std_bitmaps;
 
678
    GLUI_String      window_name;
 
679
    RGBc             bkgd_color;
 
680
    float            bkgd_color_f[3];
 
681
 
 
682
    void            *font;
 
683
    int              curr_modifiers;
 
684
 
 
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 );
 
689
    
 
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 );
 
694
    
 
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).
 
697
    */
 
698
    bool         should_redraw_now(GLUI_Control *ctl);
 
699
    
 
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
 
703
    */
 
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 );
 
707
    
 
708
    /** Pack, resize the window, and redraw all the controls. */
 
709
    void         refresh();
 
710
    
 
711
    /** Redraw the main graphics window */
 
712
    void         post_update_main_gfx();
 
713
  
 
714
    /** Recompute the sizes and positions of all controls */
 
715
    void         pack_controls();
 
716
    
 
717
    void         close_internal();
 
718
    void         check_subwindow_position();
 
719
    void         set_ortho_projection();
 
720
    void         set_viewport();
 
721
    int          get_glut_window_id( void ) { return glut_window_id; } /* JVK */
 
722
};
 
723
 
 
724
/************************************************************/
 
725
/*                                                          */
 
726
/*       GLUI_Control: base class for all controls          */
 
727
/*                                                          */
 
728
/************************************************************/
 
729
 
 
730
/**
 
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.
 
735
 
 
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.
 
740
*/
 
741
class GLUI_Control : public GLUI_Node 
 
742
{
 
743
public:
 
744
 
 
745
/** Onscreen coordinates */
 
746
    int             w, h;                        /* dimensions of control */
 
747
    int             x_abs, y_abs;
 
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 */
 
755
 
 
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.
 
761
    
 
762
/** Callbacks */
 
763
    long            user_id;  ///< Integer to pass to callback function.
 
764
    GLUI_CB         callback; ///< User callback function, or NULL.
 
765
 
 
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 */
 
772
    
 
773
/** "Live variable" updating */
 
774
    void           *ptr_val;          /**< A pointer to the user's live variable value */
 
775
    int             live_type;
 
776
    bool            live_inited;
 
777
    /* These variables store the last value that live variable was known to have. */
 
778
    int             last_live_int;  
 
779
    float           last_live_float;
 
780
    GLUI_String     last_live_text;
 
781
    float           last_live_float_array[GLUI_DEF_MAX_ARRAY];
 
782
    
 
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) */
 
786
    int             alignment;
 
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 */
 
794
 
 
795
public:
 
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 );
 
802
 
 
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; }
 
808
 
 
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; }
 
814
 
 
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; }
 
818
 
 
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; }
 
823
 
 
824
    /** Hide (shrink into a rollout) and unhide (expose from a rollout) */
 
825
    void         hide_internal( int recurse );
 
826
    void         unhide_internal( int recurse );
 
827
 
 
828
    /** Return true if it currently makes sense to draw this class. */
 
829
    int          can_draw( void ) { return (glui != NULL && hidden == false); }
 
830
 
 
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.
 
836
    */
 
837
    void          redraw(void);
 
838
    
 
839
    /** Redraw everybody in our window. */
 
840
    void         redraw_window(void);
 
841
 
 
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 );
 
858
 
 
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 );
 
872
 
 
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; }
 
886
 
 
887
    GLUI_Control(void) 
 
888
    {
 
889
        x_off          = GLUI_XOFF;
 
890
        y_off_top      = GLUI_YOFF;
 
891
        y_off_bot      = GLUI_YOFF;
 
892
        x_abs          = GLUI_XOFF;
 
893
        y_abs          = GLUI_YOFF;
 
894
        active         = false;
 
895
        enabled        = true;
 
896
        int_val        = 0;
 
897
        last_live_int  = 0;
 
898
        float_array_size = 0;
 
899
        glui_format_str(name, "Control: %p", this);
 
900
        float_val      = 0.0;
 
901
        last_live_float = 0.0;
 
902
        ptr_val        = NULL;
 
903
        glui           = NULL;
 
904
        w              = GLUI_DEFAULT_CONTROL_WIDTH;
 
905
        h              = GLUI_DEFAULT_CONTROL_HEIGHT;
 
906
        font           = NULL;
 
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;
 
913
        text = "";
 
914
        last_live_text == "";
 
915
        live_inited    = false;
 
916
        collapsible    = false;
 
917
        is_open        = true;
 
918
        hidden         = false;
 
919
        memset(char_widths, -1, sizeof(char_widths)); /* JVK */
 
920
        int i;
 
921
        for( i=0; i<GLUI_DEF_MAX_ARRAY; i++ )
 
922
            float_array_val[i] = last_live_float_array[i] = 0.0;
 
923
    }
 
924
 
 
925
    virtual ~GLUI_Control();
 
926
};
 
927
 
 
928
/************************************************************/
 
929
/*                                                          */
 
930
/*               Button class (container)                   */
 
931
/*                                                          */
 
932
/************************************************************/
 
933
/**
 
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.
 
937
*/
 
938
class GLUI_Button : public GLUI_Control
 
939
{
 
940
public:
 
941
    bool currently_inside;
 
942
 
 
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 );
 
947
 
 
948
    void draw( int x, int y );
 
949
    void draw_pressed( void );
 
950
    void draw_text( int sunken );
 
951
 
 
952
    void update_size( void );
 
953
 
 
954
/**
 
955
 Create a new button.
 
956
 
 
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.
 
961
*/
 
962
    GLUI_Button( GLUI_Node *parent, const char *name, 
 
963
                 int id=-1, GLUI_CB cb=GLUI_CB() );
 
964
    GLUI_Button( void ) { common_init(); };
 
965
 
 
966
protected:
 
967
    void common_init(void) {
 
968
        glui_format_str(name, "Button: %p", this );
 
969
        h            = GLUI_BUTTON_SIZE;
 
970
        w            = 100;
 
971
        alignment    = GLUI_ALIGN_CENTER;
 
972
        can_activate = true;
 
973
    }
 
974
};
 
975
 
 
976
 
 
977
/************************************************************/
 
978
/*                                                          */
 
979
/*               Checkbox class (container)                 */
 
980
/*                                                          */
 
981
/************************************************************/
 
982
 
 
983
/**
 
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.
 
986
*/
 
987
class GLUI_Checkbox : public GLUI_Control
 
988
{
 
989
public:
 
990
    int  orig_value;
 
991
    bool currently_inside;
 
992
    int  text_x_offset;
 
993
 
 
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 );
 
998
 
 
999
    void update_size( void );
 
1000
 
 
1001
    void draw( int x, int y );
 
1002
 
 
1003
    void draw_active_area( void );
 
1004
    void draw_empty_box( void );
 
1005
    void set_int_val( int new_val );
 
1006
 
 
1007
/**
 
1008
 Create a new checkbox object.
 
1009
 
 
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.
 
1016
*/
 
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(); }
 
1020
 
 
1021
protected:
 
1022
    void common_init(void) {
 
1023
        glui_format_str( name, "Checkbox: %p", this );
 
1024
        w              = 100;
 
1025
        h              = GLUI_CHECKBOX_SIZE;
 
1026
        orig_value     = -1;
 
1027
        text_x_offset  = 18;
 
1028
        can_activate   = true;
 
1029
        live_type      = GLUI_LIVE_INT;   /* This control has an 'int' live var */
 
1030
    }
 
1031
};
 
1032
 
 
1033
/************************************************************/
 
1034
/*                                                          */
 
1035
/*               Column class                               */
 
1036
/*                                                          */
 
1037
/************************************************************/
 
1038
 
 
1039
/**
 
1040
 A GLUI_Column object separates all previous controls
 
1041
 from subsequent controls with a vertical bar.
 
1042
*/
 
1043
class GLUI_Column : public GLUI_Control
 
1044
{
 
1045
public:
 
1046
    void draw( int x, int y );
 
1047
 
 
1048
/**
 
1049
 Create a new column, which separates the previous controls
 
1050
 from subsequent controls.
 
1051
 
 
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.
 
1054
*/
 
1055
    GLUI_Column( GLUI_Node *parent, int draw_bar = true );
 
1056
    GLUI_Column( void ) { common_init(); }
 
1057
 
 
1058
protected:
 
1059
    void common_init() {
 
1060
        w            = 0;
 
1061
        h            = 0;
 
1062
        int_val      = 0;
 
1063
        can_activate = false;
 
1064
    }
 
1065
};
 
1066
 
 
1067
 
 
1068
/************************************************************/
 
1069
/*                                                          */
 
1070
/*               Panel class (container)                    */
 
1071
/*                                                          */
 
1072
/************************************************************/
 
1073
 
 
1074
/**
 
1075
 A GLUI_Panel contains a group of related controls.
 
1076
*/
 
1077
class GLUI_Panel : public GLUI_Control
 
1078
{
 
1079
public:
 
1080
 
 
1081
/**
 
1082
 Create a new panel.  A panel groups together a set of related controls.
 
1083
 
 
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.
 
1089
*/
 
1090
    GLUI_Panel( GLUI_Node *parent, const char *name, 
 
1091
                int type=GLUI_PANEL_EMBOSSED );
 
1092
    GLUI_Panel() { common_init(); }
 
1093
 
 
1094
    void draw( int x, int y );
 
1095
    void set_name( const char *text );
 
1096
    void set_type( int new_type );
 
1097
 
 
1098
    void update_size( void );
 
1099
 
 
1100
protected:
 
1101
    void common_init( void ) {
 
1102
        w            = 300;
 
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;
 
1108
        name="";
 
1109
    };
 
1110
};
 
1111
 
 
1112
/************************************************************/
 
1113
/*                                                          */
 
1114
/*               File Browser class (container)             */
 
1115
/*                         JVK                              */
 
1116
/************************************************************/
 
1117
 
 
1118
/**
 
1119
 A list of files the user can select from.
 
1120
*/
 
1121
class GLUI_FileBrowser : public GLUI_Panel
 
1122
{
 
1123
public:
 
1124
/**
 
1125
 Create a new list of files the user can select from.
 
1126
 
 
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.
 
1134
*/
 
1135
    GLUI_FileBrowser( GLUI_Node *parent, 
 
1136
                      const char *name,
 
1137
                      int frame_type = GLUI_PANEL_EMBOSSED,
 
1138
                      int user_id = -1,
 
1139
                      GLUI_CB callback = GLUI_CB());
 
1140
 
 
1141
    GLUI_List *list;
 
1142
    GLUI_String current_dir;
 
1143
 
 
1144
    void fbreaddir(const char *);
 
1145
    static void dir_list_callback(GLUI_Control*);
 
1146
 
 
1147
    void set_w(int w);
 
1148
    void set_h(int h);
 
1149
    const char* get_file() { return file.c_str(); }
 
1150
    void set_allow_change_dir(int c) { allow_change_dir = c; }
 
1151
 
 
1152
protected:
 
1153
    void common_init() 
 
1154
    {
 
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;
 
1162
        last_item    = -1;
 
1163
        user_id      = -1;
 
1164
        name         = "";
 
1165
        current_dir  = ".";
 
1166
        file         = "";
 
1167
    };
 
1168
 
 
1169
private:
 
1170
    int last_item;
 
1171
    GLUI_String file;
 
1172
    int allow_change_dir;
 
1173
 
 
1174
};
 
1175
 
 
1176
/************************************************************/
 
1177
/*                                                          */
 
1178
/*               Rollout class (container)                  */
 
1179
/*                                                          */
 
1180
/************************************************************/
 
1181
/**
 
1182
 A rollout contains a set of controls,
 
1183
 like a panel, but can be collapsed to just the name.
 
1184
*/
 
1185
class GLUI_Rollout : public GLUI_Panel
 
1186
{
 
1187
public:
 
1188
 
 
1189
/**
 
1190
 Create a new rollout.  A rollout contains a set of controls,
 
1191
 like a panel, but can be collapsed to just the name.
 
1192
 
 
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.
 
1200
*/
 
1201
    GLUI_Rollout( GLUI_Node *parent, const char *name, int open=true, 
 
1202
                  int type=GLUI_PANEL_EMBOSSED );
 
1203
    GLUI_Rollout( void ) { common_init(); }
 
1204
    
 
1205
    
 
1206
    bool        currently_inside, initially_inside;
 
1207
    GLUI_Button  button;
 
1208
 
 
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 );
 
1214
        
 
1215
    void  open( void ); 
 
1216
    void  close( void );
 
1217
 
 
1218
    void update_size( void );
 
1219
 
 
1220
protected:
 
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;
 
1228
        y_off_top        = 21;
 
1229
        collapsible      = true;
 
1230
        name = "";
 
1231
    }
 
1232
};
 
1233
 
 
1234
/************************************************************/
 
1235
/*                                                          */
 
1236
/*               Tree    Panel class (container)            */
 
1237
/*                         JVK                              */
 
1238
/************************************************************/
 
1239
 
 
1240
/**
 
1241
  One collapsible entry in a GLUI_TreePanel.
 
1242
*/
 
1243
class GLUI_Tree : public GLUI_Panel
 
1244
{
 
1245
public:
 
1246
    GLUI_Tree(GLUI_Node *parent, const char *name, 
 
1247
              int open=false, int inset=0);
 
1248
 
 
1249
private:
 
1250
    int level;   // how deep is this node
 
1251
    float red;   //Color coding of column line
 
1252
    float green;
 
1253
    float blue;
 
1254
    float lred;   //Color coding of level name
 
1255
    float lgreen;
 
1256
    float lblue;
 
1257
    int id;
 
1258
    GLUI_Column *column;
 
1259
    int is_current;          // Whether this tree is the
 
1260
    // current root in a treePanel
 
1261
    int child_number;
 
1262
    int format;
 
1263
 
 
1264
public:
 
1265
    bool        currently_inside, initially_inside;
 
1266
    GLUI_Button  button;
 
1267
    GLUI_String  level_name; // level name, eg: 1.1.2, III, or 3
 
1268
    GLUI_TreePanel *panel; 
 
1269
 
 
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; }
 
1276
    void  open( void ); 
 
1277
    void  close( void );
 
1278
 
 
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) { 
 
1292
        lred = r;
 
1293
        lgreen = g;
 
1294
        lblue  = b;
 
1295
    }
 
1296
    void set_color(float r, float g, float b) { 
 
1297
        red = r;
 
1298
        green = g;
 
1299
        blue  = b;
 
1300
    }
 
1301
protected:
 
1302
    void common_init()
 
1303
    {
 
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;
 
1310
        y_off_top        = 21;
 
1311
        collapsible      = true;
 
1312
        red              = .5;
 
1313
        green            = .5;
 
1314
        blue             = .5;
 
1315
        lred             = 0;
 
1316
        lgreen           = 0;
 
1317
        lblue            = 0;
 
1318
        column           = NULL;
 
1319
        is_current       = 0;
 
1320
        child_number     = 0;
 
1321
        format           = 0;
 
1322
        panel            = NULL;
 
1323
        name             = "";
 
1324
        level_name       = "";
 
1325
        level            = 0;
 
1326
    
 
1327
    };
 
1328
};
 
1329
 
 
1330
 
 
1331
/************************************************************/
 
1332
/*                                                          */
 
1333
/*               TreePanel class (container) JVK            */
 
1334
/*                                                          */
 
1335
/************************************************************/
 
1336
 
 
1337
/**
 
1338
  Manages, maintains, and formats a tree of GLUI_Tree objects.
 
1339
  These are shown in a heirarchical, collapsible display.
 
1340
  
 
1341
  FIXME: There's an infinite loop in the traversal code (OSL 2006/06)
 
1342
*/
 
1343
class GLUI_TreePanel : public GLUI_Panel 
 
1344
{
 
1345
public:
 
1346
    GLUI_TreePanel(GLUI_Node *parent, const char *name,
 
1347
                   bool open=false, int inset=0);
 
1348
 
 
1349
    int max_levels;
 
1350
    int next_id;
 
1351
    int format;
 
1352
    float red;
 
1353
    float green;
 
1354
    float blue;
 
1355
    float lred;
 
1356
    float lgreen;
 
1357
    float lblue;
 
1358
    int root_children;
 
1359
    /* These variables allow the tree panel to traverse the tree
 
1360
       using only two function calls. (Well, four, if you count 
 
1361
       going in reverse */
 
1362
 
 
1363
    GLUI_Tree    *curr_branch; /* Current Branch */
 
1364
    GLUI_Panel *curr_root;   /* Current Root */
 
1365
 
 
1366
public:
 
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; }
 
1370
 
 
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);
 
1381
    void            next( void );
 
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);
 
1388
 
 
1389
protected:
 
1390
    int uniqueID( void ) { next_id++; return next_id - 1; }
 
1391
    void common_init() 
 
1392
    {
 
1393
        GLUI_Panel();
 
1394
        next_id = 0;
 
1395
        curr_root = this;
 
1396
        curr_branch = NULL;
 
1397
        red = .5;
 
1398
        green = .5;
 
1399
        blue = .5;
 
1400
        root_children = 0;
 
1401
    }
 
1402
};
 
1403
 
 
1404
/************************************************************/
 
1405
/*                                                          */
 
1406
/*                     User-Level GLUI class                */
 
1407
/*                                                          */
 
1408
/************************************************************/
 
1409
 
 
1410
class GLUI_Rotation;
 
1411
class GLUI_Translation;
 
1412
 
 
1413
/**
 
1414
 The main user-visible interface object to GLUI.
 
1415
 
 
1416
*/
 
1417
class GLUI : public GLUI_Main 
 
1418
{
 
1419
public:
 
1420
/** DEPRECATED interface for creating new GLUI objects */
 
1421
    int   add_control( GLUI_Control *control ) { return main_panel->add_control(control); }
 
1422
 
 
1423
    void  add_column( int draw_bar = true );
 
1424
    void  add_column_to_panel( GLUI_Panel *panel, int draw_bar = true );
 
1425
 
 
1426
    void  add_separator( void );
 
1427
    void  add_separator_to_panel( GLUI_Panel *panel );
 
1428
 
 
1429
    GLUI_RadioGroup 
 
1430
    *add_radiogroup( int *live_var=NULL,
 
1431
                     int user_id=-1,GLUI_CB callback=GLUI_CB());
 
1432
 
 
1433
    GLUI_RadioGroup 
 
1434
    *add_radiogroup_to_panel(  GLUI_Panel *panel,
 
1435
                               int *live_var=NULL,
 
1436
                               int user_id=-1, GLUI_CB callback=GLUI_CB() );
 
1437
    GLUI_RadioButton
 
1438
    *add_radiobutton_to_group(  GLUI_RadioGroup *group,
 
1439
                                const char *name );
 
1440
 
 
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());
 
1446
 
 
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());
 
1452
  
 
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());
 
1460
  
 
1461
    GLUI_Checkbox  *add_checkbox( const char *name, 
 
1462
                                  int *live_var=NULL,
 
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());
 
1467
 
 
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() );
 
1472
 
 
1473
    GLUI_StaticText  *add_statictext( const char *name );
 
1474
    GLUI_StaticText  *add_statictext_to_panel( GLUI_Panel *panel, const char *name );
 
1475
 
 
1476
    GLUI_EditText  *add_edittext( const char *name, 
 
1477
                                  int data_type=GLUI_EDITTEXT_TEXT,
 
1478
                                  void*live_var=NULL,
 
1479
                                  int id=-1, GLUI_CB callback=GLUI_CB() );
 
1480
    GLUI_EditText  *add_edittext_to_panel( GLUI_Panel *panel, 
 
1481
                                           const char *name,
 
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() );
 
1490
 
 
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, 
 
1496
                                         const char *name,
 
1497
                                         int data_type=GLUI_SPINNER_INT,
 
1498
                                         void *live_var=NULL,
 
1499
                                         int id=-1,
 
1500
                                         GLUI_CB callback=GLUI_CB() );
 
1501
 
 
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 );
 
1505
 
 
1506
 
 
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, 
 
1510
                                          int open=true,
 
1511
                                          int type=GLUI_PANEL_EMBOSSED);
 
1512
 
 
1513
 
 
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; }
 
1517
 
 
1518
    void            enable( void ) { main_panel->enable(); }
 
1519
    void            disable( void );
 
1520
 
 
1521
    void            sync_live( void );
 
1522
 
 
1523
    void            close( void );
 
1524
 
 
1525
    void            show( void );
 
1526
    void            hide( void );
 
1527
 
 
1528
    /***** GLUT callback setup functions *****/
 
1529
    /*
 
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);
 
1544
    */
 
1545
 
 
1546
    /***** Constructors and desctructors *****/
 
1547
 
 
1548
    int init( const char *name, long flags, int x, int y, int parent_window );
 
1549
protected:
 
1550
    virtual int add_control( GLUI_Node *parent, GLUI_Control *control ) {
 
1551
        return GLUI_Main::add_control( parent, control );
 
1552
    }
 
1553
};
 
1554
 
 
1555
/************************************************************/
 
1556
/*                                                          */
 
1557
/*               EditText class                             */
 
1558
/*                                                          */
 
1559
/************************************************************/
 
1560
 
 
1561
class GLUI_EditText : public GLUI_Control
 
1562
{
 
1563
public:
 
1564
    int                 has_limits;
 
1565
    int                 data_type;
 
1566
    GLUI_String         orig_text;
 
1567
    int                 insertion_pt;
 
1568
    int                 title_x_offset;
 
1569
    int                 text_x_offset;
 
1570
    int                 substring_start; /*substring that gets displayed in box*/
 
1571
    int                 substring_end;  
 
1572
    int                 sel_start, sel_end;  /* current selection */
 
1573
    int                 num_periods;
 
1574
    int                 last_insertion_pt;
 
1575
    float               float_low, float_high;
 
1576
    int                 int_low, int_high;
 
1577
    GLUI_Spinner       *spinner;
 
1578
    int                 debug;
 
1579
    int                 draw_text_only;
 
1580
 
 
1581
 
 
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 );
 
1587
 
 
1588
    void activate( int how );
 
1589
    void deactivate( void );
 
1590
 
 
1591
    void draw( int x, int y );
 
1592
 
 
1593
    int  mouse_over( int state, int x, int y );
 
1594
 
 
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 );
 
1606
 
 
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(); }
 
1614
 
 
1615
    void dump( FILE *out, const char *text );
 
1616
 
 
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,
 
1623
                   int *live_var,
 
1624
                   int id=-1, GLUI_CB callback=GLUI_CB() );
 
1625
    // Constructor, float live variable
 
1626
    GLUI_EditText( GLUI_Node *parent, const char *name,
 
1627
                   float *live_var,
 
1628
                   int id=-1, GLUI_CB callback=GLUI_CB() );
 
1629
    // Constructor, char* live variable
 
1630
    GLUI_EditText( GLUI_Node *parent, const char *name, 
 
1631
                   char *live_var,
 
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() );
 
1637
 
 
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(); }
 
1644
 
 
1645
protected:
 
1646
    void common_init( void ) {
 
1647
        h                     = GLUI_EDITTEXT_HEIGHT;
 
1648
        w                     = GLUI_EDITTEXT_WIDTH;
 
1649
        title_x_offset        = 0;
 
1650
        text_x_offset         = 55;
 
1651
        insertion_pt          = -1;
 
1652
        last_insertion_pt     = -1;
 
1653
        name                  = "";
 
1654
        substring_start       = 0;
 
1655
        data_type             = GLUI_EDITTEXT_TEXT;
 
1656
        substring_end         = 2;
 
1657
        num_periods           = 0;
 
1658
        has_limits            = GLUI_LIMIT_NONE;
 
1659
        sel_start             = 0;
 
1660
        sel_end               = 0;
 
1661
        active_type           = GLUI_CONTROL_ACTIVE_PERMANENT;
 
1662
        can_activate          = true;
 
1663
        spacebar_mouse_click  = false;
 
1664
        spinner               = NULL;
 
1665
        debug                 = false;
 
1666
        draw_text_only        = false;
 
1667
    }
 
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 );
 
1671
};
 
1672
 
 
1673
/************************************************************/
 
1674
/*                                                          */
 
1675
/*               CommandLine class                          */
 
1676
/*                                                          */
 
1677
/************************************************************/
 
1678
 
 
1679
class GLUI_CommandLine : public GLUI_EditText
 
1680
{
 
1681
public:
 
1682
    typedef GLUI_EditText Super;
 
1683
 
 
1684
    enum { HIST_SIZE = 100 };
 
1685
    std::vector<GLUI_String> hist_list;
 
1686
    int  curr_hist;
 
1687
    int  oldest_hist;
 
1688
    int  newest_hist;
 
1689
    bool commit_flag;
 
1690
 
 
1691
public:
 
1692
    int  key_handler( unsigned char key,int modifiers );
 
1693
    int  special_handler(       int key,int modifiers );
 
1694
    void deactivate( void );
 
1695
 
 
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 );
 
1706
 
 
1707
    void dump( FILE *out, const char *text );
 
1708
 
 
1709
 
 
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(); }
 
1713
protected:
 
1714
    void common_init() {
 
1715
        hist_list.resize(HIST_SIZE);
 
1716
        curr_hist = 0;
 
1717
        oldest_hist = 0;
 
1718
        newest_hist = 0;
 
1719
        commit_flag = false;
 
1720
    }
 
1721
};
 
1722
 
 
1723
/************************************************************/
 
1724
/*                                                          */
 
1725
/*              RadioGroup class (container)                */
 
1726
/*                                                          */
 
1727
/************************************************************/
 
1728
 
 
1729
class GLUI_RadioGroup : public GLUI_Control
 
1730
{
 
1731
public:
 
1732
    int  num_buttons;
 
1733
 
 
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 );
 
1738
 
 
1739
    void draw_group( int translate );
 
1740
 
 
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(); }
 
1744
 
 
1745
protected:
 
1746
    void common_init( void ) {
 
1747
        x_off         = 0;
 
1748
        y_off_top     = 0;
 
1749
        y_off_bot     = 0;
 
1750
        is_container  = true;
 
1751
        w             = 300;
 
1752
        h             = 300;
 
1753
        num_buttons   = 0;
 
1754
        name          = "";
 
1755
        can_activate  = false;
 
1756
        live_type     = GLUI_LIVE_INT;
 
1757
    }
 
1758
};
 
1759
 
 
1760
/************************************************************/
 
1761
/*                                                          */
 
1762
/*               RadioButton class (container)              */
 
1763
/*                                                          */
 
1764
/************************************************************/
 
1765
 
 
1766
class GLUI_RadioButton : public GLUI_Control
 
1767
{
 
1768
public:
 
1769
    int orig_value;
 
1770
    bool currently_inside;
 
1771
    int text_x_offset;
 
1772
 
 
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 );
 
1776
 
 
1777
    void draw( int x, int y );
 
1778
    void update_size( void );
 
1779
 
 
1780
    void draw_active_area( void );
 
1781
    void draw_checked( void );
 
1782
    void draw_unchecked( void );
 
1783
    void draw_O( void );
 
1784
 
 
1785
    GLUI_RadioButton( GLUI_RadioGroup *group, const char *name );
 
1786
    GLUI_RadioGroup *group;
 
1787
 
 
1788
protected:
 
1789
    void common_init()
 
1790
    {
 
1791
        glui_format_str( name, "RadioButton: %p", (void *) this );
 
1792
        h              = GLUI_RADIOBUTTON_SIZE;
 
1793
        group          = NULL;
 
1794
        orig_value     = -1;
 
1795
        text_x_offset  = 18;
 
1796
        can_activate   = true;
 
1797
    }
 
1798
};
 
1799
 
 
1800
 
 
1801
/************************************************************/
 
1802
/*                                                          */
 
1803
/*               Separator class (container)                */
 
1804
/*                                                          */
 
1805
/************************************************************/
 
1806
 
 
1807
class GLUI_Separator : public GLUI_Control
 
1808
{
 
1809
public:
 
1810
    void draw( int x, int y );
 
1811
 
 
1812
    GLUI_Separator( GLUI_Node *parent );
 
1813
    GLUI_Separator( void ) { common_init(); }
 
1814
 
 
1815
protected:
 
1816
    void common_init() {
 
1817
        w            = 100;
 
1818
        h            = GLUI_SEPARATOR_HEIGHT;
 
1819
        can_activate = false;
 
1820
    }
 
1821
};
 
1822
 
 
1823
#define  GLUI_SPINNER_ARROW_WIDTH   12
 
1824
#define  GLUI_SPINNER_ARROW_HEIGHT   8
 
1825
#define  GLUI_SPINNER_ARROW_Y        2
 
1826
 
 
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
 
1831
 
 
1832
#define  GLUI_SPINNER_DEFAULT_GROWTH_EXP   1.05f
 
1833
 
 
1834
/************************************************************/
 
1835
/*                                                          */
 
1836
/*               Spinner class (container)                  */
 
1837
/*                                                          */
 
1838
/************************************************************/
 
1839
 
 
1840
class GLUI_Spinner : public GLUI_Control
 
1841
{
 
1842
public:
 
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, 
 
1854
                  int data_type,
 
1855
                  void *live_var,
 
1856
                  int id=-1, GLUI_CB callback=GLUI_CB() );
 
1857
    // Deprecated constructor
 
1858
    GLUI_Spinner( void ) { common_init(); }
 
1859
 
 
1860
    bool          currently_inside;
 
1861
    int           state;
 
1862
    float         growth, growth_exp;
 
1863
    int           last_x, last_y;
 
1864
    int           data_type;
 
1865
    int           callback_count;
 
1866
    int           last_int_val;
 
1867
    float         last_float_val;
 
1868
    int           first_callback;
 
1869
    float         user_speed;
 
1870
 
 
1871
    GLUI_EditText *edittext;
 
1872
 
 
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 );
 
1878
 
 
1879
    void draw( int x, int y );
 
1880
    void draw_pressed( void );
 
1881
    void draw_unpressed( void );
 
1882
    void draw_text( int sunken );
 
1883
 
 
1884
    void update_size( void );
 
1885
 
 
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 );
 
1892
    void idle( void );
 
1893
    bool needs_idle( void ) const;
 
1894
 
 
1895
    const char *get_text( void );
 
1896
 
 
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 );
 
1903
 
 
1904
    void set_speed( float speed ) { user_speed = speed; }
 
1905
 
 
1906
protected:
 
1907
    void common_init() {
 
1908
        glui_format_str( name, "Spinner: %p", this );
 
1909
        h            = GLUI_EDITTEXT_HEIGHT;
 
1910
        w            = GLUI_EDITTEXT_WIDTH;
 
1911
        x_off        = 0;
 
1912
        y_off_top    = 0;
 
1913
        y_off_bot    = 0;
 
1914
        can_activate = true;
 
1915
        state        = GLUI_SPINNER_STATE_NONE;
 
1916
        edittext     = NULL;
 
1917
        growth_exp   = GLUI_SPINNER_DEFAULT_GROWTH_EXP;
 
1918
        callback_count = 0;
 
1919
        first_callback = true;
 
1920
        user_speed   = 1.0;
 
1921
    }
 
1922
    void common_construct( GLUI_Node* parent, const char *name, 
 
1923
                           int data_type, void *live_var,
 
1924
                           int id, GLUI_CB callback );
 
1925
};
 
1926
 
 
1927
/************************************************************/
 
1928
/*                                                          */
 
1929
/*               StaticText class                           */
 
1930
/*                                                          */
 
1931
/************************************************************/
 
1932
 
 
1933
class GLUI_StaticText : public GLUI_Control
 
1934
{
 
1935
public:
 
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 );
 
1941
 
 
1942
    GLUI_StaticText(GLUI_Node *parent, const char *name);
 
1943
    GLUI_StaticText( void ) { common_init(); }
 
1944
 
 
1945
protected:
 
1946
    void common_init() {
 
1947
        h       = GLUI_STATICTEXT_SIZE;
 
1948
        name    = "";
 
1949
        can_activate  = false;
 
1950
    }
 
1951
};
 
1952
 
 
1953
/************************************************************/
 
1954
/*                                                          */
 
1955
/*               TextBox class - JVK                        */
 
1956
/*                                                          */
 
1957
/************************************************************/
 
1958
 
 
1959
class GLUI_TextBox : public GLUI_Control
 
1960
{
 
1961
public:
 
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() );
 
1968
 
 
1969
    GLUI_String         orig_text;
 
1970
    int                 insertion_pt;
 
1971
    int                 substring_start; /*substring that gets displayed in box*/
 
1972
    int                 substring_end;  
 
1973
    int                 sel_start, sel_end;  /* current selection */
 
1974
    int                 last_insertion_pt;
 
1975
    int                 debug;
 
1976
    int                 draw_text_only;
 
1977
    int                 tab_width;
 
1978
    int                 start_line;
 
1979
    int                 num_lines;
 
1980
    int                 curr_line;
 
1981
    int                 visible_lines;
 
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;
 
1986
 
 
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 );
 
1992
  
 
1993
    void activate( int how );
 
1994
    void deactivate( void );
 
1995
 
 
1996
    void enable( void );
 
1997
    void disable( void );
 
1998
 
 
1999
    void draw( int x, int y );
 
2000
 
 
2001
    int  mouse_over( int state, int x, int y );
 
2002
 
 
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 );
 
2014
 
 
2015
    void set_text( const char *text );
 
2016
    const char *get_text( void )         { return text.c_str(); }
 
2017
 
 
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*);
 
2022
 
 
2023
    bool wants_tabs( void ) const { return true; }
 
2024
 
 
2025
protected:
 
2026
    void common_init()
 
2027
    {
 
2028
        h                     = GLUI_TEXTBOX_HEIGHT;
 
2029
        w                     = GLUI_TEXTBOX_WIDTH;
 
2030
        tab_width             = GLUI_TAB_WIDTH;
 
2031
        num_lines             = 0;
 
2032
        visible_lines         = 0;
 
2033
        start_line            = 0;
 
2034
        curr_line             = 0;
 
2035
        insert_y              = -1;
 
2036
        insert_x              = -1;
 
2037
        insertion_pt          = -1;
 
2038
        last_insertion_pt     = -1;
 
2039
        name[0]               = '\0';
 
2040
        substring_start       = 0;
 
2041
        substring_end         = 2;
 
2042
        sel_start             = 0;
 
2043
        sel_end               = 0;
 
2044
        active_type           = GLUI_CONTROL_ACTIVE_PERMANENT;
 
2045
        can_activate          = true;
 
2046
        spacebar_mouse_click  = false;
 
2047
        scrollbar             = NULL;
 
2048
        debug                 = false;
 
2049
        draw_text_only        = false;
 
2050
    }
 
2051
    void common_construct(
 
2052
        GLUI_Node *parent, GLUI_String *live_var, 
 
2053
        bool scroll, int id, GLUI_CB callback); 
 
2054
};
 
2055
 
 
2056
/************************************************************/
 
2057
/*                                                          */
 
2058
/*                   List class - JVK                       */
 
2059
/*                                                          */
 
2060
/************************************************************/
 
2061
 
 
2062
class GLUI_List_Item : public GLUI_Node 
 
2063
{
 
2064
public:
 
2065
    GLUI_String text;
 
2066
    int         id;
 
2067
};
 
2068
 
 
2069
/************************************************************/
 
2070
/*                                                          */
 
2071
/*               List class - JVK                           */
 
2072
/*                                                          */
 
2073
/************************************************************/
 
2074
 
 
2075
class GLUI_List : public GLUI_Control
 
2076
{
 
2077
public:
 
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);*/
 
2083
 
 
2084
    GLUI_List( GLUI_Node *parent,
 
2085
               GLUI_String& live_var, bool scroll = false, 
 
2086
               int id=-1, 
 
2087
               GLUI_CB callback=GLUI_CB()
 
2088
               /*,GLUI_Control *object = NULL */
 
2089
               /*,GLUI_InterObject_CB obj_cb = NULL*/);
 
2090
 
 
2091
 
 
2092
    GLUI_String         orig_text;
 
2093
    int                 debug;
 
2094
    int                 draw_text_only;
 
2095
    int                 start_line;
 
2096
    int                 num_lines;
 
2097
    int                 curr_line;
 
2098
    int                 visible_lines;
 
2099
    GLUI_Scrollbar      *scrollbar;
 
2100
    GLUI_List_Item      items_list;
 
2101
    GLUI_Control        *associated_object;
 
2102
    GLUI_CB             obj_cb;
 
2103
    int                 cb_click_type;
 
2104
    int                 last_line;
 
2105
    int                 last_click_time;
 
2106
 
 
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 );
 
2112
  
 
2113
    void activate( int how );
 
2114
    void deactivate( void );
 
2115
 
 
2116
    void draw( int x, int y );
 
2117
 
 
2118
    int  mouse_over( int state, int x, int y );
 
2119
 
 
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 );
 
2127
 
 
2128
 
 
2129
    int  add_item( int id, const char *text );
 
2130
    int  delete_item( const char *text );
 
2131
    int  delete_item( int id );
 
2132
    int  delete_all();
 
2133
 
 
2134
    GLUI_List_Item *get_item_ptr( const char *text );
 
2135
    GLUI_List_Item *get_item_ptr( int id );
 
2136
 
 
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; }
 
2145
 
 
2146
protected:
 
2147
    void common_init()
 
2148
    {
 
2149
        h                     = GLUI_LIST_HEIGHT;
 
2150
        w                     = GLUI_LIST_WIDTH;
 
2151
        num_lines             = 0;
 
2152
        visible_lines         = 0;
 
2153
        start_line            = 0;
 
2154
        curr_line             = 0;
 
2155
        name[0]               = '\0';
 
2156
        active_type           = GLUI_CONTROL_ACTIVE_PERMANENT;
 
2157
        can_activate          = true;
 
2158
        spacebar_mouse_click  = false;
 
2159
        scrollbar             = NULL;
 
2160
        debug                 = false;
 
2161
        draw_text_only        = false;
 
2162
        cb_click_type         = GLUI_SINGLE_CLICK;
 
2163
        last_line             = -1;
 
2164
        last_click_time       = 0;
 
2165
        associated_object     = NULL;
 
2166
    };
 
2167
    void common_construct(
 
2168
        GLUI_Node *parent,
 
2169
        GLUI_String* live_var, bool scroll,
 
2170
        int id,
 
2171
        GLUI_CB callback
 
2172
        /*,GLUI_Control *object*/
 
2173
        /*,GLUI_InterObject_CB obj_cb*/);
 
2174
};
 
2175
 
 
2176
/************************************************************/
 
2177
/*                                                          */
 
2178
/*               Scrollbar class - JVK                      */
 
2179
/*                                                          */
 
2180
/************************************************************/
 
2181
 
 
2182
class GLUI_Scrollbar : public GLUI_Control
 
2183
{
 
2184
public:
 
2185
    // Constructor, no live var
 
2186
    GLUI_Scrollbar( GLUI_Node *parent,
 
2187
                    const char *name, 
 
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*/
 
2193
                    );
 
2194
 
 
2195
    // Constructor, int live var
 
2196
    GLUI_Scrollbar( GLUI_Node *parent, const char *name, int horz_vert,
 
2197
                    int *live_var,
 
2198
                    int id=-1, GLUI_CB callback=GLUI_CB() 
 
2199
                    /*,GLUI_Control *object = NULL*/
 
2200
                    /*,GLUI_InterObject_CB obj_cb = NULL*/
 
2201
                    );
 
2202
 
 
2203
    // Constructor, float live var
 
2204
    GLUI_Scrollbar( GLUI_Node *parent, const char *name, int horz_vert,
 
2205
                    float *live_var,
 
2206
                    int id=-1, GLUI_CB callback=GLUI_CB()
 
2207
                    /*,GLUI_Control *object = NULL*/
 
2208
                    /*,GLUI_InterObject_CB obj_cb = NULL*/
 
2209
                    );
 
2210
 
 
2211
    bool          currently_inside;
 
2212
    int           state;
 
2213
    float         growth, growth_exp;
 
2214
    int           last_x, last_y;
 
2215
    int           data_type;
 
2216
    int           callback_count;
 
2217
    int           last_int_val;  ///< Used to prevent repeated callbacks.
 
2218
    float         last_float_val;
 
2219
    int           first_callback;
 
2220
    float         user_speed;
 
2221
    float         float_min, float_max;
 
2222
    int           int_min, int_max;
 
2223
    int           horizontal;
 
2224
    double     last_update_time; ///< GLUI_Time() we last advanced scrollbar.
 
2225
    double     velocity_limit; ///< Maximum distance to advance per second.
 
2226
    int box_length;
 
2227
    int box_start_position;
 
2228
    int box_end_position;
 
2229
    int track_length;
 
2230
 
 
2231
 
 
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.
 
2237
    */
 
2238
    void *        associated_object; /* Lets the Spinner manage it's own callbacks */
 
2239
    GLUI_CB       object_cb; /* function pointer to object call_back */
 
2240
 
 
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 );
 
2246
  
 
2247
    void draw( int x, int y );
 
2248
    void draw_pressed( void );
 
2249
    void draw_unpressed( void );
 
2250
    void draw_text( int sunken );
 
2251
 
 
2252
    void update_size( void );
 
2253
 
 
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 );
 
2261
    void idle( 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 );
 
2267
 
 
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; }
 
2272
 
 
2273
protected:
 
2274
    void common_init ( void );
 
2275
    void common_construct(
 
2276
        GLUI_Node *parent,
 
2277
        const char *name, 
 
2278
        int horz_vert,
 
2279
        int data_type, void* live_var,
 
2280
        int id, GLUI_CB callback
 
2281
        /*,GLUI_Control *object
 
2282
        ,GLUI_InterObject_CB obj_cb*/
 
2283
        );
 
2284
 
 
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);
 
2287
};
 
2288
 
 
2289
/************************************************************/
 
2290
/*                                                          */
 
2291
/*                   Listbox class                          */
 
2292
/*                                                          */
 
2293
/************************************************************/
 
2294
 
 
2295
class GLUI_Listbox_Item : public GLUI_Node 
 
2296
{
 
2297
public:
 
2298
    GLUI_String text;
 
2299
    int         id;
 
2300
};
 
2301
 
 
2302
class GLUI_Listbox : public GLUI_Control
 
2303
{
 
2304
public:
 
2305
    GLUI_String       curr_text;
 
2306
    GLUI_Listbox_Item items_list;
 
2307
    int               depressed;
 
2308
 
 
2309
    int  orig_value;
 
2310
    bool currently_inside;
 
2311
    int  text_x_offset, title_x_offset;
 
2312
    int  glut_menu_id;
 
2313
 
 
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 );
 
2319
 
 
2320
    void update_size( void );
 
2321
    void draw( int x, int y );
 
2322
    int  mouse_over( int state, int x, int y );
 
2323
 
 
2324
    void set_int_val( int new_val );
 
2325
    void dump( FILE *output );
 
2326
 
 
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 );
 
2331
 
 
2332
    int  do_selection( int item );
 
2333
 
 
2334
    GLUI_Listbox_Item *get_item_ptr( const char *text );
 
2335
    GLUI_Listbox_Item *get_item_ptr( int id );
 
2336
  
 
2337
 
 
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(); }
 
2342
 
 
2343
protected:
 
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;
 
2350
        orig_value     = -1;
 
2351
        title_x_offset = 0;
 
2352
        text_x_offset  = 55;
 
2353
        can_activate   = true;
 
2354
        curr_text      = "";
 
2355
        live_type      = GLUI_LIVE_INT;  /* This has an integer live var */
 
2356
        depressed      = false;
 
2357
        glut_menu_id   = -1;
 
2358
    }
 
2359
 
 
2360
    ~GLUI_Listbox();
 
2361
};
 
2362
 
 
2363
/************************************************************/
 
2364
/*                                                          */
 
2365
/*              Mouse_Interaction class                     */
 
2366
/*                                                          */
 
2367
/************************************************************/
 
2368
 
 
2369
/**
 
2370
  This is the superclass of translation and rotation widgets.
 
2371
*/
 
2372
class GLUI_Mouse_Interaction : public GLUI_Control
 
2373
{
 
2374
public:
 
2375
    /*int  get_main_area_size( void ) { return MIN( h-18,  */
 
2376
    int            draw_active_area_only;
 
2377
 
 
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 );
 
2385
 
 
2386
    /***  The following methods (starting with "iaction_") need to
 
2387
          be overloaded  ***/
 
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;
 
2396
  
 
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;
 
2405
    }
 
2406
};
 
2407
 
 
2408
/************************************************************/
 
2409
/*                                                          */
 
2410
/*                   Rotation class                         */
 
2411
/*                                                          */
 
2412
/************************************************************/
 
2413
 
 
2414
/**
 
2415
  An onscreen rotation controller--allows the user to interact with
 
2416
  a 3D rotation via a spaceball-like interface.
 
2417
*/
 
2418
class GLUI_Rotation : public GLUI_Mouse_Interaction
 
2419
{
 
2420
public:
 
2421
    Arcball        *ball;
 
2422
    GLUquadricObj *quadObj;
 
2423
    bool           can_spin, spinning;
 
2424
    float          damping;
 
2425
  
 
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 );
 
2434
 
 
2435
    /*  void update_size( void ); */
 
2436
    /*  void draw( int x, int y ); */
 
2437
    /*  int mouse_over( int state, int x, int y ); */
 
2438
 
 
2439
    void setup_texture( void );
 
2440
    void setup_lights( void );
 
2441
    void draw_ball( float radius );
 
2442
 
 
2443
    void init_ball( void );
 
2444
 
 
2445
    void reset( void );
 
2446
 
 
2447
    bool needs_idle( void ) const;
 
2448
    void idle( void );
 
2449
 
 
2450
    void copy_float_array_to_ball( void );
 
2451
    void copy_ball_to_float_array( void );
 
2452
 
 
2453
    void set_spin( float damp_factor );
 
2454
 
 
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(); }
 
2458
 
 
2459
protected:
 
2460
    void common_init();
 
2461
};
 
2462
 
 
2463
/************************************************************/
 
2464
/*                                                          */
 
2465
/*                   Translation class                      */
 
2466
/*                                                          */
 
2467
/************************************************************/
 
2468
 
 
2469
/**
 
2470
  An onscreen translation controller--allows the user to interact with
 
2471
  a 3D translation.
 
2472
*/
 
2473
class GLUI_Translation : public GLUI_Mouse_Interaction
 
2474
{
 
2475
public:
 
2476
    int trans_type;  /* Is this an XY or a Z controller? */
 
2477
    int down_x, down_y;
 
2478
    float scale_factor;
 
2479
    GLUquadricObj *quadObj;
 
2480
    int   trans_mouse_code;
 
2481
    float orig_x, orig_y, orig_z;
 
2482
    int   locked;
 
2483
 
 
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 );
 
2492
 
 
2493
    void set_speed( float s ) { scale_factor = s; }
 
2494
 
 
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 );
 
2502
 
 
2503
    int  get_mouse_code( int x, int y );
 
2504
 
 
2505
    /* Float array is either a single float (for single-axis controls),
 
2506
       or two floats for X and Y (if an XY controller) */
 
2507
 
 
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];
 
2513
    }
 
2514
 
 
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 );
 
2519
 
 
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(); }
 
2524
 
 
2525
protected:
 
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;
 
2536
        scale_factor        = 1.0;
 
2537
        quadObj             = NULL;
 
2538
        trans_mouse_code    = GLUI_TRANSLATION_MOUSE_NONE;
 
2539
    }
 
2540
};
 
2541
 
 
2542
/********** Misc functions *********************/
 
2543
int _glutBitmapWidthString( void *font, const char *s );
 
2544
void _glutBitmapString( void *font, const char *s );
 
2545
 
 
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
 
2549
   glut callbacks.  
 
2550
*/
 
2551
 
 
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);
 
2562
 
 
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);
 
2567
 
 
2568
#endif