Exemple #1
0
/* Return a copy of source truncated to be no longer than max_len_x including the append_str on the end. */
char *truncated_string(char *dest, const char *source, size_t dest_max_len, const char *append_str, float max_len_x, float font_ratio)
{
	float string_width = 0;
	size_t dest_len = 0;
	float append_len_x = get_string_width((unsigned char*)append_str) * font_ratio;
	char *dest_p = dest;
	
	while ((*source != '\0') && (dest_len < dest_max_len-1))
	{
		float char_width = get_char_width(*source) * font_ratio;
		if ((string_width + char_width) > (max_len_x - append_len_x))
			break;
		*dest_p++ = *source++;
		dest_len++;
		string_width += char_width;
	}
	
	while ((*append_str != '\0') && (dest_len < dest_max_len-1))
	{
		*dest_p++ = *append_str++;
		dest_len++;
	}

	*dest_p = '\0';
	return dest;
}
Exemple #2
0
int draw_string_shadowed_width (int x, int y, const unsigned char * our_string, int max_width, int max_lines, float fr,float fg,float fb, float br,float bg,float bb)
{
 	 int px,py,r;
	 float zoom = ((float)max_width*12.0)/((float)get_string_width(our_string)*11.0);
 	 //set shadow colour
	 glColor3f(br, bg, bb);
	 for(px=-1;px<2;px++)
  	     for(py=-1;py<2;py++)
  	         if(px!=0 || py!=0)
  	             r=draw_string_zoomed(x+px, y+py, our_string, max_lines, zoom);
 	 //set foreground colour
	 glColor3f(fr, fg, fb);
     r=draw_string_zoomed(x, y, our_string, max_lines, zoom);
     return r;
}
Exemple #3
0
void draw_box(char * name, int x, int y, int w, int h, int rad)
{
	int l=0;

	if(name){
		l=(w-10-(get_string_width((unsigned char*)name)*8.0f/12.0f))/2.0f;
		draw_string_small(x+l+5, y-6, (unsigned char*)name, 1);
	}

	glDisable(GL_TEXTURE_2D);
	if(l>0){
		glBegin(GL_LINE_STRIP);
			glVertex2i(x+l, y);
			draw_circle_ext(x, y, rad, 5, 90, 180);
			draw_circle_ext(x, y+h-2*rad, rad, 5, 180, 270);
			draw_circle_ext(x+w-2*rad, y+h-2*rad, rad, 5, 270, 360);
			draw_circle_ext(x+w-2*rad, y, rad, 5, 0, 90);
			glVertex2i(x+w-l, y);
		glEnd();
	} else if(l<0){
		glBegin(GL_LINE_STRIP);
			glVertex2i(x+l, y);
			draw_circle_ext(x+rad, y+h-rad, rad, 5, 180, 270);
			draw_circle_ext(x+w-2*rad, y+h-rad, rad, 5, 270, 360);
			glVertex2i(x+w-l, y);
		glEnd();
	} else {
		glBegin(GL_LINE_LOOP);
			draw_circle_ext(x+rad, y, rad, 5, 90, 180);
			draw_circle_ext(x+rad, y+h-rad, rad, 5, 180, 270);
			draw_circle_ext(x+w-2*rad, y+h-rad, rad, 5, 270, 360);
			draw_circle_ext(x+w-2*rad, y, rad, 5, 0, 90);
		glEnd();
	}
	glEnable(GL_TEXTURE_2D);
#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE
}
Exemple #4
0
Fichier : input.c Projet : dmt4/ne
static void input_move_to_eol(void) {
	const int width_to_end = get_string_width(input_buffer + pos, len - pos, encoding);

	if (x + width_to_end < ne_columns) {
		x += width_to_end;
		pos = len;
		return;
	}

	x = start_x;
	pos = offset = len;
	int i = ne_columns - 1 - start_x;
	for(;;) {
		const int prev = prev_pos(input_buffer, offset, encoding);
		const int width = get_char_width(&input_buffer[prev], encoding);
		if (i - width < 0) break; 
		offset = prev;
		i -= width;
		x += width;
	}
	input_refresh();
}
Exemple #5
0
/* Creates and returns a tree view that contains each of the
   lines in IA's file as a row. */
static PsppSheetView *
create_lines_tree_view (GtkContainer *parent, struct import_assistant *ia)
{
  PsppSheetView *tree_view = NULL;
  PsppSheetViewColumn *column;
  size_t max_line_length;
  gint content_width, header_width;
  size_t i;
  const gchar *title = _("Text");

  make_tree_view (ia, 0, &tree_view);

  column = pspp_sheet_view_column_new_with_attributes (
     title, ia->asst.fixed_renderer, (void *) NULL);
  pspp_sheet_view_column_set_cell_data_func (column, ia->asst.fixed_renderer,
                                           render_line, NULL, NULL);
  pspp_sheet_view_column_set_resizable (column, TRUE);
  pspp_sheet_view_column_set_expand (column, TRUE);

  max_line_length = 0;
  for (i = 0; i < ia->file.line_cnt; i++)
    {
      size_t w = ds_length (&ia->file.lines[i]);
      max_line_length = MAX (max_line_length, w);
    }

  content_width = get_monospace_width (tree_view, ia->asst.fixed_renderer,
                                       max_line_length);
  header_width = get_string_width (tree_view, ia->asst.prop_renderer, title);
  pspp_sheet_view_column_set_fixed_width (column, MAX (content_width,
                                                     header_width));
  pspp_sheet_view_append_column (tree_view, column);

  gtk_container_add (parent, GTK_WIDGET (tree_view));
  gtk_widget_show (GTK_WIDGET (tree_view));

  return tree_view;
}
// display the current time for the hud timer, coloured by stopped or running
//
int Hud_Timer::display(window_info *win, int base_y_start)
{
	char str[10];
	int x;
	check_cm_menu(win, base_y_start);
	if (input && (!view_hud_timer || !get_show_window(input->popup_win)))
		destroy_popup();
	if (!view_hud_timer)
		return 0;
	base_y_start -= height;
	safe_snprintf(str, sizeof(str), "%c%1d:%02d", ((mode_coundown) ?countdown_str[0] :stopwatch_str[0]), current_value/60, current_value%60);
	x= 3+(win->len_x - (get_string_width((unsigned char*)str)*11)/12)/2;
	if (running)
		draw_string_shadowed(x, 2 + base_y_start, (unsigned char*)str, 1,0.5f, 1.0f, 0.5f,0.0f,0.0f,0.0f);
	else
		draw_string_shadowed(x, 2 + base_y_start, (unsigned char*)str, 1,1.0f, 0.5f, 0.5f,0.0f,0.0f,0.0f);
	if (mouse_over)
	{
		char *use_str = ((mode_coundown) ?countdown_str:stopwatch_str);
		draw_string_small_shadowed(-(int)(SMALL_FONT_X_LEN*(strlen(use_str)+0.5)), base_y_start, (unsigned char*)use_str, 1,1.0f,1.0f,1.0f,0.0f,0.0f,0.0f);
		mouse_over = false;
	}
	return height;
}
Exemple #7
0
void draw_smooth_button(char * str, float size, int x, int y, int w, int lines, float r, float g, float b, int highlight, float hr, float hg, float hb, float ha)
{
	int radius=lines*BUTTONRADIUS*size;
	float width_ratio=(size*DEFAULT_FONT_X_LEN)/12.0f;
	int xstr=0;
	
	if(str){
		xstr=x+radius+(w-(get_string_width((unsigned char*)str)*width_ratio))/2.0f;
	}

	glDisable(GL_TEXTURE_2D);

	if(r>=0.0f)
		glColor3f(r, g, b);
	
#ifdef OSX
	if (square_buttons) {
		glBegin(GL_LINE_LOOP);
		glVertex3i(x,y,0);
		glVertex3i(x + w + radius*2,y,0);
		glVertex3i(x + w + radius*2,y + radius*2,0);
		glVertex3i(x,y + radius*2,0);
		glEnd();
		
		if(highlight) {
			if(hr>=0.0f)
				glColor4f(hr,hg,hb,ha);
			glBegin(GL_POLYGON);
			glVertex3i(x+1,y+1,0);
			glVertex3i(x + w + radius*2 -1,y+1,0);
			glVertex3i(x + w + radius*2 -1,y + radius*2 -1,0);
			glVertex3i(x+1,y + radius*2 -1,0);
			glEnd();
		}
		
		glEnable(GL_TEXTURE_2D);
	} else {
#endif
	glBegin(GL_LINE_LOOP);
		draw_circle_ext(x, y, radius, 10, 90, 270);
		draw_circle_ext(x+w, y, radius, 10, -90, 90);
	glEnd();
	if(highlight) {
		if(hr>=0.0f)
			glColor4f(hr,hg,hb,ha);
		glBegin(GL_POLYGON);
			draw_circle_ext(x+1, y+1, radius-1, 10, 90, 270);
			draw_circle_ext(x+w+1, y+1, radius-1, 10, -90, 90);
		glEnd();
	}
	glEnable(GL_TEXTURE_2D);

#ifdef OSX
	}	// to close off square_buttons conditional
#endif

	if(highlight) {
		glColor3f(r, g, b);
	}

	if(str) {
		draw_string_zoomed(xstr + gx_adjust, y+radius/2.0f + gy_adjust, (unsigned char*)str, lines, size);
	}
#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE
}
Exemple #8
0
void display_map_markers() {
	int ax, ay;
	float z,x,y;
	int i;
	GLdouble model[16],proj[16];
	GLint view[4];
	GLdouble hx,hy,hz;
	float banner_width;
	float font_scale = 1.0f/ALT_INGAME_FONT_X_LEN;
	float font_size_x=font_scale*SMALL_INGAME_FONT_X_LEN;
	float font_size_y=font_scale*SMALL_INGAME_FONT_Y_LEN;
	char tmpb[4];
	actor *me;

	me = get_our_actor();
	if(!me) return;
	ax = me->x_pos;
	ay = me->y_pos;
	
	glGetDoublev(GL_MODELVIEW_MATRIX, model);
	glGetDoublev(GL_PROJECTION_MATRIX, proj);
	glGetIntegerv(GL_VIEWPORT, view);
	glPushMatrix();
	glLoadIdentity();
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	glOrtho(view[0],view[2]+view[0],view[1],view[3]+view[1],0.0f,-1.0f);
	glDepthFunc(GL_LEQUAL);
	glEnable(GL_TEXTURE_2D);
	glColor4f(1.0,1.0,1.0,1.0);
	glDisable(GL_LIGHTING);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE);
	
	for(i=0;i<max_mark;i++){
		x=marks[i].x/2.0;
		y=marks[i].y/2.0;
		x += (TILESIZE_X / 2);
		y += (TILESIZE_Y / 2);
		if(DST(ax,ay,x,y)>MARK_DIST||marks[i].x<0||!marks_3d) continue;
		z = get_tile_height(marks[i].x, marks[i].y)+2.3;
		gluProject(x, y, z, model, proj, view, &hx, &hy, &hz);
		//shorten text
		memcpy(tmpb,marks[i].text+MARK_CLIP_POS,4);
		marks[i].text[MARK_CLIP_POS]=marks[i].text[MARK_CLIP_POS+1]=marks[i].text[MARK_CLIP_POS+2]='.';
		marks[i].text[MARK_CLIP_POS+3]=0;
		banner_width = ((float)get_string_width((unsigned char*)marks[i].text)*(font_size_x*name_zoom))/2.0;
		draw_ortho_ingame_string(hx-banner_width, hy, hz, (unsigned char*)marks[i].text, 4, font_size_x, font_size_y);
		//restore text
		memcpy(marks[i].text+MARK_CLIP_POS,tmpb,4);
			
	}
	glDisable(GL_BLEND);
	glDisable(GL_TEXTURE_2D);
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
	glPopMatrix();
	//glEnable(GL_LIGHTING);
	glDepthFunc(GL_LESS);
	
	
}
Exemple #9
0
int display_book_handler(window_info *win)
{
	int x=32,i,p;
	char str[20];
	book *b=win->data;
	
	if(!b) {
		toggle_window(book_win);
		return 1;
	}
	switch(b->type){
		case 1:
#ifdef	NEW_TEXTURES
			bind_texture(paper1_text);
#else	/* NEW_TEXTURES */
			get_and_set_texture_id(paper1_text);
#endif	/* NEW_TEXTURES */
			break;
		case 2:
#ifdef	NEW_TEXTURES
			bind_texture(book1_text);
#else	/* NEW_TEXTURES */
			get_and_set_texture_id(book1_text);
#endif	/* NEW_TEXTURES */
			break;
	}
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f,1.0f); glVertex3i(0,0,0);
		glTexCoord2f(0.0f,0.0f); glVertex3i(0,win->len_y-20,0);
		glTexCoord2f(1.0f,0.0f); glVertex3i(win->len_x,win->len_y-20,0);
		glTexCoord2f(1.0f,1.0f); glVertex3i(win->len_x,0,0);
	glEnd();
	glPushMatrix();
	if(b->type==1)
		glTranslatef(15,25,0);
	else if(b->type==2)
		glTranslatef(30,15,0);
	display_book(b, b->type);
	glPopMatrix();
	
	glPushMatrix();
	glTranslatef(0,win->len_y-18,0);
	book_mouse_y-=(win->len_y-18);
	x=10;
	if(book_mouse_y>0 && book_mouse_y<18 && book_mouse_x>10 && book_mouse_x<(get_string_width((unsigned char*)"<-")*11.0f/12.0f)){
		glColor3f(0.95f, 0.76f, 0.52f);
		draw_string(10,-2,(unsigned char*)"<-",0);
		
		glColor3f(0.77f,0.59f, 0.38f);
		draw_string(win->len_x-33,-2,(unsigned char*)"->",0);
	} else if(book_mouse_y>0 && book_mouse_y<18 && book_mouse_x>win->len_x-33 && book_mouse_x<win->len_x-33+(get_string_width((unsigned char*)"->")*11.0f/12.0f)){
		glColor3f(0.95f, 0.76f, 0.52f);
		draw_string(win->len_x-33,-2,(unsigned char*)"->",0);
		
		glColor3f(0.77f,0.59f, 0.38f);
		draw_string(10,-2,(unsigned char*)"<-",0);
	} else {
		glColor3f(0.77f,0.59f, 0.38f);
		draw_string(10,-2,(unsigned char*)"<-",0);
		draw_string(win->len_x-33,-2,(unsigned char*)"->",0);
	}
	if(b->type==1) {
		x=50;
		p=b->active_page-5;
		if(p>=0){
			safe_snprintf(str,sizeof(str),"%d",p+1);

			if(book_mouse_y>0 && book_mouse_y<18 && book_mouse_x>x && book_mouse_x<x+(get_string_width((unsigned char*)str)*11.0f/12.0f)){
				glColor3f(0.95f, 0.76f, 0.52f);
				draw_string(x,0,(unsigned char*)str,0);
				glColor3f(0.77f,0.59f, 0.38f);
			} else 
				draw_string(x,0,(unsigned char*)str,0);
		}
		x=100;
		p=b->active_page-2;
		if(p>=0){
			safe_snprintf(str,sizeof(str),"%d",p+1);
			
			if(book_mouse_y>0 && book_mouse_y<18 && book_mouse_x>x && book_mouse_x<x+(get_string_width((unsigned char*)str)*11.0f/12.0f)){
				glColor3f(0.95f, 0.76f, 0.52f);
				draw_string(x,0,(unsigned char*)str,0);
				glColor3f(0.77f,0.59f, 0.38f);
			} else 
				draw_string(x,0,(unsigned char*)str,0);
		}
		x=win->len_x-120;
		p=b->active_page+2;
		if(p<b->no_pages){
			safe_snprintf(str,sizeof(str),"%d",p+1);
			
			if(book_mouse_y>0 && book_mouse_y<18 && book_mouse_x>x && book_mouse_x<x+(get_string_width((unsigned char*)str)*11.0f/12.0f)){
				glColor3f(0.95f, 0.76f, 0.52f);
				draw_string(x,0,(unsigned char*)str,0);
				glColor3f(0.77f,0.59f, 0.38f);
			} else 
				draw_string(x,0,(unsigned char*)str,0);
		}
		x=win->len_x-70;
		p=b->active_page+5;
		if(p<b->no_pages){
			safe_snprintf(str,sizeof(str),"%d",p+1);
			
			if(book_mouse_y>0 && book_mouse_y<18 && book_mouse_x>x && book_mouse_x<x+(get_string_width((unsigned char*)str)*11.0f/12.0f)){
				glColor3f(0.95f, 0.76f, 0.52f);
				draw_string(x,0,(unsigned char*)str,0);
				glColor3f(0.77f,0.59f, 0.38f);
			} else 
				draw_string(x,0,(unsigned char*)str,0);
		}
	} else if(b->type==2) {
		x=win->len_x/2-60;
		for(i=1;i<5;i++){
			p=b->active_page-i*b->type;
			if(p>=0){
				safe_snprintf(str,sizeof(str),"%d",p+1);
				
				if(book_mouse_y>0 && book_mouse_y<18 && book_mouse_x>x && book_mouse_x<x+(get_string_width((unsigned char*)str)*11.0f/12.0f)){
					glColor3f(0.95f, 0.76f, 0.52f);
					draw_string(x,0,(unsigned char*)str,0);
					glColor3f(0.77f,0.59f, 0.38f);
				} else
					draw_string(x,0,(unsigned char*)str,0);
			}
			x-=40;
		}
		x=win->len_x/2+50;
		for(i=1;i<5;i++){
			p=b->active_page+i*b->type;
			if(p<b->no_pages){
				safe_snprintf(str,sizeof(str),"%d",p+1);
				
				if(book_mouse_y>0 && book_mouse_y<18 && book_mouse_x>x && book_mouse_x<x+(get_string_width((unsigned char*)str)*11.0f/12.0f)){
					glColor3f(0.95f, 0.76f, 0.52f);
					draw_string(x,0,(unsigned char*)str,0);
					glColor3f(0.77f,0.59f, 0.38f);
				} else
					draw_string(x,0,(unsigned char*)str,0);
			}
			x+=40;
		}
	}
	
	if(book_mouse_y>0 && book_mouse_y<18 && book_mouse_x>win->len_x/2-15 && book_mouse_x<win->len_x/2+15)
		glColor3f(0.95f, 0.76f, 0.52f);
	
	draw_string(win->len_x/2-15,0,(unsigned char*)"[X]",0);
	glPopMatrix();
#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE
	return 1;
}
Exemple #10
0
void draw_floatingmessage(floating_message *message, float healthbar_z) {
        float cut;
        double f, width, y, x, z;
        double model[16],proj[16];
        int view[4];

        if(!message)return;

        cut=message->active_time/4000.0f;
        f = ((float)(message->active_time-(cur_time-message->first_time)))/message->active_time;
        glColor4f(message->color[0], message->color[1], message->color[2], f > cut ? 1.0f : (f / cut));
		width = (float)get_string_width((unsigned char*)message->message) * INGAME_FONT_X_LEN * name_zoom * 8.0;

        //Figure out where the point just above the actor's head is in the viewport
        glGetDoublev(GL_MODELVIEW_MATRIX, model);
        glGetDoublev(GL_PROJECTION_MATRIX, proj);
        glGetIntegerv(GL_VIEWPORT, view);
        if (first_person)
        {
			x=window_width/2.0;
			y=window_height/2.0-40.0;
        }
        else
        {
			gluProject(0.0, 0.0, healthbar_z * get_actor_scale(your_actor), model, proj, view, &x, &y, &z);
			y += 50*name_zoom; // size of the actor name/bar
        }


        switch(message->direction){
                case FLOATINGMESSAGE_EAST:
                        x+=-width/2.0f-(f*window_width*0.1f);
                        y+=window_height*0.1;
                        break;
                case FLOATINGMESSAGE_SOUTH:
                        x+=-width/2.0f;
                        y+=f*window_height*0.1;
                        break;
                case FLOATINGMESSAGE_WEST:
                        x+=-width/2.0f+(f*window_width*0.1f);
                        y+=window_height*0.1;
                        break;
                case FLOATINGMESSAGE_MIDDLE:
                        x+=-width/2.0f;
                        y+=f*window_height*0.05f;
                        break;
                case FLOATINGMESSAGE_NORTH:
                default:
                        x+=-width/2.0f;
                        y+=(1.0-f)*window_height*0.1;
                        break;
        }

        glPushMatrix();
        glLoadIdentity();
        glMatrixMode(GL_PROJECTION);
        glPushMatrix();
        glLoadIdentity();
        glOrtho(view[0],view[2]+view[0],view[1],view[3]+view[1],0.0f,-1.0f);

        draw_ortho_ingame_string(x, y, 0, (unsigned char*)message->message, 1, INGAME_FONT_X_LEN*8.0, INGAME_FONT_Y_LEN*8.0);

        glMatrixMode(GL_PROJECTION);
        glPopMatrix();
        glMatrixMode(GL_MODELVIEW);
        glPopMatrix();

}
Exemple #11
0
int	draw_window_title(window_info *win)
{
	float u_first_start= (float)31/255;
	float u_first_end= 0;
#ifdef	NEW_TEXTURES
	float v_first_start = (float)160/255;
	float v_first_end = (float)175/255;
#else	/* NEW_TEXTURES */
	float v_first_start= 1.0f-(float)160/255;
	float v_first_end= 1.0f-(float)175/255;
#endif	/* NEW_TEXTURES */

	float u_middle_start= (float)32/255;
	float u_middle_end= (float)63/255;
#ifdef	NEW_TEXTURES
	float v_middle_start = (float)160/255;
	float v_middle_end = (float)175/255;
#else	/* NEW_TEXTURES */
	float v_middle_start= 1.0f-(float)160/255;
	float v_middle_end= 1.0f-(float)175/255;
#endif	/* NEW_TEXTURES */

	float u_last_start= 0;
	float u_last_end= (float)31/255;
#ifdef	NEW_TEXTURES
	float v_last_start = (float)160/255;
	float v_last_end = (float)175/255;
#else	/* NEW_TEXTURES */
	float v_last_start= 1.0f-(float)160/255;
	float v_last_end= 1.0f-(float)175/255;
#endif	/* NEW_TEXTURES */

	if((win->flags&ELW_TITLE_BAR) == ELW_TITLE_NONE)	return 0;

	glColor3f(1.0f,1.0f,1.0f);
	//ok, now draw that shit...

#ifdef	NEW_TEXTURES
	bind_texture(icons_text);
#else	/* NEW_TEXTURES */
	get_and_set_texture_id(icons_text);
#endif	/* NEW_TEXTURES */
	glEnable(GL_ALPHA_TEST);
    glAlphaFunc(GL_GREATER,0.03f);
	glBegin(GL_QUADS);

	glTexCoord2f(u_first_end, v_first_start);
	glVertex3i(0, -ELW_TITLE_HEIGHT, 0);
	glTexCoord2f(u_first_end, v_first_end);
	glVertex3i(0, 0, 0);
	glTexCoord2f(u_first_start, v_first_end);
	glVertex3i(32, 0, 0);
	glTexCoord2f(u_first_start, v_first_start);
	glVertex3i(32, -ELW_TITLE_HEIGHT, 0);

	// draw one streched out cell to the proper size
	glTexCoord2f(u_middle_end, v_middle_start);
	glVertex3i(32, -ELW_TITLE_HEIGHT, 0);
	glTexCoord2f(u_middle_end, v_middle_end);
	glVertex3i(32, 0, 0);
	glTexCoord2f(u_middle_start, v_middle_end);
	glVertex3i(win->len_x-32, 0, 0);
	glTexCoord2f(u_middle_start, v_middle_start);
	glVertex3i(win->len_x-32, -ELW_TITLE_HEIGHT, 0);

	glTexCoord2f(u_last_end, v_last_start);
	glVertex3i(win->len_x-32, -ELW_TITLE_HEIGHT, 0);
	glTexCoord2f(u_last_end, v_last_end);
	glVertex3i(win->len_x-32, 0, 0);
	glTexCoord2f(u_last_start, v_last_end);
	glVertex3i(win->len_x, 0, 0);
	glTexCoord2f(u_last_start, v_last_start);
	glVertex3i(win->len_x, -ELW_TITLE_HEIGHT, 0);

	glEnd();
	glDisable(GL_ALPHA_TEST);

	// draw the name of the window
	if(win->flags&ELW_TITLE_NAME)
		{
			int	len;
			const unsigned char* name = (const unsigned char*) win->window_name;

			glEnable(GL_TEXTURE_2D);
			glColor3f(win->border_color[0],win->border_color[1],win->border_color[2]);
			// center text
			len = (get_string_width (name) * 8) / 12;
			draw_string_small((win->len_x-len)/2, -ELW_TITLE_HEIGHT, name, 1);
		}

	return 1;
}
Exemple #12
0
int display_knowledge_handler(window_info *win)
{
	size_t i;
	int x = text_border;
	int y = text_border;
	int scroll = vscrollbar_get_pos (win->window_id, knowledge_scroll_id);
	char points_string[16];
	char *research_string;
	int points_pos;
	float font_ratio = win->small_font_len_x/12.0;
	float max_name_x = (win->len_x - win->box_size - 2*x)/2;
	int is_researching = 1;
	int text_width = win->len_x - 2 * text_border;
	char knowledge_text_buf[TEXTBUFSIZE];

	if(your_info.research_total && 
	   (your_info.research_completed==your_info.research_total))
		safe_snprintf(points_string, sizeof(points_string), "%s", completed_research);
	else
		safe_snprintf(points_string, sizeof(points_string), "%i/%i",your_info.research_completed,your_info.research_total);
	if(your_info.researching < knowledge_count)
	{
		research_string = knowledge_list[your_info.researching].name;
	}
	else if (your_info.researching < sizeof(knowledge_list))
	{
		research_string = unknown_book_short_str;
	}
	else
	{
		research_string = not_researching_anything;
		points_string[0] = '\0';
		is_researching = 0;
	}
	points_pos = (progress_right_x - progress_left_x - strlen(points_string) * win->small_font_len_x) / 2;

	glDisable(GL_TEXTURE_2D);
	glColor3f(0.77f,0.57f,0.39f);
	glBegin(GL_LINES);
	// window separators
	glVertex3i(0,booklist_y_len,0);
	glVertex3i(win->len_x,booklist_y_len,0);
	glVertex3i(0,progressbox_y_len,0);
	glVertex3i(win->len_x,progressbox_y_len,0);
	//progress bar
	glVertex3i(progress_left_x,progress_top_y,0);
	glVertex3i(progress_right_x,progress_top_y,0);
	glVertex3i(progress_left_x,progress_bot_y,0);
	glVertex3i(progress_right_x,progress_bot_y,0);
	glVertex3i(progress_left_x,progress_top_y,0);
	glVertex3i(progress_left_x,progress_bot_y,0);
	glVertex3i(progress_right_x,progress_top_y,0);
	glVertex3i(progress_right_x,progress_bot_y,0);
	glEnd();
	//progress bar
	if (is_researching)
	{
		int progress = (progress_right_x - progress_left_x - 1) * get_research_fraction();
		glBegin(GL_QUADS);
		glColor3f(0.40f,0.40f,1.00f);
		glVertex3i(progress_left_x+1+gx_adjust,progress_top_y+gy_adjust,0);
		glVertex3i(progress_left_x+1+progress+gx_adjust,progress_top_y+gy_adjust,0);
		glColor3f(0.10f,0.10f,0.80f);
		glVertex3i(progress_left_x+1+progress+gx_adjust,progress_bot_y-1+gy_adjust,0);
		glVertex3i(progress_left_x+1+gx_adjust,progress_bot_y-1+gy_adjust,0);
		glColor3f(0.77f,0.57f,0.39f);
		glEnd();
	}
	glEnable(GL_TEXTURE_2D);
	//draw text
	if (selected_book >= 0 && knowledge_list[selected_book].present && knowledge_list[selected_book].has_book)
		text_width = book_start_x - 2 * text_border;
	put_small_text_in_box_zoomed((unsigned char *)raw_knowledge_string, strlen((char *)raw_knowledge_string), text_width, (char *)knowledge_text_buf, win->current_scale);
	draw_string_small_zoomed(text_border,booklist_y_len + text_border,(unsigned char*)knowledge_text_buf, info_lines, win->current_scale);
	glColor3f(1.0f,1.0f,1.0f);
	draw_string_small_zoomed(text_border,progress_top_y+3+gy_adjust,(unsigned char*)researching_str,1, win->current_scale);
	draw_string_small_zoomed(text_border+(strlen(researching_str)+1)*win->small_font_len_x,progress_top_y+3+gy_adjust,(unsigned char*)research_string,1, win->current_scale);
	draw_string_small_zoomed(progress_left_x+points_pos+gx_adjust,progress_top_y+3+gy_adjust,(unsigned char*)points_string,1, win->current_scale);
	if (is_researching && mouse_over_progress_bar)
	{
		char eta_string[20];
		int eta_pos;
		get_research_eta_str(eta_string, sizeof(eta_string));
		eta_pos = (int)(progress_right_x - progress_left_x - strlen(eta_string)*win->small_font_len_x) / 2;
		draw_string_small_zoomed(progress_left_x + eta_pos, progress_top_y - win->small_font_len_y + 2, (unsigned char*)eta_string, 1, win->current_scale);
		mouse_over_progress_bar=0;
	}
	// Draw knowledges
	for(i = 2*scroll; y < (booklist_y_len - booklist_y_step); i++)
	{
		int highlight = 0;
		float colour_brightness = (knowledge_list[i].present) ?1.0 : 0.6;

		if (*highlight_string && (strlen(knowledge_list[i].name) > 0) &&
			(get_string_occurance(highlight_string, knowledge_list[i].name, strlen(knowledge_list[i].name), 1) != -1))
			highlight = 1;

		if (!highlight && (i == selected_book))
		{
			GLfloat cols[3];
			elglGetColour3v("global.mouseselected", cols);
			glColor3f (cols[0]*colour_brightness, cols[1]*colour_brightness, cols[2]*colour_brightness);
		}
		else if (knowledge_list[i].mouse_over)
			elglColourN("global.mousehighlight");
		else if (highlight)
			glColor3f (1.0f*colour_brightness, 0.6f*colour_brightness, 0.0f*colour_brightness);
		else
			glColor3f (1.0f*colour_brightness, 1.0f*colour_brightness, 1.0f*colour_brightness);

		/* truncate the string if it is too long */
		if ((get_string_width((unsigned char*)knowledge_list[i].name) * font_ratio) > max_name_x)
		{
			const char *append_str = "... ";
			size_t dest_max_len = strlen(knowledge_list[i].name)+strlen(append_str)+1;
			char *used_name = (char *)malloc(dest_max_len);
			truncated_string(used_name, knowledge_list[i].name, dest_max_len, append_str, max_name_x, font_ratio);
			draw_string_zoomed(x, y, (unsigned char*)used_name,1,font_ratio);
			/* if the mouse is over this line and its truncated, tooltip to full name */
			if (knowledge_list[i].mouse_over)
			{
				show_help(knowledge_list[i].name, -TAB_MARGIN, win->len_y+10+TAB_MARGIN, win->current_scale);
				know_show_win_help = 0;
			}
			free(used_name);
		}
		else
			draw_string_zoomed(x,y,(unsigned char*)knowledge_list[i].name,1,font_ratio);

		x += (win->len_x-win->box_size-2*text_border)/2;
		if (i % 2 == 1)
		{
			y += booklist_y_step;
			x = text_border;
		}
	}
	if (know_show_win_help)
	{
		show_help(cm_help_options_str, -TAB_MARGIN, win->len_y+10+TAB_MARGIN, win->current_scale);
		know_show_win_help = 0;
	}
#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE
	return 1;
}
Exemple #13
0
int mp_lobby_render()
{
	memcpy(get_program_secondary_buf(),get_background()->color,get_vram_size());
	printgr_shade_centered(get_program_secondary_buf(),"Lobby",get_v_res()/2-200, 0.75,0xFFFF,5,5, .1, 8);
	printgr_shade(get_program_secondary_buf(),get_program_playername(),10, get_v_res()- get_line_space(2), 0.75,0xFFFF,5,5, .1, 2);
	if(*get_date_str_ptr() != NULL)
		printgr_shade_centered(get_program_secondary_buf(),*get_date_str_ptr(),0, 0.75,0xFFFF,5,5, .1, 1);
	if(get_role() == SEARCHING)
	{
		if(get_ticks() % 120 < 30)
			printgr_shade_centered(get_program_secondary_buf(),"Searching",get_v_res()/2, 0.75,0xFFFF,5,5, .1, 7);
		else if(get_ticks() % 120 < 60)
			printgr_shade_centered(get_program_secondary_buf(),"Searching.",get_v_res()/2, 0.75,0xFFFF,5,5, .1, 7);
		else if(get_ticks() % 120 < 90)
			printgr_shade_centered(get_program_secondary_buf(),"Searching..",get_v_res()/2, 0.75,0xFFFF,5,5, .1, 7);
		else
			printgr_shade_centered(get_program_secondary_buf(),"Searching...",get_v_res()/2, 0.75,0xFFFF,5,5, .1, 7);
	}
	else if(get_role() == FAILED)
	{
		printgr_shade_centered(get_program_secondary_buf(),"Connection Failed",get_v_res()/2, 0.75,0xFFFF,5,5, .1, 7);
		printgr_shade_centered(get_program_secondary_buf(),"Player Names must not be the same",get_v_res()/2+100, 0.75,0xFFFF,5,5, .1, 7);
	}
	if(get_role() == CLIENT || get_role() == SERVER)
	{
		strcpy(opponentmessage, "Opponent: ");
		strcat(opponentmessage, get_program_playername2());
		printgr_shade_centered(get_program_secondary_buf(),opponentmessage,get_v_res()/2 +200, 0.75,0xFFFF,5,5, .1, 5);
		draw_cursor(get_program_secondary_buf(),get_cursor());
		size_t i;
		if(lobby_state == PLAYER2_READY)
		{
			lobby_buttons[0]->text = "Play";
			lobby_buttons[0]->trans = 0.9;
		}
		else if(lobby_state == PLAYER1_READY)
		{
			lobby_buttons[0]->text = "Unready";
			lobby_buttons[0]->trans = 0.6;
		}
		else if(lobby_state == BOTH_READY)
		{
			lobby_buttons[0]->text = "Launching";
			lobby_buttons[0]->trans = 0.9;
		}
		else {
			lobby_buttons[0]->text = "Ready";
			lobby_buttons[0]->trans = 0.9;
		}
		lobby_buttons[0]->width = get_string_width(lobby_buttons[0]->text, lobby_buttons[0]->size);
		lobby_buttons[0]->pos.x = get_h_res()/2- lobby_buttons[0]->width/2;
		for(i = 0; i < NUM_LOBBY_BUTTONS; i++)
		{
			draw_button_t_centered(lobby_buttons[i]);
		}
		for(i = 0; i < size(im_message_log) && i < 20; ++i)
		{
			if(**(char**)at(im_message_log,size(im_message_log)-i-1) == 'm')
					printgr_shade(get_program_secondary_buf(),*(char**)at(im_message_log, size(im_message_log)-i-1),20,get_v_res()-100-(i+1)*20, .75,RGB(0,63,16),5,5, .1, 2);
			else printgr_shade(get_program_secondary_buf(),*(char**)at(im_message_log, size(im_message_log)-i-1),20,get_v_res()-100-(i+1)*20, .75,0xFFFF,5,5, .1, 2);
		}
		printgr_shade(get_program_secondary_buf(),">",10,get_v_res()-100, 0.75,0xFFFF,5,5, .1, 2);
		printgr_shade(get_program_secondary_buf(),current_im,20,get_v_res()-100, 0.75,0xFFFF,5,5, .1, 2);
	}
	if(darken > 0)
		darken_buf(get_program_secondary_buf(),darken);
	if(darken > 0 && !fade_condition)
	{

		darken-= FADE_RATE;
	}
	if(fade_condition)
	{
		if(darken <= 127)
		{

			darken += FADE_RATE;
		}
		else
		{
			if(lobby_state == BOTH_READY)
			{

				mp_game();
				fade_condition = false;
				lobby_state = NOT_READY;
			}
			else continue_condition = false;
		}
	}
	copy_video_buffer(get_program_video_mem(), get_program_secondary_buf());
	return 0;
}
Exemple #14
0
int BEE::Font::get_string_width(std::string text) {
	return get_string_width(text, font_size);
}