2016-08-02 18:58:30 +02:00
|
|
|
/* Copyright (C) 2016 Wildfire Games.
|
2009-04-18 19:00:33 +02:00
|
|
|
* This file is part of 0 A.D.
|
|
|
|
*
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2004-06-03 20:38:14 +02:00
|
|
|
#include "precompiled.h"
|
2015-08-21 19:08:41 +02:00
|
|
|
|
2003-11-06 01:21:45 +01:00
|
|
|
#include "GUI.h"
|
2009-12-03 21:17:22 +01:00
|
|
|
#include "GUIManager.h"
|
2005-02-05 08:25:16 +01:00
|
|
|
|
2015-08-21 19:08:41 +02:00
|
|
|
#include "maths/Matrix3D.h"
|
2009-09-27 17:04:46 +02:00
|
|
|
#include "ps/CLogger.h"
|
2016-08-02 18:58:30 +02:00
|
|
|
#include "ps/GameSetup/Config.h"
|
2009-09-27 17:04:46 +02:00
|
|
|
|
2015-08-21 19:08:41 +02:00
|
|
|
extern int g_xres, g_yres;
|
2003-11-06 01:21:45 +01:00
|
|
|
|
2004-05-29 06:06:50 +02:00
|
|
|
template <>
|
2015-08-21 19:08:41 +02:00
|
|
|
bool __ParseString<bool>(const CStrW& Value, bool& Output)
|
2004-05-29 06:06:50 +02:00
|
|
|
{
|
2010-05-30 15:11:32 +02:00
|
|
|
if (Value == L"true")
|
2004-05-29 06:06:50 +02:00
|
|
|
Output = true;
|
2015-08-21 19:08:41 +02:00
|
|
|
else if (Value == L"false")
|
2004-05-29 06:06:50 +02:00
|
|
|
Output = false;
|
2015-08-21 19:08:41 +02:00
|
|
|
else
|
2004-05-29 06:06:50 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
2015-08-21 19:08:41 +02:00
|
|
|
bool __ParseString<int>(const CStrW& Value, int& Output)
|
2004-05-29 06:06:50 +02:00
|
|
|
{
|
|
|
|
Output = Value.ToInt();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
2015-08-21 19:08:41 +02:00
|
|
|
bool __ParseString<float>(const CStrW& Value, float& Output)
|
2004-05-29 06:06:50 +02:00
|
|
|
{
|
|
|
|
Output = Value.ToFloat();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
2015-08-21 19:08:41 +02:00
|
|
|
bool __ParseString<CRect>(const CStrW& Value, CRect& Output)
|
2004-05-29 06:06:50 +02:00
|
|
|
{
|
2014-05-25 05:16:52 +02:00
|
|
|
const unsigned int NUM_COORDS = 4;
|
|
|
|
float coords[NUM_COORDS];
|
|
|
|
std::wstringstream stream;
|
|
|
|
stream.str(Value);
|
|
|
|
// Parse each coordinate
|
2015-08-21 19:08:41 +02:00
|
|
|
for (unsigned int i = 0; i < NUM_COORDS; ++i)
|
2004-05-29 06:06:50 +02:00
|
|
|
{
|
2014-05-25 05:16:52 +02:00
|
|
|
if (stream.eof())
|
|
|
|
{
|
2015-01-22 21:36:24 +01:00
|
|
|
LOGWARNING("Too few CRect parameters (min %i). Your input: '%s'", NUM_COORDS, Value.ToUTF8().c_str());
|
2014-05-25 05:16:52 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
stream >> coords[i];
|
|
|
|
if ((stream.rdstate() & std::wstringstream::failbit) != 0)
|
2004-05-29 06:06:50 +02:00
|
|
|
{
|
2015-01-22 21:36:24 +01:00
|
|
|
LOGWARNING("Unable to parse CRect parameters. Your input: '%s'", Value.ToUTF8().c_str());
|
2004-05-29 06:06:50 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-25 05:16:52 +02:00
|
|
|
if (!stream.eof())
|
|
|
|
{
|
2015-01-22 21:36:24 +01:00
|
|
|
LOGWARNING("Too many CRect parameters (max %i). Your input: '%s'", NUM_COORDS, Value.ToUTF8().c_str());
|
2014-05-25 05:16:52 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2004-05-29 06:06:50 +02:00
|
|
|
// Finally the rectangle values
|
2014-05-25 05:16:52 +02:00
|
|
|
Output = CRect(coords[0], coords[1], coords[2], coords[3]);
|
|
|
|
|
2004-05-29 06:06:50 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
2015-08-21 19:08:41 +02:00
|
|
|
bool __ParseString<CClientArea>(const CStrW& Value, CClientArea& Output)
|
2004-05-29 06:06:50 +02:00
|
|
|
{
|
2011-02-17 21:08:20 +01:00
|
|
|
return Output.SetClientArea(Value.ToUTF8());
|
2004-05-29 06:06:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
2015-08-21 19:08:41 +02:00
|
|
|
bool GUI<int>::ParseColor(const CStrW& Value, CColor& Output, int DefaultAlpha)
|
2004-05-29 06:06:50 +02:00
|
|
|
{
|
2005-07-25 21:06:18 +02:00
|
|
|
// First, check our database in g_GUI for pre-defined colors
|
|
|
|
// If we find anything, we'll ignore DefaultAlpha
|
|
|
|
// If it fails, it won't do anything with Output
|
2011-02-17 21:08:20 +01:00
|
|
|
if (g_GUI->GetPreDefinedColor(Value.ToUTF8(), Output))
|
2005-07-25 21:06:18 +02:00
|
|
|
return true;
|
|
|
|
|
2011-02-17 21:08:20 +01:00
|
|
|
return Output.ParseString(Value.ToUTF8(), DefaultAlpha);
|
2004-05-29 06:06:50 +02:00
|
|
|
}
|
|
|
|
|
2005-01-03 23:23:27 +01:00
|
|
|
|
|
|
|
template <>
|
2015-08-21 19:08:41 +02:00
|
|
|
bool __ParseString<CColor>(const CStrW& Value, CColor& Output)
|
2005-01-03 23:23:27 +01:00
|
|
|
{
|
2005-07-25 21:06:18 +02:00
|
|
|
// First, check our database in g_GUI for pre-defined colors
|
|
|
|
// If it fails, it won't do anything with Output
|
2011-02-17 21:08:20 +01:00
|
|
|
if (g_GUI->GetPreDefinedColor(Value.ToUTF8(), Output))
|
2005-07-25 21:06:18 +02:00
|
|
|
return true;
|
|
|
|
|
2014-06-04 02:58:05 +02:00
|
|
|
return Output.ParseString(Value.ToUTF8());
|
2005-01-03 23:23:27 +01:00
|
|
|
}
|
|
|
|
|
2004-08-31 04:09:58 +02:00
|
|
|
template <>
|
2015-08-21 19:08:41 +02:00
|
|
|
bool __ParseString<CSize>(const CStrW& Value, CSize& Output)
|
2004-08-31 04:09:58 +02:00
|
|
|
{
|
2014-05-25 05:16:52 +02:00
|
|
|
const unsigned int NUM_COORDS = 2;
|
|
|
|
float coords[NUM_COORDS];
|
|
|
|
std::wstringstream stream;
|
|
|
|
stream.str(Value);
|
|
|
|
// Parse each coordinate
|
2015-08-21 19:08:41 +02:00
|
|
|
for (unsigned int i = 0; i < NUM_COORDS; ++i)
|
2004-08-31 04:09:58 +02:00
|
|
|
{
|
2014-05-25 05:16:52 +02:00
|
|
|
if (stream.eof())
|
|
|
|
{
|
2015-01-22 21:36:24 +01:00
|
|
|
LOGWARNING("Too few CSize parameters (min %i). Your input: '%s'", NUM_COORDS, Value.ToUTF8().c_str());
|
2014-05-25 05:16:52 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
stream >> coords[i];
|
|
|
|
if ((stream.rdstate() & std::wstringstream::failbit) != 0)
|
|
|
|
{
|
2015-01-22 21:36:24 +01:00
|
|
|
LOGWARNING("Unable to parse CSize parameters. Your input: '%s'", Value.ToUTF8().c_str());
|
2014-05-25 05:16:52 +02:00
|
|
|
return false;
|
|
|
|
}
|
2004-08-31 04:09:58 +02:00
|
|
|
}
|
|
|
|
|
2014-05-25 05:16:52 +02:00
|
|
|
Output.cx = coords[0];
|
|
|
|
Output.cy = coords[1];
|
2004-08-31 04:09:58 +02:00
|
|
|
|
2014-05-25 05:16:52 +02:00
|
|
|
if (!stream.eof())
|
2004-08-31 04:09:58 +02:00
|
|
|
{
|
2015-01-22 21:36:24 +01:00
|
|
|
LOGWARNING("Too many CSize parameters (max %i). Your input: '%s'", NUM_COORDS, Value.ToUTF8().c_str());
|
2004-08-31 04:09:58 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-12-21 14:37:24 +01:00
|
|
|
template <>
|
2015-08-21 19:08:41 +02:00
|
|
|
bool __ParseString<CPos>(const CStrW& Value, CPos& Output)
|
2004-12-21 14:37:24 +01:00
|
|
|
{
|
2014-05-25 05:16:52 +02:00
|
|
|
const unsigned int NUM_COORDS = 2;
|
|
|
|
float coords[NUM_COORDS];
|
|
|
|
std::wstringstream stream;
|
|
|
|
stream.str(Value);
|
|
|
|
// Parse each coordinate
|
2015-08-21 19:08:41 +02:00
|
|
|
for (unsigned int i = 0; i < NUM_COORDS; ++i)
|
2014-05-25 05:16:52 +02:00
|
|
|
{
|
|
|
|
if (stream.eof())
|
|
|
|
{
|
2015-01-22 21:36:24 +01:00
|
|
|
LOGWARNING("Too few CPos parameters (min %i). Your input: '%s'", NUM_COORDS, Value.ToUTF8().c_str());
|
2014-05-25 05:16:52 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
stream >> coords[i];
|
|
|
|
if ((stream.rdstate() & std::wstringstream::failbit) != 0)
|
|
|
|
{
|
2015-01-22 21:36:24 +01:00
|
|
|
LOGWARNING("Unable to parse CPos parameters. Your input: '%s'", Value.ToUTF8().c_str());
|
2014-05-25 05:16:52 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2010-04-19 21:43:05 +02:00
|
|
|
|
2014-05-25 05:16:52 +02:00
|
|
|
Output.x = coords[0];
|
|
|
|
Output.y = coords[1];
|
2010-04-19 21:43:05 +02:00
|
|
|
|
2014-05-25 05:16:52 +02:00
|
|
|
if (!stream.eof())
|
|
|
|
{
|
2015-01-22 21:36:24 +01:00
|
|
|
LOGWARNING("Too many CPos parameters (max %i). Your input: '%s'", NUM_COORDS, Value.ToUTF8().c_str());
|
2004-12-21 14:37:24 +01:00
|
|
|
return false;
|
2014-05-25 05:16:52 +02:00
|
|
|
}
|
2010-04-19 21:43:05 +02:00
|
|
|
|
|
|
|
return true;
|
2004-12-21 14:37:24 +01:00
|
|
|
}
|
|
|
|
|
2004-09-02 05:02:32 +02:00
|
|
|
template <>
|
2015-08-21 19:08:41 +02:00
|
|
|
bool __ParseString<EAlign>(const CStrW& Value, EAlign& Output)
|
2004-09-02 05:02:32 +02:00
|
|
|
{
|
2010-05-30 15:11:32 +02:00
|
|
|
if (Value == L"left")
|
2004-09-02 05:02:32 +02:00
|
|
|
Output = EAlign_Left;
|
2015-08-21 19:08:41 +02:00
|
|
|
else if (Value == L"center")
|
2004-09-02 05:02:32 +02:00
|
|
|
Output = EAlign_Center;
|
2015-08-21 19:08:41 +02:00
|
|
|
else if (Value == L"right")
|
2004-09-02 05:02:32 +02:00
|
|
|
Output = EAlign_Right;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
2015-08-21 19:08:41 +02:00
|
|
|
bool __ParseString<EVAlign>(const CStrW& Value, EVAlign& Output)
|
2004-09-02 05:02:32 +02:00
|
|
|
{
|
2010-05-30 15:11:32 +02:00
|
|
|
if (Value == L"top")
|
2004-09-02 05:02:32 +02:00
|
|
|
Output = EVAlign_Top;
|
2015-08-21 19:08:41 +02:00
|
|
|
else if (Value == L"center")
|
2004-09-02 05:02:32 +02:00
|
|
|
Output = EVAlign_Center;
|
2015-08-21 19:08:41 +02:00
|
|
|
else if (Value == L"bottom")
|
2004-09-02 05:02:32 +02:00
|
|
|
Output = EVAlign_Bottom;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-05-29 06:06:50 +02:00
|
|
|
template <>
|
2015-08-21 19:08:41 +02:00
|
|
|
bool __ParseString<CGUIString>(const CStrW& Value, CGUIString& Output)
|
2004-05-29 06:06:50 +02:00
|
|
|
{
|
2010-05-30 15:11:32 +02:00
|
|
|
Output.SetValue(Value);
|
2004-05-29 06:06:50 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-12-17 01:05:37 +01:00
|
|
|
template <>
|
2010-05-30 15:11:32 +02:00
|
|
|
bool __ParseString<CStr>(const CStrW& Value, CStr& Output)
|
2004-12-17 01:05:37 +01:00
|
|
|
{
|
|
|
|
// Do very little.
|
2011-02-17 21:08:20 +01:00
|
|
|
Output = Value.ToUTF8();
|
2004-12-17 01:05:37 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-10-14 12:09:26 +02:00
|
|
|
template <>
|
2010-05-30 15:11:32 +02:00
|
|
|
bool __ParseString<CStrW>(const CStrW& Value, CStrW& Output)
|
2004-10-14 12:09:26 +02:00
|
|
|
{
|
2010-05-30 15:11:32 +02:00
|
|
|
Output = Value;
|
2004-10-14 12:09:26 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-12-15 22:24:46 +01:00
|
|
|
template <>
|
2015-08-21 19:08:41 +02:00
|
|
|
bool __ParseString<CGUISpriteInstance>(const CStrW& Value, CGUISpriteInstance& Output)
|
2004-12-15 22:24:46 +01:00
|
|
|
{
|
2011-02-17 21:08:20 +01:00
|
|
|
Output = CGUISpriteInstance(Value.ToUTF8());
|
2004-12-15 22:24:46 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2005-04-24 01:20:50 +02:00
|
|
|
template <>
|
2010-05-30 15:11:32 +02:00
|
|
|
bool __ParseString<CGUIList>(const CStrW& UNUSED(Value), CGUIList& UNUSED(Output))
|
2005-04-24 01:20:50 +02:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-12-07 20:03:54 +01:00
|
|
|
template <>
|
|
|
|
bool __ParseString<CGUISeries>(const CStrW& UNUSED(Value), CGUISeries& UNUSED(Output))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2005-04-24 01:20:50 +02:00
|
|
|
|
2005-02-05 08:25:16 +01:00
|
|
|
//--------------------------------------------------------
|
|
|
|
|
2012-01-29 21:04:21 +01:00
|
|
|
CMatrix3D GetDefaultGuiMatrix()
|
2005-02-05 08:25:16 +01:00
|
|
|
{
|
2017-06-14 19:13:44 +02:00
|
|
|
float xres = g_xres / g_GuiScale;
|
|
|
|
float yres = g_yres / g_GuiScale;
|
2015-01-24 21:06:37 +01:00
|
|
|
|
2012-01-29 21:04:21 +01:00
|
|
|
CMatrix3D m;
|
|
|
|
m.SetIdentity();
|
|
|
|
m.Scale(1.0f, -1.f, 1.0f);
|
2015-01-24 21:06:37 +01:00
|
|
|
m.Translate(0.0f, yres, -1000.0f);
|
2012-02-08 21:43:38 +01:00
|
|
|
|
|
|
|
CMatrix3D proj;
|
2015-01-24 21:06:37 +01:00
|
|
|
proj.SetOrtho(0.f, xres, 0.f, yres, -1.f, 1000.f);
|
2012-02-08 21:43:38 +01:00
|
|
|
m = proj * m;
|
|
|
|
|
2012-01-29 21:04:21 +01:00
|
|
|
return m;
|
2005-02-05 08:25:16 +01:00
|
|
|
}
|
|
|
|
|
2003-11-06 12:54:46 +01:00
|
|
|
//--------------------------------------------------------
|
|
|
|
// Utilities implementation
|
|
|
|
//--------------------------------------------------------
|
2015-08-21 19:08:41 +02:00
|
|
|
IGUIObject* CInternalCGUIAccessorBase::GetObjectPointer(CGUI& GUIinstance, const CStr& Object)
|
2003-11-06 01:21:45 +01:00
|
|
|
{
|
2015-08-21 19:08:41 +02:00
|
|
|
return GUIinstance.FindObjectByName(Object);
|
2003-11-06 01:21:45 +01:00
|
|
|
}
|
|
|
|
|
2015-08-21 19:08:41 +02:00
|
|
|
const IGUIObject* CInternalCGUIAccessorBase::GetObjectPointer(const CGUI& GUIinstance, const CStr& Object)
|
2003-11-06 01:21:45 +01:00
|
|
|
{
|
2015-08-21 19:08:41 +02:00
|
|
|
return GUIinstance.FindObjectByName(Object);
|
2003-11-24 18:13:37 +01:00
|
|
|
}
|
2003-11-25 04:21:11 +01:00
|
|
|
|
2015-08-21 19:08:41 +02:00
|
|
|
void CInternalCGUIAccessorBase::QueryResetting(IGUIObject* pObject)
|
2003-11-25 04:21:11 +01:00
|
|
|
{
|
2003-12-01 08:06:55 +01:00
|
|
|
GUI<>::RecurseObject(0, pObject, &IGUIObject::ResetStates);
|
2003-11-25 04:21:11 +01:00
|
|
|
}
|
2003-12-27 08:23:47 +01:00
|
|
|
|
2015-08-21 19:08:41 +02:00
|
|
|
void CInternalCGUIAccessorBase::HandleMessage(IGUIObject* pObject, SGUIMessage& message)
|
2003-12-27 08:23:47 +01:00
|
|
|
{
|
2011-04-28 22:42:11 +02:00
|
|
|
pObject->HandleMessage(message);
|
2003-12-27 08:23:47 +01:00
|
|
|
}
|
2004-09-03 23:25:39 +02:00
|
|
|
|
|
|
|
|
2004-12-17 01:05:37 +01:00
|
|
|
|
2004-12-08 19:15:39 +01:00
|
|
|
#ifndef NDEBUG
|
|
|
|
#define TYPE(T) \
|
|
|
|
template<> void CheckType<T>(const IGUIObject* obj, const CStr& setting) { \
|
2009-07-28 18:59:19 +02:00
|
|
|
std::map<CStr, SGUISetting>::const_iterator it = obj->m_Settings.find(setting); \
|
|
|
|
if (it == obj->m_Settings.end() || it->second.m_Type != GUIST_##T) \
|
2004-12-08 19:15:39 +01:00
|
|
|
{ \
|
2004-12-21 19:41:58 +01:00
|
|
|
/* Abort now, to avoid corrupting everything by invalidly \
|
|
|
|
casting pointers */ \
|
2008-01-19 12:33:11 +01:00
|
|
|
DEBUG_DISPLAY_ERROR(L"FATAL ERROR: Inconsistent types in GUI"); \
|
2004-12-08 19:15:39 +01:00
|
|
|
} \
|
|
|
|
}
|
2004-12-17 01:05:37 +01:00
|
|
|
#include "GUItypes.h"
|
2004-12-08 19:15:39 +01:00
|
|
|
#undef TYPE
|
|
|
|
#endif
|
2004-12-17 01:05:37 +01:00
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
2007-06-15 19:03:26 +02:00
|
|
|
|
2004-12-17 01:05:37 +01:00
|
|
|
template <typename T>
|
2015-08-21 19:08:41 +02:00
|
|
|
PSRETURN GUI<T>::GetSettingPointer(const IGUIObject* pObject, const CStr& Setting, T*& Value)
|
2004-12-17 01:05:37 +01:00
|
|
|
{
|
2011-04-30 15:01:45 +02:00
|
|
|
ENSURE(pObject != NULL);
|
2004-12-17 01:05:37 +01:00
|
|
|
|
2007-06-15 19:03:26 +02:00
|
|
|
std::map<CStr, SGUISetting>::const_iterator it = pObject->m_Settings.find(Setting);
|
|
|
|
if (it == pObject->m_Settings.end())
|
2009-09-27 17:04:46 +02:00
|
|
|
{
|
2015-08-21 19:08:41 +02:00
|
|
|
LOGWARNING("setting %s was not found on object %s",
|
2009-09-27 17:04:46 +02:00
|
|
|
Setting.c_str(),
|
|
|
|
pObject->GetPresentableName().c_str());
|
|
|
|
return PSRETURN_GUI_InvalidSetting;
|
|
|
|
}
|
2004-12-17 01:05:37 +01:00
|
|
|
|
2007-06-15 19:03:26 +02:00
|
|
|
if (it->second.m_pSetting == NULL)
|
2009-09-27 17:04:46 +02:00
|
|
|
return PSRETURN_GUI_InvalidSetting;
|
2004-12-17 01:05:37 +01:00
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
CheckType<T>(pObject, Setting);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Get value
|
2007-06-15 19:03:26 +02:00
|
|
|
Value = (T*)(it->second.m_pSetting);
|
2004-12-17 01:05:37 +01:00
|
|
|
|
2009-09-27 17:04:46 +02:00
|
|
|
return PSRETURN_OK;
|
2004-12-17 01:05:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2015-08-21 19:08:41 +02:00
|
|
|
PSRETURN GUI<T>::GetSetting(const IGUIObject* pObject, const CStr& Setting, T& Value)
|
2004-12-17 01:05:37 +01:00
|
|
|
{
|
2010-02-03 20:43:39 +01:00
|
|
|
T* v = NULL;
|
2009-09-27 17:04:46 +02:00
|
|
|
PSRETURN ret = GetSettingPointer(pObject, Setting, v);
|
|
|
|
if (ret == PSRETURN_OK)
|
2004-12-17 01:05:37 +01:00
|
|
|
Value = *v;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-01-27 20:20:34 +01:00
|
|
|
// Helper function for SetSetting
|
|
|
|
template <typename T>
|
|
|
|
bool IsBoolTrue(const T&)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
template <>
|
|
|
|
bool IsBoolTrue<bool>(const bool& v)
|
|
|
|
{
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2004-12-17 01:05:37 +01:00
|
|
|
template <typename T>
|
2015-08-21 19:08:41 +02:00
|
|
|
PSRETURN GUI<T>::SetSetting(IGUIObject* pObject, const CStr& Setting, const T& Value, const bool& SkipMessage)
|
2004-12-17 01:05:37 +01:00
|
|
|
{
|
2011-04-30 15:01:45 +02:00
|
|
|
ENSURE(pObject != NULL);
|
2004-12-17 01:05:37 +01:00
|
|
|
|
|
|
|
if (!pObject->SettingExists(Setting))
|
2009-09-27 17:04:46 +02:00
|
|
|
{
|
2015-08-21 19:08:41 +02:00
|
|
|
LOGWARNING("setting %s was not found on object %s",
|
2009-09-27 17:04:46 +02:00
|
|
|
Setting.c_str(),
|
|
|
|
pObject->GetPresentableName().c_str());
|
|
|
|
return PSRETURN_GUI_InvalidSetting;
|
|
|
|
}
|
2004-12-17 01:05:37 +01:00
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
CheckType<T>(pObject, Setting);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Set value
|
|
|
|
*(T*)pObject->m_Settings[Setting].m_pSetting = Value;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Some settings needs special attention at change
|
|
|
|
//
|
|
|
|
|
|
|
|
// If setting was "size", we need to re-cache itself and all children
|
2004-12-19 13:20:04 +01:00
|
|
|
if (Setting == "size")
|
2004-12-17 01:05:37 +01:00
|
|
|
{
|
|
|
|
RecurseObject(0, pObject, &IGUIObject::UpdateCachedSize);
|
|
|
|
}
|
2015-08-21 19:08:41 +02:00
|
|
|
else if (Setting == "hidden")
|
2004-12-19 13:20:04 +01:00
|
|
|
{
|
|
|
|
// Hiding an object requires us to reset it and all children
|
2010-01-27 20:20:34 +01:00
|
|
|
if (IsBoolTrue(Value))
|
|
|
|
QueryResetting(pObject);
|
2004-12-19 13:20:04 +01:00
|
|
|
}
|
2004-12-17 01:05:37 +01:00
|
|
|
|
2005-02-05 08:25:16 +01:00
|
|
|
if (!SkipMessage)
|
2011-04-28 22:42:11 +02:00
|
|
|
{
|
|
|
|
SGUIMessage msg(GUIM_SETTINGS_UPDATED, Setting);
|
|
|
|
HandleMessage(pObject, msg);
|
|
|
|
}
|
2004-12-17 01:05:37 +01:00
|
|
|
|
2009-09-27 17:04:46 +02:00
|
|
|
return PSRETURN_OK;
|
2004-12-17 01:05:37 +01:00
|
|
|
}
|
|
|
|
|
2004-12-17 17:20:08 +01:00
|
|
|
// Instantiate templated functions:
|
2004-12-17 01:05:37 +01:00
|
|
|
#define TYPE(T) \
|
2015-08-21 19:08:41 +02:00
|
|
|
template PSRETURN GUI<T>::GetSettingPointer(const IGUIObject* pObject, const CStr& Setting, T*& Value); \
|
|
|
|
template PSRETURN GUI<T>::GetSetting(const IGUIObject* pObject, const CStr& Setting, T& Value); \
|
|
|
|
template PSRETURN GUI<T>::SetSetting(IGUIObject* pObject, const CStr& Setting, const T& Value, const bool& SkipMessage);
|
2004-12-17 01:05:37 +01:00
|
|
|
#define GUITYPE_IGNORE_CGUISpriteInstance
|
|
|
|
#include "GUItypes.h"
|
2010-02-18 01:06:50 +01:00
|
|
|
#undef GUITYPE_IGNORE_CGUISpriteInstance
|
|
|
|
#undef TYPE
|
2004-12-17 01:05:37 +01:00
|
|
|
|
|
|
|
// Don't instantiate GetSetting<CGUISpriteInstance> - this will cause linker errors if
|
|
|
|
// you attempt to retrieve a sprite using GetSetting, since that copies the sprite
|
|
|
|
// and will mess up the caching performed by DrawSprite. You have to use GetSettingPointer
|
|
|
|
// instead. (This is mainly useful to stop me accidentally using the wrong function.)
|
2015-08-21 19:08:41 +02:00
|
|
|
template PSRETURN GUI<CGUISpriteInstance>::GetSettingPointer(const IGUIObject* pObject, const CStr& Setting, CGUISpriteInstance*& Value);
|
|
|
|
template PSRETURN GUI<CGUISpriteInstance>::SetSetting(IGUIObject* pObject, const CStr& Setting, const CGUISpriteInstance& Value, const bool& SkipMessage);
|