void GLUI_EditText::draw( int x, int y ) { GLUI_DRAWINGSENTINAL_IDIOM int name_x; name_x = MAX(text_x_offset - string_width(this->name) - 3,0); draw_name( name_x , 13); glBegin( GL_LINES ); glColor3f( .5, .5, .5 ); glVertex2i( text_x_offset, 0 ); glVertex2i( w, 0 ); glVertex2i( text_x_offset, 0 ); glVertex2i( text_x_offset, h ); glColor3f( 1., 1., 1. ); glVertex2i( text_x_offset, h ); glVertex2i( w, h ); glVertex2i( w, h ); glVertex2i( w, 0 ); if ( enabled ) glColor3f( 0., 0., 0. ); else glColor3f( .25, .25, .25 ); glVertex2i( text_x_offset+1, 1 ); glVertex2i( w-1, 1 ); glVertex2i( text_x_offset+1, 1 ); glVertex2i( text_x_offset+1, h-1 ); glColor3f( .75, .75, .75 ); glVertex2i( text_x_offset+1, h-1 ); glVertex2i( w-1, h-1 ); glVertex2i( w-1, h-1 ); glVertex2i( w-1, 1 ); glEnd(); /** Find where to draw the text **/ update_substring_bounds(); draw_text(0,0); draw_insertion_pt(); }
void GLUI_EditText::draw( int x, int y ) { int orig; int name_x; if ( NOT can_draw() ) return; orig = set_to_glut_window(); name_x = MAX(text_x_offset - string_width(this->name) - 3,0); draw_name( name_x , 13); glBegin( GL_LINES ); glColor3f( .5, .5, .5 ); glVertex2i( text_x_offset, 0 ); glVertex2i( w, 0 ); glVertex2i( text_x_offset, 0 ); glVertex2i( text_x_offset, h ); glColor3f( 1., 1., 1. ); glVertex2i( text_x_offset, h ); glVertex2i( w, h ); glVertex2i( w, h ); glVertex2i( w, 0 ); if ( enabled ) glColor3f( 0., 0., 0. ); else glColor3f( .25, .25, .25 ); glVertex2i( text_x_offset+1, 1 ); glVertex2i( w-1, 1 ); glVertex2i( text_x_offset+1, 1 ); glVertex2i( text_x_offset+1, h-1 ); glColor3f( .75, .75, .75 ); glVertex2i( text_x_offset+1, h-1 ); glVertex2i( w-1, h-1 ); glVertex2i( w-1, h-1 ); glVertex2i( w-1, 1 ); glEnd(); /** Find where to draw the text **/ update_substring_bounds(); draw_text(0,0); draw_insertion_pt(); restore_window(orig); }
void GLUI_TextBox::draw( int x, int y ) { GLUI_DRAWINGSENTINAL_IDIOM int line = 0; int text_length; int box_width; int i; /* Bevelled Border */ glBegin( GL_LINES ); glColor3f( .5, .5, .5 ); glVertex2i( 0, 0 ); glVertex2i( w, 0 ); glVertex2i( 0, 0 ); glVertex2i( 0, h ); glColor3f( 1., 1., 1. ); glVertex2i( 0, h ); glVertex2i( w, h ); glVertex2i( w, h ); glVertex2i( w, 0 ); if ( enabled ) glColor3f( 0., 0., 0. ); else glColor3f( .25, .25, .25 ); glVertex2i( 1, 1 ); glVertex2i( w-1, 1 ); glVertex2i( 1, 1 ); glVertex2i( 1, h-1 ); glColor3f( .75, .75, .75 ); glVertex2i( 1, h-1 ); glVertex2i( w-1, h-1 ); glVertex2i( w-1, h-1 ); glVertex2i( w-1, 1 ); glEnd(); /* Draw Background if enabled*/ if (enabled) { glColor3f( 1., 1., 1. ); glDisable( GL_CULL_FACE ); glBegin( GL_QUADS ); glVertex2i( 2, 2 ); glVertex2i( w-2, 2 ); glVertex2i( w-2, h-2 ); glVertex2i(2, h-2 ); glEnd(); } else { glColor3f( .8, .8, .8 ); glDisable( GL_CULL_FACE ); glBegin( GL_QUADS ); glVertex2i( 2, 2 ); glVertex2i( w-2, 2 ); glVertex2i( w-2, h-2 ); glVertex2i(2, h-2 ); glEnd(); } /* Begin Drawing Lines of Text */ substring_start = 0; substring_end = 0; text_length = text.length()-1; /* Figure out how wide the box is */ box_width = get_box_width(); /* Get the first line substring */ while (substring_width(substring_start, substring_end+1 ) < box_width && substring_end < text_length && text[substring_end+1] != '\n') substring_end++; /* Figure out which lines are visible*/ visible_lines = (int)(h-20)/LINE_HEIGHT; if (start_line < (curr_line-visible_lines)) { for (i = 0; ((curr_line-i)*LINE_HEIGHT+20) > h; i++); start_line = i; } else if ( start_line > curr_line) { start_line = curr_line; } line = 0; do { if (line && substring_end < text_length) { substring_start = substring_end+1; while (substring_width(substring_start, substring_end+1 ) < box_width && substring_end < text_length && text[substring_end+1] != '\n') substring_end++; } if (text[substring_end+1] == '\n') { /* Skip newline */ substring_end++; } if (line < start_line || (line > curr_line && curr_line > (start_line + visible_lines))) { line++; continue; } if ((line - start_line) <= visible_lines) draw_text(0,(line - start_line)*LINE_HEIGHT); /* tabs and other nasties are handled by substring_width */ line++; } while (substring_end < text_length); num_lines = line; draw_insertion_pt(); if (scrollbar) { scrollbar->set_int_limits(MAX(0,num_lines/*-1*/-visible_lines),0); glPushMatrix(); glTranslatef(scrollbar->x_abs-x_abs, scrollbar->y_abs-y_abs,0.0); scrollbar->draw_scroll(); glPopMatrix(); } }