forked from 0ad/0ad
no message
This was SVN commit r74.
This commit is contained in:
parent
6b51d71c85
commit
5122b0f906
13
binaries/data/gui/hello.xml
Executable file
13
binaries/data/gui/hello.xml
Executable file
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="iso-8859-1" standalone="no" ?>
|
||||
|
||||
<!DOCTYPE objects SYSTEM "file:///C:/objects.dtd">
|
||||
|
||||
<objects>
|
||||
<object name="Button2" type="button" size1024="10 10 100 100" style="hello" z="10" />
|
||||
|
||||
<object name="Button3" type="button" size1024="120 120 220 220" style="hello" z="20">
|
||||
<object name="Child" type="button" size1024="140 140 300 200" z="22">
|
||||
<object name="ChildsChilds" type="button" size1024="200 150 400 190" z="24"> </object>
|
||||
</object>
|
||||
</object>
|
||||
</objects>
|
49
binaries/data/gui/objects.dtd
Executable file
49
binaries/data/gui/objects.dtd
Executable file
@ -0,0 +1,49 @@
|
||||
<!--
|
||||
GUI XML Files DTD
|
||||
|
||||
Root Element: <objects>
|
||||
|
||||
Version:
|
||||
-->
|
||||
|
||||
<!ELEMENT objects (object*)>
|
||||
<!ELEMENT object (#PCDATA|object|action)*>
|
||||
|
||||
<!--
|
||||
Base Settings
|
||||
-->
|
||||
<!ATTLIST object name CDATA #IMPLIED>
|
||||
<!ATTLIST object type CDATA #IMPLIED>
|
||||
<!ATTLIST object absolute (true|false) #IMPLIED>
|
||||
<!ATTLIST object disabled (true|false) #IMPLIED>
|
||||
<!ATTLIST object ghost (true|false) #IMPLIED>
|
||||
<!ATTLIST object hidden (true|false) #IMPLIED>
|
||||
<!ATTLIST object size1024 CDATA #IMPLIED>
|
||||
<!ATTLIST object style CDATA #IMPLIED>
|
||||
<!ATTLIST object z CDATA #IMPLIED>
|
||||
|
||||
<!--
|
||||
Setting Pool
|
||||
-->
|
||||
<!ATTLIST object font CDATA #IMPLIED>
|
||||
<!ATTLIST object input-initvalue-destroyed-at-focus (true|false) #IMPLIED>
|
||||
<!ATTLIST object rectcolor-selected CDATA #IMPLIED>
|
||||
<!ATTLIST object scrollbar (true|false) #IMPLIED>
|
||||
<!ATTLIST object scrollbar-style CDATA #IMPLIED>
|
||||
<!ATTLIST object sprite CDATA #IMPLIED>
|
||||
<!ATTLIST object sprite2 CDATA #IMPLIED>
|
||||
<!ATTLIST object sprite-disabled CDATA #IMPLIED>
|
||||
<!ATTLIST object sprite2-disabled CDATA #IMPLIED>
|
||||
<!ATTLIST object sprite-over CDATA #IMPLIED>
|
||||
<!ATTLIST object sprite2-over CDATA #IMPLIED>
|
||||
<!ATTLIST object sprite-pressed CDATA #IMPLIED>
|
||||
<!ATTLIST object square-side CDATA #IMPLIED>
|
||||
<!ATTLIST object textalign (left|center|right) #IMPLIED>
|
||||
<!ATTLIST object textcolor CDATA #IMPLIED>
|
||||
<!ATTLIST object textcolor-disabled CDATA #IMPLIED>
|
||||
<!ATTLIST object textcolor-over CDATA #IMPLIED>
|
||||
<!ATTLIST object textcolor-pressed CDATA #IMPLIED>
|
||||
<!ATTLIST object textcolor-selected CDATA #IMPLIED>
|
||||
<!ATTLIST object textvalign (top|center|bottom) #IMPLIED>
|
||||
<!ATTLIST object tooltip CDATA #IMPLIED>
|
||||
<!ATTLIST object tooltip-style CDATA #IMPLIED>
|
9
binaries/data/gui/sprite1.xml
Executable file
9
binaries/data/gui/sprite1.xml
Executable file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="iso-8859-1" standalone="no"?>
|
||||
|
||||
<!DOCTYPE sprites SYSTEM "sprites.dtd">
|
||||
|
||||
<sprites>
|
||||
<sprite name="sprite1">
|
||||
<image texture="t1" />
|
||||
</sprite>
|
||||
</sprites>
|
28
binaries/data/gui/sprites.dtd
Executable file
28
binaries/data/gui/sprites.dtd
Executable file
@ -0,0 +1,28 @@
|
||||
<!--
|
||||
GUI XML Files DTD
|
||||
|
||||
Root Element: <sprites>
|
||||
|
||||
Version:
|
||||
-->
|
||||
|
||||
<!ELEMENT sprites (sprite*)>
|
||||
<!ELEMENT sprite (image+)>
|
||||
<!ELEMENT image (#PCDATA)>
|
||||
|
||||
<!--
|
||||
<sprite>
|
||||
-->
|
||||
<!ATTLIST sprite name CDATA #REQUIRED>
|
||||
|
||||
<!--
|
||||
<image>
|
||||
-->
|
||||
<!ATTLIST image texture CDATA #IMPLIED>
|
||||
<!ATTLIST image pixel CDATA #IMPLIED>
|
||||
<!ATTLIST image percent CDATA #IMPLIED>
|
||||
<!ATTLIST image t_pixel CDATA #IMPLIED>
|
||||
<!ATTLIST image t_percent CDATA #IMPLIED>
|
||||
<!ATTLIST image backcolor CDATA #IMPLIED>
|
||||
<!ATTLIST image bordercolor CDATA #IMPLIED>
|
||||
<!ATTLIST image bordersize CDATA #IMPLIED>
|
@ -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(<red>%s</>) <AADDFF>%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);
|
||||
|
||||
|
@ -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<SButtonSettings>, public CGUIButtonBehavior
|
||||
class CButton : public IGUISettingsObject<SButtonSettings>, public IGUIButtonBehavior
|
||||
{
|
||||
GUI_OBJECT(CButton)
|
||||
|
||||
@ -79,7 +79,7 @@ public:
|
||||
*
|
||||
* @return Settings infos
|
||||
*/
|
||||
virtual map_Settings GetSettingsInfo() const { return CGUISettingsObject<SButtonSettings>::m_SettingsInfo; }
|
||||
virtual map_Settings GetSettingsInfo() const { return IGUISettingsObject<SButtonSettings>::m_SettingsInfo; }
|
||||
|
||||
/**
|
||||
* Handle Messages
|
||||
|
@ -10,15 +10,15 @@ gee@pyro.nu
|
||||
#include <assert.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
///#include "nemesis.h"
|
||||
//#include incCONSOLE
|
||||
|
||||
#include <xercesc/dom/DOM.hpp>
|
||||
#include <xercesc/parsers/XercesDOMParser.hpp>
|
||||
#include <xercesc/framework/LocalFileInputSource.hpp>
|
||||
#include <xercesc/util/XMLString.hpp>
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
|
||||
#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<CGUIObject*>::RecurseObject(GUIRR_HIDDEN, m_BaseObject, &CGUIObject::ChooseMouseOverAndClosest, pNearest);
|
||||
// pNearest will after this point at the hovered object, possibly NULL
|
||||
GUI<IGUIObject*>::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<CGUIObject*>::RecurseObject(GUIRR_HIDDEN, m_BaseObject, &CGUIObject::UpdateMouseOver, pNearest);
|
||||
GUI<IGUIObject*>::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<EGUIMessage>::RecurseObject(0, m_BaseObject, &CGUIObject::HandleMessage, GUIM_PREPROCESS);
|
||||
GUI<EGUIMessage>::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<CGUIObject*>::RecurseObject(GUIRR_HIDDEN, m_BaseObject, &CGUIObject::ChooseMouseOverAndClosest, pNearest);
|
||||
GUI<IGUIObject*>::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<CGUIObject*>::RecurseObject(GUIRR_HIDDEN, m_BaseObject, &CGUIObject::UpdateMouseOver, pNearest);
|
||||
GUI<IGUIObject*>::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<EGUIMessage>::RecurseObject(0, m_BaseObject, &CGUIObject::HandleMessage, GUIM_POSTPROCESS);
|
||||
GUI<EGUIMessage>::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<CGUI*>::RecurseObject(0, pObject, &CGUIObject::SetGUI, this);
|
||||
GUI<CGUI*>::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") ) );
|
||||
|
@ -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<CGUI>
|
||||
{
|
||||
// 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:<br>
|
||||
* 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:
|
||||
|
|
||||
+-\<action\>
|
||||
|
|
||||
+-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 \<objects\> (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 \<sprites\> (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 \<object\> (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
|
||||
* \<action\> will call Xerces_ReadAction (TODO, real funcion?).
|
||||
*
|
||||
* Reads in the root element "sprites" (the DOMElement).
|
||||
* Reads in the root element \<sprites\> (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 \<sprite\> (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 \<image\> (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<CStr, ConstructObjectFunction> m_ObjectTypes;
|
||||
@ -333,7 +341,7 @@ private:
|
||||
//--------------------------------------------------------
|
||||
//@{
|
||||
|
||||
std::map<CStr, CGUISprite> m_Sprites;
|
||||
std::map<CStr, CGUISprite> m_Sprites;
|
||||
|
||||
//@}
|
||||
};
|
||||
|
@ -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
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -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
|
||||
* <a href="http://gee.pyro.nu/GUIfiles/">Technical Design Document</a>
|
||||
*
|
||||
* The GUI uses <a href="http://xml.apache.org/xerces-c/">Xerces C++ Parser</a>,
|
||||
* 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"
|
||||
|
@ -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 <code>CGUIObject::HandleMessage()</code> in order
|
||||
/**
|
||||
* @enum EGUIMessage
|
||||
* Message send to IGUIObject::HandleMessage() in order
|
||||
* to give life to Objects manually with
|
||||
* a derived <code>HandleMessage()</code>.
|
||||
* a derived HandleMessage().
|
||||
*/
|
||||
enum EGUIMessage
|
||||
{
|
||||
@ -95,7 +96,7 @@ enum
|
||||
};
|
||||
|
||||
// Typedefs
|
||||
typedef std::map<CStr, CGUIObject*> map_pObjects;
|
||||
typedef std::map<CStr, IGUIObject*> map_pObjects;
|
||||
|
||||
|
||||
//--------------------------------------------------------
|
||||
|
@ -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;
|
||||
|
@ -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 <code>CGUIObject</code>-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).
|
||||
*
|
||||
* <b>Restrictions:</b><br>
|
||||
* <b>Restrictions:</b>\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
|
||||
* <code>GUIRR_*</code> 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)
|
||||
{
|
||||
|
60
source/gui/IGUIButtonBehavior.cpp
Executable file
60
source/gui/IGUIButtonBehavior.cpp
Executable file
@ -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;
|
||||
}
|
||||
}
|
71
source/gui/IGUIButtonBehavior.h
Executable file
71
source/gui/IGUIButtonBehavior.h
Executable file
@ -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
|
313
source/gui/IGUIObject.cpp
Executable file
313
source/gui/IGUIObject.cpp
Executable file
@ -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 <assert.h>
|
||||
/////
|
||||
|
||||
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<CStr>::SetSetting(this, Setting, Value);
|
||||
}
|
||||
else
|
||||
if (set.m_Type == CStr(_T("float")))
|
||||
{
|
||||
GUI<float>::SetSetting(this, Setting, Value.ToFloat() );
|
||||
}
|
||||
else
|
||||
if (set.m_Type == CStr(_T("rect")))
|
||||
{
|
||||
// TEMP
|
||||
//GUI<CRect>::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<CRect>::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<IGUIObject*>::RecurseObject(0, this, &IGUIObject::UpdateMouseOver, NULL);
|
||||
}
|
||||
catch (...) {}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// Send message to myself
|
||||
HandleMessage(GUIM_SETTINGS_UPDATED);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
}
|
405
source/gui/IGUIObject.h
Executable file
405
source/gui/IGUIObject.h
Executable file
@ -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 <string>
|
||||
#include <vector>
|
||||
|
||||
struct SGUISetting;
|
||||
class CGUI;
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Macros
|
||||
//--------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Types
|
||||
//--------------------------------------------------------
|
||||
|
||||
// Map with pointers
|
||||
typedef std::map<CStr, SGUISetting> map_Settings;
|
||||
typedef std::vector<IGUIObject*> 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; }
|
||||
|
||||
/**
|
||||
* <b>NOTE!</b> 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.
|
||||
* <b>note!</b> <u>NOT</u> 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
|
10
source/gui/IGUISettingsObject.cpp
Executable file
10
source/gui/IGUISettingsObject.cpp
Executable file
@ -0,0 +1,10 @@
|
||||
/*
|
||||
IGUISettingsObject
|
||||
by Gustav Larsson
|
||||
gee@pyro.nu
|
||||
*/
|
||||
|
||||
//#include "stdafx.h"
|
||||
#include "GUI.h"
|
||||
|
||||
using namespace std;
|
124
source/gui/IGUISettingsObject.h
Executable file
124
source/gui/IGUISettingsObject.h
Executable file
@ -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<SButtonSettings>
|
||||
|
||||
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 <typename SETTINGS>
|
||||
class IGUISettingsObject : virtual public IGUIObject
|
||||
{
|
||||
public:
|
||||
IGUISettingsObject() {}
|
||||
virtual ~IGUISettingsObject() {}
|
||||
|
||||
/**
|
||||
* Get Offsets, <b>important</b> 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;
|
||||
|
||||
/**
|
||||
* <b>Offset database</b>\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.
|
||||
*
|
||||
* <b>note!</b> _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
|
@ -24,51 +24,77 @@ gee@pyro.nu
|
||||
#include <xercesc/sax/ErrorHandler.hpp>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
/**
|
||||
* @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
|
@ -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();
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
@ -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");
|
||||
|
@ -16,6 +16,10 @@ Standard declarations which are included in all projects.
|
||||
#include <math.h>
|
||||
#include <assert.h>
|
||||
|
||||
// Globals
|
||||
extern int g_xres, g_yres;
|
||||
|
||||
|
||||
// Standard typedefs
|
||||
|
||||
typedef int _int;
|
||||
|
Loading…
Reference in New Issue
Block a user