2003-11-03 17:22:45 +01:00
|
|
|
/*
|
|
|
|
CGUI
|
|
|
|
by Gustav Larsson
|
|
|
|
gee@pyro.nu
|
|
|
|
|
|
|
|
--Overview--
|
|
|
|
|
|
|
|
This is the top class of the whole GUI, all objects
|
|
|
|
and settings are stored within this class.
|
|
|
|
|
|
|
|
--More info--
|
|
|
|
|
|
|
|
Check GUI.h
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CGUI_H
|
|
|
|
#define CGUI_H
|
|
|
|
|
|
|
|
//--------------------------------------------------------
|
|
|
|
// Includes / Compiler directives
|
|
|
|
//--------------------------------------------------------
|
|
|
|
#include "GUI.h"
|
|
|
|
#include <xercesc/dom/DOM.hpp>
|
|
|
|
#include <xercesc/util/XMLString.hpp>
|
|
|
|
#include <xercesc/util/PlatformUtils.hpp>
|
|
|
|
|
2003-11-05 23:34:38 +01:00
|
|
|
///// janwas: yeah I don't know how the including etiquette is really
|
|
|
|
#include "../ps/Singleton.h"
|
2003-11-03 17:22:45 +01:00
|
|
|
#include "input.h" // JW: grr, classes suck in this case :P
|
|
|
|
|
|
|
|
class XERCES_CPP_NAMESPACE::DOMElement;
|
|
|
|
|
2003-11-05 23:34:38 +01:00
|
|
|
|
2003-11-03 17:22:45 +01:00
|
|
|
//--------------------------------------------------------
|
|
|
|
// Macros
|
|
|
|
//--------------------------------------------------------
|
|
|
|
|
|
|
|
//--------------------------------------------------------
|
|
|
|
// Types
|
|
|
|
//--------------------------------------------------------
|
|
|
|
|
|
|
|
//--------------------------------------------------------
|
|
|
|
// Error declarations
|
|
|
|
//--------------------------------------------------------
|
|
|
|
|
|
|
|
//--------------------------------------------------------
|
|
|
|
// Declarations
|
|
|
|
//--------------------------------------------------------
|
|
|
|
|
2003-11-05 23:34:38 +01:00
|
|
|
class CGUI : public Singleton<CGUI>
|
2003-11-03 17:22:45 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
// Only CGUIObject's leaf functions uses CGUI
|
|
|
|
// freely.
|
|
|
|
friend class CGUIObject;
|
2003-11-05 23:34:38 +01:00
|
|
|
friend class CInternalCGUIAccessorBase;
|
2003-11-03 17:22:45 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Private typedefs
|
|
|
|
typedef CGUIObject *(*ConstructObjectFunction)();
|
|
|
|
|
2003-11-05 00:59:41 +01:00
|
|
|
// don't want to pass this around with the ChooseMouseOverAndClosest broadcast -
|
|
|
|
// we'd need to pack this and pNearest in a struct
|
2003-11-05 23:34:38 +01:00
|
|
|
u16 m_MouseX, m_MouseY;
|
2003-11-05 00:59:41 +01:00
|
|
|
|
2003-11-03 17:22:45 +01:00
|
|
|
public:
|
|
|
|
CGUI();
|
|
|
|
~CGUI();
|
|
|
|
|
|
|
|
// Initialize
|
|
|
|
void Initialize(/*/*nemInput *pInput*/);
|
|
|
|
|
|
|
|
// Process
|
|
|
|
void Process();
|
|
|
|
|
|
|
|
// Draw
|
|
|
|
void Draw();
|
|
|
|
|
|
|
|
// Shutdown
|
|
|
|
void Destroy();
|
|
|
|
|
2003-11-05 00:41:42 +01:00
|
|
|
bool HandleEvent(const SDL_Event& ev);
|
|
|
|
|
2003-11-03 17:22:45 +01:00
|
|
|
// Load a GUI XML file
|
2003-11-07 02:55:29 +01:00
|
|
|
void LoadXMLFile(const std::string &Filename);
|
2003-11-03 17:22:45 +01:00
|
|
|
|
|
|
|
// Checks if object exists and return true or false accordingly
|
|
|
|
bool ObjectExists(const CStr &Name) const;
|
|
|
|
|
|
|
|
// Get pInput
|
|
|
|
/// CInput *GetInput() { return m_pInput; }
|
|
|
|
|
|
|
|
// to add a type:
|
|
|
|
// AddObjecType("button", &CButton::ConstructObject);
|
|
|
|
void AddObjectType(const CStr &str, ConstructObjectFunction pFunc) { m_ObjectTypes[str] = pFunc; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
void UpdateObjects();
|
|
|
|
|
|
|
|
// Adds an object to the GUI's object database
|
|
|
|
// Private, you can only add objects through XML files.
|
|
|
|
void AddObject(CGUIObject* pObject);
|
|
|
|
|
|
|
|
// Report a XML parsing error
|
|
|
|
void ReportParseError(const CStr &str, ...);
|
|
|
|
|
|
|
|
// Construct an object
|
|
|
|
CGUIObject *ConstructObject(const CStr &str);
|
|
|
|
|
|
|
|
//
|
|
|
|
// XML Reading Xerces C++ specific subroutines
|
|
|
|
//
|
|
|
|
|
|
|
|
/**
|
|
|
|
Xerces_* functions tree
|
|
|
|
|
|
|
|
==========================
|
|
|
|
|
|
|
|
<objects> (ReadRootObjects)
|
|
|
|
|
|
|
|
|
+-<object> (ReadObject)
|
|
|
|
|
|
|
|
|
+-<action>
|
|
|
|
|
|
|
|
|
+-Optional Type Extensions (CGUIObject::ReadExtendedElement) TODO
|
|
|
|
|
|
|
|
|
+-�object� *recursive*
|
|
|
|
|
|
|
|
|
|
|
|
<styles> (ReadRootStyles)
|
|
|
|
|
|
|
|
|
+-<style> (ReadStyle)
|
|
|
|
|
|
|
|
|
|
|
|
<sprites> (ReadRootSprites)
|
|
|
|
|
|
|
|
|
+-<sprite> (ReadSprite)
|
|
|
|
|
|
|
|
|
+-<image> (ReadImage)
|
|
|
|
|
|
|
|
|
|
|
|
<setup> (ReadRootSetup)
|
|
|
|
|
|
|
|
|
+-<tooltip> (ReadToolTip)
|
|
|
|
|
|
|
|
|
+-<scrollbar> (ReadScrollBar)
|
|
|
|
|
|
|
|
|
+-<icon> (ReadIcon)
|
|
|
|
|
|
|
|
==========================
|
|
|
|
*/
|
|
|
|
|
|
|
|
// These does not throw!
|
|
|
|
// Because when reading in XML files, it won't be fatal
|
|
|
|
// if an error occurs, perhaps one particular object
|
|
|
|
// fails, but it'll still continue reading in the next
|
|
|
|
// All Error are reported with ReportParseError
|
|
|
|
|
|
|
|
// Read roots
|
|
|
|
void Xerces_ReadRootObjects(XERCES_CPP_NAMESPACE::DOMElement *pElement);
|
|
|
|
void Xerces_ReadRootSprites(XERCES_CPP_NAMESPACE::DOMElement *pElement);
|
|
|
|
|
|
|
|
// Read subs
|
|
|
|
void Xerces_ReadObject(XERCES_CPP_NAMESPACE::DOMElement *, CGUIObject *pParent);
|
|
|
|
void Xerces_ReadSprite(XERCES_CPP_NAMESPACE::DOMElement *);
|
|
|
|
void Xerces_ReadImage(XERCES_CPP_NAMESPACE::DOMElement *, CGUISprite &parent);
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
// Variables
|
|
|
|
|
|
|
|
// Pointer to input module
|
|
|
|
/// CInput *m_pInput;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Objects
|
|
|
|
//
|
|
|
|
|
|
|
|
// Base Object, all its children are considered parentless
|
|
|
|
// because this is no real object per se.
|
|
|
|
CGUIObject* m_BaseObject;
|
|
|
|
|
|
|
|
// Just pointers for fast name access, each object
|
|
|
|
// is really constructed within its parent for easy
|
|
|
|
// recursive management.
|
|
|
|
// Notice m_BaseObject won't belong here since it's
|
|
|
|
// not considered a real object.
|
|
|
|
map_pObjects m_pAllObjects;
|
|
|
|
|
|
|
|
// Function pointers to functions that constructs
|
|
|
|
// CGUIObjects by name... For instance m_ObjectTypes["button"]
|
|
|
|
// is filled with a function that will "return new CButton();"
|
|
|
|
std::map<CStr, ConstructObjectFunction> m_ObjectTypes;
|
|
|
|
|
|
|
|
// Used when reading in XML files
|
|
|
|
int m_Errors;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Sprites
|
|
|
|
//
|
|
|
|
|
|
|
|
std::map<CStr, CGUISprite> m_Sprites;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|