[Plib-cvs] plib/src/pui puRange.cxx,NONE,1.1 puSpinBox.cxx,NONE,1.1 Makefile.am,1.13,1.14 pu.h,1.113
Brought to you by:
sjbaker
Update of /cvsroot/plib/plib/src/pui In directory usw-pr-cvs1:/tmp/cvs-serv11761 Modified Files: Makefile.am pu.h puArrowButton.cxx puBiSlider.cxx puDial.cxx puSlider.cxx puTriSlider.cxx Added Files: puRange.cxx puSpinBox.cxx Log Message: Added new class: puRange. Added new widget: puSpinBox. Updated all previous "slider" widgets to now use the functions contained within puRange. --- NEW FILE: puRange.cxx --- /* PLIB - A Suite of Portable Game Libraries Copyright (C) 2001 Steve Baker This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA For further information visit http://plib.sourceforge.net */ #include "puLocal.h" --- NEW FILE: puSpinBox.cxx --- /* PLIB - A Suite of Portable Game Libraries Copyright (C) 2001 Steve Baker This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA For further information visit http://plib.sourceforge.net [...88 lines suppressed...] input_box->setValue ( getFloatValue () ) ; } puSetActiveWidget ( this, x, y ) ; invokeCallback () ; } } int puSpinBox::checkKey ( int key, int updown ) { input_box->checkKey ( key, updown ) ; setValue ( input_box->getFloatValue () ) ; if ( getFloatValue () > getMaxValue () ) setValue ( getMaxValue () ) ; else if ( getFloatValue () < getMinValue () ) setValue ( getMinValue () ) ; invokeCallback () ; return TRUE ; } Index: Makefile.am =================================================================== RCS file: /cvsroot/plib/plib/src/pui/Makefile.am,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- Makefile.am 25 Oct 2001 20:30:38 -0000 1.13 +++ Makefile.am 12 Jul 2002 02:57:19 -0000 1.14 @@ -10,7 +10,8 @@ puFilePicker.cxx puListBox.cxx puSlider.cxx puText.cxx \ puValue.cxx puFont.cxx puBiSlider.cxx puTriSlider.cxx \ puDial.cxx puVerticalMenu.cxx puLargeInput.cxx \ - puFileSelector.cxx puComboBox.cxx puSelectBox.cxx + puFileSelector.cxx puComboBox.cxx puSelectBox.cxx puRange.cxx \ + puSpinBox.cxx INCLUDES = -I$(top_srcdir)/src/sg -I$(top_srcdir)/src/fnt INCLUDES += -I$(top_srcdir)/src/util Index: pu.h =================================================================== RCS file: /cvsroot/plib/plib/src/pui/pu.h,v retrieving revision 1.113 retrieving revision 1.114 diff -u -d -r1.113 -r1.114 --- pu.h 12 Jul 2002 01:55:16 -0000 1.113 +++ pu.h 12 Jul 2002 02:57:19 -0000 1.114 @@ -326,6 +326,8 @@ #define PUCLASS_LARGEINPUT 0x00400000 #define PUCLASS_COMBOBOX 0x00800000 #define PUCLASS_SELECTBOX 0x01000000 +#define PUCLASS_RANGE 0x02000000 +#define PUCLASS_SPINBOX 0x04000000 /* This function is not required for GLUT programs */ void puSetWindowSize ( int width, int height ) ; @@ -349,6 +351,8 @@ class puPopupMenu ; class puMenuBar ; [...338 lines suppressed...] + { + type |= PUCLASS_SPINBOX ; + if (arrow_pos==1) + input_box = new puInput ( minx, miny, maxx - (maxy-miny)/2, maxy ) ; + else + input_box = new puInput ( minx + (maxy-miny)/2, miny, maxx, maxy ) ; + up_arrow_active = down_arrow_active = 0 ; + arrow_position = arrow_pos ; + arrow_height = 0.5f ; + inbox_height = maxy - miny ; + } + + ~puSpinBox () + { + puDeleteObject ( (puObject *)input_box ) ; // THIS MAY NEED TO CHANGE !!! + } +} ; class puButtonBox : public puObject { Index: puArrowButton.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/pui/puArrowButton.cxx,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- puArrowButton.cxx 10 Nov 2001 13:37:38 -0000 1.13 +++ puArrowButton.cxx 12 Jul 2002 02:57:19 -0000 1.14 @@ -23,6 +23,110 @@ #include "puLocal.h" +void puDrawArrowButtonTriangle ( int pos_x, int pos_y, int size_x, int size_y, + puColour colour, int arrow_type, int active ) +{ + /* + If greyed out then halve the opacity when drawing + the widget + */ + [...186 lines suppressed...] - case PUARROW_FASTRIGHT : - glBegin ( GL_TRIANGLES ) ; - glVertex2i ( pos_x - size_x/4, pos_y - size_y/4 ) ; - glVertex2i ( pos_x , pos_y ) ; - glVertex2i ( pos_x - size_x/4, pos_y + size_y/4 ) ; - - glVertex2i ( pos_x , pos_y - size_y/4 ) ; - glVertex2i ( pos_x + size_x/4, pos_y ) ; - glVertex2i ( pos_x , pos_y + size_y/4 ) ; - glEnd () ; - break; - - default : - ulSetError ( UL_WARNING, "PUI: Unrecognised 'arrow_type' %d", arrow_type ) ; - break; - } + puDrawArrowButtonTriangle ( pos_x, pos_y, size_x, size_y, colour [ PUCOL_MISC ], arrow_type, active ) ; } draw_label ( dx, dy ) ; Index: puBiSlider.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/pui/puBiSlider.cxx,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- puBiSlider.cxx 7 Nov 2001 23:51:09 -0000 1.17 +++ puBiSlider.cxx 12 Jul 2002 02:57:19 -0000 1.18 @@ -51,7 +51,7 @@ char str_value[10] ; sprintf (str_value, "%d", getCurrentMax() ) ; - draw_slider_box ( dx, dy, val, str_value ) ; + draw_slider_box ( dx, dy, abox, val, str_value ) ; // Draw the current_min slider and label it @@ -62,7 +62,7 @@ sprintf (str_value, "%d", getCurrentMin() ) ; - draw_slider_box ( dx, dy, val, str_value ) ; + draw_slider_box ( dx, dy, abox, val, str_value ) ; draw_legend ( dx, dy ) ; } @@ -107,29 +107,29 @@ next_value = (next_value < 0.0f) ? 0.0f : (next_value > 1.0) ? 1.0f : next_value ; - int new_value = getMinValue() + (int)( next_value * ( getMaxValue() - getMinValue() ) + 0.5 ) ; + float new_value = getMinValue() + ( next_value * ( getMaxValue() - getMinValue() ) + 0.5 ) ; if ( ( getActiveButton() == 0 ) || ( updown == PU_DOWN ) ) // No currently-active slider, set whichever is closest { if ( (new_value-getCurrentMin()) < (getCurrentMax()-new_value) ) // Closest to current_min { - setCurrentMin ( new_value ) ; + setCurrentMin ( checkStep(new_value) ) ; setActiveButton ( 1 ) ; } else // Closest to current_max { - setCurrentMax ( new_value ) ; + setCurrentMax ( checkStep(new_value) ) ; setActiveButton ( 2 ) ; } } else if ( getActiveButton() == 1 ) // Currently moving current_min { - setCurrentMin ( new_value ) ; + setCurrentMin ( checkStep(new_value) ) ; if ( getCurrentMax() < getCurrentMin() ) setCurrentMax ( getCurrentMin() ) ; } else if ( getActiveButton() == 2 ) // Currently moving current_max { - setCurrentMax ( new_value ) ; + setCurrentMax ( checkStep(new_value) ) ; if ( getCurrentMax() < getCurrentMin() ) setCurrentMin ( getCurrentMax() ) ; } @@ -145,7 +145,7 @@ } break ; - case PUSLIDER_DELTA : + case PUSLIDER_DELTA :/* Deprecated! */ if ( fabs ( last_cb_value - next_value ) >= cb_delta ) { last_cb_value = next_value ; Index: puDial.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/pui/puDial.cxx,v retrieving revision 1.21 retrieving revision 1.22 diff -u -d -r1.21 -r1.22 --- puDial.cxx 10 Jun 2002 23:10:13 -0000 1.21 +++ puDial.cxx 12 Jul 2002 02:57:19 -0000 1.22 @@ -1,21 +1,21 @@ /* PLIB - A Suite of Portable Game Libraries Copyright (C) 2001 Steve Baker - + This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. - + You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - + For further information visit http://plib.sourceforge.net $Id$ @@ -81,6 +81,7 @@ float val ; getValue ( &val ) ; + val = ( val - minimum_value) / (maximum_value - minimum_value) ; if ( val < 0.0 ) val = 0.0 ; if ( val > 1.0 ) val = 1.0 ; @@ -144,26 +145,27 @@ else if ( ( angle < 0.25 ) && ( getFloatValue () > 0.75 ) ) angle = 1.0 ; } - - setValue ( angle ) ; + + angle = angle * (maximum_value - minimum_value) + minimum_value ; + setValue( checkStep(angle) ) ; switch ( cb_mode ) { case PUSLIDER_CLICK : if ( updown == active_mouse_edge ) { - last_cb_value = angle ; - puSetActiveWidget ( this, x, y ) ; - invokeCallback () ; + last_cb_value = angle ; + puSetActiveWidget ( this, x, y ) ; + invokeCallback () ; } break ; - case PUSLIDER_DELTA : + case PUSLIDER_DELTA :/* Deprecated! */ if ( fabs ( last_cb_value - angle ) >= cb_delta ) { - last_cb_value = angle ; - puSetActiveWidget ( this, x, y ) ; - invokeCallback () ; + last_cb_value = angle ; + puSetActiveWidget ( this, x, y ) ; + invokeCallback () ; } break ; Index: puSlider.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/pui/puSlider.cxx,v retrieving revision 1.22 retrieving revision 1.23 diff -u -d -r1.22 -r1.23 --- puSlider.cxx 1 Mar 2002 14:54:44 -0000 1.22 +++ puSlider.cxx 12 Jul 2002 02:57:19 -0000 1.23 @@ -1,21 +1,21 @@ /* PLIB - A Suite of Portable Game Libraries Copyright (C) 2001 Steve Baker - + This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. - + You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - + For further information visit http://plib.sourceforge.net $Id$ @@ -24,12 +24,12 @@ #include "puLocal.h" -void puSlider::draw_slider_box ( int dx, int dy, float val, const char *box_label ) +void puSlider::draw_slider_box ( int dx, int dy, const puBox &box, float val, const char *box_label ) { int sd, od ; if ( isVertical() ) { sd = 1 ; od = 0 ; } else { sd = 0 ; od = 1 ; } - int sz = abox.max [sd] - abox.min [sd] ; // Size of slider box, in pixels + int sz = box.max [sd] - box.min [sd] ; // Size of slider box, in pixels if ( val < 0.0f ) val = 0.0f ; if ( val > 1.0f ) val = 1.0f ; @@ -38,10 +38,10 @@ puBox bx ; - bx.min [ sd ] = abox.min [ sd ] + (int) val ; + bx.min [ sd ] = box.min [ sd ] + (int) val ; bx.max [ sd ] = (int) ( (float) bx.min [ sd ] + (float) sz * slider_fraction ) ; - bx.min [ od ] = abox.min [ od ] + 2 ; - bx.max [ od ] = abox.max [ od ] - 2 ; + bx.min [ od ] = box.min [ od ] + 2 ; + bx.max [ od ] = box.max [ od ] - 2 ; bx.draw ( dx, dy, PUSTYLE_SMALL_SHADED, colour, FALSE, 2 ) ; @@ -88,11 +88,9 @@ r_cb ( this, dx, dy, render_data ) ; else { - float val ; - - getValue ( & val ) ; + float val = getFloatValue () ; - draw_slider_box ( dx, dy, val ) ; + draw_slider_box ( dx, dy, abox, ( val - minimum_value ) / ( maximum_value - minimum_value ) ) ; draw_legend ( dx, dy ) ; } @@ -135,9 +133,10 @@ } next_value = (next_value < 0.0f) ? 0.0f : (next_value > 1.0f) ? 1.0f : next_value ; + next_value = next_value * ( maximum_value - minimum_value ) + minimum_value ; - setValue ( next_value ) ; - + setValue ( checkStep (next_value) ); + switch ( cb_mode ) { case PUSLIDER_CLICK : @@ -149,7 +148,7 @@ } break ; - case PUSLIDER_DELTA : + case PUSLIDER_DELTA : /* Deprecated! */ if ( fabs ( last_cb_value - next_value ) >= cb_delta ) { last_cb_value = next_value ; Index: puTriSlider.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/pui/puTriSlider.cxx,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- puTriSlider.cxx 10 Jun 2002 18:39:37 -0000 1.18 +++ puTriSlider.cxx 12 Jul 2002 02:57:19 -0000 1.19 @@ -50,7 +50,7 @@ char str_value[10] ; sprintf (str_value, "%d", getIntegerValue () ) ; - draw_slider_box ( dx, dy, val, str_value ) ; + draw_slider_box ( dx, dy, abox, val, str_value ) ; if ( val < 0.0f ) val = 0.0f ; if ( val > 1.0f ) val = 1.0f ; @@ -64,7 +64,7 @@ sprintf (str_value, "%d", getCurrentMax() ) ; [...74 lines suppressed...] { - setCurrentMax ( new_value ) ; + setCurrentMax ( checkStep(new_value) ) ; if ( getIntegerValue() > getCurrentMax() ) setValue ( getCurrentMax() ) ; if ( getCurrentMax() < getCurrentMin() ) setCurrentMin ( getCurrentMax() ) ; } @@ -180,7 +186,7 @@ } break ; - case PUSLIDER_DELTA : + case PUSLIDER_DELTA :/* Deprecated! */ if ( fabs ( last_cb_value - next_value ) >= cb_delta ) { last_cb_value = next_value ; @@ -198,4 +204,3 @@ } } } - |