4 inline float clamp01 ( float x )
6 return (x >= 1.0f) ? 1.0f : x ;
9 static void load_colour_scheme ( float col[][4], float r, float g,
12 puSetColour ( col [ PUCOL_FOREGROUND ], r, g, b, a ) ;
13 puSetColour ( col [ PUCOL_BACKGROUND ], r/2, g/2, b/2, a ) ;
14 puSetColour ( col [ PUCOL_HIGHLIGHT ], clamp01(r*1.3f), clamp01(g*1.3f),
15 clamp01(b*1.3f), a ) ;
17 if ( 4 * g + 3 * r + b > 0.5 )
18 puSetColour ( col [ PUCOL_LEGEND ], 0.0, 0.0, 0.0, a ) ;
20 puSetColour ( col [ PUCOL_LEGEND ], 1.0, 1.0, 1.0, a ) ;
24 static int defaultStyle = PUSTYLE_DEFAULT ;
25 static puFont defaultLegendFont = NULL ;
26 static puFont defaultLabelFont = NULL ;
27 static float defaultColourScheme [ 4 ] ;
29 void puSetDefaultStyle ( int style ) { defaultStyle = style ; }
30 int puGetDefaultStyle ( void ) { return defaultStyle ; }
32 void puSetDefaultFonts ( puFont legendFont, puFont labelFont )
34 defaultLegendFont = legendFont ;
35 defaultLabelFont = labelFont ;
38 void puGetDefaultFonts ( puFont *legendFont, puFont *labelFont )
40 if ( legendFont ) *legendFont = defaultLegendFont ;
41 if ( labelFont ) *labelFont = defaultLabelFont ;
44 void puSetDefaultColourScheme ( float r, float g, float b, float a )
46 defaultColourScheme[0] = r ;
47 defaultColourScheme[1] = g ;
48 defaultColourScheme[2] = b ;
49 defaultColourScheme[3] = a ;
50 load_colour_scheme ( _puDefaultColourTable, r, g, b, a ) ;
53 void puGetDefaultColourScheme ( float *r, float *g, float *b, float *a )
55 if ( r ) *r = defaultColourScheme[0] ;
56 if ( g ) *g = defaultColourScheme[1] ;
57 if ( b ) *b = defaultColourScheme[2] ;
58 if ( a ) *a = defaultColourScheme[3] ;
63 void puObject::setColourScheme ( float r, float g, float b, float a )
65 load_colour_scheme ( colour, r, g, b, a ) ;
68 puObject::puObject ( int minx, int miny, int maxx, int maxy ) : puValue ()
70 type |= PUCLASS_OBJECT ;
71 bbox.min[0] = abox.min[0] = minx ;
72 bbox.min[1] = abox.min[1] = miny ;
73 bbox.max[0] = abox.max[0] = maxx ;
74 bbox.max[1] = abox.max[1] = maxy ;
76 active_mouse_edge = PU_UP ;
77 style = defaultStyle ;
78 visible = active = TRUE ;
86 labelPlace = PUPLACE_DEFAULT ;
87 labelFont = defaultLabelFont ;
89 legendFont = defaultLegendFont ;
91 for ( int i = 0 ; i < PUCOL_MAX ; i++ )
92 puSetColour ( colour[i], _puDefaultColourTable[i] ) ;
94 if ( ! puNoInterface() )
96 parent = puGetCurrInterface() ;
97 parent -> add ( this ) ;
104 puObject::~puObject ()
106 if ( parent != this && parent != NULL )
107 parent -> remove ( this ) ;
110 void puObject::recalc_bbox ( void )
115 switch ( labelPlace )
117 case PUPLACE_ABOVE : bbox.max[1] += puGetStringHeight ( getLabelFont() ) + puGetStringDescender ( getLabelFont () ) + PUSTR_TGAP + PUSTR_BGAP ; break ;
118 case PUPLACE_BELOW : bbox.min[1] -= puGetStringHeight ( getLabelFont() ) + puGetStringDescender ( getLabelFont () ) + PUSTR_TGAP + PUSTR_BGAP ; break ;
119 case PUPLACE_LEFT : bbox.min[0] -= puGetStringWidth ( getLabelFont(), getLabel() ) + PUSTR_LGAP + PUSTR_RGAP ; break ;
120 case PUPLACE_RIGHT : bbox.max[0] += puGetStringWidth ( getLabelFont(), getLabel() ) + PUSTR_LGAP + PUSTR_RGAP ; break ;
123 if ( parent != NULL )
124 parent -> recalc_bbox () ;
127 void puObject::draw_label ( int dx, int dy )
129 if ( !visible ) return ;
131 /* If greyed out then halve the opacity when drawing the label */
134 glColor4fv ( colour [ PUCOL_LABEL ] ) ;
136 glColor4f ( colour [ PUCOL_LABEL ][0],
137 colour [ PUCOL_LABEL ][1],
138 colour [ PUCOL_LABEL ][2],
139 colour [ PUCOL_LABEL ][3] / 2.0f ) ; /* 50% more transparent */
141 switch ( labelPlace )
143 case PUPLACE_ABOVE : puDrawString ( labelFont, label, dx + abox.min[0] + PUSTR_LGAP, dy + abox.max[1] + puGetStringDescender(labelFont) + PUSTR_BGAP ) ; break ;
144 case PUPLACE_BELOW : puDrawString ( labelFont, label, dx + abox.min[0] + PUSTR_LGAP, dy + bbox.min[1] + puGetStringDescender(labelFont) + PUSTR_BGAP ) ; break ;
145 case PUPLACE_LEFT : puDrawString ( labelFont, label, dx + bbox.min[0] + PUSTR_LGAP, dy + abox.min[1] + puGetStringDescender(labelFont) + PUSTR_BGAP ) ; break ;
146 case PUPLACE_RIGHT : puDrawString ( labelFont, label, dx + abox.max[0] + PUSTR_LGAP, dy + abox.min[1] + puGetStringDescender(labelFont) + PUSTR_BGAP ) ; break ;
151 int puObject::checkKey ( int key, int updown )
153 if ( updown == PU_UP )
156 if ( isReturnDefault() && ( key == '\r' || key == '\n' ) )
158 checkHit ( PU_LEFT_BUTTON, PU_DOWN, (abox.min[0]+abox.max[0])/2,
159 (abox.min[1]+abox.max[1])/2 ) ;
160 checkHit ( PU_LEFT_BUTTON, PU_UP , (abox.min[0]+abox.max[0])/2,
161 (abox.min[1]+abox.max[1])/2 ) ;
169 void puObject::doHit ( int button, int updown, int x, int y )
173 if ( button == PU_LEFT_BUTTON )
175 if ( updown == active_mouse_edge || active_mouse_edge == PU_UP_AND_DOWN )
187 int puObject::checkHit ( int button, int updown, int x, int y )
191 doHit ( button, updown, x, y ) ;
200 char *puValue::getTypeString ( void )
204 if ( i & PUCLASS_DIALOGBOX ) return "puDialogBox" ;
205 if ( i & PUCLASS_SLIDER ) return "puSlider" ;
206 if ( i & PUCLASS_BUTTONBOX ) return "puButtonBox" ;
207 if ( i & PUCLASS_INPUT ) return "puInput" ;
208 if ( i & PUCLASS_MENUBAR ) return "puMenuBar" ;
209 if ( i & PUCLASS_POPUPMENU ) return "puPopupMenu" ;
210 if ( i & PUCLASS_POPUP ) return "puPopup" ;
211 if ( i & PUCLASS_ONESHOT ) return "puOneShot" ;
212 if ( i & PUCLASS_BUTTON ) return "puButton" ;
213 if ( i & PUCLASS_TEXT ) return "puText" ;
214 if ( i & PUCLASS_FRAME ) return "puFrame" ;
215 if ( i & PUCLASS_INTERFACE ) return "puInterface" ;
216 if ( i & PUCLASS_OBJECT ) return "puObject" ;
217 if ( i & PUCLASS_VALUE ) return "puValue" ;
219 return "Unknown Object type." ;