~ubuntu-branches/ubuntu/lucid/glui/lucid

« back to all changes in this revision

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