Skip to content

Commit

Permalink
Use the bar for for the menu title
Browse files Browse the repository at this point in the history
  • Loading branch information
amadvance committed Sep 8, 2018
1 parent 56e1af6 commit 0a22846
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
11 changes: 7 additions & 4 deletions advance/menu/choice.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,12 @@ const string& choice::print_get() const

void choice_bag::draw(const string& title, int x, int y, int dx, int pos_base, int pos_rel, int rows, bool center)
{
int_put_filled(text, x, y, dx, title, COLOR_CHOICE_TITLE);
if (center)
int_put_filled_center(bar, x, y, dx, title, COLOR_CHOICE_TITLE);
else
int_put_filled(bar, x, y, dx, title, COLOR_CHOICE_TITLE);

y += int_font_dy_get(text);
y += int_font_dy_get(bar);

for (unsigned j = 0; j < rows; ++j) {
int_color color;
Expand Down Expand Up @@ -216,7 +219,7 @@ int choice_bag::run(const string& title, int x, int y, int dx, choice_container:
if (x < 0)
x = (int_dx_get() - dx - border * 2) / 2;
if (y < 0)
y = (int_dy_get() - (size() + 1) * int_font_dy_get(text) - border * 2) / 2;
y = (int_dy_get() - (int_font_dy_get(bar) + size() * int_font_dy_get(text)) - border * 2) / 2;

int pos_rel_max = (int_dy_get() - y) / int_font_dy_get(text);
pos_rel_max -= 2;
Expand All @@ -228,7 +231,7 @@ int choice_bag::run(const string& title, int x, int y, int dx, choice_container:
int pos_base = 0;
int pos_rel = 0;

int dy = (pos_rel_max + 1) * int_font_dy_get(text);
int dy = int_font_dy_get(bar) + pos_rel_max * int_font_dy_get(text);

int_box(x - border, y - border, dx + 2 * border, dy + border * 2, 1, COLOR_CHOICE_NORMAL.foreground);
int_clear(x - border + 1, y - border + 1, dx + 2 * border - 2, dy + border * 2 - 2, COLOR_CHOICE_NORMAL.background);
Expand Down
2 changes: 1 addition & 1 deletion advance/menu/submenu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ int run_volume(config_state& rs)
// ------------------------------------------------------------------------
// Exit

#define EXIT_CHOICE_DX 14 * int_font_dx_get(text)
#define EXIT_CHOICE_DX 18 * int_font_dx_get(text)
#define EXIT_CHOICE_DY 4 * int_font_dy_get(text)
#define EXIT_CHOICE_X (int_dx_get() - EXIT_CHOICE_DX) / 2
#define EXIT_CHOICE_Y (int_dy_get() - EXIT_CHOICE_DY) / 2
Expand Down
13 changes: 13 additions & 0 deletions advance/menu/text.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2564,6 +2564,19 @@ void int_put_filled(font_t font, int x, int y, int dx, const string& s, const in
int_clear(x, y, dx, int_font_dy_get(font), color.background);
}

void int_put_filled_center(font_t font, int x, int y, int dx, const string& s, const int_color& color)
{
int width = int_put_width(font, s);
if (width + 1 < dx) {
int prefix_dx = (dx - width) / 2;
int_clear(x, y, prefix_dx, int_font_dy_get(font), color.background);
x += prefix_dx;
dx -= prefix_dx;
}

int_put_filled(font, x, y, dx, s, color);
}

void int_put_filled_alpha(font_t font, int x, int y, int dx, const string& s, const int_color& color)
{
for (unsigned i = 0; i < s.length(); ++i) {
Expand Down
1 change: 1 addition & 0 deletions advance/menu/text.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ unsigned int_put_width(font_t font, const std::string& s);
void int_put(font_t font, int x, int y, char c, const int_color& color);
void int_put(font_t font, int x, int y, const std::string& s, const int_color& color);
void int_put_filled(font_t font, int x, int y, int dx, const std::string& s, const int_color& color);
void int_put_filled_center(font_t font, int x, int y, int dx, const std::string& s, const int_color& color);
void int_put_special(font_t font, bool& in, int x, int y, int dx, const std::string& s, const int_color& c0, const int_color& c1, const int_color& c2);
void int_put_special_center(font_t font, bool& in, int x, int y, int dx, const std::string& s, const int_color& c0, const int_color& c1, const int_color& c2);
void int_put_alpha(font_t font, int x, int y, char c, const int_color& color);
Expand Down

0 comments on commit 0a22846

Please sign in to comment.