15 #define GETTEXT_DOMAIN "wesnoth-lib"
17 #include "widgets/button.hpp"
35 #include <boost/algorithm/string/predicate.hpp>
38 #define ERR_DP LOG_STREAM(err, log_display)
50 :
widget(video, auto_join), type_(type),
52 label_text_(label), label_image_(),
53 image_(), pressedImage_(), activeImage_(), pressedActiveImage_(),
54 disabledImage_(), pressedDisabledImage_(),
55 overlayImage_(), overlayPressedImage_(), overlayActiveImage_(),
58 image_(nullptr), pressedImage_(nullptr), activeImage_(nullptr), pressedActiveImage_(nullptr),
59 disabledImage_(nullptr), pressedDisabledImage_(nullptr),
60 overlayImage_(nullptr), overlayPressedImage_(nullptr), overlayActiveImage_(nullptr),
62 state_(
NORMAL), pressed_(false),
63 spacing_(spacing), base_height_(0), base_width_(0),
64 button_image_name_(), button_overlay_image_name_(overlay_image),
65 button_image_path_suffix_()
67 if (button_image_name.empty()) {
101 size_postfix =
"_30";
104 size_postfix =
"_60";
114 sdl::timage disabled_image;
117 sdl::timage pressed_disabled_image, pressed_active_image, touched_image;
139 if (disabled_image.null()) {
143 if (pressed_image.null())
144 pressed_image = button_image;
146 if (active_image.null())
147 active_image = button_image;
151 if (touched_image.null())
152 touched_image = pressed_image;
155 if (pressed_active_image.null())
156 pressed_active_image = pressed_image;
160 if (pressed_disabled_image.null())
164 if (button_image.null()) {
165 ERR_DP <<
"error initializing button!" << std::endl;
196 surface pressed_disabled_image, pressed_active_image, touched_image;
224 if (disabled_image ==
nullptr) {
228 if (pressed_image.
null())
229 pressed_image.
assign(button_image);
231 if (active_image.
null())
232 active_image.
assign(button_image);
236 if (touched_image.
null())
237 touched_image.
assign(pressed_image);
240 if (pressed_active_image.
null())
241 pressed_active_image.
assign(pressed_image);
245 if (pressed_disabled_image.
null())
249 if (button_image.
null()) {
250 std::string err_msg =
"error initializing button images! file name: ";
253 ERR_DP << err_msg << std::endl;
296 loc_image.h =
image_.height();
297 loc_image.w =
image_.width();
306 bool change_size = loc.h == 0 || loc.w == 0;
313 int style = TTF_STYLE_NORMAL;
364 if (
state_ != new_state) {
403 const int image_w =
image_.width();
427 SDL_Rect clipArea = loc;
435 textx = loc.x + image_w + checkbox_horizontal_padding / 2;
473 image.set_scale(
float(loc.w) / image.width(), float(loc.h) / image.height());
474 overlay.set_scale(
float(loc.w) / overlay.width(), float(loc.h) / image.height());
476 video().draw_texture(image, loc.x, loc.y);
477 video().draw_texture(overlay, loc.x, loc.y);
484 video().draw_texture(label_image_, textx, texty);
488 const int image_w =
image_->w;
512 SDL_Rect clipArea = loc;
520 textx = loc.x + image_w + checkbox_horizontal_padding / 2;
611 const std::vector<std::string>::const_iterator
i = std::find_if(items.begin(),items.end(),
is_valid_image);
612 if(i != items.end()) {
621 label_image_ = text.render_as_texture();
629 if (
hit(event.x, event.y)) {
663 if (
hit(event.x, event.y) && event.button == SDL_BUTTON_LEFT) {
691 if (!(
hit(event.x, event.y) && event.button == SDL_BUTTON_LEFT))
752 case SDL_MOUSEBUTTONDOWN:
755 case SDL_MOUSEBUTTONUP:
758 case SDL_MOUSEMOTION:
766 if (start_state !=
state_)
const SDL_Color BUTTON_COLOR
surface get_image(const image::locator &i_locator, TYPE type)
function to get the surface corresponding to an image.
static void check(LexState *ls, int c)
GLuint GLuint GLsizei GLenum type
static l_noret error(LoadState *S, const char *why)
bool ends_with(const std::string &str, const std::string &suffix)
const int horizontal_padding
surface image_
The image is cached in this surface.
GLuint const GLfloat * val
GLint GLint GLint GLint GLint GLint y
const std::vector< std::string > items
surface scale_surface(const surface &surf, int w, int h)
void blit_surface(int x, int y, surface surf, SDL_Rect *srcrect=nullptr, SDL_Rect *clip_rect=nullptr)
void blit_surface(const surface &surf, const SDL_Rect *srcrect, surface &dst, const SDL_Rect *dstrect)
Replacement for sdl_blit.
static bool is_valid_image(const std::string &str)
GLubyte GLubyte GLubyte GLubyte w
bool point_in_rect(int x, int y, const SDL_Rect &rect)
Tests whether a point is inside a rectangle.
std::string::const_iterator parse_markup(std::string::const_iterator i1, std::string::const_iterator i2, int *font_size, SDL_Color *color, int *style)
Parses the markup-tags at the front of a string.
SDL_Rect draw_text(surface &dst, const SDL_Rect &area, int size, const SDL_Color &color, const std::string &txt, int x, int y, bool use_tooltips, int style)
Function to draw text on a surface.
GLfloat GLfloat GLfloat GLfloat h
GLint GLint GLint GLint GLint x
Declarations for File-IO.
std::string make_text_ellipsis(const std::string &text, int font_size, int max_width, int style)
If the text exceeds the specified max width, end it with an ellipsis (...)
const std::string button_press
const int vertical_padding
Contains the SDL_Rect helper code.
char const COLUMN_SEPARATOR
bool find(E event, F functor)
Tests whether an event handler is available.
const SDL_Color GRAY_COLOR
surface make_neutral_surface(const surface &surf)
this module manages the cache of images.
void play_UI_sound(const std::string &files)
Standard logging facilities (interface).
void assign(const surface &o)
bool set_text(const std::string &text, const bool markedup)
Sets the text to render.
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.
void update_rect(const SDL_Rect &)
bool file_exists(const std::string &name)
Returns true if a file or directory with such name already exists.
GLsizei const GLcharARB ** string
const int checkbox_horizontal_padding
const std::string checkbox_release