From 03130c5bcec3c885a1be005c24e192dfb57f3fe5 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Tue, 12 Apr 2016 18:48:49 -0400 Subject: moved menu stuff to own file --- include/ui.hpp | 58 ++++++------------------------------------------ include/ui_menu.hpp | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 51 deletions(-) create mode 100644 include/ui_menu.hpp (limited to 'include') diff --git a/include/ui.hpp b/include/ui.hpp index a9a7f05..6fa2451 100644 --- a/include/ui.hpp +++ b/include/ui.hpp @@ -11,54 +11,16 @@ #include #include +#include + #include #include #include #include FT_FREETYPE_H -#define DEBUG +#define SDL_KEY e.key.keysym.sym -typedef void(*menuFunc)(); - -struct menuItem{ - int member; - union{ - struct{ - vec2 loc; - dim2 dim; - Color color; - const char* text; - menuFunc func; - }button; - struct{ - vec2 loc; - dim2 dim; - Color color; - float minValue; - float maxValue; - const char* text; - float* var; - - float sliderLoc; - }slider; - }; -}; - -class Menu{ -public: - std::vectoritems; - Menu *child; - Menu *parent; - ~Menu(){ - child = NULL; - parent = NULL; - delete child; - delete parent; - } - - void gotoChild(); - void gotoParent(); -}; +#define DEBUG typedef uint8_t BYTE; typedef uint16_t WORD; @@ -87,15 +49,13 @@ typedef struct{ } __attribute__ ((packed)) BITMAPINFOHEADER; namespace ui { - menuItem createButton(vec2 l, dim2 d, Color c, const char* t, menuFunc f); - menuItem createChildButton(vec2 l, dim2 d, Color c, const char* t); - menuItem createParentButton(vec2 l, dim2 d, Color c, const char* t); - menuItem createSlider(vec2 l, dim2 d, Color c, float min, float max, const char* t, float* v); + /** * Contains the coordinates of the mouse inside the window. */ extern vec2 mouse; + extern vec2 premouse; /* * These flags are used elsewhere. @@ -172,12 +132,8 @@ namespace ui { void draw(void); - - /* - * Draw various menu items - */ void quitGame(); - void drawMenu(Menu* menu); + /* diff --git a/include/ui_menu.hpp b/include/ui_menu.hpp new file mode 100644 index 0000000..9a51739 --- /dev/null +++ b/include/ui_menu.hpp @@ -0,0 +1,63 @@ +#ifndef UI_MENU_H_ +#define UI_MENU_H_ + +#include +#include + +typedef void (*menuFunc)(void); + +struct menuItem { + int member; + union { + struct { + vec2 loc; + dim2 dim; + Color color; + + const char *text; + menuFunc func; + } button; + struct { + vec2 loc; + dim2 dim; + Color color; + + float minValue; + float maxValue; + float sliderLoc; + + const char *text; + float *var; + } slider; + }; +}; + +class Menu { +public: + std::vector items; + Menu *child, *parent; + + ~Menu() { + // TODO you CANNOT delete null pointers! + /*child = NULL; + parent = NULL; + delete child; + delete parent;*/ + } + + void gotoChild(void); + void gotoParent(void); +}; + +namespace ui { + namespace menu { + menuItem createButton(vec2 l, dim2 d, Color c, const char* t, menuFunc f); + menuItem createChildButton(vec2 l, dim2 d, Color c, const char* t); + menuItem createParentButton(vec2 l, dim2 d, Color c, const char* t); + menuItem createSlider(vec2 l, dim2 d, Color c, float min, float max, const char* t, float* v); + + void draw( void ); + } +} + +#endif // UI_MENU_H_ -- cgit v1.2.3