diff --git a/include/igui.h b/include/igui.h index 7d05e3c9ac..794244c1ea 100644 --- a/include/igui.h +++ b/include/igui.h @@ -3,12 +3,120 @@ #include #include #include "imodule.h" +#include "math/Vector4.h" +#include "ishaders.h" namespace gui { -class GuiWindowDef; -typedef std::shared_ptr GuiWindowDefPtr; +class IGui; +class RenderableText; + +class IGuiWindowDef; +typedef std::shared_ptr IGuiWindowDefPtr; + +class IGuiWindowDef +{ +public: + // Public properties + + // The name of this windowDef + std::string name; + + // Window size (x,y,width,height) + Vector4 rect; + + // Visible or hidden + bool visible; + + // Whether this gui is full screen (use on desktop window) + bool menugui; + + Vector4 forecolor; + Vector4 hovercolor; + Vector4 backcolor; + Vector4 bordercolor; + Vector4 matcolor; + + float rotate; + + // background shader name + std::string background; + + // background shader (NULL until realised) + MaterialPtr backgroundShader; + + // The name of the font + std::string font; + + // The scale for rendering the font + float textscale; + + // The text alignment (left, right, center) + int textalign; + + // Text offsets + float textalignx; + float textaligny; + + // Force a specific aspect ratio + float forceaspectwidth; + float forceaspectheight; + + // No mouse events for this window + bool noevents; + + // Whether this window forces text to wrap at their borders + bool noclip; + + // Whether time is running for this windowDef + bool notime; + + // Don't display the cursor + bool nocursor; + + // Don't wrap words at rectangle borders + bool nowrap; + + // The window time (0..infinity) + std::size_t time; + + // All child windowDefs of this window + typedef std::vector ChildWindows; + ChildWindows children; + +public: + virtual ~IGuiWindowDef() {} + + // Returns the owning GUI + virtual IGui& getGui() const = 0; + + virtual void addWindow(const IGuiWindowDefPtr& window) = 0; + + // Recursively looks for a named child windowDef + // Returns NULL if not found + virtual IGuiWindowDefPtr findWindowDef(const std::string& name) = 0; + + virtual const std::string& getText() const = 0; + virtual void setText(const std::string& newText) = 0; + + // Get the renderable text object containing the OpenGLRenderables + virtual RenderableText& getRenderableText() = 0; + + /** + * greebo: This is some sort of "think" method, giving this windowDef + * a chance to handle timed events. + * + * @updateChildren: recursively updates child windowDef if true + */ + virtual void update(const std::size_t timeStep, bool updateChildren = true) = 0; + + // Initialises the time of this windowDef and all children + virtual void initTime(const std::size_t time, bool updateChildren = true) = 0; + + // Prepares renderable objects, to be called by the parent Gui only + virtual void pepareRendering(bool prepareChildren = true) = 0; +}; /** * greebo: This class represents a single D3 GUI. It holds all @@ -19,8 +127,8 @@ class IGui public: virtual ~IGui() {} - virtual const GuiWindowDefPtr& getDesktop() const = 0; - virtual void setDesktop(const GuiWindowDefPtr& newDesktop) = 0; + virtual const IGuiWindowDefPtr& getDesktop() const = 0; + virtual void setDesktop(const IGuiWindowDefPtr& newDesktop) = 0; // Sets the given state variable (gui:: = ) virtual void setStateString(const std::string& key, const std::string& value) = 0; @@ -35,7 +143,7 @@ class IGui virtual void update(const std::size_t timestep) = 0; // Returns a reference to the named windowDef, returns NULL if not found - virtual GuiWindowDefPtr findWindowDef(const std::string& name) = 0; + virtual IGuiWindowDefPtr findWindowDef(const std::string& name) = 0; // Called by the GuiRenderer to re-compile text VBOs, etc. virtual void pepareRendering() = 0; diff --git a/plugins/dm.gui/ReadableGuiView.cpp b/plugins/dm.gui/ReadableGuiView.cpp index 523d92341c..29544ce48c 100644 --- a/plugins/dm.gui/ReadableGuiView.cpp +++ b/plugins/dm.gui/ReadableGuiView.cpp @@ -41,7 +41,7 @@ void ReadableGuiView::setGui(const IGuiPtr& gui) if (_gui != NULL) { - GuiWindowDefPtr bgWindowDef = _gui->findWindowDef("backgroundImage"); + IGuiWindowDefPtr bgWindowDef = _gui->findWindowDef("backgroundImage"); if (!bgWindowDef) { bgWindowDef = _gui->findWindowDef("backgroundmulti"); diff --git a/plugins/dm.gui/gui/Gui.cpp b/plugins/dm.gui/gui/Gui.cpp index bbe2ee61b1..99754bb79f 100644 --- a/plugins/dm.gui/gui/Gui.cpp +++ b/plugins/dm.gui/gui/Gui.cpp @@ -4,16 +4,12 @@ namespace gui { -Gui::Gui() -{ -} - -const GuiWindowDefPtr& Gui::getDesktop() const +const IGuiWindowDefPtr& Gui::getDesktop() const { return _desktop; } -void Gui::setDesktop(const GuiWindowDefPtr& newDesktop) +void Gui::setDesktop(const IGuiWindowDefPtr& newDesktop) { _desktop = newDesktop; } @@ -76,7 +72,7 @@ void Gui::update(const std::size_t timestep) } } -GuiWindowDefPtr Gui::findWindowDef(const std::string& name) +IGuiWindowDefPtr Gui::findWindowDef(const std::string& name) { // Handle "Desktop" right here if (name == "Desktop") @@ -84,7 +80,7 @@ GuiWindowDefPtr Gui::findWindowDef(const std::string& name) return _desktop; } - return (_desktop != NULL) ? _desktop->findWindowDef(name) : GuiWindowDefPtr(); + return (_desktop != NULL) ? _desktop->findWindowDef(name) : IGuiWindowDefPtr(); } void Gui::pepareRendering() diff --git a/plugins/dm.gui/gui/Gui.h b/plugins/dm.gui/gui/Gui.h index 5918d6e2ca..7fafe0adff 100644 --- a/plugins/dm.gui/gui/Gui.h +++ b/plugins/dm.gui/gui/Gui.h @@ -25,17 +25,15 @@ class Gui : { private: // The desktop window - GuiWindowDefPtr _desktop; + IGuiWindowDefPtr _desktop; // The global GUI state variables typedef std::map GuiState; GuiState _state; public: - Gui(); - - const GuiWindowDefPtr& getDesktop() const override; - void setDesktop(const GuiWindowDefPtr& newDesktop) override; + const IGuiWindowDefPtr& getDesktop() const override; + void setDesktop(const IGuiWindowDefPtr& newDesktop) override; // Sets the given state variable (gui:: = ) void setStateString(const std::string& key, const std::string& value) override; @@ -50,7 +48,7 @@ class Gui : void update(const std::size_t timestep) override; // Returns a reference to the named windowDef, returns NULL if not found - GuiWindowDefPtr findWindowDef(const std::string& name) override; + IGuiWindowDefPtr findWindowDef(const std::string& name) override; // Called by the GuiRenderer to re-compile text VBOs, etc. void pepareRendering() override; diff --git a/plugins/dm.gui/gui/GuiRenderer.cpp b/plugins/dm.gui/gui/GuiRenderer.cpp index 43ceab4bf3..a9a61a4bc1 100644 --- a/plugins/dm.gui/gui/GuiRenderer.cpp +++ b/plugins/dm.gui/gui/GuiRenderer.cpp @@ -63,7 +63,7 @@ void GuiRenderer::render() glDisable(GL_BLEND); } -void GuiRenderer::render(const GuiWindowDefPtr& window) +void GuiRenderer::render(const IGuiWindowDefPtr& window) { if (window == NULL) return; diff --git a/plugins/dm.gui/gui/GuiRenderer.h b/plugins/dm.gui/gui/GuiRenderer.h index c5ba502ce4..342de709c9 100644 --- a/plugins/dm.gui/gui/GuiRenderer.h +++ b/plugins/dm.gui/gui/GuiRenderer.h @@ -37,7 +37,7 @@ class GuiRenderer : void render(); private: - void render(const GuiWindowDefPtr& window); + void render(const IGuiWindowDefPtr& window); }; } diff --git a/plugins/dm.gui/gui/GuiScript.cpp b/plugins/dm.gui/gui/GuiScript.cpp index 4d212ad46d..97a608d2cd 100644 --- a/plugins/dm.gui/gui/GuiScript.cpp +++ b/plugins/dm.gui/gui/GuiScript.cpp @@ -377,7 +377,7 @@ VariablePtr GuiScript::getVariableFromExpression(const std::string& expr) std::string windowDefName = expr.substr(0, ddPos); // Look up the windowDef - GuiWindowDefPtr windowDef = _owner.getGui().findWindowDef(windowDefName); + IGuiWindowDefPtr windowDef = _owner.getGui().findWindowDef(windowDefName); if (windowDef != NULL) { diff --git a/plugins/dm.gui/gui/GuiWindowDef.cpp b/plugins/dm.gui/gui/GuiWindowDef.cpp index c716135132..57dfa9c737 100644 --- a/plugins/dm.gui/gui/GuiWindowDef.cpp +++ b/plugins/dm.gui/gui/GuiWindowDef.cpp @@ -15,31 +15,32 @@ namespace gui { -GuiWindowDef::GuiWindowDef(Gui& owner) : +GuiWindowDef::GuiWindowDef(IGui& owner) : _owner(owner), _renderableText(*this), - _textChanged(true), - visible(true), - forecolor(1,1,1,1), - hovercolor(1,1,1,1), - backcolor(0,0,0,0), - bordercolor(0,0,0,0), - matcolor(1,1,1,1), - rotate(0), - textscale(1), - textalign(0), - textalignx(0), - textaligny(0), - forceaspectwidth(640), - forceaspectheight(480), - noclip(false), - notime(false), - nocursor(false), - nowrap(false), - time(0) -{} - -Gui& GuiWindowDef::getGui() const + _textChanged(true) +{ + visible = true; + forecolor = Vector4(1, 1, 1, 1); + hovercolor = Vector4(1, 1, 1, 1); + backcolor = Vector4(0, 0, 0, 0); + bordercolor = Vector4(0, 0, 0, 0); + matcolor = Vector4(1, 1, 1, 1); + rotate = 0; + textscale = 1; + textalign = 0; + textalignx = 0; + textaligny = 0; + forceaspectwidth = 640; + forceaspectheight = 480; + noclip = false; + notime = false; + nocursor = false; + nowrap = false; + time = 0; +} + +IGui& GuiWindowDef::getGui() const { return _owner; } @@ -138,7 +139,7 @@ bool GuiWindowDef::parseBool(parser::DefTokeniser& tokeniser) return string::convert(getExpression(tokeniser)) != 0; } -void GuiWindowDef::addWindow(const GuiWindowDefPtr& window) +void GuiWindowDef::addWindow(const IGuiWindowDefPtr& window) { children.push_back(window); } @@ -411,7 +412,7 @@ void GuiWindowDef::initTime(const std::size_t toTime, bool updateChildren) } } -GuiWindowDefPtr GuiWindowDef::findWindowDef(const std::string& windowName) +IGuiWindowDefPtr GuiWindowDef::findWindowDef(const std::string& windowName) { // First look at all direct children for (ChildWindows::const_iterator i = children.begin(); i != children.end(); ++i) @@ -425,13 +426,13 @@ GuiWindowDefPtr GuiWindowDef::findWindowDef(const std::string& windowName) // Not found, ask each child to search for the windowDef for (ChildWindows::const_iterator i = children.begin(); i != children.end(); ++i) { - GuiWindowDefPtr window = (*i)->findWindowDef(windowName); + IGuiWindowDefPtr window = (*i)->findWindowDef(windowName); if (window != NULL) return window; } // Not found - return GuiWindowDefPtr(); + return IGuiWindowDefPtr(); } void GuiWindowDef::pepareRendering(bool prepareChildren) diff --git a/plugins/dm.gui/gui/GuiWindowDef.h b/plugins/dm.gui/gui/GuiWindowDef.h index 3ec65e2ab6..58fefdbbdb 100644 --- a/plugins/dm.gui/gui/GuiWindowDef.h +++ b/plugins/dm.gui/gui/GuiWindowDef.h @@ -1,6 +1,6 @@ -#ifndef GuiWindowDef_h__ -#define GuiWindowDef_h__ +#pragma once +#include "igui.h" #include "ishaders.h" #include "math/Vector4.h" @@ -23,11 +23,12 @@ typedef std::shared_ptr GuiScriptPtr; * greebo: This is the base class for all windowDef-like objects in a GUI, * including windowDef, choiceDef, bindDef, etc. */ -class GuiWindowDef +class GuiWindowDef : + public IGuiWindowDef { private: // The owning GUI - Gui& _owner; + IGui& _owner; // The renderable text object for submission to a Renderer RenderableText _renderableText; @@ -42,94 +43,26 @@ class GuiWindowDef typedef std::multimap TimedEventMap; TimedEventMap _timedEvents; -public: - // Public properties - - // The name of this windowDef - std::string name; - - // Window size (x,y,width,height) - Vector4 rect; - - // Visible or hidden - bool visible; - - // Whether this gui is full screen (use on desktop window) - bool menugui; - - Vector4 forecolor; - Vector4 hovercolor; - Vector4 backcolor; - Vector4 bordercolor; - Vector4 matcolor; - - float rotate; - - // background shader name - std::string background; - - // background shader (NULL until realised) - MaterialPtr backgroundShader; - - // The name of the font - std::string font; - - // The scale for rendering the font - float textscale; - - // The text alignment (left, right, center) - int textalign; - - // Text offsets - float textalignx; - float textaligny; - - // Force a specific aspect ratio - float forceaspectwidth; - float forceaspectheight; - - // No mouse events for this window - bool noevents; - - // Whether this window forces text to wrap at their borders - bool noclip; - - // Whether time is running for this windowDef - bool notime; - - // Don't display the cursor - bool nocursor; - - // Don't wrap words at rectangle borders - bool nowrap; - - // The window time (0..infinity) - std::size_t time; - - // All child windowDefs of this window - typedef std::vector ChildWindows; - ChildWindows children; - public: // Default constructor - GuiWindowDef(Gui& owner); + GuiWindowDef(IGui& owner); // Returns the GUI - Gui& getGui() const; + IGui& getGui() const override; void constructFromTokens(parser::DefTokeniser& tokeniser); - void addWindow(const GuiWindowDefPtr& window); + void addWindow(const IGuiWindowDefPtr& window) override; // Recursively looks for a named child windowDef // Returns NULL if not found - GuiWindowDefPtr findWindowDef(const std::string& name); + IGuiWindowDefPtr findWindowDef(const std::string& name) override; - const std::string& getText() const; - void setText(const std::string& newText); + const std::string& getText() const override; + void setText(const std::string& newText) override; // Get the renderable text object containing the OpenGLRenderables - RenderableText& getRenderableText(); + RenderableText& getRenderableText() override; /** * greebo: This is some sort of "think" method, giving this windowDef @@ -137,13 +70,13 @@ class GuiWindowDef * * @updateChildren: recursively updates child windowDef if true */ - void update(const std::size_t timeStep, bool updateChildren = true); + void update(const std::size_t timeStep, bool updateChildren = true) override; // Initialises the time of this windowDef and all children - void initTime(const std::size_t time, bool updateChildren = true); + void initTime(const std::size_t time, bool updateChildren = true) override; // Prepares renderable objects, to be called by the parent Gui only - void pepareRendering(bool prepareChildren = true); + void pepareRendering(bool prepareChildren = true) override; private: Vector4 parseVector4(parser::DefTokeniser& tokeniser); @@ -157,5 +90,3 @@ class GuiWindowDef } // namespace - -#endif // GuiWindowDef_h__ diff --git a/plugins/dm.gui/gui/Variable.cpp b/plugins/dm.gui/gui/Variable.cpp index 171c6d7133..206699751a 100644 --- a/plugins/dm.gui/gui/Variable.cpp +++ b/plugins/dm.gui/gui/Variable.cpp @@ -1,13 +1,12 @@ #include "Variable.h" -#include "Gui.h" -#include "GuiWindowDef.h" +#include "igui.h" #include "string/case_conv.h" namespace gui { -WindowDefVariable::WindowDefVariable(GuiWindowDef& windowDef, +WindowDefVariable::WindowDefVariable(IGuiWindowDef& windowDef, const std::string& name) : _windowDef(windowDef), _name(string::to_lower_copy(name)) @@ -40,7 +39,7 @@ bool WindowDefVariable::assignValueFromString(const std::string& val) } } -GuiStateVariable::GuiStateVariable(Gui& gui, const std::string& key) : +GuiStateVariable::GuiStateVariable(IGui& gui, const std::string& key) : _gui(gui), _key(key) {} diff --git a/plugins/dm.gui/gui/Variable.h b/plugins/dm.gui/gui/Variable.h index 6adbdf88d2..322869a302 100644 --- a/plugins/dm.gui/gui/Variable.h +++ b/plugins/dm.gui/gui/Variable.h @@ -1,5 +1,4 @@ -#ifndef _GUI_VARIABLE_H_ -#define _GUI_VARIABLE_H_ +#pragma once #include #include @@ -7,8 +6,8 @@ namespace gui { -class Gui; -class GuiWindowDef; +class IGui; +class IGuiWindowDef; // An abstract variable wrapping around a target object in a GUI. // This can be a GUI state variable or a windowDef property @@ -28,13 +27,13 @@ class WindowDefVariable : { private: // The parent windowDef of this variable - GuiWindowDef& _windowDef; + IGuiWindowDef& _windowDef; // Variable name (in the windowDef std::string _name; public: - WindowDefVariable(GuiWindowDef& windowDef, const std::string& name); + WindowDefVariable(IGuiWindowDef& windowDef, const std::string& name); // Assign a value to this Variable (returns TRUE on success) bool assignValueFromString(const std::string& val); @@ -46,17 +45,15 @@ class GuiStateVariable : { private: // The GUi the state variable is located in - Gui& _gui; + IGui& _gui; // State key (name) std::string _key; public: - GuiStateVariable(Gui& gui, const std::string& key); + GuiStateVariable(IGui& gui, const std::string& key); bool assignValueFromString(const std::string& val); }; } // namespace - -#endif /* _GUI_VARIABLE_H_ */