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

« back to all changes in this revision

Viewing changes to tests/bullet/Extras/glui/glui_panel.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
  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_Panel::GLUI_Panel( GLUI_Node *parent, const char *name, int type )
 
35
{
 
36
  common_init();
 
37
  set_name( name );
 
38
  user_id    = -1;
 
39
  int_val    = type;
 
40
 
 
41
  parent->add_control( this );
 
42
}
 
43
 
 
44
/****************************** GLUI_Panel::draw() **********/
 
45
 
 
46
void    GLUI_Panel::draw( int x, int y )
 
47
{
 
48
  int top;
 
49
  GLUI_DRAWINGSENTINAL_IDIOM
 
50
 
 
51
  if ( int_val == GLUI_PANEL_RAISED ) {
 
52
    top = 0;
 
53
    glLineWidth( 1.0 );
 
54
    glColor3f( 1.0, 1.0, 1.0 );
 
55
    glBegin( GL_LINE_LOOP );
 
56
    glVertex2i( 0, top );    glVertex2i( w, top );
 
57
    glVertex2i( 0, top );    glVertex2i( 0, h );
 
58
    glEnd();
 
59
    
 
60
    glColor3f( .5, .5, .5 );
 
61
    glBegin( GL_LINE_LOOP );
 
62
    glVertex2i( w, top );
 
63
    glVertex2i( w, h );
 
64
    glVertex2i( 0, h );
 
65
    glVertex2i( w, h );
 
66
    glEnd();
 
67
 
 
68
    /** ORIGINAL RAISED PANEL METHOD - A LITTLE TOO HIGH **
 
69
    glLineWidth(1.0);
 
70
    glBegin( GL_LINES );
 
71
    glColor3f( 1.0, 1.0, 1.0 );
 
72
    glVertex2i( 1, 1 );    glVertex2i( w-2, 1 );
 
73
    glVertex2i( 1, 1 );    glVertex2i( 1, h-2 );
 
74
    
 
75
    glColor3f( .5, .5, .5 );
 
76
    glVertex2i( w-1, 1 );    glVertex2i( w-1, h-1 );
 
77
    glVertex2i( 1, h-1 );    glVertex2i( w-1, h-1 );
 
78
    
 
79
    glColor3f( 0.0, 0.0, 0.0 );
 
80
    glVertex2i( 0, h );    glVertex2i( w, h );
 
81
    glVertex2i( w, 0 );    glVertex2i( w, h );
 
82
    glEnd();
 
83
    
 
84
    -- Touch up the lines a bit (needed in some opengl implementations   
 
85
    glBegin( GL_POINTS );
 
86
    glColor3f( .5, .5, .5 );
 
87
    glVertex2i( w-1, h-1 );
 
88
    glColor3f( 0.0, 0.0, 0.0 );
 
89
    glVertex2i( w, h );
 
90
    glEnd();
 
91
    **/    
 
92
      }
 
93
  else if ( int_val == GLUI_PANEL_EMBOSSED ) {
 
94
    if ( parent_node == NULL || name == "" ) {
 
95
      top = 0;
 
96
    }
 
97
    else {
 
98
      top = GLUI_PANEL_EMBOSS_TOP;
 
99
    }
 
100
 
 
101
    glLineWidth( 1.0 );
 
102
    glColor3f( 1.0, 1.0, 1.0 );
 
103
    glBegin( GL_LINE_LOOP );
 
104
    glVertex2i( 0, top );    glVertex2i( w, top );
 
105
    glVertex2i( w, h );    glVertex2i( 0, h );
 
106
 
 
107
    glVertex2i( 1, top+1 );    glVertex2i( w-1, top+1 );
 
108
    glVertex2i( w-1, h-1 );    glVertex2i( 1, h-1 );
 
109
    glEnd();
 
110
    
 
111
    glColor3f( .5, .5, .5 );
 
112
    glBegin( GL_LINE_LOOP );
 
113
    glVertex2i( 0, top );
 
114
    glVertex2i( w-1, top );
 
115
    glVertex2i( w-1, h-1 );
 
116
    glVertex2i( 0, h-1 );
 
117
    glEnd();
 
118
 
 
119
    /**** Only display text in embossed panel ****/
 
120
    if ( parent_node != NULL && name != "" ) { /* Only  draw non-null strings */
 
121
      int left = 7, height=GLUI_PANEL_NAME_DROP+1;
 
122
      int str_width;
 
123
 
 
124
      str_width = string_width(name);
 
125
 
 
126
      if ( glui )
 
127
        glColor3ub(glui->bkgd_color.r,glui->bkgd_color.g,glui->bkgd_color.b);
 
128
      glDisable( GL_CULL_FACE );
 
129
      glBegin( GL_QUADS );
 
130
      glVertex2i( left-3, 0 );               glVertex2i( left+str_width+3, 0 );
 
131
      glVertex2i( left+str_width+3, height );  glVertex2i( left-3, height );
 
132
      glEnd();
 
133
 
 
134
      draw_name( left, GLUI_PANEL_NAME_DROP );
 
135
    }
 
136
  }
 
137
 
 
138
  glLineWidth( 1.0 );
 
139
}
 
140
 
 
141
/****************************** GLUI_Panel::set_name() **********/
 
142
 
 
143
void    GLUI_Panel::set_name( const char *new_name )
 
144
{
 
145
  name = new_name ? new_name : "";
 
146
 
 
147
  update_size();
 
148
 
 
149
  if ( glui )
 
150
    glui->refresh();
 
151
}
 
152
 
 
153
 
 
154
/****************************** GLUI_Panel::set_type() **********/
 
155
 
 
156
void    GLUI_Panel::set_type( int new_type )
 
157
{
 
158
  if ( new_type != int_val ) {
 
159
    int_val = new_type;
 
160
    update_size();
 
161
    redraw();
 
162
  }
 
163
}
 
164
 
 
165
 
 
166
/************************************** GLUI_Panel::update_size() **********/
 
167
 
 
168
void   GLUI_Panel::update_size( void )
 
169
{
 
170
  int text_size;
 
171
 
 
172
  if ( NOT glui )
 
173
    return;
 
174
 
 
175
  text_size = string_width(name);
 
176
 
 
177
  if ( w < text_size + 16 )
 
178
    w = text_size + 16 ;
 
179
 
 
180
  if ( name != "" AND int_val == GLUI_PANEL_EMBOSSED ) {
 
181
    this->y_off_top = GLUI_YOFF + 8;
 
182
  }
 
183
  else {
 
184
    this->y_off_top = GLUI_YOFF;
 
185
  }
 
186
}