Пример #1
0
int draw_string_width(int x, int y, const unsigned char * our_string, int max_width, int max_lines)
{
	return draw_string_zoomed_width (x, y, our_string, max_width, max_lines, 1.0f);
}
Пример #2
0
int draw_string_zoomed (int x, int y, const unsigned char * our_string, int max_lines, float text_zoom)
{
	return draw_string_zoomed_width (x, y, our_string, window_width, max_lines, text_zoom);
}
Пример #3
0
/*  Access the caught url list and display in a scrollable window. */
static int display_url_handler(window_info *win)
{
#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE

	url_win_hover_url = NULL;
	
	/* save current position so K_WINDOWS_ON_TOP restores to where its been moved */
	url_win_x = win->cur_x;
	url_win_y = win->cur_y;
 
	glEnable(GL_TEXTURE_2D);
	set_font(0);
	
	/* check for external state change */
	if (!have_url_count && !url_win_status)
		url_win_status = URLW_EMPTY;
	/* if we have a status message, display it */
	if (url_win_status)
	{
		char *message[] = { urlcmd_none_str, urlwin_clear_str, urlwin_open_str };
		int y_start = (url_win_text_start_y - 0.75 * url_win_text_zoom * DEFAULT_FONT_Y_LEN)/2;
		glColor3f(1.0f,1.0f,1.0f);
		draw_string_zoomed(url_win_help_x, y_start, (unsigned char *)message[url_win_status-1], 1, 0.75 * url_win_text_zoom);
		url_win_status = (have_url_count) ?0 :URLW_EMPTY;
	}
	
	/* display a page of url */
 	if (have_url_count)
	{
		list_node_t *local_head = newest_url;
		int currenty = url_win_text_start_y;
		int start_url = 0;
		int num_url_displayed = 0;
		
		/* don't scroll if everything will fit in the window, also catch if the list has been cleared via #url */
		if (((url_win_line_step * have_url_count) <= url_win_text_len_y) || (url_win_top_line > have_url_count))
			url_win_top_line = 0;
		
		/* move to the first url to be displayed - set from the scroll bar */
		while (start_url < url_win_top_line && local_head->next != NULL)
		{
			local_head = local_head->next;
			start_url++;
		}
		
		/* loop over the remaining URLs while there is room in the window */
		while (local_head != NULL)
		{
			char *thetext = ((URLDATA *)local_head->data)->text;
			int dsp_string_len = 0;
			float string_width = 0;
			int highlight_url = 0;
			
			/* stop now if the url line will not fit into the window */
			if (((currenty - url_win_text_start_y) + url_win_line_step) > url_win_text_len_y)
				break;
				
			/* highlight the active (F2) url */
			if (local_head == active_url)
				glColor3f(0.0f,1.0f,0.0f);
			else
				glColor3f(1.0f,1.0f,1.0f);
			
			/* calculate the length of string we can display */
			while((*thetext != '\0') && (string_width < url_win_max_string_width))
			{
				float char_width = get_char_width(*thetext++) * url_win_text_zoom * DEFAULT_FONT_X_LEN / 12.0;
				if ((string_width+char_width) < url_win_max_string_width)
				{
					dsp_string_len++;
					string_width += char_width;
				}
			}
						
			/* if the string length will fit in the window, just draw it */
			if (dsp_string_len == strlen(((URLDATA *)local_head->data)->text))
				draw_string_zoomed(url_win_sep, currenty, (unsigned char *)((URLDATA *)local_head->data)->text, 1, url_win_text_zoom);
			/* otherwise, draw a truncated version with "..." at the end */
			else
			{
				//float toobig_width = (get_char_width('-') + get_char_width('>'))
				//	* url_win_text_zoom * DEFAULT_FONT_X_LEN / 12.0;
				float toobig_width = (3*get_char_width('.'))
					* url_win_text_zoom * DEFAULT_FONT_X_LEN / 12.0;
				draw_string_zoomed_width(url_win_sep, currenty, (unsigned char *)((URLDATA *)local_head->data)->text,
					url_win_sep + url_win_max_string_width - toobig_width, 1, url_win_text_zoom);
				draw_string_zoomed(url_win_sep + url_win_max_string_width - toobig_width, currenty,
					(unsigned char *)"..." , 1, url_win_text_zoom);
			}
			
			/* step down a line, do it now as the maths for mouse over below is easier */
			currenty += url_win_line_step;
			
			/* if the mouse is over the current line, hightlight it */
			if ((mouse_y >= win->cur_y + currenty - url_win_line_step) &&
				(mouse_y < win->cur_y + currenty) &&
				(mouse_x >= win->cur_x + (int)url_win_sep) &&
				(mouse_x - (int)url_win_sep <= win->cur_x + url_win_max_string_width))
			{
				/* remember which url we're over in case it's clicked */
				url_win_hover_url = local_head;				
				highlight_url = 1;
			}
				
			/* if a context menu is open, only hightlight the last URL hovered over before the context opened */
			if (cm_window_shown() != CM_INIT_VALUE)
			{
				if (cm_url == local_head)
					highlight_url = 1;
				else
					highlight_url = 0;
			}
			else
				cm_url = NULL;
			
			/* if mouse over or context activated, highlight the current URL */
			if (highlight_url)
			{
				char *help_substring = NULL;
				size_t help_substring_len = 0;
				int dsp_start = 0;
				int helpline = 0;
				Uint32 currenttime = SDL_GetTicks();
				size_t full_help_len = strlen(((URLDATA *)local_head->data)->text) + 30;
				char *full_help_text = (char *)malloc(sizeof(char) * full_help_len);
	
				/* display the mouse over help next time round */
				url_win_status = URLW_OVER;
			
				/* underline the text, just clicked links are red, otherwise blue - paler when visited */
				if ((currenttime - url_win_clicktime < 500) && (url_win_clicked_url == url_win_hover_url))
					glColor3f(1.0f,0.0f,0.3f);
				else if (((URLDATA *)local_head->data)->visited)
					glColor3f(0.3f,0.5f,1.0f);
				else
					glColor3f(0.1f,0.2f,1.0f);
				glDisable(GL_TEXTURE_2D);
				glBegin(GL_LINES);
				glVertex2i(url_win_sep, currenty-2);
				glVertex2i(url_win_sep+string_width, currenty-2);
				glEnd();
				glEnable(GL_TEXTURE_2D);
				
				/* write the full url as help text at the bottom of the window */
				safe_snprintf(full_help_text, full_help_len, "%s (seen %d time%s) (%s)",
					((URLDATA *)local_head->data)->text, ((URLDATA *)local_head->data)->seen_count,
					((URLDATA *)local_head->data)->seen_count == 1?"":"s",  ((((URLDATA *)local_head->data)->visited)?"visited":"unvisited"));
				thetext = full_help_text;
				dsp_string_len = 0;
				string_width = 0;
				while(*thetext != '\0')
				{
					float char_width = get_char_width(*thetext++) * SMALL_FONT_X_LEN / 12.0;
					if (((string_width+char_width) > (win->len_x - 2*url_win_sep)) || (*thetext == '\0'))
					{
						if (*thetext == '\0') /* catch the last line */
							dsp_string_len++;
						if (help_substring_len < dsp_string_len)
						{
							if (help_substring != NULL)
								free(help_substring);
							help_substring = (char *)malloc(sizeof(char)*(dsp_string_len+1));
							help_substring_len = dsp_string_len;
						}
						strncpy(help_substring, &full_help_text[dsp_start], dsp_string_len);
						help_substring[dsp_string_len] = '\0';
						show_help(help_substring, url_win_sep, (url_win_y_len - url_win_full_url_y_len) + helpline++ * SMALL_FONT_Y_LEN);
						dsp_start += dsp_string_len;
						dsp_string_len = 0;
						string_width = 0;
					}
					dsp_string_len++;
					string_width += char_width;
				}
				free(help_substring);
				free(full_help_text);
				
			} /* end if mouse over url */
			
			/* count how many displayed so we can set the scroll bar properly */
			num_url_displayed++;
			
			local_head = local_head->next;
		}
				
		/* set the number of steps for the scroll bar */
		vscrollbar_set_bar_len(url_win, url_scroll_id, have_url_count - num_url_displayed);

	} /* end if have url */
	
	/* draw a line below the list of url, above the current url full text */
	glColor3f(0.77f,0.59f,0.39f);
	glDisable(GL_TEXTURE_2D);
	glBegin(GL_LINES);
	glVertex2i(0, url_win_url_y_start);
	glVertex2i(url_win_x_len+1, url_win_url_y_start);
	glEnd();
	glEnable(GL_TEXTURE_2D);

#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE
 
	return 1;
	
} /* end display_url_handler() */