1
/****************************************************************************
3
GLUI User Interface Toolkit
4
---------------------------
6
glui_panel.cpp - GLUI_Panel 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
*****************************************************************************/
19
#include "glui_internal_control.h"
22
/****************************** GLUI_Tree::GLUI_Tree() **********/
23
GLUI_Tree::GLUI_Tree(GLUI_Node *parent, const char *name,
27
GLUI_StaticText *inset_label;
30
this->set_name( name );
34
this->is_open = false;
35
this->h = GLUI_DEFAULT_CONTROL_HEIGHT + 7;
38
parent->add_control( this );
39
inset_label = new GLUI_StaticText(this,"");
40
inset_label->set_w(inset);
41
col = new GLUI_Column(this,true);
42
this->set_column(col);
43
this->set_alignment(GLUI_ALIGN_LEFT);
47
/****************************** GLUI_Tree::open() **********/
49
void GLUI_Tree::open( void )
55
GLUI_DRAWINGSENTINAL_IDIOM
57
child_head = collapsed_node.child_head;
58
child_tail = collapsed_node.child_tail;
60
collapsed_node.child_head = NULL;
61
collapsed_node.child_tail = NULL;
63
if ( child_head != NULL ) {
64
((GLUI_Control*) child_head)->unhide_internal( true );
71
/****************************** GLUI_Tree::close() **********/
73
void GLUI_Tree::close( void )
82
GLUI_DRAWINGSENTINAL_IDIOM
84
if ( child_head != NULL ) {
85
((GLUI_Control*) child_head)->hide_internal( true );
88
collapsed_node.child_head = first_child();
89
collapsed_node.child_tail = last_child();
94
this->h = GLUI_DEFAULT_CONTROL_HEIGHT + 7;
100
/**************************** GLUI_Tree::mouse_down_handler() **********/
103
int GLUI_Tree::mouse_down_handler( int local_x, int local_y )
105
if ( local_y - y_abs > 18 ) {
106
initially_inside = currently_inside = false;
110
currently_inside = true;
111
initially_inside = true;
117
/**************************** GLUI_Tree::mouse_held_down_handler() ****/
119
int GLUI_Tree::mouse_held_down_handler(
120
int local_x, int local_y,
123
if ( NOT initially_inside )
126
if ( local_y - y_abs> 18 )
129
if (currently_inside != new_inside)
136
/**************************** GLUI_Tree::mouse_down_handler() **********/
138
int GLUI_Tree::mouse_up_handler( int local_x, int local_y, bool inside )
140
if ( currently_inside ) {
147
currently_inside = false;
148
initially_inside = false;
155
/********************************* GLUI_Tree::draw() ***********/
157
void GLUI_Tree::draw( int x, int y )
159
GLUI_DRAWINGSENTINAL_IDIOM
160
int left, right, top, bottom, delta_x;
168
glui->draw_raised_box( left, top, 16, 16 );
171
glColor3ub(glui->bkgd_color.r,glui->bkgd_color.g,glui->bkgd_color.b);
172
glDisable( GL_CULL_FACE );
174
glVertex2i( left+17, top+1 ); glVertex2i( right-1, top+1 );
175
glVertex2i( right-1, bottom-1 ); glVertex2i( left+17, bottom-1 );
178
if (format & GLUI_TREEPANEL_DISPLAY_HIERARCHY) {
179
delta_x = string_width( level_name ) + char_width(' ');
180
glColor3f( lred, lgreen, lblue); /* The hierarchy is drawn in bold */
181
glRasterPos2i(left + 25, top + 11);
182
draw_string(level_name);
183
glRasterPos2i(left + 24, top + 11);
184
draw_string(level_name);
187
draw_name( delta_x+left+24, top+11 );
190
draw_active_box( left+22, delta_x+left+string_width( name )+32,
194
/** Draw '+' or '-' **/
200
glColor3f( 0, 0, 1 );
202
glColor3f( 0.0, 0.0, 0.0 );
204
glColor3f( 0.5, 0.5, 0.5 );
205
glVertex2i(left+4,(top+bottom)/2); glVertex2i(left+13,(top+bottom)/2);
207
glColor3f( 1.0, 1.0, 1.0 );
208
glVertex2i(left+4,1+(top+bottom)/2);glVertex2i(left+13,1+(top+bottom)/2);
212
glColor3f( 1.0, 1.0, 1.0 );
213
glVertex2i(left+9,top+3); glVertex2i(left+9,bottom-4);
214
glVertex2i(left+4,(top+bottom)/2); glVertex2i(left+13,(top+bottom)/2);
218
glColor3f( 0, 0, 1 );
220
glColor3f( 0.0, 0.0, 0.0 );
222
glColor3f( 0.5, 0.5, 0.5 );
223
glVertex2i(left+4,-1+(top+bottom)/2);
224
glVertex2i(left+13,-1+(top+bottom)/2);
225
glVertex2i(left+8,top+3);
226
glVertex2i(left+8,bottom-4);
232
if (currently_inside) draw_pressed();
236
/***************************** GLUI_Tree::update_size() **********/
238
void GLUI_Tree::update_size( void )
240
int text_size = 0, delta_x = 0;
245
text_size = string_width(name);
247
if (format & GLUI_TREEPANEL_DISPLAY_HIERARCHY) {
248
delta_x = string_width( level_name );
251
if ( w < text_size + 36 + delta_x)
252
w = text_size + 36 + delta_x;
256
/**************************** GLUI_Tree::draw_pressed() ***********/
258
void GLUI_Tree::draw_pressed( void )
260
int left, right, top, bottom;
267
glColor3f( 0.0, 0.0, 0.0 );
269
glBegin( GL_LINE_LOOP );
270
glVertex2i( left, top ); glVertex2i( right, top );
271
glVertex2i( right, bottom ); glVertex2i( left,bottom );
274
glBegin( GL_LINE_LOOP );
275
glVertex2i( left+1, top+1 ); glVertex2i( right-1, top+1 );
276
glVertex2i( right-1, bottom-1 ); glVertex2i( left+1,bottom-1 );