The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
button.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2003 - 2025
3 by David White <dave@whitevine.net>
4 Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY.
12
13 See the COPYING file for more details.
14*/
15
16#pragma once
17
18#include "widget.hpp"
19
20#include "exceptions.hpp"
21
22#include "sdl/texture.hpp"
23
24namespace gui {
25
26class button : public widget
27{
28public:
30 TYPE get_type() const { return type_; }
31
33
34 button(const std::string& label, TYPE type=TYPE_PRESS,
35 const std::string& button_image="", SPACE_CONSUMPTION spacing=DEFAULT_SPACE,
36 const bool auto_join=true, std::string overlay_image="", int font_size = -1);
37
38
39 /** Default implementation, but defined out-of-line for efficiency reasons. */
40 virtual ~button();
41 void set_check(bool check);
42 void set_active(bool active);
43 bool checked() const;
44
45 void set_label(const std::string& val);
46 void set_image(const std::string& image_file_base);
47 void set_overlay(const std::string& image_file_base);
48 void set_image_path_suffix(const std::string& suffix) { button_image_path_suffix_ = suffix; load_images(); }
49
50 bool pressed();
51 bool hit(int x, int y) const;
52 virtual void enable(bool new_val=true);
53 void release();
54
55protected:
56 virtual void handle_event(const SDL_Event& event);
57 virtual void mouse_motion(const SDL_MouseMotionEvent& event);
58 virtual void mouse_down(const SDL_MouseButtonEvent& event);
59 virtual void mouse_up(const SDL_MouseButtonEvent& event);
60 virtual void draw_contents();
61
63
64private:
65
66 void load_images();
67
68 void calculate_size();
69
70 std::string label_text_;
71
77
80
82
84
86
87 std::string button_image_name_;
90
95
96}; //end class button
97
98}
int checkbox_horizontal_padding_
Definition button.hpp:93
void set_overlay(const std::string &image_file_base)
Definition button.cpp:395
texture image_
Definition button.hpp:72
int base_width_
Definition button.hpp:85
virtual void handle_event(const SDL_Event &event)
Definition button.cpp:537
void load_images()
Definition button.cpp:85
texture disabledImage_
Definition button.hpp:73
void set_image_path_suffix(const std::string &suffix)
Definition button.hpp:48
bool hit(int x, int y) const
Definition button.cpp:377
texture touchedImage_
Definition button.hpp:73
bool pressed()
Definition button.cpp:568
virtual void enable(bool new_val=true)
Definition button.cpp:273
int font_size_
Definition button.hpp:91
TYPE type_
Definition button.hpp:62
int base_height_
Definition button.hpp:85
TYPE get_type() const
Definition button.hpp:30
std::string button_image_path_suffix_
Definition button.hpp:89
void calculate_size()
Definition button.cpp:202
texture overlayPressedImage_
Definition button.hpp:74
virtual void draw_contents()
Definition button.cpp:287
bool pressed_
Definition button.hpp:81
void release()
Definition button.cpp:481
STATE state_
Definition button.hpp:79
SPACE_CONSUMPTION spacing_
Definition button.hpp:83
std::string button_image_name_
Definition button.hpp:87
void set_active(bool active)
Definition button.cpp:257
@ MINIMUM_SPACE
Definition button.hpp:32
@ DEFAULT_SPACE
Definition button.hpp:32
texture overlayActiveImage_
Definition button.hpp:75
virtual void mouse_up(const SDL_MouseButtonEvent &event)
Definition button.cpp:486
texture activeImage_
Definition button.hpp:72
std::string label_text_
Definition button.hpp:70
texture pressedActiveImage_
Definition button.hpp:72
texture overlayDisabledImage_
Definition button.hpp:74
int horizontal_padding_
Definition button.hpp:92
texture overlayImage_
Definition button.hpp:74
texture pressedDisabledImage_
Definition button.hpp:73
void set_image(const std::string &image_file_base)
Definition button.cpp:384
int vertical_padding_
Definition button.hpp:94
void set_label(const std::string &val)
Definition button.cpp:407
virtual void mouse_down(const SDL_MouseButtonEvent &event)
Definition button.cpp:458
bool checked() const
Definition button.cpp:268
virtual void mouse_motion(const SDL_MouseMotionEvent &event)
Definition button.cpp:424
@ TOUCHED_NORMAL
Definition button.hpp:78
@ TOUCHED_PRESSED
Definition button.hpp:78
@ PRESSED_ACTIVE
Definition button.hpp:78
rect textRect_
Definition button.hpp:76
texture pressedImage_
Definition button.hpp:72
texture overlayPressedDisabledImage_
Definition button.hpp:74
std::string button_overlay_image_name_
Definition button.hpp:88
void set_check(bool check)
Definition button.cpp:239
virtual ~button()
Default implementation, but defined out-of-line for efficiency reasons.
Definition button.cpp:198
Wrapper class to encapsulate creation and management of an SDL_Texture.
Definition texture.hpp:33
std::string label
What to show in the filter's drop-down list.
Definition manager.cpp:201
General purpose widgets.
An abstract description of a rectangle with integer coordinates.
Definition rect.hpp:49