diff options
| author | Reimar <Reimar@Leike.name> | 2015-12-08 11:31:35 +0100 | 
|---|---|---|
| committer | Reimar <Reimar@Leike.name> | 2015-12-08 11:31:35 +0100 | 
| commit | e3a66514d57ff4acf2f02df7d86bd2cf8be0e730 (patch) | |
| tree | 686eabd8aac2f2eb9d0b3429fe0feee3f031904a /GUI.h | |
| download | RCade-e3a66514d57ff4acf2f02df7d86bd2cf8be0e730.tar RCade-e3a66514d57ff4acf2f02df7d86bd2cf8be0e730.tar.gz RCade-e3a66514d57ff4acf2f02df7d86bd2cf8be0e730.tar.bz2 RCade-e3a66514d57ff4acf2f02df7d86bd2cf8be0e730.tar.xz RCade-e3a66514d57ff4acf2f02df7d86bd2cf8be0e730.zip  | |
initial commit
Diffstat (limited to 'GUI.h')
| -rw-r--r-- | GUI.h | 225 | 
1 files changed, 225 insertions, 0 deletions
| @@ -0,0 +1,225 @@ | |||
| 1 | #ifndef GUI_H | ||
| 2 | #define GUI_H | ||
| 3 | |||
| 4 | #include <SDL/SDL_rotozoom.h> | ||
| 5 | #include "util.h" | ||
| 6 | |||
| 7 | #define BUTTON_CLICKED 0 | ||
| 8 | #define BUTTON_NORMAL 1 | ||
| 9 | #define BUTTON_HOVER 2 | ||
| 10 | #define BUTTON_PRESSEDOVER 3 | ||
| 11 | #define BUTTON_PRESSEDOUT 4 | ||
| 12 | #define BUTTON_SELECTED 5 | ||
| 13 | #define MENU_SELECT 1<<27 | ||
| 14 | #define MENU_CLICK 1<<26 | ||
| 15 | |||
| 16 | |||
| 17 | using namespace std; | ||
| 18 | |||
| 19 | |||
| 20 | class Label | ||
| 21 | { | ||
| 22 | protected: | ||
| 23 | string caption; | ||
| 24 | SDL_Surface* image; | ||
| 25 | // int textSize; | ||
| 26 | SDL_Color textColor; | ||
| 27 | int render(); | ||
| 28 | public: | ||
| 29 | SDL_Rect pos; | ||
| 30 | Label(); | ||
| 31 | Label(string ncaption, SDL_Rect& npos); | ||
| 32 | ~Label(); | ||
| 33 | void draw(SDL_Surface* screen); | ||
| 34 | int setTextSize(int ntextSize); | ||
| 35 | void setTextColor(SDL_Color textColor); | ||
| 36 | int setCaption(string ncaption); | ||
| 37 | }; | ||
| 38 | |||
| 39 | vector<Label*> textField(string s, SDL_Rect& r, int textSize); | ||
| 40 | |||
| 41 | |||
| 42 | class SlidingBackground | ||
| 43 | { | ||
| 44 | protected: | ||
| 45 | SDL_Surface *background; | ||
| 46 | double x1; | ||
| 47 | double x2; | ||
| 48 | double y; | ||
| 49 | public: | ||
| 50 | double xSpeed; | ||
| 51 | double ySpeed; | ||
| 52 | bool randm; | ||
| 53 | |||
| 54 | SlidingBackground(SDL_Surface *nbackground, double nxSpeed, double nySpeed); | ||
| 55 | ~SlidingBackground(); | ||
| 56 | |||
| 57 | void setRandom(bool r); | ||
| 58 | void draw(SDL_Surface *screen); | ||
| 59 | void frame(double time); | ||
| 60 | }; | ||
| 61 | |||
| 62 | class AbstractInteractive | ||
| 63 | { | ||
| 64 | public: | ||
| 65 | virtual ~AbstractInteractive(){} | ||
| 66 | virtual void draw(SDL_Surface *screen) {} | ||
| 67 | virtual int handleEvents(SDL_Event event){return 0;} | ||
| 68 | virtual void frame(double time){} | ||
| 69 | virtual void refresh(){} | ||
| 70 | }; | ||
| 71 | |||
| 72 | class TextBox: public AbstractInteractive | ||
| 73 | { | ||
| 74 | protected: | ||
| 75 | vector<Label*> labels; | ||
| 76 | public: | ||
| 77 | TextBox(vector<Label*> nlabels); | ||
| 78 | ~TextBox(); | ||
| 79 | |||
| 80 | virtual void draw(SDL_Surface *screen); | ||
| 81 | virtual int handleEvents(SDL_Event event); | ||
| 82 | virtual void frame(double time); | ||
| 83 | virtual void refresh(); | ||
| 84 | }; | ||
| 85 | |||
| 86 | class Button: AbstractInteractive | ||
| 87 | { | ||
| 88 | protected: | ||
| 89 | SDL_Surface *normal; | ||
| 90 | SDL_Surface *mouseOver; | ||
| 91 | SDL_Surface *pressed; | ||
| 92 | SDL_Surface *inactive; | ||
| 93 | bool clicked; | ||
| 94 | bool over; | ||
| 95 | public: | ||
| 96 | bool deactivated; | ||
| 97 | bool isDblClckButton; | ||
| 98 | double timer; | ||
| 99 | bool selected; | ||
| 100 | SDL_Rect pos; | ||
| 101 | |||
| 102 | Button(SDL_Rect nPos, SDL_Surface *nnormal, SDL_Surface *nmouseOver, SDL_Surface *npressed, SDL_Surface *ninactive); | ||
| 103 | Button(SDL_Rect npos, string message, int& shouldbeTextSize); | ||
| 104 | //fancybutton & draggable button | ||
| 105 | Button(SDL_Rect npos, SDL_Surface* content, bool fancy); | ||
| 106 | ~Button(); | ||
| 107 | void draw(SDL_Surface *screen); | ||
| 108 | int handleEvents(const SDL_Event& event); | ||
| 109 | void frame(double time); | ||
| 110 | void refresh(); | ||
| 111 | }; | ||
| 112 | |||
| 113 | class Scrollbar | ||
| 114 | { | ||
| 115 | protected: | ||
| 116 | SDL_Surface *bar; | ||
| 117 | SDL_Surface *dot; | ||
| 118 | bool horizontal; | ||
| 119 | bool clicked; | ||
| 120 | double stateGoal; | ||
| 121 | public: | ||
| 122 | double state; | ||
| 123 | double sensitivity; | ||
| 124 | SDL_Rect pos; | ||
| 125 | |||
| 126 | //makes direction according to h/w of the Rect | ||
| 127 | Scrollbar(SDL_Rect npos); | ||
| 128 | ~Scrollbar(); | ||
| 129 | |||
| 130 | void draw(SDL_Surface *screen); | ||
| 131 | double handleEvents(const SDL_Event& event); | ||
| 132 | double frame(double time); | ||
| 133 | void refresh(); | ||
| 134 | }; | ||
| 135 | |||
| 136 | class Scrollable : public AbstractInteractive | ||
| 137 | { | ||
| 138 | protected: | ||
| 139 | int currentSubPos; | ||
| 140 | SDL_Surface* fakeScreen; | ||
| 141 | AbstractInteractive* subInteractive; | ||
| 142 | SDL_Rect pos; | ||
| 143 | SDL_Rect wholeMenu; | ||
| 144 | Scrollbar* bar; | ||
| 145 | bool horizontal; | ||
| 146 | void setSubPosition(double d); | ||
| 147 | SDL_Rect MousePos; | ||
| 148 | public: | ||
| 149 | Scrollable(SDL_Rect npos, AbstractInteractive* nsubInteractive, SDL_Rect subRect, bool nhorizontal, bool nscrollbarSide); | ||
| 150 | ~Scrollable(); | ||
| 151 | void draw(SDL_Surface* screen); | ||
| 152 | int handleEvents(SDL_Event event); | ||
| 153 | void frame(double time); | ||
| 154 | void refresh(); | ||
| 155 | }; | ||
| 156 | |||
| 157 | class Menu : public AbstractInteractive | ||
| 158 | { | ||
| 159 | public: | ||
| 160 | vector<Button*> buttons; | ||
| 161 | vector<int> effects; | ||
| 162 | SlidingBackground *BG; | ||
| 163 | bool isSelectMenu; | ||
| 164 | //wether to send signal on Mouse up or down | ||
| 165 | bool onMouseDown; | ||
| 166 | |||
| 167 | Menu(){ | ||
| 168 | } | ||
| 169 | Menu(vector<Button*> nbuttons, vector<int> neffects, SDL_Surface *background, bool rBG); | ||
| 170 | Menu(vector<string> choices, vector<int> neffects, SDL_Surface *background, bool rBG, SDL_Surface *screen); | ||
| 171 | Menu(vector<SDL_Surface*> pics, int width, int& height, bool nisSelectMenu, bool nonMouseDown); | ||
| 172 | virtual ~Menu(); | ||
| 173 | |||
| 174 | virtual void draw(SDL_Surface *screen); | ||
| 175 | virtual int handleEvents(SDL_Event event); | ||
| 176 | virtual void frame(double time); | ||
| 177 | virtual void refresh(); | ||
| 178 | }; | ||
| 179 | |||
| 180 | |||
| 181 | |||
| 182 | class CompositMenu: public AbstractInteractive | ||
| 183 | { | ||
| 184 | protected: | ||
| 185 | vector<Button*> tabs; | ||
| 186 | int state; | ||
| 187 | SDL_Surface* fakeScreen; | ||
| 188 | SDL_Rect subPos; | ||
| 189 | public: | ||
| 190 | vector<AbstractInteractive*> submenues; | ||
| 191 | SlidingBackground* BG; | ||
| 192 | CompositMenu(vector<AbstractInteractive*> nsubmenues, SDL_Surface* nBG, SDL_Rect nsubPos, vector<Button*> ntabs); | ||
| 193 | ~CompositMenu(); | ||
| 194 | |||
| 195 | virtual void draw(SDL_Surface *screen); | ||
| 196 | virtual int handleEvents(SDL_Event event); | ||
| 197 | virtual void frame(double time); | ||
| 198 | virtual void refresh(); | ||
| 199 | int getState(); | ||
| 200 | }; | ||
| 201 | |||
| 202 | class GetStringMenu: public AbstractInteractive | ||
| 203 | { | ||
| 204 | protected: | ||
| 205 | Label* title; | ||
| 206 | Label* input; | ||
| 207 | Button* back; | ||
| 208 | Button* oK; | ||
| 209 | int iBack; | ||
| 210 | int iOK; | ||
| 211 | int screenw; | ||
| 212 | public: | ||
| 213 | SlidingBackground* BG; | ||
| 214 | string s; | ||
| 215 | int maxLength; | ||
| 216 | GetStringMenu(string headline, int back, int ok, SDL_Surface* nBG, SDL_Surface* screen); | ||
| 217 | ~GetStringMenu(); | ||
| 218 | |||
| 219 | virtual void draw(SDL_Surface* screen); | ||
| 220 | virtual int handleEvents(SDL_Event event); | ||
| 221 | virtual void frame(double time); | ||
| 222 | virtual void refresh(); | ||
| 223 | }; | ||
| 224 | |||
| 225 | #endif | ||
