The Battle for Wesnoth  1.15.10+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

A button is a control that can be pushed to start an action or close a dialog. More...

#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 (CVideo &video, 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="")
 
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 SDL_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 set_volatile (bool val=true)
 
void set_dirty (bool dirty=true)
 
bool dirty () const
 
const std::string & id () const
 
void set_id (const std::string &id)
 
void set_help_string (const std::string &str)
 
void set_tooltip_string (const std::string &str)
 
virtual void process_help_string (int mousex, int mousey)
 
virtual void process_tooltip_string (int mousex, int mousey)
 
virtual void draw ()
 
- Public Member Functions inherited from events::sdl_handler
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
 

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 (CVideo &video, const bool auto_join=true)
 
virtual ~widget ()
 
void bg_register (const SDL_Rect &rect)
 
void bg_restore () const
 
void bg_restore (const SDL_Rect &rect) const
 
void bg_update ()
 
void bg_cancel ()
 
CVideovideo () const
 
virtual void update_location (const SDL_Rect &rect)
 
const SDL_Rect * clip_rect () const
 
virtual sdl_handler_vector member_handlers ()
 
virtual void handle_window_event (const SDL_Event &event)
 
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 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_
 
surface image_
 
surface pressedImage_
 
surface activeImage_
 
surface pressedActiveImage_
 
surface touchedImage_
 
surface disabledImage_
 
surface pressedDisabledImage_
 
surface overlayImage_
 
surface overlayPressedImage_
 
surface overlayPressedDisabledImage_
 
surface overlayDisabledImage_
 
surface 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_
 

Detailed Description

A button is a control that can be pushed to start an action or close a dialog.

When a button has a return value it sets the return value for the window. Normally this closes the window and returns this value to the caller. The return value can either be defined by the user or determined from the id of the button. The return value has a higher precedence as the one defined by the id. (Of course it's weird to give a button an id and then override its return value.)

When the button doesn't have a standard id, but you still want to use the return value of that id, use return_value_id instead. This has a higher precedence as return_value.

List with the button specific variables:

Key Type DefaultDescription
return_value_idstring"" The return value id.
return_value int 0 The return value.

The following states exist:

Definition at line 49 of file button.hpp.

Member Enumeration Documentation

◆ SPACE_CONSUMPTION

Enumerator
DEFAULT_SPACE 
MINIMUM_SPACE 

Definition at line 61 of file button.hpp.

◆ STATE

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

Definition at line 107 of file button.hpp.

◆ TYPE

Enumerator
TYPE_PRESS 
TYPE_CHECK 
TYPE_TURBO 
TYPE_IMAGE 
TYPE_RADIO 

Definition at line 58 of file button.hpp.

Constructor & Destructor Documentation

◆ button()

gui::button::button ( CVideo video,
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 = "" 
)

Definition at line 45 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 286 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

◆ get_type()

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

Definition at line 59 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

◆ 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 494 of file button.cpp.

References draw_contents(), NORMAL, and state_.

Referenced by set_image_path_suffix().

◆ set_active()

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

Definition at line 275 of file button.cpp.

References ACTIVE, NORMAL, gui::widget::set_dirty(), 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

◆ 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_

surface gui::button::activeImage_
private

Definition at line 101 of file button.hpp.

Referenced by draw_contents(), and load_images().

◆ base_height_

int gui::button::base_height_
private

Definition at line 114 of file button.hpp.

Referenced by calculate_size(), and load_images().

◆ base_width_

int gui::button::base_width_
private

Definition at line 114 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 116 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 118 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 117 of file button.hpp.

Referenced by load_images(), and set_overlay().

◆ disabledImage_

surface gui::button::disabledImage_
private

Definition at line 101 of file button.hpp.

Referenced by draw_contents(), and load_images().

◆ image_

surface gui::button::image_
private

Definition at line 101 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 99 of file button.hpp.

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

◆ overlayActiveImage_

surface gui::button::overlayActiveImage_
private

Definition at line 101 of file button.hpp.

Referenced by draw_contents(), and load_images().

◆ overlayDisabledImage_

surface gui::button::overlayDisabledImage_
private

Definition at line 101 of file button.hpp.

Referenced by draw_contents(), and load_images().

◆ overlayImage_

surface gui::button::overlayImage_
private

Definition at line 101 of file button.hpp.

Referenced by draw_contents(), and load_images().

◆ overlayPressedDisabledImage_

surface gui::button::overlayPressedDisabledImage_
private

Definition at line 101 of file button.hpp.

Referenced by draw_contents(), and load_images().

◆ overlayPressedImage_

surface gui::button::overlayPressedImage_
private

Definition at line 101 of file button.hpp.

Referenced by draw_contents(), and load_images().

◆ pressed_

bool gui::button::pressed_
private

Definition at line 110 of file button.hpp.

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

◆ pressedActiveImage_

surface gui::button::pressedActiveImage_
private

Definition at line 101 of file button.hpp.

Referenced by draw_contents(), and load_images().

◆ pressedDisabledImage_

surface gui::button::pressedDisabledImage_
private

Definition at line 101 of file button.hpp.

Referenced by draw_contents(), and load_images().

◆ pressedImage_

surface gui::button::pressedImage_
private

Definition at line 101 of file button.hpp.

Referenced by draw_contents(), and load_images().

◆ spacing_

SPACE_CONSUMPTION gui::button::spacing_
private

Definition at line 112 of file button.hpp.

Referenced by calculate_size().

◆ state_

STATE gui::button::state_
private

◆ textRect_

SDL_Rect gui::button::textRect_
private

Definition at line 105 of file button.hpp.

Referenced by calculate_size(), and draw_contents().

◆ touchedImage_

surface gui::button::touchedImage_
private

Definition at line 101 of file button.hpp.

Referenced by draw_contents(), and load_images().

◆ type_

TYPE gui::button::type_
protected

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