Index: ps/trunk/source/gui/CGUI.h =================================================================== --- ps/trunk/source/gui/CGUI.h +++ ps/trunk/source/gui/CGUI.h @@ -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 @@ 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 m_SettingsDefaults; -}; - class CGUISpriteInstance; class CGUISprite; +class IGUIObject; struct SGUIImageEffects; struct SGUIScrollBarStyle; Index: ps/trunk/source/gui/CGUIText.h =================================================================== --- ps/trunk/source/gui/CGUIText.h +++ ps/trunk/source/gui/CGUIText.h @@ -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, 2>; /** Index: ps/trunk/source/gui/EAlign.h =================================================================== --- ps/trunk/source/gui/EAlign.h +++ ps/trunk/source/gui/EAlign.h @@ -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 . + */ + +#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 Index: ps/trunk/source/gui/GUIbase.h =================================================================== --- ps/trunk/source/gui/GUIbase.h +++ ps/trunk/source/gui/GUIbase.h @@ -15,13 +15,6 @@ * along with 0 A.D. If not, see . */ -/* -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 @@ #include "ps/Shapes.h" #include "scriptinterface/ScriptInterface.h" -#include -#include - -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; -using vector_pObjects = std::vector; - -// Icon, you create them in the XML file with root element -// 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 * Index: ps/trunk/source/gui/GUItypes.h =================================================================== --- ps/trunk/source/gui/GUItypes.h +++ ps/trunk/source/gui/GUItypes.h @@ -25,10 +25,8 @@ 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 @@ #endif #ifndef GUITYPE_IGNORE_NONCOPYABLE +#include "gui/CGUIList.h" +#include "gui/CGUISeries.h" TYPE(CClientArea) TYPE(CGUIColor) TYPE(CGUIList) Index: ps/trunk/source/gui/IGUIObject.h =================================================================== --- ps/trunk/source/gui/IGUIObject.h +++ ps/trunk/source/gui/IGUIObject.h @@ -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 #include +class CGUI; +class IGUIObject; class IGUISetting; +using map_pObjects = std::map; + +#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 @@ CStr m_Name; // Constructed on the heap, will be destroyed along with the the CGUI - vector_pObjects m_Children; + std::vector m_Children; // Pointer to parent IGUIObject* m_pParent; Index: ps/trunk/source/gui/IGUIScrollBar.h =================================================================== --- ps/trunk/source/gui/IGUIScrollBar.h +++ ps/trunk/source/gui/IGUIScrollBar.h @@ -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. Index: ps/trunk/source/gui/SGUIIcon.h =================================================================== --- ps/trunk/source/gui/SGUIIcon.h +++ ps/trunk/source/gui/SGUIIcon.h @@ -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 . + */ + +#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 . + * 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 Index: ps/trunk/source/gui/SGUIMessage.h =================================================================== --- ps/trunk/source/gui/SGUIMessage.h +++ ps/trunk/source/gui/SGUIMessage.h @@ -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 . + */ + +#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 Index: ps/trunk/source/gui/SGUIStyle.h =================================================================== --- ps/trunk/source/gui/SGUIStyle.h +++ ps/trunk/source/gui/SGUIStyle.h @@ -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 . + */ + +#ifndef INCLUDED_SGUISTYLE +#define INCLUDED_SGUISTYLE + +#include "ps/CStr.h" + +#include + +/** + * 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 m_SettingsDefaults; +}; + +#endif // INCLUDED_SGUISTYLE