1 /* Copyright (C) 2021 Wildfire Games.
2 * This file is part of 0 A.D.
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
18 #include "precompiled.h"
21 #include "gui/SettingTypes/CGUIString.h"
22 #include "ps/CLogger.h"
28 bool CGUI::ParseString
<bool>(const CGUI
* UNUSED(pGUI
), const CStrW
& Value
, bool& Output
)
32 else if (Value
== L
"false")
41 bool CGUI::ParseString
<i32
>(const CGUI
* UNUSED(pGUI
), const CStrW
& Value
, int& Output
)
43 Output
= Value
.ToInt();
48 bool CGUI::ParseString
<u32
>(const CGUI
* UNUSED(pGUI
), const CStrW
& Value
, u32
& Output
)
50 Output
= Value
.ToUInt();
55 bool CGUI::ParseString
<float>(const CGUI
* UNUSED(pGUI
), const CStrW
& Value
, float& Output
)
57 Output
= Value
.ToFloat();
62 bool CGUI::ParseString
<CRect
>(const CGUI
* UNUSED(pGUI
), const CStrW
& Value
, CRect
& Output
)
64 const unsigned int NUM_COORDS
= 4;
65 float coords
[NUM_COORDS
];
66 std::wstringstream stream
;
68 // Parse each coordinate
69 for (unsigned int i
= 0; i
< NUM_COORDS
; ++i
)
73 LOGWARNING("Too few CRect parameters (min %i). Your input: '%s'", NUM_COORDS
, Value
.ToUTF8().c_str());
77 if ((stream
.rdstate() & std::wstringstream::failbit
) != 0)
79 LOGWARNING("Unable to parse CRect parameters. Your input: '%s'", Value
.ToUTF8().c_str());
86 LOGWARNING("Too many CRect parameters (max %i). Your input: '%s'", NUM_COORDS
, Value
.ToUTF8().c_str());
90 // Finally the rectangle values
91 Output
= CRect(coords
[0], coords
[1], coords
[2], coords
[3]);
97 bool CGUI::ParseString
<CGUISize
>(const CGUI
* UNUSED(pGUI
), const CStrW
& Value
, CGUISize
& Output
)
99 return Output
.FromString(Value
.ToUTF8());
103 bool CGUI::ParseString
<CGUIColor
>(const CGUI
* pGUI
, const CStrW
& Value
, CGUIColor
& Output
)
105 return Output
.ParseString(*pGUI
, Value
.ToUTF8());
109 bool CGUI::ParseString
<CSize2D
>(const CGUI
* UNUSED(pGUI
), const CStrW
& Value
, CSize2D
& Output
)
111 const unsigned int NUM_COORDS
= 2;
112 float coords
[NUM_COORDS
];
113 std::wstringstream stream
;
115 // Parse each coordinate
116 for (unsigned int i
= 0; i
< NUM_COORDS
; ++i
)
120 LOGWARNING("Too few CSize2D parameters (min %i). Your input: '%s'", NUM_COORDS
, Value
.ToUTF8().c_str());
124 if ((stream
.rdstate() & std::wstringstream::failbit
) != 0)
126 LOGWARNING("Unable to parse CSize2D parameters. Your input: '%s'", Value
.ToUTF8().c_str());
131 Output
.Width
= coords
[0];
132 Output
.Height
= coords
[1];
136 LOGWARNING("Too many CSize2D parameters (max %i). Your input: '%s'", NUM_COORDS
, Value
.ToUTF8().c_str());
144 bool CGUI::ParseString
<CVector2D
>(const CGUI
* UNUSED(pGUI
), const CStrW
& Value
, CVector2D
& Output
)
146 const unsigned int NUM_COORDS
= 2;
147 float coords
[NUM_COORDS
];
148 std::wstringstream stream
;
150 // Parse each coordinate
151 for (unsigned int i
= 0; i
< NUM_COORDS
; ++i
)
155 LOGWARNING("Too few CVector2D parameters (min %i). Your input: '%s'", NUM_COORDS
, Value
.ToUTF8().c_str());
159 if ((stream
.rdstate() & std::wstringstream::failbit
) != 0)
161 LOGWARNING("Unable to parse CVector2D parameters. Your input: '%s'", Value
.ToUTF8().c_str());
166 Output
.X
= coords
[0];
167 Output
.Y
= coords
[1];
171 LOGWARNING("Too many CVector2D parameters (max %i). Your input: '%s'", NUM_COORDS
, Value
.ToUTF8().c_str());
179 bool CGUI::ParseString
<EAlign
>(const CGUI
* UNUSED(pGUI
), const CStrW
& Value
, EAlign
& Output
)
181 if (Value
== L
"left")
182 Output
= EAlign::LEFT
;
183 else if (Value
== L
"center")
184 Output
= EAlign::CENTER
;
185 else if (Value
== L
"right")
186 Output
= EAlign::RIGHT
;
194 bool CGUI::ParseString
<EVAlign
>(const CGUI
* UNUSED(pGUI
), const CStrW
& Value
, EVAlign
& Output
)
197 Output
= EVAlign::TOP
;
198 else if (Value
== L
"center")
199 Output
= EVAlign::CENTER
;
200 else if (Value
== L
"bottom")
201 Output
= EVAlign::BOTTOM
;
209 bool CGUI::ParseString
<CGUIString
>(const CGUI
* UNUSED(pGUI
), const CStrW
& Value
, CGUIString
& Output
)
211 Output
.SetValue(Value
);
216 bool CGUI::ParseString
<CStr
>(const CGUI
* UNUSED(pGUI
), const CStrW
& Value
, CStr
& Output
)
218 Output
= Value
.ToUTF8();
223 bool CGUI::ParseString
<CStrW
>(const CGUI
* UNUSED(pGUI
), const CStrW
& Value
, CStrW
& Output
)
230 bool CGUI::ParseString
<CGUISpriteInstance
>(const CGUI
* UNUSED(pGUI
), const CStrW
& Value
, CGUISpriteInstance
& Output
)
232 Output
= CGUISpriteInstance(Value
.ToUTF8());
237 bool CGUI::ParseString
<CGUISeries
>(const CGUI
* UNUSED(pGUI
), const CStrW
& UNUSED(Value
), CGUISeries
& UNUSED(Output
))
243 bool CGUI::ParseString
<CGUIList
>(const CGUI
* UNUSED(pGUI
), const CStrW
& UNUSED(Value
), CGUIList
& UNUSED(Output
))