1
/****************************************************************************
3
GLUI User Interface Toolkit
4
---------------------------
6
glui_translation - GLUI_Translation 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
*****************************************************************************/
23
/********************** GLUI_Translation::iaction_mouse_down_handler() ***/
24
/* These are really in local coords (5/10/99) */
26
int GLUI_Translation::iaction_mouse_down_handler( int local_x,
29
int center_x, center_y;
34
if ( trans_type == GLUI_TRANSLATION_XY ) {
35
orig_x = float_array_val[0];
36
orig_y = float_array_val[1];
38
/** Check if the Alt key is down, which means lock to an axis **/
43
if ( glui->curr_modifiers & GLUT_ACTIVE_ALT ) {
44
if ( ABS(local_y-center_y) > ABS(local_x-center_x) ) {
45
locked = GLUI_TRANSLATION_LOCK_Y;
46
glutSetCursor( GLUT_CURSOR_UP_DOWN );
49
locked = GLUI_TRANSLATION_LOCK_X;
50
glutSetCursor( GLUT_CURSOR_LEFT_RIGHT );
54
locked = GLUI_TRANSLATION_LOCK_NONE;
55
glutSetCursor( GLUT_CURSOR_SPRAY );
58
else if ( trans_type == GLUI_TRANSLATION_X ) {
59
glutSetCursor( GLUT_CURSOR_LEFT_RIGHT );
60
orig_x = float_array_val[0];
62
else if ( trans_type == GLUI_TRANSLATION_Y ) {
63
glutSetCursor( GLUT_CURSOR_UP_DOWN );
64
orig_y = float_array_val[0];
66
else if ( trans_type == GLUI_TRANSLATION_Z ) {
67
glutSetCursor( GLUT_CURSOR_UP_DOWN );
68
orig_z = float_array_val[0];
72
translate_and_draw_front();
78
/*********************** GLUI_Translation::iaction_mouse_up_handler() **********/
80
int GLUI_Translation::iaction_mouse_up_handler( int local_x, int local_y,
83
trans_mouse_code = GLUI_TRANSLATION_MOUSE_NONE;
84
locked = GLUI_TRANSLATION_LOCK_NONE;
86
translate_and_draw_front();
92
/******************* GLUI_Translation::iaction_mouse_held_down_handler() ******/
94
int GLUI_Translation::iaction_mouse_held_down_handler( int local_x, int local_y,
100
x_off = scale_factor * (float)(local_x - down_x);
101
y_off = -scale_factor * (float)(local_y - down_y);
103
if ( glui->curr_modifiers & GLUT_ACTIVE_SHIFT ) {
107
else if ( glui->curr_modifiers & GLUT_ACTIVE_CTRL ) {
113
if ( trans_type == GLUI_TRANSLATION_XY ) {
115
if ( locked == GLUI_TRANSLATION_LOCK_X )
117
else if ( locked == GLUI_TRANSLATION_LOCK_Y )
120
off_array[0] = x_off + orig_x;
121
off_array[1] = y_off + orig_y;
123
else if ( trans_type == GLUI_TRANSLATION_X ) {
124
off_array[0] = x_off + orig_x;
126
else if ( trans_type == GLUI_TRANSLATION_Y ) {
127
off_array[0] = y_off + orig_y;
129
else if ( trans_type == GLUI_TRANSLATION_Z ) {
130
off_array[0] = y_off + orig_z;
133
set_float_array_val( (float*) &off_array[0] );
139
/******************** GLUI_Translation::iaction_draw_active_area_persp() **************/
141
void GLUI_Translation::iaction_draw_active_area_persp( void )
143
if ( NOT can_draw() )
148
/******************** GLUI_Translation::iaction_draw_active_area_ortho() **********/
150
void GLUI_Translation::iaction_draw_active_area_ortho( void )
152
if ( NOT can_draw() )
155
/********* Draw emboss circles around arcball control *********/
157
radius = (float)(h-22)/2.0; /* MIN((float)w/2.0, (float)h/2.0); */
160
draw_emboss_box( (int) -radius-2, (int)radius+2,
161
(int)-radius-2, (int)radius+2 );
163
glMatrixMode( GL_MODELVIEW );
165
glTranslatef( .5, .5, .5 );
166
/* glScalef( radius-1.0, radius-1.0, radius-1.0 ); */
167
if ( trans_type == GLUI_TRANSLATION_Z )
168
draw_2d_z_arrows((int)radius-1);
169
else if ( trans_type == GLUI_TRANSLATION_XY )
170
draw_2d_xy_arrows((int)radius-1);
171
else if ( trans_type == GLUI_TRANSLATION_X )
172
draw_2d_x_arrows((int)radius-1);
173
else if ( trans_type == GLUI_TRANSLATION_Y )
174
draw_2d_y_arrows((int)radius-1);
180
/******************************** GLUI_Translation::iaction_dump() **********/
182
void GLUI_Translation::iaction_dump( FILE *output )
187
/******************** GLUI_Translation::iaction_special_handler() **********/
189
int GLUI_Translation::iaction_special_handler( int key,int modifiers )
197
/*************************** GLUI_Translation::draw_2d_z_arrows() **************/
199
void GLUI_Translation::draw_2d_z_arrows( int radius )
201
if ( trans_mouse_code != GLUI_TRANSLATION_MOUSE_NONE ) {
202
draw_2d_arrow(radius, true, 2);
203
draw_2d_arrow(radius, true, 0);
206
draw_2d_arrow(radius, false, 2);
207
draw_2d_arrow(radius, false, 0);
212
/*************************** GLUI_Translation::draw_2d_x_arrows() **************/
214
void GLUI_Translation::draw_2d_x_arrows( int radius )
216
if ( trans_mouse_code != GLUI_TRANSLATION_MOUSE_NONE ) {
217
draw_2d_arrow(radius, true, 1);
218
draw_2d_arrow(radius, true, 3);
221
draw_2d_arrow(radius, false, 1);
222
draw_2d_arrow(radius, false, 3);
227
/*************************** GLUI_Translation::draw_2d_y_arrows() **************/
229
void GLUI_Translation::draw_2d_y_arrows( int radius )
231
if ( trans_mouse_code != GLUI_TRANSLATION_MOUSE_NONE ) {
232
draw_2d_arrow(radius, true, 0);
233
draw_2d_arrow(radius, true, 2);
236
draw_2d_arrow(radius, false, 0);
237
draw_2d_arrow(radius, false, 2);
242
/************************** GLUI_Translation::draw_2d_xy_arrows() **************/
244
void GLUI_Translation::draw_2d_xy_arrows( int radius)
246
if ( trans_mouse_code != GLUI_TRANSLATION_MOUSE_NONE ) {
247
if ( locked == GLUI_TRANSLATION_LOCK_X ) {
248
draw_2d_arrow(radius, false, 0);
249
draw_2d_arrow(radius, false, 2);
250
draw_2d_arrow(radius, true, 1);
251
draw_2d_arrow(radius, true, 3);
253
else if ( locked == GLUI_TRANSLATION_LOCK_Y ) {
254
draw_2d_arrow(radius, false, 1);
255
draw_2d_arrow(radius, false, 3);
256
draw_2d_arrow(radius, true, 0);
257
draw_2d_arrow(radius, true, 2);
260
draw_2d_arrow(radius, true, 0);
261
draw_2d_arrow(radius, true, 1);
262
draw_2d_arrow(radius, true, 2);
263
draw_2d_arrow(radius, true, 3);
267
draw_2d_arrow(radius, false, 0);
268
draw_2d_arrow(radius, false, 1);
269
draw_2d_arrow(radius, false, 2);
270
draw_2d_arrow(radius, false, 3);
277
/*************************** GLUI_Translation::draw_2d_arrow() **************/
278
/* ori: 0=up, 1=left, 2=down, 3=right */
290
/* -x2,y1 -x1b,y1 x1b,y1 x2,y1 */
300
void GLUI_Translation::draw_2d_arrow( int radius, int filled, int orientation )
302
float x1 = .2, x2 = .4, y1 = .54, y2 = .94, y0;
304
vec3 col1( 0.0, 0.0, 0.0 ), col2( .45, .45, .45 ),
305
col3( .7, .7, .7 ), col4( 1.0, 1.0, 1.0 );
306
vec3 c1, c2, c3, c4, c5, c6;
307
vec3 white(1.0,1.0,1.0), black(0.0,0.0,0.0), gray(.45,.45,.45),
309
int c_off; /* color index offset */
312
bkgd.set(glui->bkgd_color_f[0],
313
glui->bkgd_color_f[1],
314
glui->bkgd_color_f[2]);
316
/* bkgd[0] = 255.0; bkgd[1] = 0; */
318
/** The following 8 colors define the shading of an octagon, in
319
clockwise order, starting from the upstroke on the left **/
320
/** This is for an outside and inside octagons **/
321
vec3 colors_out[]={white, white, white, gray, black, black, black, gray};
322
vec3 colors_in[] ={bkgd,white,bkgd,gray,gray,gray,gray,gray};
324
#define SET_COL_OUT(i) glColor3fv((float*) &colors_out[(i)%8][0]);
325
#define SET_COL_IN(i) glColor3fv((float*) &colors_in[(i)%8][0]);
327
x1 = (float)radius * .2;
329
y1 = (float)radius * .54;
334
glMatrixMode(GL_MODELVIEW);
337
#define DRAW_SEG( xa,ya,xb,yb ) glVertex2f(xa,ya); glVertex2f(xb,yb);
339
glScalef( -1.0, 1.0, 1.0 );
341
if ( orientation == 2 ) {
344
else if ( orientation == 0 ) {
346
glRotatef( 180.0, 0.0, 0.0, 1.0 );
348
else if ( orientation == 1 ) {
350
glRotatef( 90.0, 0.0, 0.0, 1.0 );
352
else if ( orientation == 3 ) {
354
glRotatef( -90.0, 0.0, 0.0, 1.0 );
357
if ( trans_type == GLUI_TRANSLATION_Z )
359
else if ( trans_type == GLUI_TRANSLATION_XY )
365
if ( trans_type == GLUI_TRANSLATION_Z ) {
366
if ( orientation == 0 ) {
374
else if ( orientation == 2 ) {
382
/*** Fill in inside of arrow ***/
383
if ( NOT filled ) { /*** Means button is up - control is not clicked ***/
384
/*glColor3f( .8, .8, .8 ); */
386
glColor3f( bkgd[0]+.07, bkgd[1]+.07, bkgd[2]+.07 );
388
else { /*** Button is down on control ***/
389
glColor3f( .6, .6, .6 );
390
c_off += 4; /* Indents the shadows - goes from a raised look to embossed */
393
/*** Check if control is enabled or not ***/
396
/*c_off += 4; -- Indents the shadows - goes from a raised look to embossed */
397
colors_out[0] = colors_out[1] = colors_out[2] = colors_out[7] = gray;
398
colors_out[3] = colors_out[4] = colors_out[5] = colors_out[6] = white;
399
colors_in[0] = colors_in[1] = colors_in[2] = colors_in[7] = white;
400
colors_in[3] = colors_in[4] = colors_in[5] = colors_in[6] = gray;
404
glBegin( GL_POLYGON );
405
glVertex2f( 0.0, 0.0 ); glVertex2f( -x1a, 0.0 );
406
glVertex2f( -x1a, 0.0 ); glVertex2f( -x1b, y1 );
407
glVertex2f( x1b, y1); glVertex2f( x1a, 0.0 );
408
glVertex2f( x1a, 0.0 ); glVertex2f( 0.0, 0.0 );
410
glBegin( GL_TRIANGLES );
411
glVertex2f( -x2, y1 ); glVertex2f( 0.0, y2 ); glVertex2f( x2, y1 );
415
/*** Draw arrow outline ***/
418
SET_COL_IN(1+c_off); DRAW_SEG( 0.0, y2-1.0, -x2, y1-1.0 );
419
SET_COL_IN(6+c_off); DRAW_SEG( -x2+2.0, y1+1.0, -x1b+1.0, y1+1.0 );
420
SET_COL_IN(0+c_off); DRAW_SEG( -x1b+1.0, y1+1.0, -x1a+1.0, y0 );
421
SET_COL_IN(3+c_off); DRAW_SEG( 0.0, y2-1.0, x2, y1-1.0 );
422
SET_COL_IN(6+c_off); DRAW_SEG( x2-1.0, y1+1.0, x1b-1.0, y1+1.0 );
423
SET_COL_IN(4+c_off); DRAW_SEG( x1b-1.0, y1+1.0, x1a-1.0, y0 );
425
SET_COL_OUT(0+c_off); DRAW_SEG( -x1a, y0, -x1b, y1 );
426
SET_COL_OUT(6+c_off); DRAW_SEG( -x1b, y1, -x2, y1 );
427
SET_COL_OUT(1+c_off); DRAW_SEG( -x2, y1, 0.0, y2 );
428
SET_COL_OUT(3+c_off); DRAW_SEG( 0.0, y2, x2, y1 );
429
SET_COL_OUT(6+c_off); DRAW_SEG( x2, y1, x1b, y1 );
430
SET_COL_OUT(4+c_off); DRAW_SEG( x1b, y1, x1a, y0 );
440
/*************************** GLUI_Translation::get_mouse_code() *************/
442
int GLUI_Translation::get_mouse_code( int x, int y )
444
if ( x == 0 AND y < 0 )
445
return GLUI_TRANSLATION_MOUSE_DOWN;
446
else if ( x == 0 AND y > 0 )
447
return GLUI_TRANSLATION_MOUSE_UP;
448
else if ( x > 0 AND y == 0 )
449
return GLUI_TRANSLATION_MOUSE_LEFT;
450
else if ( x < 0 AND y == 0 )
451
return GLUI_TRANSLATION_MOUSE_RIGHT;
452
else if ( x < 0 AND y < 0 )
453
return GLUI_TRANSLATION_MOUSE_DOWN_LEFT;
454
else if ( x < 0 AND y > 0 )
455
return GLUI_TRANSLATION_MOUSE_DOWN_RIGHT;
456
else if ( x > 0 AND y < 0 )
457
return GLUI_TRANSLATION_MOUSE_UP_LEFT;
458
else if ( x > 0 AND y > 0 )
459
return GLUI_TRANSLATION_MOUSE_UP_RIGHT;
462
return GLUI_TRANSLATION_MOUSE_NONE;
466
/*********************************** GLUI_Translation::set_x() ******/
468
void GLUI_Translation::set_x( float val )
470
set_one_val( val, 0 );
474
/*********************************** GLUI_Translation::set_y() ******/
476
void GLUI_Translation::set_y( float val )
478
if ( trans_type == GLUI_TRANSLATION_XY )
479
set_one_val( val, 1 );
481
set_one_val( val, 0 );
485
/*********************************** GLUI_Translation::set_z() ******/
487
void GLUI_Translation::set_z( float val )
489
set_one_val( val, 0 );
493
/******************************* GLUI_Translation::set_one_val() ****/
495
void GLUI_Translation::set_one_val( float val, int index )
499
float_array_val[index] = val; /* set value in array */
501
/*** The code below is like output_live, except it only operates on
502
a single member of the float array (given by 'index') instead of
503
outputting the entire array ****/
505
if ( ptr_val == NULL OR NOT live_inited )
508
fp = (float*) ptr_val;
509
fp[index] = float_array_val[index];
510
last_live_float_array[index] = float_array_val[index];
512
/** Update the main gfx window? **/
513
if ( this->glui != NULL ) {
514
this->glui->post_update_main_gfx();