Some updates on the file layout

This was SVN commit r28.
This commit is contained in:
Gee 2003-11-05 22:34:38 +00:00
parent 88bbb5148a
commit 8d0cb1b954
10 changed files with 92 additions and 409 deletions

View File

@ -135,8 +135,13 @@ void CButton::Draw()
else
glColor3f((float)m_BaseSettings.m_Size.right/300.f,0,1);
////////// Gee: janwas, this is just temp to see it
glDisable(GL_TEXTURE_2D);
//////////
glPushMatrix();
glTranslatef(0.0f, 0.0f, GetBaseSettings().m_Z);
/// glTranslatef(0.0f, 0.0f, GetBaseSettings().m_Z);
glTranslatef(0.0f, 0.0f, 0.0f);
// Do this
glBegin(GL_QUADS);

View File

@ -63,7 +63,6 @@ public:
virtual ~CButton();
// Since we're doing multiple inheritance, this is to avoid error message
virtual map_Settings GetSettingsInfo() const { return CGUISettingsObject<SButtonSettings>::m_SettingsInfo; }

View File

@ -31,22 +31,21 @@ using namespace std;
#include "input.h"
// called from main loop when (input) events are received.
// event is passed to other handlers if false is returned.
// trampoline: we don't want to make the implementation (in CGUI) static
bool gui_handler(const SDL_Event& ev)
{
// return gui.HandleEvent(ev);
return g_GUI.HandleEvent(ev);
return false;
// return false;
}
bool CGUI::HandleEvent(const SDL_Event& ev)
{
if(ev.type == SDL_MOUSEMOTION)
mouse_x = ev.motion.x, mouse_y = ev.motion.y;
m_MouseX = ev.motion.x, m_MouseY = ev.motion.y;
// JW: (pre|post)process omitted; what're they for? why would we need any special button_released handling?

View File

@ -25,10 +25,13 @@ gee@pyro.nu
#include <xercesc/util/XMLString.hpp>
#include <xercesc/util/PlatformUtils.hpp>
///// janwas: yeah I don't know how the including etiquette is really
#include "../ps/Singleton.h"
#include "input.h" // JW: grr, classes suck in this case :P
class XERCES_CPP_NAMESPACE::DOMElement;
//--------------------------------------------------------
// Macros
//--------------------------------------------------------
@ -45,12 +48,13 @@ class XERCES_CPP_NAMESPACE::DOMElement;
// Declarations
//--------------------------------------------------------
class CGUI
class CGUI : public Singleton<CGUI>
{
// Only CGUIObject's leaf functions uses CGUI
// freely.
friend class CGUIObject;
friend class CInternalCGUIAccessorBase;
private:
// Private typedefs
@ -58,7 +62,7 @@ private:
// don't want to pass this around with the ChooseMouseOverAndClosest broadcast -
// we'd need to pack this and pNearest in a struct
u16 mouse_x, mouse_y;
u16 m_MouseX, m_MouseY;
public:
CGUI();

View File

@ -6,15 +6,27 @@ gee@pyro.nu
//#include "stdafx."
#include "GUI.h"
#include "cgui.h"
///#include "Parser/parser.h"
///// janwas: you addded this? not needed
//#include "cgui.h"
/////
///// janwas: again, including etiquette?
#include "../ps/Parser.h"
#include <assert.h>
/////
using namespace std;
// Offsets
map_Settings CGUIObject::m_SettingsInfo;
// This must be placed after the line above defining
// m_SettingsInfo, GeeTODO, I'm not sure if this is
// the appropriate file, but it crashes if it's not
// in this file.
CGUI g_GUI;
//-------------------------------------------------------------------
// Implementation Macros
//-------------------------------------------------------------------
@ -158,6 +170,9 @@ void CGUIObject::Destroy()
//-------------------------------------------------------------------
void CGUIObject::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)
@ -166,23 +181,35 @@ void CGUIObject::SetupBaseSettingsInfo(map_Settings &SettingsInfo)
_GUI_ADD_OFFSET("string", "caption", m_Caption)
}
//-------------------------------------------------------------------
// Checks if mouse is over and returns result
// mouse_x, mouse_y defined in CGUI
//-------------------------------------------------------------------
bool CGUIObject::MouseOver()
{
CGUI* gui = GetGUI();
if(!gui)
if(!GetGUI())
throw PS_NEEDS_PGUI;
return (gui->mouse_x >= m_BaseSettings.m_Size.left &&
gui->mouse_x <= m_BaseSettings.m_Size.right &&
gui->mouse_y >= m_BaseSettings.m_Size.bottom &&
gui->mouse_y <= m_BaseSettings.m_Size.top);
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);
}
//-------------------------------------------------------------------
// Get Mouse X/Y from CGUI
//-------------------------------------------------------------------
u16 CGUIObject::GetMouseX() const
{
return ((GetGUI())?(GetGUI()->m_MouseX):0);
}
u16 CGUIObject::GetMouseY() const
{
return ((GetGUI())?(GetGUI()->m_MouseY):0);
}
//-------------------------------------------------------------------
@ -234,7 +261,6 @@ bool CGUIObject::SettingExists(const CStr &Setting) const
return (GetSettingsInfo().count(Setting) == 1)?true:false;
}
//-------------------------------------------------------------------
// Set a setting by string, regardless of what type it is...
// example a CRect(10,10,20,20) would be "10 10 20 20"
@ -287,10 +313,10 @@ void CGUIObject::SetSetting(const CStr &Setting, const CStr &Value)
if (set.m_Type == "rect")
{
// TEMP
GUI<CRect>::SetSetting(this, Setting, CRect(100,100,200,200));
// GUI<CRect>::SetSetting(this, Setting, CRect(100,100,200,200));
// Use the parser to parse the values
/* CParser parser;
CParser parser;
parser.InputTaskType("", "_$value_$value_$value_$value_");
CParserLine line;
@ -313,7 +339,7 @@ void CGUIObject::SetSetting(const CStr &Setting, const CStr &Value)
// Finally the rectangle values
CRect rect(values[0], values[1], values[2], values[3]);
GUI<CRect>::SetSetting(this, Setting, rect);
*/ }
}
else
{
throw PS_FAIL;
@ -374,6 +400,7 @@ CGUIObject *CGUIObject::GetParent()
return m_pParent;
}
// GeeTODO keep this function and all???
//-------------------------------------------------------------------
// Called every time settings are change, this is where you check
// validity (not syntactical, that's already check) of your values.

View File

@ -35,6 +35,8 @@ gee@pyro.nu
struct SGUISetting;
class CGUI;
extern CGUI g_GUI;
//--------------------------------------------------------
// Macros
//--------------------------------------------------------
@ -212,6 +214,7 @@ protected:
// from within
// SetGUI uses a first parameter that fits into RecurseObject
CGUI *GetGUI() { return m_pGUI; }
const CGUI *GetGUI() const { return m_pGUI; }
void SetGUI(CGUI * const &pGUI) { m_pGUI = pGUI; }
// Set parent
@ -230,6 +233,10 @@ protected:
// class will be only one with permission
// void UpdateObjects();
// Get cached mouse x/y from CGUI
u16 GetMouseX() const; //{ return ((GetGUI())?(GetGUI()->m_MouseX):0); }
u16 GetMouseY() const; //{ return ((GetGUI())?(GetGUI()->m_MouseY):0); }
private:
// Functions used fully private and by friends (mainly the CGUI)

View File

@ -7,4 +7,4 @@ gee@pyro.nu
//#include "stdafx.h"
#include "GUI.h"
using namespace std;
using namespace std;

View File

@ -7,9 +7,6 @@ gee@pyro.nu
Include this file and it will include the whole GUI
Also includes global GUI functions that is used to
make global functions templated
--More info--
http://gee.pyro.nu/wfg/GUI/
@ -19,385 +16,28 @@ gee@pyro.nu
#ifndef GUI_H
#define GUI_H
#ifdef WIN32
# pragma warning(disable:4786)
#endif // WIN32
//--------------------------------------------------------
// Includes / Compiler directives
// Includes
//--------------------------------------------------------
// { temp TODO
/// #include "nemesis.h"
#define DEFINE_ERROR(x, y) PS_RESULT x=y;
#define DECLARE_ERROR(x) extern PS_RESULT x;
// } temp
// Includes used by the whole GUI
#include <map>
#include <string>
#include <stddef.h>
//// janwas: these are very sloppy added, I don't know the etiquette
#include "../ps/Prometheus.h"
#include "types.h"
#include "ogl.h"
//--------------------------------------------------------
// TODO name this section
//--------------------------------------------------------
class CGUIObject;
//--------------------------------------------------------
// Macros
//--------------------------------------------------------
// Temp
///#define CInput nemInput
#define CStr std::string
// Example
// GUI_ADD_OFFSET(CButton, SButtonSettings, m_Settings, "frozen", m_Frozen);
//
#define GUI_ADD_OFFSET(_class, _struct, name, type, str, var) \
m_SettingsInfo[str].m_Offset = offsetof(_class, name) + offsetof(_struct, var); \
m_SettingsInfo[str].m_Type = type;
// Declares the static variable in CGUISettingsObject<>
#define DECLARE_SETTINGS_INFO(_struct) \
map_Settings CGUISettingsObject<_struct>::m_SettingsInfo;
// Setup an object's ConstructObject function
#define GUI_OBJECT(obj) \
public: \
static CGUIObject *ConstructObject() { return new obj(); }
//--------------------------------------------------------
// Types
//--------------------------------------------------------
// Message send to HandleMessage in order
// to give life to Objects manually with
// a derived HandleMessage().
enum EGUIMessage
{
GUIM_PREPROCESS,
GUIM_POSTPROCESS,
GUIM_MOUSE_OVER,
GUIM_MOUSE_ENTER,
GUIM_MOUSE_LEAVE,
GUIM_MOUSE_PRESS_LEFT,
GUIM_MOUSE_PRESS_RIGHT,
GUIM_MOUSE_DOWN_LEFT,
GUIM_MOUSE_DOWN_RIGHT,
GUIM_MOUSE_RELEASE_LEFT,
GUIM_MOUSE_RELEASE_RIGHT,
GUIM_SETTINGS_UPDATED,
GUIM_PRESSED
};
// Recurse restrictions, when we recurse, if an object
// is hidden for instance, you might want it to skip
// the children also
// Notice these are flags! and we don't really need one
// for no restrictions, because then you'll just enter 0
enum
{
GUIRR_HIDDEN=1,
GUIRR_DISABLED=2
};
// Typedefs
typedef std::map<CStr, CGUIObject*> map_pObjects;
//--------------------------------------------------------
// Error declarations
//--------------------------------------------------------
typedef const char * PS_RESULT;
DECLARE_ERROR(PS_FAIL)
DECLARE_ERROR(PS_OK)
DECLARE_ERROR(PS_NAME_TAKEN)
DECLARE_ERROR(PS_OBJECT_FAIL)
DECLARE_ERROR(PS_SETTING_FAIL)
DECLARE_ERROR(PS_VALUE_INVALID)
DECLARE_ERROR(PS_NEEDS_PGUI)
DECLARE_ERROR(PS_NAME_AMBIGUITY)
DECLARE_ERROR(PS_NEEDS_NAME)
DECLARE_ERROR(PS_LEXICAL_FAIL)
DECLARE_ERROR(PS_SYNTACTICAL_FAIL)
//--------------------------------------------------------
// Includes static functions that needs one template
// argument.
//--------------------------------------------------------
// int is only to please functions that doesn't even use
// T
template <typename T=int>
class GUI
{
// Private functions further ahead
friend class CGUI;
friend class CGUIObject;
public:
//--------------------------------------------------------
// Retrieves a setting by name
// Input:
// pObject Object pointer
// Setting Setting by name
// Output:
// Value Stores value here
// note type T!
//--------------------------------------------------------
static PS_RESULT GetSetting(CGUIObject *pObject, const CStr &Setting, T &Value)
{
if (pObject == NULL)
return PS_OBJECT_FAIL;
if (!pObject->SettingExists(Setting))
return PS_SETTING_FAIL;
// Set value
Value = *(T*)((size_t)pObject+pObject->GetSettingsInfo()[Setting].m_Offset);
return PS_OK;
}
//--------------------------------------------------------
// Sets a value by name using a real datatype as input
// Input:
// pObject Object pointer
// Setting Setting by name
// Value Sets value to this
// note type T!
//--------------------------------------------------------
static PS_RESULT SetSetting(CGUIObject *pObject, const CStr &Setting, const T &Value)
{
if (pObject == NULL)
return PS_OBJECT_FAIL;
if (!pObject->SettingExists(Setting))
return PS_SETTING_FAIL;
// Set value
// This better be the correct adress
*(T*)((size_t)pObject+pObject->GetSettingsInfo()[Setting].m_Offset) = Value;
pObject->CheckSettingsValidity();
return PS_OK;
}
//--------------------------------------------------------
// Retrieves a setting and object name
// Input:
// GUI GUI Object const ref
// Object Object name
// Setting Setting by name
// Output:
// Value Stores value here
// note type T!
//--------------------------------------------------------
/* static PS_RESULT GetSetting(
const CGUI &GUIinstance, const CStr &Object,
const CStr &Setting, T &Value)
{
if (GUIinstance.ObjectExists(Object))
return PS_OBJECT_FAIL;
// Retrieve pointer and call sibling function
CGUIObject *pObject = GUIinstance.m_pAllObjects[Object];
return GetSetting(pObject, Setting, Value);
}
//--------------------------------------------------------
// Sets a value by setting and object name using a real
// datatype as input
// Input:
// GUI GUI Object const ref
// Object Object name
// Setting Setting by name
// Value Sets value to this
// note type T!
//--------------------------------------------------------
static PS_RESULT SetSetting(
const CGUI &GUIinstance, const CStr &Object,
const CStr &Setting, const T &Value)
{
if (GUIinstance.ObjectExists(Object))
return PS_OBJECT_FAIL;
// Retrieve pointer and call sibling function
CGUIObject *pObject = GUIinstance.m_pAllObjects[Object];
return SetSetting(pObject, Setting, Value);
}
*/
//--------------------------------------------------------
// This function returns the C++ structure of the
// inputted string. For instance if you input
// "0 0 10 10" and request a CRect, it will give you
// a CRect(0,0,10,10).
// This function is widely used within the GUI.
// Input:
// String The Value in string format
// Return:
// Returns the value in the structure T.
//--------------------------------------------------------
/* static T GetStringValue(const CStr &String)
{
if (typeid(T) == typeid(int))
{
return atoi(String.c_str());
}
if (typeid(T) == typeid(float) ||
typeid(T) == typeid(double))
{
return atof(String.c_str());
}
if (typeid(T) == typeid(CRect))
{
(CRect)return CRect();
}
if (typeid(T) == typeid(CColor))
{
return CColor();
}
switch(typeid(T))
{
case typeid(int):
return atoi(String);
case typeid(float):
case typeid(double):
return atof(String);
case typeid(CRect):
return CRect(0,0,0,0);
case typeid(CColor):
return CColor(0,0,0,0);
default:
// Repport error unrecognized
return T();
}
// If this function is called T is unrecognized
// TODO repport error
return T();
}
*/
//// This is what I need from these includes
/*
static T<int> GetStringValue(const CStr &String)
{
return atoi(String.c_str());
}
*/
// int
/* static int GetStringValue(const CStr &String)
{
// If this function is called T is unrecognized
// TODO repport error
return 10;
}
- OGL
- #define DEFINE_ERROR(x, y) PS_RESULT x=y;
- #define DECLARE_ERROR(x) extern PS_RESULT x;
- PS_RESULT
- u16
*/
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)();
//--------------------------------------------------------
// Recurses an object calling a function on itself
// and all children (and so forth)
// Input:
// RR Recurse Restrictions
// pObject Object to iterate
// pFunc Function to recurse
// Argument Argument of type T
//--------------------------------------------------------
static void RecurseObject(const int &RR, CGUIObject *pObject, void_Object_pFunction_argT pFunc, const T &Argument)
{
if (CheckIfRestricted(RR, pObject))
return;
(pObject->*pFunc)(Argument);
// Iterate children
vector_pObjects::iterator it;
for (it = pObject->ChildrenItBegin(); it != pObject->ChildrenItEnd(); ++it)
{
RecurseObject(RR, *it, pFunc, Argument);
}
}
//--------------------------------------------------------
// Same as above only with reference
//--------------------------------------------------------
static void RecurseObject(const int &RR, CGUIObject *pObject, void_Object_pFunction_argRefT pFunc, T &Argument)
{
if (CheckIfRestricted(RR, pObject))
return;
(pObject->*pFunc)(Argument);
// Iterate children
vector_pObjects::iterator it;
for (it = pObject->ChildrenItBegin(); it != pObject->ChildrenItEnd(); ++it)
{
RecurseObject(RR, *it, pFunc, Argument);
}
}
//--------------------------------------------------------
// Same as above only with no argument
//--------------------------------------------------------
static void RecurseObject(const int &RR, CGUIObject *pObject, void_Object_pFunction pFunc)
{
if (CheckIfRestricted(RR, pObject))
return;
(pObject->*pFunc)();
// Iterate children
vector_pObjects::iterator it;
for (it = pObject->ChildrenItBegin(); it != pObject->ChildrenItEnd(); ++it)
{
RecurseObject(RR, *it, pFunc);
}
}
private:
// Sub functions
static bool CheckIfRestricted(const int &RR, CGUIObject *pObject)
{
if (RR & GUIRR_HIDDEN)
{
if (pObject->GetBaseSettings().m_Hidden)
return true;
}
if (RR & GUIRR_DISABLED)
{
if (pObject->GetBaseSettings().m_Enabled)
return true;
}
// false means not restricted
return false;
}
};
//--------------------------------------------------------
// Post includes
//--------------------------------------------------------
#include "GUIbase.h"
#include "GUIutil.h"
#include "CGUIObject.h"
#include "CGUISettingsObject.h"
#include "CGUIButtonBehavior.h"
@ -405,9 +45,5 @@ private:
#include "CGUISprite.h"
#include "CGUI.h"
//--------------------------------------------------------
// Prototypes
//--------------------------------------------------------
#endif

View File

@ -4,8 +4,6 @@ by Gustav Larsson
gee@pyro.nu
*/
///#include "nemesis.h"
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
@ -15,6 +13,9 @@ gee@pyro.nu
#include <stdlib.h>
#include <string.h>
// Use namespace
XERCES_CPP_NAMESPACE_USE
void XercesErrorHandler::warning(const SAXParseException&)
{
@ -25,7 +26,10 @@ void XercesErrorHandler::warning(const SAXParseException&)
void XercesErrorHandler::error(const SAXParseException& toCatch)
{
char * buf = XMLString::transcode(toCatch.getMessage());
fSawErrors = true;
XMLString::release(&buf);
/* cerr << "Error at file \"" << StrX(toCatch.getSystemId())
<< "\", line " << toCatch.getLineNumber()
<< ", column " << toCatch.getColumnNumber()
@ -37,7 +41,12 @@ void XercesErrorHandler::error(const SAXParseException& toCatch)
void XercesErrorHandler::fatalError(const SAXParseException& toCatch)
{
char * buf = XMLString::transcode(toCatch.getMessage());
fSawErrors = true;
XMLString::release(&buf);
/* cerr << "Fatal Error at file \"" << StrX(toCatch.getSystemId())
<< "\", line " << toCatch.getLineNumber()
<< ", column " << toCatch.getColumnNumber()

View File

@ -25,10 +25,7 @@ gee@pyro.nu
#include <iostream>
XERCES_CPP_NAMESPACE_USE
class XercesErrorHandler : public ErrorHandler
class XercesErrorHandler : public XERCES_CPP_NAMESPACE::ErrorHandler
{
public:
// -----------------------------------------------------------------------
@ -47,9 +44,9 @@ public:
// -----------------------------------------------------------------------
// Implementation of the error handler interface
// -----------------------------------------------------------------------
void warning(const SAXParseException& toCatch);
void error(const SAXParseException& toCatch);
void fatalError(const SAXParseException& toCatch);
void warning(const XERCES_CPP_NAMESPACE::SAXParseException& toCatch);
void error(const XERCES_CPP_NAMESPACE::SAXParseException& toCatch);
void fatalError(const XERCES_CPP_NAMESPACE::SAXParseException& toCatch);
void resetErrors();
// -----------------------------------------------------------------------