Skip to content

Commit

Permalink
Move GuiWindowDef interface to igui.h.
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Nov 7, 2017
1 parent d79c720 commit afd5ae3
Show file tree
Hide file tree
Showing 11 changed files with 178 additions and 148 deletions.
118 changes: 113 additions & 5 deletions include/igui.h
Expand Up @@ -3,12 +3,120 @@
#include <vector>
#include <string>
#include "imodule.h"
#include "math/Vector4.h"
#include "ishaders.h"

namespace gui
{

class GuiWindowDef;
typedef std::shared_ptr<GuiWindowDef> GuiWindowDefPtr;
class IGui;
class RenderableText;

class IGuiWindowDef;
typedef std::shared_ptr<IGuiWindowDef> 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<IGuiWindowDefPtr> 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
Expand 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::<key> = <value>)
virtual void setStateString(const std::string& key, const std::string& value) = 0;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion plugins/dm.gui/ReadableGuiView.cpp
Expand Up @@ -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");
Expand Down
12 changes: 4 additions & 8 deletions plugins/dm.gui/gui/Gui.cpp
Expand Up @@ -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;
}
Expand Down Expand Up @@ -76,15 +72,15 @@ 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")
{
return _desktop;
}

return (_desktop != NULL) ? _desktop->findWindowDef(name) : GuiWindowDefPtr();
return (_desktop != NULL) ? _desktop->findWindowDef(name) : IGuiWindowDefPtr();
}

void Gui::pepareRendering()
Expand Down
10 changes: 4 additions & 6 deletions plugins/dm.gui/gui/Gui.h
Expand Up @@ -25,17 +25,15 @@ class Gui :
{
private:
// The desktop window
GuiWindowDefPtr _desktop;
IGuiWindowDefPtr _desktop;

// The global GUI state variables
typedef std::map<std::string, std::string> 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::<key> = <value>)
void setStateString(const std::string& key, const std::string& value) override;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion plugins/dm.gui/gui/GuiRenderer.cpp
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion plugins/dm.gui/gui/GuiRenderer.h
Expand Up @@ -37,7 +37,7 @@ class GuiRenderer :
void render();

private:
void render(const GuiWindowDefPtr& window);
void render(const IGuiWindowDefPtr& window);
};

}
2 changes: 1 addition & 1 deletion plugins/dm.gui/gui/GuiScript.cpp
Expand Up @@ -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)
{
Expand Down
55 changes: 28 additions & 27 deletions plugins/dm.gui/gui/GuiWindowDef.cpp
Expand Up @@ -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;
}
Expand Down Expand Up @@ -138,7 +139,7 @@ bool GuiWindowDef::parseBool(parser::DefTokeniser& tokeniser)
return string::convert<int>(getExpression(tokeniser)) != 0;
}

void GuiWindowDef::addWindow(const GuiWindowDefPtr& window)
void GuiWindowDef::addWindow(const IGuiWindowDefPtr& window)
{
children.push_back(window);
}
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit afd5ae3

Please sign in to comment.