1 /****************************************************************************
3 GLUI User Interface Toolkit
4 ---------------------------
6 glui_button.cpp - GLUI_Button control class
9 --------------------------------------------------
11 Copyright (c) 1998 Paul Rademacher
13 WWW: http://sourceforge.net/projects/glui/
14 Forums: http://sourceforge.net/forum/?group_id=92496
16 This library is free software; you can redistribute it and/or
17 modify it under the terms of the GNU Lesser General Public
18 License as published by the Free Software Foundation; either
19 version 2.1 of the License, or (at your option) any later version.
21 This library is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 Lesser General Public License for more details.
26 You should have received a copy of the GNU Lesser General Public
27 License along with this library; if not, write to the Free Software
28 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 *****************************************************************************/
31 #include "glui_internal_control.h"
33 /****************************** GLUI_Button::GLUI_Button() **********/
35 GLUI_Button::GLUI_Button( GLUI_Node *parent, const char *name,
42 currently_inside = false;
44 parent->add_control( this );
48 /****************************** GLUI_Button::mouse_down_handler() **********/
50 int GLUI_Button::mouse_down_handler( int local_x, int local_y )
52 int_val = 1; /** A button always in unpressed before here, so
53 now we invariably set it to 'depressed' **/
55 currently_inside = true;
62 /****************************** GLUI_Button::mouse_up_handler() **********/
64 int GLUI_Button::mouse_up_handler( int local_x, int local_y, bool inside )
66 set_int_val( 0 ); /** A button always turns off after you press it **/
68 currently_inside = false;
72 /*** Invoke the user's callback ***/
80 /****************************** GLUI_Button::mouse_held_down_handler() ******/
82 int GLUI_Button::mouse_held_down_handler( int local_x, int local_y,
85 if (new_inside != currently_inside) {
86 currently_inside = new_inside;
94 /****************************** GLUI_Button::key_handler() **********/
96 int GLUI_Button::key_handler( unsigned char key,int modifiers )
101 /********************************************** GLUI_Button::draw() **********/
103 void GLUI_Button::draw( int x, int y )
105 if (currently_inside) draw_pressed();
107 glui->draw_raised_box( 0, 0, w, h );
113 /************************************** GLUI_Button::draw_pressed() ******/
115 void GLUI_Button::draw_pressed( void )
117 glColor3f( 0.0, 0.0, 0.0 );
121 glBegin( GL_LINE_LOOP );
122 glVertex2i( 0, 0 ); glVertex2i( w, 0 );
123 glVertex2i( w, h ); glVertex2i( 0, h );
126 glBegin( GL_LINE_LOOP );
127 glVertex2i( 1, 1 ); glVertex2i( w-1, 1 );
128 glVertex2i( w-1, h-1 ); glVertex2i( 1, h-1 );
133 /**************************************** GLUI_Button::draw_text() **********/
135 void GLUI_Button::draw_text( int sunken )
139 glColor3ub( glui->bkgd_color.r, glui->bkgd_color.g, glui->bkgd_color.b );
140 glDisable( GL_CULL_FACE );
142 glVertex2i( 2, 2 ); glVertex2i( w-2, 2 );
143 glVertex2i( w-2, h-2 ); glVertex2i( 2, h-2 );
148 string_width = _glutBitmapWidthString( glui->font,
149 this->name.c_str() );
151 draw_name( MAX((w-string_width),0)/2, 13);
154 draw_name( MAX((w-string_width),0)/2 + 1, 13 + 1);
158 glEnable( GL_LINE_STIPPLE );
159 glLineStipple( 1, 0x5555 );
161 glColor3f( 0., 0., 0. );
163 glBegin( GL_LINE_LOOP );
164 glVertex2i( 3, 3 ); glVertex2i( w-3, 3 );
165 glVertex2i( w-3, h-3 ); glVertex2i( 3, h-3 );
168 glDisable( GL_LINE_STIPPLE );
173 /************************************** GLUI_Button::update_size() **********/
175 void GLUI_Button::update_size( void )
182 text_size = string_width( name );
184 if ( w < text_size + 16 )