The Battle for Wesnoth
1.19.7+dev
editor
palette
tristate_button.hpp
Go to the documentation of this file.
1
/*
2
Copyright (C) 2003 - 2024
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 "widgets/widget.hpp"
19
20
#include "
exceptions.hpp
"
21
#include "
editor/palette/common_palette.hpp
"
22
#include "
sdl/texture.hpp
"
23
24
namespace
gui
{
25
26
//This button has 4 states, why it is called tristate?
27
class
tristate_button
:
public
widget
28
{
29
30
public
:
31
32
struct
error
:
public
game::error
{
33
error
()
34
:
game
::
error
(
"GUI1 tristate button error"
)
35
{}
36
};
37
38
enum
PRESSED_STATE
{
LEFT
,
RIGHT
,
BOTH
,
NONE
};
39
40
tristate_button
(
41
editor::tristate_palette
*
palette
,
42
std::string button_image=
""
,
43
const
bool
auto_join=
true
);
44
45
/** Default implementation, but defined out-of-line for efficiency reasons. */
46
virtual
~tristate_button
();
47
48
void
set_pressed
(
PRESSED_STATE
new_pressed_state);
49
50
// void set_active(bool active);
51
52
bool
pressed
();
53
PRESSED_STATE
pressed_state
()
const
;
54
55
bool
hit
(
int
x,
int
y)
const
;
56
virtual
void
enable
(
bool
new_val=
true
)
override
;
57
void
release
();
58
59
void
set_item_image
(
const
texture
& base,
const
texture
& over =
texture
())
60
{
61
itemBaseImage_
= base;
62
itemOverlayImage_
= over;
63
}
64
65
void
set_item_id
(
const
std::string&
id
) {
66
item_id_
=
id
;
67
}
68
69
protected
:
70
71
virtual
void
handle_event
(
const
SDL_Event& event)
override
;
72
virtual
void
mouse_motion
(
const
SDL_MouseMotionEvent& event);
73
virtual
void
mouse_down
(
const
SDL_MouseButtonEvent& event);
74
virtual
void
mouse_up
(
const
SDL_MouseButtonEvent& event);
75
76
virtual
void
draw_contents
()
override
;
77
78
private
:
79
80
void
calculate_size
();
81
82
texture
baseImage_
,
touchedBaseImage_
,
activeBaseImage_
,
83
itemBaseImage_
,
itemOverlayImage_
,
84
// normalImage_, activeImage_,
85
pressedDownImage_
,
pressedUpImage_
,
pressedBothImage_
,
86
pressedBothActiveImage_
,
pressedDownActiveImage_
,
pressedUpActiveImage_
,
87
touchedDownImage_
,
touchedUpImage_
,
touchedBothImage_
;
88
// disabledImage_, pressedDownDisabledImage_, pressedUpDisabledImage_, pressedBothDisabledImage_;
89
90
SDL_Rect
textRect_
;
91
92
enum
STATE
{
UNINIT
,
93
NORMAL
,
ACTIVE
,
94
PRESSED_ACTIVE_LEFT
,
PRESSED_ACTIVE_RIGHT
,
PRESSED_ACTIVE_BOTH
,
95
TOUCHED_RIGHT
,
TOUCHED_BOTH_RIGHT
,
TOUCHED_BOTH_LEFT
,
TOUCHED_LEFT
,
96
PRESSED_LEFT
,
PRESSED_RIGHT
,
PRESSED_BOTH
97
};
98
99
100
STATE
state_
;
101
102
bool
pressed_
;
103
104
int
base_height_
,
base_width_
;
105
106
editor::tristate_palette
*
palette_
;
107
108
std::string
item_id_
;
109
110
};
//end class button
111
112
}
editor::tristate_palette
Definition:
common_palette.hpp:100
gui::tristate_button
Definition:
tristate_button.hpp:28
gui::tristate_button::activeBaseImage_
texture activeBaseImage_
Definition:
tristate_button.hpp:82
gui::tristate_button::pressedBothImage_
texture pressedBothImage_
Definition:
tristate_button.hpp:85
gui::tristate_button::touchedBaseImage_
texture touchedBaseImage_
Definition:
tristate_button.hpp:82
gui::tristate_button::touchedDownImage_
texture touchedDownImage_
Definition:
tristate_button.hpp:87
gui::tristate_button::touchedUpImage_
texture touchedUpImage_
Definition:
tristate_button.hpp:87
gui::tristate_button::pressed
bool pressed()
Definition:
tristate_button.cpp:409
gui::tristate_button::textRect_
SDL_Rect textRect_
Definition:
tristate_button.hpp:90
gui::tristate_button::draw_contents
virtual void draw_contents() override
Definition:
tristate_button.cpp:171
gui::tristate_button::item_id_
std::string item_id_
Definition:
tristate_button.hpp:108
gui::tristate_button::pressedUpImage_
texture pressedUpImage_
Definition:
tristate_button.hpp:85
gui::tristate_button::itemOverlayImage_
texture itemOverlayImage_
Definition:
tristate_button.hpp:83
gui::tristate_button::pressedUpActiveImage_
texture pressedUpActiveImage_
Definition:
tristate_button.hpp:86
gui::tristate_button::hit
bool hit(int x, int y) const
Definition:
tristate_button.cpp:246
gui::tristate_button::baseImage_
texture baseImage_
Definition:
tristate_button.hpp:82
gui::tristate_button::base_width_
int base_width_
Definition:
tristate_button.hpp:104
gui::tristate_button::pressedDownImage_
texture pressedDownImage_
Definition:
tristate_button.hpp:85
gui::tristate_button::set_pressed
void set_pressed(PRESSED_STATE new_pressed_state)
Definition:
tristate_button.cpp:107
gui::tristate_button::~tristate_button
virtual ~tristate_button()
Default implementation, but defined out-of-line for efficiency reasons.
Definition:
tristate_button.cpp:105
gui::tristate_button::palette_
editor::tristate_palette * palette_
Definition:
tristate_button.hpp:106
gui::tristate_button::base_height_
int base_height_
Definition:
tristate_button.hpp:104
gui::tristate_button::handle_event
virtual void handle_event(const SDL_Event &event) override
Definition:
tristate_button.cpp:380
gui::tristate_button::mouse_up
virtual void mouse_up(const SDL_MouseButtonEvent &event)
Definition:
tristate_button.cpp:332
gui::tristate_button::set_item_id
void set_item_id(const std::string &id)
Definition:
tristate_button.hpp:65
gui::tristate_button::pressed_state
PRESSED_STATE pressed_state() const
Definition:
tristate_button.cpp:142
gui::tristate_button::enable
virtual void enable(bool new_val=true) override
Definition:
tristate_button.cpp:161
gui::tristate_button::calculate_size
void calculate_size()
gui::tristate_button::release
void release()
Definition:
tristate_button.cpp:327
gui::tristate_button::pressedBothActiveImage_
texture pressedBothActiveImage_
Definition:
tristate_button.hpp:86
gui::tristate_button::STATE
STATE
Definition:
tristate_button.hpp:92
gui::tristate_button::TOUCHED_BOTH_RIGHT
@ TOUCHED_BOTH_RIGHT
Definition:
tristate_button.hpp:95
gui::tristate_button::PRESSED_BOTH
@ PRESSED_BOTH
Definition:
tristate_button.hpp:96
gui::tristate_button::PRESSED_ACTIVE_RIGHT
@ PRESSED_ACTIVE_RIGHT
Definition:
tristate_button.hpp:94
gui::tristate_button::PRESSED_LEFT
@ PRESSED_LEFT
Definition:
tristate_button.hpp:96
gui::tristate_button::TOUCHED_RIGHT
@ TOUCHED_RIGHT
Definition:
tristate_button.hpp:95
gui::tristate_button::TOUCHED_BOTH_LEFT
@ TOUCHED_BOTH_LEFT
Definition:
tristate_button.hpp:95
gui::tristate_button::PRESSED_RIGHT
@ PRESSED_RIGHT
Definition:
tristate_button.hpp:96
gui::tristate_button::TOUCHED_LEFT
@ TOUCHED_LEFT
Definition:
tristate_button.hpp:95
gui::tristate_button::NORMAL
@ NORMAL
Definition:
tristate_button.hpp:93
gui::tristate_button::UNINIT
@ UNINIT
Definition:
tristate_button.hpp:92
gui::tristate_button::ACTIVE
@ ACTIVE
Definition:
tristate_button.hpp:93
gui::tristate_button::PRESSED_ACTIVE_LEFT
@ PRESSED_ACTIVE_LEFT
Definition:
tristate_button.hpp:94
gui::tristate_button::PRESSED_ACTIVE_BOTH
@ PRESSED_ACTIVE_BOTH
Definition:
tristate_button.hpp:94
gui::tristate_button::mouse_down
virtual void mouse_down(const SDL_MouseButtonEvent &event)
Definition:
tristate_button.cpp:305
gui::tristate_button::pressed_
bool pressed_
Definition:
tristate_button.hpp:102
gui::tristate_button::touchedBothImage_
texture touchedBothImage_
Definition:
tristate_button.hpp:87
gui::tristate_button::mouse_motion
virtual void mouse_motion(const SDL_MouseMotionEvent &event)
Definition:
tristate_button.cpp:250
gui::tristate_button::state_
STATE state_
Definition:
tristate_button.hpp:100
gui::tristate_button::set_item_image
void set_item_image(const texture &base, const texture &over=texture())
Definition:
tristate_button.hpp:59
gui::tristate_button::PRESSED_STATE
PRESSED_STATE
Definition:
tristate_button.hpp:38
gui::tristate_button::NONE
@ NONE
Definition:
tristate_button.hpp:38
gui::tristate_button::BOTH
@ BOTH
Definition:
tristate_button.hpp:38
gui::tristate_button::LEFT
@ LEFT
Definition:
tristate_button.hpp:38
gui::tristate_button::RIGHT
@ RIGHT
Definition:
tristate_button.hpp:38
gui::tristate_button::pressedDownActiveImage_
texture pressedDownActiveImage_
Definition:
tristate_button.hpp:86
gui::tristate_button::itemBaseImage_
texture itemBaseImage_
Definition:
tristate_button.hpp:83
gui::tristate_button::tristate_button
tristate_button(editor::tristate_palette *palette, std::string button_image="", const bool auto_join=true)
Definition:
tristate_button.cpp:32
gui::widget
Definition:
widget.hpp:28
gui::widget::id
const std::string & id() const
Definition:
widget.cpp:198
texture
Wrapper class to encapsulate creation and management of an SDL_Texture.
Definition:
texture.hpp:33
palette
std::vector< color_t > palette(const color_range &cr)
Creates a reference color palette from a color range.
Definition:
color_range.cpp:111
common_palette.hpp
game
Definition:
exceptions.hpp:21
gui
General purpose widgets.
Definition:
tristate_button.cpp:30
exceptions.hpp
game::error
Base class for all the errors encountered by the engine.
Definition:
exceptions.hpp:29
gui::tristate_button::error
Definition:
tristate_button.hpp:32
gui::tristate_button::error::error
error()
Definition:
tristate_button.hpp:33
texture.hpp
Generated by
1.9.1