Skip to content

Commit

Permalink
Clean up the show_help() function usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
pjbroad committed Oct 11, 2017
1 parent a4d0ffd commit 2d1d3c6
Show file tree
Hide file tree
Showing 24 changed files with 116 additions and 181 deletions.
6 changes: 3 additions & 3 deletions achievements.cpp
Expand Up @@ -787,11 +787,11 @@ int Achievements_Window::display_handler(window_info *win)
if (over_controls && show_help_text)
{
if (over_close)
scaled_show_help(as->get_close_help(), 0, win->len_y + as->get_y_win_offset());
show_help(as->get_close_help(), 0, win->len_y + as->get_y_win_offset(), win->current_scale);
else if (over_prev)
scaled_show_help((first)?as->get_prev_help() :as->get_no_prev_help(), 0, win->len_y + as->get_y_win_offset());
show_help((first)?as->get_prev_help() :as->get_no_prev_help(), 0, win->len_y + as->get_y_win_offset(), win->current_scale);
else if (over_next)
scaled_show_help((another_page)?as->get_next_help() :as->get_no_next_help(), 0, win->len_y + as->get_y_win_offset());
show_help((another_page)?as->get_next_help() :as->get_no_next_help(), 0, win->len_y + as->get_y_win_offset(), win->current_scale);
}

win_mouse_x = win_mouse_y = -1;
Expand Down
2 changes: 1 addition & 1 deletion bags.c
Expand Up @@ -451,7 +451,7 @@ static int pre_display_ground_items_handler(window_info *win)
glEnable(GL_TEXTURE_2D);
if (item_desc_str != NULL)
{
scaled_show_help(item_desc_str, 0, win->len_y+10);
show_help(item_desc_str, 0, win->len_y+10, win->current_scale);
item_desc_str = NULL;
}
return 1;
Expand Down
4 changes: 2 additions & 2 deletions buddy.c
Expand Up @@ -292,13 +292,13 @@ void split_long_show_help(window_info *win, const char *str, int x, int y)
tmp_str[last_space_out_index] = '\0';
in_index = last_space_in_index;
last_space_out_index = out_index = 0;
scaled_show_help(tmp_str, x, y + num_lines++ * win->small_font_len_y);
show_help(tmp_str, x, y + num_lines++ * win->small_font_len_y, win->current_scale);
}
in_index++;
}

tmp_str[out_index] = '\0';
scaled_show_help(tmp_str, x, y + num_lines++ * win->small_font_len_y);
show_help(tmp_str, x, y + num_lines++ * win->small_font_len_y, win->current_scale);
free(tmp_str);
}

Expand Down
5 changes: 3 additions & 2 deletions chat.c
Expand Up @@ -1662,7 +1662,8 @@ static int chan_tab_mouseover_handler(widget_list *widget)
if(!show_help_text){return 0;}
for (itab = 0; itab < tabs_in_use; itab++){
if ((tabs[itab].button) == (widget->id)){
scaled_show_help(tabs[itab].description, widget->pos_x,widget->pos_y+widget->len_y+2);
window_info *win = &windows_list.window[widget->window_id];
show_help(tabs[itab].description, widget->pos_x,widget->pos_y+widget->len_y+2, win->current_scale);
return 1;
}
}
Expand Down Expand Up @@ -1693,7 +1694,7 @@ static int display_chan_sel_handler(window_info *win)
draw_string_zoomed(x, y, (unsigned char*)((chan_name*)(step->data))->name, 1, local_zoom);
if(mouse_y > win->pos_y+y && mouse_y < win->pos_y+y+win->small_font_len_y && mouse_x >= win->pos_x+chan_sel_border
&& mouse_x-chan_sel_border <= win->pos_x + win->small_font_len_x*((signed)strlen(((chan_name*)(step->data))->name))) {
scaled_show_help(((chan_name*)(step->data))->description, mouse_x-win->pos_x,mouse_y-win->pos_y-win->small_font_len_y);
show_help(((chan_name*)(step->data))->description, mouse_x-win->pos_x,mouse_y-win->pos_y-win->small_font_len_y, win->current_scale);
}
y += win->default_font_len_y;
step = step->next;
Expand Down
6 changes: 3 additions & 3 deletions counters.c
Expand Up @@ -788,8 +788,8 @@ int display_counters_handler(window_info *win)
truncated_string(used_name, counters[i][j].name, dest_max_len, append_str, max_name_x, font_ratio);
scaled_draw_string_small(x, y, (unsigned char*)used_name, 1);
/* if the mouse is over this line and its truncated, tooltip to full name */
if (mouseover_entry_y >= y && mouseover_entry_y < y+16) {
scaled_show_help(counters[i][j].name, -TAB_MARGIN, win->len_y+10+TAB_MARGIN);
if (mouseover_entry_y >= y && mouseover_entry_y < y+step_y) {
show_help(counters[i][j].name, -TAB_MARGIN, win->len_y+10+TAB_MARGIN, win->current_scale);
counters_show_win_help = 0;
}
free(used_name);
Expand All @@ -801,7 +801,7 @@ int display_counters_handler(window_info *win)
}

if (counters_show_win_help) {
scaled_show_help(cm_help_options_str, -TAB_MARGIN, win->len_y+10+TAB_MARGIN);
show_help(cm_help_options_str, -TAB_MARGIN, win->len_y+10+TAB_MARGIN, win->current_scale);
counters_show_win_help = 0;
}

Expand Down
2 changes: 1 addition & 1 deletion dialogues.c
Expand Up @@ -319,7 +319,7 @@ static int display_dialogue_handler(window_info *win)

// display help text if appropriate
if ((show_help_text) && (highlight_repeat || highlight_copy || mouse_over_name))
scaled_show_help(cm_help_options_str, 0, win->len_y+10);
show_help(cm_help_options_str, 0, win->len_y+10, win->current_scale);

show_keypress_letters = highlight_close = highlight_copy = highlight_repeat = mouse_over_name = 0;

Expand Down
9 changes: 1 addition & 8 deletions elwindows.c
Expand Up @@ -50,7 +50,6 @@ void update_window_scale(window_info *win, float scale_factor)
return;
if (win->flags & ELW_USE_UISCALE)
{
win->is_scalable = 1;
win->current_scale = scale_factor;
win->box_size = (int)(0.5 + win->current_scale * ELW_BOX_SIZE);
win->title_height = (int)(0.5 + win->current_scale * ELW_TITLE_HEIGHT);
Expand All @@ -61,7 +60,6 @@ void update_window_scale(window_info *win, float scale_factor)
}
else
{
win->is_scalable = 0;
win->current_scale = 1.0;
win->box_size = ELW_BOX_SIZE;
win->title_height = ELW_TITLE_HEIGHT;
Expand Down Expand Up @@ -1012,12 +1010,7 @@ int draw_window_title(window_info *win)
if (show_help_text && cm_valid(win->cm_id) && (cm_window_shown() == CM_INIT_VALUE) &&
mouse_x > win->cur_x && mouse_x < win->cur_x+win->len_x &&
mouse_y > win->cur_y-win->title_height && mouse_y < win->cur_y)
{
if (win->is_scalable)
scaled_show_help(cm_title_help_str, 0, win->len_y+10);
else
show_help(cm_title_help_str, 0, win->len_y+10);
}
show_help(cm_title_help_str, 0, win->len_y+10, win->current_scale);

glColor3f(1.0f,1.0f,1.0f);
//ok, now draw that shit...
Expand Down
1 change: 0 additions & 1 deletion elwindows.h
Expand Up @@ -61,7 +61,6 @@ typedef struct {
* \name scalable elements
*/
/*! @{ */
int is_scalable;
float current_scale;
int box_size;
int title_height;
Expand Down
2 changes: 1 addition & 1 deletion encyclopedia.c
Expand Up @@ -152,7 +152,7 @@ int display_encyclopedia_handler(window_info *win)
}
if (show_cm_help)
{
scaled_show_help(cm_encycl_help_str, 0, win->len_y+10);
show_help(cm_encycl_help_str, 0, win->len_y+10, win->current_scale);
show_cm_help = 0;
}

Expand Down
89 changes: 33 additions & 56 deletions hud.c
Expand Up @@ -407,51 +407,21 @@ int enlarge_text(void)
return ((SDL_GetModState() & (KMOD_CTRL|KMOD_ALT)));
}

void show_help(const char *help_message, int x, int y)
static void show_help_coloured_scaled(const char *help_message, int x, int y, float r, float g, float b, int use_big_font, float size)
{
show_sized_help_coloured(help_message, x, y, 1.0f, 1.0f, 1.0f, SHOW_SMALL_HELP);
}

void scaled_show_help(const char *help_message, int x, int y)
{
show_sized_help_coloured(help_message, x, y, 1.0f, 1.0f, 1.0f, SHOW_SCALED_HELP);
}

void show_sized_help(const char *help_message, int x, int y, show_help_modes size_mode)
{
show_sized_help_coloured(help_message, x, y, 1.0f, 1.0f, 1.0f, size_mode);
}

void show_help_coloured(const char *help_message, int x, int y, float r, float g, float b)
{
show_sized_help_coloured(help_message, x, y, r, g, b, SHOW_SMALL_HELP);
}

void show_sized_help_coloured(const char *help_message, int x, int y, float r, float g, float b, show_help_modes size_mode)
{
float y_font_len = 0;
int y_font_len = 0;
int len = 0;
int width=window_width-80;

if (size_mode == SHOW_BIG_HELP)
if (use_big_font)
{
y_font_len = DEFAULT_FONT_Y_LEN;
len = strlen(help_message) * DEFAULT_FONT_X_LEN + 1;
}
else if (size_mode == SHOW_SCALED_HELP)
{
y_font_len = UI_SCALED_VALUE(SMALL_FONT_Y_LEN);
len = strlen(help_message) * UI_SCALED_VALUE(SMALL_FONT_X_LEN) + 1;
}
else if (size_mode == SHOW_BIG_SCALED_HELP)
{
y_font_len = UI_SCALED_VALUE(DEFAULT_FONT_Y_LEN);
len = strlen(help_message) * UI_SCALED_VALUE(DEFAULT_FONT_X_LEN) + 1;
y_font_len = (int)(0.5 + DEFAULT_FONT_Y_LEN * size);
len = strlen(help_message) * (int)(0.5 + DEFAULT_FONT_X_LEN * size) + 1;
}
else
{
y_font_len = SMALL_FONT_Y_LEN;
len = strlen(help_message) * SMALL_FONT_X_LEN + 1;
y_font_len = (int)(0.5 + SMALL_FONT_Y_LEN * size);
len = strlen(help_message) * (int)(0.5 + SMALL_FONT_X_LEN * size) + 1;
}

if(x+len>width) x-=(x+len)-width;
Expand All @@ -471,19 +441,26 @@ void show_sized_help_coloured(const char *help_message, int x, int y, float r, f
glEnable(GL_TEXTURE_2D);

glColor3f(r,g,b);
if (size_mode == SHOW_BIG_HELP)
draw_string(x, y, (unsigned char*)help_message, 1);
else if (size_mode == SHOW_SCALED_HELP)
scaled_draw_string_small(x, y, (unsigned char*)help_message, 1);
else if (size_mode == SHOW_BIG_SCALED_HELP)
scaled_draw_string(x, y, (unsigned char*)help_message, 1);
if (use_big_font)
draw_string_zoomed(x, y, (unsigned char*)help_message, 1, size);
else
draw_string_small(x, y, (unsigned char*)help_message, 1);
draw_string_small_scaled(x, y, (unsigned char*)help_message, 1, size);
#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE
}

void show_help(const char *help_message, int x, int y, float scale)
{
show_help_coloured_scaled(help_message, x, y, 1.0f, 1.0f, 1.0f, 0, scale);
}

void show_help_big(const char *help_message, int x, int y, float scale)
{
show_help_coloured_scaled(help_message, x, y, 1.0f, 1.0f, 1.0f, 1, scale);
}


// Stats bars in the bottom HUD .....

int show_action_bar = 0;
Expand Down Expand Up @@ -722,7 +699,7 @@ void init_stats_display()
if(stats_bar_win < 0)
{
static size_t cm_id_ap = CM_INIT_VALUE;
stats_bar_win= create_window("Stats Bar", -1, 0, 0, stats_y_pos, stats_width, stats_height, ELW_TITLE_NONE|ELW_SHOW_LAST);
stats_bar_win= create_window("Stats Bar", -1, 0, 0, stats_y_pos, stats_width, stats_height, ELW_USE_UISCALE|ELW_TITLE_NONE|ELW_SHOW_LAST);
set_window_handler(stats_bar_win, ELW_HANDLER_DISPLAY, &display_stats_bar_handler);
set_window_handler(stats_bar_win, ELW_HANDLER_MOUSEOVER, &mouseover_stats_bar_handler);

Expand Down Expand Up @@ -897,7 +874,7 @@ void set_last_heal(int quantity)
}

/* draws damage and heal above the health bar */
static void draw_last_health_change(void)
static void draw_last_health_change(window_info *win)
{
char str[20];
static const Uint32 timeoutms = 2*60*1000;
Expand All @@ -910,7 +887,7 @@ static void draw_last_health_change(void)
else
{
safe_snprintf(str, sizeof(str), " %d ", my_last_health.d);
show_sized_help_coloured(str, health_bar_start_x+stats_bar_len/2-strlen(str)*UI_SCALED_VALUE(SMALL_FONT_X_LEN)-2, yoff, 1.0f, 0.0f, 0.0f, SHOW_SCALED_HELP);
show_help_coloured_scaled(str, health_bar_start_x+stats_bar_len/2-strlen(str)*UI_SCALED_VALUE(SMALL_FONT_X_LEN)-2, yoff, 1.0f, 0.0f, 0.0f, 0, win->current_scale);
}
}
/* heal in green */
Expand All @@ -921,7 +898,7 @@ static void draw_last_health_change(void)
else
{
safe_snprintf(str, sizeof(str), " %d ", my_last_health.h);
show_sized_help_coloured(str, health_bar_start_x+stats_bar_len/2+2, yoff, 0.0f, 1.0f, 0.0f, SHOW_SCALED_HELP);
show_help_coloured_scaled(str, health_bar_start_x+stats_bar_len/2+2, yoff, 0.0f, 1.0f, 0.0f, 0, win->current_scale);
}
}
}
Expand Down Expand Up @@ -995,15 +972,15 @@ int display_stats_bar_handler(window_info *win)

if(show_help_text && statbar_cursor_x>=0)
{
if(over_health_bar) scaled_show_help((char*)attributes.material_points.name,health_bar_start_x+stats_bar_len+10,-3);
else if(statbar_cursor_x>food_bar_start_x && statbar_cursor_x < food_bar_start_x+stats_bar_len) scaled_show_help((char*)attributes.food.name,food_bar_start_x+stats_bar_len+10,-3);
else if(statbar_cursor_x>mana_bar_start_x && statbar_cursor_x < mana_bar_start_x+stats_bar_len) scaled_show_help((char*)attributes.ethereal_points.name,mana_bar_start_x+stats_bar_len+10,-3);
else if(statbar_cursor_x>load_bar_start_x && statbar_cursor_x < load_bar_start_x+stats_bar_len) scaled_show_help((char*)attributes.carry_capacity.name,load_bar_start_x+stats_bar_len+10,-3);
else if(show_action_bar && statbar_cursor_x>action_bar_start_x && statbar_cursor_x < action_bar_start_x+stats_bar_len) scaled_show_help((char*)attributes.action_points.name,action_bar_start_x+stats_bar_len+10,-3);
if(over_health_bar) show_help((char*)attributes.material_points.name,health_bar_start_x+stats_bar_len+10,-3, win->current_scale);
else if(statbar_cursor_x>food_bar_start_x && statbar_cursor_x < food_bar_start_x+stats_bar_len) show_help((char*)attributes.food.name,food_bar_start_x+stats_bar_len+10,-3, win->current_scale);
else if(statbar_cursor_x>mana_bar_start_x && statbar_cursor_x < mana_bar_start_x+stats_bar_len) show_help((char*)attributes.ethereal_points.name,mana_bar_start_x+stats_bar_len+10,-3, win->current_scale);
else if(statbar_cursor_x>load_bar_start_x && statbar_cursor_x < load_bar_start_x+stats_bar_len) show_help((char*)attributes.carry_capacity.name,load_bar_start_x+stats_bar_len+10,-3, win->current_scale);
else if(show_action_bar && statbar_cursor_x>action_bar_start_x && statbar_cursor_x < action_bar_start_x+stats_bar_len) show_help((char*)attributes.action_points.name,action_bar_start_x+stats_bar_len+10,-3, win->current_scale);
}

if (over_health_bar)
draw_last_health_change();
draw_last_health_change(win);

statbar_cursor_x = -1;

Expand Down Expand Up @@ -1541,7 +1518,7 @@ int mouseover_misc_handler(window_info *win, int mx, int my)
/* Optionally display scrolling help if statsbar is active and restricted in size */
if (show_help_text && show_stats_in_hud && (num_disp_stat < NUM_WATCH_STAT-1) &&
(my - statbar_start_y >= 0) && (my - statbar_start_y < num_disp_stat*stats_bar_height))
scaled_show_help(stats_scroll_help_str, -10-UI_SCALED_VALUE(strlen(stats_scroll_help_str)*SMALL_FONT_X_LEN), win->len_y-UI_SCALED_VALUE(70));
show_help(stats_scroll_help_str, -10-UI_SCALED_VALUE(strlen(stats_scroll_help_str)*SMALL_FONT_X_LEN), win->len_y-UI_SCALED_VALUE(70), win->current_scale);

/* stat hover experience left */
if (show_stats_in_hud && have_stats && (my - statbar_start_y >= 0) && (my - statbar_start_y < num_disp_stat*stats_bar_height))
Expand Down Expand Up @@ -1891,7 +1868,7 @@ static void quickbar_item_description_help(window_info *win, int pos, int slot)
if ((ypos + UI_SCALED_VALUE(SMALL_FONT_Y_LEN) + win->cur_y) > window_height)
ypos = -(5 + UI_SCALED_VALUE(SMALL_FONT_Y_LEN) + (quickbar_draggable * ELW_TITLE_HEIGHT));
}
scaled_show_help(str, xpos, ypos);
show_help(str, xpos, ypos, win->current_scale);
}
}
}
Expand Down
51 changes: 7 additions & 44 deletions hud.h
Expand Up @@ -38,8 +38,6 @@ typedef enum
{
SHOW_SMALL_HELP = 0,
SHOW_BIG_HELP,
SHOW_SCALED_HELP,
SHOW_BIG_SCALED_HELP
} show_help_modes;

extern int qb_action_mode; /*!< flag indicating whether we are in quickbar action mode or not */
Expand Down Expand Up @@ -249,67 +247,32 @@ void view_map_win(int *win, int id);
* \ingroup windows
* \brief Shows the \a message at the given position (\a x, \a y).
*
* Shows the \a message at the given position (\a x, \a y).
* Shows the \a message at the given position (\a x, \a y) using the small font.
*
* \param message the help message to show
* \param x the x coordinate of the position to draw the help message
* \param y the y coordinate of the position to draw the help message
* \param scale the multiplier for the text size
*
* \callgraph
*/
void show_help(const char *message, int x, int y);
void scaled_show_help(const char *message, int x, int y); /* temporary function during ui scaling changes */

/*!
* \ingroup windows
* \brief Shows the \a message at the given position (\a x, \a y).
*
* Shows the \a message at the given position (\a x, \a y).
*
* \param message the help message to show
* \param x the x coordinate of the position to draw the help message
* \param y the y coordinate of the position to draw the help message
* \param size_mode one of the show_help_modes values
*
* \callgraph
*/
void show_sized_help(const char *message, int x, int y, show_help_modes size_mode);

/*!
* \ingroup windows
* \brief Shows the \a message at the given position and colour (\a x, \a y).
*
* Shows the \a message at the given position and colour (\a x, \a y).
*
* \param message the help message to show
* \param x the x coordinate of the position to draw the help message
* \param y the y coordinate of the position to draw the help message
* \param r the red RGB value for text
* \param g the green RGB value for text
* \param b the blue RGB value for text
*
* \callgraph
*/
void show_help_coloured(const char *help_message, int x, int y, float r, float g, float b);
void show_help(const char *message, int x, int y, float scale);


/*!
* \ingroup windows
* \brief Shows the \a message at the given position and colour (\a x, \a y).
* \brief Shows the \a message at the given position (\a x, \a y).
*
* Shows the \a message at the given position and colour (\a x, \a y).
* Shows the \a message at the given position (\a x, \a y) using the default font.
*
* \param message the help message to show
* \param x the x coordinate of the position to draw the help message
* \param y the y coordinate of the position to draw the help message
* \param r the red RGB value for text
* \param g the green RGB value for text
* \param b the blue RGB value for text
* \param size_mode one of the show_help_modes values
* \param scale the multiplier for the text size
*
* \callgraph
*/
void show_sized_help_coloured(const char *help_message, int x, int y, float r, float g, float b, show_help_modes size_mode);
void show_help_big(const char *message, int x, int y, float scale);

/*!
* \ingroup windows
Expand Down
2 changes: 1 addition & 1 deletion hud_indicators.cpp
Expand Up @@ -467,7 +467,7 @@ namespace Indicators
int x_offset = -static_cast<int>(Vars::border() + win->small_font_len_x * (1 + tooltip.size()) + 0.5);
if ((win->cur_x + x_offset) < 0)
x_offset = win->len_x;
scaled_show_help(tooltip.c_str(), x_offset, Vars::border());
show_help(tooltip.c_str(), x_offset, Vars::border(), win->current_scale);
}
}

Expand Down

0 comments on commit 2d1d3c6

Please sign in to comment.