2019-01-13 16:38:41 +01: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
|
|
|
/*
|
|
|
|
GUI Core, stuff that the whole GUI uses
|
|
|
|
|
|
|
|
--Overview--
|
|
|
|
|
2015-08-21 19:08:41 +02:00
|
|
|
Contains defines, includes, types etc that the whole
|
2003-11-06 01:21:45 +01:00
|
|
|
GUI should have included.
|
|
|
|
|
|
|
|
--More info--
|
|
|
|
|
2003-11-25 03:47:12 +01:00
|
|
|
Check GUI.h
|
2003-11-06 01:21:45 +01:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
#ifndef INCLUDED_GUIBASE
|
|
|
|
#define INCLUDED_GUIBASE
|
2003-11-06 01:21:45 +01:00
|
|
|
|
2004-12-19 00:30:28 +01:00
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
2003-11-06 01:21:45 +01:00
|
|
|
|
2019-07-26 20:57:28 +02:00
|
|
|
#include "gui/CGUIColor.h"
|
2015-08-21 19:08:41 +02:00
|
|
|
#include "ps/CStr.h"
|
|
|
|
#include "ps/Errors.h"
|
2004-08-31 04:09:58 +02:00
|
|
|
// I would like to just forward declare CSize, but it doesn't
|
|
|
|
// seem to be defined anywhere in the predefined header.
|
2015-03-15 19:06:32 +01:00
|
|
|
#include "ps/Shapes.h"
|
2019-07-26 16:47:27 +02:00
|
|
|
#include "scriptinterface/ScriptInterface.h"
|
2004-08-31 04:09:58 +02:00
|
|
|
|
2003-11-24 03:18:41 +01:00
|
|
|
class IGUIObject;
|
2003-11-06 01:21:45 +01:00
|
|
|
|
2003-12-27 07:26:03 +01:00
|
|
|
// Object settings setups
|
2003-11-06 01:21:45 +01:00
|
|
|
// Setup an object's ConstructObject function
|
|
|
|
#define GUI_OBJECT(obj) \
|
|
|
|
public: \
|
2019-08-01 22:20:24 +02:00
|
|
|
static IGUIObject* ConstructObject(CGUI* pGUI) \
|
|
|
|
{ return new obj(pGUI); }
|
2003-11-06 01:21:45 +01:00
|
|
|
|
2010-07-29 17:55:41 +02:00
|
|
|
|
2015-08-21 19:08:41 +02:00
|
|
|
/**
|
2010-07-29 17:55:41 +02:00
|
|
|
* Message types.
|
2003-12-27 07:26:03 +01:00
|
|
|
* @see SGUIMessage
|
2003-11-18 11:00:57 +01:00
|
|
|
*/
|
2003-12-27 07:26:03 +01:00
|
|
|
enum EGUIMessageType
|
2003-11-06 01:21:45 +01:00
|
|
|
{
|
|
|
|
GUIM_MOUSE_OVER,
|
|
|
|
GUIM_MOUSE_ENTER,
|
|
|
|
GUIM_MOUSE_LEAVE,
|
|
|
|
GUIM_MOUSE_PRESS_LEFT,
|
2017-06-29 04:58:04 +02:00
|
|
|
GUIM_MOUSE_PRESS_LEFT_ITEM,
|
2003-11-06 01:21:45 +01:00
|
|
|
GUIM_MOUSE_PRESS_RIGHT,
|
|
|
|
GUIM_MOUSE_DOWN_LEFT,
|
|
|
|
GUIM_MOUSE_DOWN_RIGHT,
|
2006-01-21 12:07:25 +01:00
|
|
|
GUIM_MOUSE_DBLCLICK_LEFT,
|
2015-11-16 19:23:21 +01:00
|
|
|
GUIM_MOUSE_DBLCLICK_LEFT_ITEM, // Triggered when doubleclicking on a list item
|
2006-01-21 12:07:25 +01:00
|
|
|
GUIM_MOUSE_DBLCLICK_RIGHT,
|
2003-11-06 01:21:45 +01:00
|
|
|
GUIM_MOUSE_RELEASE_LEFT,
|
|
|
|
GUIM_MOUSE_RELEASE_RIGHT,
|
2003-12-27 07:26:03 +01:00
|
|
|
GUIM_MOUSE_WHEEL_UP,
|
|
|
|
GUIM_MOUSE_WHEEL_DOWN,
|
|
|
|
GUIM_SETTINGS_UPDATED, // SGUIMessage.m_Value = name of setting
|
|
|
|
GUIM_PRESSED,
|
2016-12-07 20:18:57 +01:00
|
|
|
GUIM_RELEASED,
|
2011-06-06 21:39:19 +02:00
|
|
|
GUIM_DOUBLE_PRESSED,
|
2004-05-29 06:06:50 +02:00
|
|
|
GUIM_MOUSE_MOTION,
|
2004-10-14 12:09:26 +02:00
|
|
|
GUIM_LOAD, // Called when an object is added to the GUI.
|
|
|
|
GUIM_GOT_FOCUS,
|
2013-01-03 23:53:46 +01:00
|
|
|
GUIM_LOST_FOCUS,
|
|
|
|
GUIM_PRESSED_MOUSE_RIGHT,
|
2014-01-01 01:23:18 +01:00
|
|
|
GUIM_DOUBLE_PRESSED_MOUSE_RIGHT,
|
2017-09-01 14:06:18 +02:00
|
|
|
GUIM_TAB, // Used by CInput
|
|
|
|
GUIM_TEXTEDIT
|
2003-12-27 07:26:03 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Message send to IGUIObject::HandleMessage() in order
|
|
|
|
* to give life to Objects manually with
|
|
|
|
* a derived HandleMessage().
|
|
|
|
*/
|
|
|
|
struct SGUIMessage
|
|
|
|
{
|
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
|
|
|
// This should be passed as a const reference or pointer.
|
|
|
|
NONCOPYABLE(SGUIMessage);
|
|
|
|
|
2011-04-28 22:42:11 +02:00
|
|
|
SGUIMessage(EGUIMessageType _type) : type(_type), skipped(false) {}
|
|
|
|
SGUIMessage(EGUIMessageType _type, const CStr& _value) : type(_type), value(_value), skipped(false) {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method can be used to allow other event handlers to process this GUI event,
|
|
|
|
* by default an event is not skipped (only the first handler will process it).
|
|
|
|
*
|
|
|
|
* @param skip true to allow further event handling, false to prevent it
|
|
|
|
*/
|
|
|
|
void Skip(bool skip = true) { skipped = skip; }
|
2003-12-27 07:26:03 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Describes what the message regards
|
|
|
|
*/
|
|
|
|
EGUIMessageType type;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Optional data
|
|
|
|
*/
|
|
|
|
CStr value;
|
2011-04-28 22:42:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Flag that specifies if object skipped handling the event
|
|
|
|
*/
|
|
|
|
bool skipped;
|
2003-11-06 01:21:45 +01:00
|
|
|
};
|
|
|
|
|
2003-11-18 11:00:57 +01:00
|
|
|
/**
|
|
|
|
* Recurse restrictions, when we recurse, if an object
|
|
|
|
* is hidden for instance, you might want it to skip
|
|
|
|
* the children also
|
|
|
|
* Notice these are flags! and we don't really need one
|
|
|
|
* for no restrictions, because then you'll just enter 0
|
|
|
|
*/
|
2003-11-06 01:21:45 +01:00
|
|
|
enum
|
|
|
|
{
|
2003-12-27 07:26:03 +01:00
|
|
|
GUIRR_HIDDEN = 0x00000001,
|
|
|
|
GUIRR_DISABLED = 0x00000010,
|
|
|
|
GUIRR_GHOST = 0x00000100
|
2003-11-06 01:21:45 +01:00
|
|
|
};
|
|
|
|
|
2004-09-02 05:02:32 +02:00
|
|
|
// Text alignments
|
|
|
|
enum EAlign { EAlign_Left, EAlign_Right, EAlign_Center };
|
|
|
|
enum EVAlign { EVAlign_Top, EVAlign_Bottom, EVAlign_Center };
|
|
|
|
|
2003-11-06 01:21:45 +01:00
|
|
|
// Typedefs
|
2003-11-24 03:18:41 +01:00
|
|
|
typedef std::map<CStr, IGUIObject*> map_pObjects;
|
2003-11-24 18:13:37 +01:00
|
|
|
typedef std::vector<IGUIObject*> vector_pObjects;
|
2003-11-06 01:21:45 +01:00
|
|
|
|
2006-01-29 19:23:47 +01:00
|
|
|
// Icon, you create them in the XML file with root element <setup>
|
|
|
|
// you use them in text owned by different objects... Such as CText.
|
|
|
|
struct SGUIIcon
|
|
|
|
{
|
MOVABLE idiom, const CGUI struct maps, in place move construction instead of copying temporaries during CGUI XML loading and GenerateText.
Introduce MOVABLE idiom indicating that a class can use move semantics.
Make values of CGUI struct maps holding XML data const to ensure at the
root that the data is not modified.
Use NONCOPYABLE and MOVABLE for SGUIIcon and SGUIStyle to enforce the
non-copy policy on the compiler level (until someone changes the GUI
design to make modifications needed).
As indicated by that:
Replace copy operations by in place move operations for these CGUI
struct maps in the CGUI Xeromyces XML loading functions.
Replace copy operations by const references for CSize and SGUIIcon in
CGUIString::GenerateTextCall and CGUI::GenerateText.
This avoids copying of non primitive members, such as the strings and
containers of strings.
Further related cleanup to be kept separated for auditability.
Differential Revision: https://code.wildfiregames.com/D2163
Few comments on IRC by: wraitii, Itms
Tested on: gcc 9, Jenkins, partially VS2015
Refs #1984,
NONCOPYABLE CGUISpriteInstances: 0a7d0ecdde, 8f4f8e240f, c19f3608a5
NONCOPYABLE Image, Sprite: fb8032043b
NONCOPYABLE GUI page: 94c57085e9
NONCOPYABLE GUIManager: 7c2e9027c2
NONCOPYABLE macro: 16ccae10cd
This was SVN commit r22637.
2019-08-09 19:25:55 +02:00
|
|
|
// This struct represents an immutable type, so ensure to avoid copying the strings.
|
|
|
|
NONCOPYABLE(SGUIIcon);
|
|
|
|
MOVABLE(SGUIIcon);
|
|
|
|
|
2006-01-29 19:23:47 +01:00
|
|
|
SGUIIcon() : m_CellID(0) {}
|
|
|
|
|
|
|
|
// Sprite name of icon
|
|
|
|
CStr m_SpriteName;
|
|
|
|
|
|
|
|
// Size
|
|
|
|
CSize m_Size;
|
|
|
|
|
|
|
|
// Cell of texture to use; ignored unless the texture has specified cell-size
|
|
|
|
int m_CellID;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Client Area is a rectangle relative to a parent rectangle
|
|
|
|
*
|
|
|
|
* You can input the whole value of the Client Area by
|
|
|
|
* string. Like used in the GUI.
|
|
|
|
*/
|
|
|
|
class CClientArea
|
|
|
|
{
|
|
|
|
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
|
|
|
// COPYABLE, since there are only primitives involved, making move and copy identical,
|
|
|
|
// and since some temporaries cannot be avoided.
|
2006-01-29 19:23:47 +01:00
|
|
|
CClientArea();
|
|
|
|
CClientArea(const CStr& Value);
|
2009-12-03 21:17:22 +01:00
|
|
|
CClientArea(const CRect& pixel, const CRect& percent);
|
2006-01-29 19:23:47 +01:00
|
|
|
|
|
|
|
/// Pixel modifiers
|
|
|
|
CRect pixel;
|
|
|
|
|
|
|
|
/// Percent modifiers
|
|
|
|
CRect percent;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get client area rectangle when the parent is given
|
|
|
|
*/
|
2015-08-21 19:08:41 +02:00
|
|
|
CRect GetClientArea(const CRect& parent) const;
|
2006-01-29 19:23:47 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The ClientArea can be set from a string looking like:
|
|
|
|
*
|
|
|
|
* "0 0 100% 100%"
|
|
|
|
* "50%-10 50%-10 50%+10 50%+10"
|
2015-08-21 19:08:41 +02:00
|
|
|
*
|
2006-01-29 19:23:47 +01:00
|
|
|
* i.e. First percent modifier, then + or - and the pixel modifier.
|
|
|
|
* Although you can use just the percent or the pixel modifier. Notice
|
|
|
|
* though that the percent modifier must always be the first when
|
|
|
|
* both modifiers are inputted.
|
|
|
|
*
|
|
|
|
* @return true if success, false if failure. If false then the client area
|
|
|
|
* will be unchanged.
|
|
|
|
*/
|
|
|
|
bool SetClientArea(const CStr& Value);
|
2013-11-02 15:39:08 +01:00
|
|
|
|
|
|
|
bool operator==(const CClientArea& other) const
|
|
|
|
{
|
|
|
|
return pixel == other.pixel && percent == other.percent;
|
|
|
|
}
|
2019-07-26 16:47:27 +02:00
|
|
|
|
|
|
|
void ToJSVal(JSContext* cx, JS::MutableHandleValue ret) const;
|
|
|
|
bool FromJSVal(JSContext* cx, JS::HandleValue v);
|
2006-01-29 19:23:47 +01:00
|
|
|
};
|
|
|
|
|
2015-08-21 19:08:41 +02:00
|
|
|
|
2009-09-23 23:16:55 +02:00
|
|
|
ERROR_GROUP(GUI);
|
|
|
|
|
|
|
|
ERROR_TYPE(GUI, InvalidSetting);
|
|
|
|
ERROR_TYPE(GUI, OperationNeedsGUIObject);
|
|
|
|
ERROR_TYPE(GUI, NameAmbiguity);
|
|
|
|
ERROR_TYPE(GUI, ObjectNeedsName);
|
2003-11-06 01:21:45 +01:00
|
|
|
|
2015-08-21 19:08:41 +02:00
|
|
|
#endif // INCLUDED_GUIBASE
|