~ubuntu-branches/ubuntu/edgy/glui/edgy

« back to all changes in this revision

Viewing changes to glui.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Marcelo E. Magallon
  • Date: 2001-09-23 12:57:28 UTC
  • Revision ID: james.westby@ubuntu.com-20010923125728-qbts7xit2eg1ogo2
Tags: upstream-2.1.0.beta
ImportĀ upstreamĀ versionĀ 2.1.0.beta

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
  
 
3
  GLUI User Interface Toolkit
 
4
  ---------------------------
 
5
 
 
6
     glui.cpp
 
7
 
 
8
 
 
9
          --------------------------------------------------
 
10
 
 
11
  Copyright (c) 1998 Paul Rademacher
 
12
 
 
13
  This program is freely distributable without licensing fees and is
 
14
  provided without guarantee or warrantee expressed or implied. This
 
15
  program is -not- in the public domain.
 
16
 
 
17
*****************************************************************************/
 
18
 
 
19
#include "glui.h"
 
20
#include "stdinc.h"
 
21
#include <GL/glut.h>
 
22
 
 
23
 
 
24
/*** This object must be used to create a GLUI ***/
 
25
 
 
26
GLUI_Master_Object GLUI_Master;
 
27
 
 
28
 
 
29
/************************************ finish_drawing() ************/
 
30
 
 
31
void finish_drawing( void ) 
 
32
{
 
33
        glFinish();
 
34
}
 
35
 
 
36
/************************************************ GLUI::GLUI() **********/
 
37
 
 
38
int GLUI::init( char *text, long flags, int x, int y, int parent_window ) 
 
39
{
 
40
  int old_glut_window;
 
41
 
 
42
  this->flags = flags;
 
43
 
 
44
  strncpy( window_name.string, text, sizeof(GLUI_String));
 
45
 
 
46
  /*** We copy over the current window callthroughs ***/
 
47
  /*** (I think this might actually only be needed for subwindows) ***/
 
48
  /*  glut_keyboard_CB = GLUI_Master.glut_keyboard_CB;
 
49
      glut_reshape_CB  = GLUI_Master.glut_reshape_CB;
 
50
      glut_special_CB  = GLUI_Master.glut_special_CB;
 
51
      glut_mouse_CB    = GLUI_Master.glut_mouse_CB;*/
 
52
 
 
53
 
 
54
  if ( (flags & GLUI_SUBWINDOW) != GLUI_SUBWINDOW ) {
 
55
    old_glut_window = glutGetWindow();
 
56
 
 
57
    create_standalone_window( window_name, x, y );
 
58
    setup_default_glut_callbacks();
 
59
 
 
60
    if ( old_glut_window > 0 )
 
61
      glutSetWindow( old_glut_window );
 
62
 
 
63
    top_level_glut_window_id = glut_window_id;
 
64
  } 
 
65
  else {
 
66
    old_glut_window = glutGetWindow();
 
67
 
 
68
    create_subwindow( parent_window, flags );
 
69
    setup_default_glut_callbacks();
 
70
 
 
71
    if ( old_glut_window > 0 )
 
72
      glutSetWindow( old_glut_window );
 
73
 
 
74
    top_level_glut_window_id = parent_window;
 
75
 
 
76
    /*
 
77
      glutReshapeFunc( glui_parent_window_reshape_func );
 
78
      glutSpecialFunc( glui_parent_window_special_func );
 
79
      glutKeyboardFunc( glui_parent_window_keyboard_func );
 
80
      glutMouseFunc( glui_parent_window_mouse_func );
 
81
      */
 
82
    
 
83
  }
 
84
 
 
85
  return true;
 
86
}
 
87
 
 
88
 
 
89
/**************************** GLUI_Main::create_standalone_window() ********/
 
90
 
 
91
void    GLUI_Main::create_standalone_window( char *name, int x, int y )
 
92
{
 
93
  glutInitWindowSize( 100, 100 );
 
94
  if ( x >= 0 OR y >= 0 )
 
95
    glutInitWindowPosition( x, y );
 
96
  glutInitDisplayMode( GLUT_RGB | GLUT_SINGLE ); /* | GLUT_DOUBLE );          */
 
97
  glut_window_id = glutCreateWindow( name );
 
98
  glDisable( GL_DEPTH_TEST );
 
99
  glCullFace( GL_BACK );
 
100
  glDisable( GL_CULL_FACE );
 
101
  glDisable( GL_LIGHTING );
 
102
  glDrawBuffer( GL_FRONT );
 
103
}
 
104
 
 
105
 
 
106
/******************************** GLUI_Main::create_subwindow() **********/
 
107
 
 
108
void     GLUI_Main::create_subwindow( int parent_window, int window_alignment )
 
109
{
 
110
  glut_window_id = glutCreateSubWindow( parent_window, 0,0, 100, 100 );
 
111
  glDisable( GL_DEPTH_TEST );
 
112
  glCullFace( GL_BACK );
 
113
  glDisable( GL_CULL_FACE );
 
114
  glDisable( GL_LIGHTING );  
 
115
  glDrawBuffer( GL_FRONT );
 
116
 
 
117
  this->parent_window = parent_window;
 
118
}
 
119
 
 
120
 
 
121
/**************************** GLUI_Main::setup_default_glut_callbacks() *****/
 
122
 
 
123
void   GLUI_Main::setup_default_glut_callbacks( void )
 
124
{
 
125
  glutDisplayFunc( glui_display_func );
 
126
  glutReshapeFunc( glui_reshape_func );
 
127
  glutKeyboardFunc( glui_keyboard_func );
 
128
  glutSpecialFunc( glui_special_func );
 
129
  glutMouseFunc( glui_mouse_func );
 
130
  glutMotionFunc( glui_motion_func );
 
131
  glutPassiveMotionFunc( glui_passive_motion_func );
 
132
  glutEntryFunc( glui_entry_func );
 
133
  glutVisibilityFunc( glui_visibility_func );
 
134
  /*  glutIdleFunc( glui_idle_func );          */
 
135
}
 
136
 
 
137
 
 
138
/********************************************** glui_display_func() ********/
 
139
 
 
140
void glui_display_func( void )
 
141
{
 
142
  GLUI *glui;
 
143
 
 
144
  /*  printf( "display func\n" );          */
 
145
 
 
146
  glui = GLUI_Master.find_glui_by_window_id( glutGetWindow() );
 
147
 
 
148
  if ( glui ) {
 
149
    glui->display(); 
 
150
    /* 
 
151
       Do not do anything after the above line, b/c the GLUI
 
152
       window might have just closed itself 
 
153
   */
 
154
  }
 
155
}
 
156
 
 
157
 
 
158
/********************************************** glui_reshape_func() ********/
 
159
 
 
160
void glui_reshape_func( int w, int h )
 
161
{
 
162
  GLUI             *glui;
 
163
  GLUI_Glut_Window *glut_window;
 
164
  int               current_window;
 
165
 
 
166
  /*printf( "glui_reshape_func(): %d  w/h: %d/%d\n", glutGetWindow(), w, h );          */
 
167
 
 
168
  current_window = glutGetWindow();
 
169
 
 
170
  /***  First check if this is main glut window ***/
 
171
  glut_window = GLUI_Master.find_glut_window( current_window );
 
172
  if ( glut_window ) {
 
173
    glut_window->glut_reshape_CB(w,h);
 
174
 
 
175
    /***  Now send reshape events to all subwindows  ***/
 
176
    glui = (GLUI*) GLUI_Master.gluis.first_child();
 
177
    while(glui) {
 
178
      if ( TEST_AND( glui->flags, GLUI_SUBWINDOW) AND 
 
179
           glui->parent_window == current_window ) {
 
180
        glutSetWindow( glui->get_glut_window_id());
 
181
        glui->reshape(w,h);
 
182
        /*      glui->check_subwindow_position();          */
 
183
      }
 
184
      glui = (GLUI*) glui->next();
 
185
    }
 
186
  }
 
187
  else {
 
188
    /***  A standalone GLUI window  ***/
 
189
 
 
190
    glui = GLUI_Master.find_glui_by_window_id( current_window );
 
191
 
 
192
    if ( glui ) {
 
193
      glui->reshape(w,h);
 
194
    }
 
195
  }
 
196
}
 
197
 
 
198
/********************************************** glui_keyboard_func() ********/
 
199
 
 
200
void glui_keyboard_func(unsigned char key, int x, int y)
 
201
{
 
202
  GLUI              *glui;
 
203
  int                current_window;
 
204
  GLUI_Glut_Window  *glut_window;
 
205
 
 
206
  current_window = glutGetWindow();
 
207
  glut_window = GLUI_Master.find_glut_window( current_window );
 
208
 
 
209
  /*printf( "key: %d\n", current_window );          */
 
210
 
 
211
  if ( glut_window ) { /**  Was event in a GLUT window?  **/
 
212
    if ( GLUI_Master.active_control_glui AND GLUI_Master.active_control ) {
 
213
      glutSetWindow( GLUI_Master.active_control_glui->get_glut_window_id() );
 
214
      
 
215
      GLUI_Master.active_control_glui->keyboard(key,x,y);    
 
216
          finish_drawing();
 
217
      
 
218
      glutSetWindow( current_window );
 
219
    }
 
220
    else {
 
221
      glut_window->glut_keyboard_CB( key, x, y );
 
222
    } 
 
223
  }
 
224
  else {   /***  Nope, event was in a standalone GLUI window  **/
 
225
    glui = GLUI_Master.find_glui_by_window_id( glutGetWindow() );
 
226
 
 
227
    if ( glui ) {
 
228
      glui->keyboard(key,x,y);
 
229
          finish_drawing();
 
230
    }
 
231
  }
 
232
}
 
233
 
 
234
 
 
235
/************************************************ glui_special_func() ********/
 
236
 
 
237
void glui_special_func(int key, int x, int y)
 
238
{
 
239
  GLUI              *glui;
 
240
  int                current_window;
 
241
  GLUI_Glut_Window  *glut_window;
 
242
 
 
243
  current_window = glutGetWindow();
 
244
  glut_window = GLUI_Master.find_glut_window( current_window );
 
245
 
 
246
  if ( glut_window ) { /**  Was event in a GLUT window?  **/
 
247
    if ( GLUI_Master.active_control_glui AND GLUI_Master.active_control ) {
 
248
      glutSetWindow( GLUI_Master.active_control_glui->get_glut_window_id() );
 
249
      
 
250
      GLUI_Master.active_control_glui->special(key,x,y);    
 
251
          finish_drawing();
 
252
      
 
253
      glutSetWindow( current_window );
 
254
    }
 
255
    else {
 
256
      glut_window->glut_special_CB( key, x, y );
 
257
    } 
 
258
  }
 
259
  else {   /***  Nope, event was in a standalone GLUI window  **/
 
260
    glui = GLUI_Master.find_glui_by_window_id( glutGetWindow() );
 
261
 
 
262
    if ( glui ) {
 
263
      glui->special(key,x,y);
 
264
          finish_drawing();
 
265
    }
 
266
  }
 
267
}
 
268
 
 
269
 
 
270
 
 
271
/********************************************** glui_mouse_func() ********/
 
272
 
 
273
void glui_mouse_func(int button, int state, int x, int y)
 
274
{
 
275
  GLUI              *glui;
 
276
  int                current_window;
 
277
  GLUI_Glut_Window  *glut_window;
 
278
 
 
279
  current_window = glutGetWindow();
 
280
  glut_window = GLUI_Master.find_glut_window( current_window );
 
281
 
 
282
  if ( glut_window ) { /**  Was event in a GLUT window?  **/
 
283
    if ( GLUI_Master.active_control_glui != NULL ) 
 
284
      GLUI_Master.active_control_glui->disactivate_current_control();
 
285
 
 
286
    glut_window->glut_mouse_CB( button, state, x, y );
 
287
        finish_drawing();
 
288
  }
 
289
  else {               /**  Nope - event was in a GLUI standalone window  **/
 
290
    glui = GLUI_Master.find_glui_by_window_id( glutGetWindow() );
 
291
    if ( glui ) {
 
292
      glui->passive_motion( 0,0 );
 
293
      glui->mouse( button, state, x, y );
 
294
          finish_drawing();
 
295
    }
 
296
  }
 
297
}
 
298
 
 
299
 
 
300
/********************************************** glui_motion_func() ********/
 
301
 
 
302
void glui_motion_func(int x, int y)
 
303
{
 
304
  GLUI *glui;
 
305
 
 
306
  glui = GLUI_Master.find_glui_by_window_id( glutGetWindow() );
 
307
 
 
308
  if ( glui ) {
 
309
    glui->motion(x,y);
 
310
        finish_drawing();
 
311
  }
 
312
 
 
313
}
 
314
 
 
315
 
 
316
/**************************************** glui_passive_motion_func() ********/
 
317
 
 
318
void glui_passive_motion_func(int x, int y)
 
319
{
 
320
  GLUI *glui;
 
321
 
 
322
  glui = GLUI_Master.find_glui_by_window_id( glutGetWindow() );
 
323
 
 
324
  if ( glui ) {
 
325
    glui->passive_motion(x,y);
 
326
        finish_drawing();
 
327
  }
 
328
}
 
329
 
 
330
 
 
331
/********************************************** glui_entry_func() ********/
 
332
 
 
333
void glui_entry_func(int state)
 
334
{
 
335
  GLUI *glui;
 
336
 
 
337
  glui = GLUI_Master.find_glui_by_window_id( glutGetWindow() );
 
338
 
 
339
  if ( glui ) {
 
340
    glui->entry(state);
 
341
  }
 
342
}
 
343
 
 
344
 
 
345
/******************************************** glui_visibility_func() ********/
 
346
 
 
347
void glui_visibility_func(int state)
 
348
{
 
349
  GLUI *glui;
 
350
 
 
351
  /*  printf( "IN GLUI VISIBILITY()\n" );          */
 
352
  /*  fflush( stdout );          */
 
353
 
 
354
  glui = GLUI_Master.find_glui_by_window_id( glutGetWindow() );
 
355
 
 
356
  if ( glui ) {
 
357
    glui->visibility(state);
 
358
  }
 
359
}
 
360
 
 
361
 
 
362
/********************************************** glui_idle_func() ********/
 
363
/* Send idle event to each glui, then to the main window            */
 
364
 
 
365
void glui_idle_func(void)
 
366
{
 
367
  GLUI *glui;
 
368
 
 
369
  glui = (GLUI*) GLUI_Master.gluis.first_child();
 
370
  while( glui ) {
 
371
    glui->idle();
 
372
        finish_drawing();
 
373
    
 
374
    glui = (GLUI*) glui->next();
 
375
  }
 
376
 
 
377
  if ( GLUI_Master.glut_idle_CB ) {
 
378
    /*** We set the current glut window before calling the user's
 
379
      idle function, even though glut explicitly says the window id is 
 
380
      undefined in an idle callback.  ***/
 
381
    
 
382
    /** Check what the current window is first ***/
 
383
 
 
384
    /*** Arbitrarily set the window id to the main gfx window of the 
 
385
      first glui window ***/
 
386
    /*   int current_window, new_window;          */
 
387
    /*   current_window = glutGetWindow();          */
 
388
    /*   if (GLUI_Master.gluis.first_child() != NULL ) {          */
 
389
    /*      new_window = ((GLUI_Main*)GLUI_Master.gluis.first_child())-> */
 
390
    /*   main_gfx_window_id;          */
 
391
    /*   if ( new_window > 0 AND new_window != old_window ) {          */
 
392
    /*   --- Window is changed only if its not already the current window ---*/
 
393
    /*  glutSetWindow( new_window );          */
 
394
    /* }          */
 
395
    /*}          */
 
396
    
 
397
    GLUI_Master.glut_idle_CB();
 
398
  }
 
399
}
 
400
 
 
401
 
 
402
/*********************************** GLUI_Master_Object::create_glui() ******/
 
403
 
 
404
GLUI    *GLUI_Master_Object::create_glui( char *name, long flags,int x,int y )
 
405
{
 
406
  GLUI *new_glui;
 
407
 
 
408
  new_glui = new GLUI;
 
409
  
 
410
  if ( new_glui ) {
 
411
    new_glui->init( name, flags, x, y, -1 );
 
412
    new_glui->link_this_to_parent_last( &this->gluis );
 
413
    return new_glui;
 
414
  }
 
415
  else {
 
416
    return NULL;
 
417
  }
 
418
}
 
419
 
 
420
 
 
421
/************************** GLUI_Master_Object::create_glui_subwindow() ******/
 
422
 
 
423
GLUI   *GLUI_Master_Object::create_glui_subwindow( int parent_window, 
 
424
                                                   long flags )
 
425
{
 
426
  GLUI *new_glui;
 
427
  char  new_name[80];
 
428
 
 
429
  new_glui = new GLUI;
 
430
 
 
431
  if ( new_glui ) {
 
432
    sprintf( new_name, "subwin_%p", this );
 
433
 
 
434
    new_glui->init( new_name, flags | GLUI_SUBWINDOW, 0,0,
 
435
                    parent_window );
 
436
    new_glui->main_panel->set_int_val( GLUI_PANEL_EMBOSSED );
 
437
    new_glui->link_this_to_parent_last( &this->gluis );
 
438
    return new_glui;
 
439
  }
 
440
  else {
 
441
    return NULL;
 
442
  }
 
443
}
 
444
 
 
445
 
 
446
 
 
447
/********************** GLUI_Master_Object::find_glui_by_window_id() ********/
 
448
 
 
449
GLUI  *GLUI_Master_Object::find_glui_by_window_id( int window_id )
 
450
{
 
451
  GLUI_Node *node;
 
452
 
 
453
  node = gluis.first_child();
 
454
  while( node ) {
 
455
    if ( ((GLUI*)node)->get_glut_window_id() == window_id ) 
 
456
      return (GLUI*) node;
 
457
    
 
458
    node = node->next();
 
459
  }
 
460
  return NULL;
 
461
}
 
462
 
 
463
 
 
464
/******************************************** GLUI_Main::display() **********/
 
465
 
 
466
void    GLUI_Main::display( void )
 
467
{
 
468
  int       win_w, win_h;
 
469
 
 
470
  /*glutSetWindow(1);///WOW WHAT A HACK          */
 
471
 
 
472
  /**** This function is used as a special place to do 'safe' processing,
 
473
    e.g., handling window close requests.
 
474
    That is, we can't close the window directly in the callback, so 
 
475
    we set a flag, post a redisplay message (which eventually calls
 
476
    this function), then close the window safely in here.  ****/
 
477
  if ( closing == true ) {
 
478
    close_internal();
 
479
    return;
 
480
  }
 
481
 
 
482
  /*  if ( TEST_AND( this->flags, GLUI_SUBWINDOW ))
 
483
      check_subwindow_position();
 
484
      */
 
485
 
 
486
  /*******    Draw GLUI window     ******/
 
487
 
 
488
  glClearColor( (float) bkgd_color.r / 255.0,
 
489
                (float) bkgd_color.g / 255.0,
 
490
                (float) bkgd_color.b / 255.0,
 
491
                1.0 );
 
492
  glClear( GL_COLOR_BUFFER_BIT ); /* | GL_DEPTH_BUFFER_BIT );          */
 
493
 
 
494
  /*  glutSwapBuffers(); //performs flush also  // %%%%%%%%%%          */
 
495
  /*  return;          */
 
496
 
 
497
  win_w = glutGet( GLUT_WINDOW_WIDTH );
 
498
  win_h = glutGet( GLUT_WINDOW_HEIGHT );
 
499
 
 
500
  /*** Check here if the window needs resizing ***/
 
501
  if ( win_w != main_panel->w OR win_h != main_panel->h ) {
 
502
    glutReshapeWindow( main_panel->w, main_panel->h );
 
503
    return;
 
504
  }
 
505
 
 
506
  set_ortho_projection();
 
507
 
 
508
  glMatrixMode( GL_MODELVIEW );
 
509
  glLoadIdentity();
 
510
 
 
511
  /*** Rotate image so y increases upwards, contrary to OpenGL axes ***/
 
512
  glTranslatef( (float) win_w/2.0, (float) win_h/2.0, 0.0 );
 
513
  glRotatef( 180.0, 0.0, 1.0, 0.0 );
 
514
  glRotatef( 180.0, 0.0, 0.0, 1.0 );
 
515
  glTranslatef( (float) -win_w/2.0, (float) -win_h/2.0, 0.0 );
 
516
 
 
517
  /*  glDrawBuffer( GL_BACK );  // Is there ever a need to draw to back buffer??           */
 
518
 
 
519
  //  main_panel->draw_bkgd_box( 0, 0, win_w, win_h );
 
520
  main_panel->draw_recursive( 0, 0 );
 
521
 
 
522
  /*glutSwapBuffers(); //performs flush also            */
 
523
  finish_drawing();
 
524
}
 
525
 
 
526
 
 
527
 
 
528
 
 
529
/*************************************** _glutBitmapWidthString() **********/
 
530
 
 
531
int _glutBitmapWidthString( void *font, char *s )
 
532
{
 
533
  char *p = s;
 
534
  int  width = 0;
 
535
 
 
536
  while( *p != '\0' )  {
 
537
    width += glutBitmapWidth( font, *p );
 
538
    p++;
 
539
  }
 
540
 
 
541
  return width;
 
542
}
 
543
 
 
544
/************************************ _glutBitmapString *********************/
 
545
/* Displays the contents of a string using GLUT's bitmap character function */
 
546
/* Does not handle newlines                                             */
 
547
 
 
548
void _glutBitmapString( void *font, char *s )
 
549
{
 
550
  char *p = s;
 
551
 
 
552
  while( *p != '\0' )  {
 
553
    glutBitmapCharacter( font, *p );
 
554
    p++;
 
555
  }
 
556
}
 
557
 
 
558
 
 
559
 
 
560
/****************************** GLUI_Main::reshape() **************/
 
561
 
 
562
void    GLUI_Main::reshape( int reshape_w, int reshape_h )
 
563
{
 
564
  int new_w, new_h;
 
565
 
 
566
  pack_controls();
 
567
 
 
568
  new_w = main_panel->w;/* + 1;          */
 
569
  new_h = main_panel->h;/* + 1;          */
 
570
 
 
571
  if ( reshape_w != new_w OR reshape_h != new_h ) {
 
572
    this->w = new_w;
 
573
    this->h = new_h;
 
574
    
 
575
    glutReshapeWindow( new_w, new_h );
 
576
  }
 
577
  else {
 
578
  }
 
579
 
 
580
  if ( TEST_AND( this->flags, GLUI_SUBWINDOW ) ) {
 
581
    check_subwindow_position();
 
582
 
 
583
    /***** if ( TEST_AND(this->flags,GLUI_SUBWINDOW_LEFT )) {
 
584
      }
 
585
      else if ( TEST_AND(this->flags,GLUI_SUBWINDOW_LEFT )) {
 
586
      }
 
587
      else if ( TEST_AND(this->flags,GLUI_SUBWINDOW_LEFT )) {
 
588
      }
 
589
      else if ( TEST_AND(this->flags,GLUI_SUBWINDOW_RIGHT )) {
 
590
      }
 
591
      ****/
 
592
  }
 
593
  
 
594
  glViewport( 0, 0, new_w, new_h );
 
595
 
 
596
  /*  printf( "%d: %d\n", glutGetWindow(), this->flags );          */
 
597
 
 
598
  /*  glutPostRedisplay();          */
 
599
}
 
600
 
 
601
 
 
602
/****************************** GLUI_Main::keyboard() **************/
 
603
 
 
604
void    GLUI_Main::keyboard(unsigned char key, int x, int y)
 
605
{
 
606
  GLUI_Control *new_control;
 
607
 
 
608
  curr_modifiers = glutGetModifiers();
 
609
 
 
610
  /*** If it's a tab or shift tab, we don't pass it on to the controls.
 
611
    Instead, we use it to cycle through active controls ***/
 
612
  if ( key == '\t' AND mouse_button_down == false ) {
 
613
    if ( curr_modifiers & GLUT_ACTIVE_SHIFT ) {
 
614
      new_control = find_prev_control( active_control );
 
615
    }
 
616
    else {
 
617
      new_control = find_next_control( active_control );
 
618
    }
 
619
 
 
620
    /*    if ( new_control )
 
621
          printf( "new_control: %s\n", new_control->name );
 
622
          */
 
623
 
 
624
    disactivate_current_control();
 
625
    activate_control( new_control, GLUI_ACTIVATE_TAB );
 
626
  }
 
627
  else if ( key == ' ' AND active_control 
 
628
            AND active_control->spacebar_mouse_click == true ) { 
 
629
    /*** If the user presses the spacebar, and a non-edittext control
 
630
      is active, we send it a mouse down event followed by a mouse up
 
631
      event (simulated mouse-click) ***/
 
632
    
 
633
    active_control->mouse_down_handler( 0, 0 );
 
634
    active_control->mouse_up_handler( 0, 0, true );
 
635
  } else {
 
636
    /*** Pass the keystroke onto the active control, if any ***/
 
637
    if ( active_control != NULL )
 
638
      active_control->key_handler( key, curr_modifiers );
 
639
  }
 
640
}
 
641
 
 
642
 
 
643
/****************************** GLUI_Main::special() **************/
 
644
 
 
645
void    GLUI_Main::special(int key, int x, int y)
 
646
{
 
647
  curr_modifiers = glutGetModifiers();
 
648
 
 
649
  /*** Pass the keystroke onto the active control, if any ***/
 
650
  if ( active_control != NULL )
 
651
    active_control->special_handler( key, glutGetModifiers() );
 
652
}
 
653
 
 
654
 
 
655
 
 
656
/****************************** GLUI_Main::mouse() **************/
 
657
 
 
658
void    GLUI_Main::mouse(int button, int state, int x, int y)
 
659
{
 
660
  int callthrough;
 
661
  GLUI_Control *control;
 
662
 
 
663
  /*  printf( "MOUSE: %d %d\n", button, state );          */
 
664
 
 
665
  callthrough = true;
 
666
 
 
667
  curr_modifiers = glutGetModifiers();
 
668
 
 
669
  if ( button == GLUT_LEFT ) {
 
670
    control = find_control( x, y );
 
671
 
 
672
    /*if ( control ) printf( "control: %s\n", control->name.string );          */
 
673
    
 
674
    if ( mouse_button_down AND active_control != NULL AND
 
675
         state == GLUT_UP ) {
 
676
      /** We just released the mouse, which was depressed at some
 
677
        control **/
 
678
 
 
679
      callthrough = active_control->
 
680
        mouse_up_handler( x, y, control==active_control);
 
681
      glutSetCursor( GLUT_CURSOR_LEFT_ARROW );
 
682
 
 
683
      if ( active_control AND 
 
684
           active_control->active_type == 
 
685
           GLUI_CONTROL_ACTIVE_MOUSEDOWN AND 0){
 
686
        /*** This is a control that needs to be disactivated when the
 
687
          mouse button is released ****/
 
688
        disactivate_current_control();
 
689
      }
 
690
    }
 
691
    else {
 
692
      if ( control ) {
 
693
        if ( NOT mouse_button_down AND state == GLUT_DOWN ) {
 
694
          /*** We just pressed the mouse down at some control ***/
 
695
 
 
696
          if ( active_control != control ) {
 
697
            if ( active_control != NULL ) {
 
698
              /** There is an active control still - disactivate it ***/
 
699
              disactivate_current_control();
 
700
            }
 
701
          }
 
702
 
 
703
          if ( control->enabled ) {
 
704
            activate_control( control, GLUI_ACTIVATE_MOUSE );
 
705
            callthrough    = control->mouse_down_handler( x, y );
 
706
          }
 
707
        }
 
708
      }
 
709
    }
 
710
 
 
711
    if ( state == GLUT_DOWN )
 
712
      mouse_button_down = true;
 
713
    else if ( state == GLUT_UP )
 
714
      mouse_button_down = false;
 
715
  }
 
716
 
 
717
  /**
 
718
    NO CALLTHROUGH NEEDED FOR MOUSE EVENTS
 
719
    if ( callthrough AND glut_mouse_CB )
 
720
    glut_mouse_CB( button, state, x, y );
 
721
    **/
 
722
 
 
723
  callthrough=callthrough; /* To get rid of compiler warnings */
 
724
}
 
725
 
 
726
 
 
727
/****************************** GLUI_Main::motion() **************/
 
728
 
 
729
void    GLUI_Main::motion(int x, int y)
 
730
{
 
731
  int           callthrough;
 
732
  GLUI_Control *control;
 
733
 
 
734
  /*  printf( "MOTION: %d %d\n", x, y );          */
 
735
 
 
736
  callthrough = true;
 
737
 
 
738
  control = find_control(x,y);
 
739
  
 
740
  if ( mouse_button_down AND active_control != NULL ) {
 
741
    callthrough = 
 
742
      active_control->mouse_held_down_handler(x,y,control==active_control);
 
743
  }
 
744
  
 
745
  /**
 
746
    NO CALLTHROUGH NEEDED FOR MOUSE EVENTS
 
747
 
 
748
    if ( callthrough AND glut_motion_CB )
 
749
    glut_motion_CB(x,y);
 
750
    **/
 
751
 
 
752
  callthrough=callthrough; /* To get rid of compiler warnings */
 
753
}
 
754
 
 
755
 
 
756
/*********************** GLUI_Main::passive_motion() **************/
 
757
 
 
758
void    GLUI_Main::passive_motion(int x, int y)
 
759
{
 
760
  GLUI_Control *control;
 
761
 
 
762
  control = find_control( x, y );
 
763
 
 
764
  /*  printf( "%p %p\n", control, mouse_over_control );          */
 
765
 
 
766
  if ( control != mouse_over_control ) {
 
767
    if ( mouse_over_control ) {
 
768
      mouse_over_control->mouse_over( false, x, y );
 
769
    }
 
770
 
 
771
    if ( control ) {
 
772
      control->mouse_over( true, x, y );
 
773
      mouse_over_control = control;
 
774
    }
 
775
  }
 
776
 
 
777
  /*
 
778
    if ( curr_cursor != GLUT_CURSOR_INHERIT ) {
 
779
    curr_cursor = GLUT_CURSOR_INHERIT;
 
780
    glutSetCursor( GLUT_CURSOR_INHERIT );
 
781
    }*/
 
782
 
 
783
}
 
784
 
 
785
 
 
786
/****************************** GLUI_Main::entry() **************/
 
787
 
 
788
void    GLUI_Main::entry(int state)
 
789
{
 
790
  /*if ( NOT active_control OR ( active_control AND ( active_control->type == GLUI_CONTROL_EDITTEXT
 
791
    OR active_control->type == GLUI_CONTROL_SPINNER) ) )*/
 
792
  glutSetCursor( GLUT_CURSOR_LEFT_ARROW );
 
793
}
 
794
 
 
795
 
 
796
/****************************** GLUI_Main::visibility() **************/
 
797
 
 
798
void    GLUI_Main::visibility(int state)
 
799
{
 
800
}
 
801
 
 
802
 
 
803
/****************************** GLUI_Main::idle() **************/
 
804
 
 
805
void    GLUI_Main::idle(void)
 
806
{
 
807
  /*** Pass the idle event onto the active control, if any ***/
 
808
 
 
809
  /*  printf( "IDLE \t" );          */
 
810
 
 
811
  if ( active_control != NULL ) {
 
812
    /* First we check if the control actually needs the idle right now.
 
813
       Otherwise, let's avoid wasting cycles and OpenGL context switching */
 
814
 
 
815
    if ( active_control->needs_idle() ) {
 
816
      /*** Set the current glut window to the glui window */
 
817
      /*** But don't change the window if we're already at that window ***/
 
818
 
 
819
      if ( glut_window_id > 0 AND glutGetWindow() != glut_window_id ) {
 
820
        glutSetWindow( glut_window_id );
 
821
      }
 
822
      
 
823
      active_control->idle();
 
824
    }
 
825
  }
 
826
}
 
827
 
 
828
 
 
829
/******************************************* GLUI_Main::find_control() ******/
 
830
 
 
831
GLUI_Control  *GLUI_Main::find_control( int x, int y )
 
832
{
 
833
  GLUI_Control *node, *last_container;
 
834
 
 
835
  last_container = NULL;
 
836
 
 
837
  node = main_panel;
 
838
  while( node != NULL ) {
 
839
    if ( node->type != GLUI_CONTROL_COLUMN AND
 
840
         PT_IN_BOX( x, y, 
 
841
                    node->x_abs, node->x_abs + node->w, 
 
842
                    node->y_abs, node->y_abs + node->h ) ) {
 
843
      /*** Point is inside current node ***/
 
844
      
 
845
      if ( node->first_child() == NULL ) {
 
846
        /*** SPECIAL CASE: for edittext boxes, we make sure click is
 
847
          in box, and not on name string.  This should be generalized
 
848
          for all controls later... ***/
 
849
        if ( node->type == GLUI_CONTROL_EDITTEXT ) {
 
850
          if ( x < node->x_abs + ((GLUI_EditText*)node)->text_x_offset )
 
851
            return (GLUI_Control*) node->parent();
 
852
        }
 
853
 
 
854
        return node;   /* point is inside this node, and node has no children,
 
855
                          so return this node as the selected node */
 
856
      }
 
857
      else {
 
858
        /*** This is a container class ***/
 
859
        last_container = node;
 
860
        node = (GLUI_Control*) node->first_child();  /* Descend into child */
 
861
      }
 
862
      
 
863
    }
 
864
    else {
 
865
      node = (GLUI_Control*) node->next();
 
866
    }
 
867
  }
 
868
 
 
869
  /** No leaf-level nodes found to accept the mouse click, so
 
870
    return the last container control found which DOES accept the click **/
 
871
  
 
872
  if ( last_container ) {
 
873
    /*    printf( "ctrl: '%s'\n", last_container->name );          */
 
874
  
 
875
    return last_container;
 
876
  }
 
877
  else {
 
878
    return NULL;
 
879
  }
 
880
}
 
881
 
 
882
 
 
883
/************************************* GLUI_Main::pack_controls() ***********/
 
884
 
 
885
void      GLUI_Main::pack_controls( void )
 
886
{
 
887
  main_panel->pack(0,0);
 
888
 
 
889
  /**** Now align controls within their bounds ****/
 
890
  align_controls( main_panel );
 
891
 
 
892
  /***  If this is a subwindow, expand panel to fit parent window  ***/
 
893
  if ( TEST_AND( this->flags, GLUI_SUBWINDOW ) ) {
 
894
    int parent_h, parent_w;
 
895
    int orig_window;
 
896
 
 
897
    orig_window = glutGetWindow();
 
898
    glutSetWindow( this->top_level_glut_window_id );
 
899
    parent_h = glutGet( GLUT_WINDOW_HEIGHT );
 
900
    parent_w = glutGet( GLUT_WINDOW_WIDTH );
 
901
 
 
902
    glutSetWindow( orig_window );
 
903
 
 
904
    /*          printf( "%d %d\n", parent_h, parent_w );          */
 
905
 
 
906
    if ( 1 ) {
 
907
      if ( TEST_AND(this->flags,GLUI_SUBWINDOW_TOP )) {
 
908
        main_panel->w = MAX( main_panel->w, parent_w );
 
909
      }
 
910
      else if ( TEST_AND(this->flags,GLUI_SUBWINDOW_LEFT )) {
 
911
        main_panel->h = MAX( main_panel->h, parent_h );
 
912
      }
 
913
      else if ( TEST_AND(this->flags,GLUI_SUBWINDOW_BOTTOM )) {
 
914
        main_panel->w = MAX( main_panel->w, parent_w );
 
915
      }
 
916
      else if ( TEST_AND(this->flags,GLUI_SUBWINDOW_RIGHT )) {
 
917
        main_panel->h = MAX( main_panel->h, parent_h );
 
918
      }
 
919
    }
 
920
  }
 
921
 
 
922
  this->w = main_panel->w;
 
923
  this->h = main_panel->h;
 
924
}
 
925
 
 
926
 
 
927
/************************************ GLUI_Main::align_controls() **********/
 
928
 
 
929
void    GLUI_Main::align_controls( GLUI_Control *control )
 
930
{
 
931
  GLUI_Control *child;
 
932
 
 
933
  control->align();
 
934
 
 
935
  child = (GLUI_Control*) control->first_child();
 
936
 
 
937
  while( child != NULL ) {
 
938
    align_controls( child );
 
939
    
 
940
    child = (GLUI_Control*)child->next();
 
941
  }  
 
942
}
 
943
 
 
944
 
 
945
 
 
946
/*********************************** GLUI::set_main_gfx_window() ************/
 
947
 
 
948
void   GLUI::set_main_gfx_window( int window_id )
 
949
{
 
950
  main_gfx_window_id = window_id;
 
951
}
 
952
 
 
953
 
 
954
/********************************* GLUI_Main::post_update_main_gfx() ********/
 
955
 
 
956
void   GLUI_Main::post_update_main_gfx( void )
 
957
{
 
958
  int old_window;
 
959
 
 
960
  if ( main_gfx_window_id > 0 ) {
 
961
    old_window = glutGetWindow();
 
962
    glutSetWindow( main_gfx_window_id );
 
963
    glutPostRedisplay();
 
964
    if( old_window > 0 )
 
965
      glutSetWindow( old_window );
 
966
  }
 
967
}
 
968
 
 
969
 
 
970
/********************************* GLUI_Main::set_front_draw_buffer() ********/
 
971
 
 
972
int          GLUI_Main::set_front_draw_buffer( void )
 
973
{
 
974
  GLint state;
 
975
  
 
976
  glGetIntegerv( GL_DRAW_BUFFER, &state );
 
977
 
 
978
  glDrawBuffer( GL_FRONT );
 
979
  
 
980
  return (int)state;
 
981
}
 
982
 
 
983
 
 
984
/********************************* GLUI_Main::restore_draw_buffer() **********/
 
985
 
 
986
void         GLUI_Main::restore_draw_buffer( int buffer_state )
 
987
{
 
988
  glDrawBuffer( buffer_state );
 
989
}
 
990
 
 
991
 
 
992
/******************************************** GLUI_Main::GLUI_Main() ********/
 
993
 
 
994
GLUI_Main::GLUI_Main( void ) 
 
995
{
 
996
  mouse_button_down       = false;
 
997
  w                       = 0;
 
998
  h                       = 0;
 
999
  active_control          = NULL;
 
1000
  mouse_over_control      = NULL;
 
1001
  main_gfx_window_id      = -1;
 
1002
  glut_window_id          = -1;
 
1003
  curr_modifiers          = 0;
 
1004
  closing                 = false;
 
1005
  parent_window           = -1;
 
1006
  glui_id                 = GLUI_Master.glui_id_counter;
 
1007
  GLUI_Master.glui_id_counter++;
 
1008
 
 
1009
  font                    = GLUT_BITMAP_HELVETICA_12;
 
1010
  curr_cursor             = GLUT_CURSOR_LEFT_ARROW;
 
1011
 
 
1012
  bkgd_color.set( 200, 200, 200 );
 
1013
  bkgd_color_f[0] = 200.0 / 255.0;
 
1014
  bkgd_color_f[1] = 200.0 / 255.0;
 
1015
  bkgd_color_f[2] = 200.0 / 255.0;
 
1016
 
 
1017
  /*** Create the main panel ***/
 
1018
  main_panel              = new GLUI_Panel;
 
1019
  main_panel->set_int_val( GLUI_PANEL_NONE );
 
1020
  main_panel->glui        = (GLUI*) this;
 
1021
  main_panel->name        = "\0";
 
1022
}
 
1023
 
 
1024
/************************************ GLUI_Main::draw_raised_box() **********/
 
1025
 
 
1026
void      GLUI_Main::draw_raised_box( int x, int y, int w, int h )
 
1027
{
 
1028
  w = w+x;
 
1029
  h = h+y;
 
1030
 
 
1031
  glColor3ub( bkgd_color.r, bkgd_color.g, bkgd_color.b );
 
1032
  glBegin( GL_LINE_LOOP );
 
1033
  glVertex2i( x+1, y+1 );         glVertex2i( w-1, y+1 );
 
1034
  glVertex2i( w-1, h-1 );     glVertex2i( x+1, h-1 );
 
1035
  glEnd();
 
1036
 
 
1037
  glColor3d( 1.0, 1.0, 1.0 );
 
1038
  glBegin( GL_LINE_STRIP );
 
1039
  glVertex2i( x, h );  glVertex2i( x, y );  glVertex2i( w, y );
 
1040
  glEnd();
 
1041
 
 
1042
  glColor3d( 0.0, 0.0, 0.0 );
 
1043
  glBegin( GL_LINE_STRIP );
 
1044
  glVertex2i( w, y );  glVertex2i( w, h );  glVertex2i( x, h );
 
1045
  glEnd();
 
1046
 
 
1047
  glColor3d( .5, .5, .5 );
 
1048
  glBegin( GL_LINE_STRIP );
 
1049
  glVertex2i( w-1, y+1 );  glVertex2i( w-1, h-1 );  glVertex2i( x+1, h-1 );
 
1050
  glEnd();
 
1051
}
 
1052
 
 
1053
 
 
1054
/************************************ GLUI_Main::draw_lowered_box() **********/
 
1055
/* Not quite perfect...      **/
 
1056
 
 
1057
void      GLUI_Main::draw_lowered_box( int x, int y, int w, int h )
 
1058
{
 
1059
  w = w+x;
 
1060
  h = h+y;
 
1061
 
 
1062
  glColor3ub( bkgd_color.r, bkgd_color.g, bkgd_color.b );
 
1063
  glBegin( GL_LINE_LOOP );
 
1064
  glVertex2i( x+1, y+1 );         glVertex2i( w-1, y+1 );
 
1065
  glVertex2i( w-1, h-1 );     glVertex2i( x+1, h-1 );
 
1066
  glEnd();
 
1067
 
 
1068
  glColor3d( 0.0, 0.0, 0.0 );
 
1069
  glBegin( GL_LINE_STRIP );
 
1070
  glVertex2i( x, h );  glVertex2i( x, y );  glVertex2i( w, y );
 
1071
  glEnd();
 
1072
 
 
1073
  glColor3d( 1.0, 1.0, 1.0 );
 
1074
  glBegin( GL_LINE_STRIP );
 
1075
  glVertex2i( w, y );  glVertex2i( w, h );  glVertex2i( x, h );
 
1076
  glEnd();
 
1077
 
 
1078
  glColor3d( .5, .5, .5 );
 
1079
  glBegin( GL_LINE_STRIP );
 
1080
  glVertex2i( w-1, y+1 );  glVertex2i( w-1, h-1 );  glVertex2i( x+1, h-1 );
 
1081
  glEnd();
 
1082
}
 
1083
 
 
1084
 
 
1085
/************************************* GLUI_Main::activate_control() *********/
 
1086
 
 
1087
void         GLUI_Main::activate_control( GLUI_Control *control, int how )
 
1088
{
 
1089
  /** Are we not activating a control in the same window as the
 
1090
    previous active control? */
 
1091
  if ( GLUI_Master.active_control_glui AND
 
1092
       this != (GLUI_Main*) GLUI_Master.active_control_glui ) {
 
1093
    GLUI_Master.active_control_glui->disactivate_current_control();
 
1094
  }
 
1095
 
 
1096
  /*******      Now activate it      *****/
 
1097
  if ( control != NULL AND control->can_activate AND control->enabled ) {
 
1098
    active_control = control;
 
1099
    
 
1100
    control->activate(how);
 
1101
 
 
1102
    /*if ( NOT active_control->is_container OR           */
 
1103
    /*          active_control->type == GLUI_CONTROL_ROLLOUT) {          */
 
1104
    active_control->translate_and_draw_front();
 
1105
    /*}          */
 
1106
  }
 
1107
  else {
 
1108
    active_control = NULL;
 
1109
  }
 
1110
 
 
1111
  /*  printf( "activate: %d\n", glutGetWindow() );          */
 
1112
  GLUI_Master.active_control      = active_control;
 
1113
  GLUI_Master.active_control_glui = (GLUI*) this;
 
1114
}
 
1115
 
 
1116
 
 
1117
/************************* GLUI_Main::disactivate_current_control() **********/
 
1118
 
 
1119
void         GLUI_Main::disactivate_current_control( void )
 
1120
{
 
1121
  int orig;
 
1122
 
 
1123
  if ( active_control != NULL ) {
 
1124
    orig = active_control->set_to_glut_window();
 
1125
 
 
1126
    active_control->disactivate();
 
1127
    
 
1128
    /** If this isn't a container control, then redraw it in its 
 
1129
      disactivated state.  Container controls, such as panels, look
 
1130
      the same activated or not **/
 
1131
 
 
1132
    /*if ( NOT active_control->is_container OR           */
 
1133
    /*          active_control->type == GLUI_CONTROL_ROLLOUT ) {        */
 
1134
    active_control->translate_and_draw_front();
 
1135
    /*}          */
 
1136
 
 
1137
    active_control->restore_window( orig );
 
1138
 
 
1139
    active_control = NULL;
 
1140
  }
 
1141
 
 
1142
  /*  printf( "disactivate: %d\n", glutGetWindow() );          */
 
1143
  GLUI_Master.active_control      = NULL;
 
1144
  GLUI_Master.active_control_glui = NULL;
 
1145
}
 
1146
 
 
1147
 
 
1148
/****************************** GLUI_Main::find_next_control() **************/
 
1149
 
 
1150
GLUI_Control  *GLUI_Main::find_next_control_( GLUI_Control *control )
 
1151
{
 
1152
  /*** THIS IS NOT find_next_control()!  This is an unused older
 
1153
    version (look at the underscore at the end) ***/
 
1154
 
 
1155
  if ( control == NULL )
 
1156
    return find_next_control_rec( main_panel );
 
1157
  else
 
1158
    return find_next_control_rec( control );
 
1159
}
 
1160
 
 
1161
/****************************** GLUI_Main::find_next_control() **************/
 
1162
 
 
1163
GLUI_Control  *GLUI_Main::find_next_control_rec( GLUI_Control *control )
 
1164
{
 
1165
  GLUI_Control *child = NULL, *rec_control, *sibling;
 
1166
 
 
1167
  /*** Recursively investigate children ***/
 
1168
  child = (GLUI_Control*) control->first_child();
 
1169
  if ( child ) {
 
1170
    /*** If we can activate the first child, then do so ***/
 
1171
    if ( child->can_activate AND child->enabled )
 
1172
      return child;
 
1173
    else     /*** Recurse into first child ***/
 
1174
      rec_control = find_next_control_rec( child );    
 
1175
 
 
1176
    if ( rec_control )
 
1177
      return rec_control;
 
1178
  }
 
1179
 
 
1180
  /*** At this point, either we don't have children, or the child cannot
 
1181
    be activated.  So let's try the next sibling ***/
 
1182
 
 
1183
  sibling = (GLUI_Control*) control->next();
 
1184
  if ( sibling ) {
 
1185
    if ( sibling->can_activate AND sibling->enabled )
 
1186
      return sibling;
 
1187
    else     /*** Recurse into sibling ***/
 
1188
      rec_control = find_next_control_rec( sibling );    
 
1189
 
 
1190
    if ( rec_control )
 
1191
      return rec_control;
 
1192
  }
 
1193
  
 
1194
  return NULL;
 
1195
}
 
1196
 
 
1197
 
 
1198
/****************************** GLUI_Main::find_next_control() **************/
 
1199
 
 
1200
GLUI_Control  *GLUI_Main::find_next_control( GLUI_Control *control )
 
1201
{
 
1202
  GLUI_Control *tmp_control = NULL;
 
1203
  int           back_up;
 
1204
  
 
1205
  if ( control == NULL )
 
1206
    control = main_panel;
 
1207
 
 
1208
  while( control != NULL ) {
 
1209
    /** see if this control has a child **/
 
1210
    tmp_control = (GLUI_Control*) control->first_child();
 
1211
 
 
1212
    if ( tmp_control != NULL ) {
 
1213
      if ( tmp_control->can_activate AND tmp_control->enabled )
 
1214
        return tmp_control;
 
1215
      
 
1216
      control = tmp_control;  /* Descend into child */
 
1217
      continue;
 
1218
    }
 
1219
    
 
1220
    /*** At this point, control has no children ***/
 
1221
 
 
1222
    /** see if this control has a next sibling **/
 
1223
    tmp_control = (GLUI_Control*) control->next();
 
1224
    
 
1225
    if ( tmp_control != NULL ) {
 
1226
      if ( tmp_control->can_activate AND tmp_control->enabled )
 
1227
        return tmp_control;
 
1228
      
 
1229
      control = tmp_control;  
 
1230
      continue;
 
1231
    }
 
1232
 
 
1233
    /** back up until we find a sibling of an ancestor **/
 
1234
    back_up = true;
 
1235
    while ( control->parent() AND back_up ) {
 
1236
      control = (GLUI_Control*) control->parent();
 
1237
 
 
1238
      if ( control->next() ) {
 
1239
        control = (GLUI_Control*) control->next();  
 
1240
        if ( control->can_activate AND control->enabled )
 
1241
          return control;
 
1242
        else
 
1243
          back_up = false;
 
1244
 
 
1245
        /***    if ( control->is_container ) {
 
1246
          tmp_control = control;
 
1247
          control     = NULL;
 
1248
          break;
 
1249
          }
 
1250
          else {
 
1251
          back_up = false;
 
1252
          }
 
1253
          ***/
 
1254
      }
 
1255
    }
 
1256
 
 
1257
    /** Check if we've cycled back to the top... if so, return NULL **/
 
1258
    if ( control == main_panel ) {
 
1259
      return NULL;
 
1260
    }
 
1261
  }
 
1262
  /*
 
1263
    if ( tmp_control != NULL AND tmp_control->can_activate AND
 
1264
    tmp_control->enabled ) {
 
1265
    return tmp_control;
 
1266
    }*/
 
1267
 
 
1268
  return NULL;
 
1269
}
 
1270
 
 
1271
 
 
1272
/****************************** GLUI_Main::find_prev_control() **************/
 
1273
 
 
1274
GLUI_Control  *GLUI_Main::find_prev_control( GLUI_Control *control )
 
1275
{
 
1276
  GLUI_Control *tmp_control, *next_control;
 
1277
 
 
1278
  if ( control == NULL ) {        /* here we find the last valid control */
 
1279
    next_control = main_panel;
 
1280
  
 
1281
    do {
 
1282
      tmp_control  = next_control;
 
1283
      next_control = find_next_control( tmp_control ); 
 
1284
    } while( next_control != NULL );
 
1285
 
 
1286
    return tmp_control;    
 
1287
  }
 
1288
  else {                         /* here we find the actual previous control */
 
1289
    next_control = main_panel;
 
1290
  
 
1291
    do {
 
1292
      tmp_control  = next_control;
 
1293
      next_control = find_next_control( tmp_control ); 
 
1294
    } while( next_control != NULL AND next_control != control );
 
1295
    
 
1296
    if ( next_control == NULL OR tmp_control == main_panel )
 
1297
      return NULL;
 
1298
    else 
 
1299
      return tmp_control;
 
1300
  }
 
1301
}
 
1302
 
 
1303
/************************* GLUI_Master_Object::set_glutIdleFunc() ***********/
 
1304
 
 
1305
void    GLUI_Master_Object::set_glutIdleFunc(void (*f)(void))
 
1306
{
 
1307
  glut_idle_CB = f;
 
1308
  glutIdleFunc( glui_idle_func );
 
1309
}
 
1310
 
 
1311
 
 
1312
/**************************************** GLUI::disable() ********************/
 
1313
 
 
1314
void   GLUI::disable( void )
 
1315
 
1316
  disactivate_current_control();
 
1317
  main_panel->disable(); 
 
1318
}
 
1319
 
 
1320
 
 
1321
/******************************************** GLUI::sync_live() **************/
 
1322
 
 
1323
void   GLUI::sync_live( void )
 
1324
{
 
1325
  main_panel->sync_live(true, true);
 
1326
}
 
1327
 
 
1328
 
 
1329
/********************************* GLUI_Master_Object::sync_live_all() *****/
 
1330
 
 
1331
void   GLUI_Master_Object::sync_live_all( void ) 
 
1332
{
 
1333
  GLUI *glui;
 
1334
 
 
1335
  glui = (GLUI*) GLUI_Master.gluis.first_child();
 
1336
  while( glui ) {
 
1337
   
 
1338
    glui->sync_live();  /** sync it **/
 
1339
 
 
1340
    glui = (GLUI*) glui->next();
 
1341
  }  
 
1342
}
 
1343
 
 
1344
 
 
1345
/************************************* GLUI_Master_Object::close() **********/
 
1346
 
 
1347
void   GLUI_Master_Object::close_all( void ) 
 
1348
{
 
1349
  GLUI *glui;
 
1350
 
 
1351
  glui = (GLUI*) GLUI_Master.gluis.first_child();
 
1352
  while( glui ) {
 
1353
   
 
1354
    glui->close();  /** Set flag to close **/
 
1355
 
 
1356
    glui = (GLUI*) glui->next();
 
1357
  }  
 
1358
}
 
1359
 
 
1360
 
 
1361
/************************************* GLUI_Main::close_internal() **********/
 
1362
 
 
1363
void   GLUI_Main::close_internal( void ) 
 
1364
{
 
1365
  glutDestroyWindow(glutGetWindow()); /** Close this window **/
 
1366
 
 
1367
  this->unlink();
 
1368
  
 
1369
  if ( GLUI_Master.active_control_glui == this ) {
 
1370
    GLUI_Master.active_control      = NULL;
 
1371
    GLUI_Master.active_control_glui = NULL;
 
1372
  }
 
1373
    
 
1374
  if ( parent_window != -1 ) {
 
1375
    glutSetWindow( parent_window );
 
1376
    int win_w = glutGet( GLUT_WINDOW_WIDTH );
 
1377
    int win_h = glutGet( GLUT_WINDOW_HEIGHT );
 
1378
    glutReshapeWindow(win_w+1, win_h);
 
1379
    glutReshapeWindow(win_w-1, win_h);
 
1380
  }
 
1381
 
 
1382
  delete this->main_panel;
 
1383
 
 
1384
  delete this;
 
1385
}
 
1386
 
 
1387
 
 
1388
/************************************************** GLUI::close() **********/
 
1389
 
 
1390
void   GLUI::close( void ) 
 
1391
{
 
1392
  int   old_glut_window;
 
1393
 
 
1394
  closing = true;
 
1395
 
 
1396
  old_glut_window = glutGetWindow();
 
1397
  glutSetWindow( get_glut_window_id() );
 
1398
  glutPostRedisplay();
 
1399
 
 
1400
  glutSetWindow( old_glut_window );
 
1401
}
 
1402
 
 
1403
 
 
1404
/************************** GLUI_Main::check_subwindow_position() **********/
 
1405
 
 
1406
void   GLUI_Main::check_subwindow_position( void )
 
1407
{
 
1408
  /*** Reposition this window if subwindow ***/
 
1409
  if ( TEST_AND( this->flags, GLUI_SUBWINDOW ) ) {
 
1410
 
 
1411
    int parent_w, parent_h, new_x, new_y;
 
1412
    int old_window = glutGetWindow();
 
1413
 
 
1414
    glutSetWindow( glut_window_id );
 
1415
 
 
1416
    glutSetWindow( glutGet( GLUT_WINDOW_PARENT ));
 
1417
    parent_w = glutGet( GLUT_WINDOW_WIDTH );
 
1418
    parent_h = glutGet( GLUT_WINDOW_HEIGHT );
 
1419
 
 
1420
    glutSetWindow( glut_window_id );
 
1421
 
 
1422
    if ( TEST_AND(this->flags,GLUI_SUBWINDOW_RIGHT )) {
 
1423
      new_x = parent_w - this->w;
 
1424
      new_y = 0;
 
1425
    } 
 
1426
    else if ( TEST_AND(this->flags,GLUI_SUBWINDOW_LEFT )) {
 
1427
      new_x = 0;
 
1428
      new_y = 0;
 
1429
    } 
 
1430
    else if ( TEST_AND(this->flags,GLUI_SUBWINDOW_BOTTOM )) {
 
1431
      new_x = 0;
 
1432
      new_y = parent_h - this->h;
 
1433
    } 
 
1434
    else {    /***   GLUI_SUBWINDOW_TOP    ***/
 
1435
      new_x = 0;
 
1436
      new_y = 0;
 
1437
    }
 
1438
 
 
1439
    /** Now make adjustments based on presence of other subwindows **/
 
1440
    GLUI *curr_glui;
 
1441
    curr_glui = (GLUI*) GLUI_Master.gluis.first_child(); 
 
1442
    while( curr_glui ) {
 
1443
      if ( TEST_AND( curr_glui->flags, GLUI_SUBWINDOW) AND 
 
1444
           curr_glui->parent_window == this->parent_window ) {
 
1445
 
 
1446
        if ( TEST_AND( curr_glui->flags,GLUI_SUBWINDOW_LEFT ) ) {
 
1447
        }
 
1448
        else if ( TEST_AND( curr_glui->flags,GLUI_SUBWINDOW_BOTTOM ) ) {
 
1449
        }
 
1450
        else if ( TEST_AND( curr_glui->flags,GLUI_SUBWINDOW_RIGHT ) ) {
 
1451
        }
 
1452
        else if ( TEST_AND( curr_glui->flags,GLUI_SUBWINDOW_TOP ) AND 
 
1453
                  ( TEST_AND( this->flags,GLUI_SUBWINDOW_LEFT ) OR
 
1454
                    TEST_AND( this->flags,GLUI_SUBWINDOW_RIGHT ) ) ) {
 
1455
          /** If we are a RIGHT or LEFT subwindow, and there exists some 
 
1456
            TOP subwindow, bump our position down  **/
 
1457
 
 
1458
          new_y += curr_glui->h;
 
1459
        }
 
1460
 
 
1461
        /** CHeck multiple subwins at same position  **/
 
1462
        /** We check the glui_id's:  only the glui with the higher
 
1463
          ID number (meaning it was created later) gets bumped over **/
 
1464
        if ( curr_glui != this AND this->glui_id > curr_glui->glui_id ) {
 
1465
          if ( TEST_AND( this->flags,GLUI_SUBWINDOW_LEFT ) AND
 
1466
               TEST_AND( curr_glui->flags,GLUI_SUBWINDOW_LEFT ) ) {
 
1467
            new_x += curr_glui->w;
 
1468
          }
 
1469
          else if ( TEST_AND( this->flags,GLUI_SUBWINDOW_TOP ) AND
 
1470
                    TEST_AND( curr_glui->flags,GLUI_SUBWINDOW_TOP ) ) {
 
1471
            new_y += curr_glui->h;
 
1472
          }
 
1473
          else if ( TEST_AND( this->flags,GLUI_SUBWINDOW_BOTTOM ) AND
 
1474
                    TEST_AND( curr_glui->flags,GLUI_SUBWINDOW_BOTTOM ) ) {
 
1475
            new_y -= curr_glui->h;
 
1476
          }
 
1477
          else if ( TEST_AND( this->flags,GLUI_SUBWINDOW_RIGHT ) AND
 
1478
                    TEST_AND( curr_glui->flags,GLUI_SUBWINDOW_RIGHT ) ) {
 
1479
            new_x -= curr_glui->w;
 
1480
          }
 
1481
 
 
1482
        }
 
1483
      }
 
1484
 
 
1485
      curr_glui = (GLUI*) curr_glui->next();
 
1486
    }
 
1487
        
 
1488
 
 
1489
                
 
1490
    CLAMP( new_x, 0, new_x );
 
1491
    CLAMP( new_y, 0, new_y );
 
1492
 
 
1493
    glutPositionWindow( new_x, new_y );
 
1494
    /*          glutPostRedisplay();          */
 
1495
 
 
1496
    glutSetWindow( old_window );
 
1497
  }
 
1498
}
 
1499
 
 
1500
 
 
1501
/********************************* GLUI_Master_Object::reshape() **********/
 
1502
/* This gets called by the user from a GLUT reshape callback.  So we look */
 
1503
/* for subwindows that belong to the current window                   */
 
1504
 
 
1505
void  GLUI_Master_Object::reshape( void )
 
1506
{
 
1507
  GLUI *glui;
 
1508
  int   current_window;
 
1509
 
 
1510
  current_window = glutGetWindow();
 
1511
  
 
1512
  glui = (GLUI*) GLUI_Master.gluis.first_child();
 
1513
  while( glui ) {
 
1514
    if ( TEST_AND( glui->flags, GLUI_SUBWINDOW) AND 
 
1515
         glui->parent_window == current_window ) {
 
1516
      glutSetWindow( glui->get_glut_window_id());
 
1517
      glui->check_subwindow_position();
 
1518
    }
 
1519
    
 
1520
    glui = (GLUI*) glui->next();
 
1521
  }  
 
1522
 
 
1523
  glutSetWindow(current_window);
 
1524
}
 
1525
 
 
1526
 
 
1527
/**************************** GLUI_Master_Object::set_glutReshapeFunc() *****/
 
1528
 
 
1529
void GLUI_Master_Object::set_glutReshapeFunc(void (*f)(int width, int height))
 
1530
{
 
1531
  glutReshapeFunc( glui_reshape_func );
 
1532
  add_cb_to_glut_window( glutGetWindow(), GLUI_GLUT_RESHAPE, (void*) f);
 
1533
}
 
1534
 
 
1535
 
 
1536
/**************************** GLUI_Master_Object::set_glutKeyboardFunc() ****/
 
1537
 
 
1538
void GLUI_Master_Object::set_glutKeyboardFunc(void (*f)(unsigned char key, 
 
1539
                                                        int x, int y))
 
1540
{
 
1541
  glutKeyboardFunc( glui_keyboard_func );
 
1542
  add_cb_to_glut_window( glutGetWindow(), GLUI_GLUT_KEYBOARD, (void*) f);
 
1543
}
 
1544
 
 
1545
 
 
1546
/*********************** GLUI_Master_Object::set_glutSpecialFunc() **********/
 
1547
 
 
1548
void GLUI_Master_Object::set_glutSpecialFunc(void (*f)(int key, 
 
1549
                                                       int x, int y))
 
1550
{
 
1551
  glutSpecialFunc( glui_special_func );
 
1552
  add_cb_to_glut_window( glutGetWindow(), GLUI_GLUT_SPECIAL, (void*) f);
 
1553
}
 
1554
 
 
1555
 
 
1556
/*********************** GLUI_Master_Object::set_glutMouseFunc() **********/
 
1557
 
 
1558
void GLUI_Master_Object::set_glutMouseFunc(void (*f)(int button, int state,
 
1559
                                                     int x, int y))
 
1560
{
 
1561
  glutMouseFunc( glui_mouse_func );
 
1562
  add_cb_to_glut_window( glutGetWindow(), GLUI_GLUT_MOUSE, (void*) f);
 
1563
}
 
1564
 
 
1565
 
 
1566
/****************************** glui_parent_window_reshape_func() **********/
 
1567
/* This is the reshape callback for a window that contains subwindows      */
 
1568
 
 
1569
void glui_parent_window_reshape_func( int w, int h )
 
1570
{
 
1571
  int   current_window;
 
1572
  GLUI  *glui;
 
1573
  int   first = true;
 
1574
 
 
1575
  /*  printf( "glui_parent_window_reshape_func: %d\n", glutGetWindow() );          */
 
1576
 
 
1577
  current_window = glutGetWindow();
 
1578
 
 
1579
  glui = (GLUI*) GLUI_Master.gluis.first_child();
 
1580
  while( glui ) {
 
1581
    if ( TEST_AND( glui->flags, GLUI_SUBWINDOW) AND 
 
1582
         glui->parent_window == current_window ) {
 
1583
      glutSetWindow( glui->get_glut_window_id());
 
1584
      glui->check_subwindow_position();
 
1585
      glutSetWindow( current_window );
 
1586
 
 
1587
      if ( first ) {
 
1588
        glui->glut_reshape_CB( w, h );
 
1589
        
 
1590
        first = false;
 
1591
      }
 
1592
    }
 
1593
    
 
1594
    glui = (GLUI*) glui->next();
 
1595
  }  
 
1596
}
 
1597
 
 
1598
 
 
1599
/****************************** glui_parent_window_keyboard_func() **********/
 
1600
 
 
1601
void glui_parent_window_keyboard_func(unsigned char key, int x, int y)
 
1602
{
 
1603
  /*  printf( "glui_parent_window_keyboard_func: %d\n", glutGetWindow() );          */
 
1604
 
 
1605
  int   current_window;
 
1606
  GLUI  *glui;
 
1607
 
 
1608
  current_window = glutGetWindow();
 
1609
 
 
1610
  if ( GLUI_Master.active_control_glui AND GLUI_Master.active_control ) {
 
1611
    glutSetWindow( GLUI_Master.active_control_glui->get_glut_window_id() );
 
1612
 
 
1613
    GLUI_Master.active_control_glui->keyboard(key,x,y);    
 
1614
 
 
1615
    glutSetWindow( current_window );
 
1616
  }
 
1617
  else {
 
1618
    glui = (GLUI*) GLUI_Master.gluis.first_child();
 
1619
    while( glui ) {
 
1620
      if ( TEST_AND( glui->flags, GLUI_SUBWINDOW) AND 
 
1621
           glui->parent_window == current_window ) {
 
1622
        glui->glut_keyboard_CB( key, x, y );
 
1623
        break;
 
1624
      }
 
1625
        
 
1626
      glui = (GLUI*) glui->next();
 
1627
    }
 
1628
  } 
 
1629
}
 
1630
 
 
1631
 
 
1632
/****************************** glui_parent_window_special_func() **********/
 
1633
 
 
1634
void glui_parent_window_special_func(int key, int x, int y)
 
1635
{
 
1636
  /*printf( "glui_parent_window_special_func: %d\n", glutGetWindow() );          */
 
1637
 
 
1638
  int   current_window;
 
1639
  GLUI  *glui;
 
1640
 
 
1641
  /**  If clicking in the main area of a window w/subwindows, 
 
1642
    disactivate any current control  **/
 
1643
  if ( GLUI_Master.active_control_glui != NULL ) 
 
1644
    GLUI_Master.active_control_glui->disactivate_current_control();
 
1645
 
 
1646
  /***   Now pass on the mouse event   ***/
 
1647
 
 
1648
  current_window = glutGetWindow();
 
1649
 
 
1650
  glui = (GLUI*) GLUI_Master.gluis.first_child();
 
1651
  while( glui ) {
 
1652
    if ( TEST_AND( glui->flags, GLUI_SUBWINDOW) AND 
 
1653
         glui->parent_window == current_window ) {
 
1654
      glutSetWindow( glui->get_glut_window_id());
 
1655
      glui->glut_special_CB( key, x, y );
 
1656
      break;
 
1657
    }
 
1658
    
 
1659
    glui = (GLUI*) glui->next();
 
1660
  }  
 
1661
}
 
1662
 
 
1663
 
 
1664
/****************************** glui_parent_window_mouse_func() **********/
 
1665
 
 
1666
void glui_parent_window_mouse_func(int button, int state, int x, int y)
 
1667
{
 
1668
  int   current_window;
 
1669
  GLUI  *glui;
 
1670
 
 
1671
  /**  If clicking in the main area of a window w/subwindows, 
 
1672
    disactivate any current control  **/
 
1673
  if ( GLUI_Master.active_control_glui != NULL ) 
 
1674
    GLUI_Master.active_control_glui->disactivate_current_control();
 
1675
 
 
1676
 
 
1677
  /***   Now pass on the mouse event   ***/
 
1678
 
 
1679
  current_window = glutGetWindow();
 
1680
 
 
1681
  glui = (GLUI*) GLUI_Master.gluis.first_child();
 
1682
  while( glui ) {
 
1683
    if ( TEST_AND( glui->flags, GLUI_SUBWINDOW) AND 
 
1684
         glui->parent_window == current_window ) {
 
1685
      glutSetWindow( glui->get_glut_window_id());
 
1686
      glui->glut_mouse_CB( button, state, x, y );
 
1687
      break;
 
1688
    }
 
1689
    
 
1690
    glui = (GLUI*) glui->next();
 
1691
  }  
 
1692
  
 
1693
}
 
1694
 
 
1695
 
 
1696
/************************** GLUI_Master_Object::find_glut_window() **********/
 
1697
 
 
1698
GLUI_Glut_Window  *GLUI_Master_Object::find_glut_window( int window_id )
 
1699
{
 
1700
  GLUI_Glut_Window *window;
 
1701
 
 
1702
  window = (GLUI_Glut_Window*) glut_windows.first_child();
 
1703
  while( window ) {
 
1704
    if ( window->glut_window_id == window_id ) 
 
1705
      return window;
 
1706
    
 
1707
    window = (GLUI_Glut_Window*) window->next();
 
1708
  }
 
1709
 
 
1710
  /***  Window not found - return NULL ***/
 
1711
  return NULL;
 
1712
}
 
1713
 
 
1714
 
 
1715
/******************** GLUI_Master_Object::add_cb_to_glut_window() **********/
 
1716
 
 
1717
void     GLUI_Master_Object::add_cb_to_glut_window(int window_id,
 
1718
                                                   int cb_type,void *cb)
 
1719
{
 
1720
  GLUI_Glut_Window *window;
 
1721
 
 
1722
  window = find_glut_window( window_id );
 
1723
  if ( NOT window ) {
 
1724
    /***  Allocate new window structure  ***/
 
1725
    
 
1726
    window                 = new GLUI_Glut_Window;
 
1727
    window->glut_window_id = window_id;
 
1728
    window->link_this_to_parent_last( (GLUI_Node*) &this->glut_windows );
 
1729
  }
 
1730
 
 
1731
  switch( cb_type ) {
 
1732
  case GLUI_GLUT_RESHAPE:
 
1733
    window->glut_reshape_CB   = (void(*)(int,int)) cb;
 
1734
    break;
 
1735
  case GLUI_GLUT_DISPLAY:
 
1736
    window->glut_display_CB   = (void(*)()) cb;
 
1737
    break;
 
1738
  case GLUI_GLUT_KEYBOARD:
 
1739
    window->glut_keyboard_CB  = (void(*)(unsigned char,int,int)) cb;
 
1740
    break;
 
1741
  case GLUI_GLUT_SPECIAL:
 
1742
    window->glut_special_CB   = (void(*)(int,int,int)) cb;
 
1743
    break;
 
1744
  case GLUI_GLUT_MOUSE:
 
1745
    window->glut_mouse_CB     = (void(*)(int,int,int,int)) cb;
 
1746
    break;
 
1747
  case GLUI_GLUT_MOTION:
 
1748
    window->glut_motion_CB    = (void(*)(int,int)) cb;
 
1749
    break;
 
1750
  case GLUI_GLUT_PASSIVE_MOTION:
 
1751
    window->glut_passive_motion_CB = (void(*)(int,int)) cb;
 
1752
    break;
 
1753
  case GLUI_GLUT_ENTRY:
 
1754
    window->glut_entry_CB     = (void(*)(int)) cb;
 
1755
    break;
 
1756
  case GLUI_GLUT_VISIBILITY:
 
1757
    window->glut_visibility_CB= (void(*)(int)) cb;
 
1758
    break;
 
1759
  }
 
1760
}
 
1761
 
 
1762
 
 
1763
/************* GLUI_Master_Object::set_left_button_glut_menu_control() *****/
 
1764
 
 
1765
void  GLUI_Master_Object::set_left_button_glut_menu_control( 
 
1766
                                                            GLUI_Control *control )
 
1767
{
 
1768
  curr_left_button_glut_menu = control;
 
1769
}
 
1770
 
 
1771
 
 
1772
/******************************* GLUI_Main::set_ortho_projection() **********/
 
1773
 
 
1774
void  GLUI_Main::set_ortho_projection( void )
 
1775
{
 
1776
  int win_h, win_w;
 
1777
 
 
1778
  win_w = glutGet( GLUT_WINDOW_WIDTH );
 
1779
  win_h = glutGet( GLUT_WINDOW_HEIGHT );
 
1780
 
 
1781
  glMatrixMode( GL_PROJECTION );
 
1782
  glLoadIdentity();
 
1783
  /*  gluOrtho2D( 0.0, (float) win_w, 0.0, (float) win_h );          */
 
1784
  glOrtho( 0.0, (float)win_w, 0.0, (float) win_h, -1000.0, 1000.0 );
 
1785
 
 
1786
  glMatrixMode( GL_MODELVIEW );
 
1787
 
 
1788
  return; /****-----------------------------------------------***/
 
1789
 
 
1790
  glMatrixMode( GL_MODELVIEW );
 
1791
  glLoadIdentity();
 
1792
 
 
1793
  /*** Rotate image so y increases upwards, contrary to OpenGL axes ***/
 
1794
  glTranslatef( (float) win_w/2.0, (float) win_h/2.0, 0.0 );
 
1795
  glRotatef( 180.0, 0.0, 1.0, 0.0 );
 
1796
  glRotatef( 180.0, 0.0, 0.0, 1.0 );
 
1797
  glTranslatef( (float) -win_w/2.0, (float) -win_h/2.0, 0.0 );
 
1798
}
 
1799
 
 
1800
 
 
1801
/******************************* GLUI_Main::set_viewport() **********/
 
1802
 
 
1803
void  GLUI_Main::set_viewport( void )
 
1804
{
 
1805
  glViewport( 0, 0, main_panel->w, main_panel->h );
 
1806
}
 
1807
 
 
1808
 
 
1809
/****************************** GLUI_Main::refresh() ****************/
 
1810
 
 
1811
void    GLUI_Main::refresh( void )
 
1812
{
 
1813
  int orig;
 
1814
  int new_w, new_h;
 
1815
 
 
1816
  /******  GLUI_Glut_Window *glut_window;
 
1817
    int              current_window;
 
1818
    current_window = glutGetWindow();
 
1819
    glut_window    = GLUI_Master.find_glut_window( current_window );
 
1820
    if ( glut_window ) {
 
1821
    glut_window->glut_reshape_CB(w,h);
 
1822
    ******/
 
1823
 
 
1824
  orig  = glutGetWindow();
 
1825
 
 
1826
  pack_controls();
 
1827
 
 
1828
  if ( TEST_AND( this->flags, GLUI_SUBWINDOW ) ) {
 
1829
    /*** GLUI subwindow ***/
 
1830
 
 
1831
    check_subwindow_position();
 
1832
 
 
1833
    if ( glut_window_id > 0 )
 
1834
      glutSetWindow( glut_window_id );
 
1835
    glutPostRedisplay();
 
1836
 
 
1837
    /*  printf( "top_level: %d\n", top_level_glut_window_id );*/
 
1838
    glutSetWindow( top_level_glut_window_id );
 
1839
  }
 
1840
  else {
 
1841
    /*** Standalone GLUI window ***/
 
1842
 
 
1843
    if ( glut_window_id > 0 )
 
1844
      glutSetWindow( glut_window_id );
 
1845
  
 
1846
    new_h = glutGet( GLUT_WINDOW_HEIGHT );
 
1847
    new_w = glutGet( GLUT_WINDOW_WIDTH );
 
1848
    
 
1849
    new_h = this->h;
 
1850
    new_w = this->w;
 
1851
 
 
1852
    glutReshapeWindow( new_w, new_h );
 
1853
 
 
1854
    glutPostRedisplay();
 
1855
  }
 
1856
 
 
1857
  glutSetWindow( orig);
 
1858
}
 
1859
 
 
1860
 
 
1861
 
 
1862
/***************** GLUI_Master_Object::get_main_gfx_viewport() ***********/
 
1863
 
 
1864
void     GLUI_Master_Object::get_viewport_area( int *x, int *y, 
 
1865
                                                int *w, int *h )
 
1866
{
 
1867
  GLUI *curr_glui;
 
1868
  int   curr_x, curr_y, curr_w, curr_h;
 
1869
  int   curr_window;
 
1870
 
 
1871
  curr_window = glutGetWindow();
 
1872
  curr_x = 0;
 
1873
  curr_y = 0;
 
1874
  curr_w = glutGet( GLUT_WINDOW_WIDTH );
 
1875
  curr_h = glutGet( GLUT_WINDOW_HEIGHT );
 
1876
 
 
1877
  curr_glui = (GLUI*) gluis.first_child(); 
 
1878
  while( curr_glui ) {
 
1879
    if ( TEST_AND( curr_glui->flags, GLUI_SUBWINDOW) AND 
 
1880
         curr_glui->parent_window == curr_window ) {
 
1881
 
 
1882
      /*                        printf( "%s -> %d   %d %d\n", curr_glui->window_name.string, curr_glui->flags,
 
1883
                                curr_glui->w, curr_glui->h );*/
 
1884
 
 
1885
      if ( TEST_AND( curr_glui->flags,GLUI_SUBWINDOW_LEFT ) ) {
 
1886
        curr_x += curr_glui->w;
 
1887
        curr_w -= curr_glui->w;
 
1888
      }
 
1889
      else if ( TEST_AND( curr_glui->flags,GLUI_SUBWINDOW_BOTTOM ) ) {
 
1890
        curr_y += curr_glui->h;
 
1891
        curr_h -= curr_glui->h;
 
1892
      }
 
1893
      else if ( TEST_AND( curr_glui->flags,GLUI_SUBWINDOW_RIGHT ) ) {
 
1894
        curr_w -= curr_glui->w;
 
1895
      }
 
1896
      else if ( TEST_AND( curr_glui->flags,GLUI_SUBWINDOW_TOP ) ) {
 
1897
        curr_h -= curr_glui->h;
 
1898
      }
 
1899
    }
 
1900
 
 
1901
    curr_glui = (GLUI*) curr_glui->next();
 
1902
  }
 
1903
 
 
1904
  curr_x = MAX( 0, curr_x );
 
1905
  curr_y = MAX( 0, curr_y );
 
1906
  curr_w = MAX( 0, curr_w );
 
1907
  curr_h = MAX( 0, curr_h );
 
1908
 
 
1909
  *x = curr_x;
 
1910
  *y = curr_y;
 
1911
  *w = curr_w;
 
1912
  *h = curr_h;
 
1913
}
 
1914
 
 
1915
 
 
1916
/*****************GLUI_Master_Object::auto_set_main_gfx_viewport() **********/
 
1917
 
 
1918
void           GLUI_Master_Object::auto_set_viewport( void )
 
1919
{
 
1920
  int x, y, w, h;
 
1921
 
 
1922
  get_viewport_area( &x, &y, &w, &h );
 
1923
  glViewport( MAX(x,0), MAX(y,0), MAX(w,0), MAX(h,0) );
 
1924
}
 
1925
 
 
1926
 
 
1927
 
 
1928
/***************************************** GLUI::show() **********************/
 
1929
 
 
1930
void            GLUI::show( void )
 
1931
{
 
1932
  int orig_window;
 
1933
 
 
1934
  orig_window = main_panel->set_to_glut_window();
 
1935
 
 
1936
  glutShowWindow();
 
1937
 
 
1938
  main_panel->restore_window(orig_window);
 
1939
}
 
1940
 
 
1941
 
 
1942
 
 
1943
/***************************************** GLUI::hide() **********************/
 
1944
 
 
1945
void            GLUI::hide( void )
 
1946
{
 
1947
  int orig_window;
 
1948
 
 
1949
  this->disactivate_current_control();
 
1950
 
 
1951
  orig_window = main_panel->set_to_glut_window();
 
1952
 
 
1953
  glutHideWindow();
 
1954
 
 
1955
  main_panel->restore_window(orig_window);
 
1956
}