From 3acd4a22f23a08273eaed5580e4d48d1a9a61af7 Mon Sep 17 00:00:00 2001 From: David Dormagen Date: Sat, 20 Jan 2018 18:20:51 +0100 Subject: [PATCH] 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. --- src/gui/C4ScriptGuiWindow.cpp | 11 +-- src/gui/C4ScriptGuiWindow.h | 122 ++++++++++++++++++---------------- 2 files changed, 71 insertions(+), 62 deletions(-) diff --git a/src/gui/C4ScriptGuiWindow.cpp b/src/gui/C4ScriptGuiWindow.cpp index 122c817c6..c45ed4836 100644 --- a/src/gui/C4ScriptGuiWindow.cpp +++ b/src/gui/C4ScriptGuiWindow.cpp @@ -720,7 +720,7 @@ void C4ScriptGuiWindow::SetMarginProperties(const C4Value &property, C4String *t // always set all four margins for (int i = 0; i < 4; ++i) { - C4ScriptGuiWindowPropertyName relative, absolute; + C4ScriptGuiWindowPropertyName::type relative, absolute; switch (i) { case 0: @@ -769,7 +769,7 @@ C4Value C4ScriptGuiWindow::MarginsToC4Value() } // 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 if (property.GetType() == C4V_Type::C4V_PropList) @@ -836,7 +836,7 @@ void C4ScriptGuiWindow::SetPositionStringProperties(const C4Value &property, C4S } // 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. // 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()) + float(parentWidthOrHeight) * props[relativeProperty].GetFloat(); @@ -1402,6 +1402,7 @@ void C4ScriptGuiWindow::UpdateLayoutGrid() { C4ScriptGuiWindow *child = static_cast(element); // calculate the space the child needs, correctly respecting the margins + using namespace C4ScriptGuiWindowPropertyName; const float childLeftMargin = child->CalculateRelativeSize(width, leftMargin, relLeftMargin); const float childTopMargin = child->CalculateRelativeSize(height, topMargin, relTopMargin); const float childRightMargin = child->CalculateRelativeSize(width, rightMargin, relRightMargin); @@ -1456,6 +1457,7 @@ void C4ScriptGuiWindow::UpdateLayoutTightGrid() { C4ScriptGuiWindow *child = static_cast(element); // calculate the space the child needs, correctly respecting the margins + using namespace C4ScriptGuiWindowPropertyName; const float childLeftMargin = child->CalculateRelativeSize(width, leftMargin, relLeftMargin); const float childTopMargin = child->CalculateRelativeSize(height, topMargin, relTopMargin); 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. // 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 childBottomMargin = child->CalculateRelativeSize(rcBounds.Hgt, bottomMargin, relBottomMargin); diff --git a/src/gui/C4ScriptGuiWindow.h b/src/gui/C4ScriptGuiWindow.h index 8ec77ed10..deb9b7185 100644 --- a/src/gui/C4ScriptGuiWindow.h +++ b/src/gui/C4ScriptGuiWindow.h @@ -22,66 +22,72 @@ #include "gui/C4Gui.h" #include "script/C4Value.h" -enum C4ScriptGuiWindowPropertyName -{ - left = 0, - top, - right, - bottom, +namespace C4ScriptGuiWindowPropertyName { + enum type + { + left = 0, + top, + right, + bottom, - relLeft, - relRight, - relTop, - relBottom, + relLeft, + relRight, + relTop, + relBottom, - leftMargin, - topMargin, - rightMargin, - bottomMargin, - - relLeftMargin, - relRightMargin, - relTopMargin, - relBottomMargin, + leftMargin, + topMargin, + rightMargin, + bottomMargin, - backgroundColor, - frameDecoration, - symbolObject, - symbolDef, - symbolGraphicsName, - text, - onClickAction, - onMouseInAction, - onMouseOutAction, - onCloseAction, - style, - priority, - player, - tooltip, - _lastProp -}; + relLeftMargin, + relRightMargin, + relTopMargin, + relBottomMargin, -enum C4ScriptGuiWindowActionID -{ - SetTag = 1, - Call, -}; + backgroundColor, + frameDecoration, + symbolObject, + symbolDef, + symbolGraphicsName, + text, + onClickAction, + onMouseInAction, + onMouseOutAction, + onCloseAction, + style, + priority, + player, + tooltip, + _lastProp + }; +} -enum C4ScriptGuiWindowStyleFlag -{ - None = 0, - GridLayout = 1, - VerticalLayout = 2, - TextVCenter = 4, - TextHCenter = 8, - TextRight = 16, - TextBottom = 32, - FitChildren = 64, - Multiple = 128, - IgnoreMouse = 256, - NoCrop = 512, - TightGridLayout = 1024, -}; +namespace C4ScriptGuiWindowActionID { + enum type + { + SetTag = 1, + Call, + }; +} + +namespace C4ScriptGuiWindowStyleFlag { + enum type + { + None = 0, + GridLayout = 1, + VerticalLayout = 2, + TextVCenter = 4, + TextHCenter = 8, + TextRight = 16, + TextBottom = 32, + FitChildren = 64, + Multiple = 128, + IgnoreMouse = 256, + NoCrop = 512, + TightGridLayout = 1024, + }; +} class C4ScriptGuiWindow; @@ -214,8 +220,8 @@ public: // will sort the child correctly into the children list void ChildChangedPriority(C4ScriptGuiWindow *child); // helper function to extract relative and absolute position values from a string - void SetPositionStringProperties(const C4Value &property, C4ScriptGuiWindowPropertyName relative, C4ScriptGuiWindowPropertyName absolute, C4String *tag); - C4Value PositionToC4Value(C4ScriptGuiWindowPropertyName relative, C4ScriptGuiWindowPropertyName absolute); + void SetPositionStringProperties(const C4Value &property, C4ScriptGuiWindowPropertyName::type relative, C4ScriptGuiWindowPropertyName::type absolute, C4String *tag); + C4Value PositionToC4Value(C4ScriptGuiWindowPropertyName::type relative, C4ScriptGuiWindowPropertyName::type absolute); // sets all margins either from a string or from an array void SetMarginProperties(const C4Value &property, C4String *tag); C4Value MarginsToC4Value(); @@ -279,7 +285,7 @@ public: void ClearPointers(C4Object *pObj); // 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 void RequestLayoutUpdate();