1
/****************************************************************************
3
GLUI User Interface Toolkit
4
---------------------------
6
glui_mouse_iaction - GLUI Mouse Interaction 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
*****************************************************************************/
32
#include "glui_internal_control.h"
34
/********************** GLUI_Mouse_Interaction::mouse_down_handler() ******/
36
int GLUI_Mouse_Interaction::mouse_down_handler( int local_x, int local_y )
38
/* int win_h = glutGet( GLUT_WINDOW_HEIGHT ); */
40
/* iaction_mouse_down_handler( local_x, local_y ); */
41
iaction_mouse_down_handler( local_x-x_abs, local_y-y_abs );
42
/*local_x-x_abs, ((glui->h-local_y)-y_abs) ); */
49
/**************************** GLUI_Mouse_Interaction::mouse_up_handler() */
51
int GLUI_Mouse_Interaction::mouse_up_handler( int local_x, int local_y, bool inside )
53
iaction_mouse_up_handler( local_x-x_abs, local_y-y_abs, inside );
58
/****************************** GLUI_Mouse_Interaction::mouse_held_down_handler() ******/
60
int GLUI_Mouse_Interaction::mouse_held_down_handler( int local_x, int local_y,
63
iaction_mouse_held_down_handler( local_x-x_abs, local_y-y_abs , inside );
67
/** Tell the main graphics window to update iteself **/
69
glui->post_update_main_gfx();
78
/****************************** GLUI_Mouse_Interaction::draw() **********/
80
void GLUI_Mouse_Interaction::draw( int x, int y )
82
GLUI_DRAWINGSENTINAL_IDIOM
83
int text_width = string_width( this->name );
84
int x_left = this->w/2 - text_width/2;
86
if ( NOT draw_active_area_only ) {
87
draw_name( x_left, h-4 );
88
draw_active_box( x_left-4, x_left+string_width( name )+4,
96
/************************************ GLUI_Mouse_Interaction::update_size() **********/
98
void GLUI_Mouse_Interaction::update_size( void )
103
int text_width = string_width( this->name );
105
if ( w < text_width+6 )
115
/****************************** GLUI_Mouse_Interaction::special_handler() **********/
117
int GLUI_Mouse_Interaction::special_handler( int key,int modifiers )
119
int center_x, center_y;
127
if ( key == GLUT_KEY_LEFT )
129
else if ( key == GLUT_KEY_RIGHT )
131
else if ( key == GLUT_KEY_UP )
133
else if ( key == GLUT_KEY_DOWN )
136
if ( drag_x != 0 OR drag_y != 0 ) {
137
mouse_down_handler( center_x, center_y );
138
mouse_held_down_handler( center_x + drag_x, center_y + drag_y,true );
139
mouse_up_handler( center_x + drag_x, center_y + drag_y, true );
146
/****************************** GLUI_Mouse_Interaction::draw_active_area() **********/
148
void GLUI_Mouse_Interaction::draw_active_area( void )
150
int win_h = glutGet( GLUT_WINDOW_HEIGHT ), win_w = glutGet(GLUT_WINDOW_WIDTH);
152
int text_height = 18; /* what a kludge */
154
int viewport_size = h-text_height; /*MIN(w,h); */
156
glMatrixMode( GL_MODELVIEW );
159
glTranslatef( (float) win_w/2.0, (float) win_h/2.0, 0.0 );
160
glRotatef( 180.0, 0.0, 1.0, 0.0 );
161
glRotatef( 180.0, 0.0, 0.0, 1.0 );
162
glTranslatef( (float) -win_w/2.0, (float) -win_h/2.0, 0.0 );
164
glTranslatef( (float) this->x_abs + .5, (float) this->y_abs + .5, 0.0 );
166
glTranslatef( (float)this->w/2.0, (float)viewport_size/2.0 + 2.0 , 0.0 );
168
/*** Draw the interaction control's orthographic elements ***/
169
iaction_draw_active_area_ortho();
171
/*** Setup and draw the interaction control's perspective elements ***/
173
/*** Set the viewport to just the square of the drawing area ***/
174
/* glViewport( this->x_abs , glui->main_panel->h - this->y_abs - this->h,*/
175
/*glViewport( this->x_abs+1+(this->w/2-viewport_size/2),
176
this->h-this->y_abs-viewport_size-1,
177
viewport_size, viewport_size );*/
181
if ( ((this->w-viewport_size) % 2) == 1 )
184
glViewport( this->x_abs + (this->w-viewport_size)/2 + offset,
185
win_h - this->y_abs - this->h + text_height,
186
viewport_size, viewport_size );
188
glMatrixMode( GL_PROJECTION );
190
double xy=1.00,zc=50.0; /* X-Y size, and Z origin */
191
glFrustum( -1.0*xy, 1.0*xy, -xy, xy, zc*0.7, zc*1.3 );
192
glMatrixMode( GL_MODELVIEW );
195
glTranslatef( 0.0, 0.0, -zc );
196
glScalef(xy,xy,1.0); // xy);
198
/* glutSolidTeapot( 1.0 ); */
199
iaction_draw_active_area_persp();
201
glMatrixMode( GL_MODELVIEW );
204
glui->set_viewport();
205
glui->set_ortho_projection();
207
glMatrixMode( GL_MODELVIEW );