#ifndef GUI_H #define GUI_H #include #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 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 labels; public: TextBox(vector 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 buttons; vector effects; SlidingBackground *BG; bool isSelectMenu; //wether to send signal on Mouse up or down bool onMouseDown; Menu(){ } Menu(vector nbuttons, vector neffects, SDL_Surface *background, bool rBG); Menu(vector choices, vector neffects, SDL_Surface *background, bool rBG, SDL_Surface *screen); Menu(vector 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 tabs; int state; SDL_Surface* fakeScreen; SDL_Rect subPos; public: vector submenues; SlidingBackground* BG; CompositMenu(vector nsubmenues, SDL_Surface* nBG, SDL_Rect nsubPos, vector 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