libPUI_la_SOURCES = \
pu.h puLocal.h \
+ complex.cxx \
pu.cxx \
puBox.cxx \
puButton.cxx \
--- /dev/null
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#ifdef WIN32
+#include <windows.h>
+#else
+#include <unistd.h>
+#endif
+#include <math.h>
+#include <GL/glut.h>
+#include "pu.h"
+
+/***********************************\
+* *
+* These are the PUI widget pointers *
+* *
+\***********************************/
+
+puMenuBar *main_menu_bar ;
+puButton *hide_menu_button ;
+puDialogBox *dialog_box ;
+puText *dialog_box_message ;
+puOneShot *dialog_box_ok_button ;
+puText *timer_text ;
+puSlider *rspeedSlider;
+
+
+/***********************************\
+* *
+* This is a generic tumbling cube *
+* *
+\***********************************/
+
+GLfloat light_diffuse [] = {1.0, 0.0, 0.0, 1.0} ; /* Red diffuse light. */
+GLfloat light_position[] = {1.0, 1.0, 1.0, 0.0} ; /* Infinite light location. */
+
+GLfloat cube_n[6][3] = /* Normals */
+{
+ {-1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {1.0, 0.0, 0.0},
+ { 0.0,-1.0, 0.0}, {0.0, 0.0, 1.0}, {0.0, 0.0,-1.0}
+} ;
+
+GLint cube_i[6][4] = /* Vertex indices */
+{
+ {0, 1, 2, 3}, {3, 2, 6, 7}, {7, 6, 5, 4},
+ {4, 5, 1, 0}, {5, 6, 2, 1}, {7, 4, 0, 3}
+} ;
+
+GLfloat cube_v[8][3] = /* Vertices */
+{
+ {-1.0,-1.0, 1.0}, {-1.0,-1.0,-1.0}, {-1.0, 1.0,-1.0}, {-1.0, 1.0, 1.0},
+ { 1.0,-1.0, 1.0}, { 1.0,-1.0,-1.0}, { 1.0, 1.0,-1.0}, { 1.0, 1.0, 1.0}
+} ;
+
+
+static int firsttime;
+
+void drawCube (void)
+{
+
+ if ( firsttime )
+ {
+ /*
+ Deliberately do this only once - it's a better test of
+ PUI's attempts to leave the OpenGL state undisturbed
+ */
+
+ firsttime = FALSE ;
+ glLightfv ( GL_LIGHT0, GL_DIFFUSE , light_diffuse ) ;
+ glLightfv ( GL_LIGHT0, GL_POSITION, light_position ) ;
+ glEnable ( GL_LIGHT0 ) ;
+ glEnable ( GL_LIGHTING ) ;
+ glEnable ( GL_DEPTH_TEST ) ;
+ glMatrixMode ( GL_PROJECTION ) ;
+ gluPerspective ( 40.0, 1.0, 1.0, 10.0 ) ;
+ glMatrixMode ( GL_MODELVIEW ) ;
+ gluLookAt ( 0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 ) ;
+ glTranslatef ( 0.0, 0.0, -1.0 ) ;
+ glRotatef ( 60.0, 1.0, 0.0, 0.0 ) ;
+ }
+
+ glCullFace ( GL_FRONT ) ;
+ glEnable ( GL_CULL_FACE ) ;
+ // glRotatef ( 1.0f, 0.0, 0.0, 1.0 ) ; /* Tumble that cube! */
+
+ glBegin ( GL_QUADS ) ;
+
+ for ( int i = 0 ; i < 6 ; i++ )
+ {
+ glNormal3fv ( &cube_n[i][0] ) ;
+ glVertex3fv ( cube_v[cube_i[i][0]] ) ; glVertex3fv ( cube_v[cube_i[i][1]] ) ;
+ glVertex3fv ( cube_v[cube_i[i][2]] ) ; glVertex3fv ( cube_v[cube_i[i][3]] ) ;
+ }
+
+ glEnd () ;
+}
+
+/********************************\
+* *
+* End of cube renderer in OpenGL *
+* *
+\********************************/
+
+
+/**************************************\
+* *
+* These three functions capture mouse *
+* and keystrokes (special and mundane) *
+* from GLUT and pass them on to PUI. *
+* *
+\**************************************/
+
+static void specialfn ( int key, int, int )
+{
+ puKeyboard ( key + PU_KEY_GLUT_SPECIAL_OFFSET, PU_DOWN ) ;
+ glutPostRedisplay () ;
+}
+
+static void keyfn ( unsigned char key, int, int )
+{
+ puKeyboard ( key, PU_DOWN ) ;
+ glutPostRedisplay () ;
+}
+
+static void motionfn ( int x, int y )
+{
+ puMouse ( x, y ) ;
+ glutPostRedisplay () ;
+}
+
+static void mousefn ( int button, int updown, int x, int y )
+{
+ puMouse ( button, updown, x, y ) ;
+ glutPostRedisplay () ;
+}
+
+/**************************************\
+* *
+* This function redisplays the PUI and *
+* the tumbling cube, flips the double *
+* buffer and then asks GLUT to post a *
+* redisplay command - so we re-render *
+* at maximum rate. *
+* *
+\**************************************/
+
+static void displayfn (void)
+{
+ /* Clear the screen */
+
+ glClearColor ( 0.0, 0.0, 0.0, 1.0 ) ;
+ glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) ;
+
+ /* Draw the tumbling cube */
+
+ float val ; rspeedSlider->getValue ( &val ) ;
+
+ glRotatef( 4*val, 15.0, 10.0 , 5.0 );
+
+ drawCube () ;
+
+ /* Update the 'timer' */
+
+ time_t t = time ( NULL ) ;
+ timer_text -> setLabel ( ctime ( & t ) ) ;
+
+ /* Make PUI redraw */
+
+ puDisplay () ;
+
+ /* Off we go again... */
+
+ glutSwapBuffers () ;
+ glutPostRedisplay () ;
+}
+
+
+/***********************************\
+* *
+* Here are the PUI widget callback *
+* functions. *
+* *
+\***********************************/
+
+void hide_menu_cb ( puObject *cb )
+{
+ if ( cb -> getValue () )
+ {
+ main_menu_bar -> reveal () ;
+ hide_menu_button->setLegend ( "Hide Menu" ) ;
+ }
+ else
+ {
+ main_menu_bar -> hide () ;
+ hide_menu_button->setLegend ( "Show Menu" ) ;
+ }
+}
+
+
+void go_away_cb ( puObject * )
+{
+ /*
+ Delete the dialog box when its 'OK' button is pressed.
+
+ This seems to crash on MSVC compilers - probably because
+ I delete dialog_box - whose member function is calling
+ this function. Hence we return to something that is
+ in a distinctly 'iffy' state.
+ */
+
+ delete dialog_box ;
+ dialog_box = NULL ;
+}
+
+void mk_dialog ( char *txt )
+{
+ dialog_box = new puDialogBox ( 150, 50 ) ;
+ {
+ new puFrame ( 0, 0, 400, 100 ) ;
+ dialog_box_message = new puText ( 10, 70 ) ;
+ dialog_box_message -> setLabel ( txt ) ;
+ dialog_box_ok_button = new puOneShot ( 180, 10, 240, 50 ) ;
+ dialog_box_ok_button -> setLegend ( "OK" ) ;
+ dialog_box_ok_button -> makeReturnDefault ( TRUE ) ;
+ dialog_box_ok_button -> setCallback ( go_away_cb ) ;
+ }
+ dialog_box -> close () ;
+ dialog_box -> reveal () ;
+}
+
+void ni_cb ( puObject * )
+{
+ mk_dialog ( "Sorry, that function isn't implemented" ) ;
+}
+
+void about_cb ( puObject * )
+{
+ mk_dialog ( "This is the PUI 'complex' program" ) ;
+}
+
+void help_cb ( puObject * )
+{
+ mk_dialog ( "Sorry, no help is available for this demo" ) ;
+}
+
+void edit_cb ( puObject * )
+{
+}
+
+void exit_cb ( puObject * )
+{
+ fprintf ( stderr, "Exiting PUI demo program.\n" ) ;
+ exit ( 1 ) ;
+}
+
+/* Menu bar entries: */
+
+char *file_submenu [] = { "Exit", "Close", "--------", "Print", "--------", "Save", "New", NULL } ;
+puCallback file_submenu_cb [] = { exit_cb, exit_cb, NULL, ni_cb , NULL, ni_cb, ni_cb, NULL } ;
+
+char *edit_submenu [] = { "Edit text", NULL } ;
+puCallback edit_submenu_cb [] = { edit_cb, NULL } ;
+
+char *help_submenu [] = { "About...", "Help", NULL } ;
+puCallback help_submenu_cb [] = { about_cb, help_cb, NULL } ;
+
+
+void sliderCB( puObject *sliderObj)
+{
+ glutPostRedisplay();
+}
+
+int main ( int argc, char **argv )
+{
+
+ firsttime = TRUE;
+
+ glutInitWindowSize ( 640, 480 ) ;
+ glutInit ( &argc, argv ) ;
+ glutInitDisplayMode ( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ) ;
+ glutCreateWindow ( "Complex PUI Application" ) ;
+ glutDisplayFunc ( displayfn ) ;
+ glutKeyboardFunc ( keyfn ) ;
+ glutSpecialFunc ( specialfn ) ;
+ glutMouseFunc ( mousefn ) ;
+ glutMotionFunc ( motionfn ) ;
+ glutPassiveMotionFunc ( motionfn ) ;
+ glutIdleFunc ( displayfn ) ;
+
+ puInit () ;
+
+#ifdef USING_3DFX
+ puShowCursor () ;
+#endif
+
+ puSetDefaultStyle ( PUSTYLE_SMALL_SHADED ) ;
+ puSetDefaultColourScheme ( 0.8, 0.2, 0.2 ) ;
+
+ timer_text = new puText ( 300, 10 ) ;
+ timer_text -> setColour ( PUCOL_LABEL, 1.0, 1.0, 1.0 ) ;
+
+ /* Make a button to hide the menu bar */
+
+ hide_menu_button = new puButton ( 10, 10, 150, 50 ) ;
+ hide_menu_button->setValue ( TRUE ) ;
+ hide_menu_button->setLegend ( "Hide Menu" ) ;
+ hide_menu_button->setCallback ( hide_menu_cb ) ;
+ hide_menu_button->makeReturnDefault ( TRUE ) ;
+
+ /* Make the menu bar */
+
+ main_menu_bar = new puMenuBar () ;
+ {
+ main_menu_bar -> add_submenu ( "File", file_submenu, file_submenu_cb ) ;
+ main_menu_bar -> add_submenu ( "Edit", edit_submenu, edit_submenu_cb ) ;
+ main_menu_bar -> add_submenu ( "Help", help_submenu, help_submenu_cb ) ;
+ }
+ main_menu_bar -> close () ;
+
+ rspeedSlider = new puSlider (20,80,150,TRUE);
+ rspeedSlider->setDelta(0.1);
+ rspeedSlider->setCBMode( PUSLIDER_DELTA );
+ rspeedSlider->setCallback(sliderCB);
+
+ glutMainLoop () ;
+ return 0 ;
+}
+
+
#include "puLocal.h"
+#ifdef PU_NOT_USING_GLUT
+#include <assert.h>
+#include <iostream.h>
+#endif
+
#define PU_STRING_X_FUDGE 6
#define PU_STRING_Y_FUDGE 6
int puRefresh = TRUE ;
+#ifdef PU_NOT_USING_GLUT
+
+static int puWindowWidth = 400 ;
+static int puWindowHeight = 400 ;
+
+int puGetWindowHeight () { return puWindowHeight ; }
+int puGetWindowWidth () { return puWindowWidth ; }
+
+void puSetWindowSize ( int width, int height )
+{
+ puWindowWidth = width ;
+ puWindowHeight = height ;
+}
+
+static int fontBase = 0;
+static int fontSize[257];
+#else
+
+int puGetWindowHeight () { return glutGet ( (GLenum) GLUT_WINDOW_HEIGHT ) ; }
+int puGetWindowWidth () { return glutGet ( (GLenum) GLUT_WINDOW_WIDTH ) ; }
+
+void puSetWindowSize ( int width, int height )
+{
+ fprintf ( stderr, "PUI: puSetWindowSize shouldn't be used with GLUT.\n" ) ;
+}
+
+#endif
+
puColour _puDefaultColourTable[] =
{
- { 0.5, 0.5, 0.5, 1.0 }, /* PUCOL_FOREGROUND */
- { 0.3, 0.3, 0.3, 1.0 }, /* PUCOL_BACKGROUND */
- { 0.7, 0.7, 0.7, 1.0 }, /* PUCOL_HIGHLIGHT */
- { 0.0, 0.0, 0.0, 1.0 }, /* PUCOL_LABEL */
- { 1.0, 1.0, 1.0, 1.0 }, /* PUCOL_TEXT */
+ { 0.5f, 0.5f, 0.5f, 1.0f }, /* PUCOL_FOREGROUND */
+ { 0.3f, 0.3f, 0.3f, 1.0f }, /* PUCOL_BACKGROUND */
+ { 0.7f, 0.7f, 0.7f, 1.0f }, /* PUCOL_HIGHLIGHT */
+ { 0.0f, 0.0f, 0.0f, 1.0f }, /* PUCOL_LABEL */
+ { 1.0f, 1.0f, 1.0f, 1.0f }, /* PUCOL_TEXT */
- { 0.0, 0.0, 0.0, 0.0 } /* ILLEGAL */
+ { 0.0f, 0.0f, 0.0f, 0.0f } /* ILLEGAL */
} ;
int puGetStringDescender ( void *fnt )
{
if ( fnt == NULL )
- fnt = GLUT_BITMAP_9_BY_15 ;
+ fnt = PUFONT_9_BY_15 ;
- if ( fnt == GLUT_BITMAP_8_BY_13 ) return 2 ;
- if ( fnt == GLUT_BITMAP_9_BY_15 ) return 3 ;
- if ( fnt == GLUT_BITMAP_TIMES_ROMAN_10 ) return 2 ;
- if ( fnt == GLUT_BITMAP_TIMES_ROMAN_24 ) return 5 ;
- if ( fnt == GLUT_BITMAP_HELVETICA_10 ) return 2 ;
- if ( fnt == GLUT_BITMAP_HELVETICA_12 ) return 3 ;
- if ( fnt == GLUT_BITMAP_HELVETICA_18 ) return 4 ;
+ if ( fnt == PUFONT_8_BY_13 ) return 2 ;
+ if ( fnt == PUFONT_9_BY_15 ) return 3 ;
+ if ( fnt == PUFONT_TIMES_ROMAN_10 ) return 2 ;
+ if ( fnt == PUFONT_TIMES_ROMAN_24 ) return 5 ;
+ if ( fnt == PUFONT_HELVETICA_10 ) return 2 ;
+ if ( fnt == PUFONT_HELVETICA_12 ) return 3 ;
+ if ( fnt == PUFONT_HELVETICA_18 ) return 4 ;
return 0 ;
}
int puGetStringHeight ( void *fnt )
{
/* Height *excluding* descender */
-
if ( fnt == NULL )
- fnt = GLUT_BITMAP_9_BY_15 ;
+ fnt = PUFONT_9_BY_15 ;
- if ( fnt == GLUT_BITMAP_8_BY_13 ) return 9 ;
- if ( fnt == GLUT_BITMAP_9_BY_15 ) return 10 ;
- if ( fnt == GLUT_BITMAP_TIMES_ROMAN_10 ) return 7 ;
- if ( fnt == GLUT_BITMAP_TIMES_ROMAN_24 ) return 17 ;
- if ( fnt == GLUT_BITMAP_HELVETICA_10 ) return 8 ;
- if ( fnt == GLUT_BITMAP_HELVETICA_12 ) return 9 ;
- if ( fnt == GLUT_BITMAP_HELVETICA_18 ) return 14 ;
+ if ( fnt == PUFONT_8_BY_13 ) return 9 ;
+ if ( fnt == PUFONT_9_BY_15 ) return 10 ;
+ if ( fnt == PUFONT_TIMES_ROMAN_10 ) return 7 ;
+ if ( fnt == PUFONT_TIMES_ROMAN_24 ) return 17 ;
+ if ( fnt == PUFONT_HELVETICA_10 ) return 8 ;
+ if ( fnt == PUFONT_HELVETICA_12 ) return 9 ;
+ if ( fnt == PUFONT_HELVETICA_18 ) return 14 ;
return 0 ;
}
int puGetStringWidth ( void *fnt, char *str )
{
+
if ( str == NULL )
return 0 ;
- if ( fnt == NULL )
- fnt = GLUT_BITMAP_9_BY_15 ;
-
int res = 0 ;
+#ifdef PU_NOT_USING_GLUT
+ while ( *str != '\0' )
+ {
+ res += fontSize [ *str ] ;
+ str++ ;
+ }
+#else
+ if ( fnt == NULL )
+ fnt = PUFONT_9_BY_15 ;
+
while ( *str != '\0' )
{
res += glutBitmapWidth ( fnt, *str ) ;
str++ ;
}
+#endif
return res ;
}
if ( str == NULL )
return ;
- if ( fnt == NULL )
- fnt = GLUT_BITMAP_9_BY_15 ;
+ glRasterPos2f((float)x, (float)y);
+
+#ifdef PU_NOT_USING_GLUT
+ /*
+ Display a string:
+ indicate start of glyph display lists
+ */
- glRasterPos2f ( x, y ) ;
+ glListBase (fontBase);
+
+ /* Now draw the characters in a string */
+
+ int len = strlen(str);
+ glCallLists(len, GL_UNSIGNED_BYTE, str);
+ glListBase(0);
+#else
+ if ( fnt == NULL )
+ fnt = PUFONT_9_BY_15 ;
while ( *str != '\0' )
{
glutBitmapCharacter ( fnt, *str ) ;
str++ ;
}
+#endif
}
puPushInterface ( base_interface ) ;
puPushLiveInterface ( base_interface ) ;
firsttime = FALSE ;
+#ifdef PU_NOT_USING_GLUT
+
+ /* Create bitmaps for the device context font's first 256 glyphs */
+
+ fontBase = glGenLists(256);
+ assert(fontBase);
+ HDC hdc = wglGetCurrentDC();
+
+ /* Make the system font the device context's selected font */
+
+ SelectObject (hdc, GetStockObject (SYSTEM_FONT));
+
+ int *tempSize = &fontSize[1];
+
+ if ( ! GetCharWidth32 ( hdc, 1, 255, tempSize ) )
+ {
+ LPVOID lpMsgBuf ;
+
+ FormatMessage ( FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM,
+ NULL,
+ GetLastError(),
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPTSTR) &lpMsgBuf,
+ 0, NULL ) ;
+
+ fprintf ( stderr, "PUI: Error: %s\n" (char *)lpMsgBuf ) ;
+ LocalFree ( lpMsgBuf ) ;
+ }
+ wglUseFontBitmaps ( hdc, 0, 256, fontBase ) ;
+#endif
}
}
static void puSetOpenGLState ( void )
{
- int w = glutGet ( (GLenum) GLUT_WINDOW_WIDTH ) ;
- int h = glutGet ( (GLenum) GLUT_WINDOW_HEIGHT ) ;
+ int w = puGetWindowWidth () ;
+ int h = puGetWindowHeight () ;
glPushAttrib ( GL_ENABLE_BIT | GL_VIEWPORT_BIT | GL_TRANSFORM_BIT ) ;
glDisable ( GL_LIGHTING ) ;
puSetOpenGLState () ;
puGetUltimateLiveInterface () -> draw ( 0, 0 ) ;
+ int h = puGetWindowHeight () ;
+
if ( _puCursor_enable )
puDrawCursor ( _puCursor_x,
- glutGet((GLenum)GLUT_WINDOW_HEIGHT) - _puCursor_y ) ;
+ h - _puCursor_y ) ;
puRestoreOpenGLState () ;
}
static int last_buttons = 0 ;
-
int puMouse ( int button, int updown, int x, int y )
{
puCursor ( x, y ) ;
+ int h = puGetWindowHeight () ;
+
if ( updown == PU_DOWN )
last_buttons |= ( 1 << button ) ;
else
last_buttons &= ~( 1 << button ) ;
return puGetBaseLiveInterface () -> checkHit ( button, updown, x,
- glutGet((GLenum)GLUT_WINDOW_HEIGHT) - y ) ;
+ h - y ) ;
}
int puMouse ( int x, int y )
(last_buttons & (1<<PU_MIDDLE_BUTTON)) ? PU_MIDDLE_BUTTON :
(last_buttons & (1<<PU_RIGHT_BUTTON )) ? PU_RIGHT_BUTTON : 0 ;
+ int h = puGetWindowHeight () ;
+
return puGetBaseLiveInterface () -> checkHit ( button, PU_DRAG, x,
- glutGet((GLenum)GLUT_WINDOW_HEIGHT) - y ) ;
+ h - y ) ;
}
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+
+#ifdef PU_NOT_USING_GLUT
+#include <windows.h>
+#include <GL/gl.h>
+#include <GL/glu.h>
+#else
#include <GL/glut.h>
+#endif
#ifndef TRUE
#define TRUE 1
typedef void *puFont ;
+#ifdef PU_NOT_USING_GLUT
+#define PU_LEFT_BUTTON 0
+#define PU_LEFT_BUTTON 0
+#define PU_MIDDLE_BUTTON 1
+#define PU_RIGHT_BUTTON 2
+#define PU_DOWN 0
+#define PU_UP 1
+
+#define PUFONT_8_BY_13 ((void*)3)
+#define PUFONT_9_BY_15 ((void*)2)
+#define PUFONT_TIMES_ROMAN_10 ((void*)4)
+#define PUFONT_TIMES_ROMAN_24 ((void*)5)
+#define PUFONT_HELVETICA_10 ((void*)6)
+#define PUFONT_HELVETICA_12 ((void*)7)
+#define PUFONT_HELVETICA_18 ((void*)8)
+
+#else
+
#define PUFONT_8_BY_13 GLUT_BITMAP_8_BY_13
#define PUFONT_9_BY_15 GLUT_BITMAP_9_BY_15
#define PUFONT_TIMES_ROMAN_10 GLUT_BITMAP_TIMES_ROMAN_10
#define PUFONT_HELVETICA_12 GLUT_BITMAP_HELVETICA_12
#define PUFONT_HELVETICA_18 GLUT_BITMAP_HELVETICA_18
-#define PU_LEFT_BUTTON GLUT_LEFT_BUTTON
-#define PU_MIDDLE_BUTTON GLUT_MIDDLE_BUTTON
-#define PU_RIGHT_BUTTON GLUT_RIGHT_BUTTON
-#define PU_DOWN GLUT_DOWN
-#define PU_UP GLUT_UP
+#define PU_LEFT_BUTTON GLUT_LEFT_BUTTON
+#define PU_MIDDLE_BUTTON GLUT_MIDDLE_BUTTON
+#define PU_RIGHT_BUTTON GLUT_RIGHT_BUTTON
+#define PU_DOWN GLUT_DOWN
+#define PU_UP GLUT_UP
+#endif // PU_NOT_USING_GLUT
+
#define PU_UP_AND_DOWN 254
#define PU_DRAG 255
#define PU_CONTINUAL PU_DRAG
#define PU_KEY_GLUT_SPECIAL_OFFSET 256
+
+#ifdef PU_NOT_USING_GLUT
+#define PU_KEY_F1 (1 + PU_KEY_GLUT_SPECIAL_OFFSET)
+#define PU_KEY_F2 (2 + PU_KEY_GLUT_SPECIAL_OFFSET)
+#define PU_KEY_F3 (3 + PU_KEY_GLUT_SPECIAL_OFFSET)
+#define PU_KEY_F4 (4 + PU_KEY_GLUT_SPECIAL_OFFSET)
+#define PU_KEY_F5 (5 + PU_KEY_GLUT_SPECIAL_OFFSET)
+#define PU_KEY_F6 (6 + PU_KEY_GLUT_SPECIAL_OFFSET)
+#define PU_KEY_F7 (7 + PU_KEY_GLUT_SPECIAL_OFFSET)
+#define PU_KEY_F8 (8 + PU_KEY_GLUT_SPECIAL_OFFSET)
+#define PU_KEY_F9 (9 + PU_KEY_GLUT_SPECIAL_OFFSET)
+#define PU_KEY_F10 (10 + PU_KEY_GLUT_SPECIAL_OFFSET)
+#define PU_KEY_F11 (11 + PU_KEY_GLUT_SPECIAL_OFFSET)
+#define PU_KEY_F12 (12 + PU_KEY_GLUT_SPECIAL_OFFSET)
+#define PU_KEY_LEFT (100 + PU_KEY_GLUT_SPECIAL_OFFSET)
+#define PU_KEY_UP (101 + PU_KEY_GLUT_SPECIAL_OFFSET)
+#define PU_KEY_RIGHT (102 + PU_KEY_GLUT_SPECIAL_OFFSET)
+#define PU_KEY_DOWN (103 + PU_KEY_GLUT_SPECIAL_OFFSET)
+#define PU_KEY_PAGE_UP (104 + PU_KEY_GLUT_SPECIAL_OFFSET)
+#define PU_KEY_PAGE_DOWN (105 + PU_KEY_GLUT_SPECIAL_OFFSET)
+#define PU_KEY_HOME (106 + PU_KEY_GLUT_SPECIAL_OFFSET)
+#define PU_KEY_END (107 + PU_KEY_GLUT_SPECIAL_OFFSET)
+#define PU_KEY_INSERT (108 + PU_KEY_GLUT_SPECIAL_OFFSET)
+
+#else
#define PU_KEY_F1 (GLUT_KEY_F1 + PU_KEY_GLUT_SPECIAL_OFFSET)
#define PU_KEY_F2 (GLUT_KEY_F2 + PU_KEY_GLUT_SPECIAL_OFFSET)
#define PU_KEY_F3 (GLUT_KEY_F3 + PU_KEY_GLUT_SPECIAL_OFFSET)
#define PU_KEY_HOME (GLUT_KEY_HOME + PU_KEY_GLUT_SPECIAL_OFFSET)
#define PU_KEY_END (GLUT_KEY_END + PU_KEY_GLUT_SPECIAL_OFFSET)
#define PU_KEY_INSERT (GLUT_KEY_INSERT + PU_KEY_GLUT_SPECIAL_OFFSET)
+#endif // PU_NOT_USING_GLUT
#define PUPLACE_DEFAULT PUPLACE_RIGHT
#define PUPLACE_ABOVE 0
/* These styles may be negated to get 'highlighted' graphics */
-#define PUSTYLE_DEFAULT PUSTYLE_BEVELLED
+#define PUSTYLE_DEFAULT PUSTYLE_SHADED
#define PUSTYLE_NONE 0
#define PUSTYLE_PLAIN 1
#define PUSTYLE_BEVELLED 2
#define PUSTYLE_SPECIAL_UNDERLINED 5
#define PUSTYLE_SMALL_BEVELLED 6
#define PUSTYLE_RADIO 7
-#define PUSTYLE_MAX 8
+#define PUSTYLE_SHADED 8
+#define PUSTYLE_SMALL_SHADED 9
+#define PUSTYLE_MAX 10
/* These are the gaps that we try to leave around text objects */
#define PUCLASS_SLIDER 0x00001000
#define PUCLASS_DIALOGBOX 0x00002000
+/* This function is not required for GLUT programs */
+void puSetWindowSize ( int width, int height ) ;
+
+int puGetWindowHeight () ;
+int puGetWindowWidth () ;
+
class puValue ;
class puObject ;
class puInterface ;
else
{
integer = atoi(s) ;
- floater = atof(s) ;
+ floater = (float)atof(s) ;
if ( string != s ) strcpy ( string, s ) ;
}
}
void setCBMode ( int m ) { cb_mode = m ; }
- float getCBMode ( void ) { return cb_mode ; }
+ float getCBMode ( void ) { return (float)cb_mode ; }
int isVertical ( void ) { return vert ; }
- void setDelta ( float f ) { cb_delta = (f<=0.0f) ? 0.1f : (f>=1.0) ? 0.9 : f ; }
+ void setDelta ( float f ) { cb_delta = (f<=0.0f) ? 0.1f : (f>=1.0f) ? 0.9f : f ; }
float getDelta ( void ) { return cb_delta ; }
- void setSliderFraction ( float f ) { slider_fraction = (f<=0.0f) ? 0.1f : (f>=1.0) ? 0.9 : f ; }
+ void setSliderFraction ( float f ) { slider_fraction = (f<=0.0f) ? 0.1f : (f>=1.0f) ? 0.9f : f ; }
float getSliderFraction ( void ) { return slider_fraction ; }
} ;
void close ( void ) ;
} ;
-
class puMenuBar : public puInterface
{
protected:
public:
puMenuBar ( int h = -1 ) :
- puInterface ( 0, h < 0 ? glutGet((GLenum) GLUT_WINDOW_HEIGHT ) -
+
+ puInterface ( 0, h < 0 ? puGetWindowHeight() -
( puGetStringHeight() + PUSTR_TGAP + PUSTR_BGAP ) : h )
{
type |= PUCLASS_MENUBAR ;
select_start_position = -1 ;
select_end_position = -1 ;
- setColourScheme ( 0.8, 0.7, 0.7 ) ; /* Yeukky Pink */
+ setColourScheme ( 0.8f, 0.7f, 0.7f ) ; /* Yeukky Pink */
}
} ;
+
#include "puLocal.h"
#define PU_BEVEL 5
#define PU_SMALL_BEVEL 2
#define PU_DFLT_OFFSET 8
#define PU_BOX_WIDTH 2
-#define PU_DROPSHADOW_OFFSET 10
+#define PU_DROPSHADOW_OFFSET 5
void puBox::extend ( puBox *bx )
{
lo = PUCOL_BACKGROUND ;
break ;
+ case PUSTYLE_SMALL_SHADED :
+ case PUSTYLE_SHADED :
case PUSTYLE_SMALL_BEVELLED :
case PUSTYLE_BEVELLED :
case PUSTYLE_BOXED :
case -PUSTYLE_SMALL_BEVELLED :
case -PUSTYLE_BEVELLED :
+ case -PUSTYLE_SMALL_SHADED :
+ case -PUSTYLE_SHADED :
case -PUSTYLE_BOXED :
case -PUSTYLE_SPECIAL_UNDERLINED :
mid = PUCOL_FOREGROUND ;
break ;
case PUSTYLE_SMALL_BEVELLED :
+ case PUSTYLE_SMALL_SHADED :
glColor4fv ( colour [ hi ] ) ;
glBegin ( GL_QUAD_STRIP ) ;
glVertex2i ( dx + min[0] + PU_SMALL_BEVEL, dy + min[1] + PU_SMALL_BEVEL ) ;
glVertex2i ( dx + max[0], dy + max[1] ) ;
glVertex2i ( dx + max[0] - PU_SMALL_BEVEL, dy + max[1] - PU_SMALL_BEVEL ) ;
glEnd () ;
- glColor4fv ( colour [ mid ] ) ;
- glRecti ( dx + min[0] + PU_SMALL_BEVEL, dy + min[1] + PU_SMALL_BEVEL,
- dx + max[0] - PU_SMALL_BEVEL, dy + max[1] - PU_SMALL_BEVEL ) ;
+
+ if ( abs(style) == PUSTYLE_SMALL_BEVELLED )
+ {
+ glColor4fv ( colour [ mid ] ) ;
+ glRecti ( dx + min[0] + PU_SMALL_BEVEL, dy + min[1] + PU_SMALL_BEVEL,
+ dx + max[0] - PU_SMALL_BEVEL, dy + max[1] - PU_SMALL_BEVEL ) ;
+ }
+ else
+ {
+ glShadeModel(GL_SMOOTH);
+ glBegin(GL_POLYGON);
+ glColor4fv( colour [ mid ] );
+ glVertex2i( dx + min[0] + PU_SMALL_BEVEL , dy + min[1] + PU_SMALL_BEVEL );
+ if(style==PUSTYLE_SMALL_SHADED)
+ glColor4f( colour [mid][0] + (colour[lo][0] - colour[mid][0])/2.0,
+ colour [mid][1] + (colour[lo][1] - colour[mid][1])/2.0,
+ colour [mid][2] + (colour[lo][2] - colour[mid][2])/2.0,
+ colour [lo][3] );
+ else
+ glColor4f( colour [mid][0] + (colour[hi][0] - colour[mid][0])/2.0,
+ colour [mid][1] + (colour[hi][1] - colour[mid][1])/2.0,
+ colour [mid][2] + (colour[hi][2] - colour[mid][2])/2.0,
+ colour [hi][3] );
+ glVertex2i( dx + min[0] + PU_SMALL_BEVEL , dy + max[1] - PU_SMALL_BEVEL );
+ glColor4fv( colour [ mid ] );
+ glVertex2i( dx + max[0] - PU_SMALL_BEVEL , dy + max[1] - PU_SMALL_BEVEL );
+ if(style==-PUSTYLE_SMALL_SHADED)
+ glColor4f( colour [mid][0] + (colour[lo][0] - colour[mid][0])/2.0,
+ colour [mid][1] + (colour[lo][1] - colour[mid][1])/2.0,
+ colour [mid][2] + (colour[lo][2] - colour[mid][2])/2.0,
+ colour [lo][3] );
+ else
+ glColor4f( colour [mid][0] + (colour[hi][0] - colour[mid][0])/2.0,
+ colour [mid][1] + (colour[hi][1] - colour[mid][1])/2.0,
+ colour [mid][2] + (colour[hi][2] - colour[mid][2])/2.0,
+ colour [hi][3] );
+ glVertex2i( dx + max[0] - PU_SMALL_BEVEL , dy + min[1] + PU_SMALL_BEVEL );
+ glEnd();
+ glShadeModel(GL_FLAT);
+
+ if(style == -PUSTYLE_SMALL_SHADED)
+ {
+ glColor4fv ( colour [ lo ] ) ;
+ glBegin ( GL_QUAD_STRIP ) ;
+ glVertex2i ( dx + min[0] + PU_SMALL_BEVEL , dy + min[1] + PU_SMALL_BEVEL ) ;
+ glVertex2i ( dx + min[0] + PU_SMALL_BEVEL/2 , dy + min[1] + PU_SMALL_BEVEL/2 ) ;
+ glVertex2i ( dx + min[0] + PU_SMALL_BEVEL , dy + max[1] - PU_SMALL_BEVEL ) ;
+ glVertex2i ( dx + min[0] + PU_SMALL_BEVEL/2 , dy + max[1] - PU_SMALL_BEVEL/2 ) ;
+ glVertex2i ( dx + max[0] - PU_SMALL_BEVEL , dy + max[1] - PU_SMALL_BEVEL ) ;
+ glVertex2i ( dx + max[0] - PU_SMALL_BEVEL/2 , dy + max[1] - PU_SMALL_BEVEL/2 ) ;
+ glEnd () ;
+ glColor4fv ( colour [ hi ] ) ;
+ glBegin ( GL_QUAD_STRIP ) ;
+ glVertex2i ( dx + min[0] + PU_SMALL_BEVEL/2 , dy + min[1] + PU_SMALL_BEVEL/2 ) ;
+ glVertex2i ( dx + min[0] + PU_SMALL_BEVEL , dy + min[1] + PU_SMALL_BEVEL ) ;
+ glVertex2i ( dx + max[0] - PU_SMALL_BEVEL/2 , dy + min[1] + PU_SMALL_BEVEL/2 ) ;
+ glVertex2i ( dx + max[0] - PU_SMALL_BEVEL , dy + min[1] + PU_SMALL_BEVEL ) ;
+ glVertex2i ( dx + max[0] - PU_SMALL_BEVEL/2 , dy + max[1] - PU_SMALL_BEVEL/2 ) ;
+ glVertex2i ( dx + max[0] - PU_SMALL_BEVEL , dy + max[1] - PU_SMALL_BEVEL ) ;
+ glEnd () ;
+ }
+ }
break ;
case PUSTYLE_BEVELLED :
+ case PUSTYLE_SHADED :
glColor4fv ( colour [ hi ] ) ;
glBegin ( GL_QUAD_STRIP ) ;
glVertex2i ( dx + min[0] + PU_BEVEL, dy + min[1] + PU_BEVEL ) ;
glVertex2i ( dx + max[0], dy + max[1] ) ;
glVertex2i ( dx + max[0] - PU_BEVEL, dy + max[1] - PU_BEVEL ) ;
glEnd () ;
- glColor4fv ( colour [ mid ] ) ;
- glRecti ( dx + min[0] + PU_BEVEL, dy + min[1] + PU_BEVEL,
- dx + max[0] - PU_BEVEL, dy + max[1] - PU_BEVEL ) ;
+
+ if ( abs(style) == PUSTYLE_BEVELLED )
+ {
+ glColor4fv ( colour [ mid ] ) ;
+ glRecti ( dx + min[0] + PU_BEVEL, dy + min[1] + PU_BEVEL,
+ dx + max[0] - PU_BEVEL, dy + max[1] - PU_BEVEL ) ;
+ }
+ else
+ {
+ glShadeModel(GL_SMOOTH);
+ glBegin(GL_POLYGON);
+ glColor4fv( colour [ mid ] );
+ glVertex2i( dx + min[0] + PU_BEVEL , dy + min[1] + PU_BEVEL );
+ if(style==PUSTYLE_SHADED)
+ glColor4f( colour [mid][0] + (colour[lo][0] - colour[mid][0])/2.0,
+ colour [mid][1] + (colour[lo][1] - colour[mid][1])/2.0,
+ colour [mid][2] + (colour[lo][2] - colour[mid][2])/2.0,
+ colour [lo][3] );
+ else
+ glColor4f( colour [mid][0] + (colour[hi][0] - colour[mid][0])/2.0,
+ colour [mid][1] + (colour[hi][1] - colour[mid][1])/2.0,
+ colour [mid][2] + (colour[hi][2] - colour[mid][2])/2.0,
+ colour [hi][3] );
+ glVertex2i( dx + min[0] + PU_BEVEL , dy + max[1] - PU_BEVEL );
+ glColor4fv( colour [ mid ] );
+ glVertex2i( dx + max[0] - PU_BEVEL , dy + max[1] - PU_BEVEL );
+ if(style==-PUSTYLE_SHADED)
+ glColor4f( colour [mid][0] + (colour[lo][0] - colour[mid][0])/2.0,
+ colour [mid][1] + (colour[lo][1] - colour[mid][1])/2.0,
+ colour [mid][2] + (colour[lo][2] - colour[mid][2])/2.0,
+ colour [lo][3] );
+ else
+ glColor4f( colour [mid][0] + (colour[hi][0] - colour[mid][0])/2.0,
+ colour [mid][1] + (colour[hi][1] - colour[mid][1])/2.0,
+ colour [mid][2] + (colour[hi][2] - colour[mid][2])/2.0,
+ colour [hi][3] );
+ glVertex2i( dx + max[0] - PU_BEVEL , dy + min[1] + PU_BEVEL );
+ glEnd();
+ glShadeModel(GL_FLAT);
+
+ if(style == -PUSTYLE_SHADED)
+ {
+ glColor4fv ( colour [ lo ] ) ;
+ glBegin ( GL_QUAD_STRIP ) ;
+ glVertex2i ( dx + min[0] + PU_BEVEL , dy + min[1] + PU_BEVEL ) ;
+ glVertex2i ( dx + min[0] + PU_BEVEL/2 , dy + min[1] + PU_BEVEL/2 ) ;
+ glVertex2i ( dx + min[0] + PU_BEVEL , dy + max[1] - PU_BEVEL ) ;
+ glVertex2i ( dx + min[0] + PU_BEVEL/2 , dy + max[1] - PU_BEVEL/2 ) ;
+ glVertex2i ( dx + max[0] - PU_BEVEL , dy + max[1] - PU_BEVEL ) ;
+ glVertex2i ( dx + max[0] - PU_BEVEL/2 , dy + max[1] - PU_BEVEL/2 ) ;
+ glEnd () ;
+ glColor4fv ( colour [ hi ] ) ;
+ glBegin ( GL_QUAD_STRIP ) ;
+ glVertex2i ( dx + min[0] + PU_BEVEL/2 , dy + min[1] + PU_BEVEL/2 ) ;
+ glVertex2i ( dx + min[0] + PU_BEVEL , dy + min[1] + PU_BEVEL ) ;
+ glVertex2i ( dx + max[0] - PU_BEVEL/2 , dy + min[1] + PU_BEVEL/2 ) ;
+ glVertex2i ( dx + max[0] - PU_BEVEL , dy + min[1] + PU_BEVEL ) ;
+ glVertex2i ( dx + max[0] - PU_BEVEL/2 , dy + max[1] - PU_BEVEL/2 ) ;
+ glVertex2i ( dx + max[0] - PU_BEVEL , dy + max[1] - PU_BEVEL ) ;
+ glEnd () ;
+ }
+ }
break ;
case PUSTYLE_BOXED :
}
+
glColor4f ( colour [ PUCOL_LEGEND ][0],
colour [ PUCOL_LEGEND ][1],
colour [ PUCOL_LEGEND ][2],
- colour [ PUCOL_LEGEND ][3] / 2.0 ) ; /* 50% more transparent */
+ colour [ PUCOL_LEGEND ][3] / 2.0f ) ; /* 50% more transparent */
int xx = ( abox.max[0] - abox.min[0] - puGetStringWidth(legendFont,legend) ) / 2 ;
int yy = ( abox.max[1] - abox.min[1] - puGetStringHeight(legendFont) ) / 2 ;
glColor4f ( colour [ PUCOL_LEGEND ][0],
colour [ PUCOL_LEGEND ][1],
colour [ PUCOL_LEGEND ][2],
- colour [ PUCOL_LEGEND ][3] / 2.0 ) ; /* 50% more transparent */
+ colour [ PUCOL_LEGEND ][3] / 2.0f ) ; /* 50% more transparent */
puDrawString ( legendFont, button_labels[i],
dx + tbox.min[0] + PU_RADIO_BUTTON_SIZE + PUSTR_LGAP,
glColor4f ( colour [ PUCOL_LEGEND ][0],
colour [ PUCOL_LEGEND ][1],
colour [ PUCOL_LEGEND ][2],
- colour [ PUCOL_LEGEND ][3] / 2.0 ) ; /* 50% more transparent */
+ colour [ PUCOL_LEGEND ][3] / 2.0f ) ; /* 50% more transparent */
int xx = ( abox.max[0] - abox.min[0] - puGetStringWidth ( legendFont, legend ) ) / 2 ;
/* 3D Input boxes look nicest if they are always in inverse style. */
- abox . draw ( dx, dy, (style==PUSTYLE_SMALL_BEVELLED) ? -style :
+ abox . draw ( dx, dy, ( (style==PUSTYLE_SMALL_BEVELLED ||
+ style==PUSTYLE_SMALL_SHADED) ) ? -style :
(accepting ? -style : style ), colour, FALSE ) ;
int xx = puGetStringWidth ( legendFont, " " ) ;
val [ select_start_position ] = '\0' ;
int cpos1 = puGetStringWidth ( legendFont, val ) + xx + dx + abox.min[0] ;
- glColor3f ( 1.0, 1.0, 0.7 ) ;
+ glColor3f ( 1.0f, 1.0f, 0.7f ) ;
glRecti ( cpos1, dy + abox.min[1] + 6 ,
cpos2, dy + abox.max[1] - 6 ) ;
}
glColor4f ( colour [ PUCOL_LEGEND ][0],
colour [ PUCOL_LEGEND ][1],
colour [ PUCOL_LEGEND ][2],
- colour [ PUCOL_LEGEND ][3] / 2.0 ) ; /* 50% more transparent */
+ colour [ PUCOL_LEGEND ][3] / 2.0f ) ; /* 50% more transparent */
char val [ PUSTRING_MAX ] ;
getValue ( val ) ;
int cpos = puGetStringWidth ( legendFont, val ) + xx + dx + abox.min[0] ;
- glColor3f ( 0.1, 0.1, 1.0 ) ;
+ glColor3f ( 0.1f, 0.1f, 1.0f ) ;
glBegin ( GL_LINES ) ;
glVertex2i ( cpos , dy + abox.min[1] + 7 ) ;
glVertex2i ( cpos , dy + abox.max[1] - 7 ) ;
void puInterface::draw ( int dx, int dy )
{
- if ( isVisible () )
- for ( puObject *bo = dlist ; bo != NULL ; bo = bo->next )
- bo -> draw ( dx + abox.min[0], dy + abox.min[1] ) ;
+ if ( ! isVisible () )
+ return ;
+
+ for ( puObject *bo = dlist ; bo != NULL ; bo = bo->next )
+ {
+ /* June 16th, 98, Shammi :
+ * The next if statement checks if the object is
+ * a menu bar and makes sure it is repositioned
+ * correctly.
+ */
+
+ if ( bo->getType() & PUCLASS_MENUBAR )
+ {
+ int obWidth, obHeight ;
+ bo -> getSize ( &obWidth, &obHeight ) ;
+ bo -> setPosition ( 0, puGetWindowHeight() - obHeight ) ;
+ }
+
+ bo -> draw ( dx + abox.min[0], dy + abox.min[1] ) ;
+ }
}
}
+
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#endif
#include <math.h>
+
+#ifndef PU_NOT_USING_GLUT
#include <GL/glut.h>
+#endif
#include "pu.h"
inline float clamp01 ( float x )
{
- return (x >= 1.0) ? 1.0 : x ;
+ return (x >= 1.0f) ? 1.0f : x ;
}
static void load_colour_scheme ( float col[][4], float r, float g,
{
puSetColour ( col [ PUCOL_FOREGROUND ], r, g, b, a ) ;
puSetColour ( col [ PUCOL_BACKGROUND ], r/2, g/2, b/2, a ) ;
- puSetColour ( col [ PUCOL_HIGHLIGHT ], clamp01(r*1.3), clamp01(g*1.3),
- clamp01(b*1.3), a ) ;
+ puSetColour ( col [ PUCOL_HIGHLIGHT ], clamp01(r*1.3f), clamp01(g*1.3f),
+ clamp01(b*1.3f), a ) ;
if ( 4 * g + 3 * r + b > 0.5 )
puSetColour ( col [ PUCOL_LEGEND ], 0.0, 0.0, 0.0, a ) ;
glColor4f ( colour [ PUCOL_LABEL ][0],
colour [ PUCOL_LABEL ][1],
colour [ PUCOL_LABEL ][2],
- colour [ PUCOL_LABEL ][3] / 2.0 ) ; /* 50% more transparent */
+ colour [ PUCOL_LABEL ][3] / 2.0f ) ; /* 50% more transparent */
switch ( labelPlace )
{
if ( !visible ) return ;
abox . draw ( dx, dy,
- style==PUSTYLE_BEVELLED ? -PUSTYLE_BOXED : -style,
+ (style==PUSTYLE_BEVELLED||
+ style==PUSTYLE_SHADED) ? -PUSTYLE_BOXED : -style,
colour, FALSE ) ;
int sd, od ;
bx . min [ od ] = abox . min [ od ] + 2 ;
bx . max [ od ] = abox . max [ od ] - 2 ;
- bx . draw ( dx, dy, PUSTYLE_SMALL_BEVELLED, colour, FALSE ) ;
+ bx . draw ( dx, dy, PUSTYLE_SMALL_SHADED, colour, FALSE ) ;
/* If greyed out then halve the opacity when drawing the label and legend */
glColor4f ( colour [ PUCOL_LEGEND ][0],
colour [ PUCOL_LEGEND ][1],
colour [ PUCOL_LEGEND ][2],
- colour [ PUCOL_LEGEND ][3] / 2.0 ) ; /* 50% more transparent */
+ colour [ PUCOL_LEGEND ][3] / 2.0f ) ; /* 50% more transparent */
int xx = ( abox.max[0] - abox.min[0] - puGetStringWidth(legendFont,legend) ) / 2 ;
int yy = ( abox.max[1] - abox.min[1] - puGetStringHeight(legendFont) ) / 2 ;