16 #define GETTEXT_DOMAIN "wesnoth-lib" 94 return less(redirect->second,row1,row2);
98 return row1.
id < row2.
id;
101 if(column < 0 || column >=
int(row2.
fields.size())) {
105 if(column >=
int(row1.
fields.size())) {
109 const std::string& item1 = row1.
fields[column];
110 const std::string& item2 = row2.
fields[column];
113 std::string::const_iterator begin1 = item1.begin(), end1 = item1.end(),
114 begin2 = item2.begin(), end2 = item2.end();
125 int val_1 = lexical_cast_default<int>(item1, 0);
126 int val_2 = lexical_cast_default<int>(item2, 0);
128 return val_1 > val_2;
131 const std::map<int,std::vector<int>>::const_iterator itor =
pos_sort_.find(column);
133 const std::vector<int>& pos = itor->second;
134 if(row1.
id >= pos.size()) {
138 if(row2.
id >= pos.size()) {
142 return pos[row1.
id] < pos[row2.
id];
149 bool click_selects,
int max_height,
int max_width,
150 const sorter* sorter_obj,
style *menu_style,
const bool auto_join)
175 for(std::vector<std::string>::const_iterator itor = items.begin();
176 itor != items.end(); ++itor) {
183 const std::size_t
id =
items_.size();
186 items_.push_back(new_item);
189 if(
items_.back().fields.empty()) {
190 items_.back().fields.push_back(
" ");
195 std::string& first_item =
items_.back().fields.front();
196 if(first_item.empty() ==
false && first_item[0] ==
DEFAULT_ITEM) {
198 first_item.erase(first_item.begin());
215 sort_func(
const menu::sorter& pred,
int column) : pred_(&pred), column_(column)
220 return pred_->less(column_,a,b);
244 if(selectid >= 0 && selectid <
int(
item_pos_.size())) {
253 std::size_t sz =
items_.size();
255 for(std::size_t
i = 0;
i != sz; ++
i)
262 std::size_t sz =
items_.size();
264 for(std::size_t
n = 0;
n != sz; ++
n) {
275 i->help.emplace_back();
278 if(items.size() >= 2) {
280 i->help.push_back(items.back());
282 i->help.emplace_back();
302 h = std::max(h,
height());
309 int w = std::accumulate(widths.begin(), widths.end(), 0);
312 w = std::max(w,
width());
340 if(pos1 < 0 || pos1 >=
int(
item_pos_.size()) ||
351 std::size_t nb_items =
items_.size();
352 if (index >= nb_items)
362 for(std::size_t
i = 0;
i != nb_items; ++
i) {
365 if (n2 > index) --n2;
401 if (!keep_viewport ||
selected_ >= items.size()) {
408 }
else if(scrolled_to_max) {
444 std::vector<int> heights;
446 for(n = 0; n !=
items_.size(); ++
n) {
450 std::sort(heights.begin(),heights.end(),std::greater<int>());
452 for(n = 0; n !=
items_.size() && sum < max_height; ++
n) {
456 if(sum > max_height && n > 1)
471 if (new_selected >=
items_.size())
474 bool changed =
false;
484 if(!
silent_ && !silent && changed) {
497 std::size_t nb_items =
items_.size();
569 if(event ==
nullptr) {
574 if(event->type == SDL_KEYDOWN) {
575 SDL_Keycode key =
event->key.keysym.sym;
603 if(event.type == SDL_KEYDOWN) {
607 }
else if(!
mouse_locked() && ((event.type == SDL_MOUSEBUTTONDOWN &&
608 (event.button.button == SDL_BUTTON_LEFT || event.button.button == SDL_BUTTON_RIGHT)) ||
613 if(event.type == SDL_MOUSEBUTTONDOWN) {
617 x =
reinterpret_cast<std::size_t
>(
event.user.data1);
618 y =
reinterpret_cast<std::size_t
>(
event.user.data2);
660 }
else if(!
mouse_locked() && event.type == SDL_MOUSEMOTION) {
662 const int item =
hit(event.motion.x,event.motion.y);
663 const bool out = (item == -1);
673 const int heading_item =
hit_heading(event.motion.x,event.motion.y);
727 const bool already_sorted = (column ==
sortby_);
747 SDL_Rect res {0,0,0,0};
749 for (std::vector<std::string>::const_iterator it = img_text_items.begin();
750 it != img_text_items.end(); ++it) {
751 if (res.w > 0 || res.h > 0) {
755 const std::string str = *it;
757 const std::string image_name(str.begin()+1,str.end());
758 surface const img = get_item_image(image_name);
761 res.h = std::max<int>(img->h, res.h);
765 const SDL_Rect area {0,0,10000,10000};
766 const SDL_Rect font_size =
768 res.w += font_size.w;
769 res.h = std::max<int>(font_size.h, res.h);
785 alpha = normal_alpha_;
789 alpha = selected_alpha_;
793 alpha = heading_alpha_;
798 color_t c((rgb & 0xff0000) >> 16, (rgb & 0xff00) >> 8, rgb & 0xff);
806 if(rect.w == 0 || rect.h == 0) {
809 draw_row_bg(menu_ref, row_index, rect, type);
811 SDL_Rect minirect = rect;
813 minirect.x += thickness_;
814 minirect.y += thickness_;
815 minirect.w -= 2*thickness_;
816 minirect.h -= 2*thickness_;
818 menu_ref.
draw_row(row_index, minirect, type);
825 for(std::size_t col = 0; col != row.size(); ++col) {
829 if(col == widths.size()) {
830 widths.push_back(res.w + text_trailing_space);
831 }
else if(static_cast<std::size_t>(res.w) > widths[col] - text_trailing_space) {
832 widths[col] = res.w + text_trailing_space;
840 pos = (pos == std::string::npos) ? 0 : pos+1;
841 return(item.size() > pos && item.at(pos) ==
IMAGE_PREFIX);
848 for(std::size_t row = 0; row !=
items_.size(); ++row) {
872 int dir = (lang_rtl) ? -1 : 1;
873 SDL_Rect column = loc;
878 for(std::size_t
i = 0;
i != row.size(); ++
i) {
897 const int last_x = xpos;
898 column.w = widths[
i];
899 std::string str = row[
i];
901 for (std::vector<std::string>::const_iterator it = img_text_items.begin();
902 it != img_text_items.end(); ++it) {
905 const std::string image_name(str.begin()+1,str.end());
907 const int remaining_width =
max_width_ < 0 ? area.w :
908 std::min<int>(
max_width_, ((lang_rtl)? xpos - rect.x : rect.x + rect.w - xpos));
909 if(img !=
nullptr && img->w <= remaining_width
910 && rect.y + img->h < area.h) {
911 const std::size_t
y = rect.y + (rect.h - img->h)/2;
912 const std::size_t
w = img->w + 5;
913 const std::size_t
x = xpos + ((lang_rtl) ? widths[
i] - w : 0);
923 const std::size_t
y = rect.y + (rect.h - text_size.second)/2;
924 const std::size_t padding = 2;
925 SDL_Rect text_rect = column;
927 text_rect.h = text_size.second;
933 "buttons/sliders/slider_arrow_blue.png~ROTATE(180)");
934 if(sort_img !=
nullptr && sort_img->w <= widths[
i] && sort_img->h <= rect.h) {
935 const std::size_t sort_x = xpos + widths[
i] - sort_img->w - padding;
936 const std::size_t sort_y = rect.y + rect.h/2 - sort_img->h/2;
941 xpos += dir * (text_size.first + 5);
947 xpos = last_x + widths[
i];
1005 if (x >= loc.x && x < loc.x + loc.w && y >= loc.y && y < loc.y + loc.h) {
1006 for(std::size_t
i = 0;
i !=
items_.size(); ++
i) {
1008 if (y >= rect.y && y < rect.y + rect.h)
1019 int j = -1, j_end = widths.size();
1020 for(x -=
location().x; x >= 0; x -= widths[j]) {
1030 const int row =
hit(x, y);
1032 return std::pair<int,int>(-1, -1);
1037 return std::pair<int,int>(-1, -1);
1040 return std::pair<int,int>(
x,
y);
1047 if(y >= loc.y && static_cast<std::size_t>(y) < loc.y + height) {
1062 if (item < first_item_on_screen ||
1067 const std::map<int,SDL_Rect>::const_iterator
i =
itemRects_.find(item);
1074 if (item != first_item_on_screen) {
1076 y = prev.y + prev.h;
1083 if(res.x > draw_area.w) {
1085 }
else if(res.x + res.w > draw_area.w) {
1086 res.w = draw_area.w - res.x;
1089 if(res.y > draw_area.h) {
1091 }
else if(res.y + res.h > draw_area.h) {
1092 res.h = draw_area.h - res.y;
1097 if (loc.x > 0 && loc.y > 0)
1105 std::size_t res = 0;
1106 for(std::vector<std::string>::const_iterator
i = item.begin();
i != item.end(); ++
i) {
1108 res = std::max<int>(rect.h,res);
1128 std::size_t max_height = 0;
1129 for(std::size_t
n = 0;
n !=
items_.size(); ++
n) {
1140 const std::pair<int,int> loc(
hit(mousex,mousey),
hit_column(mousex));
1143 }
else if(loc.first == -1) {
1151 if(std::size_t(loc.first) <
items_.size()) {
1152 const std::vector<std::string>& row =
items_[
item_pos_[loc.first]].help;
1153 if(std::size_t(loc.second) < row.size()) {
1154 const std::string&
help = row[loc.second];
1155 if(help.empty() ==
false) {
1168 if(
id >=
items_.size()) {
1177 if(pos >=
items_.size()) {
surface get_image(const image::locator &i_locator, TYPE type)
Caches and returns an image.
int get_height() const
Returns the height of the drawing surface in pixels.
char const IMG_TEXT_SEPARATOR
New lexcical_cast header.
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 std::vector< std::string > items
const std::string menu_select
void blit_surface(int x, int y, surface surf, SDL_Rect *srcrect=nullptr, SDL_Rect *clip_rect=nullptr)
Copies an area of a surface to the drawing surface.
SDL_Rect draw_area() const
Returns the size and location of the current drawing area in pixels.
char const HELP_STRING_SEPARATOR
bool current_language_rtl()
SDL_Rect pango_draw_text(CVideo *gui, const SDL_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.
const color_t NORMAL_COLOR
#define DOUBLE_CLICK_EVENT
bool is_wml_separator(char c)
static map_location::DIRECTION s
std::vector< std::string > quoted_split(const std::string &val, char c, int flags, char quote)
This function is identical to split(), except it does not split when it otherwise would if the previo...
std::size_t index(const std::string &str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
int set_help_string(const std::string &str)
Displays a help string with the given text.
bool chars_less_insensitive(char a, char b)
const std::string button_press
SDL_Rect create_rect(const int x, const int y, const int w, const int h)
Creates an SDL_Rect with the given dimensions.
char const HEADING_PREFIX
Contains the SDL_Rect helper code.
char const COLUMN_SEPARATOR
constexpr const SDL_Rect empty_rect
std::vector< std::string > split(const config_attribute_value &val)
void play_UI_sound(const std::string &files)
void fill_rectangle(const SDL_Rect &rect, const color_t &color)
Draws a filled rectangle.
static map_location::DIRECTION n
Transitional API for porting SDL_ttf-based code to Pango.
std::string::const_iterator iterator
void clear_help_string(int handle)
Removes the help string with the given handle.