Skip to content

Commit

Permalink
Add named variable set to IGuiWindowDef, complete [define]float parsi…
Browse files Browse the repository at this point in the history
…ng code.
  • Loading branch information
codereader committed Nov 26, 2017
1 parent be689d3 commit eda107b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
12 changes: 12 additions & 0 deletions include/igui.h
Expand Up @@ -3,6 +3,8 @@
#include <vector>
#include <string>
#include <memory>
#include <map>

#include <sigc++/signal.h>
#include "imodule.h"
#include "math/Vector4.h"
Expand Down Expand Up @@ -31,6 +33,9 @@ template<typename ValueType>
class IGuiExpression
{
public:
// Shared ptr typedef
typedef std::shared_ptr<IGuiExpression<ValueType>> Ptr;

virtual ~IGuiExpression() {}

// Evaluate this expression to retrieve the result
Expand Down Expand Up @@ -95,6 +100,7 @@ class WindowVariable :

public:
typedef ValueType ValueType; // make the ValueType public
typedef std::shared_ptr<WindowVariable<ValueType>> Ptr; // smart ptr typedef

operator ValueType() const
{
Expand Down Expand Up @@ -195,6 +201,12 @@ class IGuiWindowDef
// The window time (0..infinity)
std::size_t time;

// Each window can define its own set of named variables,
// which can be of type float or Vector4
typedef std::shared_ptr<IWindowVariable> IWindowVariablePtr;
typedef std::map<std::string, IWindowVariablePtr> NamedVariables;
NamedVariables variables;

// All child windowDefs of this window
typedef std::vector<IGuiWindowDefPtr> ChildWindows;
ChildWindows children;
Expand Down
18 changes: 16 additions & 2 deletions plugins/dm.gui/gui/GuiWindowDef.cpp
Expand Up @@ -353,13 +353,16 @@ void GuiWindowDef::constructFromTokens(parser::DefTokeniser& tokeniser)
}
else if (token == "float" || token == "definefloat")
{
// TODO: Add variable
// Add variable
std::string variableName = tokeniser.nextToken();

// Initial value
float value = 0.0f;

// try to check if the next token is a numeric initialisation value
try
{
float value = std::stof(tokeniser.peek());
value = std::stof(tokeniser.peek());

// Success, load the value
tokeniser.nextToken();
Expand All @@ -368,6 +371,17 @@ void GuiWindowDef::constructFromTokens(parser::DefTokeniser& tokeniser)
{
// Not a number, ignore and continue
}

WindowVariable<float>::Ptr windowVar = std::make_shared<WindowVariable<float>>();
windowVar->setValue(value);

std::pair<NamedVariables::iterator, bool> result = variables.insert(
std::make_pair(variableName, windowVar));

if (!result.second)
{
rWarning() << "Duplicate variable defined in windowDef " << name << ": " << variableName << std::endl;
}
}
else if (token == "definevec4")
{
Expand Down

0 comments on commit eda107b

Please sign in to comment.