16 #define GETTEXT_DOMAIN "wesnoth-lib"
38 const std::string indent_string{
" "};
43 menu::menu(
bool click_selects,
int max_height,
int max_width,
style *menu_style,
const bool auto_join)
45 max_height_(max_height), max_width_(max_width),
46 max_items_(-1), item_height_(-1),
47 selected_(0), click_selects_(click_selects), out_(false),
48 previous_button_(true), show_result_(false),
49 double_clicked_(false),
51 ignore_next_doubleclick_(false),
52 last_was_doubleclick_(false), use_ellipsis_(false)
65 for(
const auto& itor : items) {
66 const std::size_t
id =
items_.size();
68 items_.emplace_back(itor,
id);
139 if(scrolled_to_max) {
172 const std::size_t max_height = (
178 std::vector<int> heights;
187 std::sort(heights.begin(),heights.end(),std::greater<int>());
189 for(
n = 0;
n !=
items_.size() && sum < max_height; ++
n) {
193 if(sum > max_height &&
n > 1)
208 if (new_selected >=
items_.size())
211 bool changed =
false;
221 if(!
silent_ && !silent && changed) {
234 std::size_t nb_items =
items_.size();
306 if(event ==
nullptr) {
311 if(event->type == SDL_KEYDOWN) {
312 SDL_Keycode key =
event->key.keysym.sym;
340 if(event.type == SDL_KEYDOWN) {
344 }
else if(!
mouse_locked() && ((event.type == SDL_MOUSEBUTTONDOWN &&
345 (event.button.button == SDL_BUTTON_LEFT || event.button.button == SDL_BUTTON_RIGHT)) ||
350 if(event.type == SDL_MOUSEBUTTONDOWN) {
354 x =
reinterpret_cast<std::size_t
>(
event.user.data1);
355 y =
reinterpret_cast<std::size_t
>(
event.user.data2);
390 }
else if(!
mouse_locked() && event.type == SDL_MOUSEMOTION) {
392 const int item =
hit(event.motion.x,event.motion.y);
393 const bool out = (
item == -1);
439 SDL_Rect res {0,0,0,0};
443 if (!imi.
icon.empty()) {
449 res.h = std::max<int>(img.
h(), res.h);
452 if (!imi.
text.empty()) {
456 const SDL_Rect area {0,0,10000,10000};
457 const SDL_Rect font_size =
460 res.w += font_size.w;
461 res.h = std::max<int>(font_size.h, res.h);
474 alpha = normal_alpha_;
478 alpha = selected_alpha_;
483 color_t c((rgb & 0xff0000) >> 16, (rgb & 0xff00) >> 8, rgb & 0xff);
494 draw_row_bg(menu_ref, row_index,
rect,
type);
496 SDL_Rect minirect =
rect;
497 minirect.x += thickness_;
498 minirect.y += thickness_;
499 minirect.w -= 2*thickness_;
500 minirect.h -= 2*thickness_;
508 for(
const auto& row :
items_) {
510 widest = std::max(widest,
size.w);
521 if(row_index >=
items_.size()) {
527 const auto& imi =
items_[row_index].fields;
528 int width_used_so_far =
style_->
item_size({imi.indent_level, imi.icon,
""}).
w;
534 return x > loc.x + loc.w - width_used_so_far;
536 return x < loc.x + width_used_so_far;
542 const auto& imi =
items_[row_index].fields;
549 if (!imi.icon.empty()) {
553 const int remaining_width =
max_width_ < 0 ? area.w : std::min<int>(
max_width_, loc.w - width_used_so_far);
554 if(img && img_w <= remaining_width && loc.y + img_h < area.h) {
555 const std::size_t
y = loc.y + (loc.h - img_h)/2;
556 const std::size_t
x = loc.x + (lang_rtl ? loc.w - width_used_so_far - img_w : width_used_so_far);
561 width_used_so_far += img_w + 5;
566 if (!imi.text.empty()) {
568 const std::size_t
x = loc.x + (lang_rtl ? std::max(0, loc.w - width_used_so_far - text_size.first) : width_used_so_far);
569 const std::size_t
y = loc.y + (loc.h - text_size.second)/2;
572 text_loc.h = text_size.second;
589 if (
x >= loc.x && x < loc.x + loc.w && y >= loc.y &&
y < loc.y + loc.h) {
590 for(std::size_t
i = 0;
i !=
items_.size(); ++
i) {
608 if (
item < first_item_on_screen ||
613 const std::map<int,SDL_Rect>::const_iterator
i =
itemRects_.find(
item);
620 if (
item != first_item_on_screen) {
629 if(res.x > canvas_size.x) {
631 }
else if(res.x + res.w > canvas_size.x) {
632 res.w = canvas_size.x - res.x;
635 if(res.y > canvas_size.y) {
637 }
else if(res.y + res.h > canvas_size.y) {
638 res.h = canvas_size.y - res.y;
643 if (loc.x > 0 && loc.y > 0)
662 std::size_t max_height = 0;
681 if(pos >=
items_.size()) {
Wrapper class to encapsulate creation and management of an SDL_Texture.
int w() const
The draw-space width of the texture, in pixels.
int h() const
The draw-space height of the texture, in pixels.
Drawing functions, for drawing things on the screen.
#define DOUBLE_CLICK_EVENT
bool current_language_rtl()
void fill(const SDL_Rect &rect, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
Fill an area with the given colour.
void blit(const texture &tex, const SDL_Rect &dst)
Draws a texture, or part of a texture, at the given location.
void rect(const SDL_Rect &rect)
Draw a rectangle.
rect pango_draw_text(bool actually_draw, const rect &area, int size, const color_t &color, const std::string &text, int x, int y, bool use_tooltips, pango_text::FONT_STYLE style)
Draws text on the screen.
std::pair< int, int > pango_line_size(const std::string &line, int font_size, font::pango_text::FONT_STYLE font_style)
Determine the width and height of a line of text given a certain font size.
const color_t NORMAL_COLOR
const std::string menu_select
const std::string button_press
texture get_texture(const image::locator &i_locator, TYPE type, bool skip_cache)
Returns an image texture suitable for hardware-accelerated rendering.
constexpr const SDL_Rect empty_rect
void play_UI_sound(const std::string &files)
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
point game_canvas_size()
The size of the game canvas, in drawing coordinates / game pixels.
rect game_canvas()
The game canvas area, in drawing coordinates.
Contains the SDL_Rect helper code.
Transitional API for porting SDL_ttf-based code to Pango.
The basic class for representing 8-bit RGB or RGBA colour values.
An abstract description of a rectangle with integer coordinates.
static map_location::DIRECTION n