]> git.mxchange.org Git - flightgear.git/blob - PUI/pu.h
Pui -> PUI.
[flightgear.git] / PUI / pu.h
1 #ifndef _PU_H_
2 #define _PU_H_
3
4 #ifdef HAVE_CONFIG_H
5 #  include <config.h>
6 #endif
7
8 #ifdef HAVE_WINDOWS_H
9 #  include <windows.h>
10 #endif
11
12 #include <stdlib.h>
13 #include <stdio.h>
14 #include <string.h>
15 #include <GL/glut.h>
16
17 #ifndef TRUE
18 #define TRUE  1
19 #define FALSE 0
20 #endif
21
22 /*
23   Webster's Dictionary (for American English) permits
24   Color or Colour as acceptable spellings - but
25   The Oxford English Dictionary (for English) only
26   permits Colour.
27
28   Hence, the logical thing to do is to use 'colour',
29   which *ought* to be acceptable on both sides of
30   the atlantic.
31
32   However, as a concession to the illogical:
33 */
34
35 #define setColorScheme          setColourScheme
36 #define setColor                setColour
37 #define getColor                getColour
38 #define puColor                 puColour
39 #define puSetColor              puSetColour
40 #define puSetDefaultColorScheme puSetDefaultColourScheme
41 #define puGetDefaultColorScheme puGetDefaultColourScheme
42
43
44 typedef void *puFont ;
45
46 #define PUFONT_8_BY_13        GLUT_BITMAP_8_BY_13
47 #define PUFONT_9_BY_15        GLUT_BITMAP_9_BY_15
48 #define PUFONT_TIMES_ROMAN_10 GLUT_BITMAP_TIMES_ROMAN_10
49 #define PUFONT_TIMES_ROMAN_24 GLUT_BITMAP_TIMES_ROMAN_24
50 #define PUFONT_HELVETICA_10   GLUT_BITMAP_HELVETICA_10
51 #define PUFONT_HELVETICA_12   GLUT_BITMAP_HELVETICA_12
52 #define PUFONT_HELVETICA_18   GLUT_BITMAP_HELVETICA_18
53
54 #define PU_LEFT_BUTTON   GLUT_LEFT_BUTTON
55 #define PU_MIDDLE_BUTTON GLUT_MIDDLE_BUTTON
56 #define PU_RIGHT_BUTTON  GLUT_RIGHT_BUTTON
57 #define PU_DOWN          GLUT_DOWN
58 #define PU_UP            GLUT_UP
59 #define PU_UP_AND_DOWN   254
60 #define PU_DRAG          255
61 #define PU_CONTINUAL     PU_DRAG
62
63 #define PU_KEY_GLUT_SPECIAL_OFFSET  256
64 #define PU_KEY_F1        (GLUT_KEY_F1        + PU_KEY_GLUT_SPECIAL_OFFSET)
65 #define PU_KEY_F2        (GLUT_KEY_F2        + PU_KEY_GLUT_SPECIAL_OFFSET)
66 #define PU_KEY_F3        (GLUT_KEY_F3        + PU_KEY_GLUT_SPECIAL_OFFSET)
67 #define PU_KEY_F4        (GLUT_KEY_F4        + PU_KEY_GLUT_SPECIAL_OFFSET)
68 #define PU_KEY_F5        (GLUT_KEY_F5        + PU_KEY_GLUT_SPECIAL_OFFSET)
69 #define PU_KEY_F6        (GLUT_KEY_F6        + PU_KEY_GLUT_SPECIAL_OFFSET)
70 #define PU_KEY_F7        (GLUT_KEY_F7        + PU_KEY_GLUT_SPECIAL_OFFSET)
71 #define PU_KEY_F8        (GLUT_KEY_F8        + PU_KEY_GLUT_SPECIAL_OFFSET)
72 #define PU_KEY_F9        (GLUT_KEY_F9        + PU_KEY_GLUT_SPECIAL_OFFSET)
73 #define PU_KEY_F10       (GLUT_KEY_F10       + PU_KEY_GLUT_SPECIAL_OFFSET)
74 #define PU_KEY_F11       (GLUT_KEY_F11       + PU_KEY_GLUT_SPECIAL_OFFSET)
75 #define PU_KEY_F12       (GLUT_KEY_F12       + PU_KEY_GLUT_SPECIAL_OFFSET)
76 #define PU_KEY_LEFT      (GLUT_KEY_LEFT      + PU_KEY_GLUT_SPECIAL_OFFSET)
77 #define PU_KEY_UP        (GLUT_KEY_UP        + PU_KEY_GLUT_SPECIAL_OFFSET)
78 #define PU_KEY_RIGHT     (GLUT_KEY_RIGHT     + PU_KEY_GLUT_SPECIAL_OFFSET)
79 #define PU_KEY_DOWN      (GLUT_KEY_DOWN      + PU_KEY_GLUT_SPECIAL_OFFSET)
80 #define PU_KEY_PAGE_UP   (GLUT_KEY_PAGE_UP   + PU_KEY_GLUT_SPECIAL_OFFSET)
81 #define PU_KEY_PAGE_DOWN (GLUT_KEY_PAGE_DOWN + PU_KEY_GLUT_SPECIAL_OFFSET)
82 #define PU_KEY_HOME      (GLUT_KEY_HOME      + PU_KEY_GLUT_SPECIAL_OFFSET)
83 #define PU_KEY_END       (GLUT_KEY_END       + PU_KEY_GLUT_SPECIAL_OFFSET)
84 #define PU_KEY_INSERT    (GLUT_KEY_INSERT    + PU_KEY_GLUT_SPECIAL_OFFSET)
85
86 #define PUPLACE_DEFAULT  PUPLACE_RIGHT
87 #define PUPLACE_ABOVE    0
88 #define PUPLACE_BELOW    1
89 #define PUPLACE_LEFT     2
90 #define PUPLACE_RIGHT    3
91
92 #define PUCOL_FOREGROUND 0
93 #define PUCOL_BACKGROUND 1
94 #define PUCOL_HIGHLIGHT  2
95 #define PUCOL_LABEL      3
96 #define PUCOL_LEGEND     4
97 #define PUCOL_MAX        5
98
99 #define PUSLIDER_CLICK   0
100 #define PUSLIDER_ALWAYS  1
101 #define PUSLIDER_DELTA   2
102
103 /* These styles may be negated to get 'highlighted' graphics */
104
105 #define PUSTYLE_DEFAULT    PUSTYLE_BEVELLED
106 #define PUSTYLE_NONE       0
107 #define PUSTYLE_PLAIN      1
108 #define PUSTYLE_BEVELLED   2
109 #define PUSTYLE_BOXED      3
110 #define PUSTYLE_DROPSHADOW 4
111 #define PUSTYLE_SPECIAL_UNDERLINED 5
112 #define PUSTYLE_SMALL_BEVELLED     6
113 #define PUSTYLE_RADIO      7
114 #define PUSTYLE_MAX        8
115
116 /* These are the gaps that we try to leave around text objects */
117
118 #define PUSTR_TGAP   5
119 #define PUSTR_BGAP   5
120 #define PUSTR_LGAP   5
121 #define PUSTR_RGAP   5
122 #define PUSTR_MAX_HEIGHT  ( 25 + PUSTR_TGAP + PUSTR_BGAP )
123
124 #define PU_RADIO_BUTTON_SIZE 16
125
126 extern int puRefresh ;
127
128 #define PUCLASS_VALUE            0x00000001
129 #define PUCLASS_OBJECT           0x00000002
130 #define PUCLASS_INTERFACE        0x00000004
131 #define PUCLASS_FRAME            0x00000008
132 #define PUCLASS_TEXT             0x00000010
133 #define PUCLASS_BUTTON           0x00000020
134 #define PUCLASS_ONESHOT          0x00000040
135 #define PUCLASS_POPUP            0x00000080
136 #define PUCLASS_POPUPMENU        0x00000100
137 #define PUCLASS_MENUBAR          0x00000200
138 #define PUCLASS_INPUT            0x00000400
139 #define PUCLASS_BUTTONBOX        0x00000800
140 #define PUCLASS_SLIDER           0x00001000
141 #define PUCLASS_DIALOGBOX        0x00002000
142
143 class puValue            ;
144 class puObject           ;
145 class puInterface        ;
146 class puButtonBox        ;
147 class puFrame            ;
148 class puText             ;
149 class puButton           ;
150 class puOneShot          ;
151 class puPopup            ;
152 class puPopupMenu        ;
153 class puMenuBar          ;
154 class puInput            ;
155 class puSlider           ;
156
157 typedef float puColour [ 4 ] ;  /* RGBA */
158
159 struct puBox
160 {
161   int min [ 2 ] ;
162   int max [ 2 ] ;
163
164   void draw   ( int dx, int dy, int style, puColour colour[], int am_default ) ;
165   void extend ( puBox *bx ) ;
166
167   void empty   ( void ) { min[0]=min[1]=1000000 ; max[0]=max[1]=-1000000 ; }
168   int  isEmpty ( void ) { return min[0]>max[0] || min[1]>max[1] ; }
169 } ;
170
171 #define PUSTRING_MAX 80
172
173 /* If you change - or add to these, be sure to change _puDefaultColourTable */
174
175 extern puColour _puDefaultColourTable[] ;
176
177
178 inline void puSetColour ( puColour dst, puColour src )
179 {
180   dst[0] = src[0] ; dst[1] = src[1] ; dst[2] = src[2] ; dst[3] = src[3] ;
181 }
182
183 inline void puSetColour ( puColour c, float r, float g, float b, float a = 1.0f )
184 {
185   c [ 0 ] = r ; c [ 1 ] = g ; c [ 2 ] = b ; c [ 3 ] = a ;
186 }
187
188
189 void  puInit           ( void ) ;
190 void  puDisplay        ( void ) ;
191 int   puMouse          ( int button, int updown, int x, int y ) ;
192 int   puMouse          ( int x, int y ) ;
193 int   puKeyboard       ( int key, int updown ) ;
194 void  puHideCursor     ( void ) ;
195 void  puShowCursor     ( void ) ;
196 int   puCursorIsHidden ( void ) ;
197
198 void puDrawString         ( puFont fnt, char *str, int x, int y ) ;
199 int  puGetStringWidth     ( puFont fnt, char *str ) ;
200 int  puGetStringHeight    ( puFont fnt = NULL ) ;
201 int  puGetStringDescender ( puFont fnt = NULL ) ;
202
203 class puValue
204 {
205 protected:
206   int   type    ;
207   int   integer ;
208   float floater ;
209   char  string  [ PUSTRING_MAX ] ;
210 public:
211   puValue () { type = PUCLASS_VALUE ; clrValue () ; }
212
213   virtual ~puValue () ;
214
215   int  getType ( void ) { return type ; }
216   char *getTypeString ( void ) ;
217   void clrValue ( void ) { setValue ( "" ) ; }
218
219   void setValue ( puValue *pv )
220   {
221     integer = pv -> integer ;
222     floater = pv -> floater ;
223     strcpy ( string, pv -> string ) ;
224     puRefresh = TRUE ;
225   }
226
227   void setValue ( int   i ) { integer = i ; floater = (float) i ; sprintf ( string, "%d", i ) ; puRefresh = TRUE ; }
228   void setValue ( float f ) { integer = (int) f ; floater = f ; sprintf ( string, "%g", f ) ; puRefresh = TRUE ; }
229   void setValue ( char *s ) { 
230                               if ( s == NULL || s[0] == '\0' )
231                               {
232                                 integer = 0 ;
233                                 floater = 0.0f ;
234                                 s = "" ;
235                               }
236                               else
237                               {
238                                 integer = atoi(s) ;
239                                 floater = atof(s) ;
240
241                                 if ( string != s ) strcpy ( string, s ) ;
242                               }
243                               puRefresh = TRUE ;
244                             }
245
246   void getValue ( int   *i ) { *i = integer ; }
247   void getValue ( float *f ) { *f = floater ; }
248   void getValue ( char **s ) { *s = string  ; }
249   void getValue ( char  *s ) { strcpy ( s, string ) ; }
250
251   int  getValue ( void ) { return integer ; }
252 } ;
253
254 typedef void (*puCallback)(class puObject *) ;
255
256 void puSetDefaultStyle ( int  style ) ;
257 int  puGetDefaultStyle ( void ) ;
258 void puSetDefaultFonts ( puFont  legendFont, puFont  labelFont ) ;
259 void puGetDefaultFonts ( puFont *legendFont, puFont *labelFont ) ;
260 void puSetDefaultColourScheme ( float r, float g, float b, float a = 1.0 ) ;
261 void puGetDefaultColourScheme ( float *r, float *g, float *b, float *a = NULL );
262
263 class puObject : public puValue
264 {
265 protected:
266   puValue default_value ;
267
268   puBox bbox ;   /* Bounding box of entire Object */
269   puBox abox ;   /* Active (clickable) area */
270   puColour colour [ PUCOL_MAX ] ;
271   puInterface *parent ;
272
273   int active_mouse_edge ; /* is it PU_UP or PU_DOWN (or both) that activates this? */
274   int style       ;
275   int visible     ;
276   int active      ;
277   int highlighted ;
278   int am_default  ;
279
280   char *label  ; puFont  labelFont ; int labelPlace ;
281   char *legend ; puFont legendFont ;
282
283   void *user_data ;
284   puCallback cb ;
285
286   virtual void draw_label  ( int dx, int dy ) ;
287   virtual int  isHit ( int x, int y ) { return isVisible() && isActive() &&
288                                                x >= abox.min[0] &&
289                                                x <= abox.max[0] &&
290                                                y >= abox.min[1] &&
291                                                y <= abox.max[1] ; }
292   virtual void doHit ( int button, int updown, int x, int y ) ;
293
294 public:
295    puObject ( int minx, int miny, int maxx, int maxy ) ;
296   ~puObject () ;
297
298   puObject *next ;
299   puObject *prev ;
300  
301   puBox *getBBox ( void ) { return & bbox ; }
302   puBox *getABox ( void ) { return & abox ; }
303
304   void setPosition ( int x, int y )
305   {
306     if ( abox.isEmpty() )
307     {
308       abox.max[0] = abox.min[0] = x ;
309       abox.max[1] = abox.min[1] = y ;
310     }
311     else
312     {
313       abox.max[0] += x - abox.min[0] ;
314       abox.max[1] += y - abox.min[1] ;
315       abox.min[0]  = x ;
316       abox.min[1]  = y ;
317     }
318     recalc_bbox() ; puRefresh = TRUE ;
319   }
320
321   void setSize ( int w, int h )
322   {
323     abox.max[0] = abox.min[0] + w ;
324     abox.max[1] = abox.min[1] + h ;
325     recalc_bbox() ; puRefresh = TRUE ;
326   }
327
328   void getPosition ( int *x, int *y )
329   {
330     if ( abox . isEmpty () )
331     {
332       if ( x ) *x = 0 ;
333       if ( y ) *y = 0 ;
334     }
335     else
336     {
337       if ( x ) *x = abox.min[0] ;
338       if ( y ) *y = abox.min[1] ;
339     }
340   }
341
342   void getSize ( int *w, int *h )
343   {
344     if ( abox . isEmpty () )
345     {
346       if ( w ) *w = 0 ;
347       if ( h ) *h = 0 ;
348     }
349     else
350     {
351       if ( w ) *w = abox.max[0] - abox.min[0] ;
352       if ( h ) *h = abox.max[1] - abox.min[1] ;
353     }
354   }
355
356   virtual void recalc_bbox ( void ) ;
357   virtual int  checkHit ( int button, int updown, int x, int y ) ;
358   virtual int  checkKey ( int key   , int updown ) ;
359   virtual void draw ( int dx, int dy ) = 0 ;
360
361   puInterface *getParent     ( void ) { return parent ; }
362   puObject    *getNextObject ( void ) { return next   ; }
363   puObject    *getPrevObject ( void ) { return prev   ; }
364
365   void       setCallback ( puCallback c ) { cb = c ;    }
366   puCallback getCallback ( void )               { return cb ; }
367   void       invokeCallback ( void ) { if ( cb ) (*cb)(this) ; }
368
369   void  makeReturnDefault ( int def ) { am_default = def ; }
370   int   isReturnDefault   ( void )          { return am_default ; }
371
372   void  setActiveDirn ( int e ) { active_mouse_edge = e ; }
373   int   getActiveDirn ( void ) { return active_mouse_edge ; }
374
375   void  setLegend ( char *l ) { legend = l ; recalc_bbox() ; puRefresh = TRUE ; }
376   char *getLegend ( void ) { return legend ; }
377
378   void  setLegendFont ( puFont f ) { legendFont = f ; recalc_bbox() ; puRefresh = TRUE ; }
379   puFont getLegendFont ( void ) { return legendFont ; }
380
381   void  setLabel ( char *l ) { label = l ; recalc_bbox() ; puRefresh = TRUE ; }
382   char *getLabel ( void ) { return label ; }
383
384   void  setLabelFont ( puFont f ) { labelFont = f ; recalc_bbox() ; puRefresh = TRUE ; }
385   puFont getLabelFont ( void ) { return labelFont ; }
386
387   void  setLabelPlace ( int lp ) { labelPlace = lp ; recalc_bbox() ; puRefresh = TRUE ; }
388   int   getLabelPlace ( void ) { return labelPlace ; }
389
390   void activate   ( void ) { if ( ! active  ) { active  = TRUE  ; puRefresh = TRUE ; } }
391   void greyOut    ( void ) { if (   active  ) { active  = FALSE ; puRefresh = TRUE ; } }
392   int  isActive   ( void ) { return active ; }
393
394   void highlight  ( void ) { if ( ! highlighted ) { highlighted = TRUE  ; puRefresh = TRUE ; } }
395   void lowlight   ( void ) { if (   highlighted ) { highlighted = FALSE ; puRefresh = TRUE ; } }
396   int isHighlighted( void ){ return highlighted ; }
397
398   void reveal     ( void ) { if ( ! visible ) { visible = TRUE  ; puRefresh = TRUE ; } }
399   void hide       ( void ) { if (   visible ) { visible = FALSE ; puRefresh = TRUE ; } }
400   int  isVisible  ( void ) { return visible ; }
401
402   void setStyle ( int which )
403   {
404     style = which ;
405     recalc_bbox () ;
406     puRefresh = TRUE ;
407   }
408
409   int  getStyle ( void ) { return style ; }
410
411   void setColourScheme ( float r, float g, float b, float a = 1.0f ) ;
412
413   void setColour ( int which, float r, float g, float b, float a = 1.0f )
414   {
415     puSetColour ( colour [ which ], r, g, b, a ) ;
416     puRefresh = TRUE ;
417   }
418
419   void getColour ( int which, float *r, float *g, float *b, float *a = NULL )
420   {
421     if ( r ) *r = colour[which][0] ;
422     if ( g ) *g = colour[which][1] ;
423     if ( b ) *b = colour[which][2] ;
424     if ( a ) *a = colour[which][3] ;
425   }
426
427   void  setUserData ( void *data ) { user_data = data ; }
428   void *getUserData ( void )             { return user_data ; }
429
430   void defaultValue ( void ) { setValue ( & default_value ) ; }
431
432   void setDefaultValue ( int    i ) { default_value . setValue ( i ) ; }
433   void setDefaultValue ( float  f ) { default_value . setValue ( f ) ; }
434   void setDefaultValue ( char  *s ) { default_value . setValue ( s ) ; }
435
436   void getDefaultValue ( int   *i ) { default_value . getValue ( i ) ; }
437   void getDefaultValue ( float *f ) { default_value . getValue ( f ) ; }
438   void getDefaultValue ( char **s ) { default_value . getValue ( s ) ; }
439   int  getDefaultValue ( void )    { return default_value . getValue () ; }
440 } ;
441
442 /*
443   The 'live' interface stack is used for clicking and rendering.
444 */
445
446 void         puPushLiveInterface        ( puInterface *in ) ;
447 void         puPopLiveInterface         ( void ) ;
448 int          puNoLiveInterface          ( void ) ;
449 puInterface *puGetBaseLiveInterface     ( void ) ;
450 puInterface *puGetUltimateLiveInterface ( void ) ;
451
452 /*
453   The regular interface stack is used for adding widgets
454 */
455
456 void         puPushInterface        ( puInterface *in ) ;
457 void         puPopInterface         ( void ) ;
458 int          puNoInterface          ( void ) ;
459 puInterface *puGetCurrInterface     ( void ) ;
460
461 class puInterface : public puObject
462 {
463 protected:
464   int num_children ;
465   puObject *dlist ;
466
467   void doHit       ( int button, int updown, int x, int y ) ;
468
469 public:
470
471   puInterface ( int x, int y ) : puObject ( x, y, x, y )
472   {
473     type |= PUCLASS_INTERFACE ;
474     dlist = NULL ;
475     num_children = 0 ;
476     puPushInterface ( this ) ;
477     puPushLiveInterface ( this ) ;
478   }
479
480   ~puInterface () ;
481
482   void recalc_bbox ( void ) ;
483   virtual void add    ( puObject *new_object ) ;
484   virtual void remove ( puObject *old_object ) ;
485
486   void draw        ( int dx, int dy ) ;
487   int  checkHit    ( int button, int updown, int x, int y ) ;
488   int  checkKey    ( int key   , int updown ) ;
489
490   puObject *getFirstChild ( void ) { return dlist ; }
491   int getNumChildren ( void ) { return num_children ; }
492
493   virtual void close ( void )
494   {
495     if ( puGetCurrInterface () != this )
496       fprintf ( stderr, "PUI: puInterface::close() is mismatched!\n" ) ;
497     else
498       puPopInterface () ;
499   }
500 } ;
501
502 class puFrame : public puObject
503 {
504 protected:
505   virtual int  isHit ( int /* x */, int /* y */ ) { return FALSE ; }
506 public:
507   void draw ( int dx, int dy ) ;
508   puFrame ( int minx, int miny, int maxx, int maxy ) :
509              puObject ( minx, miny, maxx, maxy )
510   {
511     type |= PUCLASS_FRAME ;
512   }
513 } ;
514
515
516 class puText : public puObject
517 {
518 protected:
519   virtual int  isHit ( int /* x */, int /* y */ ) { return FALSE ; }
520 public:
521   void draw ( int dx, int dy ) ;
522   puText ( int x, int y ) : puObject ( x, y, x, y )
523   {
524     type |= PUCLASS_TEXT ;
525   }
526 } ;
527
528
529 class puButton : public puObject
530 {
531 protected:
532 public:
533   void doHit ( int button, int updown, int x, int y ) ;
534   void draw  ( int dx, int dy ) ;
535   puButton   ( int minx, int miny, char *l ) :
536                  puObject ( minx, miny,
537                             minx + puGetStringWidth  ( NULL, l ) + PUSTR_LGAP + PUSTR_RGAP,
538                             miny + puGetStringHeight () + puGetStringDescender () + PUSTR_TGAP + PUSTR_BGAP )
539   {
540     type |= PUCLASS_BUTTON ;
541     setLegend ( l ) ;
542   }
543
544   puButton   ( int minx, int miny, int maxx, int maxy ) :
545                  puObject ( minx, miny, maxx, maxy )
546   {
547     type |= PUCLASS_BUTTON ;
548   }
549 } ;
550
551
552 class puSlider : public puObject
553 {
554 protected:
555   int vert ;
556   float last_cb_value ;
557   float cb_delta ;
558   int   cb_mode ;
559   float slider_fraction ;
560 public:
561   void doHit ( int button, int updown, int x, int y ) ;
562   void draw  ( int dx, int dy ) ;
563   puSlider ( int minx, int miny, int sz, int vertical = FALSE ) :
564      puObject ( minx, miny, vertical ?
565                              ( minx + puGetStringWidth ( NULL, "W" ) +
566                                       PUSTR_LGAP + PUSTR_RGAP ) :
567                              ( minx + sz ),
568                             vertical ?
569                              ( miny + sz ) :
570                              ( miny + puGetStringHeight () +
571                                       puGetStringDescender () +
572                                       PUSTR_TGAP + PUSTR_BGAP )
573                            )
574   {
575     type |= PUCLASS_SLIDER ;
576     slider_fraction = 0.1f ;
577     getValue ( & last_cb_value ) ;
578     vert = vertical ;
579     cb_delta = 0.1f ;
580     cb_mode = PUSLIDER_ALWAYS ;
581   }
582
583   void setCBMode ( int m ) { cb_mode = m ; }
584   float getCBMode ( void ) { return cb_mode ; }
585
586   int  isVertical ( void ) { return vert ; }
587
588   void setDelta ( float f ) { cb_delta = (f<=0.0f) ? 0.1f : (f>=1.0) ? 0.9 : f ; }
589   float getDelta ( void ) { return cb_delta ; }
590
591   void setSliderFraction ( float f ) { slider_fraction = (f<=0.0f) ? 0.1f : (f>=1.0) ? 0.9 : f ; }
592   float getSliderFraction ( void ) { return slider_fraction ; }
593 } ;
594
595
596
597 class puOneShot : public puButton
598 {
599 protected:
600 public:
601   void doHit ( int button, int updown, int x, int y ) ;
602
603   puOneShot ( int minx, int miny, char *l ) : puButton   ( minx, miny, l )
604   {
605     type |= PUCLASS_ONESHOT ;
606   }
607
608   puOneShot ( int minx, int miny, int maxx, int maxy ) :
609                  puButton ( minx, miny, maxx, maxy )
610   {
611     type |= PUCLASS_ONESHOT ;
612   }
613 } ;
614
615
616
617 class puPopup : public puInterface
618 {
619 protected:
620 public:
621   puPopup ( int x, int y ) : puInterface ( x, y )
622   {
623     type |= PUCLASS_POPUP ;
624     hide () ;
625   }
626 } ;
627
628 class puPopupMenu : public puPopup
629 {
630 protected:
631 public:
632   puPopupMenu ( int x, int y ) : puPopup ( x, y )
633   {
634     type |= PUCLASS_POPUPMENU ;
635   }
636
637   puObject *add_item ( char *str, puCallback cb ) ;
638   int  checkHit ( int button, int updown, int x, int y ) ;
639   int  checkKey ( int key   , int updown ) ;
640   void close ( void ) ;
641 } ;
642
643
644 class puMenuBar : public puInterface
645 {
646 protected:
647 public:
648   puMenuBar ( int h = -1 ) :
649     puInterface ( 0, h < 0 ? glutGet((GLenum) GLUT_WINDOW_HEIGHT ) -
650                       ( puGetStringHeight() + PUSTR_TGAP + PUSTR_BGAP ) : h )
651   {
652     type |= PUCLASS_MENUBAR ;
653   }
654
655   void add_submenu ( char *str, char *items[], puCallback cb[] ) ;
656   void close ( void ) ;
657 } ;
658
659
660 class puInput : public puObject
661 {
662   int accepting ;
663   int cursor_position ;
664   int select_start_position ;
665   int select_end_position ;
666
667   void normalize_cursors ( void ) ;
668
669 public:
670   void draw     ( int dx, int dy ) ;
671   void doHit    ( int button, int updown, int x, int y ) ;
672   int  checkKey ( int key, int updown ) ;
673
674   int  isAcceptingInput ( void ) { return accepting ; }
675   void rejectInput      ( void ) { accepting = FALSE ; }
676   void acceptInput      ( void ) { accepting = TRUE ;
677                              cursor_position = strlen ( string ) ;
678                              select_start_position = select_end_position = -1 ; }
679
680   int  getCursor ( void )        { return cursor_position ; }
681   void setCursor ( int c ) { cursor_position = c ; }
682
683   void setSelectRegion ( int s, int e )
684   {
685     select_start_position = s ;
686     select_end_position   = e ;
687   }
688
689   void getSelectRegion ( int *s, int *e )
690   {
691     if ( s ) *s = select_start_position ;
692     if ( e ) *e = select_end_position   ;
693   }
694
695   puInput ( int minx, int miny, int maxx, int maxy ) :
696              puObject ( minx, miny, maxx, maxy )
697   {
698     type |= PUCLASS_INPUT ;
699
700     accepting = FALSE ;
701
702     cursor_position       =  0 ;
703     select_start_position = -1 ;
704     select_end_position   = -1 ;
705
706     setColourScheme ( 0.8, 0.7, 0.7 ) ; /* Yeukky Pink */
707   }
708 } ;
709
710
711 class puButtonBox : public puObject
712 {
713 protected:
714   int one_only ;
715   int num_kids ;
716   char **button_labels ;
717
718 public:
719
720   puButtonBox ( int minx, int miny, int maxx, int maxy, 
721                 char **labels, int one_button ) ;
722
723   int isOneButton ( void ) { return one_only ; }
724
725   int checkKey ( int key   , int updown ) ;
726   int checkHit ( int button, int updown, int x, int y ) ;
727   void draw    ( int dx, int dy ) ;
728 } ;
729
730
731
732 class puDialogBox : public puPopup
733 {
734 protected:
735 public:
736
737   puDialogBox ( int x, int y ) : puPopup ( x, y )
738   {
739     type |= PUCLASS_DIALOGBOX ;
740   }
741 } ;
742
743 #endif
744