From 4775ffa253110d66338030db8633463195e81615 Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=B4me=20Chilliet?= Date: Sat, 10 Dec 2016 14:08:25 +0700 Subject: [PATCH] Changed namespace Menu for a class --- Source/Menu.cpp | 48 +++------------------------------ Source/Menu.h | 72 +++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 61 insertions(+), 59 deletions(-) diff --git a/Source/Menu.cpp b/Source/Menu.cpp index f3d9e0b..49b4732 100644 --- a/Source/Menu.cpp +++ b/Source/Menu.cpp @@ -23,52 +23,10 @@ along with Lugaru. If not, see . #include "gamegl.h" #include "Menu.h" -using namespace Menu; extern float multiplier; -struct MenuItem { - enum MenuItemType {NONE, LABEL, BUTTON, IMAGE, IMAGEBUTTON, MAPMARKER, MAPLINE, MAPLABEL} type; - int id; - string text; - Texture texture; - int x, y, w, h; - float r, g, b; - float effectfade; - - float linestartsize; - float lineendsize; - - void init(MenuItemType _type, int _id, const string& _text, Texture _texture, - int _x, int _y, int _w, int _h, float _r, float _g, float _b, - float _linestartsize = 1, float _lineendsize = 1) { - type = _type; - id = _id; - text = _text; - texture = _texture; - x = _x; - y = _y; - w = _w; - h = _h; - r = _r; - g = _g; - b = _b; - effectfade = 0; - linestartsize = _linestartsize; - lineendsize = _lineendsize; - if (type == MenuItem::BUTTON) { - if (w == -1) - w = text.length() * 10; - if (h == -1) - h = 20; - } - } -}; - -vector items; - - - +std::vector Menu::items; void Menu::clearMenu() { @@ -152,7 +110,7 @@ int Menu::getSelected(int mousex, int mousey) return -1; } -void GUITick() +void Menu::handleFadeEffect() { for (vector::iterator it = items.begin(); it != items.end(); it++) { if (it->id == Game::selected) { @@ -169,7 +127,7 @@ void GUITick() void Menu::drawItems() { - GUITick(); + handleFadeEffect(); glEnable(GL_TEXTURE_2D); glEnable(GL_ALPHA_TEST); glEnable(GL_BLEND); diff --git a/Source/Menu.h b/Source/Menu.h index 4c6878b..a1fc295 100644 --- a/Source/Menu.h +++ b/Source/Menu.h @@ -23,20 +23,64 @@ along with Lugaru. If not, see . #include "Game.h" -namespace Menu +struct MenuItem { + enum MenuItemType {NONE, LABEL, BUTTON, IMAGE, IMAGEBUTTON, MAPMARKER, MAPLINE, MAPLABEL} type; + int id; + string text; + Texture texture; + int x, y, w, h; + float r, g, b; + float effectfade; + + float linestartsize; + float lineendsize; + + void init(MenuItemType _type, int _id, const string& _text, Texture _texture, + int _x, int _y, int _w, int _h, float _r, float _g, float _b, + float _linestartsize = 1, float _lineendsize = 1) { + type = _type; + id = _id; + text = _text; + texture = _texture; + x = _x; + y = _y; + w = _w; + h = _h; + r = _r; + g = _g; + b = _b; + effectfade = 0; + linestartsize = _linestartsize; + lineendsize = _lineendsize; + if (type == MenuItem::BUTTON) { + if (w == -1) + w = text.length() * 10; + if (h == -1) + h = 20; + } + } +}; + +class Menu { -void clearMenu(); -void addLabel(int id, const string& text, int x, int y, float r = 1, float g = 0, float b = 0); -void addButton(int id, const string& text, int x, int y, float r = 1, float g = 0, float b = 0); -void addImage(int id, Texture texture, int x, int y, int w, int h, float r = 1, float g = 1, float b = 1); -void addButtonImage(int id, Texture texture, int x, int y, int w, int h, float r = 1, float g = 1, float b = 1); -void addMapLine(int x, int y, int w, int h, float startsize, float endsize, float r, float g, float b); -void addMapMarker(int id, Texture texture, int x, int y, int w, int h, float r, float g, float b); -void addMapLabel(int id, const string& text, int x, int y, float r = 1, float g = 0, float b = 0); -void setText(int id, const string& text); -void setText(int id, const string& text, int x, int y, int w, int h); -int getSelected(int mousex, int mousey); -void drawItems(); -} +public: + static void clearMenu(); + static void addLabel(int id, const string& text, int x, int y, float r = 1, float g = 0, float b = 0); + static void addButton(int id, const string& text, int x, int y, float r = 1, float g = 0, float b = 0); + static void addImage(int id, Texture texture, int x, int y, int w, int h, float r = 1, float g = 1, float b = 1); + static void addButtonImage(int id, Texture texture, int x, int y, int w, int h, float r = 1, float g = 1, float b = 1); + static void addMapLine(int x, int y, int w, int h, float startsize, float endsize, float r, float g, float b); + static void addMapMarker(int id, Texture texture, int x, int y, int w, int h, float r, float g, float b); + static void addMapLabel(int id, const string& text, int x, int y, float r = 1, float g = 0, float b = 0); + static void setText(int id, const string& text); + static void setText(int id, const string& text, int x, int y, int w, int h); + static int getSelected(int mousex, int mousey); + static void drawItems(); + +private: + static void handleFadeEffect(); + + static std::vector items; +}; #endif -- 2.39.2