-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbutton.h
More file actions
107 lines (80 loc) · 2.65 KB
/
button.h
File metadata and controls
107 lines (80 loc) · 2.65 KB
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
#ifndef button_h
#define button_h
#include "camera.h"
#include <list>
#include <map>
class Camera;
/********************************************************************/
class Button {
public:
Button(std::string button_name, int x,int y, int w=32, int h=32);
virtual ~Button() {}
bool isActive() { return active_; }
virtual void activate() { active_ = true; }
virtual void deactivate() { active_ = false; }
virtual bool checkButtonPressed(bool /*button_pressed*/) const { return true; }
bool isVisible() const { return visible_; }
void setVisible(bool value) { visible_ = value; }
bool mouseOverButton(int mouse_x, int mouse_y) const;
void hasFocus(bool value) { focus_ = value; }
bool hasFocus() const { return focus_; }
virtual void setSize(int w, int h) { w_ = w; h_ = h; }
virtual void setPosition(int x,int y) { x_ = x; y_ = y; }
int x() const { return x_; }
int y() const { return y_; }
int w() const { return w_; }
int h() const { return h_; }
const std::string& buttonName() const { return button_name_; }
void setButtonName(const std::string& name) { button_name_ = name; }
private:
bool active_;
bool visible_;
bool focus_;
std::string button_name_;
int x_; // position x
int y_; // position y
int w_; // width
int h_; // height
};
/********************************************************************/
class MenuButton {
public:
MenuButton(int max_column, int x, int y);
virtual ~MenuButton() {}
bool isVisible() const { return visible_; }
void show();
void hide();
void addButton(Button* button);
int x() { return x_; }
int y() { return y_; }
int width() { return width_; }
int height() { return height_; }
protected:
void resetButtons();
private:
int max_column_;
int x_;
int y_;
bool visible_;
std::list<Button*> buttons_;
int width_;
int height_;
};
/********************************************************************/
typedef void (*PtrFunc)();
class ButtonManager : public View {
public:
ButtonManager() {}
virtual ~ButtonManager() {}
void addButton(Button* button) { buttons_.push_back(button); }
void removeButton(Button* button) { buttons_.remove(button); }
void connectButton(Button* button, void(&f)());
void addMenuButton(MenuButton* menu) { menus_.push_back(menu); }
void removeMenuButton(MenuButton* menu) { menus_.remove(menu); }
protected:
std::list<Button*> buttons_;
std::list<MenuButton*> menus_;
std::map<Button*,PtrFunc> connections_;
};
/********************************************************************/
#endif // button_h