Changeset View
Changeset View
Standalone View
Standalone View
source/gui/GUIutil.cpp
Show All 21 Lines | |||||
#include "maths/Matrix3D.h" | #include "maths/Matrix3D.h" | ||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
#include "ps/GameSetup/Config.h" | #include "ps/GameSetup/Config.h" | ||||
extern int g_xres, g_yres; | extern int g_xres, g_yres; | ||||
template <> | template <> | ||||
bool __ParseString<bool>(const CStrW& Value, bool& Output) | bool __ParseString<bool>(const CGUI* UNUSED(guiPage), const CStrW& Value, bool& Output) | ||||
{ | { | ||||
if (Value == L"true") | if (Value == L"true") | ||||
Output = true; | Output = true; | ||||
else if (Value == L"false") | else if (Value == L"false") | ||||
Output = false; | Output = false; | ||||
else | else | ||||
return false; | return false; | ||||
return true; | return true; | ||||
} | } | ||||
template <> | template <> | ||||
bool __ParseString<int>(const CStrW& Value, int& Output) | bool __ParseString<int>(const CGUI* UNUSED(guiPage), const CStrW& Value, int& Output) | ||||
{ | { | ||||
Output = Value.ToInt(); | Output = Value.ToInt(); | ||||
return true; | return true; | ||||
} | } | ||||
template <> | template <> | ||||
bool __ParseString<u32>(const CStrW& Value, u32& Output) | bool __ParseString<u32>(const CGUI* UNUSED(guiPage), const CStrW& Value, u32& Output) | ||||
{ | { | ||||
Output = Value.ToUInt(); | Output = Value.ToUInt(); | ||||
return true; | return true; | ||||
} | } | ||||
template <> | template <> | ||||
bool __ParseString<float>(const CStrW& Value, float& Output) | bool __ParseString<float>(const CGUI* UNUSED(guiPage), const CStrW& Value, float& Output) | ||||
{ | { | ||||
Output = Value.ToFloat(); | Output = Value.ToFloat(); | ||||
return true; | return true; | ||||
} | } | ||||
template <> | template <> | ||||
bool __ParseString<CRect>(const CStrW& Value, CRect& Output) | bool __ParseString<CRect>(const CGUI* UNUSED(guiPage), const CStrW& Value, CRect& Output) | ||||
{ | { | ||||
const unsigned int NUM_COORDS = 4; | const unsigned int NUM_COORDS = 4; | ||||
float coords[NUM_COORDS]; | float coords[NUM_COORDS]; | ||||
std::wstringstream stream; | std::wstringstream stream; | ||||
stream.str(Value); | stream.str(Value); | ||||
// Parse each coordinate | // Parse each coordinate | ||||
for (unsigned int i = 0; i < NUM_COORDS; ++i) | for (unsigned int i = 0; i < NUM_COORDS; ++i) | ||||
{ | { | ||||
Show All 18 Lines | bool __ParseString<CRect>(const CGUI* UNUSED(guiPage), const CStrW& Value, CRect& Output) | ||||
// Finally the rectangle values | // Finally the rectangle values | ||||
Output = CRect(coords[0], coords[1], coords[2], coords[3]); | Output = CRect(coords[0], coords[1], coords[2], coords[3]); | ||||
return true; | return true; | ||||
} | } | ||||
template <> | template <> | ||||
bool __ParseString<CClientArea>(const CStrW& Value, CClientArea& Output) | bool __ParseString<CClientArea>(const CGUI* UNUSED(guiPage), const CStrW& Value, CClientArea& Output) | ||||
{ | { | ||||
return Output.SetClientArea(Value.ToUTF8()); | return Output.SetClientArea(Value.ToUTF8()); | ||||
} | } | ||||
template <> | template <> | ||||
bool GUI<int>::ParseColor(const CStrW& Value, CColor& Output, int DefaultAlpha) | bool GUI<int>::ParseColor(const CGUI* guiPage, const CStrW& Value, CColor& Output, int DefaultAlpha) | ||||
{ | { | ||||
ENSURE(guiPage); | |||||
// First, check our database in g_GUI for pre-defined colors | // First, check our database in g_GUI for pre-defined colors | ||||
// If we find anything, we'll ignore DefaultAlpha | // If we find anything, we'll ignore DefaultAlpha | ||||
// If it fails, it won't do anything with Output | // If it fails, it won't do anything with Output | ||||
if (g_GUI->GetPreDefinedColor(Value.ToUTF8(), Output)) | if (guiPage && guiPage->GetPreDefinedColor(Value.ToUTF8(), Output)) | ||||
return true; | return true; | ||||
return Output.ParseString(Value.ToUTF8(), DefaultAlpha); | return Output.ParseString(Value.ToUTF8(), DefaultAlpha); | ||||
} | } | ||||
template <> | template <> | ||||
bool __ParseString<CColor>(const CStrW& Value, CColor& Output) | bool __ParseString<CColor>(const CGUI* guiPage, const CStrW& Value, CColor& Output) | ||||
{ | { | ||||
// First, check our database in g_GUI for pre-defined colors | ENSURE(guiPage); | ||||
// First, check our database in guiPage for pre-defined colors | |||||
// If it fails, it won't do anything with Output | // If it fails, it won't do anything with Output | ||||
if (g_GUI->GetPreDefinedColor(Value.ToUTF8(), Output)) | if (guiPage->GetPreDefinedColor(Value.ToUTF8(), Output)) | ||||
return true; | return true; | ||||
return Output.ParseString(Value.ToUTF8()); | return Output.ParseString(Value.ToUTF8()); | ||||
} | } | ||||
template <> | template <> | ||||
bool __ParseString<CSize>(const CStrW& Value, CSize& Output) | bool __ParseString<CSize>(const CGUI* UNUSED(guiPage), const CStrW& Value, CSize& Output) | ||||
{ | { | ||||
const unsigned int NUM_COORDS = 2; | const unsigned int NUM_COORDS = 2; | ||||
float coords[NUM_COORDS]; | float coords[NUM_COORDS]; | ||||
std::wstringstream stream; | std::wstringstream stream; | ||||
stream.str(Value); | stream.str(Value); | ||||
// Parse each coordinate | // Parse each coordinate | ||||
for (unsigned int i = 0; i < NUM_COORDS; ++i) | for (unsigned int i = 0; i < NUM_COORDS; ++i) | ||||
{ | { | ||||
Show All 18 Lines | if (!stream.eof()) | ||||
LOGWARNING("Too many CSize parameters (max %i). Your input: '%s'", NUM_COORDS, Value.ToUTF8().c_str()); | LOGWARNING("Too many CSize parameters (max %i). Your input: '%s'", NUM_COORDS, Value.ToUTF8().c_str()); | ||||
return false; | return false; | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
template <> | template <> | ||||
bool __ParseString<CPos>(const CStrW& Value, CPos& Output) | bool __ParseString<CPos>(const CGUI* UNUSED(guiPage), const CStrW& Value, CPos& Output) | ||||
{ | { | ||||
const unsigned int NUM_COORDS = 2; | const unsigned int NUM_COORDS = 2; | ||||
float coords[NUM_COORDS]; | float coords[NUM_COORDS]; | ||||
std::wstringstream stream; | std::wstringstream stream; | ||||
stream.str(Value); | stream.str(Value); | ||||
// Parse each coordinate | // Parse each coordinate | ||||
for (unsigned int i = 0; i < NUM_COORDS; ++i) | for (unsigned int i = 0; i < NUM_COORDS; ++i) | ||||
{ | { | ||||
Show All 18 Lines | if (!stream.eof()) | ||||
LOGWARNING("Too many CPos parameters (max %i). Your input: '%s'", NUM_COORDS, Value.ToUTF8().c_str()); | LOGWARNING("Too many CPos parameters (max %i). Your input: '%s'", NUM_COORDS, Value.ToUTF8().c_str()); | ||||
return false; | return false; | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
template <> | template <> | ||||
bool __ParseString<EAlign>(const CStrW& Value, EAlign& Output) | bool __ParseString<EAlign>(const CGUI* UNUSED(guiPage), const CStrW& Value, EAlign& Output) | ||||
{ | { | ||||
if (Value == L"left") | if (Value == L"left") | ||||
Output = EAlign_Left; | Output = EAlign_Left; | ||||
else if (Value == L"center") | else if (Value == L"center") | ||||
Output = EAlign_Center; | Output = EAlign_Center; | ||||
else if (Value == L"right") | else if (Value == L"right") | ||||
Output = EAlign_Right; | Output = EAlign_Right; | ||||
else | else | ||||
return false; | return false; | ||||
return true; | return true; | ||||
} | } | ||||
template <> | template <> | ||||
bool __ParseString<EVAlign>(const CStrW& Value, EVAlign& Output) | bool __ParseString<EVAlign>(const CGUI* UNUSED(guiPage), const CStrW& Value, EVAlign& Output) | ||||
{ | { | ||||
if (Value == L"top") | if (Value == L"top") | ||||
Output = EVAlign_Top; | Output = EVAlign_Top; | ||||
else if (Value == L"center") | else if (Value == L"center") | ||||
Output = EVAlign_Center; | Output = EVAlign_Center; | ||||
else if (Value == L"bottom") | else if (Value == L"bottom") | ||||
Output = EVAlign_Bottom; | Output = EVAlign_Bottom; | ||||
else | else | ||||
return false; | return false; | ||||
return true; | return true; | ||||
} | } | ||||
template <> | template <> | ||||
bool __ParseString<CGUIString>(const CStrW& Value, CGUIString& Output) | bool __ParseString<CGUIString>(const CGUI* UNUSED(guiPage), const CStrW& Value, CGUIString& Output) | ||||
{ | { | ||||
Output.SetValue(Value); | Output.SetValue(Value); | ||||
return true; | return true; | ||||
} | } | ||||
template <> | template <> | ||||
bool __ParseString<CStr>(const CStrW& Value, CStr& Output) | bool __ParseString<CStr>(const CGUI* UNUSED(guiPage), const CStrW& Value, CStr& Output) | ||||
{ | { | ||||
// Do very little. | // Do very little. | ||||
Output = Value.ToUTF8(); | Output = Value.ToUTF8(); | ||||
return true; | return true; | ||||
} | } | ||||
template <> | template <> | ||||
bool __ParseString<CStrW>(const CStrW& Value, CStrW& Output) | bool __ParseString<CStrW>(const CGUI* UNUSED(guiPage), const CStrW& Value, CStrW& Output) | ||||
{ | { | ||||
Output = Value; | Output = Value; | ||||
return true; | return true; | ||||
} | } | ||||
template <> | template <> | ||||
bool __ParseString<CGUISpriteInstance>(const CStrW& Value, CGUISpriteInstance& Output) | bool __ParseString<CGUISpriteInstance>(const CGUI* UNUSED(guiPage), const CStrW& Value, CGUISpriteInstance& Output) | ||||
{ | { | ||||
Output = CGUISpriteInstance(Value.ToUTF8()); | Output = CGUISpriteInstance(Value.ToUTF8()); | ||||
return true; | return true; | ||||
} | } | ||||
template <> | template <> | ||||
bool __ParseString<CGUIList>(const CStrW& UNUSED(Value), CGUIList& UNUSED(Output)) | bool __ParseString<CGUIList>(const CGUI* UNUSED(guiPage), const CStrW& UNUSED(Value), CGUIList& UNUSED(Output)) | ||||
{ | { | ||||
return false; | return false; | ||||
} | } | ||||
template <> | template <> | ||||
bool __ParseString<CGUISeries>(const CStrW& UNUSED(Value), CGUISeries& UNUSED(Output)) | bool __ParseString<CGUISeries>(const CGUI* UNUSED(guiPage), const CStrW& UNUSED(Value), CGUISeries& UNUSED(Output)) | ||||
{ | { | ||||
return false; | return false; | ||||
} | } | ||||
//-------------------------------------------------------- | //-------------------------------------------------------- | ||||
CMatrix3D GetDefaultGuiMatrix() | CMatrix3D GetDefaultGuiMatrix() | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 168 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator