Skip to content

Commit

Permalink
Migrate most of the remaining scalar variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Nov 25, 2017
1 parent 2436453 commit 5989c10
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 36 deletions.
16 changes: 8 additions & 8 deletions include/igui.h
Expand Up @@ -132,13 +132,13 @@ class IGuiWindowDef
Vector4 rect;

// Visible or hidden
bool visible;
ScalarWindowVariable<bool> visible;

// The body text of this window
ScalarWindowVariable<std::string> text;

// Whether this gui is full screen (use on desktop window)
bool menugui;
ScalarWindowVariable<bool> menugui;

Vector4 forecolor;
Vector4 hovercolor;
Expand All @@ -162,7 +162,7 @@ class IGuiWindowDef
ScalarWindowVariable<float> textscale;

// The text alignment (left, right, center)
int textalign;
ScalarWindowVariable<int> textalign;

// Text offsets
ScalarWindowVariable<float> textalignx;
Expand All @@ -173,19 +173,19 @@ class IGuiWindowDef
ScalarWindowVariable<float> forceaspectheight;

// No mouse events for this window
bool noevents;
ScalarWindowVariable<bool> noevents;

// Whether this window forces text to wrap at their borders
bool noclip;
ScalarWindowVariable<bool> noclip;

// Whether time is running for this windowDef
bool notime;
ScalarWindowVariable<bool> notime;

// Don't display the cursor
bool nocursor;
ScalarWindowVariable<bool> nocursor;

// Don't wrap words at rectangle borders
bool nowrap;
ScalarWindowVariable<bool> nowrap;

// The window time (0..infinity)
std::size_t time;
Expand Down
19 changes: 19 additions & 0 deletions plugins/dm.gui/gui/GuiExpression.h
Expand Up @@ -46,6 +46,25 @@ class TypedExpression :
}
};

// Boolean specialisation
template<>
class TypedExpression<bool> :
public IGuiExpression<bool>
{
private:
GuiExpressionPtr _contained;

public:
TypedExpression(const GuiExpressionPtr& contained) :
_contained(contained)
{}

virtual bool evaluate() override
{
return _contained->getFloatValue() != 0.0f;
}
};

// An expression representing a constant floating point value
class FloatExpression :
public GuiExpression,
Expand Down
52 changes: 26 additions & 26 deletions plugins/dm.gui/gui/GuiWindowDef.cpp
Expand Up @@ -42,24 +42,24 @@ GuiWindowDef::GuiWindowDef(IGui& owner) :
_owner(owner),
_renderableText(*this)
{
visible = true;
visible.setValue(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);
bordersize.setValue(ConstantExpression<float>::Create(0.0f));
bordersize.setValue(0.0f);
matcolor = Vector4(1, 1, 1, 1);
rotate.setValue(ConstantExpression<float>::Create(0.0f));
textscale.setValue(ConstantExpression<float>::Create(1.0f));
textalign = 0;
textalignx.setValue(ConstantExpression<float>::Create(0.0f));
textaligny.setValue(ConstantExpression<float>::Create(0.0f));
forceaspectwidth.setValue(ConstantExpression<float>::Create(640.0f));
forceaspectheight.setValue(ConstantExpression<float>::Create(480.0f));
noclip = false;
notime = false;
nocursor = false;
nowrap = false;
rotate.setValue(0.0f);
textscale.setValue(1.0f);
textalign.setValue(0);
textalignx.setValue(0.0f);
textaligny.setValue(0.0f);
forceaspectwidth.setValue(640.0f);
forceaspectheight.setValue(480.0f);
noclip.setValue(false);
notime.setValue(false);
nocursor.setValue(false);
nowrap.setValue(false);
time = 0;

_textChanged = true;
Expand Down Expand Up @@ -120,7 +120,7 @@ std::shared_ptr<IGuiExpression<float>> GuiWindowDef::parseFloat(parser::DefToken
return std::make_shared<TypedExpression<float>>(expr);
}

int GuiWindowDef::parseInt(parser::DefTokeniser& tokeniser)
std::shared_ptr<IGuiExpression<int>> GuiWindowDef::parseInt(parser::DefTokeniser& tokeniser)
{
GuiExpressionPtr expr = getExpression(tokeniser);

Expand All @@ -129,7 +129,7 @@ int GuiWindowDef::parseInt(parser::DefTokeniser& tokeniser)
throw parser::ParseException("Failed to parse integer expression.");
}

return static_cast<int>(expr->getFloatValue());
return std::make_shared<TypedExpression<int>>(expr);
}

std::shared_ptr<IGuiExpression<std::string>> GuiWindowDef::parseString(parser::DefTokeniser& tokeniser)
Expand All @@ -149,7 +149,7 @@ std::shared_ptr<IGuiExpression<std::string>> GuiWindowDef::parseString(parser::D
return std::make_shared<TypedExpression<std::string>>(expr);
}

bool GuiWindowDef::parseBool(parser::DefTokeniser& tokeniser)
std::shared_ptr<IGuiExpression<bool>> GuiWindowDef::parseBool(parser::DefTokeniser& tokeniser)
{
GuiExpressionPtr expr = getExpression(tokeniser);

Expand All @@ -158,7 +158,7 @@ bool GuiWindowDef::parseBool(parser::DefTokeniser& tokeniser)
throw parser::ParseException("Failed to parse integer expression.");
}

return expr->getFloatValue() != 0;
return std::make_shared<TypedExpression<bool>>(expr);
}

void GuiWindowDef::addWindow(const IGuiWindowDefPtr& window)
Expand Down Expand Up @@ -189,11 +189,11 @@ void GuiWindowDef::constructFromTokens(parser::DefTokeniser& tokeniser)
}
else if (token == "visible")
{
visible = parseBool(tokeniser);
visible.setValue(parseBool(tokeniser));
}
else if (token == "notime")
{
notime = parseBool(tokeniser);
notime.setValue(parseBool(tokeniser));
}
else if (token == "forecolor")
{
Expand Down Expand Up @@ -233,7 +233,7 @@ void GuiWindowDef::constructFromTokens(parser::DefTokeniser& tokeniser)
}
else if (token == "textalign")
{
textalign = parseInt(tokeniser);
textalign.setValue(parseInt(tokeniser));
}
else if (token == "textalignx")
{
Expand All @@ -257,27 +257,27 @@ void GuiWindowDef::constructFromTokens(parser::DefTokeniser& tokeniser)
}
else if (token == "noevents")
{
noevents = parseBool(tokeniser);
noevents.setValue(parseBool(tokeniser));
}
else if (token == "nocursor")
{
nocursor = parseBool(tokeniser);
nocursor.setValue(parseBool(tokeniser));
}
else if (token == "noclip")
{
noclip = parseBool(tokeniser);
noclip.setValue(parseBool(tokeniser));
}
else if (token == "nowrap")
{
nowrap = parseBool(tokeniser);
nowrap.setValue(parseBool(tokeniser));
}
else if (token == "modal")
{
noevents = parseBool(tokeniser);
noevents.setValue(parseBool(tokeniser));
}
else if (token == "menugui")
{
menugui = parseBool(tokeniser);
menugui.setValue(parseBool(tokeniser));
}
else if (token == "windowdef" || token == "indowdef") // yes, there's a syntax error in the TDM GUI
{
Expand Down
4 changes: 2 additions & 2 deletions plugins/dm.gui/gui/GuiWindowDef.h
Expand Up @@ -76,9 +76,9 @@ class GuiWindowDef :
public:
static Vector4 parseVector4(parser::DefTokeniser& tokeniser);
static std::shared_ptr<IGuiExpression<float>> parseFloat(parser::DefTokeniser& tokeniser);
static int parseInt(parser::DefTokeniser& tokeniser);
static std::shared_ptr<IGuiExpression<int>> parseInt(parser::DefTokeniser& tokeniser);
static std::shared_ptr<IGuiExpression<std::string>> parseString(parser::DefTokeniser& tokeniser);
static bool parseBool(parser::DefTokeniser& tokeniser);
static std::shared_ptr<IGuiExpression<bool>> parseBool(parser::DefTokeniser& tokeniser);

static GuiExpressionPtr getExpression(parser::DefTokeniser& tokeniser);
};
Expand Down

0 comments on commit 5989c10

Please sign in to comment.