take 'left' and 'player' (and more) out of global namespace

The values from the enums are converted to numbers a lot, so using an enum class would be counter-productive.
Having 'left' in the global namespace appeared to be an actual problem with some Qt headers, according to Fulgen.
install-platforms
David Dormagen 2018-01-20 18:20:51 +01:00
parent 735a29103f
commit 3acd4a22f2
2 changed files with 71 additions and 62 deletions

View File

@ -720,7 +720,7 @@ void C4ScriptGuiWindow::SetMarginProperties(const C4Value &property, C4String *t
// always set all four margins // always set all four margins
for (int i = 0; i < 4; ++i) for (int i = 0; i < 4; ++i)
{ {
C4ScriptGuiWindowPropertyName relative, absolute; C4ScriptGuiWindowPropertyName::type relative, absolute;
switch (i) switch (i)
{ {
case 0: case 0:
@ -769,7 +769,7 @@ C4Value C4ScriptGuiWindow::MarginsToC4Value()
} }
// helper function // helper function
void C4ScriptGuiWindow::SetPositionStringProperties(const C4Value &property, C4ScriptGuiWindowPropertyName relative, C4ScriptGuiWindowPropertyName absolute, C4String *tag) void C4ScriptGuiWindow::SetPositionStringProperties(const C4Value &property, C4ScriptGuiWindowPropertyName::type relative, C4ScriptGuiWindowPropertyName::type absolute, C4String *tag)
{ {
// the value might be a tagged proplist again // the value might be a tagged proplist again
if (property.GetType() == C4V_Type::C4V_PropList) if (property.GetType() == C4V_Type::C4V_PropList)
@ -836,7 +836,7 @@ void C4ScriptGuiWindow::SetPositionStringProperties(const C4Value &property, C4S
} }
// for saving // for saving
C4Value C4ScriptGuiWindow::PositionToC4Value(C4ScriptGuiWindowPropertyName relativeName, C4ScriptGuiWindowPropertyName absoluteName) C4Value C4ScriptGuiWindow::PositionToC4Value(C4ScriptGuiWindowPropertyName::type relativeName, C4ScriptGuiWindowPropertyName::type absoluteName)
{ {
// Go through all tags of the position attributes and save. // Go through all tags of the position attributes and save.
// Note that the tags for both the relative and the absolute attribute are always the same. // Note that the tags for both the relative and the absolute attribute are always the same.
@ -1379,7 +1379,7 @@ void C4ScriptGuiWindow::EnableScrollBar(bool enable, float childrenHeight)
} }
float C4ScriptGuiWindow::CalculateRelativeSize(float parentWidthOrHeight, C4ScriptGuiWindowPropertyName absoluteProperty, C4ScriptGuiWindowPropertyName relativeProperty) float C4ScriptGuiWindow::CalculateRelativeSize(float parentWidthOrHeight, C4ScriptGuiWindowPropertyName::type absoluteProperty, C4ScriptGuiWindowPropertyName::type relativeProperty)
{ {
const float widthOrHeight = Em2Pix(props[absoluteProperty].GetFloat()) const float widthOrHeight = Em2Pix(props[absoluteProperty].GetFloat())
+ float(parentWidthOrHeight) * props[relativeProperty].GetFloat(); + float(parentWidthOrHeight) * props[relativeProperty].GetFloat();
@ -1402,6 +1402,7 @@ void C4ScriptGuiWindow::UpdateLayoutGrid()
{ {
C4ScriptGuiWindow *child = static_cast<C4ScriptGuiWindow*>(element); C4ScriptGuiWindow *child = static_cast<C4ScriptGuiWindow*>(element);
// calculate the space the child needs, correctly respecting the margins // calculate the space the child needs, correctly respecting the margins
using namespace C4ScriptGuiWindowPropertyName;
const float childLeftMargin = child->CalculateRelativeSize(width, leftMargin, relLeftMargin); const float childLeftMargin = child->CalculateRelativeSize(width, leftMargin, relLeftMargin);
const float childTopMargin = child->CalculateRelativeSize(height, topMargin, relTopMargin); const float childTopMargin = child->CalculateRelativeSize(height, topMargin, relTopMargin);
const float childRightMargin = child->CalculateRelativeSize(width, rightMargin, relRightMargin); const float childRightMargin = child->CalculateRelativeSize(width, rightMargin, relRightMargin);
@ -1456,6 +1457,7 @@ void C4ScriptGuiWindow::UpdateLayoutTightGrid()
{ {
C4ScriptGuiWindow *child = static_cast<C4ScriptGuiWindow*>(element); C4ScriptGuiWindow *child = static_cast<C4ScriptGuiWindow*>(element);
// calculate the space the child needs, correctly respecting the margins // calculate the space the child needs, correctly respecting the margins
using namespace C4ScriptGuiWindowPropertyName;
const float childLeftMargin = child->CalculateRelativeSize(width, leftMargin, relLeftMargin); const float childLeftMargin = child->CalculateRelativeSize(width, leftMargin, relLeftMargin);
const float childTopMargin = child->CalculateRelativeSize(height, topMargin, relTopMargin); const float childTopMargin = child->CalculateRelativeSize(height, topMargin, relTopMargin);
const float childRightMargin = child->CalculateRelativeSize(width, rightMargin, relRightMargin); const float childRightMargin = child->CalculateRelativeSize(width, rightMargin, relRightMargin);
@ -1537,6 +1539,7 @@ void C4ScriptGuiWindow::UpdateLayoutVertical()
// Do the calculations in floats first to not lose accuracy. // Do the calculations in floats first to not lose accuracy.
// Take the height of the child and then add the margins. // Take the height of the child and then add the margins.
using namespace C4ScriptGuiWindowPropertyName;
const float childTopMargin = child->CalculateRelativeSize(rcBounds.Hgt, topMargin, relTopMargin); const float childTopMargin = child->CalculateRelativeSize(rcBounds.Hgt, topMargin, relTopMargin);
const float childBottomMargin = child->CalculateRelativeSize(rcBounds.Hgt, bottomMargin, relBottomMargin); const float childBottomMargin = child->CalculateRelativeSize(rcBounds.Hgt, bottomMargin, relBottomMargin);

View File

@ -22,66 +22,72 @@
#include "gui/C4Gui.h" #include "gui/C4Gui.h"
#include "script/C4Value.h" #include "script/C4Value.h"
enum C4ScriptGuiWindowPropertyName namespace C4ScriptGuiWindowPropertyName {
{ enum type
left = 0, {
top, left = 0,
right, top,
bottom, right,
bottom,
relLeft, relLeft,
relRight, relRight,
relTop, relTop,
relBottom, relBottom,
leftMargin, leftMargin,
topMargin, topMargin,
rightMargin, rightMargin,
bottomMargin, bottomMargin,
relLeftMargin,
relRightMargin,
relTopMargin,
relBottomMargin,
backgroundColor, relLeftMargin,
frameDecoration, relRightMargin,
symbolObject, relTopMargin,
symbolDef, relBottomMargin,
symbolGraphicsName,
text,
onClickAction,
onMouseInAction,
onMouseOutAction,
onCloseAction,
style,
priority,
player,
tooltip,
_lastProp
};
enum C4ScriptGuiWindowActionID backgroundColor,
{ frameDecoration,
SetTag = 1, symbolObject,
Call, symbolDef,
}; symbolGraphicsName,
text,
onClickAction,
onMouseInAction,
onMouseOutAction,
onCloseAction,
style,
priority,
player,
tooltip,
_lastProp
};
}
enum C4ScriptGuiWindowStyleFlag namespace C4ScriptGuiWindowActionID {
{ enum type
None = 0, {
GridLayout = 1, SetTag = 1,
VerticalLayout = 2, Call,
TextVCenter = 4, };
TextHCenter = 8, }
TextRight = 16,
TextBottom = 32, namespace C4ScriptGuiWindowStyleFlag {
FitChildren = 64, enum type
Multiple = 128, {
IgnoreMouse = 256, None = 0,
NoCrop = 512, GridLayout = 1,
TightGridLayout = 1024, VerticalLayout = 2,
}; TextVCenter = 4,
TextHCenter = 8,
TextRight = 16,
TextBottom = 32,
FitChildren = 64,
Multiple = 128,
IgnoreMouse = 256,
NoCrop = 512,
TightGridLayout = 1024,
};
}
class C4ScriptGuiWindow; class C4ScriptGuiWindow;
@ -214,8 +220,8 @@ public:
// will sort the child correctly into the children list // will sort the child correctly into the children list
void ChildChangedPriority(C4ScriptGuiWindow *child); void ChildChangedPriority(C4ScriptGuiWindow *child);
// helper function to extract relative and absolute position values from a string // helper function to extract relative and absolute position values from a string
void SetPositionStringProperties(const C4Value &property, C4ScriptGuiWindowPropertyName relative, C4ScriptGuiWindowPropertyName absolute, C4String *tag); void SetPositionStringProperties(const C4Value &property, C4ScriptGuiWindowPropertyName::type relative, C4ScriptGuiWindowPropertyName::type absolute, C4String *tag);
C4Value PositionToC4Value(C4ScriptGuiWindowPropertyName relative, C4ScriptGuiWindowPropertyName absolute); C4Value PositionToC4Value(C4ScriptGuiWindowPropertyName::type relative, C4ScriptGuiWindowPropertyName::type absolute);
// sets all margins either from a string or from an array // sets all margins either from a string or from an array
void SetMarginProperties(const C4Value &property, C4String *tag); void SetMarginProperties(const C4Value &property, C4String *tag);
C4Value MarginsToC4Value(); C4Value MarginsToC4Value();
@ -279,7 +285,7 @@ public:
void ClearPointers(C4Object *pObj); void ClearPointers(C4Object *pObj);
// calculate the width/height based on a certain property (f.e. leftMargin and relLeftMargin) and the parent's width/height // calculate the width/height based on a certain property (f.e. leftMargin and relLeftMargin) and the parent's width/height
float CalculateRelativeSize(float parentWidthOrHeight, C4ScriptGuiWindowPropertyName absoluteProperty, C4ScriptGuiWindowPropertyName relativeProperty); float CalculateRelativeSize(float parentWidthOrHeight, C4ScriptGuiWindowPropertyName::type absoluteProperty, C4ScriptGuiWindowPropertyName::type relativeProperty);
// schedules a layout update for the next drawing step // schedules a layout update for the next drawing step
void RequestLayoutUpdate(); void RequestLayoutUpdate();