4 #ifdef PU_NOT_USING_GLUT
9 #define PU_STRING_X_FUDGE 6
10 #define PU_STRING_Y_FUDGE 6
12 int puRefresh = TRUE ;
14 #ifdef PU_NOT_USING_GLUT
16 static int puWindowWidth = 400 ;
17 static int puWindowHeight = 400 ;
19 int puGetWindowHeight () { return puWindowHeight ; }
20 int puGetWindowWidth () { return puWindowWidth ; }
22 void puSetWindowSize ( int width, int height )
24 puWindowWidth = width ;
25 puWindowHeight = height ;
28 static int fontBase = 0;
29 static int fontSize[257];
32 int puGetWindowHeight () { return glutGet ( (GLenum) GLUT_WINDOW_HEIGHT ) ; }
33 int puGetWindowWidth () { return glutGet ( (GLenum) GLUT_WINDOW_WIDTH ) ; }
35 void puSetWindowSize ( int width, int height )
37 fprintf ( stderr, "PUI: puSetWindowSize shouldn't be used with GLUT.\n" ) ;
42 puColour _puDefaultColourTable[] =
44 { 0.5f, 0.5f, 0.5f, 1.0f }, /* PUCOL_FOREGROUND */
45 { 0.3f, 0.3f, 0.3f, 1.0f }, /* PUCOL_BACKGROUND */
46 { 0.7f, 0.7f, 0.7f, 1.0f }, /* PUCOL_HIGHLIGHT */
47 { 0.0f, 0.0f, 0.0f, 1.0f }, /* PUCOL_LABEL */
48 { 1.0f, 1.0f, 1.0f, 1.0f }, /* PUCOL_TEXT */
50 { 0.0f, 0.0f, 0.0f, 0.0f } /* ILLEGAL */
54 puValue::~puValue () {}
56 static int _puCursor_enable = FALSE ;
57 static int _puCursor_x = 0 ;
58 static int _puCursor_y = 0 ;
59 static float _puCursor_bgcolour [4] = { 1.0f, 1.0f, 1.0f, 1.0f } ;
60 static float _puCursor_fgcolour [4] = { 0.0f, 0.0f, 0.0f, 1.0f } ;
62 void puHideCursor ( void ) { _puCursor_enable = FALSE ; }
63 void puShowCursor ( void ) { _puCursor_enable = TRUE ; }
64 int puCursorIsHidden ( void ) { return ! _puCursor_enable ; }
66 void puCursor ( int x, int y )
72 int puGetStringDescender ( void *fnt )
75 fnt = PUFONT_9_BY_15 ;
77 if ( fnt == PUFONT_8_BY_13 ) return 2 ;
78 if ( fnt == PUFONT_9_BY_15 ) return 3 ;
79 if ( fnt == PUFONT_TIMES_ROMAN_10 ) return 2 ;
80 if ( fnt == PUFONT_TIMES_ROMAN_24 ) return 5 ;
81 if ( fnt == PUFONT_HELVETICA_10 ) return 2 ;
82 if ( fnt == PUFONT_HELVETICA_12 ) return 3 ;
83 if ( fnt == PUFONT_HELVETICA_18 ) return 4 ;
88 int puGetStringHeight ( void *fnt )
90 /* Height *excluding* descender */
92 fnt = PUFONT_9_BY_15 ;
94 if ( fnt == PUFONT_8_BY_13 ) return 9 ;
95 if ( fnt == PUFONT_9_BY_15 ) return 10 ;
96 if ( fnt == PUFONT_TIMES_ROMAN_10 ) return 7 ;
97 if ( fnt == PUFONT_TIMES_ROMAN_24 ) return 17 ;
98 if ( fnt == PUFONT_HELVETICA_10 ) return 8 ;
99 if ( fnt == PUFONT_HELVETICA_12 ) return 9 ;
100 if ( fnt == PUFONT_HELVETICA_18 ) return 14 ;
105 int puGetStringWidth ( void *fnt, char *str )
113 #ifdef PU_NOT_USING_GLUT
114 while ( *str != '\0' )
116 res += fontSize [ *str ] ;
121 fnt = PUFONT_9_BY_15 ;
123 while ( *str != '\0' )
125 res += glutBitmapWidth ( fnt, *str ) ;
134 void puDrawString ( void *fnt, char *str, int x, int y )
139 glRasterPos2f((float)x, (float)y);
141 #ifdef PU_NOT_USING_GLUT
144 indicate start of glyph display lists
147 glListBase (fontBase);
149 /* Now draw the characters in a string */
151 int len = strlen(str);
152 glCallLists(len, GL_UNSIGNED_BYTE, str);
156 fnt = PUFONT_9_BY_15 ;
158 while ( *str != '\0' )
160 glutBitmapCharacter ( fnt, *str ) ;
167 static void puDrawCursor ( int x, int y )
169 glColor4fv ( _puCursor_bgcolour ) ;
171 glBegin ( GL_TRIANGLES ) ;
172 glVertex2i ( x, y ) ;
173 glVertex2i ( x + 13, y - 4 ) ;
174 glVertex2i ( x + 4, y - 13 ) ;
176 glVertex2i ( x + 8, y - 3 ) ;
177 glVertex2i ( x + 17, y - 12 ) ;
178 glVertex2i ( x + 12, y - 17 ) ;
180 glVertex2i ( x + 12, y - 17 ) ;
181 glVertex2i ( x + 3, y - 8 ) ;
182 glVertex2i ( x + 8, y - 3 ) ;
185 glColor4fv ( _puCursor_fgcolour ) ;
187 glBegin ( GL_TRIANGLES ) ;
188 glVertex2i ( x+1, y-1 ) ;
189 glVertex2i ( x + 11, y - 4 ) ;
190 glVertex2i ( x + 4, y - 11 ) ;
192 glVertex2i ( x + 8, y - 5 ) ;
193 glVertex2i ( x + 15, y - 12 ) ;
194 glVertex2i ( x + 12, y - 15 ) ;
196 glVertex2i ( x + 12, y - 15 ) ;
197 glVertex2i ( x + 5, y - 8 ) ;
198 glVertex2i ( x + 8, y - 5 ) ;
204 static int firsttime = TRUE ;
208 puInterface *base_interface = new puInterface ( 0, 0 ) ;
209 puPushInterface ( base_interface ) ;
210 puPushLiveInterface ( base_interface ) ;
212 #ifdef PU_NOT_USING_GLUT
214 /* Create bitmaps for the device context font's first 256 glyphs */
216 fontBase = glGenLists(256);
218 HDC hdc = wglGetCurrentDC();
220 /* Make the system font the device context's selected font */
222 SelectObject (hdc, GetStockObject (SYSTEM_FONT));
224 int *tempSize = &fontSize[1];
226 if ( ! GetCharWidth32 ( hdc, 1, 255, tempSize ) &&
227 ! GetCharWidth ( hdc, 1, 255, tempSize ) )
231 FormatMessage ( FORMAT_MESSAGE_ALLOCATE_BUFFER |
232 FORMAT_MESSAGE_FROM_SYSTEM,
235 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
239 fprintf ( stderr, "PUI: Error: %s\n", (char *)lpMsgBuf ) ;
240 LocalFree ( lpMsgBuf ) ;
243 wglUseFontBitmaps ( hdc, 0, 256, fontBase ) ;
248 static void puSetOpenGLState ( void )
250 int w = puGetWindowWidth () ;
251 int h = puGetWindowHeight () ;
253 glPushAttrib ( GL_ENABLE_BIT | GL_VIEWPORT_BIT | GL_TRANSFORM_BIT ) ;
254 glDisable ( GL_LIGHTING ) ;
255 glDisable ( GL_FOG ) ;
256 glDisable ( GL_TEXTURE_2D ) ;
257 glDisable ( GL_DEPTH_TEST ) ;
258 glDisable ( GL_CULL_FACE ) ;
260 glViewport ( 0, 0, w, h ) ;
261 glMatrixMode ( GL_PROJECTION ) ;
264 gluOrtho2D ( 0, w, 0, h ) ;
265 glMatrixMode ( GL_MODELVIEW ) ;
270 static void puRestoreOpenGLState ( void )
272 glMatrixMode ( GL_PROJECTION ) ;
274 glMatrixMode ( GL_MODELVIEW ) ;
280 void puDisplay ( void )
282 puSetOpenGLState () ;
283 puGetUltimateLiveInterface () -> draw ( 0, 0 ) ;
285 int h = puGetWindowHeight () ;
287 if ( _puCursor_enable )
288 puDrawCursor ( _puCursor_x,
291 puRestoreOpenGLState () ;
294 int puKeyboard ( int key, int updown )
296 return puGetBaseLiveInterface () -> checkKey ( key, updown ) ;
300 static int last_buttons = 0 ;
301 int puMouse ( int button, int updown, int x, int y )
305 int h = puGetWindowHeight () ;
307 if ( updown == PU_DOWN )
308 last_buttons |= ( 1 << button ) ;
310 last_buttons &= ~( 1 << button ) ;
312 return puGetBaseLiveInterface () -> checkHit ( button, updown, x,
316 int puMouse ( int x, int y )
320 if ( last_buttons == 0 )
323 int button = (last_buttons & (1<<PU_LEFT_BUTTON )) ? PU_LEFT_BUTTON :
324 (last_buttons & (1<<PU_MIDDLE_BUTTON)) ? PU_MIDDLE_BUTTON :
325 (last_buttons & (1<<PU_RIGHT_BUTTON )) ? PU_RIGHT_BUTTON : 0 ;
327 int h = puGetWindowHeight () ;
329 return puGetBaseLiveInterface () -> checkHit ( button, PU_DRAG, x,