Cafu Engine
cf::GuiSys::WindowT Class Reference

This class represents a window of the GuiSys. More...

#include "Window.hpp"

Inheritance diagram for cf::GuiSys::WindowT:

Public Member Functions

 WindowT (const WindowCreateParamsT &Params)
 The normal constructor. More...
 
 WindowT (const WindowT &Window, bool Recursive=false)
 The copy constructor. More...
 
virtual WindowTClone (bool Recursive=false) const
 The virtual copy constructor. More...
 
virtual ~WindowT ()
 The virtual destructor. Deletes this window and all its children. More...
 
GuiImplTGetGui () const
 
IntrusivePtrT< WindowTGetParent () const
 Returns the parent window of this window. More...
 
const ArrayT< IntrusivePtrT
< WindowT > > & 
GetChildren () const
 Returns the immediate children of this window. More...
 
void GetChildren (ArrayT< IntrusivePtrT< WindowT > > &Chld, bool Recurse=false) const
 Returns the children of this window. More...
 
bool AddChild (IntrusivePtrT< WindowT > Child, unsigned long Pos=0xFFFFFFFF)
 Adds the given window to the children of this window, and sets this window as the parent of the child. More...
 
bool RemoveChild (IntrusivePtrT< WindowT > Child)
 Removes the given window from the children of this window. More...
 
IntrusivePtrT< WindowTGetRoot ()
 Returns the top-most parent of this window, that is, the root of the hierarchy this window is in. More...
 
IntrusivePtrT< ComponentBaseTGetApp ()
 Returns the application component of this window. More...
 
IntrusivePtrT< const
ComponentBaseT
GetApp () const
 The const variant of the GetApp() method above. See GetApp() for details. More...
 
void SetApp (IntrusivePtrT< ComponentBaseT > App)
 Sets the application component for this window. See GetApp() for details. More...
 
IntrusivePtrT< ComponentBasicsTGetBasics () const
 Returns the "Basics" component of this window. More...
 
IntrusivePtrT
< ComponentTransformT
GetTransform () const
 Returns the "Transform" component of this window. More...
 
const ArrayT< IntrusivePtrT
< ComponentBaseT > > & 
GetComponents () const
 Returns the components that this window is composed of. More...
 
IntrusivePtrT< ComponentBaseTGetComponent (const std::string &TypeName, unsigned int n=0) const
 Returns the (n-th) component of the given (type) name. More...
 
bool AddComponent (IntrusivePtrT< ComponentBaseT > Comp, unsigned long Index=ULONG_MAX)
 Adds the given component to this window. More...
 
void DeleteComponent (unsigned long CompNr)
 Deletes the component at the given index from this window. More...
 
Vector2fT GetAbsolutePos () const
 Returns the position of the upper left corner of this window in absolute (vs. relative to the parent) coordinates. More...
 
IntrusivePtrT< WindowTFind (const std::string &WantedName)
 Finds the window with the name WantedName in the hierachy tree of this window. More...
 
IntrusivePtrT< WindowTFind (const Vector2fT &Pos, bool OnlyVisible=true)
 Finds the topmost window that contains the point Pos in the hierachy tree of this window (with Pos being in (absolute) screen coordinates, not relative to this window). More...
 
virtual void Render () const
 Renders this window. More...
 
virtual bool OnInputEvent (const CaKeyboardEventT &KE)
 Keyboard input event handler. More...
 
virtual bool OnInputEvent (const CaMouseEventT &ME, float PosX, float PosY)
 Mouse input event handler. More...
 
virtual bool OnClockTickEvent (float t)
 The clock-tick event handler. More...
 
bool CallLuaMethod (const char *MethodName, const char *Signature="",...)
 Calls the Lua method with name MethodName of this window. More...
 
virtual const
cf::TypeSys::TypeInfoT
GetType () const
 
- Public Member Functions inherited from RefCountedT
unsigned int GetRefCount () const
 

Static Public Member Functions

static void * CreateInstance (const cf::TypeSys::CreateParamsT &Params)
 

Static Public Attributes

static const cf::TypeSys::TypeInfoT TypeInfo
 

Static Protected Member Functions

static int AddChild (lua_State *LuaState)
 
static int RemoveChild (lua_State *LuaState)
 
static int GetParent (lua_State *LuaState)
 
static int GetChildren (lua_State *LuaState)
 
static int GetTime (lua_State *LuaState)
 
static int GetBasics (lua_State *LuaState)
 
static int GetTransform (lua_State *LuaState)
 
static int AddComponent (lua_State *LuaState)
 
static int RmvComponent (lua_State *LuaState)
 
static int GetComponents (lua_State *LuaState)
 
static int GetComponent (lua_State *LuaState)
 
static int toString (lua_State *LuaState)
 

Static Protected Attributes

static const luaL_Reg MethodsList []
 List of methods registered with Lua. More...
 
static const char * DocClass
 
static const cf::TypeSys::MethsDocT DocMethods []
 
static const cf::TypeSys::MethsDocT DocCallbacks []
 

Additional Inherited Members

- Protected Member Functions inherited from RefCountedT
 RefCountedT (const RefCountedT &)
 
RefCountedToperator= (const RefCountedT &)
 

Detailed Description

This class represents a window of the GuiSys.

A WindowT is the most basic element of a GUI, and all other windows are derived and/or combined from this.

WindowT instances can be created in C++ code or in Lua scripts, using the gui:new() function. They can be passed from C++ code to Lua and from Lua to C++ code at will. In C++ code, all WindowT instances are kept in IntrusivePtrT's. Their lifetime is properly managed: A window is deleted automatically when it is no longer used in Lua and in C++. That is, code like Example 1: w=gui:new("WindowT"); gui:SetRootWindow(w); w=nil; Example 2: w=gui:new("WindowT"); w:AddChild(gui:new("WindowT")); works as expected. See the cf::ScriptBinderT class for technical and implementation details.

Constructor & Destructor Documentation

WindowT::WindowT ( const WindowCreateParamsT Params)

The normal constructor.

Parameters
ParamsThe creation parameters for the window.
WindowT::WindowT ( const WindowT Window,
bool  Recursive = false 
)

The copy constructor.

Copies a window (optionally with all of its children recursively). The parent of the copy is always NULL and it is up to the caller to put the copy into a window hierarchy.

Parameters
WindowThe window to construct this window from.
RecursiveWhether to recursively copy all children.
WindowT::~WindowT ( )
virtual

The virtual destructor. Deletes this window and all its children.

Member Function Documentation

bool WindowT::AddChild ( IntrusivePtrT< WindowT Child,
unsigned long  Pos = 0xFFFFFFFF 
)

Adds the given window to the children of this window, and sets this window as the parent of the child.

This method also makes sure that the name of the Child is unique among its siblings, modifying it as necessary. See SetName() for more details.

Parameters
ChildThe window to add to the children of this window.
PosThe position among the children to insert the child window at.
Returns
true on success, false on failure (Child has a parent already, or is the root of this window).
bool WindowT::AddComponent ( IntrusivePtrT< ComponentBaseT Comp,
unsigned long  Index = ULONG_MAX 
)

Adds the given component to this window.

Parameters
CompThe component to add to this window.
IndexThe position among the other components to insert Comp at.
Returns
true on success, false on failure (if Comp is part of a window already).
bool WindowT::CallLuaMethod ( const char *  MethodName,
const char *  Signature = "",
  ... 
)

Calls the Lua method with name MethodName of this window.

This method is analogous to GuiI::CallLuaFunc(), see there for more details.

Parameters
MethodNameThe name of the lua method to call.
SignatureDOCTODO
WindowT * WindowT::Clone ( bool  Recursive = false) const
virtual

The virtual copy constructor.

Callers can use this method to create a copy of this window without knowing its concrete type. Overrides in derived classes use a covariant return type to facilitate use when the concrete type is known.

Parameters
RecursiveWhether to recursively clone all children of this window.
void WindowT::DeleteComponent ( unsigned long  CompNr)

Deletes the component at the given index from this window.

IntrusivePtrT< WindowT > WindowT::Find ( const std::string &  WantedName)

Finds the window with the name WantedName in the hierachy tree of this window.

Use GetRoot()->Find("xy") in order to search the entire GUI for the window with name "xy".

Parameters
WantedNameThe name of the window that is to be found.
Returns
The pointer to the desired window, or NULL if no window with this name exists.
IntrusivePtrT< WindowT > WindowT::Find ( const Vector2fT Pos,
bool  OnlyVisible = true 
)

Finds the topmost window that contains the point Pos in the hierachy tree of this window (with Pos being in (absolute) screen coordinates, not relative to this window).

Use GetRoot()->Find(Pos) in order to search the entire GUI for the window containing the point Pos.

Parameters
PosThe coordinate of the point to test.
OnlyVisibleIf true, only visible windows are reported. If false, all windows are searched.
Returns
The pointer to the desired window, or NULL if there is no window that contains Pos.
Vector2fT WindowT::GetAbsolutePos ( ) const

Returns the position of the upper left corner of this window in absolute (vs. relative to the parent) coordinates.

IntrusivePtrT<ComponentBaseT> cf::GuiSys::WindowT::GetApp ( )
inline

Returns the application component of this window.

This component is much like the "Basics" and "Transform" components, but it can be set by the application (see SetApp()), and is intended for the sole use by the application, e.g. for implementing a "selection gizmo" in the GUI Editor.

IntrusivePtrT<const ComponentBaseT> cf::GuiSys::WindowT::GetApp ( ) const
inline

The const variant of the GetApp() method above. See GetApp() for details.

IntrusivePtrT<ComponentBasicsT> cf::GuiSys::WindowT::GetBasics ( ) const
inline

Returns the "Basics" component of this window.

The "Basics" component defines the name and the "show" flag of the window.

const ArrayT< IntrusivePtrT<WindowT> >& cf::GuiSys::WindowT::GetChildren ( ) const
inline

Returns the immediate children of this window.

This is analogous to calling GetChildren(Chld, false) with an initially empty Chld array.

void WindowT::GetChildren ( ArrayT< IntrusivePtrT< WindowT > > &  Chld,
bool  Recurse = false 
) const

Returns the children of this window.

Parameters
ChldThe array to which the children of this window are appended. Note that Chld gets not initially cleared by this function!
RecurseDetermines if also the grand-children, grand-grand-children etc. are returned.
IntrusivePtrT< ComponentBaseT > WindowT::GetComponent ( const std::string &  TypeName,
unsigned int  n = 0 
) const

Returns the (n-th) component of the given (type) name.

Covers the "custom" components as well as the application components, "Basics" and "Transform". That is, GetComponent("Basics") == GetBasics() and GetComponent("Transform") == GetTransform().

const ArrayT< IntrusivePtrT<ComponentBaseT> >& cf::GuiSys::WindowT::GetComponents ( ) const
inline

Returns the components that this window is composed of.

Only the "custom" components are returned, does not include the application component, "Basics" or "Transform".

IntrusivePtrT<WindowT> cf::GuiSys::WindowT::GetParent ( ) const
inline

Returns the parent window of this window.

IntrusivePtrT< WindowT > WindowT::GetRoot ( )

Returns the top-most parent of this window, that is, the root of the hierarchy this window is in.

IntrusivePtrT<ComponentTransformT> cf::GuiSys::WindowT::GetTransform ( ) const
inline

Returns the "Transform" component of this window.

The "Transform" component defines the position, size and orientation of the window.

bool WindowT::OnClockTickEvent ( float  t)
virtual

The clock-tick event handler.

Parameters
tThe time in seconds since the last clock-tick.
bool WindowT::OnInputEvent ( const CaKeyboardEventT KE)
virtual

Keyboard input event handler.

Parameters
KEKeyboard event.
bool WindowT::OnInputEvent ( const CaMouseEventT ME,
float  PosX,
float  PosY 
)
virtual

Mouse input event handler.

Parameters
MEMouse event.
PosXMouse position x.
PosYMouse position y.
bool WindowT::RemoveChild ( IntrusivePtrT< WindowT Child)

Removes the given window from the children of this window.

Parameters
ChildThe window to remove from the children of this window.
Returns
true on success, false on failure (Child is not a child of this window).
void WindowT::Render ( ) const
virtual

Renders this window.

Note that this method does not setup any of the MatSys's model, view or projection matrices: it's up to the caller to do that!

void WindowT::SetApp ( IntrusivePtrT< ComponentBaseT App)

Sets the application component for this window. See GetApp() for details.

Member Data Documentation

const char * WindowT::DocClass
staticprotected
Initial value:
=
"A window is the basic element of a graphical user interface.\n"
"\n"
"Windows are hierarchically arranged in parent/child relationships to form complex user interfaces.\n"
"\n"
"Each window essentially represents a rectangular shape, but only has very little features of its own.\n"
"Instead, a window contains a set of components, each of which implements a specific feature for the window."
const cf::TypeSys::MethsDocT WindowT::DocMethods
staticprotected
Initial value:
=
{
META_AddChild,
META_RemoveChild,
META_GetParent,
META_GetChildren,
META_GetTime,
META_GetBasics,
META_GetTransform,
META_AddComponent,
META_RemoveComponent,
META_GetComponents,
META_GetComponent,
META_toString,
{ NULL, NULL, NULL, NULL }
}
const luaL_Reg WindowT::MethodsList
staticprotected
Initial value:
=
{
{ "AddChild", AddChild },
{ "RemoveChild", RemoveChild },
{ "GetParent", GetParent },
{ "GetChildren", GetChildren },
{ "GetTime", GetTime },
{ "GetBasics", GetBasics },
{ "GetTransform", GetTransform },
{ "AddComponent", AddComponent },
{ "RemoveComponent", RmvComponent },
{ "GetComponents", GetComponents },
{ "GetComponent", GetComponent },
{ "__tostring", toString },
{ NULL, NULL }
}

List of methods registered with Lua.


The documentation for this class was generated from the following files: