The Battle for Wesnoth  1.19.1+dev
Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Types | Private Member Functions | Private Attributes | List of all members
gui::button Class Reference

#include <button.hpp>

Inheritance diagram for gui::button:

Classes

struct  error
 

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 rectlocation () 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 &region) 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_handleroperator= (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_handleroperator= (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_drawableoperator= (const top_level_drawable &)
 
 top_level_drawable (top_level_drawable &&)
 
top_level_drawableoperator= (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_
 

Detailed Description

Definition at line 26 of file button.hpp.

Member Enumeration Documentation

◆ SPACE_CONSUMPTION

Enumerator
DEFAULT_SPACE 
MINIMUM_SPACE 

Definition at line 38 of file button.hpp.

◆ STATE

enum gui::button::STATE
private
Enumerator
UNINIT 
NORMAL 
ACTIVE 
PRESSED 
PRESSED_ACTIVE 
TOUCHED_NORMAL 
TOUCHED_PRESSED 

Definition at line 84 of file button.hpp.

◆ TYPE

Enumerator
TYPE_PRESS 
TYPE_CHECK 
TYPE_TURBO 
TYPE_IMAGE 
TYPE_RADIO 

Definition at line 35 of file button.hpp.

Constructor & Destructor Documentation

◆ button()

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.

◆ ~button()

gui::button::~button ( )
virtual

Default implementation, but defined out-of-line for efficiency reasons.

Definition at line 197 of file button.cpp.

Member Function Documentation

◆ calculate_size()

void gui::button::calculate_size ( )
private

◆ checked()

bool gui::button::checked ( ) const

Definition at line 267 of file button.cpp.

References PRESSED, PRESSED_ACTIVE, state_, and TOUCHED_PRESSED.

◆ draw_contents()

void gui::button::draw_contents ( )
protectedvirtual

◆ enable()

void gui::button::enable ( bool  new_val = true)
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.

◆ get_type()

TYPE gui::button::get_type ( ) const
inline

Definition at line 36 of file button.hpp.

References type_.

◆ handle_event()

void gui::button::handle_event ( const SDL_Event &  event)
protectedvirtual

◆ hit()

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().

◆ load_images()

void gui::button::load_images ( )
private

◆ mouse_down()

void gui::button::mouse_down ( const SDL_MouseButtonEvent &  event)
protectedvirtual

◆ mouse_motion()

void gui::button::mouse_motion ( const SDL_MouseMotionEvent &  event)
protectedvirtual

◆ mouse_up()

void gui::button::mouse_up ( const SDL_MouseButtonEvent &  event)
protectedvirtual

◆ pressed()

bool gui::button::pressed ( )

◆ release()

void gui::button::release ( )

Definition at line 480 of file button.cpp.

References draw_contents(), NORMAL, and state_.

◆ set_active()

void gui::button::set_active ( bool  active)

Definition at line 256 of file button.cpp.

References ACTIVE, NORMAL, gui::widget::queue_redraw(), and state_.

◆ set_check()

void gui::button::set_check ( bool  check)

◆ set_image()

void gui::button::set_image ( const std::string &  image_file_base)

◆ set_image_path_suffix()

void gui::button::set_image_path_suffix ( const std::string &  suffix)
inline

Definition at line 54 of file button.hpp.

References button_image_path_suffix_, and load_images().

◆ set_label()

void gui::button::set_label ( const std::string &  val)

◆ set_overlay()

void gui::button::set_overlay ( const std::string &  image_file_base)

Member Data Documentation

◆ activeImage_

texture gui::button::activeImage_
private

Definition at line 78 of file button.hpp.

Referenced by draw_contents(), and load_images().

◆ base_height_

int gui::button::base_height_
private

Definition at line 91 of file button.hpp.

Referenced by calculate_size(), and load_images().

◆ base_width_

int gui::button::base_width_
private

Definition at line 91 of file button.hpp.

Referenced by calculate_size(), and load_images().

◆ button_image_name_

std::string gui::button::button_image_name_
private

Definition at line 93 of file button.hpp.

Referenced by button(), load_images(), and set_image().

◆ button_image_path_suffix_

std::string gui::button::button_image_path_suffix_
private

Definition at line 95 of file button.hpp.

Referenced by load_images(), and set_image_path_suffix().

◆ button_overlay_image_name_

std::string gui::button::button_overlay_image_name_
private

Definition at line 94 of file button.hpp.

Referenced by load_images(), and set_overlay().

◆ checkbox_horizontal_padding_

int gui::button::checkbox_horizontal_padding_
private

Definition at line 99 of file button.hpp.

Referenced by calculate_size(), and draw_contents().

◆ disabledImage_

texture gui::button::disabledImage_
private

Definition at line 79 of file button.hpp.

Referenced by draw_contents(), and load_images().

◆ font_size_

int gui::button::font_size_
private

Definition at line 97 of file button.hpp.

Referenced by calculate_size(), and draw_contents().

◆ horizontal_padding_

int gui::button::horizontal_padding_
private

Definition at line 98 of file button.hpp.

Referenced by calculate_size().

◆ image_

texture gui::button::image_
private

Definition at line 78 of file button.hpp.

Referenced by calculate_size(), draw_contents(), and load_images().

◆ label_text_

std::string gui::button::label_text_
private

Definition at line 76 of file button.hpp.

Referenced by calculate_size(), draw_contents(), load_images(), and set_label().

◆ overlayActiveImage_

texture gui::button::overlayActiveImage_
private

Definition at line 81 of file button.hpp.

Referenced by draw_contents(), and load_images().

◆ overlayDisabledImage_

texture gui::button::overlayDisabledImage_
private

Definition at line 80 of file button.hpp.

Referenced by draw_contents(), and load_images().

◆ overlayImage_

texture gui::button::overlayImage_
private

Definition at line 80 of file button.hpp.

Referenced by draw_contents(), and load_images().

◆ overlayPressedDisabledImage_

texture gui::button::overlayPressedDisabledImage_
private

Definition at line 80 of file button.hpp.

Referenced by draw_contents(), and load_images().

◆ overlayPressedImage_

texture gui::button::overlayPressedImage_
private

Definition at line 80 of file button.hpp.

Referenced by draw_contents(), and load_images().

◆ pressed_

bool gui::button::pressed_
private

Definition at line 87 of file button.hpp.

Referenced by enable(), mouse_up(), and pressed().

◆ pressedActiveImage_

texture gui::button::pressedActiveImage_
private

Definition at line 78 of file button.hpp.

Referenced by draw_contents(), and load_images().

◆ pressedDisabledImage_

texture gui::button::pressedDisabledImage_
private

Definition at line 79 of file button.hpp.

Referenced by draw_contents(), and load_images().

◆ pressedImage_

texture gui::button::pressedImage_
private

Definition at line 78 of file button.hpp.

Referenced by draw_contents(), and load_images().

◆ spacing_

SPACE_CONSUMPTION gui::button::spacing_
private

Definition at line 89 of file button.hpp.

Referenced by calculate_size().

◆ state_

STATE gui::button::state_
private

◆ textRect_

SDL_Rect gui::button::textRect_
private

Definition at line 82 of file button.hpp.

Referenced by calculate_size(), and draw_contents().

◆ touchedImage_

texture gui::button::touchedImage_
private

Definition at line 79 of file button.hpp.

Referenced by draw_contents(), and load_images().

◆ type_

TYPE gui::button::type_
protected

◆ vertical_padding_

int gui::button::vertical_padding_
private

Definition at line 100 of file button.hpp.

Referenced by calculate_size().


The documentation for this class was generated from the following files: