4 #define PU_STRING_X_FUDGE 6
5 #define PU_STRING_Y_FUDGE 6
9 puColour _puDefaultColourTable[] =
11 { 0.5, 0.5, 0.5, 1.0 }, /* PUCOL_FOREGROUND */
12 { 0.3, 0.3, 0.3, 1.0 }, /* PUCOL_BACKGROUND */
13 { 0.7, 0.7, 0.7, 1.0 }, /* PUCOL_HIGHLIGHT */
14 { 0.0, 0.0, 0.0, 1.0 }, /* PUCOL_LABEL */
15 { 1.0, 1.0, 1.0, 1.0 }, /* PUCOL_TEXT */
17 { 0.0, 0.0, 0.0, 0.0 } /* ILLEGAL */
21 puValue::~puValue () {}
23 static int _puCursor_enable = FALSE ;
24 static int _puCursor_x = 0 ;
25 static int _puCursor_y = 0 ;
26 static float _puCursor_bgcolour [4] = { 1.0f, 1.0f, 1.0f, 1.0f } ;
27 static float _puCursor_fgcolour [4] = { 0.0f, 0.0f, 0.0f, 1.0f } ;
29 void puHideCursor ( void ) { _puCursor_enable = FALSE ; }
30 void puShowCursor ( void ) { _puCursor_enable = TRUE ; }
31 int puCursorIsHidden ( void ) { return ! _puCursor_enable ; }
33 void puCursor ( int x, int y )
39 int puGetStringDescender ( void *fnt )
42 fnt = GLUT_BITMAP_9_BY_15 ;
44 if ( fnt == GLUT_BITMAP_8_BY_13 ) return 2 ;
45 if ( fnt == GLUT_BITMAP_9_BY_15 ) return 3 ;
46 if ( fnt == GLUT_BITMAP_TIMES_ROMAN_10 ) return 2 ;
47 if ( fnt == GLUT_BITMAP_TIMES_ROMAN_24 ) return 5 ;
48 if ( fnt == GLUT_BITMAP_HELVETICA_10 ) return 2 ;
49 if ( fnt == GLUT_BITMAP_HELVETICA_12 ) return 3 ;
50 if ( fnt == GLUT_BITMAP_HELVETICA_18 ) return 4 ;
55 int puGetStringHeight ( void *fnt )
57 /* Height *excluding* descender */
60 fnt = GLUT_BITMAP_9_BY_15 ;
62 if ( fnt == GLUT_BITMAP_8_BY_13 ) return 9 ;
63 if ( fnt == GLUT_BITMAP_9_BY_15 ) return 10 ;
64 if ( fnt == GLUT_BITMAP_TIMES_ROMAN_10 ) return 7 ;
65 if ( fnt == GLUT_BITMAP_TIMES_ROMAN_24 ) return 17 ;
66 if ( fnt == GLUT_BITMAP_HELVETICA_10 ) return 8 ;
67 if ( fnt == GLUT_BITMAP_HELVETICA_12 ) return 9 ;
68 if ( fnt == GLUT_BITMAP_HELVETICA_18 ) return 14 ;
73 int puGetStringWidth ( void *fnt, char *str )
79 fnt = GLUT_BITMAP_9_BY_15 ;
83 while ( *str != '\0' )
85 res += glutBitmapWidth ( fnt, *str ) ;
93 void puDrawString ( void *fnt, char *str, int x, int y )
99 fnt = GLUT_BITMAP_9_BY_15 ;
101 glRasterPos2f ( x, y ) ;
103 while ( *str != '\0' )
105 glutBitmapCharacter ( fnt, *str ) ;
111 static void puDrawCursor ( int x, int y )
113 glColor4fv ( _puCursor_bgcolour ) ;
115 glBegin ( GL_TRIANGLES ) ;
116 glVertex2i ( x, y ) ;
117 glVertex2i ( x + 13, y - 4 ) ;
118 glVertex2i ( x + 4, y - 13 ) ;
120 glVertex2i ( x + 8, y - 3 ) ;
121 glVertex2i ( x + 17, y - 12 ) ;
122 glVertex2i ( x + 12, y - 17 ) ;
124 glVertex2i ( x + 12, y - 17 ) ;
125 glVertex2i ( x + 3, y - 8 ) ;
126 glVertex2i ( x + 8, y - 3 ) ;
129 glColor4fv ( _puCursor_fgcolour ) ;
131 glBegin ( GL_TRIANGLES ) ;
132 glVertex2i ( x+1, y-1 ) ;
133 glVertex2i ( x + 11, y - 4 ) ;
134 glVertex2i ( x + 4, y - 11 ) ;
136 glVertex2i ( x + 8, y - 5 ) ;
137 glVertex2i ( x + 15, y - 12 ) ;
138 glVertex2i ( x + 12, y - 15 ) ;
140 glVertex2i ( x + 12, y - 15 ) ;
141 glVertex2i ( x + 5, y - 8 ) ;
142 glVertex2i ( x + 8, y - 5 ) ;
148 static int firsttime = TRUE ;
152 puInterface *base_interface = new puInterface ( 0, 0 ) ;
153 puPushInterface ( base_interface ) ;
154 puPushLiveInterface ( base_interface ) ;
159 static void puSetOpenGLState ( void )
161 int w = glutGet ( (GLenum) GLUT_WINDOW_WIDTH ) ;
162 int h = glutGet ( (GLenum) GLUT_WINDOW_HEIGHT ) ;
164 glPushAttrib ( GL_ENABLE_BIT | GL_VIEWPORT_BIT | GL_TRANSFORM_BIT ) ;
165 glDisable ( GL_LIGHTING ) ;
166 glDisable ( GL_FOG ) ;
167 glDisable ( GL_TEXTURE_2D ) ;
168 glDisable ( GL_DEPTH_TEST ) ;
169 glDisable ( GL_CULL_FACE ) ;
171 glViewport ( 0, 0, w, h ) ;
172 glMatrixMode ( GL_PROJECTION ) ;
175 gluOrtho2D ( 0, w, 0, h ) ;
176 glMatrixMode ( GL_MODELVIEW ) ;
181 static void puRestoreOpenGLState ( void )
183 glMatrixMode ( GL_PROJECTION ) ;
185 glMatrixMode ( GL_MODELVIEW ) ;
191 void puDisplay ( void )
193 puSetOpenGLState () ;
194 puGetUltimateLiveInterface () -> draw ( 0, 0 ) ;
196 if ( _puCursor_enable )
197 puDrawCursor ( _puCursor_x,
198 glutGet((GLenum)GLUT_WINDOW_HEIGHT) - _puCursor_y ) ;
200 puRestoreOpenGLState () ;
203 int puKeyboard ( int key, int updown )
205 return puGetBaseLiveInterface () -> checkKey ( key, updown ) ;
209 static int last_buttons = 0 ;
211 int puMouse ( int button, int updown, int x, int y )
215 if ( updown == PU_DOWN )
216 last_buttons |= ( 1 << button ) ;
218 last_buttons &= ~( 1 << button ) ;
220 return puGetBaseLiveInterface () -> checkHit ( button, updown, x,
221 glutGet((GLenum)GLUT_WINDOW_HEIGHT) - y ) ;
224 int puMouse ( int x, int y )
228 if ( last_buttons == 0 )
231 int button = (last_buttons & (1<<PU_LEFT_BUTTON )) ? PU_LEFT_BUTTON :
232 (last_buttons & (1<<PU_MIDDLE_BUTTON)) ? PU_MIDDLE_BUTTON :
233 (last_buttons & (1<<PU_RIGHT_BUTTON )) ? PU_RIGHT_BUTTON : 0 ;
235 return puGetBaseLiveInterface () -> checkHit ( button, PU_DRAG, x,
236 glutGet((GLenum)GLUT_WINDOW_HEIGHT) - y ) ;