15 #define GETTEXT_DOMAIN "wesnoth-lib" 93 return less(redirect->second,row1,row2);
97 return row1.
id < row2.
id;
100 if(column < 0 || column >=
int(row2.
fields.size())) {
104 if(column >=
int(row1.
fields.size())) {
108 const std::string& item1 = row1.
fields[column];
109 const std::string& item2 = row2.
fields[column];
112 std::string::const_iterator begin1 = item1.begin(), end1 = item1.end(),
113 begin2 = item2.begin(), end2 = item2.end();
124 int val_1 = lexical_cast_default<int>(item1, 0);
125 int val_2 = lexical_cast_default<int>(item2, 0);
127 return val_1 > val_2;
130 const std::map<int,std::vector<int>>::const_iterator itor =
pos_sort_.find(column);
132 const std::vector<int>& pos = itor->second;
133 if(row1.
id >= pos.size()) {
137 if(row2.
id >= pos.size()) {
141 return pos[row1.
id] < pos[row2.
id];
148 bool click_selects,
int max_height,
int max_width,
149 const sorter* sorter_obj,
style *menu_style,
const bool auto_join)
174 for(std::vector<std::string>::const_iterator itor = items.begin();
175 itor != items.end(); ++itor) {
182 const std::size_t
id =
items_.size();
185 items_.push_back(new_item);
188 if(
items_.back().fields.empty()) {
189 items_.back().fields.push_back(
" ");
194 std::string& first_item =
items_.back().fields.front();
195 if(first_item.empty() ==
false && first_item[0] ==
DEFAULT_ITEM) {
197 first_item.erase(first_item.begin());
214 sort_func(
const menu::sorter& pred,
int column) : pred_(&pred), column_(column)
219 return pred_->less(column_,a,b);
243 if(selectid >= 0 && selectid <
int(
item_pos_.size())) {
252 std::size_t sz =
items_.size();
254 for(std::size_t
i = 0;
i != sz; ++
i)
261 std::size_t sz =
items_.size();
263 for(std::size_t
n = 0;
n != sz; ++
n) {
274 i->help.emplace_back();
277 if(items.size() >= 2) {
279 i->help.push_back(items.back());
281 i->help.emplace_back();
301 h = std::max(h,
height());
308 int w = std::accumulate(widths.begin(), widths.end(), 0);
311 w = std::max(w,
width());
339 if(pos1 < 0 || pos1 >=
int(
item_pos_.size()) ||
350 std::size_t nb_items =
items_.size();
351 if (index >= nb_items)
361 for(std::size_t
i = 0;
i != nb_items; ++
i) {
364 if (n2 > index) --n2;
400 if (!keep_viewport ||
selected_ >= items.size()) {
407 }
else if(scrolled_to_max) {
443 std::vector<int> heights;
445 for(n = 0; n !=
items_.size(); ++
n) {
449 std::sort(heights.begin(),heights.end(),std::greater<int>());
451 for(n = 0; n !=
items_.size() && sum < max_height; ++
n) {
455 if(sum > max_height && n > 1)
470 if (new_selected >=
items_.size())
473 bool changed =
false;
483 if(!
silent_ && !silent && changed) {
496 std::size_t nb_items =
items_.size();
568 if(event ==
nullptr) {
573 if(event->type == SDL_KEYDOWN) {
574 SDL_Keycode key =
event->key.keysym.sym;
602 if(event.type == SDL_KEYDOWN) {
606 }
else if(!
mouse_locked() && ((event.type == SDL_MOUSEBUTTONDOWN &&
607 (event.button.button == SDL_BUTTON_LEFT || event.button.button == SDL_BUTTON_RIGHT)) ||
612 if(event.type == SDL_MOUSEBUTTONDOWN) {
616 x =
reinterpret_cast<std::size_t
>(
event.user.data1);
617 y =
reinterpret_cast<std::size_t
>(
event.user.data2);
659 }
else if(!
mouse_locked() && event.type == SDL_MOUSEMOTION) {
661 const int item =
hit(event.motion.x,event.motion.y);
662 const bool out = (item == -1);
672 const int heading_item =
hit_heading(event.motion.x,event.motion.y);
726 const bool already_sorted = (column ==
sortby_);
746 SDL_Rect res {0,0,0,0};
748 for (std::vector<std::string>::const_iterator it = img_text_items.begin();
749 it != img_text_items.end(); ++it) {
750 if (res.w > 0 || res.h > 0) {
754 const std::string str = *it;
756 const std::string image_name(str.begin()+1,str.end());
757 surface const img = get_item_image(image_name);
760 res.h = std::max<int>(img->h, res.h);
764 const SDL_Rect area {0,0,10000,10000};
765 const SDL_Rect font_size =
767 res.w += font_size.w;
768 res.h = std::max<int>(font_size.h, res.h);
784 alpha = normal_alpha_;
788 alpha = selected_alpha_;
792 alpha = heading_alpha_;
797 color_t c((rgb & 0xff0000) >> 16, (rgb & 0xff00) >> 8, rgb & 0xff);
805 if(rect.w == 0 || rect.h == 0) {
808 draw_row_bg(menu_ref, row_index, rect, type);
810 SDL_Rect minirect = rect;
812 minirect.x += thickness_;
813 minirect.y += thickness_;
814 minirect.w -= 2*thickness_;
815 minirect.h -= 2*thickness_;
817 menu_ref.
draw_row(row_index, minirect, type);
824 for(std::size_t col = 0; col != row.size(); ++col) {
828 if(col == widths.size()) {
829 widths.push_back(res.w + text_trailing_space);
830 }
else if(static_cast<std::size_t>(res.w) > widths[col] - text_trailing_space) {
831 widths[col] = res.w + text_trailing_space;
839 pos = (pos == std::string::npos) ? 0 : pos+1;
840 return(item.size() > pos && item.at(pos) ==
IMAGE_PREFIX);
847 for(std::size_t row = 0; row !=
items_.size(); ++row) {
871 int dir = (lang_rtl) ? -1 : 1;
872 SDL_Rect column = loc;
877 for(std::size_t
i = 0;
i != row.size(); ++
i) {
896 const int last_x = xpos;
897 column.w = widths[
i];
898 std::string str = row[
i];
900 for (std::vector<std::string>::const_iterator it = img_text_items.begin();
901 it != img_text_items.end(); ++it) {
904 const std::string image_name(str.begin()+1,str.end());
906 const int remaining_width =
max_width_ < 0 ? area.w :
907 std::min<int>(
max_width_, ((lang_rtl)? xpos - rect.x : rect.x + rect.w - xpos));
908 if(img !=
nullptr && img->w <= remaining_width
909 && rect.y + img->h < area.h) {
910 const std::size_t
y = rect.y + (rect.h - img->h)/2;
911 const std::size_t
w = img->w + 5;
912 const std::size_t
x = xpos + ((lang_rtl) ? widths[
i] - w : 0);
922 const std::size_t
y = rect.y + (rect.h - text_size.second)/2;
923 const std::size_t padding = 2;
924 SDL_Rect text_rect = column;
926 text_rect.h = text_size.second;
932 "buttons/sliders/slider_arrow_blue.png~ROTATE(180)");
933 if(sort_img !=
nullptr && sort_img->w <= widths[
i] && sort_img->h <= rect.h) {
934 const std::size_t sort_x = xpos + widths[
i] - sort_img->w - padding;
935 const std::size_t sort_y = rect.y + rect.h/2 - sort_img->h/2;
940 xpos += dir * (text_size.first + 5);
946 xpos = last_x + widths[
i];
1004 if (x >= loc.x && x < loc.x + loc.w && y >= loc.y && y < loc.y + loc.h) {
1005 for(std::size_t
i = 0;
i !=
items_.size(); ++
i) {
1007 if (y >= rect.y && y < rect.y + rect.h)
1018 int j = -1, j_end = widths.size();
1019 for(x -=
location().x; x >= 0; x -= widths[j]) {
1029 const int row =
hit(x, y);
1031 return std::pair<int,int>(-1, -1);
1036 return std::pair<int,int>(-1, -1);
1039 return std::pair<int,int>(
x,
y);
1046 if(y >= loc.y && static_cast<std::size_t>(y) < loc.y + height) {
1061 if (item < first_item_on_screen ||
1066 const std::map<int,SDL_Rect>::const_iterator
i =
itemRects_.find(item);
1073 if (item != first_item_on_screen) {
1075 y = prev.y + prev.h;
1082 if(res.x > screen_area.w) {
1084 }
else if(res.x + res.w > screen_area.w) {
1085 res.w = screen_area.w - res.x;
1088 if(res.y > screen_area.h) {
1090 }
else if(res.y + res.h > screen_area.h) {
1091 res.h = screen_area.h - res.y;
1096 if (loc.x > 0 && loc.y > 0)
1104 std::size_t res = 0;
1105 for(std::vector<std::string>::const_iterator
i = item.begin();
i != item.end(); ++
i) {
1107 res = std::max<int>(rect.h,res);
1127 std::size_t max_height = 0;
1128 for(std::size_t
n = 0;
n !=
items_.size(); ++
n) {
1139 const std::pair<int,int> loc(
hit(mousex,mousey),
hit_column(mousex));
1142 }
else if(loc.first == -1) {
1150 if(std::size_t(loc.first) <
items_.size()) {
1151 const std::vector<std::string>& row =
items_[
item_pos_[loc.first]].help;
1152 if(std::size_t(loc.second) < row.size()) {
1153 const std::string&
help = row[loc.second];
1154 if(help.empty() ==
false) {
1167 if(
id >=
items_.size()) {
1176 if(pos >=
items_.size()) {
surface get_image(const image::locator &i_locator, TYPE type)
Caches and returns an image.
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::string menu_select
const std::vector< std::string > items
void blit_surface(int x, int y, surface surf, SDL_Rect *srcrect=nullptr, SDL_Rect *clip_rect=nullptr)
Draws a surface directly onto the screen framebuffer.
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...
int get_height(bool as_pixels=true) const
Returns the window renderer height in pixels or in screen coordinates.
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.
static int sort(lua_State *L)
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 void reverse(lua_State *L, StkId from, StkId to)
SDL_Rect screen_area(bool as_pixels=true) const
Returns the current window renderer area, either in pixels or screen coordinates. ...
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.