1 /****************************************************************************
2 
3   GLUI User Interface Toolkit
4   ---------------------------
5 
6      glui_mouse_iaction - GLUI Mouse Interaction control class
7 
8 
9           --------------------------------------------------
10 
11   Copyright (c) 1998 Paul Rademacher
12 
13   WWW:    http://sourceforge.net/projects/glui/
14   Forums: http://sourceforge.net/forum/?group_id=92496
15 
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.
20 
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.
25 
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
29 
30 *****************************************************************************/
31 
32 #include "glui_internal_control.h"
33 
34 /********************** GLUI_Mouse_Interaction::mouse_down_handler() ******/
35 
mouse_down_handler(int local_x,int local_y)36 int    GLUI_Mouse_Interaction::mouse_down_handler( int local_x, int local_y )
37 {
38   /* int win_h = glutGet( GLUT_WINDOW_HEIGHT ); */
39 
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) );              */
43   redraw();
44 
45   return false;
46 }
47 
48 
49 /**************************** GLUI_Mouse_Interaction::mouse_up_handler() */
50 
mouse_up_handler(int local_x,int local_y,bool inside)51 int    GLUI_Mouse_Interaction::mouse_up_handler( int local_x, int local_y, bool inside )
52 {
53   iaction_mouse_up_handler( local_x-x_abs, local_y-y_abs, inside );
54   return false;
55 }
56 
57 
58 /****************************** GLUI_Mouse_Interaction::mouse_held_down_handler() ******/
59 
mouse_held_down_handler(int local_x,int local_y,bool inside)60 int    GLUI_Mouse_Interaction::mouse_held_down_handler( int local_x, int local_y,
61 							bool inside)
62 {
63   iaction_mouse_held_down_handler( local_x-x_abs, local_y-y_abs , inside );
64 
65   redraw();
66 
67   /** Tell the main graphics window to update iteself **/
68   if( glui )
69     glui->post_update_main_gfx();
70 
71   execute_callback();
72 
73   return false;
74 }
75 
76 
77 
78 /****************************** GLUI_Mouse_Interaction::draw() **********/
79 
draw(int x,int y)80 void    GLUI_Mouse_Interaction::draw( int x, int y )
81 {
82   GLUI_DRAWINGSENTINAL_IDIOM
83   int text_width	= string_width( this->name );
84   int x_left			= this->w/2 - text_width/2;
85 
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,
89 		     h, h-14 );
90   }
91 
92   draw_active_area();
93 }
94 
95 
96 /************************************ GLUI_Mouse_Interaction::update_size() **********/
97 
update_size(void)98 void   GLUI_Mouse_Interaction::update_size( void )
99 {
100   if ( NOT glui )
101     return;
102 
103   int text_width = string_width( this->name );
104 
105   if ( w < text_width+6 )
106     w = text_width+6;
107 
108   if ( h - 18 > w )
109     w = h - 18;
110 
111   iaction_init();
112 }
113 
114 
115 /****************************** GLUI_Mouse_Interaction::special_handler() **********/
116 
special_handler(int key,int modifiers)117 int    GLUI_Mouse_Interaction::special_handler( int key,int modifiers )
118 {
119   int center_x, center_y;
120   int drag_x, drag_y;
121 
122   center_x = w/2;
123   center_y = (h-18)/2;
124   drag_x   = 0;
125   drag_y   = 0;
126 
127   if ( key == GLUT_KEY_LEFT )
128     drag_x = -6;
129   else if ( key == GLUT_KEY_RIGHT )
130     drag_x = 6;
131   else if ( key == GLUT_KEY_UP )
132     drag_y = -6;
133   else if ( key == GLUT_KEY_DOWN )
134     drag_y = 6;
135 
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 );
140   }
141 
142   return false;
143 }
144 
145 
146 /****************************** GLUI_Mouse_Interaction::draw_active_area() **********/
147 
draw_active_area(void)148 void    GLUI_Mouse_Interaction::draw_active_area( void )
149 {
150   int win_h = glutGet( GLUT_WINDOW_HEIGHT ), win_w = glutGet(GLUT_WINDOW_WIDTH);
151 
152   int text_height = 18; /* what a kludge              */
153 
154   int viewport_size = h-text_height;  /*MIN(w,h);              */
155 
156   glMatrixMode( GL_MODELVIEW );
157   glPushMatrix();
158   glLoadIdentity();
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 );
163 
164   glTranslatef( (float) this->x_abs + .5, (float) this->y_abs + .5, 0.0 );
165 
166   glTranslatef( (float)this->w/2.0, (float)viewport_size/2.0 + 2.0 , 0.0  );
167 
168   /***   Draw the interaction control's orthographic elements   ***/
169   iaction_draw_active_area_ortho();
170 
171   /***   Setup and draw the interaction control's perspective elements   ***/
172 
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 );*/
178 
179   viewport_size -= 4;
180   int offset = 0;
181   if ( ((this->w-viewport_size) % 2) == 1 )
182     offset = 1;
183 
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 );
187 
188   glMatrixMode( GL_PROJECTION );
189   glLoadIdentity();
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 );
193   glPushMatrix();
194   glLoadIdentity();
195   glTranslatef( 0.0, 0.0, -zc );
196   glScalef(xy,xy,1.0); // xy);
197 
198   /*	glutSolidTeapot( 1.0 );              */
199   iaction_draw_active_area_persp();
200 
201   glMatrixMode( GL_MODELVIEW );
202   glPopMatrix();
203 
204   glui->set_viewport();
205   glui->set_ortho_projection();
206 
207   glMatrixMode( GL_MODELVIEW );
208   glPopMatrix();
209 }
210 
211