Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Class: GUI_Engine
- Purpose: -To provide a singleton class that will see over the entire GUI system.
- -To handle input and invoke the event-checking functions of the frames/elements
- -To load/unload GUI skins and to load more than one.
- -To
- */
- #ifndef GUI_ENGINE_H
- #define GUI_ENGINE_H
- #include "globalvar.h"
- #include "SpritePool.h"
- #include "GUI_Window.h"
- #include "GUI_Button.h"
- #include "GUI_Textbox.h"
- #include <sol.hpp>
- class GUI_Engine
- {
- public:
- GUI_Engine();
- virtual ~GUI_Engine();
- void Init();
- void Cleanup();
- //Load GUI skin
- void load_gui_skin(std::string dirname);
- void clear_window_list();
- void push_window(GUI_Window* window);
- void add_window(SpritePool gui_skin, int x, int y, int w, int h, bool visible, std::string str);
- void add_button(SpritePool gui_skin, int x, int y, int w, int h, bool visible, std::string str, std::string parent_name);
- void add_textbox(SpritePool gui_skin, int x, int y, int w, int h, bool visible, std::string str, std::string parent_name, std::string def_text);
- GUI_Window* get_window(std::string name);
- SpritePool get_gui_skin() {return gui_skin;}
- void render_gui();
- void update_gui();
- void check_input(Input &input);
- private:
- std::vector<GUI_Window*> window_list;
- //current_script describes the current *.lua file that is being used for the GUI
- std::string current_script;
- sol::state lua;
- SpritePool gui_skin;
- };
- #endif // GUI_ENGINE_H
- #include "GUI_Engine.h"
- GUI_Engine::GUI_Engine()
- {
- }
- GUI_Engine::~GUI_Engine()
- {
- //dtor
- }
- void GUI_Engine::Init()
- {
- load_gui_skin("default");
- lua.set_function("load_gui_skin", &GUI_Engine::load_gui_skin, this);
- lua.set_function("clear_window_list", &GUI_Engine::clear_window_list, this);
- lua.set_function("push_window", &GUI_Engine::push_window, this);
- // lua.set_function("add_window", &GUI_Engine::add_window, this);
- // lua.set_function("add_button", &GUI_Engine::add_button, this);
- // lua.set_function("add_textbox", &GUI_Engine::add_textbox, this);
- lua.set_function("get_window", &GUI_Engine::get_window, this);
- lua.set_function("get_gui_skin", &GUI_Engine::get_gui_skin, this);
- }
- void GUI_Engine::Cleanup()
- {
- gui_skin.unload_all_texture();
- }
- void GUI_Engine::load_gui_skin(std::string dir)
- {
- std::string path = "resources/graphics/gui/skins/";
- path = path + dir + "/";
- gui_skin.load_texture("for some reason the first two textures don't load");
- gui_skin.load_texture("hi some reason the first two textures don't load");
- gui_skin.load_texture(path + "window_left.png");
- gui_skin.load_texture(path + "window_right.png");
- gui_skin.load_texture(path + "window_topleft.png");
- gui_skin.load_texture(path + "window_topright.png");
- gui_skin.load_texture(path + "window_bottomleft.png");
- gui_skin.load_texture(path + "window_bottomright.png");
- gui_skin.load_texture(path + "window_minimize.png");
- gui_skin.load_texture(path + "window_pin.png");
- gui_skin.load_texture(path + "window_exit.png");
- gui_skin.load_texture(path + "gui_bg.png");
- gui_skin.load_texture(path + "button_rectnormal.png");
- gui_skin.load_texture(path + "button_recthot.png");
- gui_skin.load_texture(path + "button_rectactivated.png");
- gui_skin.load_texture(path + "button_rectlongnormal.png");
- gui_skin.load_texture(path + "button_rectlonghot.png");
- gui_skin.load_texture(path + "button_rectlongactivated.png");
- gui_skin.load_texture(path + "button_squarenormal.png");
- gui_skin.load_texture(path + "button_squarehot.png");
- gui_skin.load_texture(path + "button_squareactivated.png");
- gui_skin.load_texture(path + "checkbox_normal.png");
- gui_skin.load_texture(path + "checkbox_selected.png");
- gui_skin.load_texture(path + "menu_dropdown.png");
- gui_skin.load_texture(path + "menu_member.png");
- gui_skin.load_texture(path + "window_top.png");
- gui_skin.load_texture(path + "window_bottom.png");
- }
- void GUI_Engine::clear_window_list()
- {
- for (unsigned int i = 0; i < window_list.size(); i++)
- {
- window_list.erase(window_list.begin() + (i));
- }
- }
- void GUI_Engine::push_window(GUI_Window* window)
- {
- if (window != NULL)
- {
- window_list.push_back(window);
- }
- }
- void GUI_Engine::add_window(SpritePool gui_skin, int x, int y, int w, int h, bool visible, std::string name)
- {
- GUI_Window* window = new GUI_Window(gui_skin, x, y, w, h, visible, name);
- this->push_window(window);
- }
- void GUI_Engine::add_button(SpritePool gui_skin, int x, int y, int w, int h, bool visible, std::string str, std::string parent_name)
- {
- GUI_Window* parent_window = get_window(parent_name);
- GUI_Element* parent = parent_window;
- GUI_Button* button = new GUI_Button(gui_skin, x, y, w, h, visible, str, parent);
- parent_window->add_element(button);
- }
- void GUI_Engine::add_textbox(SpritePool gui_skin, int x, int y, int w, int h, bool visible, std::string str, std::string parent_name, std::string def_text)
- {
- GUI_Window* parent_window = get_window(parent_name);
- GUI_Element* parent = parent_window;
- GUI_Textbox* textbox = new GUI_Textbox(gui_skin, x, y, w, h, visible, str, parent, def_text);
- parent_window->add_element(textbox);
- }
- GUI_Window* GUI_Engine::get_window(std::string name)
- {
- GUI_Window* window_ptr = NULL;
- for (unsigned int i = 0; i < window_list.size(); i++)
- {
- if (window_list[i]->get_name() == name)
- window_ptr = window_list[i];
- }
- return window_ptr;
- }
- void GUI_Engine::render_gui()
- {
- for (unsigned int i = 0; i < window_list.size(); i++)
- {
- window_list[i]->render();
- }
- }
- void GUI_Engine::update_gui()
- {
- for (unsigned int i = 0; i < window_list.size(); i++)
- {
- window_list[i]->update();
- }
- }
- void GUI_Engine::check_input(Input &input)
- {
- for (unsigned int i = 0; i < window_list.size(); i++)
- {
- window_list[i]->check(input);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement