16 #define GETTEXT_DOMAIN "wesnoth-lib" 18 #include "widgets/button.hpp" 33 #include <boost/algorithm/string/predicate.hpp> 36 #define ERR_DP LOG_STREAM(err, log_display) 44 const bool auto_join, std::string overlay_image,
int font_size)
45 :
widget(video, auto_join), type_(type),
47 image_(nullptr), pressedImage_(nullptr), activeImage_(nullptr), pressedActiveImage_(nullptr),
48 disabledImage_(nullptr), pressedDisabledImage_(nullptr),
49 overlayImage_(nullptr), overlayPressedImage_(nullptr), overlayActiveImage_(nullptr),
50 state_(
NORMAL), pressed_(false),
51 spacing_(spacing), base_height_(0), base_width_(0),
52 button_image_name_(), button_overlay_image_name_(overlay_image),
53 button_image_path_suffix_(),
54 font_size_(font_size <= 0 ? (type != TYPE_CHECK && type != TYPE_RADIO ? default_font_size :
font::
SIZE_SMALL) : font_size),
55 horizontal_padding_(font_size_),
56 checkbox_horizontal_padding_(font_size_ / 2),
57 vertical_padding_(font_size_ / 2)
59 if (button_image_name.empty()) {
86 std::string size_postfix;
108 surface pressed_disabled_image, pressed_active_image, touched_image;
136 if (disabled_image ==
nullptr) {
141 pressed_image = button_image;
144 active_image = button_image;
149 touched_image = pressed_image;
152 if (!pressed_active_image)
153 pressed_active_image = pressed_image;
157 if (!pressed_disabled_image)
162 std::string err_msg =
"error initializing button images! file name: ";
165 ERR_DP << err_msg << std::endl;
251 if (
state_ != new_state) {
289 const int image_w =
image_->w;
313 SDL_Rect clipArea = loc;
314 const int texty = loc.y + loc.h / 2 -
textRect_.h / 2 + offset;
318 textx = loc.x + image->w / 2 -
textRect_.w / 2 + offset;
321 textx = loc.x + image_w + checkbox_horizontal_padding_ / 2;
357 sdl_blit(*noverlay,
nullptr, nimage,
nullptr);
363 clipArea.x += offset;
364 clipArea.y += offset;
365 clipArea.w -= 2*offset;
366 clipArea.h -= 2*offset;
408 const std::vector<std::string>::const_iterator
i = std::find_if(items.begin(),items.end(),
is_valid_image);
409 if(i != items.end()) {
421 if (
hit(event.x, event.y)) {
455 if (
hit(event.x, event.y) && event.button == SDL_BUTTON_LEFT) {
483 if (!(
hit(event.x, event.y) && event.button == SDL_BUTTON_LEFT))
544 case SDL_MOUSEBUTTONDOWN:
547 case SDL_MOUSEBUTTONUP:
550 case SDL_MOUSEMOTION:
558 if (start_state !=
state_)
const color_t BUTTON_COLOR
surface get_image(const image::locator &i_locator, TYPE type)
Caches and returns an image.
Collection of helper functions relating to Pango formatting.
static bool file_exists(const bfs::path &fpath)
bool ends_with(const std::string &str, const std::string &suffix)
const int default_font_size
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)
Copies an area of a surface to the drawing surface.
surface clone() const
Makes a copy of this surface.
std::string label
What to show in the filter's drop-down list.
static bool is_valid_image(const std::string &str)
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.
bool point_in_rect(int x, int y, const SDL_Rect &rect)
Tests whether a point is inside a rectangle.
Declarations for File-IO.
const std::string button_press
Contains the SDL_Rect helper code.
char const COLUMN_SEPARATOR
std::vector< std::string > split(const config_attribute_value &val)
Base class for all the errors encountered by the engine.
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)
Transitional API for porting SDL_ttf-based code to Pango.
const std::string checkbox_release