1
/****************************************************************************
3
GLUI User Interface Toolkit
4
---------------------------
6
glui_button.cpp - GLUI_Button control class
9
--------------------------------------------------
11
Copyright (c) 1998 Paul Rademacher
13
This program is freely distributable without licensing fees and is
14
provided without guarantee or warrantee expressed or implied. This
15
program is -not- in the public domain.
17
*****************************************************************************/
22
/****************************** GLUI_Button::mouse_down_handler() **********/
24
int GLUI_Button::mouse_down_handler( int local_x, int local_y )
26
int_val = 1; /** A button always in unpressed before here, so
27
now we invariably set it to 'depressed' **/
29
currently_inside = true;
37
/****************************** GLUI_Button::mouse_up_handler() **********/
39
int GLUI_Button::mouse_up_handler( int local_x, int local_y, int inside )
41
set_int_val( 0 ); /** A button always turns off after you press it **/
48
/*** Invoke the callback ***/
51
/** Tell the main gfx window to update itself **/
53
glui->post_update_main_gfx();
60
/****************************** GLUI_Button::mouse_held_down_handler() ******/
62
int GLUI_Button::mouse_held_down_handler( int local_x, int local_y,
65
if ( NOT new_inside AND currently_inside == true ) {
68
else if ( new_inside AND currently_inside == false ) {
72
currently_inside = new_inside;
78
/****************************** GLUI_Button::key_handler() **********/
80
int GLUI_Button::key_handler( unsigned char key,int modifiers )
86
/************************************** GLUI_Button::draw_pressed() ******/
88
void GLUI_Button::draw_pressed( void )
95
orig = set_to_glut_window();
96
state = glui->set_front_draw_buffer();
98
glColor3f( 0.0, 0.0, 0.0 );
100
translate_to_origin();
104
glBegin( GL_LINE_LOOP );
105
glVertex2i( 0, 0 ); glVertex2i( w, 0 );
106
glVertex2i( w, h ); glVertex2i( 0, h );
109
glBegin( GL_LINE_LOOP );
110
glVertex2i( 1, 1 ); glVertex2i( w-1, 1 );
111
glVertex2i( w-1, h-1 ); glVertex2i( 1, h-1 );
116
glui->restore_draw_buffer(state);
117
restore_window(orig);
121
/************************************** GLUI_Button::draw_unpressed() ******/
123
void GLUI_Button::draw_unpressed( void )
125
if ( NOT can_draw() )
128
translate_and_draw_front();
134
/********************************************** GLUI_Button::draw() **********/
136
void GLUI_Button::draw( int x, int y )
138
if ( NOT can_draw() )
142
glui->draw_raised_box( 0, 0, w, h );
148
/**************************************** GLUI_Button::draw_text() **********/
150
void GLUI_Button::draw_text( int sunken )
152
int string_width, orig;
154
if ( NOT can_draw() )
157
orig = set_to_glut_window();
159
glColor3ub( glui->bkgd_color.r, glui->bkgd_color.g, glui->bkgd_color.b );
160
glDisable( GL_CULL_FACE );
162
glVertex2i( 2, 2 ); glVertex2i( w-2, 2 );
163
glVertex2i( w-2, h-2 ); glVertex2i( 2, h-2 );
168
string_width = _glutBitmapWidthString( glui->font,
171
draw_name( MAX((w-string_width),0)/2, 13);
174
draw_name( MAX((w-string_width),0)/2 + 1, 13 + 1);
178
glEnable( GL_LINE_STIPPLE );
179
glLineStipple( 1, 0x5555 );
181
glColor3f( 0., 0., 0. );
183
glBegin( GL_LINE_LOOP );
184
glVertex2i( 3, 3 ); glVertex2i( w-3, 3 );
185
glVertex2i( w-3, h-3 ); glVertex2i( 3, h-3 );
188
glDisable( GL_LINE_STIPPLE );
191
restore_window(orig);
195
/************************************** GLUI_Button::update_size() **********/
197
void GLUI_Button::update_size( void )
204
text_size = string_width( name );
206
if ( w < text_size + 16 )