-
Notifications
You must be signed in to change notification settings - Fork 0
/
GUI.h
139 lines (98 loc) · 2.77 KB
/
GUI.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
#ifndef _GUI_H
#define _GUI_H
#include "GFX.h"
// Assign human-readable names to some common 16-bit color values:
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
namespace GUI {
void InitGFX(GFX *gfx);
GFX *getGFX();
class Scale {
private:
float a;
float b;
public:
Scale(float x1, float y1, float x2, float y2);
float convert(float x);
};
////////////////////////////////////////////
// messages
// base message
class Message {
public:
Message(uint8_t _msg, void *_sender);
uint8_t msg;
void *sender;
};
// touch message
#define TOUCH_MSG 1
class TouchMessage : public Message {
public:
TouchMessage(void *_sender, uint16_t _x, uint16_t _y);
uint16_t x;
uint16_t y;
};
#define TIMER_MSG 2
class TimerMessage : public Message {
public:
TimerMessage(long _ticks);
long ticks;
};
///////////////////////////////////////////////////
// Widget
struct Rect {
public:
uint16_t x;
uint16_t y;
uint16_t width;
uint16_t height;
// Rect(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height);
};
bool rect_intersect(const Rect *another);
bool rect_contains(const Rect *,uint16_t x,uint16_t y);
////////////////////////////////////////////////////////////////////////////////////
// Components
class BaseUI {
public:
// dispatch the message and return if the message is consumed
virtual bool dispatchMessage(Message *msg) = 0;
// send a new message
virtual void sendMessage(Message *msg) = 0;
};
// every widget has a dispatchMessage
class BaseWidget : public BaseUI {
public:
BaseWidget(BaseUI *_parent);
// startup phase
virtual void startup() = 0;
// draw the button
virtual void draw() = 0;
// dispatch the message and return if the message is consumed
virtual bool dispatchMessage(Message *msg) = 0;
virtual void sendMessage(Message *msg);
protected:
// every widgets has a parent, for dispatching
BaseUI *parent;
};
#define BUTTON_PRESSED 10
// wrapper
class Button : public BaseWidget {
public:
Button(BaseUI *_parent,const GUI::Rect *_r,char *_str, uint8_t _text_size);
virtual void startup();
virtual void draw();
virtual bool dispatchMessage(Message *msg);
private:
const GUI::Rect *rect;
uint8_t text_size;
char *str;
void _draw(bool inverted = false);
};
}
#endif