From 5122b0f906911a7c93e276be0ecd2690d4298208 Mon Sep 17 00:00:00 2001 From: Gee Date: Mon, 24 Nov 2003 02:18:41 +0000 Subject: [PATCH] no message This was SVN commit r74. --- binaries/data/gui/hello.xml | 13 + binaries/data/gui/objects.dtd | 49 ++++ binaries/data/gui/sprite1.xml | 9 + binaries/data/gui/sprites.dtd | 28 +++ source/gui/CButton.cpp | 13 +- source/gui/CButton.h | 10 +- source/gui/CGUI.cpp | 94 ++++--- source/gui/CGUI.h | 72 +++--- source/gui/CGUISprite.h | 4 +- source/gui/GUI.h | 14 +- source/gui/GUIbase.h | 17 +- source/gui/GUIutil.cpp | 4 +- source/gui/GUIutil.h | 51 ++-- source/gui/IGUIButtonBehavior.cpp | 60 +++++ source/gui/IGUIButtonBehavior.h | 71 ++++++ source/gui/IGUIObject.cpp | 313 +++++++++++++++++++++++ source/gui/IGUIObject.h | 405 ++++++++++++++++++++++++++++++ source/gui/IGUISettingsObject.cpp | 10 + source/gui/IGUISettingsObject.h | 124 +++++++++ source/gui/XercesErrorHandler.h | 72 ++++-- source/lib/font.h | 2 +- source/ps/CStr.cpp | 5 + source/ps/CStr.h | 1 + source/ps/Prometheus.cpp | 3 + source/ps/Prometheus.h | 4 + 25 files changed, 1308 insertions(+), 140 deletions(-) create mode 100755 binaries/data/gui/hello.xml create mode 100755 binaries/data/gui/objects.dtd create mode 100755 binaries/data/gui/sprite1.xml create mode 100755 binaries/data/gui/sprites.dtd create mode 100755 source/gui/IGUIButtonBehavior.cpp create mode 100755 source/gui/IGUIButtonBehavior.h create mode 100755 source/gui/IGUIObject.cpp create mode 100755 source/gui/IGUIObject.h create mode 100755 source/gui/IGUISettingsObject.cpp create mode 100755 source/gui/IGUISettingsObject.h diff --git a/binaries/data/gui/hello.xml b/binaries/data/gui/hello.xml new file mode 100755 index 0000000000..d3ec16b8d9 --- /dev/null +++ b/binaries/data/gui/hello.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/binaries/data/gui/objects.dtd b/binaries/data/gui/objects.dtd new file mode 100755 index 0000000000..1167920dd1 --- /dev/null +++ b/binaries/data/gui/objects.dtd @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/binaries/data/gui/sprite1.xml b/binaries/data/gui/sprite1.xml new file mode 100755 index 0000000000..20d0a69238 --- /dev/null +++ b/binaries/data/gui/sprite1.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/binaries/data/gui/sprites.dtd b/binaries/data/gui/sprites.dtd new file mode 100755 index 0000000000..4dd73bc7f2 --- /dev/null +++ b/binaries/data/gui/sprites.dtd @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/source/gui/CButton.cpp b/source/gui/CButton.cpp index 20cb42c84b..a582424286 100755 --- a/source/gui/CButton.cpp +++ b/source/gui/CButton.cpp @@ -9,9 +9,6 @@ gee@pyro.nu using namespace std; -// TEMP TODO Gee -///extern nemFontNTF font; - // Offsets DECLARE_SETTINGS_INFO(SButtonSettings) @@ -75,7 +72,7 @@ void CButton::HandleMessage(const EGUIMessage &Message) // TODO REMOVE #define OUTPUT(x) g_console.submit("echo Object(%s) %s", m_Name.c_str(), #x); - CGUIButtonBehavior::HandleMessage(Message); + IGUIButtonBehavior::HandleMessage(Message); switch (Message) { @@ -135,11 +132,17 @@ void CButton::Draw() // Do this glBegin(GL_QUADS); + //glBegin(GL_TRIANGLES); glVertex2i(GetBaseSettings().m_Size.right, GetBaseSettings().m_Size.bottom); glVertex2i(GetBaseSettings().m_Size.left, GetBaseSettings().m_Size.bottom); glVertex2i(GetBaseSettings().m_Size.left, GetBaseSettings().m_Size.top); glVertex2i(GetBaseSettings().m_Size.right, GetBaseSettings().m_Size.top); - glEnd(); +/* + glVertex2i(GetBaseSettings().m_Size.right, GetBaseSettings().m_Size.bottom); + glVertex2i(GetBaseSettings().m_Size.left, GetBaseSettings().m_Size.bottom); + glVertex2i(GetBaseSettings().m_Size.left, GetBaseSettings().m_Size.top); + //glVertex2i(GetBaseSettings().m_Size.right, GetBaseSettings().m_Size.top); +*/ glEnd(); //glDisable(GL_DEPTH_TEST); diff --git a/source/gui/CButton.h b/source/gui/CButton.h index 3d78654d5c..36eca0a416 100755 --- a/source/gui/CButton.h +++ b/source/gui/CButton.h @@ -61,12 +61,12 @@ struct SButtonSettings * * Button * - * @see CGUIObject - * @see CGUISettingsObject - * @see CGUIButtonBehavior + * @see IGUIObject + * @see IGUISettingsObject + * @see IGUIButtonBehavior * @see SButtonSettings */ -class CButton : public CGUISettingsObject, public CGUIButtonBehavior +class CButton : public IGUISettingsObject, public IGUIButtonBehavior { GUI_OBJECT(CButton) @@ -79,7 +79,7 @@ public: * * @return Settings infos */ - virtual map_Settings GetSettingsInfo() const { return CGUISettingsObject::m_SettingsInfo; } + virtual map_Settings GetSettingsInfo() const { return IGUISettingsObject::m_SettingsInfo; } /** * Handle Messages diff --git a/source/gui/CGUI.cpp b/source/gui/CGUI.cpp index 9e01e1689f..08a592f204 100755 --- a/source/gui/CGUI.cpp +++ b/source/gui/CGUI.cpp @@ -10,15 +10,15 @@ gee@pyro.nu #include #include -///#include "nemesis.h" -//#include incCONSOLE - #include #include #include #include #include + #include "XercesErrorHandler.h" +#include "../ps/Prometheus.h" +#include "input.h" // namespaces used XERCES_CPP_NAMESPACE_USE @@ -29,8 +29,6 @@ using namespace std; #endif -#include "input.h" - //------------------------------------------------------------------- // called from main loop when (input) events are received. // event is passed to other handlers if false is returned. @@ -39,8 +37,6 @@ using namespace std; bool gui_handler(const SDL_Event& ev) { return g_GUI.HandleEvent(ev); - -// return false; } bool CGUI::HandleEvent(const SDL_Event& ev) @@ -51,22 +47,27 @@ bool CGUI::HandleEvent(const SDL_Event& ev) // JW: (pre|post)process omitted; what're they for? why would we need any special button_released handling? // Only one object can be hovered - // check which one it is, if any ! - CGUIObject *pNearest = NULL; + IGUIObject *pNearest = NULL; - GUI::RecurseObject(GUIRR_HIDDEN, m_BaseObject, &CGUIObject::ChooseMouseOverAndClosest, pNearest); + // pNearest will after this point at the hovered object, possibly NULL + GUI::RecurseObject(GUIRR_HIDDEN, m_BaseObject, + &IGUIObject::ChooseMouseOverAndClosest, + pNearest); // Now we'll call UpdateMouseOver on *all* objects, // we'll input the one hovered, and they will each // update their own data and send messages accordingly - GUI::RecurseObject(GUIRR_HIDDEN, m_BaseObject, &CGUIObject::UpdateMouseOver, pNearest); + GUI::RecurseObject(GUIRR_HIDDEN, m_BaseObject, + &IGUIObject::UpdateMouseOver, + pNearest); if(pNearest) { if(ev.type == SDL_MOUSEBUTTONDOWN) - pNearest->HandleMessage(GUIM_MOUSE_PRESS_LEFT); // JW: want to pass SDL button value, or translate? - else if(ev.type == SDL_MOUSEBUTTONUP) - pNearest->HandleMessage(GUIM_MOUSE_RELEASE_LEFT); // JW: want to pass SDL button value, or translate? + pNearest->HandleMessage(GUIM_MOUSE_PRESS_LEFT); + else + if(ev.type == SDL_MOUSEBUTTONUP) + pNearest->HandleMessage(GUIM_MOUSE_RELEASE_LEFT); } // JW: what's the difference between mPress and mDown? what's the code below responsible for? @@ -101,19 +102,22 @@ CGUI::~CGUI() //------------------------------------------------------------------- // Functions //------------------------------------------------------------------- -CGUIObject *CGUI::ConstructObject(const CStr &str) +IGUIObject *CGUI::ConstructObject(const CStr &str) { if (m_ObjectTypes.count(str) > 0) return (*m_ObjectTypes[str])(); else + { + // Report in log (GeeTODO) return NULL; + } } -void CGUI::Initialize(/*/*CInput *pInput*/) +void CGUI::Initialize() { -/// m_pInput = pInput; - // Add base types! + // You can also add types outside the GUI to extend the flexibility of the GUI. + // Prometheus though will have all the object types inserted from here. AddObjectType("button", &CButton::ConstructObject); } @@ -127,7 +131,7 @@ void CGUI::Process() // Pre-process all objects try { - GUI::RecurseObject(0, m_BaseObject, &CGUIObject::HandleMessage, GUIM_PREPROCESS); + GUI::RecurseObject(0, m_BaseObject, &IGUIObject::HandleMessage, GUIM_PREPROCESS); } catch (PS_RESULT e) { @@ -139,14 +143,14 @@ void CGUI::Process() { // Only one object can be hovered // check which one it is, if any ! - CGUIObject *pNearest = NULL; + IGUIObject *pNearest = NULL; - GUI::RecurseObject(GUIRR_HIDDEN, m_BaseObject, &CGUIObject::ChooseMouseOverAndClosest, pNearest); + GUI::RecurseObject(GUIRR_HIDDEN, m_BaseObject, &IGUIObject::ChooseMouseOverAndClosest, pNearest); // Now we'll call UpdateMouseOver on *all* objects, // we'll input the one hovered, and they will each // update their own data and send messages accordingly - GUI::RecurseObject(GUIRR_HIDDEN, m_BaseObject, &CGUIObject::UpdateMouseOver, pNearest); + GUI::RecurseObject(GUIRR_HIDDEN, m_BaseObject, &IGUIObject::UpdateMouseOver, pNearest); // If pressed if (m_pInput->mPress(NEMM_BUTTON1) && pNearest) @@ -175,7 +179,7 @@ void CGUI::Process() // Post-process all objects try { - GUI::RecurseObject(0, m_BaseObject, &CGUIObject::HandleMessage, GUIM_POSTPROCESS); + GUI::RecurseObject(0, m_BaseObject, &IGUIObject::HandleMessage, GUIM_POSTPROCESS); } catch (PS_RESULT e) { @@ -186,15 +190,28 @@ void CGUI::Process() void CGUI::Draw() { + glPushMatrix(); + glLoadIdentity(); + + // Adapt (origio) to being in top left corner and down + // just like the mouse position + glTranslatef(0.0f, g_yres, -1000.0f); + glScalef(1.0f, -1.f, 1.0f); + try { - // Recurse CGUIObject::Draw() - GUI<>::RecurseObject(GUIRR_HIDDEN, m_BaseObject, &CGUIObject::Draw); + // Recurse IGUIObject::Draw() with restriction: hidden + // meaning all hidden objects won't call Draw (nor will it recurse its children) + GUI<>::RecurseObject(GUIRR_HIDDEN, m_BaseObject, &IGUIObject::Draw); } catch (PS_RESULT e) { + glPopMatrix(); + + // TODO return; } + glPopMatrix(); } void CGUI::Destroy() @@ -210,7 +227,7 @@ void CGUI::Destroy() } catch (PS_RESULT e) { - + // TODO } delete it->second; @@ -222,20 +239,20 @@ void CGUI::Destroy() m_Sprites.clear(); } -void CGUI::AddObject(CGUIObject* pObject) +void CGUI::AddObject(IGUIObject* pObject) { - try - { +/* try + {*/ // Add CGUI pointer - GUI::RecurseObject(0, pObject, &CGUIObject::SetGUI, this); + GUI::RecurseObject(0, pObject, &IGUIObject::SetGUI, this); // Add child to base object m_BaseObject->AddChild(pObject); - } +/* } catch (PS_RESULT e) { throw e; - } + }*/ } void CGUI::UpdateObjects() @@ -247,7 +264,7 @@ void CGUI::UpdateObjects() try { // Fill freshly - GUI< map_pObjects >::RecurseObject(0, m_BaseObject, &CGUIObject::AddToPointersMap, AllObjects ); + GUI< map_pObjects >::RecurseObject(0, m_BaseObject, &IGUIObject::AddToPointersMap, AllObjects ); } catch (PS_RESULT e) { @@ -289,6 +306,9 @@ void CGUI::ReportParseError(const CStr &str, ...) /// g_nemLog(" %s", buffer); } +/** + * @callgraph + */ void CGUI::LoadXMLFile(const string &Filename) { // Reset parse error @@ -330,6 +350,9 @@ void CGUI::LoadXMLFile(const string &Filename) ParseFailed = parser->getErrorCount() != 0; if (ParseFailed) { + int todo_remove = parser->getErrorCount(); + + // TODO report for real! /// g_console.submit("echo Xerces XML Parsing Reports %d errors", parser->getErrorCount()); } @@ -382,7 +405,6 @@ void CGUI::LoadXMLFile(const string &Filename) XMLPlatformUtils::Terminate(); } - //=================================================================== // XML Reading Xerces Specific Sub-Routines //=================================================================== @@ -425,13 +447,13 @@ void CGUI::Xerces_ReadRootSprites(XERCES_CPP_NAMESPACE::DOMElement *pElement) } } -void CGUI::Xerces_ReadObject(DOMElement *pElement, CGUIObject *pParent) +void CGUI::Xerces_ReadObject(DOMElement *pElement, IGUIObject *pParent) { assert(pParent && pElement); int i; // Our object we are going to create - CGUIObject *object = NULL; + IGUIObject *object = NULL; // Well first of all we need to determine the type string type = XMLString::transcode( pElement->getAttribute( XMLString::transcode("type") ) ); diff --git a/source/gui/CGUI.h b/source/gui/CGUI.h index 7aeb34d9c8..1a2938415a 100755 --- a/source/gui/CGUI.h +++ b/source/gui/CGUI.h @@ -31,6 +31,7 @@ gee@pyro.nu class XERCES_CPP_NAMESPACE::DOMElement; +extern bool gui_handler(const SDL_Event& ev); //-------------------------------------------------------- // Macros @@ -53,17 +54,17 @@ class XERCES_CPP_NAMESPACE::DOMElement; * * The main object that includes the whole GUI. Is singleton * and accessed by g_GUI. + * + * No interfacial functions throws. */ class CGUI : public Singleton { - // Only CGUIObject's leaf functions uses CGUI - // freely. - friend class CGUIObject; + friend class IGUIObject; friend class CInternalCGUIAccessorBase; private: // Private typedefs - typedef CGUIObject *(*ConstructObjectFunction)(); + typedef IGUIObject *(*ConstructObjectFunction)(); public: CGUI(); @@ -81,16 +82,12 @@ public: /** * Displays the whole GUI - * - * @throws PS_RESULT from CGUIObject::Draw(). */ void Draw(); /** * Clean up, call this to clean up all memory allocated * within the GUI. - * - * @throws PS_RESULT from CGUIObject::Destroy(). */ void Destroy(); @@ -121,7 +118,7 @@ public: * their constructors. Also it needs to associate a type * by a string name of the type. * - * To add a type:
+ * To add a type:\n * AddObjectType("button", &CButton::ConstructObject); * * @param str Reference name of object type @@ -139,7 +136,7 @@ private: * This function is atomic, meaning if it throws anything, it will * have seen it through that nothing was ultimately changed. * - * @throws PS_RESULT that is thrown from CGUIObject::AddToPointersMap(). + * @throws PS_RESULT that is thrown from IGUIObject::AddToPointersMap(). */ void UpdateObjects(); @@ -149,10 +146,10 @@ private: * XML files. Why? Becasue it enables the GUI to * be much more encapsulated and safe. * - * @throws Rethrows PS_RESULT from CGUIObject::SetGUI() and - * CGUIObject::AddChild(). + * @throws Rethrows PS_RESULT from IGUIObject::SetGUI() and + * IGUIObject::AddChild(). */ - void AddObject(CGUIObject* pObject); + void AddObject(IGUIObject* pObject); /** * Report XML Reading Error, should be called from within the @@ -168,9 +165,9 @@ private: * CGUIObjet* as a CButton. * * @param str Name of object type - * @return Newly constructed CGUIObject (but constructed as a subclass) + * @return Newly constructed IGUIObject (but constructed as a subclass) */ - CGUIObject *ConstructObject(const CStr &str); + IGUIObject *ConstructObject(const CStr &str); //-------------------------------------------------------- /** @name XML Reading Xerces C++ specific subroutines @@ -192,7 +189,7 @@ private: | +-\ | - +-Optional Type Extensions (CGUIObject::ReadExtendedElement) TODO + +-Optional Type Extensions (IGUIObject::ReadExtendedElement) TODO | +-«object» *recursive* @@ -224,18 +221,22 @@ private: // Read Roots /** - * Reads in the root element "objects" (the DOMElement). + * Reads in the root element \ (the DOMElement). * * @param pElement The Xerces C++ Parser object that represents * the objects-tag. + * + * @see LoadXMLFile() */ void Xerces_ReadRootObjects(XERCES_CPP_NAMESPACE::DOMElement *pElement); /** - * Reads in the root element "sprites" (the DOMElement). + * Reads in the root element \ (the DOMElement). * * @param pElement The Xerces C++ Parser object that represents * the sprites-tag. + * + * @see LoadXMLFile() */ void Xerces_ReadRootSprites(XERCES_CPP_NAMESPACE::DOMElement *pElement); @@ -244,39 +245,46 @@ private: /** * Notice! Recursive function! * - * Read in an "object"-tag (the DOMElement) and stores it + * Read in an \ (the DOMElement) and stores it * as a child in the pParent. * * It will also check the object's children and call this function * on them too. Also it will call all other functions that reads - * in other stuff that can be found within an object. Such as - * "action"-tag will call Xerces_ReadAction (TODO, real funcion?). + * in other stuff that can be found within an object. Such as a + * \ will call Xerces_ReadAction (TODO, real funcion?). * - * Reads in the root element "sprites" (the DOMElement). + * Reads in the root element \ (the DOMElement). * * @param pElement The Xerces C++ Parser object that represents * the object-tag. * @param pParent Parent to add this object as child in. + * + * @see LoadXMLFile() */ - void Xerces_ReadObject(XERCES_CPP_NAMESPACE::DOMElement *, CGUIObject *pParent); + void Xerces_ReadObject(XERCES_CPP_NAMESPACE::DOMElement *, IGUIObject *pParent); /** - * Reads in the element "sprite" (the DOMElement) and store the + * Reads in the element \ (the DOMElement) and stores the * result in a new CGUISprite. * * @param pElement The Xerces C++ Parser object that represents * the sprite-tag. + * + * @see LoadXMLFile() */ - void Xerces_ReadSprite(XERCES_CPP_NAMESPACE::DOMElement *); + void Xerces_ReadSprite(XERCES_CPP_NAMESPACE::DOMElement *pElement); /** - * Reads in the element "image" (the DOMElement) and store the + * Reads in the element \ (the DOMElement) and stores the * result within the CGUISprite. * * @param pElement The Xerces C++ Parser object that represents * the image-tag. + * @param parent Parent sprite. + * + * @see LoadXMLFile() */ - void Xerces_ReadImage(XERCES_CPP_NAMESPACE::DOMElement *, CGUISprite &parent); + void Xerces_ReadImage(XERCES_CPP_NAMESPACE::DOMElement *pElement, CGUISprite &parent); //@} @@ -297,7 +305,7 @@ private: u16 m_MouseX, m_MouseY; /// Used when reading in XML files - int m_Errors; + int16 m_Errors; //@} //-------------------------------------------------------- @@ -309,7 +317,7 @@ private: * Base Object, all its children are considered parentless * because this is no real object per se. */ - CGUIObject* m_BaseObject; + IGUIObject* m_BaseObject; /** * Just pointers for fast name access, each object @@ -318,11 +326,11 @@ private: * Notice m_BaseObject won't belong here since it's * not considered a real object. */ - map_pObjects m_pAllObjects; + map_pObjects m_pAllObjects; /** * Function pointers to functions that constructs - * CGUIObjects by name... For instance m_ObjectTypes["button"] + * IGUIObjects by name... For instance m_ObjectTypes["button"] * is filled with a function that will "return new CButton();" */ std::map m_ObjectTypes; @@ -333,7 +341,7 @@ private: //-------------------------------------------------------- //@{ - std::map m_Sprites; + std::map m_Sprites; //@} }; diff --git a/source/gui/CGUISprite.h b/source/gui/CGUISprite.h index 6466a534bd..f35dd93c15 100755 --- a/source/gui/CGUISprite.h +++ b/source/gui/CGUISprite.h @@ -63,7 +63,9 @@ struct SGUIImage //CColor m_BackColor; //CColor m_BorderColor; - int m_BorderSize; + +// int16 m_BorderSize; + bool m_Border; // I've decided to have only the 1 pixel available }; /** diff --git a/source/gui/GUI.h b/source/gui/GUI.h index c274d42374..4bab6fa4c1 100755 --- a/source/gui/GUI.h +++ b/source/gui/GUI.h @@ -15,14 +15,16 @@ gee@pyro.nu // Main page for GUI documentation /** - * \mainpage + * @mainpage * Welcome to the Wildfire Games Graphical User Interface Documentation. * * Additional Downloads can be made from the link below.\n * Technical Design Document * + * The GUI uses Xerces C++ Parser, + * Current official version (ensured to work): 2.3.0 * - * \dot + * @dot * digraph * { * node [shape=record, fontname=Helvetica, fontsize=10]; @@ -34,7 +36,7 @@ gee@pyro.nu * c -> email; * s -> email; * } - * \enddot + * @enddot */ @@ -72,9 +74,9 @@ gee@pyro.nu #include "GUIbase.h" #include "GUIutil.h" -#include "CGUIObject.h" -#include "CGUISettingsObject.h" -#include "CGUIButtonBehavior.h" +#include "IGUIObject.h" +#include "IGUISettingsObject.h" +#include "IGUIButtonBehavior.h" #include "CButton.h" #include "CGUISprite.h" #include "CGUI.h" diff --git a/source/gui/GUIbase.h b/source/gui/GUIbase.h index 259ba618d6..d226716901 100755 --- a/source/gui/GUIbase.h +++ b/source/gui/GUIbase.h @@ -25,7 +25,7 @@ gee@pyro.nu //-------------------------------------------------------- // Forward declarations //-------------------------------------------------------- -class CGUIObject; +class IGUIObject; //-------------------------------------------------------- @@ -46,23 +46,24 @@ class CGUIObject; m_SettingsInfo[str].m_Offset = offsetof(_class, name) + offsetof(_struct, var); \ m_SettingsInfo[str].m_Type = type; -// Declares the static variable in CGUISettingsObject<> +// Declares the static variable in IGUISettingsObject<> #define DECLARE_SETTINGS_INFO(_struct) \ - map_Settings CGUISettingsObject<_struct>::m_SettingsInfo; + map_Settings IGUISettingsObject<_struct>::m_SettingsInfo; // Setup an object's ConstructObject function #define GUI_OBJECT(obj) \ public: \ - static CGUIObject *ConstructObject() { return new obj(); } + static IGUIObject *ConstructObject() { return new obj(); } //-------------------------------------------------------- // Types //-------------------------------------------------------- -/** \enum EGUIMessage - * Message send to CGUIObject::HandleMessage() in order +/** + * @enum EGUIMessage + * Message send to IGUIObject::HandleMessage() in order * to give life to Objects manually with - * a derived HandleMessage(). + * a derived HandleMessage(). */ enum EGUIMessage { @@ -95,7 +96,7 @@ enum }; // Typedefs -typedef std::map map_pObjects; +typedef std::map map_pObjects; //-------------------------------------------------------- diff --git a/source/gui/GUIutil.cpp b/source/gui/GUIutil.cpp index 7dac640a7e..d30c8eab9d 100755 --- a/source/gui/GUIutil.cpp +++ b/source/gui/GUIutil.cpp @@ -12,7 +12,7 @@ using namespace std; //-------------------------------------------------------- // Utilities implementation //-------------------------------------------------------- -CGUIObject * CInternalCGUIAccessorBase::GetObjectPointer(CGUI &GUIinstance, const CStr &Object) +IGUIObject * CInternalCGUIAccessorBase::GetObjectPointer(CGUI &GUIinstance, const CStr &Object) { // if (!GUIinstance.ObjectExists(Object)) // return NULL; @@ -20,7 +20,7 @@ CGUIObject * CInternalCGUIAccessorBase::GetObjectPointer(CGUI &GUIinstance, cons return GUIinstance.m_pAllObjects.find(Object)->second; } -const CGUIObject * CInternalCGUIAccessorBase::GetObjectPointer(const CGUI &GUIinstance, const CStr &Object) +const IGUIObject * CInternalCGUIAccessorBase::GetObjectPointer(const CGUI &GUIinstance, const CStr &Object) { // if (!GUIinstance.ObjectExists(Object)) // return NULL; diff --git a/source/gui/GUIutil.h b/source/gui/GUIutil.h index 67094bac1b..e5d95b0de5 100755 --- a/source/gui/GUIutil.h +++ b/source/gui/GUIutil.h @@ -27,9 +27,11 @@ gee@pyro.nu // Forward declarations //-------------------------------------------------------- class CGUI; -class CGUIObject; +class IGUIObject; /** + * @author Gustav Larsson + * * Base class to only the class GUI. This superclass is * kind of a templateless extention of the class GUI. * Used for other functions to friend with, because it @@ -39,14 +41,16 @@ class CInternalCGUIAccessorBase { protected: /// Get object pointer - static CGUIObject * GetObjectPointer(CGUI &GUIinstance, const CStr &Object); + static IGUIObject * GetObjectPointer(CGUI &GUIinstance, const CStr &Object); /// const version - static const CGUIObject * GetObjectPointer(const CGUI &GUIinstance, const CStr &Object); + static const IGUIObject * GetObjectPointer(const CGUI &GUIinstance, const CStr &Object); }; /** + * @author Gustav Larsson + * * Includes static functions that needs one template * argument. * @@ -58,7 +62,7 @@ class GUI : public CInternalCGUIAccessorBase { // Private functions further ahead friend class CGUI; - friend class CGUIObject; + friend class IGUIObject; public: /** @@ -68,7 +72,7 @@ public: * @param Setting Setting by name * @param Value Stores value here, note type T! */ - static PS_RESULT GetSetting(const CGUIObject *pObject, const CStr &Setting, T &Value) + static PS_RESULT GetSetting(const IGUIObject *pObject, const CStr &Setting, T &Value) { if (pObject == NULL) return PS_OBJECT_FAIL; @@ -89,7 +93,7 @@ public: * @param Setting Setting by name * @param Value Sets value to this, note type T! */ - static PS_RESULT SetSetting(CGUIObject *pObject, const CStr &Setting, const T &Value) + static PS_RESULT SetSetting(IGUIObject *pObject, const CStr &Setting, const T &Value) { if (pObject == NULL) return PS_OBJECT_FAIL; @@ -122,7 +126,7 @@ public: return PS_OBJECT_FAIL; // Retrieve pointer and call sibling function - const CGUIObject *pObject = GetObjectPointer(GUIinstance, Object); + const IGUIObject *pObject = GetObjectPointer(GUIinstance, Object); return GetSetting(pObject, Setting, Value); } @@ -148,7 +152,7 @@ public: // Important, we don't want to use this T, we want // to use the standard T, since that will be the // one with the friend relationship - CGUIObject *pObject = GetObjectPointer(GUIinstance, Object); + IGUIObject *pObject = GetObjectPointer(GUIinstance, Object); return SetSetting(pObject, Setting, Value); } @@ -233,32 +237,37 @@ public: private: // templated typedef of function pointer - typedef void (CGUIObject::*void_Object_pFunction_argT)(const T &arg); - typedef void (CGUIObject::*void_Object_pFunction_argRefT)(T &arg); - typedef void (CGUIObject::*void_Object_pFunction)(); + typedef void (IGUIObject::*void_Object_pFunction_argT)(const T &arg); + typedef void (IGUIObject::*void_Object_pFunction_argRefT)(T &arg); + typedef void (IGUIObject::*void_Object_pFunction)(); /** - * If you want to call a CGUIObject-function + * If you want to call a IGUIObject-function * on not just an object, but also on ALL of their children * you want to use this recursion system. * It recurses an object calling a function on itself * and all children (and so forth). * - * Restrictions:
+ * Restrictions:\n * You can also set restrictions, so that if the recursion * reaches an objects with certain setup, it just doesn't * call the function on the object, nor it's children for * that matter. i.e. it cuts that object off from the * recursion tree. What setups that can cause restrictions * are hardcoded and specific. Check out the defines - * GUIRR_* for all different setups. + * GUIRR_* for all different setups. * - * @param RR Recurse Restrictions - * @param pObject Object to iterate + * Error reports are either logged or thrown out of RecurseObject. + * Always use it with try/catch! + * + * @param RR Recurse Restrictions, set to 0 if no restrictions + * @param pObject Top object, this is where the iteration starts * @param pFunc Function to recurse - * @param Argument Argument of type T + * @param Argument Argument for pFunc of type T + * @throws PS_RESULT Depends on what pFunc might throw. PS_RESULT is standard. + * Itself doesn't throw anything. */ - static void RecurseObject(const int &RR, CGUIObject *pObject, void_Object_pFunction_argT pFunc, const T &Argument) + static void RecurseObject(const int &RR, IGUIObject *pObject, void_Object_pFunction_argT pFunc, const T &Argument) { if (CheckIfRestricted(RR, pObject)) return; @@ -278,7 +287,7 @@ private: * * @see RecurseObject() */ - static void RecurseObject(const int &RR, CGUIObject *pObject, void_Object_pFunction_argRefT pFunc, T &Argument) + static void RecurseObject(const int &RR, IGUIObject *pObject, void_Object_pFunction_argRefT pFunc, T &Argument) { if (CheckIfRestricted(RR, pObject)) return; @@ -298,7 +307,7 @@ private: * * @see RecurseObject() */ - static void RecurseObject(const int &RR, CGUIObject *pObject, void_Object_pFunction pFunc) + static void RecurseObject(const int &RR, IGUIObject *pObject, void_Object_pFunction pFunc) { if (CheckIfRestricted(RR, pObject)) return; @@ -324,7 +333,7 @@ private: * @param pObject Object * @return true if restricted */ - static bool CheckIfRestricted(const int &RR, CGUIObject *pObject) + static bool CheckIfRestricted(const int &RR, IGUIObject *pObject) { if (RR & GUIRR_HIDDEN) { diff --git a/source/gui/IGUIButtonBehavior.cpp b/source/gui/IGUIButtonBehavior.cpp new file mode 100755 index 0000000000..5322a48cdf --- /dev/null +++ b/source/gui/IGUIButtonBehavior.cpp @@ -0,0 +1,60 @@ +/* +IGUIButtonBehavior +by Gustav Larsson +gee@pyro.nu +*/ + +//#include "stdafx.h" +#include "GUI.h" + +using namespace std; + +//------------------------------------------------------------------- +// Constructor / Destructor +//------------------------------------------------------------------- +IGUIButtonBehavior::IGUIButtonBehavior() : m_Pressed(false) +{ +} + +IGUIButtonBehavior::~IGUIButtonBehavior() +{ +} + +void IGUIButtonBehavior::HandleMessage(const EGUIMessage &Message) +{ + switch (Message) + { + case GUIM_POSTPROCESS: + // Check if button has been pressed + if (m_Pressed) + { + // Now check if mouse is released, that means + // it's released outside, since GUIM_MOUSE_RELEASE_LEFT + // would've handled m_Pressed and reset it already + + // Get input structure +/// if (GetGUI()->GetInput()->mRelease(NEMM_BUTTON1)) + { + // Reset + m_Pressed = false; + } + } + break; + + case GUIM_MOUSE_PRESS_LEFT: + m_Pressed = true; + break; + + case GUIM_MOUSE_RELEASE_LEFT: + if (m_Pressed) + { + m_Pressed = false; + // BUTTON WAS CLICKED + HandleMessage(GUIM_PRESSED); + } + break; + + default: + break; + } +} diff --git a/source/gui/IGUIButtonBehavior.h b/source/gui/IGUIButtonBehavior.h new file mode 100755 index 0000000000..1f2c100aa3 --- /dev/null +++ b/source/gui/IGUIButtonBehavior.h @@ -0,0 +1,71 @@ +/* +GUI Object - Button +by Gustav Larsson +gee@pyro.nu + +--Overview-- + + Interface class that enhance the IGUIObject with + buttony behavior (click and release to click a button), + and the GUI message GUIM_PRESSED. + When creating a class with extended settings and + buttony behavior, just do a multiple inheritance. + +--More info-- + + Check GUI.h + +*/ + +#ifndef IGUIButtonBehavior_H +#define IGUIButtonBehavior_H + +//-------------------------------------------------------- +// Includes / Compiler directives +//-------------------------------------------------------- +#include "GUI.h" + +//-------------------------------------------------------- +// Macros +//-------------------------------------------------------- + +//-------------------------------------------------------- +// Types +//-------------------------------------------------------- + +//-------------------------------------------------------- +// Declarations +//-------------------------------------------------------- + +/** + * @author Gustav Larsson + * + * Appends button behaviours to the IGUIObject. + * Can be used with multiple inheritance alongside + * IGUISettingsObject and such. + * + * @see IGUIObject + */ +class IGUIButtonBehavior : virtual public IGUIObject +{ +public: + IGUIButtonBehavior(); + virtual ~IGUIButtonBehavior(); + + /** + * @see IGUIObject#HandleMessage() + */ + virtual void HandleMessage(const EGUIMessage &Message); + +protected: + /** + * Everybody knows how a button works, you don't simply press it, + * you have to first press the button, and then release it... + * in between those two steps you can actually leave the button + * area, as long as you release it within the button area... Anyway + * this lets us know we are done with step one (clicking). + */ + bool m_Pressed; +}; + +#endif \ No newline at end of file diff --git a/source/gui/IGUIObject.cpp b/source/gui/IGUIObject.cpp new file mode 100755 index 0000000000..695109ffd7 --- /dev/null +++ b/source/gui/IGUIObject.cpp @@ -0,0 +1,313 @@ +/* +IGUIObject +by Gustav Larsson +gee@pyro.nu +*/ + +//#include "stdafx." +#include "GUI.h" + +///// janwas: again, including etiquette? +#include "../ps/Parser.h" +#include +///// + +using namespace std; + +// Offsets +map_Settings IGUIObject::m_SettingsInfo; + +//------------------------------------------------------------------- +// Implementation Macros +//------------------------------------------------------------------- +#define _GUI_ADD_OFFSET(type, str, var) \ + SettingsInfo[str].m_Offset = offsetof(IGUIObject, m_BaseSettings) + offsetof(SGUIBaseSettings,var); \ + SettingsInfo[str].m_Type = type; + +//------------------------------------------------------------------- +// Constructor / Destructor +//------------------------------------------------------------------- +IGUIObject::IGUIObject() : + m_pGUI(NULL), + m_pParent(NULL), + m_MouseHovering(false) +{ + // Default values of base settings ! + m_BaseSettings.m_Enabled = true; + m_BaseSettings.m_Hidden = false; + m_BaseSettings.m_Style = "null"; + m_BaseSettings.m_Z = 0.f; + + // Static! Only done once + if (m_SettingsInfo.empty()) + { + SetupBaseSettingsInfo(m_SettingsInfo); + } +} + +IGUIObject::~IGUIObject() +{ +} + +//------------------------------------------------------------------- +// Functions +//------------------------------------------------------------------- +void IGUIObject::SetBaseSettings(const SGUIBaseSettings &Set) +{ + m_BaseSettings = Set; + CheckSettingsValidity(); +} + +void IGUIObject::AddChild(IGUIObject *pChild) +{ + // +// assert(pChild); + + pChild->SetParent(this); + + m_Children.push_back(pChild); + + // If this (not the child) object is already attached + // to a CGUI, it pGUI pointer will be non-null. + // This will mean we'll have to check if we're using + // names already used. + if (pChild->GetGUI()) + { + try + { + // Atomic function, if it fails it won't + // have changed anything + //UpdateObjects(); + pChild->GetGUI()->UpdateObjects(); + } + catch (PS_RESULT e) + { + // If anything went wrong, reverse what we did and throw + // an exception telling it never added a child + m_Children.erase( m_Children.end()-1 ); + + // We'll throw the same exception for easier + // error handling + throw e; + } + } + // else do nothing +} + +void IGUIObject::AddToPointersMap(map_pObjects &ObjectMap) +{ + // Just don't do anything about the top node + if (m_pParent == NULL) + return; + + // Now actually add this one + // notice we won't add it if it's doesn't have any parent + // (i.e. being the base object) + if (m_Name == string()) + { + throw PS_NEEDS_NAME; + } + if (ObjectMap.count(m_Name) > 0) + { + throw PS_NAME_AMBIGUITY; + } + else + { + ObjectMap[m_Name] = this; + } +} + +void IGUIObject::Destroy() +{ + // Is there anything besides the children to destroy? +} + +void IGUIObject::SetupBaseSettingsInfo(map_Settings &SettingsInfo) +{ + SettingsInfo["hejsan"].m_Offset = 0; + + + _GUI_ADD_OFFSET("bool", "enabled", m_Enabled) + _GUI_ADD_OFFSET("bool", "hidden", m_Hidden) + _GUI_ADD_OFFSET("rect", "size1024", m_Size) + _GUI_ADD_OFFSET("string", "style", m_Style) + _GUI_ADD_OFFSET("float", "z", m_Z) + _GUI_ADD_OFFSET("string", "caption", m_Caption) +} + +bool IGUIObject::MouseOver() +{ + if(!GetGUI()) + throw PS_NEEDS_PGUI; + + u16 mouse_x = GetMouseX(), + mouse_y = GetMouseY(); + + return (mouse_x >= m_BaseSettings.m_Size.left && + mouse_x <= m_BaseSettings.m_Size.right && + mouse_y >= m_BaseSettings.m_Size.bottom && + mouse_y <= m_BaseSettings.m_Size.top); +} + +u16 IGUIObject::GetMouseX() const +{ + return ((GetGUI())?(GetGUI()->m_MouseX):0); +} + +u16 IGUIObject::GetMouseY() const +{ + return ((GetGUI())?(GetGUI()->m_MouseY):0); +} + +void IGUIObject::UpdateMouseOver(IGUIObject * const &pMouseOver) +{ + // Check if this is the object being hovered. + if (pMouseOver == this) + { + if (!m_MouseHovering) + { + // It wasn't hovering, so that must mean it just entered + HandleMessage(GUIM_MOUSE_ENTER); + } + + // Either way, set to true + m_MouseHovering = true; + + // call mouse over + HandleMessage(GUIM_MOUSE_OVER); + } + else // Some other object (or none) is hovered + { + if (m_MouseHovering) + { + m_MouseHovering = false; + HandleMessage(GUIM_MOUSE_LEAVE); + } + } +} + +bool IGUIObject::SettingExists(const CStr &Setting) const +{ + // Because GetOffsets will direct dynamically defined + // classes with polymorifsm to respective m_SettingsInfo + // we need to make no further updates on this function + // in derived classes. + return (GetSettingsInfo().count(Setting) == 1)?true:false; +} + +void IGUIObject::SetSetting(const CStr &Setting, const CStr &Value) +{ + if (!SettingExists(Setting)) + { + throw PS_FAIL; + } + + // Get setting + SGUISetting set = GetSettingsInfo()[Setting]; + + if (set.m_Type == CStr(_T("string"))) + { + GUI::SetSetting(this, Setting, Value); + } + else + if (set.m_Type == CStr(_T("float"))) + { + GUI::SetSetting(this, Setting, Value.ToFloat() ); + } + else + if (set.m_Type == CStr(_T("rect"))) + { + // TEMP + //GUI::SetSetting(this, Setting, CRect(100,100,200,200)); + + // Use the parser to parse the values + CParser parser; + parser.InputTaskType("", "_$value_$value_$value_$value_"); + + // TODO Gee string really? + string str = (const TCHAR*)Value; + + CParserLine line; + line.ParseString(parser, str); + if (!line.m_ParseOK) + { + // ERROR! + throw PS_FAIL; + } + int values[4]; + for (int i=0; i<4; ++i) + { + if (!line.GetArgInt(i, values[i])) + { + // ERROR! + throw PS_FAIL; + } + } + + // Finally the rectangle values + CRect rect(values[0], values[1], values[2], values[3]); + GUI::SetSetting(this, Setting, rect); + } + else + { + throw PS_FAIL; + } +} + +void IGUIObject::ChooseMouseOverAndClosest(IGUIObject* &pObject) +{ + if (MouseOver()) + { + // Check if we've got competition at all + if (pObject == NULL) + { + pObject = this; + return; + } + + // Or if it's closer + if (GetBaseSettings().m_Z >= pObject->GetBaseSettings().m_Z) + { + pObject = this; + return; + } + } +} + +IGUIObject *IGUIObject::GetParent() +{ + // Important, we're not using GetParent() for these + // checks, that could screw it up + if (m_pParent) + { + if (m_pParent->m_pParent == NULL) + return NULL; + } + + return m_pParent; +} + +// GeeTODO keep this function and all??? +void IGUIObject::CheckSettingsValidity() +{ + // If we hide an object, reset many of its parts + if (GetBaseSettings().m_Hidden) + { + // Simulate that no object is hovered for this object and all its children + // why? because it's + try + { + GUI::RecurseObject(0, this, &IGUIObject::UpdateMouseOver, NULL); + } + catch (...) {} + } + + try + { + // Send message to myself + HandleMessage(GUIM_SETTINGS_UPDATED); + } + catch (...) + { + } +} \ No newline at end of file diff --git a/source/gui/IGUIObject.h b/source/gui/IGUIObject.h new file mode 100755 index 0000000000..020fe6091a --- /dev/null +++ b/source/gui/IGUIObject.h @@ -0,0 +1,405 @@ +/* +The base class of an object +by Gustav Larsson +gee@pyro.nu + +--Overview-- + + All objects are derived from this class, it's an ADT + so it can't be used per se + + Also contains a Dummy object which is used for + completely blank objects. + +--Usage-- + + Write about how to use it here + +--Examples-- + + Provide examples of how to use this code, if necessary + +--More info-- + + Check GUI.h + +*/ + +#ifndef IGUIObject_H +#define IGUIObject_H + +//-------------------------------------------------------- +// Includes / Compiler directives +//-------------------------------------------------------- +#include "GUI.h" +#include +#include + +struct SGUISetting; +class CGUI; + +//-------------------------------------------------------- +// Macros +//-------------------------------------------------------- + +//-------------------------------------------------------- +// Types +//-------------------------------------------------------- + +// Map with pointers +typedef std::map map_Settings; +typedef std::vector vector_pObjects; + +//-------------------------------------------------------- +// Error declarations +//-------------------------------------------------------- + +//-------------------------------------------------------- +// Declarations +//-------------------------------------------------------- + +// TEMP +struct CRect +{ + CRect() {} + CRect(int _l, int _b, int _r, int _t) : + top(_t), + bottom(_b), + right(_r), + left(_l) {} + int bottom, top, left, right; + + bool operator ==(const CRect &rect) const + { + return (bottom==rect.bottom) && + (top==rect.top) && + (left==rect.left) && + (right==rect.right); + } + + bool operator !=(const CRect &rect) const + { + return !(*this==rect); + } +}; + +// TEMP +struct CColor +{ + float r, g, b, a; +}; + +// Text alignments +enum EAlign { EAlign_Left, EAlign_Right, EAlign_Center }; +enum EValign { EValign_Top, EValign_Bottom, EValign_Center }; + +/** + * @author Gustav Larsson + * + * Stores the information where to find a variable + * in a GUI-Object object, also what type it is. + */ +struct SGUISetting +{ + size_t m_Offset; // The offset from IGUIObject to the variable (not from SGUIBaseSettings or similar) + CStr m_Type; // "string" or maybe "int" +}; + +/** + * @author Gustav Larsson + * + * Base settings, all objects possess these settings + * in their m_BaseSettings + * Instructions can be found in the documentations. + */ +struct SGUIBaseSettings +{ + bool m_Hidden; + bool m_Enabled; + bool m_Absolute; + CRect m_Size; + CStr m_Style; + float m_Z; + CStr m_Caption; // Is usually set within an XML element and not in the attributes +}; + +////////////////////////////////////////////////////////// + +/** + * @author Gustav Larsson + * + * GUI object such as a button or an input-box. + * Abstract data type ! + */ +class IGUIObject +{ + friend class CGUI; + friend class GUI; + +public: + IGUIObject(); + virtual ~IGUIObject(); + + /** + * Get offsets + * + * @return Retrieves settings info + */ + virtual map_Settings GetSettingsInfo() const { return m_SettingsInfo; } + + /** + * Checks if mouse is hovering this object. + * The mouse position is cached in CGUI. + * + * This function checks if the mouse is hovering the + * rectangle that the base setting "size" makes. + * Although it is virtual, so one could derive + * an object from CButton, which changes only this + * to checking the circle that "size" makes. + * + * @return true if mouse is hovering + */ + virtual bool MouseOver(); + + //-------------------------------------------------------- + /** @name Leaf Functions */ + //-------------------------------------------------------- + //@{ + + /// Get object name, name is unique + CStr GetName() const { return m_Name; } + + /// Get object name + void SetName(const CStr &Name) { m_Name = Name; } + + /** + * Adds object and its children to the map, it's name being the + * first part, and the second being itself. + * + * @param ObjectMap Adds this to the map_pObjects. + * + * @throws PS_NEEDS_NAME Name is missing + * @throws PS_NAME_AMBIGUITY Name is already taken + */ + void AddToPointersMap(map_pObjects &ObjectMap); + + /** + * Notice nothing will be returned or thrown if the child hasn't + * been inputted into the GUI yet. This is because that's were + * all is checked. Now we're just linking two objects, but + * it's when we're inputting them into the GUI we'll check + * validity! Notice also when adding it to the GUI this function + * will inevitably have been called by CGUI::AddObject which + * will catch the throw and return the error code. + * i.e. The user will never put in the situation wherein a throw + * must be caught, the GUI's internal error handling will be + * completely transparent to the interfacially sequential model. + * + * @param pChild Child to add + * + * @throws PS_RESULT from CGUI::UpdateObjects(). + */ + void AddChild(IGUIObject *pChild); + + //@} + //-------------------------------------------------------- + /** @name Iterate */ + //-------------------------------------------------------- + //@{ + + vector_pObjects::iterator ChildrenItBegin() { return m_Children.begin(); } + vector_pObjects::iterator ChildrenItEnd() { return m_Children.end(); } + + //@} + //-------------------------------------------------------- + /** @name Settings Management */ + //-------------------------------------------------------- + //@{ + + SGUIBaseSettings GetBaseSettings() const { return m_BaseSettings; } + void SetBaseSettings(const SGUIBaseSettings &Set); + + /** + * Checks if settings exists, only available for derived + * classes that has this set up, that's why the base + * class just returns false + * + * @param Setting setting name + * @return True if settings exist. + */ + bool SettingExists(const CStr &Setting) const; + + /** + * Should be called every time the settings has been updated + * will also send a message GUIM_SETTINGS_UPDATED, so that + * if a derived object wants to add things to be updated, + * they add it in that message part, this is a better solution + * than making this virtual, since the updates that the base + * class does, are the most essential. + * This is not private since there should be no harm in + * checking validity. + * + * @throws GeeTODO not quite settled yet. + */ + void CheckSettingsValidity(); + + /** + * Sets up a map_size_t to include the variables in m_BaseSettings + * + * @param SettingsInfo Pointers that should be filled with base variables + */ + void SetupBaseSettingsInfo(map_Settings &SettingsInfo); + + /** + * Set a setting by string, regardless of what type it is. + * + * example a CRect(10,10,20,20) would be "10 10 20 20" + * + * @param Setting Setting by name + * @param Value Value to set to + */ + void SetSetting(const CStr &Setting, const CStr &Value); + + //@} +protected: + //-------------------------------------------------------- + /** @name Called by CGUI and friends + * + * Methods that the CGUI will call using + * its friendship, these should not + * be called by user. + * These functions' security are a lot + * what constitutes the GUI's + */ + //-------------------------------------------------------- + //@{ + + /** + * Calls Destroy on all children, and deallocates all memory. + * BIG TODO Should it destroy it's children? + */ + virtual void Destroy(); + + /** + * This function is called with different messages + * for instance when the mouse enters the object. + * + * @param Message EGUIMessage + */ + virtual void HandleMessage(const EGUIMessage &Message)=0; + + /** + * Draws the object. + * + * @throws PS_RESULT if any. But this will mostlikely be + * very rare since if an object is drawn unsuccessfully + * it'll probably only output in the Error log, and not + * disrupt the whole GUI drawing. + */ + virtual void Draw()=0; + + // This is done internally + CGUI *GetGUI() { return m_pGUI; } + const CGUI *GetGUI() const { return m_pGUI; } + void SetGUI(CGUI * const &pGUI) { m_pGUI = pGUI; } + + // Set parent + void SetParent(IGUIObject *pParent) { m_pParent = pParent; } + + /** + * NOTE! This will not just return m_pParent, when that is + * need use it! There is one exception to it, when the parent is + * the top-node (the object that isn't a real object), this + * will return NULL, so that the top-node's children are + * seemingly parentless. + * + * @return Pointer to parent + */ + IGUIObject *GetParent(); + + // Get cached mouse x/y from CGUI + u16 GetMouseX() const; + u16 GetMouseY() const; + + //@} +private: + //-------------------------------------------------------- + /** @name Internal functions */ + //-------------------------------------------------------- + //@{ + + /** + * Inputs a reference pointer, checks if the new inputted object + * if hovered, if so, then check if this's Z value is greater + * than the inputted object... If so then the object is closer + * and we'll replace the pointer with this. + * Also Notice input can be NULL, which means the Z value demand + * is out. NOTICE you can't input NULL as const so you'll have + * to set an object to NULL. + * + * @param pObject Object pointer, can be either the old one, or + * the new one. + */ + void ChooseMouseOverAndClosest(IGUIObject* &pObject); + + /** + * Inputes the object that is currently hovered, this function + * updates this object accordingly (i.e. if it's the object + * being inputted one thing happens, and not, another). + * + * @param pMouseOver Object that is currently hovered, + * can OF COURSE be NULL too! + */ + void UpdateMouseOver(IGUIObject * const &pMouseOver); + + //@} + + // Variables + +protected: + /// Name of object + CStr m_Name; + + /// Constructed on the heap, will be destroyed along with the the object TODO Really? + vector_pObjects m_Children; + + /// Pointer to parent + IGUIObject *m_pParent; + + /// Base settings + SGUIBaseSettings m_BaseSettings; + + // More variables + + /// Is mouse hovering the object? used with the function MouseOver() + bool m_MouseHovering; + + /** + * Tells us where a variable by a string name is + * located hardcoded, in order to acquire a pointer + * for that variable... Say "frozen" gives + * the offset from IGUIObject to m_Frozen. + * note! NOT from SGUIBaseSettings to + * m_Frozen! + */ + static map_Settings m_SettingsInfo; + +private: + /// An object can't function stand alone + CGUI *m_pGUI; +}; + + +/** + * @author Gustav Larsson + * + * Dummy object used primarily for the root object + * which isn't a *real* object in the GUI. + */ +class CGUIDummyObject : public IGUIObject +{ + virtual void HandleMessage(const EGUIMessage &Message) {} + virtual void Draw() {} +}; + +#endif \ No newline at end of file diff --git a/source/gui/IGUISettingsObject.cpp b/source/gui/IGUISettingsObject.cpp new file mode 100755 index 0000000000..1b66d1123b --- /dev/null +++ b/source/gui/IGUISettingsObject.cpp @@ -0,0 +1,10 @@ +/* +IGUISettingsObject +by Gustav Larsson +gee@pyro.nu +*/ + +//#include "stdafx.h" +#include "GUI.h" + +using namespace std; \ No newline at end of file diff --git a/source/gui/IGUISettingsObject.h b/source/gui/IGUISettingsObject.h new file mode 100755 index 0000000000..163f700f44 --- /dev/null +++ b/source/gui/IGUISettingsObject.h @@ -0,0 +1,124 @@ +/* +Object with settings +by Gustav Larsson +gee@pyro.nu + +--Overview-- + + Generic object that stores a struct with settings + +--Usage-- + + If an object wants settings with a standard, + it will use this as a middle step instead of being + directly derived from IGUIObject + +--Examples-- + + instead of: + + class CButton : public IGUIObject + + you go: + + class CButton : public IGUISettingsObject + + and SButtonSettings will be included as m_Settings with + all gets and sets set up + +--More info-- + + Check GUI.h + +*/ + +#ifndef IGUISettingsObject_H +#define IGUISettingsObject_H + +//-------------------------------------------------------- +// Includes / Compiler directives +//-------------------------------------------------------- +#include "GUI.h" + +//-------------------------------------------------------- +// Macros +//-------------------------------------------------------- + +//-------------------------------------------------------- +// Types +//-------------------------------------------------------- + +//-------------------------------------------------------- +// Error declarations +//-------------------------------------------------------- + +//-------------------------------------------------------- +// Declarations +//-------------------------------------------------------- + +/** + * @author Gustav Larsson + * + * Appends more settings to the IGUIObject. + * Can be used with multiple inheritance. + * + * @see IGUIObject + */ +template +class IGUISettingsObject : virtual public IGUIObject +{ +public: + IGUISettingsObject() {} + virtual ~IGUISettingsObject() {} + + /** + * Get Offsets, important to include so it returns this + * m_Offsets and not IGUIObject::m_SettingsInfo + * + * @return Settings infos + */ + virtual map_Settings GetSettingsInfo() const { return m_SettingsInfo; } + + /** + * @return Returns a copy of m_Settings + */ + SETTINGS GetSettings() const { return m_Settings; } + + /// Sets settings + void SetSettings(const SETTINGS &Set) + { + m_Settings = Set; + + //CheckSettingsValidity(); + // Since that function out-commented above really + // does just update the base settings, we'll call + // the message immediately instead + try + { + HandleMessage(GUIM_SETTINGS_UPDATED); + } + catch (...) { } + } + +protected: + /// Settings struct + SETTINGS m_Settings; + + /** + * Offset database\n + * tells us where a variable by a string name is + * located hardcoded, in order to acquire a pointer + * for that variable... Say "frozen" gives + * the offset from IGUIObject to m_Frozen. + * + * note! _NOT_ from SGUIBaseSettings to m_Frozen! + * + * Note that it's imperative that this m_SettingsInfo includes + * all offsets of m_BaseSettings too, because when + * using this class, this m_SettingsInfo will be the only + * one used. + */ + static map_Settings m_SettingsInfo; +}; + +#endif \ No newline at end of file diff --git a/source/gui/XercesErrorHandler.h b/source/gui/XercesErrorHandler.h index 636c95b1da..7057dea63a 100755 --- a/source/gui/XercesErrorHandler.h +++ b/source/gui/XercesErrorHandler.h @@ -24,51 +24,77 @@ gee@pyro.nu #include #include - +/** + * @author Gustav Larsson + * + * Adapter function that catches Xerces Reading Exceptions + * and lets us output them in Prometheus CLogFile. + * + * Used for all Xerces C++ Parser reading. + * + * @see http://xml.apache.org/xerces-c/apiDocs/classErrorHandler.html + */ class CXercesErrorHandler : public XERCES_CPP_NAMESPACE::ErrorHandler { public: - // ----------------------------------------------------------------------- - // Constructors and Destructor - // ----------------------------------------------------------------------- CXercesErrorHandler() : fSawErrors(false) - { - } + {} ~CXercesErrorHandler() - { - } - + {} // ----------------------------------------------------------------------- - // Implementation of the error handler interface + /** @name Implementation of the error handler interface */ // ----------------------------------------------------------------------- + //@{ + /** + * Sends warning exceptions here. + */ void warning(const XERCES_CPP_NAMESPACE::SAXParseException& toCatch); + + /** + * Sends error exceptions here. + */ void error(const XERCES_CPP_NAMESPACE::SAXParseException& toCatch); + + /** + * Sends fatal error exceptions here. + */ void fatalError(const XERCES_CPP_NAMESPACE::SAXParseException& toCatch); + + /** + * Sets fSawError to false. + */ void resetErrors(); + //@} // ----------------------------------------------------------------------- - // Getter methods + /** @name Access Functions */ // ----------------------------------------------------------------------- - bool getSawErrors() const; + //@{ + /** + * @return true if Errors Occured + */ + bool getSawErrors() const { return fSawErrors; } + //@} private: // ----------------------------------------------------------------------- - // Private data members - // - // fSawErrors - // This is set if we get any errors, and is queryable via a getter - // method. Its used by the main code to suppress output if there are - // errors. + /** @name Private data members */ // ----------------------------------------------------------------------- + //@{ + + /** + * This is set if we get any errors, and is queryable via an access + * function. Its used by the main code to suppress output if there are + * errors. + * + * @see getSawErrors() + */ bool fSawErrors; + + //@} }; -inline bool CXercesErrorHandler::getSawErrors() const -{ - return fSawErrors; -} - #endif \ No newline at end of file diff --git a/source/lib/font.h b/source/lib/font.h index 6a7e87b398..f489730a0f 100755 --- a/source/lib/font.h +++ b/source/lib/font.h @@ -50,7 +50,7 @@ void init() { glMatrixMode(GL_PROJECTION); glLoadIdentity(); - glOrtho(0, xres, 0, yres, -1, 1); + glOrtho(0, g_xres, 0, g_yres, -1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); diff --git a/source/ps/CStr.cpp b/source/ps/CStr.cpp index ebd2833fc1..7c1c3ce37b 100755 --- a/source/ps/CStr.cpp +++ b/source/ps/CStr.cpp @@ -360,6 +360,11 @@ CStr::operator const TCHAR*() return m_String.c_str(); } +CStr::operator const TCHAR*() const +{ + return m_String.c_str(); +} + TCHAR &CStr::operator[](_int n) { diff --git a/source/ps/CStr.h b/source/ps/CStr.h index aea153c8a2..5346c6ce31 100755 --- a/source/ps/CStr.h +++ b/source/ps/CStr.h @@ -164,6 +164,7 @@ public: CStr &operator+=(CStr &Str); CStr operator+(CStr &Str); operator const TCHAR*(); + operator const TCHAR*() const; // Gee, I've added this, Maybe the one above should be removed? TCHAR &operator[](_int n); TCHAR &operator[](_uint n); TCHAR &operator[](_long n); diff --git a/source/ps/Prometheus.cpp b/source/ps/Prometheus.cpp index 88594a8ce8..15a999d152 100755 --- a/source/ps/Prometheus.cpp +++ b/source/ps/Prometheus.cpp @@ -1,4 +1,7 @@ #include "Prometheus.h" +// Globals +int g_xres = 800, g_yres = 600; + DEFINE_ERROR(PS_OK, "OK"); DEFINE_ERROR(PS_FAIL, "Fail"); diff --git a/source/ps/Prometheus.h b/source/ps/Prometheus.h index 9a0a327c93..192c2e6cff 100755 --- a/source/ps/Prometheus.h +++ b/source/ps/Prometheus.h @@ -16,6 +16,10 @@ Standard declarations which are included in all projects. #include #include +// Globals +extern int g_xres, g_yres; + + // Standard typedefs typedef int _int;