15 #define GETTEXT_DOMAIN "wesnoth-lib"
37 #define LOG_SCOPE_HEADER \
38 "tcontrol(" + get_control_type() + ") [" + id() + "] " + __func__
39 #define LOG_HEADER LOG_SCOPE_HEADER + ':'
47 : definition_(
"default")
50 , use_tooltip_on_label_overflow_(true)
53 , canvas_(canvas_count)
56 , text_maximum_width_(0)
60 connect_signal<event::SHOW_TOOLTIP>(std::bind(
63 connect_signal<event::SHOW_HELPTIP>(std::bind(
66 connect_signal<event::NOTIFY_REMOVE_TOOLTIP>(std::bind(
71 const unsigned canvas_count,
74 , definition_(builder.definition)
75 , label_(builder.label)
77 , use_tooltip_on_label_overflow_(builder.use_tooltip_on_label_overflow)
78 , tooltip_(builder.tooltip)
79 , help_message_(builder.
help)
80 , canvas_(canvas_count)
83 , text_maximum_width_(0)
89 connect_signal<event::SHOW_TOOLTIP>(std::bind(
92 connect_signal<event::SHOW_HELPTIP>(std::bind(
95 connect_signal<event::NOTIFY_REMOVE_TOOLTIP>(std::bind(
103 string_map::const_iterator
itor = data.find(
"id");
104 if(itor != data.end()) {
108 itor = data.find(
"linked_group");
109 if(itor != data.end()) {
113 itor = data.find(
"label");
114 if(itor != data.end()) {
118 itor = data.find(
"tooltip");
119 if(itor != data.end()) {
123 itor = data.find(
"help");
124 if(itor != data.end()) {
128 itor = data.find(
"use_markup");
129 if(itor != data.end()) {
133 itor = data.find(
"text_alignment");
134 if(itor != data.end()) {
199 if(full_initialisation) {
214 size.
x +=
config_->text_extra_width;
215 size.
y +=
config_->text_extra_height;
220 <<
"' maximum_width " << maximum_width <<
" result " << size
225 <<
"' failed; either no label or wrapping not allowed.\n";
246 <<
"' result " << result <<
".\n";
293 const bool must_be_active)
const
325 #ifdef GUI2_EXPERIMENTAL_LISTBOX
376 canvas.set_variable(
"text_alignment",
378 canvas.set_variable(
"text_maximum_width",
variant(max_width));
379 canvas.set_variable(
"text_maximum_height",
variant(max_height));
380 canvas.set_variable(
"text_wrap_mode",
382 : PANGO_ELLIPSIZE_END));
383 canvas.set_variable(
"text_characters_per_line",
433 canvas() = std::vector<tcanvas>(
config()->state.size());
435 for(
size_t i = 0;
i <
canvas().size(); ++
i) {
443 const tpoint& maximum_size)
const
475 <<
LOG_HEADER <<
" Limited the number of characters per line, "
476 <<
"but wrapping is not set, output may not be as expected.\n";
481 <<
" minimum_size " << minimum_size <<
" maximum_size "
483 <<
" can_wrap " <<
can_wrap() <<
" characters_per_line "
499 if(size.
x < minimum_size.
x) {
500 size.
x = minimum_size.
x;
503 if(size.
y < minimum_size.
y) {
504 size.
y = minimum_size.
y;
508 <<
"' result " << size <<
".\n";
530 event::tmessage_show_tooltip
message(tip, location);
654 , definition(cfg[
"definition"])
655 , label(cfg[
"label"].t_str())
656 , tooltip(cfg[
"tooltip"].t_str())
657 ,
help(cfg[
"help"].t_str())
658 , use_tooltip_on_label_overflow(true)
666 _(
"Found a widget with a helptip and without a tooltip."),
668 <<
"' helptip '" <<
help <<
"'.").str());
671 DBG_GUI_P <<
"Window builder: found control with id '" <<
id
672 <<
"' and definition '" <<
definition <<
"'.\n";
Define the common log macros for the gui toolkit.
tpoint get_config_default_size() const
Gets the default size as defined in the config.
std::string encode_text_alignment(const PangoAlignment alignment)
Converts a text alignment to its string representation.
virtual void impl_draw_background(surface &frame_buffer, int x_offset, int y_offset) override
See twidget::impl_draw_background.
Request for somebody to show the tooltip based on the data send.
virtual void impl_draw_foreground(surface &frame_buffer, int x_offset, int y_offset) override
See twidget::impl_draw_foreground.
void signal_handler_show_tooltip(const event::tevent event, bool &handled, const tpoint &location)
ttext & set_alignment(const PangoAlignment alignment)
std::string interpolate_variables_into_string(const std::string &str, const string_map *const symbols)
Function which will interpolate variables, starting with '$' in the string 'str' with the equivalent ...
tformula< PangoAlignment > text_alignment_
The alignment of the text.
ttext & set_link_aware(bool b)
void set_config(tresolution_definition_ptr config)
virtual unsigned get_characters_per_line() const
Returns the number of characters per line.
ttext & set_font_style(const unsigned font_style)
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
twidget * find(const std::string &id, const bool must_be_active) override
See twidget::find.
virtual void load_config_extra()
Load class dependent config settings.
virtual const std::string & get_control_type() const =0
Returns the control_type of the control.
tresolution_definition_ptr config()
bool is_truncated() const
Has the text been truncated?
virtual void request_reduce_width(const unsigned maximum_width) override
See twidget::request_reduce_width.
virtual void set_label(const t_string &label)
lg::log_domain log_gui_layout("gui/layout")
ttext & set_font_size(const unsigned font_size)
int text_maximum_width_
The maximum width for the text in a control.
ttext & set_maximum_width(int width)
PangoAlignment decode_text_alignment(const std::string &alignment)
Converts a text alignment string to a text alignment.
ttext & set_link_color(const std::string &color)
void set_help_message(const t_string &help_message)
#define VALIDATE_WITH_DEV_MESSAGE(cond, message, dev_message)
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
virtual unsigned get_state() const =0
Returns the id of the state.
A class inherited from ttext_box that displays its input as stars.
void init_control(tcontrol *control) const
std::string definition
Parameters for the control.
virtual void set_use_markup(bool use_markup)
static UNUSEDNOWARN std::string _(const char *str)
std::map< std::string, t_string > string_map
std::string get_link(const gui2::tpoint &position) const
Checks if position points to a character in a link in the text, returns it if so, empty string otherw...
tpoint get_config_maximum_size() const
Gets the best size as defined in the config.
tpoint get_best_text_size(const tpoint &minimum_size, const tpoint &maximum_size=tpoint(0, 0)) const
Gets the best size for a text.
t_string tooltip_
Tooltip text.
std::string get_label_token(const gui2::tpoint &position, const char *delimiters=" \n\r\t") const
Exposes font::ttext::get_token, for the text label of this control.
bool fire(const tevent event, twidget &target)
Fires an event which has no extra parameters.
void remove()
Removes a tip.
t_string has_helptip_message
Request for somebody to show the helptip based on the data send.
int get_text_maximum_width() const
Returns the maximum width available for the text.
gui2::tpoint get_size() const
Returns the size needed for the text.
This file contains the defintions for the gui2::event::tmessage class.
virtual void place(const tpoint &origin, const tpoint &size) override
See twidget::place.
#define log_scope2(domain, description)
ttext & set_characters_per_line(const unsigned characters_per_line)
void load_config()
Loads the configuration of the widget.
const t_string & label() const
tevent
The event send to the dispatcher.
void set_use_tooltip_on_label_overflow(const bool use_tooltip=true)
bool shrunken_
Is the widget smaller as it's best size?
void set_tooltip(const t_string &tooltip)
bool init()
Initializes the gui subsystems.
tresolution_definition_ptr get_control(const std::string &control_type, const std::string &definition)
tresolution_definition_ptr config_
Contains the pointer to the configuration.
font::ttext renderer_
Contains a helper cache for the rendering.
std::map< std::string, t_string > string_map
PangoAlignment text_alignment_
The alignment of the text in a control.
Encapsulates the map of the game.
std::string definition_
The definition is the id of that widget class.
virtual void update_canvas()
Updates the canvas(ses).
tpoint get_config_minimum_size() const
Gets the minimum size as defined in the config.
std::string get_token(const gui2::tpoint &position, const char *delimiters=" \n\r\t") const
Gets the largest collection of characters, including the token at position, and not including any cha...
std::map< std::string, tfilter >::iterator itor
std::vector< tcanvas > canvas_
Holds all canvas objects for a control.
std::string debug_truncate(const std::string &text)
Returns a truncated version of the text.
virtual iterator::twalker_ * create_walker() override
See twidget::create_walker.
bool use_markup_
Use markup for the label?
void signal_handler_show_helptip(const event::tevent event, bool &handled, const tpoint &location)
void definition_load_configuration(const std::string &control_type)
Loads the configuration of the widget.
std::vector< tcanvas > & canvas()
bool string_bool(const std::string &str, bool def)
Convert no, false, off, 0, 0.0 to false, empty to def, and others to true.
std::string get_names(std::string id)
Returns a comma-separated string of hotkey names.
void signal_handler_notify_remove_tooltip(const event::tevent event, bool &handled)
virtual bool get_link_aware() const
Returns whether the label should be link_aware, in in rendering and in searching for links with get_l...
Base class for all visible items.
GLint GLint GLsizei GLsizei GLsizei GLint border
bool disable_click_dismiss() const override
See twidget::disable_click_dismiss.
bool use_tooltip_on_label_overflow_
If the text doesn't fit on the label should the text be used as tooltip?
t_string label_
Contain the non-editable text associated with control.
void set_text_alignment(const PangoAlignment text_alignment)
int get_text_maximum_height() const
Returns the maximum height available for the text.
virtual void set_members(const string_map &data)
Sets the members of the control.
virtual twidget * find_at(const tpoint &coordinate, const bool must_be_active) override
See twidget::find_at.
ttext & set_family_class(font::family_class fclass)
std::string get_label_link(const gui2::tpoint &position) const
tcontrol(const unsigned canvas_count)
GLsizei GLenum GLuint GLuint GLsizei char * message
virtual std::string get_link_color() const
Returns the color string to be used with links.
bool set_text(const std::string &text, const bool markedup)
Sets the text to render.
void set_definition(const std::string &definition)
Sets the definition.
The walker abstract base class.
tbuilder_control(const config &cfg)
A config object defines a single node in a WML file, with access to child nodes.
virtual bool get_active() const =0
Gets the active state of the control.
virtual void layout_initialise(const bool full_initialisation) override
See twidget::layout_initialise.
GLsizei const GLcharARB ** string
t_string help_message_
Tooltip text.
ttext & set_ellipse_mode(const PangoEllipsizeMode ellipse_mode)
Contains the implementation details for lexical_cast and shouldn't be used directly.
virtual tpoint calculate_best_size() const override
See twidget::calculate_best_size.
static const hotkey_command & get_command_by_command(HOTKEY_COMMAND command)
the execute_command argument was changed from HOTKEY_COMMAND to hotkey_command, to be able to call it...
bool use_tooltip_on_label_overflow