~ubuntu-branches/ubuntu/edgy/glui/edgy

« back to all changes in this revision

Viewing changes to glui_mouse_iaction.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Marcelo E. Magallon
  • Date: 2001-09-23 12:57:28 UTC
  • Revision ID: james.westby@ubuntu.com-20010923125728-qbts7xit2eg1ogo2
Tags: upstream-2.1.0.beta
ImportĀ upstreamĀ versionĀ 2.1.0.beta

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
  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.
 
16
 
 
17
*****************************************************************************/
 
18
 
 
19
#include "glui.h"
 
20
#include "stdinc.h"
 
21
 
 
22
/********************** GLUI_Mouse_Interaction::mouse_down_handler() ******/
 
23
 
 
24
int    GLUI_Mouse_Interaction::mouse_down_handler( int local_x, int local_y )
 
25
{
 
26
  int win_h = glutGet( GLUT_WINDOW_HEIGHT );
 
27
 
 
28
  /*    iaction_mouse_down_handler( local_x, local_y );              */
 
29
  iaction_mouse_down_handler( local_x-x_abs, local_y-y_abs );
 
30
  /*local_x-x_abs, ((glui->h-local_y)-y_abs) );              */
 
31
  
 
32
  return false;
 
33
}
 
34
 
 
35
 
 
36
/**************************** GLUI_Mouse_Interaction::mouse_up_handler() */
 
37
 
 
38
int    GLUI_Mouse_Interaction::mouse_up_handler( int local_x, int local_y, int inside )
 
39
{
 
40
  iaction_mouse_up_handler( local_x-x_abs, local_y-y_abs, inside );
 
41
  return false;
 
42
}
 
43
 
 
44
 
 
45
/****************************** GLUI_Mouse_Interaction::mouse_held_down_handler() ******/
 
46
 
 
47
int    GLUI_Mouse_Interaction::mouse_held_down_handler( int local_x, int local_y,
 
48
                                                        int inside)
 
49
{  
 
50
  iaction_mouse_held_down_handler( local_x-x_abs, local_y-y_abs , inside );
 
51
 
 
52
  draw_active_area();
 
53
 
 
54
  /** Tell the main graphics window to update iteself **/
 
55
  if( glui )
 
56
    glui->post_update_main_gfx();
 
57
 
 
58
  execute_callback();
 
59
 
 
60
  return false;
 
61
}
 
62
 
 
63
 
 
64
 
 
65
/****************************** GLUI_Mouse_Interaction::draw() **********/
 
66
 
 
67
void    GLUI_Mouse_Interaction::draw( int x, int y )
 
68
{
 
69
  int orig;
 
70
  int text_width        = string_width( this->name );
 
71
  int x_left                    = this->w/2 - text_width/2;
 
72
  
 
73
  if ( NOT glui )
 
74
    return;
 
75
 
 
76
  if ( NOT draw_active_area_only ) {
 
77
    orig = set_to_glut_window();
 
78
    draw_name( x_left, h-4 );
 
79
    restore_window(orig);
 
80
 
 
81
    draw_active_box( x_left-4, x_left+string_width( name.string )+4, 
 
82
                     h, h-14 );
 
83
  }
 
84
 
 
85
  draw_active_area();
 
86
}
 
87
 
 
88
 
 
89
/************************************ GLUI_Mouse_Interaction::update_size() **********/
 
90
 
 
91
void   GLUI_Mouse_Interaction::update_size( void )
 
92
{
 
93
  if ( NOT glui )
 
94
    return;
 
95
 
 
96
  int text_width = string_width( this->name );
 
97
 
 
98
  if ( w < text_width+6 )
 
99
    w = text_width+6;
 
100
 
 
101
  if ( h - 18 > w )
 
102
    w = h - 18;
 
103
 
 
104
  iaction_init();
 
105
}
 
106
 
 
107
 
 
108
/****************************** GLUI_Mouse_Interaction::special_handler() **********/
 
109
 
 
110
int    GLUI_Mouse_Interaction::special_handler( int key,int modifiers )
 
111
{
 
112
  int center_x, center_y;
 
113
  int drag_x, drag_y;
 
114
 
 
115
  center_x = w/2;
 
116
  center_y = (h-18)/2;
 
117
  drag_x   = 0;
 
118
  drag_y   = 0;
 
119
 
 
120
        
 
121
  if ( key == GLUT_KEY_LEFT )
 
122
    drag_x = -6;
 
123
  else if ( key == GLUT_KEY_RIGHT )
 
124
    drag_x = 6;
 
125
  else if ( key == GLUT_KEY_UP )
 
126
    drag_y = -6;
 
127
  else if ( key == GLUT_KEY_DOWN )
 
128
    drag_y = 6;
 
129
 
 
130
  if ( drag_x != 0 OR drag_y != 0 ) {
 
131
    mouse_down_handler( center_x, center_y );
 
132
    mouse_held_down_handler( center_x + drag_x, center_y + drag_y,true );
 
133
    mouse_up_handler( center_x + drag_x, center_y + drag_y, true );
 
134
  }
 
135
 
 
136
  return false;
 
137
}
 
138
 
 
139
 
 
140
/****************************** GLUI_Mouse_Interaction::draw_active_area() **********/
 
141
 
 
142
void    GLUI_Mouse_Interaction::draw_active_area( void )
 
143
{
 
144
  int orig;
 
145
  int win_h = glutGet( GLUT_WINDOW_HEIGHT ), win_w = glutGet(GLUT_WINDOW_WIDTH);
 
146
  
 
147
  if ( NOT glui )
 
148
    return;
 
149
 
 
150
  /*putchar( 'X' ); flushout;              */
 
151
 
 
152
  orig = set_to_glut_window();
 
153
        
 
154
  int text_height = 18; /* what a kludge              */
 
155
 
 
156
  int viewport_size = h-text_height;  /*MIN(w,h);              */
 
157
 
 
158
  glMatrixMode( GL_MODELVIEW );
 
159
  glPushMatrix();
 
160
  glLoadIdentity();
 
161
  glTranslatef( (float) win_w/2.0, (float) win_h/2.0, 0.0 );
 
162
  glRotatef( 180.0, 0.0, 1.0, 0.0 );
 
163
  glRotatef( 180.0, 0.0, 0.0, 1.0 );
 
164
  glTranslatef( (float) -win_w/2.0, (float) -win_h/2.0, 0.0 );
 
165
 
 
166
  glTranslatef( (float) this->x_abs + .5, (float) this->y_abs + .5, 0.0 );
 
167
 
 
168
  glTranslatef( (float)this->w/2.0, (float)viewport_size/2.0 + 2.0 , 0.0  );
 
169
 
 
170
  /***   Draw the interaction control's orthographic elements   ***/
 
171
  iaction_draw_active_area_ortho();      
 
172
 
 
173
  /***   Setup and draw the interaction control's perspective elements   ***/
 
174
 
 
175
  /***  Set the viewport to just the square of the drawing area  ***/
 
176
  /* glViewport( this->x_abs , glui->main_panel->h - this->y_abs - this->h,*/
 
177
  /*glViewport( this->x_abs+1+(this->w/2-viewport_size/2),
 
178
    this->h-this->y_abs-viewport_size-1, 
 
179
    viewport_size, viewport_size );*/
 
180
        
 
181
  viewport_size -= 4;
 
182
  int offset = 0;
 
183
  if ( ((this->w-viewport_size) % 2) == 1 ) 
 
184
    offset = 1;
 
185
 
 
186
  glViewport( this->x_abs + (this->w-viewport_size)/2 + offset, 
 
187
              win_h - this->y_abs - this->h + text_height, 
 
188
              viewport_size, viewport_size );
 
189
 
 
190
  glMatrixMode( GL_PROJECTION );
 
191
  glLoadIdentity();
 
192
  glFrustum( -1.0*.08, 1.0*.08, -.08, .08, .1, 8.0 );
 
193
  glMatrixMode( GL_MODELVIEW );
 
194
  glPushMatrix();
 
195
  glLoadIdentity();
 
196
  glTranslatef( 0.0, 0.0, -3.2f );
 
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
  restore_window(orig);
 
211
}
 
212