#include <button.hpp>
Public Types | |
enum | TYPE { TYPE_PRESS , TYPE_CHECK , TYPE_TURBO , TYPE_IMAGE , TYPE_RADIO } |
enum | SPACE_CONSUMPTION { DEFAULT_SPACE , MINIMUM_SPACE } |
Public Member Functions | |
TYPE | get_type () const |
button (const std::string &label, TYPE type=TYPE_PRESS, std::string button_image="", SPACE_CONSUMPTION spacing=DEFAULT_SPACE, const bool auto_join=true, std::string overlay_image="", int font_size=-1) | |
virtual | ~button () |
Default implementation, but defined out-of-line for efficiency reasons. More... | |
void | set_check (bool check) |
void | set_active (bool active) |
bool | checked () const |
void | set_label (const std::string &val) |
void | set_image (const std::string &image_file_base) |
void | set_overlay (const std::string &image_file_base) |
void | set_image_path_suffix (const std::string &suffix) |
bool | pressed () |
bool | hit (int x, int y) const |
virtual void | enable (bool new_val=true) |
void | release () |
Public Member Functions inherited from gui::widget | |
const rect & | location () const |
virtual void | set_location (const SDL_Rect &rect) |
void | set_location (int x, int y) |
void | set_width (int w) |
void | set_height (int h) |
void | set_measurements (int w, int h) |
int | width () const |
int | height () const |
bool | focus (const SDL_Event *event) |
void | set_focus (bool focus) |
virtual void | hide (bool value=true) |
bool | hidden () const |
bool | enabled () const |
void | set_clip_rect (const SDL_Rect &rect) |
void | queue_redraw () |
Indicate that the widget should be redrawn. More... | |
void | queue_redraw (const rect &) |
Indicate that a specific region of the screen should be redrawn. More... | |
void | set_dirty (bool dirty=true) |
bool | dirty () const |
const std::string & | id () const |
void | set_id (const std::string &id) |
void | set_tooltip_string (const std::string &str) |
virtual void | process_tooltip_string (int mousex, int mousey) override |
virtual void | layout () override |
Called by draw_manager to validate layout. More... | |
virtual bool | expose (const rect ®ion) override |
Called by draw_manager when it believes a redraw is necessary. More... | |
virtual rect | screen_location () override |
The current draw location of the display, on the screen. More... | |
Public Member Functions inherited from events::sdl_handler | |
virtual void | handle_window_event (const SDL_Event &) |
virtual void | process_event () |
virtual bool | requires_event_focus (const SDL_Event *=nullptr) const |
virtual void | join () |
virtual void | join (context &c) |
virtual void | join_same (sdl_handler *parent) |
virtual void | leave () |
virtual void | join_global () |
virtual void | leave_global () |
virtual bool | has_joined () |
virtual bool | has_joined_global () |
sdl_handler & | operator= (sdl_handler &&)=delete |
Moving would require two instances' context membership to be handled, it's simpler to delete these and require the two instances to be separately constructed / destructed. More... | |
sdl_handler (sdl_handler &&)=delete | |
Public Member Functions inherited from gui2::top_level_drawable | |
virtual void | update () |
Update state and any parameters that may effect layout, or any of the later stages. More... | |
virtual void | render () |
Perform any internal rendering necessary to prepare the drawable. More... | |
Protected Member Functions | |
virtual void | handle_event (const SDL_Event &event) |
virtual void | mouse_motion (const SDL_MouseMotionEvent &event) |
virtual void | mouse_down (const SDL_MouseButtonEvent &event) |
virtual void | mouse_up (const SDL_MouseButtonEvent &event) |
virtual void | draw_contents () |
Protected Member Functions inherited from gui::widget | |
widget (const bool auto_join=true) | |
virtual | ~widget () |
virtual void | update_location (const SDL_Rect &) |
bool | mouse_locked () const |
void | aquire_mouse_lock () |
void | free_mouse_lock () |
Protected Member Functions inherited from events::sdl_handler | |
sdl_handler (const bool auto_join=true) | |
sdl_handler (const sdl_handler &) | |
sdl_handler & | operator= (const sdl_handler &) |
virtual | ~sdl_handler () |
virtual std::vector< sdl_handler * > | handler_members () |
Protected Member Functions inherited from gui2::top_level_drawable | |
top_level_drawable () | |
virtual | ~top_level_drawable () |
top_level_drawable (const top_level_drawable &) | |
top_level_drawable & | operator= (const top_level_drawable &) |
top_level_drawable (top_level_drawable &&) | |
top_level_drawable & | operator= (top_level_drawable &&) |
Protected Attributes | |
TYPE | type_ |
Protected Attributes inherited from gui::widget | |
bool | focus_ |
Private Types | |
enum | STATE { UNINIT , NORMAL , ACTIVE , PRESSED , PRESSED_ACTIVE , TOUCHED_NORMAL , TOUCHED_PRESSED } |
Private Member Functions | |
void | load_images () |
void | calculate_size () |
Private Attributes | |
std::string | label_text_ |
texture | image_ |
texture | pressedImage_ |
texture | activeImage_ |
texture | pressedActiveImage_ |
texture | touchedImage_ |
texture | disabledImage_ |
texture | pressedDisabledImage_ |
texture | overlayImage_ |
texture | overlayPressedImage_ |
texture | overlayPressedDisabledImage_ |
texture | overlayDisabledImage_ |
texture | overlayActiveImage_ |
SDL_Rect | textRect_ |
STATE | state_ |
bool | pressed_ |
SPACE_CONSUMPTION | spacing_ |
int | base_height_ |
int | base_width_ |
std::string | button_image_name_ |
std::string | button_overlay_image_name_ |
std::string | button_image_path_suffix_ |
int | font_size_ |
int | horizontal_padding_ |
int | checkbox_horizontal_padding_ |
int | vertical_padding_ |
Definition at line 26 of file button.hpp.
Enumerator | |
---|---|
DEFAULT_SPACE | |
MINIMUM_SPACE |
Definition at line 32 of file button.hpp.
|
private |
Enumerator | |
---|---|
UNINIT | |
NORMAL | |
ACTIVE | |
PRESSED | |
PRESSED_ACTIVE | |
TOUCHED_NORMAL | |
TOUCHED_PRESSED |
Definition at line 78 of file button.hpp.
enum gui::button::TYPE |
Enumerator | |
---|---|
TYPE_PRESS | |
TYPE_CHECK | |
TYPE_TURBO | |
TYPE_IMAGE | |
TYPE_RADIO |
Definition at line 29 of file button.hpp.
gui::button::button | ( | const std::string & | label, |
button::TYPE | type = TYPE_PRESS , |
||
std::string | button_image = "" , |
||
SPACE_CONSUMPTION | spacing = DEFAULT_SPACE , |
||
const bool | auto_join = true , |
||
std::string | overlay_image = "" , |
||
int | font_size = -1 |
||
) |
Definition at line 41 of file button.cpp.
References button_image_name_, load_images(), type_, TYPE_CHECK, TYPE_PRESS, TYPE_RADIO, and TYPE_TURBO.
|
virtual |
Default implementation, but defined out-of-line for efficiency reasons.
Definition at line 197 of file button.cpp.
|
private |
Definition at line 201 of file button.cpp.
References base_height_, base_width_, font::BUTTON_COLOR, checkbox_horizontal_padding_, sdl::empty_rect, font_size_, texture::h(), horizontal_padding_, image_, label_text_, gui::widget::location(), MINIMUM_SPACE, font::pango_draw_text(), gui::widget::set_height(), gui::widget::set_location(), gui::widget::set_width(), spacing_, textRect_, type_, TYPE_IMAGE, TYPE_PRESS, TYPE_TURBO, vertical_padding_, and texture::w().
Referenced by load_images(), and set_label().
bool gui::button::checked | ( | ) | const |
Definition at line 267 of file button.cpp.
References PRESSED, PRESSED_ACTIVE, state_, and TOUCHED_PRESSED.
|
protectedvirtual |
Reimplemented from gui::widget.
Definition at line 286 of file button.cpp.
References ACTIVE, activeImage_, draw::blit(), font::BUTTON_COLOR, checkbox_horizontal_padding_, disabledImage_, gui::widget::enabled(), font_size_, font::GRAY_COLOR, texture::h(), image_, label_text_, gui::widget::location(), overlayActiveImage_, overlayDisabledImage_, overlayImage_, overlayPressedDisabledImage_, overlayPressedImage_, font::pango_draw_text(), PRESSED, PRESSED_ACTIVE, pressedActiveImage_, pressedDisabledImage_, pressedImage_, state_, textRect_, TOUCHED_NORMAL, TOUCHED_PRESSED, touchedImage_, type_, TYPE_CHECK, TYPE_IMAGE, TYPE_PRESS, TYPE_RADIO, TYPE_TURBO, and texture::w().
Referenced by release().
|
virtual |
Reimplemented from gui::widget.
Definition at line 272 of file button.cpp.
References gui::widget::enable(), gui::widget::enabled(), NORMAL, pressed_, state_, type_, and TYPE_CHECK.
|
inline |
Definition at line 30 of file button.hpp.
References type_.
|
protectedvirtual |
Reimplemented from gui::widget.
Definition at line 536 of file button.cpp.
References gui::widget::enabled(), gui::widget::handle_event(), gui::widget::hidden(), mouse_down(), gui::widget::mouse_locked(), mouse_motion(), mouse_up(), gui::widget::queue_redraw(), and state_.
bool gui::button::hit | ( | int | x, |
int | y | ||
) | const |
Definition at line 376 of file button.cpp.
References rect::contains(), and gui::widget::location().
Referenced by mouse_down(), mouse_motion(), and mouse_up().
|
private |
Definition at line 84 of file button.cpp.
References activeImage_, base_height_, base_width_, button_image_name_, button_image_path_suffix_, button_overlay_image_name_, calculate_size(), disabledImage_, ERR_DP, filesystem::file_exists(), image::get_texture(), texture::h(), h, image_, label_text_, gui::widget::location(), overlayActiveImage_, overlayDisabledImage_, overlayImage_, overlayPressedDisabledImage_, overlayPressedImage_, game_config::path, pressedActiveImage_, pressedDisabledImage_, pressedImage_, texture::reset(), set_label(), touchedImage_, type_, TYPE_CHECK, TYPE_IMAGE, TYPE_RADIO, and texture::w().
Referenced by button(), set_image(), set_image_path_suffix(), and set_overlay().
|
protectedvirtual |
Definition at line 457 of file button.cpp.
References ACTIVE, game_config::sounds::button_press, hit(), sound::play_UI_sound(), PRESSED, PRESSED_ACTIVE, state_, TOUCHED_NORMAL, TOUCHED_PRESSED, type_, TYPE_CHECK, TYPE_RADIO, and TYPE_TURBO.
Referenced by handle_event().
|
protectedvirtual |
Definition at line 423 of file button.cpp.
References ACTIVE, hit(), NORMAL, PRESSED, PRESSED_ACTIVE, state_, TOUCHED_NORMAL, TOUCHED_PRESSED, type_, TYPE_CHECK, TYPE_IMAGE, and TYPE_RADIO.
Referenced by handle_event().
|
protectedvirtual |
Reimplemented in location_palette_button.
Definition at line 485 of file button.cpp.
References ACTIVE, game_config::sounds::button_press, game_config::sounds::checkbox_release, hit(), sound::play_UI_sound(), PRESSED, pressed_, PRESSED_ACTIVE, state_, TOUCHED_NORMAL, TOUCHED_PRESSED, type_, TYPE_CHECK, TYPE_IMAGE, TYPE_PRESS, TYPE_RADIO, and TYPE_TURBO.
Referenced by handle_event(), and location_palette_button::mouse_up().
bool gui::button::pressed | ( | ) |
Definition at line 567 of file button.cpp.
References PRESSED, pressed_, PRESSED_ACTIVE, state_, TOUCHED_PRESSED, type_, and TYPE_TURBO.
Referenced by location_palette_button::mouse_up().
void gui::button::release | ( | ) |
Definition at line 480 of file button.cpp.
References draw_contents(), NORMAL, and state_.
void gui::button::set_active | ( | bool | active | ) |
Definition at line 256 of file button.cpp.
References ACTIVE, NORMAL, gui::widget::queue_redraw(), and state_.
void gui::button::set_check | ( | bool | check | ) |
Definition at line 238 of file button.cpp.
References ACTIVE, NORMAL, PRESSED, PRESSED_ACTIVE, gui::widget::queue_redraw(), state_, type_, TYPE_CHECK, TYPE_IMAGE, and TYPE_RADIO.
void gui::button::set_image | ( | const std::string & | image_file_base | ) |
Definition at line 383 of file button.cpp.
References button_image_name_, gui::is_valid_image(), load_images(), and gui::widget::queue_redraw().
|
inline |
Definition at line 48 of file button.hpp.
References button_image_path_suffix_, and load_images().
void gui::button::set_label | ( | const std::string & | val | ) |
Definition at line 406 of file button.cpp.
References calculate_size(), COLUMN_SEPARATOR, i, gui::is_valid_image(), label_text_, gui::widget::queue_redraw(), and utils::split().
Referenced by load_images().
void gui::button::set_overlay | ( | const std::string & | image_file_base | ) |
Definition at line 394 of file button.cpp.
References button_overlay_image_name_, IMAGE_PREFIX, load_images(), and gui::widget::queue_redraw().
|
private |
Definition at line 72 of file button.hpp.
Referenced by draw_contents(), and load_images().
|
private |
Definition at line 85 of file button.hpp.
Referenced by calculate_size(), and load_images().
|
private |
Definition at line 85 of file button.hpp.
Referenced by calculate_size(), and load_images().
|
private |
Definition at line 87 of file button.hpp.
Referenced by button(), load_images(), and set_image().
|
private |
Definition at line 89 of file button.hpp.
Referenced by load_images(), and set_image_path_suffix().
|
private |
Definition at line 88 of file button.hpp.
Referenced by load_images(), and set_overlay().
|
private |
Definition at line 93 of file button.hpp.
Referenced by calculate_size(), and draw_contents().
|
private |
Definition at line 73 of file button.hpp.
Referenced by draw_contents(), and load_images().
|
private |
Definition at line 91 of file button.hpp.
Referenced by calculate_size(), and draw_contents().
|
private |
Definition at line 92 of file button.hpp.
Referenced by calculate_size().
|
private |
Definition at line 72 of file button.hpp.
Referenced by calculate_size(), draw_contents(), and load_images().
|
private |
Definition at line 70 of file button.hpp.
Referenced by calculate_size(), draw_contents(), load_images(), and set_label().
|
private |
Definition at line 75 of file button.hpp.
Referenced by draw_contents(), and load_images().
|
private |
Definition at line 74 of file button.hpp.
Referenced by draw_contents(), and load_images().
|
private |
Definition at line 74 of file button.hpp.
Referenced by draw_contents(), and load_images().
|
private |
Definition at line 74 of file button.hpp.
Referenced by draw_contents(), and load_images().
|
private |
Definition at line 74 of file button.hpp.
Referenced by draw_contents(), and load_images().
|
private |
Definition at line 81 of file button.hpp.
Referenced by enable(), mouse_up(), and pressed().
|
private |
Definition at line 72 of file button.hpp.
Referenced by draw_contents(), and load_images().
|
private |
Definition at line 73 of file button.hpp.
Referenced by draw_contents(), and load_images().
|
private |
Definition at line 72 of file button.hpp.
Referenced by draw_contents(), and load_images().
|
private |
Definition at line 83 of file button.hpp.
Referenced by calculate_size().
|
private |
Definition at line 79 of file button.hpp.
Referenced by checked(), draw_contents(), enable(), handle_event(), mouse_down(), mouse_motion(), mouse_up(), pressed(), release(), set_active(), and set_check().
|
private |
Definition at line 76 of file button.hpp.
Referenced by calculate_size(), and draw_contents().
|
private |
Definition at line 73 of file button.hpp.
Referenced by draw_contents(), and load_images().
|
protected |
Definition at line 62 of file button.hpp.
Referenced by button(), calculate_size(), draw_contents(), enable(), get_type(), load_images(), mouse_down(), mouse_motion(), mouse_up(), pressed(), and set_check().
|
private |
Definition at line 94 of file button.hpp.
Referenced by calculate_size().