~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tests/bullet/Extras/glui/glui_tree.cpp

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
  
 
3
  GLUI User Interface Toolkit
 
4
  ---------------------------
 
5
 
 
6
     glui_panel.cpp - GLUI_Panel 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_internal_control.h"
 
20
 
 
21
 
 
22
/****************************** GLUI_Tree::GLUI_Tree() **********/
 
23
GLUI_Tree::GLUI_Tree(GLUI_Node *parent, const char *name, 
 
24
                     int open, int inset)
 
25
{
 
26
  common_init();
 
27
  GLUI_StaticText *inset_label;
 
28
  GLUI_Column     *col;
 
29
 
 
30
  this->set_name( name );
 
31
  this->user_id    = -1;
 
32
        
 
33
  if ( NOT open ) {
 
34
    this->is_open = false;
 
35
    this->h = GLUI_DEFAULT_CONTROL_HEIGHT + 7;
 
36
  }
 
37
 
 
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);
 
44
}
 
45
 
 
46
 
 
47
/****************************** GLUI_Tree::open() **********/
 
48
 
 
49
void GLUI_Tree::open( void )
 
50
{
 
51
  if ( is_open )
 
52
    return;
 
53
  is_open = true;
 
54
 
 
55
  GLUI_DRAWINGSENTINAL_IDIOM
 
56
 
 
57
  child_head = collapsed_node.child_head;
 
58
  child_tail = collapsed_node.child_tail;
 
59
 
 
60
  collapsed_node.child_head = NULL;
 
61
  collapsed_node.child_tail = NULL;
 
62
 
 
63
  if ( child_head != NULL ) {
 
64
    ((GLUI_Control*) child_head)->unhide_internal( true );
 
65
  }
 
66
 
 
67
  glui->refresh();
 
68
}
 
69
 
 
70
 
 
71
/****************************** GLUI_Tree::close() **********/
 
72
 
 
73
void    GLUI_Tree::close( void )
 
74
{
 
75
  if ( NOT glui )
 
76
    return;
 
77
 
 
78
  if ( NOT is_open )
 
79
    return;
 
80
  is_open = false;
 
81
 
 
82
  GLUI_DRAWINGSENTINAL_IDIOM
 
83
 
 
84
  if ( child_head != NULL ) {
 
85
    ((GLUI_Control*) child_head)->hide_internal( true );
 
86
  }
 
87
 
 
88
  collapsed_node.child_head = first_child();
 
89
  collapsed_node.child_tail = last_child();
 
90
 
 
91
  child_head = NULL;
 
92
  child_tail = NULL;
 
93
 
 
94
  this->h = GLUI_DEFAULT_CONTROL_HEIGHT + 7;
 
95
  
 
96
  glui->refresh();
 
97
}
 
98
 
 
99
 
 
100
/**************************** GLUI_Tree::mouse_down_handler() **********/
 
101
 
 
102
 
 
103
int   GLUI_Tree::mouse_down_handler( int local_x, int local_y )
 
104
{
 
105
  if ( local_y - y_abs > 18 ) {
 
106
    initially_inside = currently_inside = false;
 
107
    return false;
 
108
  }
 
109
 
 
110
  currently_inside = true;
 
111
  initially_inside = true;
 
112
  redraw();
 
113
 
 
114
  return false;
 
115
}
 
116
 
 
117
/**************************** GLUI_Tree::mouse_held_down_handler() ****/
 
118
 
 
119
int  GLUI_Tree::mouse_held_down_handler( 
 
120
                       int local_x, int local_y, 
 
121
                       bool new_inside )
 
122
{
 
123
  if ( NOT initially_inside )
 
124
    return false;
 
125
 
 
126
  if ( local_y - y_abs> 18 )
 
127
    new_inside = false;
 
128
 
 
129
  if (currently_inside != new_inside)
 
130
    redraw();
 
131
  
 
132
  return false;
 
133
}
 
134
 
 
135
 
 
136
/**************************** GLUI_Tree::mouse_down_handler() **********/
 
137
 
 
138
int   GLUI_Tree::mouse_up_handler( int local_x, int local_y, bool inside )
 
139
{
 
140
  if ( currently_inside ) {    
 
141
    if ( is_open )
 
142
      close();
 
143
    else
 
144
      open();
 
145
  }
 
146
 
 
147
  currently_inside = false;
 
148
  initially_inside = false;
 
149
  redraw();
 
150
 
 
151
  return false;
 
152
}
 
153
 
 
154
 
 
155
/********************************* GLUI_Tree::draw() ***********/
 
156
 
 
157
void   GLUI_Tree::draw( int x, int y )
 
158
{
 
159
  GLUI_DRAWINGSENTINAL_IDIOM
 
160
  int left, right, top, bottom, delta_x;
 
161
    
 
162
  left   = 5;
 
163
  right  = w-left;
 
164
  top    = 3;
 
165
  bottom = 3+16;
 
166
  delta_x = 0;
 
167
 
 
168
  glui->draw_raised_box( left, top, 16, 16 );
 
169
 
 
170
  if ( glui )
 
171
    glColor3ub(glui->bkgd_color.r,glui->bkgd_color.g,glui->bkgd_color.b);
 
172
  glDisable( GL_CULL_FACE );
 
173
  glBegin( GL_QUADS );
 
174
  glVertex2i( left+17, top+1 );      glVertex2i( right-1, top+1 );
 
175
  glVertex2i( right-1, bottom-1 );  glVertex2i( left+17, bottom-1 );
 
176
  glEnd();
 
177
 
 
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);
 
185
  }
 
186
 
 
187
  draw_name( delta_x+left+24, top+11 );
 
188
 
 
189
  if ( active )
 
190
    draw_active_box( left+22, delta_x+left+string_width( name )+32,
 
191
                     top, bottom-2 );
 
192
 
 
193
 
 
194
  /**   Draw '+' or '-'  **/
 
195
 
 
196
  glBegin( GL_LINES );
 
197
  if ( is_open ) {
 
198
    if ( enabled )      
 
199
      if (is_current) 
 
200
        glColor3f( 0, 0, 1 ); 
 
201
      else 
 
202
        glColor3f( 0.0, 0.0, 0.0 );
 
203
    else 
 
204
        glColor3f( 0.5, 0.5, 0.5 );
 
205
    glVertex2i(left+4,(top+bottom)/2);  glVertex2i(left+13,(top+bottom)/2);
 
206
 
 
207
    glColor3f( 1.0, 1.0, 1.0 );
 
208
    glVertex2i(left+4,1+(top+bottom)/2);glVertex2i(left+13,1+(top+bottom)/2);
 
209
  }
 
210
  else
 
211
  {
 
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);
 
215
 
 
216
    if ( enabled )
 
217
      if (is_current) 
 
218
        glColor3f( 0, 0, 1 ); 
 
219
      else       
 
220
        glColor3f( 0.0, 0.0, 0.0 );
 
221
    else 
 
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);
 
227
  }
 
228
  glEnd();
 
229
 
 
230
  glLineWidth( 1.0 );
 
231
  
 
232
  if (currently_inside) draw_pressed();
 
233
}
 
234
 
 
235
 
 
236
/***************************** GLUI_Tree::update_size() **********/
 
237
 
 
238
void   GLUI_Tree::update_size( void )
 
239
{
 
240
  int text_size = 0, delta_x = 0;
 
241
 
 
242
  if ( NOT glui )
 
243
    return;
 
244
 
 
245
  text_size = string_width(name);
 
246
 
 
247
  if (format & GLUI_TREEPANEL_DISPLAY_HIERARCHY) {
 
248
    delta_x = string_width( level_name );
 
249
  }
 
250
 
 
251
  if ( w < text_size + 36 + delta_x)
 
252
    w = text_size + 36 + delta_x;
 
253
}
 
254
 
 
255
 
 
256
/**************************** GLUI_Tree::draw_pressed() ***********/
 
257
 
 
258
void   GLUI_Tree::draw_pressed( void )
 
259
{
 
260
  int left, right, top, bottom;
 
261
 
 
262
  left   = 5;
 
263
  right  = w-left;
 
264
  top    = 3;
 
265
  bottom = 3+16;
 
266
  
 
267
  glColor3f( 0.0, 0.0, 0.0 );
 
268
 
 
269
  glBegin( GL_LINE_LOOP );
 
270
  glVertex2i( left, top );         glVertex2i( right, top );
 
271
  glVertex2i( right, bottom );     glVertex2i( left,bottom );
 
272
  glEnd();
 
273
 
 
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 );
 
277
  glEnd();
 
278
}