Esempio n. 1
0
void   GLUI_Slider::update_size( void )
{
   int min_w;

   if ( NOT glui )
      return;

   h =     GLUI_SLIDER_NAME_TOP_BORDER +
           GLUI_SLIDER_FONT_HEIGHT -
           GLUI_SLIDER_FONT_MID_HEIGHT +
           GLUI_SLIDER_VAL_TOP_BORDER +
           GLUI_SLIDER_FONT_HEIGHT  +
           GLUI_SLIDER_KNOB_TOP_BORDER +
           GLUI_SLIDER_KNOB_HALF_HEIGHT +
           1 +
           GLUI_SLIDER_KNOB_HALF_HEIGHT +
           GLUI_SLIDER_KNOB_BOTTOM_BORDER +
           2;

   min_w = GLUI_SLIDER_NAME_INDENT +
           string_width(name) +
           2*GLUI_SLIDER_NAME_SIDE_BORDER +
           string_width(GLUI_SLIDER_TRUNCATE_STRING) +
           2*GLUI_SLIDER_VAL_SIDE_BORDER +
           2 - 1; //+2 for border width at right


   if (w<min_w)
      w = min_w;

}
/** Change w and return true if we need to be widened to fit the current items. */
bool    GLUI_Listbox::recalculate_item_width( void )
{
  int item_text_size;

  if ( NOT glui )
    return false;

  /* Find the title size */
  text_x_offset = string_width( name );

  /* Find the longest item string ***/
  item_text_size = 0;   
 
  GLUI_Listbox_Item *item = (GLUI_Listbox_Item *) items_list.first_child();
  while( item ) {
    item_text_size = MAX(item_text_size,string_width(item->text));
    item = (GLUI_Listbox_Item *) item->next();
  }
  
  /* Sum up our layout: name, item, and drop-down marker */
  int new_wid=text_x_offset+MAX(GLUI_EDITTEXT_MIN_TEXT_WIDTH,item_text_size)+20;
  if ( w != new_wid) {
    w = new_wid;
    return true; /* we gotta be shortened or widened */
  }
  else {
    return false; /* our current width is OK */
  }
}
Esempio n. 3
0
void    GLUI_Mouse_Interaction::draw( int x, int y )
{
  GLUI_DRAWINGSENTINAL_IDIOM
  int text_width	= string_width( this->name );
  int x_left			= this->w/2 - text_width/2;

  if ( NOT draw_active_area_only ) {
    draw_name( x_left, h-4 );
    draw_active_box( x_left-4, x_left+string_width( name )+4, 
		     h, h-14 );
  }

  draw_active_area();
}
Esempio n. 4
0
int wrap(const char *input, int max_width, char *output, int max_length) {
    *output = '\0';
    char *text = malloc(sizeof(char) * (strlen(input) + 1));
    strcpy(text, input);
    int space_width = char_width(' ');
    int line_number = 0;
    char *key1, *key2;
    char *line = tokenize(text, "\r\n", &key1);
    while (line) {
        int line_width = 0;
        char *token = tokenize(line, " ", &key2);
        while (token) {
            int token_width = string_width(token);
            if (line_width) {
                if (line_width + token_width > max_width) {
                    line_width = 0;
                    line_number++;
                    strncat(output, "\n", max_length);
                }
                else {
                    strncat(output, " ", max_length);
                }
            }
            strncat(output, token, max_length);
            line_width += token_width + space_width;
            token = tokenize(NULL, " ", &key2);
        }
        line_number++;
        strncat(output, "\n", max_length);
        line = tokenize(NULL, "\r\n", &key1);
    }
    free(text);
    return line_number;
}
Esempio n. 5
0
void   GLUI_EditText::update_size( void )
{
  int text_size, delta;

  if ( NOT glui )
    return;

  text_size = string_width( name );

  delta = 0;
  if ( text_x_offset < text_size +2 )
    delta = text_size+2-text_x_offset;

  text_x_offset += delta;
  /*  w += delta;              */

  if ( data_type == GLUI_EDITTEXT_TEXT OR 
       data_type == GLUI_EDITTEXT_FLOAT OR
       data_type == GLUI_EDITTEXT_DOUBLE) {
    if ( w < text_x_offset + GLUI_EDITTEXT_MIN_TEXT_WIDTH )
      w = text_x_offset + GLUI_EDITTEXT_MIN_TEXT_WIDTH;
  }
  else if ( data_type == GLUI_EDITTEXT_INT ) {
    if ( w < text_x_offset + GLUI_EDITTEXT_MIN_INT_WIDTH )
      w = text_x_offset + GLUI_EDITTEXT_MIN_INT_WIDTH;
  }
}
Esempio n. 6
0
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();
}
Esempio n. 7
0
void   GLUI_Graph::update_size( void )
{
	int name_w, img_w;

	if ( !glui )
		return;

	h =	GLUI_GRAPH_NAME_TOP_BORDER +
			GLUI_GRAPH_FONT_FULL_HEIGHT +
			GLUI_GRAPH_NAME_BOTTOM_BORDER +
			GLUI_GRAPH_IMG_TOP_BORDER +
			graph_h +
			GLUI_GRAPH_IMG_BOTTOM_BORDER +
			2 -
			1;

	name_w =	GLUI_GRAPH_NAME_INDENT +
				string_width(name) +
				2*GLUI_GRAPH_NAME_SIDE_BORDER +
				GLUI_GRAPH_NAME_INDENT -
				1;

	img_w = GLUI_GRAPH_IMG_LEFT_BORDER + GLUI_GRAPH_IMG_RIGHT_BORDER + graph_w + 2 + 2 - 1;

	if (img_w >= name_w)
		w = img_w;
	else
	{
		w = img_w + 2*((name_w - img_w + 1)/2);
	}
}
void draw_highscore(int x1, int y1, int x2, int y2) {

    for (size_t i=0; i<enigma::highscore_list.size(); i++) {
        draw_text(x1, (i*((y2-y1)/10))+y1+10, enigma::highscore_list[i].player_name.c_str());
        draw_text(x2-string_width(toString((var)enigma::highscore_list[i].player_score)), (i*((y2-y1)/10))+y1+10 , toString((var)enigma::highscore_list[i].player_score));
    }
}
Esempio n. 9
0
void    GLUI_Slider::draw( int x, int y )
{
    int orig;

    if ( NOT glui )
        return;

    orig = set_to_glut_window();


    draw_emboss_box(        0,
                            w,
                            GLUI_SLIDER_NAME_TOP_BORDER +
                            GLUI_SLIDER_FONT_HEIGHT - 1 -
                            GLUI_SLIDER_FONT_MID_HEIGHT,
                            h );

    draw_bkgd_box( GLUI_SLIDER_NAME_INDENT-1,
                   GLUI_SLIDER_NAME_INDENT +
                   string_width(name.string) +
                   2*GLUI_SLIDER_NAME_SIDE_BORDER - 1,
                   0,
                   0 +
                   GLUI_SLIDER_FONT_FULL_HEIGHT +
                   GLUI_SLIDER_NAME_TOP_BORDER +
                   GLUI_SLIDER_NAME_BOTTOM_BORDER);

    draw_name(      GLUI_SLIDER_NAME_INDENT +
                    GLUI_SLIDER_NAME_SIDE_BORDER,
                    GLUI_SLIDER_FONT_HEIGHT-1 +
                    GLUI_SLIDER_NAME_TOP_BORDER);

    draw_active_area();

    restore_window(orig);

    draw_active_box(        GLUI_SLIDER_NAME_INDENT,
                            GLUI_SLIDER_NAME_INDENT +
                            string_width(name.string) +
                            2*GLUI_SLIDER_NAME_SIDE_BORDER - 1,
                            0,
                            GLUI_SLIDER_FONT_FULL_HEIGHT +
                            GLUI_SLIDER_NAME_TOP_BORDER +
                            GLUI_SLIDER_NAME_BOTTOM_BORDER - 1);

}
Esempio n. 10
0
static int
char_width (sws_configuration *sc, char c)
{
  char s[2];
  s[0] = c;
  s[1] = 0;
  return string_width (sc, s);
}
Esempio n. 11
0
int	GLUI_ActiveText::check_fit(const char *s)
{

  if ( w < string_width(s) + 6 )
    return 0;
  else
    return 1;
}
Esempio n. 12
0
/*
  Esta rutina estima el offset x donde se debe colocar la cadena str
  en una ventana de ancho window_size */
long double center_string(const string& str, long double window_size)
{
  long double x = (window_size - string_width(str))/2.0; 

  long double dx = window_size/2.0 - x;

  return dx;
}
Esempio n. 13
0
void   GLUI_ActiveText::update_size( void )
{
  int text_size;

  if ( NOT glui ) return;

  text_size = string_width( name );

  if ( w < text_size + 6 )  w = text_size + 6 ;
}
void    GLUI_Mouse_Interaction::draw( int x, int y )
{
  int orig;
  int text_width	= string_width( this->name );
  int x_left			= this->w/2 - text_width/2;
  
  if ( NOT glui )
    return;

  if ( NOT draw_active_area_only ) {
    orig = set_to_glut_window();
    draw_name( x_left, h-4 );
    restore_window(orig);

    draw_active_box( x_left-4, x_left+string_width( name.string )+4, 
		     h, h-14 );
  }

  draw_active_area();
}
Esempio n. 15
0
void   GLUI_Button::update_size( void )
{
  int text_size;

  if ( NOT glui )
    return;

  text_size = string_width( name );

  if ( w < text_size + 16 )
    w = text_size + 16 ;
}
Esempio n. 16
0
void   GLUI_StaticText::update_size( void )
{
  int text_size;

  if ( NOT glui )
    return;

  text_size = string_width( name );

  if ( w < text_size )
    w = text_size;    
}
Esempio n. 17
0
void   GLUI_Rollout::update_size( void )
{
  int text_size;

  if ( NOT glui )
    return;

  text_size = string_width(name);

  if ( w < text_size + 36 )
    w = text_size + 36;
}
Esempio n. 18
0
static void
startup_blurb (ModeInfo *mi)
{
  molecule_configuration *mc = &mcs[MI_SCREEN(mi)];
  const char *s = "Constructing molecules...";
  print_title_string (mi, s,
                      MI_WIDTH(mi) - (string_width (mc->xfont2, s) + 40),
                      10 + mc->xfont2->ascent + mc->xfont2->descent,
                      mc->xfont2->ascent + mc->xfont2->descent);
  glFinish();
  glXSwapBuffers(MI_DISPLAY(mi), MI_WINDOW(mi));
  firstcall = False;
}
Esempio n. 19
0
void    GLUI_Graph::draw( int x, int y )
{

  GLUI_DRAWINGSENTINAL_IDIOM;

	draw_emboss_box(	0,
							w,
							GLUI_GRAPH_NAME_TOP_BORDER +
							GLUI_GRAPH_FONT_HEIGHT - 1 -
							GLUI_GRAPH_FONT_MID_HEIGHT,
							h );

	draw_bkgd_box( GLUI_GRAPH_NAME_INDENT-1,
						GLUI_GRAPH_NAME_INDENT +
						string_width(name) +
						2*GLUI_GRAPH_NAME_SIDE_BORDER - 1,
						0,
						0 +
						GLUI_GRAPH_FONT_FULL_HEIGHT +
						GLUI_GRAPH_NAME_TOP_BORDER +
						GLUI_GRAPH_NAME_BOTTOM_BORDER);

	draw_name(	GLUI_GRAPH_NAME_INDENT +
					GLUI_GRAPH_NAME_SIDE_BORDER,
					GLUI_GRAPH_FONT_HEIGHT-1 +
					GLUI_GRAPH_NAME_TOP_BORDER);

	draw_active_area();

	draw_active_box(	GLUI_GRAPH_NAME_INDENT,
							GLUI_GRAPH_NAME_INDENT +
							string_width(name) +
							2*GLUI_GRAPH_NAME_SIDE_BORDER - 1,
							0,
							GLUI_GRAPH_FONT_FULL_HEIGHT +
							GLUI_GRAPH_NAME_TOP_BORDER +
							GLUI_GRAPH_NAME_BOTTOM_BORDER - 1);

}
Esempio n. 20
0
void   GLUI_Mouse_Interaction::update_size( void )
{
  if ( NOT glui )
    return;

  int text_width = string_width( this->name );

  if ( w < text_width+6 )
    w = text_width+6;

  if ( h - 18 > w )
    w = h - 18;

  iaction_init();
}
Esempio n. 21
0
static void
draw_string (sws_configuration *sc, GLfloat x, GLfloat y, const char *s)
{
  const char *os = s;
  if (!s || !*s) return;
  glPushMatrix ();
  glTranslatef (x, y, 0);

  if (textures_p)
    print_texture_string (sc->texfont, s);
  else
    while (*s)
      glutStrokeCharacter (GLUT_FONT, *s++);
  glPopMatrix ();

  if (debug_p)
    {
      GLfloat w;
      GLfloat h = sc->line_height / sc->font_scale;
      char c[2];
      c[1]=0;
      s = os;
      if (textures_p) glDisable (GL_TEXTURE_2D);
      glLineWidth (1);
      glColor3f (0.4, 0.4, 0.4);
      glPushMatrix ();
      glTranslatef (x, y, 0);
      while (*s)
        {
          *c = *s++;
          w = string_width (sc, c);
          glBegin (GL_LINE_LOOP);
          glVertex3f (0, 0, 0);
          glVertex3f (w, 0, 0);
          glVertex3f (w, h, 0);
          glVertex3f (0, h, 0);
          glEnd();
          glTranslatef (w, 0, 0);
        }
      glPopMatrix ();
      if (textures_p) glEnable (GL_TEXTURE_2D);
    }
}
Esempio n. 22
0
void   GLUI_Panel::update_size( void )
{
  int text_size;

  if ( NOT glui )
    return;

  text_size = string_width(name);

  if ( w < text_size + 16 )
    w = text_size + 16 ;

  if ( name != "" AND int_val == GLUI_PANEL_EMBOSSED ) {
    this->y_off_top = GLUI_YOFF + 8;
  }
  else {
    this->y_off_top = GLUI_YOFF;
  }
}
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_Listbox::draw( int x, int y )
{
  GLUI_DRAWINGSENTINAL_IDIOM
  int name_x;

  /*  draw_active_area();              */

  name_x = MAX(text_x_offset - string_width(this->name) - 3,0);
  draw_name( name_x , 13);
  draw_box_inwards_outline( text_x_offset, w,
			    0, h );

  if ( NOT active ) {
    draw_box( text_x_offset+3, w-2, 2, h-2, 1.0, 1.0, 1.0 );
    if ( NOT enabled )
      glColor3b( 32, 32, 32 );
    else
      glColor3f( 0.0, 0.0, 0.0 );
    glRasterPos2i( text_x_offset+5, 13 );
    draw_string( curr_text );
  }
  else {
    draw_box( text_x_offset+3, w-2, 2, h-2, .0, .0, .6 );
    glColor3f( 1.0, 1.0, 1.0 );
    glRasterPos2i( text_x_offset+5, 13 );
    draw_string( curr_text );
  }


  if ( enabled ) {
    glui->std_bitmaps.
      draw(GLUI_STDBITMAP_LISTBOX_UP,
	   w-glui->std_bitmaps.width(GLUI_STDBITMAP_LISTBOX_UP)-1,
	   2 );
  }
  else {
    glui->std_bitmaps.
      draw(GLUI_STDBITMAP_LISTBOX_UP_DIS,
	   w-glui->std_bitmaps.width(GLUI_STDBITMAP_LISTBOX_UP)-1,
	   2 );
  }
}
Esempio n. 25
0
void Filter::getLineColumn(int position , int& startLine , int& startColumn)
{
    Q_ASSERT( _linePositions );
    Q_ASSERT( _buffer );


    for (int i = 0 ; i < _linePositions->count() ; i++)
    {
        int nextLine = 0;

        if ( i == _linePositions->count()-1 )
            nextLine = _buffer->length() + 1;
        else
            nextLine = _linePositions->value(i+1);

        if ( _linePositions->value(i) <= position && position < nextLine )
        {
            startLine = i;
            startColumn = string_width(buffer()->mid(_linePositions->value(i),position - _linePositions->value(i)));
            return;
        }
    }
}
Esempio n. 26
0
static void
update_passwd_window (saver_info *si, const char *printed_passwd, float ratio)
{
  passwd_dialog_data *pw = si->pw_data;
  XGCValues gcv;
  GC gc1, gc2;
  int x, y;

  pw->ratio = ratio;
  gcv.foreground = pw->passwd_foreground;
  gcv.font = pw->passwd_font->fid;
  gc1 = XCreateGC (si->dpy, si->passwd_dialog, GCForeground|GCFont, &gcv);
  gcv.foreground = pw->passwd_background;
  gc2 = XCreateGC (si->dpy, si->passwd_dialog, GCForeground, &gcv);

  if (printed_passwd)
    {
      char *s = strdup (printed_passwd);
      if (pw->passwd_string) free (pw->passwd_string);
      pw->passwd_string = s;
    }

  /* [email protected] - Added to redraw username here */
  XDrawString (si->dpy, si->passwd_dialog, gc1,
                    pw->uname_field_x,
                    pw->uname_field_y,
                    si->user, strlen(si->user));

  if (pw->draw_password_prompt)
    {
      /* The user entry (password) field is double buffered.
       * This avoids flickering, particularly in synchronous mode. */

      if (pw->passwd_changed_p)
        {
	  pw->passwd_changed_p = False;

	  if (pw->user_entry_pixmap)
	    {
	      XFreePixmap(si->dpy, pw->user_entry_pixmap);
	      pw->user_entry_pixmap = 0;
	    }

	  pw->user_entry_pixmap =
            XCreatePixmap (si->dpy, si->passwd_dialog,
                           pw->passwd_field_width, pw->passwd_field_height,
                           DefaultDepthOfScreen (pw->prompt_screen->screen));

	  XFillRectangle (si->dpy, pw->user_entry_pixmap, gc2,
			  0, 0, pw->passwd_field_width,
			  pw->passwd_field_height);

	  XDrawString (si->dpy, pw->user_entry_pixmap, gc1,
		       0,
		       pw->passwd_font->ascent,
		       pw->passwd_string, strlen(pw->passwd_string));

	  /* Ensure the new pixmap gets copied to the window */
	  pw->i_beam = 0;

	}

      /* The I-beam
       */
      if (pw->i_beam == 0)
	{
	  /* Make the I-beam disappear */

	  XCopyArea(si->dpy, pw->user_entry_pixmap, si->passwd_dialog, gc2,
		    0, 0, pw->passwd_field_width, pw->passwd_field_height,
		    pw->passwd_field_x, pw->passwd_field_y);
	}
      else if (pw->i_beam == 1)
	{
	  x = (pw->passwd_field_x + 0 +
	                 string_width (pw->passwd_font, pw->passwd_string));
	            y = pw->passwd_field_y + 0;
	  if (x > pw->passwd_field_x + pw->passwd_field_width - 1)
	    x = pw->passwd_field_x + pw->passwd_field_width - 1;
	  XDrawLine (si->dpy, si->passwd_dialog, gc1,
		     x, y,
		     x, y+pw->passwd_font->ascent + pw->passwd_font->descent-1);
	}
      pw->i_beam = (pw->i_beam + 1) % 4;
    }
  XFreeGC (si->dpy, gc1);
  XFreeGC (si->dpy, gc2);
  XSync (si->dpy, False);
}
Esempio n. 27
0
/* Put the labels on the atoms.
   This can't be a part of the display list because of the games
   we play with the translation matrix.
 */
static void
draw_labels (ModeInfo *mi)
{
  molecule_configuration *mc = &mcs[MI_SCREEN(mi)];
  int wire = MI_IS_WIREFRAME(mi);
  molecule *m = &mc->molecules[mc->which];
  XFontStruct *xfont = (mc->scale_down ? mc->xfont2 : mc->xfont1);
  GLuint font_dlist  = (mc->scale_down ? mc->font2_dlist : mc->font1_dlist);
  int i, j;

  if (!do_labels)
    return;

  if (!wire)
    glDisable (GL_LIGHTING);   /* don't light fonts */

  for (i = 0; i < m->natoms; i++)
    {
      molecule_atom *a = &m->atoms[i];
      GLfloat size = atom_size (a);
      GLfloat m[4][4];

      glPushMatrix();

      if (!wire)
        set_atom_color (mi, a, True, 1);

      /* First, we translate the origin to the center of the atom.

         Then we retrieve the prevailing modelview matrix (which
         includes any rotation, wandering, and user-trackball-rolling
         of the scene.

         We set the top 3x3 cells of that matrix to be the identity
         matrix.  This removes all rotation from the matrix, while
         leaving the translation alone.  This has the effect of
         leaving the prevailing coordinate system perpendicular to
         the camera view: were we to draw a square face, it would
         be in the plane of the screen.

         Now we translate by `size' toward the viewer -- so that the
         origin is *just in front* of the ball.

         Then we draw the label text, allowing the depth buffer to
         do its work: that way, labels on atoms will be occluded
         properly when other atoms move in front of them.

         This technique (of neutralizing rotation relative to the
         observer, after both rotations and translations have been
         applied) is known as "billboarding".
       */

      glTranslatef(a->x, a->y, a->z);               /* get matrix */
      glGetFloatv (GL_MODELVIEW_MATRIX, &m[0][0]);  /* load rot. identity */
      m[0][0] = 1; m[1][0] = 0; m[2][0] = 0;
      m[0][1] = 0; m[1][1] = 1; m[2][1] = 0;
      m[0][2] = 0; m[1][2] = 0; m[2][2] = 1;
      glLoadIdentity();                             /* reset modelview */
      glMultMatrixf (&m[0][0]);                     /* replace with ours */

      glTranslatef (0, 0, (size * 1.1));           /* move toward camera */

      glRasterPos3f (0, 0, 0);                     /* draw text here */

      /* Before drawing the string, shift the origin to center
         the text over the origin of the sphere. */
      glBitmap (0, 0, 0, 0,
                -string_width (xfont, a->label, 0) / 2,
                -xfont->descent,
                NULL);

      for (j = 0; j < strlen(a->label); j++)

        glCallList (font_dlist + (int)(a->label[j]));

      glPopMatrix();
    }

  /* More efficient to always call glEnable() with correct values
     than to call glPushAttrib()/glPopAttrib(), since reading
     attributes from GL does a round-trip and  stalls the pipeline.
   */
  if (!wire)
    glEnable (GL_LIGHTING);
}
Esempio n. 28
0
ENTRYPOINT void
draw_sws (ModeInfo *mi)
{
  sws_configuration *sc = &scs[MI_SCREEN(mi)];
/*  XtAppContext app = XtDisplayToApplicationContext (sc->dpy);*/
  Display *dpy = MI_DISPLAY(mi);
  Window window = MI_WINDOW(mi);
  int i;

  if (!sc->glx_context)
    return;

  glDrawBuffer (GL_BACK);
  glXMakeCurrent (dpy, window, *(sc->glx_context));

  glClear (GL_COLOR_BUFFER_BIT);

  draw_stars (mi);

  glMatrixMode (GL_MODELVIEW);
  glPushMatrix ();

# ifdef USE_IPHONE
  /* Need to do this every time to get device rotation right */
  reshape_sws (mi, MI_WIDTH(mi), MI_HEIGHT(mi));
# endif

  if (debug_p)
    {
      int i;
      glPushMatrix ();
      if (textures_p) glDisable (GL_TEXTURE_2D);
      glLineWidth (1);
      glTranslatef (0,-1, 0);

      glColor3f(1, 0, 0);	/* Red line is where text appears */
      glPushMatrix();
      glTranslatef(0, -0.028, 0);
      glLineWidth (4);
      glBegin(GL_LINES);
      glVertex3f(-0.5,  1, 0);
      glVertex3f( 0.5,  1, 0);
      glVertex3f(-0.5, -1, 0);
      glVertex3f( 0.5, -1, 0);
      glEnd();
      glLineWidth (1);
      glPopMatrix();

      glColor3f (0.4, 0.4, 0.4);
      for (i = 0; i < 16; i++)
        {
          box (1, 1, 1);
          grid (1, 1, sc->char_width * sc->font_scale, sc->line_height, 0);
          glTranslatef(0, 1, 0);
        }
      if (textures_p) glEnable (GL_TEXTURE_2D);
      glPopMatrix ();
    }

  /* Scroll to current position */
  glTranslatef (0.0, sc->intra_line_scroll, 0.0);

  glColor3f (1.0, 1.0, 0.4);
  glCallList (sc->text_list);
  mi->polygon_count = sc->polygon_count;

  sc->intra_line_scroll += sc->line_height / scroll_steps;

  if (sc->intra_line_scroll >= sc->line_height)
    {
      sc->intra_line_scroll = 0;

      /* Drop the oldest line off the end. */
      if (sc->lines[0])
        free (sc->lines[0]);

      /* Scroll the contents of the lines array toward 0. */
      if (sc->total_lines > 0)
        {
          for (i = 1; i < sc->total_lines; i++)
            sc->lines[i-1] = sc->lines[i];
          sc->lines[--sc->total_lines] = 0;
        }

      /* Bring in new lines at the end. */
      get_more_lines (sc);

      if (sc->total_lines < max_lines)
        /* Oops, we ran out of text... well, insert some blank lines
           here so that new text still pulls in from the bottom of
           the screen, isntead of just appearing. */
        sc->total_lines = max_lines;

      glDeleteLists (sc->text_list, 1);
      sc->text_list = glGenLists (1);
      glNewList (sc->text_list, GL_COMPILE);
      sc->polygon_count = 0;
      glPushMatrix ();
      glScalef (sc->font_scale, sc->font_scale, sc->font_scale);
      for (i = 0; i < sc->total_lines; i++)
        {
          double fade = (fade_p ? 1.0 * i / sc->total_lines : 1.0);
          int offscreen_lines = 2;

          double x = -0.5;
          double y =  ((sc->total_lines - (i + offscreen_lines) - 1)
                       * sc->line_height);
          double xoff = 0;
          char *line = sc->lines[i];

          if (debug_p)
            {
              double xx = x * 1.4;  /* a little more to the left */
              char n[20];
              sprintf(n, "%d:", i);
              draw_string (sc, xx / sc->font_scale, y / sc->font_scale, n);
            }

          if (!line || !*line)
            continue;

          if (sc->line_thickness != 1 && !textures_p)
            {
              int max_thick_lines = MAX_THICK_LINES;
              GLfloat thinnest_line = 1.0;
              GLfloat thickest_line = sc->line_thickness;
              GLfloat range = thickest_line - thinnest_line;
              GLfloat thickness;

              int j = sc->total_lines - i - 1;

              if (j > max_thick_lines)
                thickness = thinnest_line;
              else
                thickness = (thinnest_line +
                             (range * ((max_thick_lines - j) /
                                       (GLfloat) max_thick_lines)));

              glLineWidth (thickness);
            }

          if (alignment >= 0)
            {
              int n = string_width (sc, line);
              xoff = 1.0 - (n * sc->font_scale);
            }

          if (alignment == 0)
            xoff /= 2;

          glColor3f (fade, fade, 0.5 * fade);
          draw_string (sc, (x + xoff) / sc->font_scale, y / sc->font_scale,
                       line);
          if (textures_p)
            sc->polygon_count += strlen (line);
        }
      glPopMatrix ();
      glEndList ();
    }

  glPopMatrix ();

  if (mi->fps_p) do_fps (mi);
  glFinish();
  glXSwapBuffers(dpy, window);

  sc->star_theta += star_spin;
}
Esempio n. 29
0
void   GLUI_Slider::draw_val( void )
{
   int max_w, i;

   char buf[GLUI_SLIDER_MAX_VAL_STRING_SIZE];

   switch (data_type) {
   case GLUI_SLIDER_INT:
      sprintf(buf,"%d", int_val);
      break;
   case GLUI_SLIDER_FLOAT:
      sprintf(buf,"%.7g", float_val);
      break;
   default:
      fprintf(stderr,"GLUI_Slider::draw_val - Impossible data type!\n");
      abort();
   }

   max_w = w +1 -
           (GLUI_SLIDER_NAME_INDENT +
            string_width(name) +
            2*GLUI_SLIDER_NAME_SIDE_BORDER +
            2*GLUI_SLIDER_VAL_SIDE_BORDER + 2);

   if (max_w < string_width(GLUI_SLIDER_TRUNCATE_STRING)) {
      fprintf(stderr,"GLUI_Slider::draw_val - Impossible max_w!!!!\n");
      abort();
   }

   if (string_width(buf) > max_w) {

      max_w -= string_width(GLUI_SLIDER_TRUNCATE_STRING);

      i = strlen(buf)-1;
      while ((string_width(buf) > max_w) && (i>=0)) {
         buf[i--] = 0;
      }

      sprintf(&buf[i+1],"%s",GLUI_SLIDER_TRUNCATE_STRING);
   }

   draw_bkgd_box(
      GLUI_SLIDER_NAME_INDENT +
      string_width(name) +
      2*GLUI_SLIDER_NAME_SIDE_BORDER +
      GLUI_SLIDER_VAL_SIDE_BORDER - 1,

      w-1 - GLUI_SLIDER_VAL_SIDE_BORDER,

      GLUI_SLIDER_NAME_TOP_BORDER +
      GLUI_SLIDER_FONT_HEIGHT -
      GLUI_SLIDER_FONT_MID_HEIGHT +
      GLUI_SLIDER_VAL_TOP_BORDER +
      GLUI_SLIDER_FONT_HEIGHT + 1,

      GLUI_SLIDER_NAME_TOP_BORDER +
      GLUI_SLIDER_FONT_HEIGHT -
      GLUI_SLIDER_FONT_MID_HEIGHT +
      GLUI_SLIDER_VAL_TOP_BORDER + 1 );

   glColor3b( 0, 0, 0 );
   glRasterPos2i(       w -
                        string_width(buf) -
                        GLUI_SLIDER_VAL_SIDE_BORDER,
                        GLUI_SLIDER_NAME_TOP_BORDER +
                        GLUI_SLIDER_FONT_HEIGHT -
                        GLUI_SLIDER_FONT_MID_HEIGHT +
                        GLUI_SLIDER_VAL_TOP_BORDER +
                        GLUI_SLIDER_FONT_HEIGHT);
   draw_string(buf);

}
Esempio n. 30
0
static void
draw_splash_window (saver_info *si)
{
  splash_dialog_data *sp = si->sp_data;
  XGCValues gcv;
  GC gc1, gc2;
  int hspacing, vspacing, height;
  int x1, x2, x3, y1, y2;
  int sw;

#ifdef PREFS_BUTTON
  int nbuttons = 3;
#else  /* !PREFS_BUTTON */
  int nbuttons = 2;
#endif /* !PREFS_BUTTON */

  height = (sp->heading_font->ascent + sp->heading_font->descent +
	    sp->body_font->ascent + sp->body_font->descent +
	    sp->body_font->ascent + sp->body_font->descent +
	    sp->button_font->ascent + sp->button_font->descent);
  vspacing = ((sp->height
	       - (4 * sp->shadow_width)
	       - (2 * sp->internal_border)
	       - height) / 5);
  if (vspacing < 0) vspacing = 0;
  if (vspacing > (sp->heading_font->ascent * 2))
    vspacing = (sp->heading_font->ascent * 2);
	    
  gcv.foreground = sp->foreground;
  gc1 = XCreateGC (si->dpy, si->splash_dialog, GCForeground, &gcv);
  gc2 = XCreateGC (si->dpy, si->splash_dialog, GCForeground, &gcv);
  x1 = sp->logo_width;
  x3 = sp->width - (sp->shadow_width * 2);
  y1 = sp->internal_border;

  /* top heading
   */
  XSetFont (si->dpy, gc1, sp->heading_font->fid);
  sw = string_width (sp->heading_font, sp->heading_label);
  x2 = (x1 + ((x3 - x1 - sw) / 2));
  y1 += sp->heading_font->ascent;
  XDrawString (si->dpy, si->splash_dialog, gc1, x2, y1,
	       sp->heading_label, strlen(sp->heading_label));
  y1 += sp->heading_font->descent;

  /* text below top heading
   */
  XSetFont (si->dpy, gc1, sp->body_font->fid);
  y1 += vspacing + sp->body_font->ascent;
  sw = string_width (sp->body_font, sp->body_label);
  x2 = (x1 + ((x3 - x1 - sw) / 2));
  XDrawString (si->dpy, si->splash_dialog, gc1, x2, y1,
	       sp->body_label, strlen(sp->body_label));
  y1 += sp->body_font->descent;

  y1 += sp->body_font->ascent;
  sw = string_width (sp->body_font, sp->body2_label);
  x2 = (x1 + ((x3 - x1 - sw) / 2));
  XDrawString (si->dpy, si->splash_dialog, gc1, x2, y1,
	       sp->body2_label, strlen(sp->body2_label));
  y1 += sp->body_font->descent;

  /* The buttons
   */
  XSetForeground (si->dpy, gc1, sp->button_foreground);
  XSetForeground (si->dpy, gc2, sp->button_background);

/*  y1 += (vspacing * 2);*/
  y1 = sp->height - sp->internal_border - sp->button_height;

  x1 += sp->internal_border;
  y2 = (y1 + ((sp->button_height -
	       (sp->button_font->ascent + sp->button_font->descent))
	      / 2)
	+ sp->button_font->ascent);
  hspacing = ((sp->width - x1 - (sp->shadow_width * 2) -
	       sp->internal_border - (sp->button_width * nbuttons))
	      / 2);

  x2 = x1 + ((sp->button_width - string_width(sp->button_font, sp->demo_label))
	     / 2);
  XFillRectangle (si->dpy, si->splash_dialog, gc2, x1, y1,
		  sp->button_width, sp->button_height);
  XDrawString (si->dpy, si->splash_dialog, gc1, x2, y2,
	       sp->demo_label, strlen(sp->demo_label));
  sp->demo_button_x = x1;
  sp->demo_button_y = y1;
  
#ifdef PREFS_BUTTON
  x1 += hspacing + sp->button_width;
  x2 = x1 + ((sp->button_width - string_width(sp->button_font,sp->prefs_label))
	     / 2);
  XFillRectangle (si->dpy, si->splash_dialog, gc2, x1, y1,
		  sp->button_width, sp->button_height);
  XDrawString (si->dpy, si->splash_dialog, gc1, x2, y2,
	       sp->prefs_label, strlen(sp->prefs_label));
  sp->prefs_button_x = x1;
  sp->prefs_button_y = y1;
#endif /* PREFS_BUTTON */

#ifdef PREFS_BUTTON
  x1 += hspacing + sp->button_width;
#else  /* !PREFS_BUTTON */
  x1 = (sp->width - sp->button_width -
        sp->internal_border - (sp->shadow_width * 2));
#endif /* !PREFS_BUTTON */

  x2 = x1 + ((sp->button_width - string_width(sp->button_font,sp->help_label))
	     / 2);
  XFillRectangle (si->dpy, si->splash_dialog, gc2, x1, y1,
		  sp->button_width, sp->button_height);
  XDrawString (si->dpy, si->splash_dialog, gc1, x2, y2,
	       sp->help_label, strlen(sp->help_label));
  sp->help_button_x = x1;
  sp->help_button_y = y1;


  /* The logo
   */
  x1 = sp->shadow_width * 6;
  y1 = sp->shadow_width * 6;
  x2 = sp->logo_width - (sp->shadow_width * 12);
  y2 = sp->logo_height - (sp->shadow_width * 12);

  if (sp->logo_pixmap)
    {
      Window root;
      int x, y;
      unsigned int w, h, bw, d;
      XGetGeometry (si->dpy, sp->logo_pixmap, &root, &x, &y, &w, &h, &bw, &d);
      XSetForeground (si->dpy, gc1, sp->foreground);
      XSetBackground (si->dpy, gc1, sp->background);
      XSetClipMask (si->dpy, gc1, sp->logo_clipmask);
      XSetClipOrigin (si->dpy, gc1, x1 + ((x2 - (int)w) /2), y1 + ((y2 - (int)h) / 2));
      if (d == 1)
        XCopyPlane (si->dpy, sp->logo_pixmap, si->splash_dialog, gc1,
                    0, 0, w, h,
                    x1 + ((x2 - (int)w) / 2),
                    y1 + ((y2 - (int)h) / 2),
                    1);
      else
        XCopyArea (si->dpy, sp->logo_pixmap, si->splash_dialog, gc1,
                   0, 0, w, h,
                   x1 + ((x2 - (int)w) / 2),
                   y1 + ((y2 - (int)h) / 2));
    }

  /* Solid border inside the logo box. */
#if 0
  XSetForeground (si->dpy, gc1, sp->foreground);
  XDrawRectangle (si->dpy, si->splash_dialog, gc1, x1, y1, x2-1, y2-1);
#endif

  /* The shadow around the logo
   */
  draw_shaded_rectangle (si->dpy, si->splash_dialog,
			 sp->shadow_width * 4,
			 sp->shadow_width * 4,
			 sp->logo_width - (sp->shadow_width * 8),
			 sp->logo_height - (sp->shadow_width * 8),
			 sp->shadow_width,
			 sp->shadow_bottom, sp->shadow_top);

  /* The shadow around the whole window
   */
  draw_shaded_rectangle (si->dpy, si->splash_dialog,
			 0, 0, sp->width, sp->height, sp->shadow_width,
			 sp->shadow_top, sp->shadow_bottom);

  XFreeGC (si->dpy, gc1);
  XFreeGC (si->dpy, gc2);

  update_splash_window (si);
}