-
Notifications
You must be signed in to change notification settings - Fork 0
/
sdl_button.h
153 lines (116 loc) · 4.19 KB
/
sdl_button.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#ifndef sdl_button_h
#define sdl_button_h
#include "button.h"
#include "sdl_camera.h"
class SDLTool;
/********************************************************************/
class SDLButtonManager : public ButtonManager {
public:
SDLButtonManager() : ButtonManager() {}
virtual ~SDLButtonManager() {}
virtual void do_render(Camera* camera, double delay_in_ms);
virtual bool handleEvent(Camera* camera) override;
};
/********************************************************************/
class SDLButton : public Button {
public:
enum class TooltipPosition {BOTTOM, RIGHT, OVER};
public:
SDLButton(const std::string& icon_name, int x, int y);
SDLButton(const std::string& icon_name, const std::string& text, int x, int y);
SDLButton(int x, int y);
virtual ~SDLButton();
virtual void activate() override;
virtual void deactivate() override;
void setText(const std::string& text) { text_ = text; }
virtual const std::string& text() const { return text_; }
void setIcon(const std::string& icon_name);
TooltipPosition tooltipPosition() const { return tooltip_position_; }
void setTooltipPosition(TooltipPosition position) { tooltip_position_ = position; }
virtual void setSize(int w, int h) override;
virtual void setPosition(int x,int y) override;
SDL_Texture* getTexture(SDL_Renderer* renderer);
const SDL_Rect& rect() const { return rect_; }
void setTexture(SDL_Texture* texture);
protected:
SDL_Surface* surface_;
SDL_Texture* texture_;
SDL_Rect rect_;
std::string text_;
TooltipPosition tooltip_position_ = TooltipPosition::RIGHT;
};
class SDLCheckBox : public Button {
SDLCheckBox(int x, int y);
virtual ~SDLCheckBox() = default;
virtual void activate() override;
virtual void deactivate() override;
protected:
bool value_;
};
/********************************************************************/
class SDLButtonMenu : public SDLButton {
public:
SDLButtonMenu(MenuButton* menu, std::string name, int x, int y) : SDLButton(name, x,y), menu_(menu) {
tooltip_position_ = TooltipPosition::BOTTOM;
}
virtual ~SDLButtonMenu() {}
virtual void activate() override;
virtual void deactivate() override;
virtual bool checkButtonPressed(bool button_pressed) const override;
private:
MenuButton* menu_;
};
/********************************************************************/
class SDLQuitButton : public SDLButton {
public:
SDLQuitButton(SDLCamera* camera, int x, int y) : SDLButton("buttons/quit.png", tr("Quit"),x,y), camera_(camera) {
tooltip_position_ = TooltipPosition::BOTTOM;
}
virtual ~SDLQuitButton() {}
virtual void activate();
private:
SDLCamera* camera_;
};
/********************************************************************/
class SDLTextButton : public SDLButton {
public:
SDLTextButton(
SDLCamera* camera,
const std::string& text,
int x, int y,
const SDL_Color& color = SDLText::black(),
const SDL_Color& background_color = SDLText::white()
);
virtual ~SDLTextButton() {}
private:
SDLCamera* camera_;
std::string text_;
};
/********************************************************************/
class SDLToolButton : public SDLButton {
public:
SDLToolButton(SDLTool* tool, std::string icon_name, int x, int y);
virtual ~SDLToolButton();
virtual void activate() override;
virtual void deactivate() override;
SDLTool* getTool() const { return tool_; }
private:
SDLTool* tool_;
};
class SDLItemToolButton : public SDLToolButton {
public:
SDLItemToolButton(const BasicItem& item, SDLTool* tool, std::string icon_name, int x, int y);
virtual ~SDLItemToolButton() = default;
virtual const std::string& text() const override;
virtual void activate() override;
protected:
BasicItem item_;
};
class SDLTransformToolButton : public SDLItemToolButton {
public:
SDLTransformToolButton(const BasicItem& item, SDLTool* tool, std::string icon_name, int x, int y);
virtual ~SDLTransformToolButton() = default;
virtual const std::string& text() const override;
};
/********************************************************************/
#endif // sdl_button_h