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