1
0
forked from 0ad/0ad

Move GUIbase structs and enums to separate files.

Differential Revision: https://code.wildfiregames.com/D2340
Tested on: clang 8.0.1, Jenkins

This was SVN commit r23022.
This commit is contained in:
elexis 2019-10-01 12:46:55 +00:00
parent 8190293f8b
commit 07cc1ba34c
10 changed files with 224 additions and 137 deletions

View File

@ -25,8 +25,9 @@
#include "gui/CGUIColor.h"
#include "gui/CGUIDummyObject.h"
#include "gui/GUIbase.h"
#include "gui/GUITooltip.h"
#include "gui/SGUIIcon.h"
#include "gui/SGUIStyle.h"
#include "lib/input.h"
#include "ps/Shapes.h"
#include "ps/XML/Xeromyces.h"
@ -40,21 +41,9 @@ ERROR_TYPE(GUI, JSOpenFailed);
extern const double SELECT_DBLCLICK_RATE;
/**
* Contains a list of values for new defaults to objects.
*/
struct SGUIStyle
{
// Take advantage of moving the entire map instead and avoiding unintended copies.
NONCOPYABLE(SGUIStyle);
MOVABLE(SGUIStyle);
SGUIStyle() = default;
std::map<CStr, CStrW> m_SettingsDefaults;
};
class CGUISpriteInstance;
class CGUISprite;
class IGUIObject;
struct SGUIImageEffects;
struct SGUIScrollBarStyle;

View File

@ -20,6 +20,7 @@
#include "gui/CGUIColor.h"
#include "gui/CGUISprite.h"
#include "gui/EAlign.h"
#include "ps/CStrIntern.h"
#include "ps/Shapes.h"
@ -29,7 +30,9 @@
class CGUI;
class CGUIString;
class IGUIObject;
struct SGenerateTextImage;
using SGenerateTextImages = std::array<std::vector<SGenerateTextImage>, 2>;
/**

24
source/gui/EAlign.h Normal file
View File

@ -0,0 +1,24 @@
/* Copyright (C) 2019 Wildfire Games.
* 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/>.
*/
#ifndef INCLUDED_EALIGN
#define INCLUDED_EALIGN
enum EAlign { EAlign_Left, EAlign_Right, EAlign_Center };
enum EVAlign { EVAlign_Top, EVAlign_Bottom, EVAlign_Center };
#endif // INCLUDED_EALIGN

View File

@ -15,13 +15,6 @@
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
*/
/*
GUI Core, stuff that the whole GUI uses
Contains defines, includes, types etc that the whole
GUI should have included.
*/
#ifndef INCLUDED_GUIBASE
#define INCLUDED_GUIBASE
@ -30,118 +23,6 @@ GUI Core, stuff that the whole GUI uses
#include "ps/Shapes.h"
#include "scriptinterface/ScriptInterface.h"
#include <map>
#include <vector>
class CGUI;
class IGUIObject;
#define GUI_OBJECT(obj) \
public: \
static IGUIObject* ConstructObject(CGUI& pGUI) \
{ return new obj(pGUI); }
/**
* Message types.
* @see SGUIMessage
*/
enum EGUIMessageType
{
GUIM_MOUSE_OVER,
GUIM_MOUSE_ENTER,
GUIM_MOUSE_LEAVE,
GUIM_MOUSE_PRESS_LEFT,
GUIM_MOUSE_PRESS_LEFT_ITEM,
GUIM_MOUSE_PRESS_RIGHT,
GUIM_MOUSE_DOWN_LEFT,
GUIM_MOUSE_DOWN_RIGHT,
GUIM_MOUSE_DBLCLICK_LEFT,
GUIM_MOUSE_DBLCLICK_LEFT_ITEM, // Triggered when doubleclicking on a list item
GUIM_MOUSE_DBLCLICK_RIGHT,
GUIM_MOUSE_RELEASE_LEFT,
GUIM_MOUSE_RELEASE_RIGHT,
GUIM_MOUSE_WHEEL_UP,
GUIM_MOUSE_WHEEL_DOWN,
GUIM_SETTINGS_UPDATED, // SGUIMessage.m_Value = name of setting
GUIM_PRESSED,
GUIM_RELEASED,
GUIM_DOUBLE_PRESSED,
GUIM_MOUSE_MOTION,
GUIM_LOAD, // Called when an object is added to the GUI.
GUIM_GOT_FOCUS,
GUIM_LOST_FOCUS,
GUIM_PRESSED_MOUSE_RIGHT,
GUIM_DOUBLE_PRESSED_MOUSE_RIGHT,
GUIM_TAB, // Used by CInput
GUIM_TEXTEDIT
};
/**
* Message send to IGUIObject::HandleMessage() in order
* to give life to Objects manually with
* a derived HandleMessage().
*/
struct SGUIMessage
{
// This should be passed as a const reference or pointer.
NONCOPYABLE(SGUIMessage);
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; }
/**
* Describes what the message regards
*/
EGUIMessageType type;
/**
* Optional data
*/
CStr value;
/**
* Flag that specifies if object skipped handling the event
*/
bool skipped;
};
// Text alignments
enum EAlign { EAlign_Left, EAlign_Right, EAlign_Center };
enum EVAlign { EVAlign_Top, EVAlign_Bottom, EVAlign_Center };
// Typedefs
using map_pObjects = std::map<CStr, IGUIObject*>;
using vector_pObjects = std::vector<IGUIObject*>;
// 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
{
// This struct represents an immutable type, so ensure to avoid copying the strings.
NONCOPYABLE(SGUIIcon);
MOVABLE(SGUIIcon);
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
*

View File

@ -25,10 +25,8 @@ places, and to make it much easier to add a new type). Just do
to handle every possible type.
*/
#include "gui/CGUIList.h"
#include "gui/CGUISeries.h"
#ifndef GUITYPE_IGNORE_COPYABLE
#include "gui/EAlign.h"
TYPE(bool)
TYPE(i32)
TYPE(u32)
@ -39,6 +37,8 @@ TYPE(CPos)
#endif
#ifndef GUITYPE_IGNORE_NONCOPYABLE
#include "gui/CGUIList.h"
#include "gui/CGUISeries.h"
TYPE(CClientArea)
TYPE(CGUIColor)
TYPE(CGUIList)

View File

@ -27,6 +27,7 @@
#include "gui/GUIbase.h"
#include "gui/scripting/JSInterface_IGUIObject.h"
#include "gui/SGUIMessage.h"
#include "lib/input.h" // just for IN_PASS
#include "ps/XML/Xeromyces.h"
@ -34,8 +35,17 @@
#include <string>
#include <vector>
class CGUI;
class IGUIObject;
class IGUISetting;
using map_pObjects = std::map<CStr, IGUIObject*>;
#define GUI_OBJECT(obj) \
public: \
static IGUIObject* ConstructObject(CGUI& pGUI) \
{ return new obj(pGUI); }
/**
* GUI object such as a button or an input-box.
* Abstract data type !
@ -463,7 +473,7 @@ protected:
CStr m_Name;
// Constructed on the heap, will be destroyed along with the the CGUI
vector_pObjects m_Children;
std::vector<IGUIObject*> m_Children;
// Pointer to parent
IGUIObject* m_pParent;

View File

@ -27,6 +27,7 @@
#include "gui/CGUISprite.h"
class IGUIScrollBarOwner;
struct SGUIMessage;
/**
* The GUI Scroll-bar style. Tells us how scroll-bars look and feel.

46
source/gui/SGUIIcon.h Normal file
View File

@ -0,0 +1,46 @@
/* Copyright (C) 2019 Wildfire Games.
* 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/>.
*/
#ifndef INCLUDED_SGUIICON
#define INCLUDED_SGUIICON
#include "ps/CStr.h"
#include "ps/Shapes.h"
/**
* 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
{
// This struct represents an immutable type, so ensure to avoid copying the strings.
NONCOPYABLE(SGUIIcon);
MOVABLE(SGUIIcon);
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;
};
#endif // INCLUDED_SGUIICON

95
source/gui/SGUIMessage.h Normal file
View File

@ -0,0 +1,95 @@
/* Copyright (C) 2019 Wildfire Games.
* 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/>.
*/
#ifndef INCLUDED_SGUIMESSAGE
#define INCLUDED_SGUIMESSAGE
#include "ps/CStr.h"
/**
* Message types.
* @see SGUIMessage
*/
enum EGUIMessageType
{
GUIM_MOUSE_OVER,
GUIM_MOUSE_ENTER,
GUIM_MOUSE_LEAVE,
GUIM_MOUSE_PRESS_LEFT,
GUIM_MOUSE_PRESS_LEFT_ITEM,
GUIM_MOUSE_PRESS_RIGHT,
GUIM_MOUSE_DOWN_LEFT,
GUIM_MOUSE_DOWN_RIGHT,
GUIM_MOUSE_DBLCLICK_LEFT,
GUIM_MOUSE_DBLCLICK_LEFT_ITEM, // Triggered when doubleclicking on a list item
GUIM_MOUSE_DBLCLICK_RIGHT,
GUIM_MOUSE_RELEASE_LEFT,
GUIM_MOUSE_RELEASE_RIGHT,
GUIM_MOUSE_WHEEL_UP,
GUIM_MOUSE_WHEEL_DOWN,
GUIM_SETTINGS_UPDATED, // SGUIMessage.m_Value = name of setting
GUIM_PRESSED,
GUIM_RELEASED,
GUIM_DOUBLE_PRESSED,
GUIM_MOUSE_MOTION,
GUIM_LOAD, // Called when an object is added to the GUI.
GUIM_GOT_FOCUS,
GUIM_LOST_FOCUS,
GUIM_PRESSED_MOUSE_RIGHT,
GUIM_DOUBLE_PRESSED_MOUSE_RIGHT,
GUIM_TAB, // Used by CInput
GUIM_TEXTEDIT
};
/**
* Message send to IGUIObject::HandleMessage() in order
* to give life to Objects manually with
* a derived HandleMessage().
*/
struct SGUIMessage
{
// This should be passed as a const reference or pointer.
NONCOPYABLE(SGUIMessage);
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; }
/**
* Describes what the message regards
*/
EGUIMessageType type;
/**
* Optional data
*/
CStr value;
/**
* Flag that specifies if object skipped handling the event
*/
bool skipped;
};
#endif // INCLUDED_SGUIMESSAGE

38
source/gui/SGUIStyle.h Normal file
View File

@ -0,0 +1,38 @@
/* Copyright (C) 2019 Wildfire Games.
* 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/>.
*/
#ifndef INCLUDED_SGUISTYLE
#define INCLUDED_SGUISTYLE
#include "ps/CStr.h"
#include <map>
/**
* Contains a list of values for new defaults to objects.
*/
struct SGUIStyle
{
// Take advantage of moving the entire map instead and avoiding unintended copies.
NONCOPYABLE(SGUIStyle);
MOVABLE(SGUIStyle);
SGUIStyle() = default;
std::map<CStr, CStrW> m_SettingsDefaults;
};
#endif // INCLUDED_SGUISTYLE