2019-07-19 23:15:04 +02:00
|
|
|
/* Copyright (C) 2019 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/>.
|
|
|
|
*/
|
|
|
|
|
2003-11-06 01:21:45 +01:00
|
|
|
/*
|
|
|
|
Contains help class GUI<>, which gives us templated
|
|
|
|
parameter to all functions within GUI.
|
|
|
|
*/
|
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
#ifndef INCLUDED_GUIUTIL
|
|
|
|
#define INCLUDED_GUIUTIL
|
2003-11-06 01:21:45 +01:00
|
|
|
|
2019-07-26 20:57:28 +02:00
|
|
|
#include "gui/IGUIObject.h"
|
2003-11-06 01:21:45 +01:00
|
|
|
|
2019-07-29 00:40:58 +02:00
|
|
|
#include <functional>
|
|
|
|
|
2019-08-25 10:57:36 +02:00
|
|
|
class CGUI;
|
2019-08-04 04:20:08 +02:00
|
|
|
template<typename T> class GUI;
|
|
|
|
|
|
|
|
class IGUISetting
|
|
|
|
{
|
|
|
|
public:
|
Use NONCOPYABLE for most GUI classes and structs to have the compiler indicate unintended copies, refs 3028551b91 / D2163.
That is CChartData, CGUIList, CGUISeries, COListColumn, GUITooltip,
SGUIMessage, SSpriteCall, STextCall, SFeedback, IGUISetting,
CGUISetting, GUI, IGUIObject, IGUIScrollBar.
Drop copying GetSetting and SetSetting template functions for CGUIList,
CGUISeries, CClientArea, CGUIString.
Stop copying COListColumn.
Drop copying GUI<CClientArea>::GetSetting call in
IGUIObject::UpdateCachedSize() and four copying
GUI<CGUIString>::GetSetting calls in SetupText() functions.
Delete unused GUIRenderer IGLState class from 849f50a500 obsolete since
1f5b8f1c9a.
Differential Revision: https://code.wildfiregames.com/D2164
This was SVN commit r22638.
2019-08-10 02:04:17 +02:00
|
|
|
NONCOPYABLE(IGUISetting);
|
|
|
|
|
|
|
|
IGUISetting() = default;
|
|
|
|
virtual ~IGUISetting() = default;
|
2019-08-04 04:20:08 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Parses the given string and assigns to the setting value. Used for parsing XML attributes.
|
|
|
|
*/
|
|
|
|
virtual bool FromString(const CStrW& Value, const bool& SkipMessage) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parses the given JS::Value using ScriptInterface::FromJSVal and assigns it to the setting data.
|
|
|
|
*/
|
|
|
|
virtual bool FromJSVal(JSContext* cx, JS::HandleValue Value) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts the setting data to a JS::Value using ScriptInterface::ToJSVal.
|
|
|
|
*/
|
|
|
|
virtual void ToJSVal(JSContext* cx, JS::MutableHandleValue Value) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
class CGUISetting : public IGUISetting
|
|
|
|
{
|
|
|
|
friend class GUI<T>;
|
|
|
|
|
|
|
|
public:
|
Use NONCOPYABLE for most GUI classes and structs to have the compiler indicate unintended copies, refs 3028551b91 / D2163.
That is CChartData, CGUIList, CGUISeries, COListColumn, GUITooltip,
SGUIMessage, SSpriteCall, STextCall, SFeedback, IGUISetting,
CGUISetting, GUI, IGUIObject, IGUIScrollBar.
Drop copying GetSetting and SetSetting template functions for CGUIList,
CGUISeries, CClientArea, CGUIString.
Stop copying COListColumn.
Drop copying GUI<CClientArea>::GetSetting call in
IGUIObject::UpdateCachedSize() and four copying
GUI<CGUIString>::GetSetting calls in SetupText() functions.
Delete unused GUIRenderer IGLState class from 849f50a500 obsolete since
1f5b8f1c9a.
Differential Revision: https://code.wildfiregames.com/D2164
This was SVN commit r22638.
2019-08-10 02:04:17 +02:00
|
|
|
NONCOPYABLE(CGUISetting);
|
|
|
|
|
2019-08-04 04:20:08 +02:00
|
|
|
CGUISetting(IGUIObject& pObject, const CStr& Name);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parses the given string and assigns to the setting value. Used for parsing XML attributes.
|
|
|
|
*/
|
|
|
|
bool FromString(const CStrW& Value, const bool& SkipMessage) override;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parses the given JS::Value using ScriptInterface::FromJSVal and assigns it to the setting data.
|
|
|
|
*/
|
|
|
|
bool FromJSVal(JSContext* cx, JS::HandleValue Value) override;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts the setting data to a JS::Value using ScriptInterface::ToJSVal.
|
|
|
|
*/
|
|
|
|
void ToJSVal(JSContext* cx, JS::MutableHandleValue Value) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The object that stores this setting.
|
|
|
|
*/
|
|
|
|
IGUIObject& m_pObject;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Property name identifying the setting.
|
|
|
|
*/
|
|
|
|
const CStr m_Name;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Holds the value of the setting..
|
|
|
|
*/
|
|
|
|
T m_pSetting;
|
|
|
|
};
|
2003-11-24 18:13:37 +01:00
|
|
|
|
2003-11-18 11:00:57 +01:00
|
|
|
/**
|
|
|
|
* Includes static functions that needs one template
|
|
|
|
* argument.
|
|
|
|
*/
|
2019-08-25 10:57:36 +02:00
|
|
|
template <typename T>
|
2019-07-28 04:39:52 +02:00
|
|
|
class GUI
|
2003-11-06 01:21:45 +01:00
|
|
|
{
|
|
|
|
public:
|
Use NONCOPYABLE for most GUI classes and structs to have the compiler indicate unintended copies, refs 3028551b91 / D2163.
That is CChartData, CGUIList, CGUISeries, COListColumn, GUITooltip,
SGUIMessage, SSpriteCall, STextCall, SFeedback, IGUISetting,
CGUISetting, GUI, IGUIObject, IGUIScrollBar.
Drop copying GetSetting and SetSetting template functions for CGUIList,
CGUISeries, CClientArea, CGUIString.
Stop copying COListColumn.
Drop copying GUI<CClientArea>::GetSetting call in
IGUIObject::UpdateCachedSize() and four copying
GUI<CGUIString>::GetSetting calls in SetupText() functions.
Delete unused GUIRenderer IGLState class from 849f50a500 obsolete since
1f5b8f1c9a.
Differential Revision: https://code.wildfiregames.com/D2164
This was SVN commit r22638.
2019-08-10 02:04:17 +02:00
|
|
|
NONCOPYABLE(GUI);
|
2004-12-17 01:05:37 +01:00
|
|
|
|
2019-08-19 12:32:29 +02:00
|
|
|
/**
|
|
|
|
* Get a mutable reference to the setting.
|
|
|
|
* If no such setting exists, an exception of type std::out_of_range is thrown.
|
2019-08-25 10:57:36 +02:00
|
|
|
* Use SettingExists if a safeguard is needed.
|
2019-08-19 12:32:29 +02:00
|
|
|
*
|
|
|
|
* If the value is modified, there is no GUIM_SETTINGS_UPDATED message sent.
|
|
|
|
* SetSetting should be used to modify the value if there is a use for the message.
|
|
|
|
*/
|
|
|
|
static T& GetSetting(const IGUIObject* pObject, const CStr& Setting);
|
|
|
|
|
2003-11-18 11:00:57 +01:00
|
|
|
/**
|
2003-11-25 03:47:12 +01:00
|
|
|
* Sets a value by name using a real datatype as input.
|
2019-07-29 00:40:58 +02:00
|
|
|
* This variant will use the move-assignment.
|
|
|
|
*
|
2003-11-18 11:00:57 +01:00
|
|
|
* @param pObject Object pointer
|
|
|
|
* @param Setting Setting by name
|
|
|
|
* @param Value Sets value to this, note type T!
|
2005-02-05 08:25:16 +01:00
|
|
|
* @param SkipMessage Does not send a GUIM_SETTINGS_UPDATED if true
|
2003-11-18 11:00:57 +01:00
|
|
|
*/
|
2019-07-29 00:40:58 +02:00
|
|
|
static PSRETURN SetSetting(IGUIObject* pObject, const CStr& Setting, T& Value, const bool& SkipMessage = false);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This variant will copy the value.
|
|
|
|
*/
|
2015-08-21 19:08:41 +02:00
|
|
|
static PSRETURN SetSetting(IGUIObject* pObject, const CStr& Setting, const T& Value, const bool& SkipMessage = false);
|
2003-11-06 01:21:45 +01:00
|
|
|
|
2003-12-01 08:06:55 +01:00
|
|
|
/**
|
2015-08-21 19:08:41 +02:00
|
|
|
* Sets a value by setting and object name using a real
|
2003-12-01 08:06:55 +01:00
|
|
|
* datatype as input.
|
|
|
|
*
|
|
|
|
* @param Value The value in string form, like "0 0 100% 100%"
|
|
|
|
* @param tOutput Parsed value of type T
|
|
|
|
* @return True at success.
|
|
|
|
*/
|
2019-08-19 21:43:13 +02:00
|
|
|
static bool ParseString(const CGUI* pGUI, const CStrW& Value, T& tOutput);
|
2003-12-01 08:06:55 +01:00
|
|
|
|
|
|
|
private:
|
2003-11-06 01:21:45 +01:00
|
|
|
|
2019-07-29 00:40:58 +02:00
|
|
|
/**
|
|
|
|
* Changes the value of the setting by calling the valueSet functon that performs either a copy or move assignment.
|
|
|
|
* Updates some internal data depending on the setting changed.
|
|
|
|
*/
|
2019-08-20 12:51:29 +02:00
|
|
|
static PSRETURN SetSettingWrap(IGUIObject* pObject, const CStr& Setting, const bool& SkipMessage, const std::function<void()>& valueSet);
|
2003-11-06 01:21:45 +01:00
|
|
|
};
|
|
|
|
|
2015-08-21 19:08:41 +02:00
|
|
|
#endif // INCLUDED_GUIUTIL
|