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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
#ifndef GUI_H
#define GUI_H
#include <SDL/SDL_rotozoom.h>
#include "util.h"
#define BUTTON_CLICKED 0
#define BUTTON_NORMAL 1
#define BUTTON_HOVER 2
#define BUTTON_PRESSEDOVER 3
#define BUTTON_PRESSEDOUT 4
#define BUTTON_SELECTED 5
#define MENU_SELECT 1<<27
#define MENU_CLICK 1<<26
using namespace std;
class Label
{
protected:
string caption;
SDL_Surface* image;
// int textSize;
SDL_Color textColor;
int render();
public:
SDL_Rect pos;
Label();
Label(string ncaption, SDL_Rect& npos);
~Label();
void draw(SDL_Surface* screen);
int setTextSize(int ntextSize);
void setTextColor(SDL_Color textColor);
int setCaption(string ncaption);
};
vector<Label*> textField(string s, SDL_Rect& r, int textSize);
class SlidingBackground
{
protected:
SDL_Surface *background;
double x1;
double x2;
double y;
public:
double xSpeed;
double ySpeed;
bool randm;
SlidingBackground(SDL_Surface *nbackground, double nxSpeed, double nySpeed);
~SlidingBackground();
void setRandom(bool r);
void draw(SDL_Surface *screen);
void frame(double time);
};
class AbstractInteractive
{
public:
virtual ~AbstractInteractive(){}
virtual void draw(SDL_Surface *screen) {}
virtual int handleEvents(SDL_Event event){return 0;}
virtual void frame(double time){}
virtual void refresh(){}
};
class TextBox: public AbstractInteractive
{
protected:
vector<Label*> labels;
public:
TextBox(vector<Label*> nlabels);
~TextBox();
virtual void draw(SDL_Surface *screen);
virtual int handleEvents(SDL_Event event);
virtual void frame(double time);
virtual void refresh();
};
class Button: AbstractInteractive
{
protected:
SDL_Surface *normal;
SDL_Surface *mouseOver;
SDL_Surface *pressed;
SDL_Surface *inactive;
bool clicked;
bool over;
public:
bool deactivated;
bool isDblClckButton;
double timer;
bool selected;
SDL_Rect pos;
Button(SDL_Rect nPos, SDL_Surface *nnormal, SDL_Surface *nmouseOver, SDL_Surface *npressed, SDL_Surface *ninactive);
Button(SDL_Rect npos, string message, int& shouldbeTextSize);
//fancybutton & draggable button
Button(SDL_Rect npos, SDL_Surface* content, bool fancy);
~Button();
void draw(SDL_Surface *screen);
int handleEvents(const SDL_Event& event);
void frame(double time);
void refresh();
};
class Scrollbar
{
protected:
SDL_Surface *bar;
SDL_Surface *dot;
bool horizontal;
bool clicked;
double stateGoal;
public:
double state;
double sensitivity;
SDL_Rect pos;
//makes direction according to h/w of the Rect
Scrollbar(SDL_Rect npos);
~Scrollbar();
void draw(SDL_Surface *screen);
double handleEvents(const SDL_Event& event);
double frame(double time);
void refresh();
};
class Scrollable : public AbstractInteractive
{
protected:
int currentSubPos;
SDL_Surface* fakeScreen;
AbstractInteractive* subInteractive;
SDL_Rect pos;
SDL_Rect wholeMenu;
Scrollbar* bar;
bool horizontal;
void setSubPosition(double d);
SDL_Rect MousePos;
public:
Scrollable(SDL_Rect npos, AbstractInteractive* nsubInteractive, SDL_Rect subRect, bool nhorizontal, bool nscrollbarSide);
~Scrollable();
void draw(SDL_Surface* screen);
int handleEvents(SDL_Event event);
void frame(double time);
void refresh();
};
class Menu : public AbstractInteractive
{
public:
vector<Button*> buttons;
vector<int> effects;
SlidingBackground *BG;
bool isSelectMenu;
//wether to send signal on Mouse up or down
bool onMouseDown;
Menu(){
}
Menu(vector<Button*> nbuttons, vector<int> neffects, SDL_Surface *background, bool rBG);
Menu(vector<string> choices, vector<int> neffects, SDL_Surface *background, bool rBG, SDL_Surface *screen);
Menu(vector<SDL_Surface*> pics, int width, int& height, bool nisSelectMenu, bool nonMouseDown);
virtual ~Menu();
virtual void draw(SDL_Surface *screen);
virtual int handleEvents(SDL_Event event);
virtual void frame(double time);
virtual void refresh();
};
class CompositMenu: public AbstractInteractive
{
protected:
vector<Button*> tabs;
int state;
SDL_Surface* fakeScreen;
SDL_Rect subPos;
public:
vector<AbstractInteractive*> submenues;
SlidingBackground* BG;
CompositMenu(vector<AbstractInteractive*> nsubmenues, SDL_Surface* nBG, SDL_Rect nsubPos, vector<Button*> ntabs);
~CompositMenu();
virtual void draw(SDL_Surface *screen);
virtual int handleEvents(SDL_Event event);
virtual void frame(double time);
virtual void refresh();
int getState();
};
class GetStringMenu: public AbstractInteractive
{
protected:
Label* title;
Label* input;
Button* back;
Button* oK;
int iBack;
int iOK;
int screenw;
public:
SlidingBackground* BG;
string s;
int maxLength;
GetStringMenu(string headline, int back, int ok, SDL_Surface* nBG, SDL_Surface* screen);
~GetStringMenu();
virtual void draw(SDL_Surface* screen);
virtual int handleEvents(SDL_Event event);
virtual void frame(double time);
virtual void refresh();
};
#endif
|