16 #define GETTEXT_DOMAIN "wesnoth-lib"
35 #define ERR_DP LOG_STREAM(err, log_display)
36 #define LOG_DP LOG_STREAM(info, log_display)
37 #define DBG_DP LOG_STREAM(debug, log_display)
38 #define ERR_G LOG_STREAM(err, lg::general)
149 ERR_DP <<
"Problem handling utf8 in message '" << message <<
"'" << std::endl;
182 if(b->first->is_option()) {
183 if(option_index == i++) {
184 return b->first->checked();
193 std::pair<dialog_button *, BUTTON_LOCATION> new_pair(btn,loc);
235 const int text_widget_max_chars,
const unsigned int text_box_width)
238 const bool editable_textbox =
std::find(text_widget_text.begin(),text_widget_text.end(),
'\n') == text_widget_text.end();
361 pane->needs_restore_ =
false;
475 int text_widget_width = 0;
476 int text_widget_height = 0;
481 text_widget_width = dim.
textbox.w;
491 unsigned int caption_width = 0;
492 unsigned int caption_height = 0;
498 int check_button_height = 0;
499 int left_check_button_height = 0;
500 int top_button_height = 0;
501 const int button_height_padding = 5;
509 check_button_height += btn->
height() + button_height_padding;
513 left_check_button_height += btn->
height() + button_height_padding;
516 top_button_height += btn->
height() + button_height_padding;
523 check_button_height = std::max<int>(check_button_height, left_check_button_height);
525 size_t above_preview_pane_height = 0, above_left_preview_pane_width = 0, above_right_preview_pane_width = 0;
526 size_t preview_pane_height = 0, left_preview_pane_width = 0, right_preview_pane_width = 0;
530 const SDL_Rect& rect = pane->
location();
532 preview_pane_height = std::max<size_t>(rect.h,preview_pane_height);
534 left_preview_pane_width += rect.w;
536 right_preview_pane_width += rect.w;
539 above_preview_pane_height = std::max<size_t>(rect.h,above_preview_pane_height);
541 above_left_preview_pane_width += rect.w;
543 above_right_preview_pane_width += rect.w;
555 const size_t total_text_height = dim.
message.h + caption_height;
557 size_t text_width = dim.
message.w;
558 if(caption_width > text_width)
559 text_width = caption_width;
563 if(dim.
menu_width + image_width + padding_width + left_preview_pane_width + right_preview_pane_width > static_cast<size_t>(scr->w))
564 dim.
menu_width = scr->w - image_width - padding_width - left_preview_pane_width - right_preview_pane_width;
569 size_t total_width = image_width + text_width + padding_width;
576 total_width > dim.
menu_width + image_width + padding_width) {
577 dim.
menu_width = total_width - image_width - padding_width;
580 const size_t text_and_image_height = image_height > total_text_height ? image_height : total_text_height;
582 const int top_widgets_height = std::max<int>(text_widget_height, top_button_height);
584 const int total_height = text_and_image_height + padding_height +
menu_->
height() +
585 top_widgets_height + check_button_height;
587 dim.
interior.w = std::max<int>(total_width,above_left_preview_pane_width + above_right_preview_pane_width);
588 dim.
interior.h = std::max<int>(total_height,
static_cast<int>(preview_pane_height));
589 dim.
interior.x = std::max<int>(0,dim.
x >= 0 ? dim.
x : scr->w/2 - (dim.
interior.w + left_preview_pane_width + right_preview_pane_width)/2);
590 dim.
interior.y = std::max<int>(0,dim.
y >= 0 ? dim.
y : scr->h/2 - (dim.
interior.h + above_preview_pane_height)/2);
592 DBG_DP <<
"above_preview_pane_height: " << above_preview_pane_height <<
"; "
593 <<
"dim.interior.y: " << scr->h/2 <<
" - " << (dim.
interior.h + above_preview_pane_height)/2 <<
" = "
596 if(dim.
x <= -1 || dim.
y <= -1) {
597 dim.
x = dim.
interior.x + left_preview_pane_width;
598 dim.
y = dim.
interior.y + above_preview_pane_height;
610 if(dim.
y + dim.
interior.h + frame_bottom_pad > scr->h) {
611 dim.
y = std::max<int>(frame_top_pad, scr->h - dim.
interior.h - frame_bottom_pad);
617 dim.
interior.w += left_preview_pane_width + right_preview_pane_width;
618 dim.
interior.h += above_preview_pane_height;
620 const int max_height = scr->h - dim.
interior.y - frame_bottom_pad;
624 if(menu_height > 0) {
633 int left_preview_pane = dim.
interior.x;
634 int right_preview_pane = dim.
interior.x + total_width + left_preview_pane_width;
636 int above_right_preview_pane = above_left_preview_pane;
646 area.x = left_preview_pane;
647 left_preview_pane += area.w;
649 area.x = right_preview_pane;
650 right_preview_pane += area.w;
654 area.h = above_preview_pane_height;
656 area.x = above_left_preview_pane - area.w;
657 above_left_preview_pane -= area.w;
659 area.x = above_right_preview_pane;
660 above_right_preview_pane += area.w;
667 const int text_widget_y = dim.
y +
top_padding + text_and_image_height - 6 + menu_hpadding;
671 dim.
textbox.y = text_widget_y + (text_widget_height - dim.
textbox.h)/2;
677 int top_buttons_y = text_widget_y;
682 std::pair<int, int>
coords(0, 0);
688 coords.second = text_widget_y + (text_widget_height - btn.
height())/2;
690 coords.second = top_buttons_y;
693 top_buttons_y += btn.
height() + button_height_padding;
708 dim.
message.x += image_width + image_h_padding;
718 int options_y = dim.
menu_y +
menu_->
height() + menu_hpadding + button_height_padding;
719 int options_left_y = options_y;
722 std::pair<int,int>
coords;
728 coords.second = options_y;
730 options_y += btn->
height() + button_height_padding;
735 coords.second = options_left_y;
737 options_left_y += btn->
height() + button_height_padding;
759 int mouse_flags = SDL_GetMouseState(&mousex,&mousey);
764 info.
key[SDLK_ESCAPE] || info.
key[SDLK_KP_ENTER];
768 const bool has_input = (use_menu||use_text_input);
790 (**i).set_selection(selection);
845 if(
b->first->pressed()) {
846 return b->first->action(info);
899 return (
dialog()->get_menu().selection());
906 label *label_ptr =
nullptr;
907 if(!caption.empty()) {
936 size_t adjusted_selection = selection +
header_row_;
948 for(
size_t i = adjusted_selection;
i <
index_map_.size(); ++
i) {
957 const std::vector<std::string> words =
utils::split(unicode_cast<utf8::string>(text),
' ');
972 std::vector<std::string>::const_iterator
w = words.begin();
973 for(; w != words.end(); ++
w)
976 w->begin(), w->end(),
980 if (w == words.end()) {
SDL_Rect text_area(const std::string &text, int size, int style)
Calculate the size of a text (in pixels) if it were to be drawn.
void set_callback(const std::string &name, callback_function)
std::vector< std::string > last_words
void set_result(const int result)
std::vector< char_t > string
void update_widget_positions()
void add_option(const std::string &label, bool checked=false, BUTTON_LOCATION loc=BUTTON_CHECKBOX, const std::string &help_string="")
int get_index(int selection) const
static const int message_font_size
void set_textbox(dialog_textbox *const box)
static const style default_style
const std::function< int(const config &, const std::string &, int) > get_int
dimension_measurements dim_
std::vector< dialog_button * > standard_buttons_
std::vector< dialog_button * > extra_buttons_
virtual void action(dialog_process_info &dp_info)
GLuint GLuint GLsizei GLenum type
int relative_size(int size)
const SDL_Rect empty_rect
static const style & default_style
static const size_t image_h_pad
void add_button(dialog_button *const btn, BUTTON_LOCATION loc)
std::vector< std::string > empty_string_vector
std::string word_wrap_text(const std::string &unwrapped_text, int font_size, int max_width, int max_height, int max_lines, bool partial_line)
Wrap text.
virtual bool show_above() const
dialog(CVideo &video, const std::string &title="", const std::string &message="", const DIALOG_TYPE type=MESSAGE, const style &dialog_style=default_style)
std::vector< button * > frame_buttons_
dialog_textbox * text_widget_
static const size_t bottom_padding
GLint GLint GLint GLint GLint GLint y
void blit_surface(int x, int y, surface surf, SDL_Rect *srcrect=nullptr, SDL_Rect *clip_rect=nullptr)
const std::string text() const
unsigned image_width(const std::string &filename)
const SDL_Color NORMAL_COLOR
std::vector< std::string > filtered_items_
static menu * get_empty_menu(CVideo &video)
Provides create-on-use semantics for empty_menu.
static const size_t right_padding
std::vector< std::pair< dialog_button *, BUTTON_LOCATION > > button_pool_
GLdouble GLdouble GLdouble b
dimension_measurements layout(int x, int y, int w, int h)
std::vector< dialog_button * > top_buttons_
int bottom_padding() const
static UNUSEDNOWARN std::string _(const char *str)
std::vector< std::string > items_to_filter_
static const style & message_style
bool chars_equal_insensitive(char a, char b)
virtual sdl_handler_vector handler_members()
std::vector< preview_pane * >::iterator pp_iterator
GLubyte GLubyte GLubyte GLubyte w
void set_menu(menu *const m)
dialog_button * help_button_
virtual bool left_side() const =0
static lg::log_domain log_display("display")
virtual dimension_measurements layout(int xloc=-1, int yloc=-1)
static const size_t top_padding
std::vector< dialog_button * >::iterator button_iterator
void set_menu_items(const std::vector< std::string > &menu_items, bool keep_selection=false)
Changes (or sets, if not previously set) the dialog's menu items to the provided list.
dimension_measurements get_layout() const
static const style hotkeys_style
virtual ~dialog_textbox()
const std::string & get_text() const
bool point_in_rect(int x, int y, const SDL_Rect &rect)
Tests whether a point is inside a rectangle.
void set_image(dialog_image *const img)
dialog_frame & get_frame()
void raise_process_event()
std::vector< std::pair< dialog_button *, BUTTON_LOCATION > >::const_iterator button_pool_const_iterator
Thrown by operations encountering invalid UTF-8 data.
std::vector< preview_pane * >::const_iterator pp_const_iterator
bool update_locked() const
static const size_t left_padding
std::map< dialog_button *, std::pair< int, int > > buttons
virtual void handle_text_changed(const ucs4::string &text)
static menu * empty_menu
A pointer to this empty menu is used instead of nullptr (for menu_).
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
GLint GLint GLint GLint GLint x
label * get_label() const
std::map< preview_pane *, SDL_Rect > panes
std::vector< preview_pane * > preview_panes_
std::vector< std::string > items_
std::vector< int > index_map_
GLint GLint GLint GLint GLint GLint GLsizei GLsizei height
const std::string button_press
bool option_checked(unsigned int option_index=0)
static const int caption_font_size
Contains the SDL_Rect helper code.
std::vector< dialog_button * >::const_iterator button_const_iterator
bool find(E event, F functor)
Tests whether an event handler is available.
static const int max_menu_width
void play_UI_sound(const std::string &files)
Standard logging facilities (interface).
int process(dialog_process_info &info)
static void delay(unsigned int milliseconds)
GLsizei GLenum GLuint GLuint GLsizei char * message
std::vector< std::pair< dialog_button *, BUTTON_LOCATION > >::iterator button_pool_iterator
std::vector< std::string > split(std::string const &val, const char c, const int flags)
Splits a (comma-)separated string into a vector of pieces.
A config object defines a single node in a WML file, with access to child nodes.
void delete_item(int selection)
void notify_event(const std::string &name, const config &data)
GLsizei const GLcharARB ** string
static const style message_style
void set_layout(dimension_measurements &new_dim)
static plugins_manager * get()