Skip to content

Commit

Permalink
Indicators position fixes.
Browse files Browse the repository at this point in the history
* Always update position if in default position when turned on.
* Temporarily hide if in default position and not enough space.
  • Loading branch information
pjbroad committed Nov 23, 2024
1 parent 971a858 commit a9c5522
Showing 1 changed file with 38 additions and 8 deletions.
46 changes: 38 additions & 8 deletions hud_indicators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "gamewin.h"
#include "gl_init.h"
#include "hud.h"
#include "icon_window.h"
#ifdef JSON_FILES
#include "json_io.h"
#endif
Expand Down Expand Up @@ -133,7 +134,8 @@ namespace Indicators
: indicators_win(-1), cm_menu_id(CM_INIT_VALUE),
cm_relocatable(0), x_len(0), y_len(0), default_location(true),
option_settings(0), position_settings(0), have_settings(false),
background_on(0), border_on(0), no_indicators_str_width(0) {}
background_on(0), border_on(0), no_indicators_str_width(0),
locally_hidden(false), force_width_change(false) {}
void init(void);
void destroy(void);
void show(void) { if (indicators_win >= 0) show_window (indicators_win); }
Expand Down Expand Up @@ -173,6 +175,8 @@ namespace Indicators
void change_width(int new_x_len);
enum { CMHI_RELOC=ELW_CM_MENU_LEN+1, CMHI_BACKGROUND, CMHI_BORDER,
CMHI_SPACE1, CMHI_RESET, CMHI_SPACE2, CMHI_INDBASE};
bool locally_hidden;
bool force_width_change;
};


Expand Down Expand Up @@ -327,6 +331,7 @@ namespace Indicators
}

x_len = 2 * Vars::border();
force_width_change = true;
for (const auto &i : indicators)
if (!i->not_active())
x_len += i->get_width() + 2 * Vars::space();
Expand Down Expand Up @@ -432,10 +437,8 @@ namespace Indicators
{
if (show)
{
if (indicators_win < 0)
init();
else
show_window(indicators_win);
init();
show_window(indicators_win);
}
else
hide_window(indicators_win);
Expand All @@ -454,14 +457,16 @@ namespace Indicators
if ((*i)->not_active())
continue;
pos_x += Vars::space();
(*i)->do_draw(pos_x);
if (!locally_hidden)
(*i)->do_draw(pos_x);
pos_x += (*i)->get_width() + Vars::space();
have_active = true;
}
if (!have_active)
{
glColor3fv(gui_dull_color);
draw_string_zoomed(pos_x, Vars::border(), (const unsigned char *)no_indicators_str, 1, Vars::zoom());
if (!locally_hidden)
draw_string_zoomed(pos_x, Vars::border(), (const unsigned char *)no_indicators_str, 1, Vars::zoom());
pos_x += no_indicators_str_width;
}
change_width(pos_x + Vars::border());
Expand All @@ -472,7 +477,30 @@ namespace Indicators
//
void Indicators_Container::change_width(int new_x_len)
{
if (new_x_len != x_len)
if (default_location)
{
if ((HUD_MARGIN_X + get_icons_win_active_len() + new_x_len) > window_width)
{
if (!locally_hidden)
{
std::string no_space_for_indicators("No space to show indicators");
LOG_TO_CONSOLE(c_red1, no_space_for_indicators.c_str());
locally_hidden = true;
}
new_x_len = 0;
}
else
{
if (locally_hidden)
{
std::string now_space_for_indicators("Now have space now to show indicators");
LOG_TO_CONSOLE(c_red1, now_space_for_indicators.c_str());
locally_hidden = false;
}
}
}

if (force_width_change || (new_x_len != x_len))
{
x_len = new_x_len;
y_len = Vars::y_len();
Expand All @@ -482,6 +510,7 @@ namespace Indicators
std::pair<int,int> loc = get_default_location();
move_window(indicators_win, -1, 0, loc.first, loc.second);
}
force_width_change = false;
}
}

Expand Down Expand Up @@ -611,6 +640,7 @@ namespace Indicators
void Indicators_Container::ui_scale_handler(window_info *win)
{
x_len = y_len = 0;
force_width_change = true;
Vars::set_scale(win->current_scale);
no_indicators_str_width = FontManager::get_instance().line_width(Vars::font_cat,
reinterpret_cast<const unsigned char*>(no_indicators_str), strlen(no_indicators_str), Vars::zoom());
Expand Down

0 comments on commit a9c5522

Please sign in to comment.