15 #define GETTEXT_DOMAIN "wesnoth-lib" 17 #include "widgets/button.hpp" 33 #include <boost/algorithm/string/predicate.hpp> 36 #define ERR_DP LOG_STREAM(err, log_display) 47 const bool auto_join, std::string overlay_image)
48 :
widget(video, auto_join), type_(type),
50 image_(nullptr), pressedImage_(nullptr), activeImage_(nullptr), pressedActiveImage_(nullptr),
51 disabledImage_(nullptr), pressedDisabledImage_(nullptr),
52 overlayImage_(nullptr), overlayPressedImage_(nullptr), overlayActiveImage_(nullptr),
53 state_(
NORMAL), pressed_(false),
54 spacing_(spacing), base_height_(0), base_width_(0),
55 button_image_name_(), button_overlay_image_name_(overlay_image),
56 button_image_path_suffix_()
58 if (button_image_name.empty()) {
85 std::string size_postfix;
107 surface pressed_disabled_image, pressed_active_image, touched_image;
135 if (disabled_image ==
nullptr) {
140 pressed_image = button_image;
143 active_image = button_image;
148 touched_image = pressed_image;
151 if (!pressed_active_image)
152 pressed_active_image = pressed_image;
156 if (!pressed_disabled_image)
161 std::string err_msg =
"error initializing button images! file name: ";
164 ERR_DP << err_msg << std::endl;
211 bool change_size = loc.h == 0 || loc.w == 0;
218 int style = TTF_STYLE_NORMAL;
222 std::string tmp(
i, i_end);
269 if (
state_ != new_state) {
307 const int image_w =
image_->w;
331 SDL_Rect clipArea = loc;
332 const int texty = loc.y + loc.h / 2 -
textRect_.h / 2 + offset;
336 textx = loc.x + image->w / 2 -
textRect_.w / 2 + offset;
339 textx = loc.x + image_w + checkbox_horizontal_padding / 2;
375 sdl_blit(*noverlay,
nullptr, nimage,
nullptr);
381 clipArea.x += offset;
382 clipArea.y += offset;
383 clipArea.w -= 2*offset;
384 clipArea.h -= 2*offset;
426 const std::vector<std::string>::const_iterator
i = std::find_if(items.begin(),items.end(),
is_valid_image);
427 if(i != items.end()) {
439 if (
hit(event.x, event.y)) {
473 if (
hit(event.x, event.y) && event.button == SDL_BUTTON_LEFT) {
501 if (!(
hit(event.x, event.y) && event.button == SDL_BUTTON_LEFT))
562 case SDL_MOUSEBUTTONDOWN:
565 case SDL_MOUSEBUTTONUP:
568 case SDL_MOUSEMOTION:
576 if (start_state !=
state_)
const color_t BUTTON_COLOR
surface get_image(const image::locator &i_locator, TYPE type)
Caches and returns an image.
static void check(LexState *ls, int c)
std::string::const_iterator parse_markup(std::string::const_iterator i1, std::string::const_iterator i2, int *font_size, color_t *color, int *style)
Parses the markup-tags at the front of a string.
static l_noret error(LoadState *S, const char *why)
static bool file_exists(const bfs::path &fpath)
bool ends_with(const std::string &str, const std::string &suffix)
const int horizontal_padding
const std::vector< std::string > items
surface scale_surface(const surface &surf, int w, int h)
Scale a surface using alpha-weighted modified bilinear filtering Note: causes artifacts with alpha gr...
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.
surface clone() const
Makes a copy of this surface.
static bool is_valid_image(const std::string &str)
bool point_in_rect(int x, int y, const SDL_Rect &rect)
Tests whether a point is inside a rectangle.
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
std::vector< std::string > split(const config_attribute_value &val)
SDL_Rect draw_text(surface &dst, const SDL_Rect &area, int size, const color_t &color, const std::string &txt, int x, int y, bool use_tooltips, int style)
Function to draw text on a surface.
Functions to load and save images from/to disk.
void play_UI_sound(const std::string &files)
Standard logging facilities (interface).
void sdl_blit(const surface &src, SDL_Rect *src_rect, surface &dst, SDL_Rect *dst_rect)
const int checkbox_horizontal_padding
const std::string checkbox_release