Show object.h syntax highlighted
/***************************************************************************
object.h - Base object class for windowing toolkit
-------------------
begin : Sun Nov 17 2002
copyright : (C) 2002 by Mattias Jansson
email : mattias@realityrift.com
***************************************************************************
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is the NeoEngine, NeoWTK, object.h
The Initial Developer of the Original Code is Mattias Jansson.
Portions created by Mattias Jansson are Copyright (C) 2002
Reality Rift Studios. All Rights Reserved.
***************************************************************************/
#ifndef __NEOWTKOBJECT_H
#define __NEOWTKOBJECT_H
#include "base.h"
#include "coord.h"
#include <neoengine/hashstring.h>
#include <neoengine/updateentity.h>
#include <neoengine/renderentity.h>
#include <neoengine/inputentity.h>
#include <neoengine/input.h>
#ifdef HAVE_NEOCHUNKIO
# include <neochunkio/complex.h>
# include "chunktype.h"
#endif
#include <vector>
/**
* \file object.h
* Base object class for windowing toolkit
*/
namespace NeoWTK
{
// External classes
class Msg;
class MsgHook;
class AttributeBase;
#ifdef HAVE_NEOCHUNKIO
// Forward declarations
class ObjectChunk;
#endif
/**
* \brief Base class all window toolkit object are derived from
* \author Mattias Jansson (mattias@realityrift.com)
*/
class Object : public virtual NeoEngine::UpdateEntity, public virtual NeoEngine::RenderEntity, public NeoEngine::InputEntity, public NeoEngine::InputGroup
{
#ifdef HAVE_NEOCHUNKIO
friend class ObjectChunk;
#endif
public:
/**
* \enum HITTESTRESULT
* \brief Identifiers for hit test result
*/
enum HITTESTRESULT
{
/*! Coordinate was outside area */
OUTSIDE,
/*! Coordinate was inside area */
INSIDE,
/*! Coordinate was on edge of area */
EDGE
};
protected:
/*! Unique ID */
unsigned int m_uiID;
/*! Parent object */
Object *m_pkParent;
/*! Children */
std::vector< Object* > m_vpkChildren;
/*! Position relative parent */
Coord m_kPos;
/*! World position */
Coord m_kWorldPos;
/*! Size */
Coord m_kSize;
/*! Name */
NeoEngine::HashString m_strName;
/*! Hooked message actions */
std::vector< MsgHook* > m_vpkMsgHook;
/*! Result of last mouse hit test */
HITTESTRESULT m_eLastMouse;
/**
* Update world cache position and recurse on children if flag set
* \param bRecurse Recursion flag
*/
void UpdateWorldCache( bool bRecurse = true );
public:
/**
* \param pkParent Parent object
* \param pkObject Reference object to copy values from
* \param bDuplicateChildren If reference object given and this flag true, duplicate child objects
*/
Object( Object *pkParent, Object *pkObject = 0, bool bDuplicateChildren = true );
/**
* Deletes all child objects
*/
virtual ~Object();
/**
* Set position relative parent
* \param rkPos Position
* \return New relative position
*/
virtual const Coord &SetPosition( const Coord &rkPos );
/**
* Set size
* \param rkSize Size
* \return New size
*/
virtual const Coord &SetSize( const Coord &rkSize );
/**
* \return Position relative parent
*/
const Coord &GetPosition() const;
/**
* \return World position
*/
const Coord &GetWorldPosition();
/**
* \return Size
*/
const Coord &GetSize() const;
/**
* \param rstrName New name
*/
virtual void SetName( const NeoEngine::HashString &rstrName );
/**
* \return Name
*/
virtual const NeoEngine::HashString &GetName() const;
/**
* Set an attribute
* \param rkAttribute Attribute
*/
virtual void SetAttribute( const AttributeBase &rkAttribute );
/**
* \return Object ID
*/
inline unsigned int GetID() const { return m_uiID; }
/**
* \return Parent object
*/
virtual Object *GetParent();
/**
* \return Root object
*/
virtual Object *GetRoot();
/**
* Search for a child object by name ("parent" for parent object, "root" for root object)
* \param rstrName Name of object
* \return Matching child object, null if not found
*/
virtual Object *GetObject( const std::string &rstrName );
/**
* Get all child objects (no recursion)
* \return Vector with child objects
*/
virtual const std::vector< Object* > &GetChildObjects() const;
/**
* Attach window object
* \param pkObject Object
*/
virtual void AttachObject( Object *pkObject );
/**
* Detach window object
* \param pkObject Object
*/
virtual void DetachObject( Object *pkObject );
/**
* Attach this object to new parent
* \param pkParent Parent object
*/
virtual void AttachToObject( Object *pkParent );
/**
* Process message
* \param pkMsg Message object
* \return Message specific return code, 0 indicates message was unprocessed
*/
virtual unsigned int ProcessMsg( Msg *pkMsg );
/**
* Render object, recurses on children
* \param pkFrustum Currently ignored
* \param bForce Force rendering
* \return true if rendered, false if not
*/
virtual bool Render( NeoEngine::Frustum *pkFrustum = 0, bool bForce = false );
/**
* Add a message hook object (hook object will be freed in dtor)
* \param pkMsgHook Message hook object
*/
virtual void AddHook( MsgHook *pkMsgHook );
/**
* Remove a message hook object (you must now free the hook object yourself)
* \param pkMsgHook Message hook object
*/
virtual void RemoveHook( MsgHook *pkMsgHook );
/**
* Process input
* \param pkEvent Event
*/
virtual void Input( const NeoEngine::InputEvent *pkEvent );
/**
* Test if coordinate is inside, on edge or outside object area
* \param rkCoord Coordinate to test
* \return Hit test identifier
*/
HITTESTRESULT HitTest( const Coord &rkCoord );
/**
* Update object
* \param fDeltaTime Deltatime passed since last update
*/
virtual void Update( float fDeltaTime );
/**
* Duplicate and/or copy this object
* \param pkParent Parent object to attach to
* \param pkObject Object to copy data into, if null will allocate new object. Will only duplicate children if this object is null or has no children
* \return New object that is duplicate of this object
*/
virtual Object *Duplicate( Object *pkParent = 0, Object *pkObject = 0 );
};
#ifdef HAVE_NEOCHUNKIO
/**
* \brief Base chunk for wtk objects
* \author Mattias Jansson (mattias@realityrift.com)
*/
class ObjectChunk : public NeoChunkIO::ComplexChunk
{
public:
/**
* \enum PARSEFLAG
* \brief Parse flags for WTK object chunks
*/
enum PARSEFLAG
{
/*! Do not search and attach children */
NOCHILDREN = 0x00100000,
/*! Do not search and parse attributes */
NOATTRIBUTES = 0x00200000
};
/*! Object */
Object *m_pkObject;
/**
* Initialize chunk
* \param usType Chunk type
* \param rstrType Chunk type as string
* \param rstrID Chunk ID string
*/
ObjectChunk( unsigned short usType, const NeoEngine::HashString &rstrType, const NeoEngine::HashString &rstrID = "" ) : NeoChunkIO::ComplexChunk( usType, rstrType, rstrID ), m_pkObject( 0 ) { m_usFindType = NeoWTK::ChunkType::OBJECT; }
/**
* Deallocate data and subchunks
*/
virtual ~ObjectChunk() { delete m_pkObject; }
/**
* Parse chunk data
* \param uiFlags Parse flags
* \param pkFileManager File manager
* \return <0 if error, >0 if successful (0 reserved)
*/
virtual int ParseData( unsigned int uiFlags, NeoEngine::FileManager *pkFileManager );
/**
* Find and attach child objects
*/
virtual void AttachChildren();
/**
* Find and set attributes
*/
virtual void SetAttributes();
/**
* Allocate new chunk
* \param usType Type identifier
* \param rstrType Type identifier as string
* \param rstrID ID string
* \return New chunk
*/
static NeoChunkIO::Chunk *Allocator( unsigned short usType, const NeoEngine::HashString &rstrType, const NeoEngine::HashString &rstrID ) { return new ObjectChunk( usType, rstrType, rstrID ); }
};
#endif
};
#endif
See more files for this project here