libRocket
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Member Functions | Protected Member Functions | Friends | List of all members
Rocket::Core::Context Class Reference

#include <Context.h>

Inheritance diagram for Rocket::Core::Context:
Rocket::Core::ScriptInterface Rocket::Core::ReferenceCountable

Public Member Functions

 Context (const String &name)
 
virtual ~Context ()
 Destroys a context. More...
 
const String & GetName () const
 
void SetDimensions (const Vector2i &dimensions)
 
const Vector2i & GetDimensions () const
 
bool Update ()
 Updates all elements in the context's documents. More...
 
bool Render ()
 Renders all visible elements in the context's documents. More...
 
ElementDocument * CreateDocument (const String &tag="body")
 
ElementDocument * LoadDocument (const String &document_path)
 
ElementDocument * LoadDocument (Stream *document_stream)
 
ElementDocument * LoadDocumentFromMemory (const String &string)
 
void UnloadDocument (ElementDocument *document)
 
void UnloadAllDocuments ()
 Unloads all loaded documents. More...
 
void AddMouseCursor (ElementDocument *cursor_document)
 
ElementDocument * LoadMouseCursor (const String &cursor_document_path)
 
void UnloadMouseCursor (const String &cursor_name)
 
void UnloadAllMouseCursors ()
 Unloads all currently loaded cursors. More...
 
bool SetMouseCursor (const String &cursor_name)
 
void ShowMouseCursor (bool show)
 
ElementDocument * GetDocument (const String &id)
 
ElementDocument * GetDocument (int index)
 
int GetNumDocuments () const
 
Element * GetHoverElement ()
 
Element * GetFocusElement ()
 
Element * GetRootElement ()
 
void PullDocumentToFront (ElementDocument *document)
 
void PushDocumentToBack (ElementDocument *document)
 
void AddEventListener (const String &event, EventListener *listener, bool in_capture_phase=false)
 
void RemoveEventListener (const String &event, EventListener *listener, bool in_capture_phase=false)
 
bool ProcessKeyDown (Input::KeyIdentifier key_identifier, int key_modifier_state)
 
bool ProcessKeyUp (Input::KeyIdentifier key_identifier, int key_modifier_state)
 
bool ProcessTextInput (word character)
 
bool ProcessTextInput (const String &string)
 
void ProcessMouseMove (int x, int y, int key_modifier_state)
 
void ProcessMouseButtonDown (int button_index, int key_modifier_state)
 
void ProcessMouseButtonUp (int button_index, int key_modifier_state)
 
bool ProcessMouseWheel (int wheel_delta, int key_modifier_state)
 
RenderInterface * GetRenderInterface () const
 
bool GetActiveClipRegion (Vector2i &origin, Vector2i &dimensions) const
 
void SetActiveClipRegion (const Vector2i &origin, const Vector2i &dimensions)
 
void SetInstancer (ContextInstancer *instancer)
 
- Public Member Functions inherited from Rocket::Core::ScriptInterface
virtual ~ScriptInterface ()
 
virtual ScriptObject GetScriptObject () const
 
- Public Member Functions inherited from Rocket::Core::ReferenceCountable
 ReferenceCountable (int initial_count=1)
 
virtual ~ReferenceCountable ()
 Destructor. The reference count must be 0 when this is invoked. More...
 
virtual int GetReferenceCount ()
 Returns the number of references outstanding against this object. More...
 
virtual void AddReference ()
 Increases the reference count. If this pushes the count above 0, OnReferenceActivate() will be called. More...
 
virtual void RemoveReference ()
 Decreases the reference count. If this pushes the count to 0, OnReferenceDeactivate() will be called. More...
 
ReferenceCountable & operator= (const ReferenceCountable &copy)
 Catches incorrect copy attempts. More...
 

Protected Member Functions

virtual void OnReferenceDeactivate ()
 A hook method called when the reference count drops to 0. More...
 
- Protected Member Functions inherited from Rocket::Core::ReferenceCountable
virtual void OnReferenceActivate ()
 A hook method called when the reference count climbs from 0. More...
 

Friends

class Element
 
ROCKETCORE_API Context * CreateContext (const String &, const Vector2i &, RenderInterface *)
 

Additional Inherited Members

- Static Public Member Functions inherited from Rocket::Core::ReferenceCountable
static void DumpLeakReport ()
 If any reference countable objects are still allocated, this function will write a leak report to the log. More...
 

Detailed Description

A context for storing, rendering and processing RML documents. Multiple contexts can exist simultaneously.

Author
Peter Curry

Constructor & Destructor Documentation

Rocket::Core::Context::Context ( const String &  name)

Constructs a new, uninitialised context. This should not be called directly, use Core::CreateContext() instead.

Parameters
[in]nameThe name of the context.
virtual Rocket::Core::Context::~Context ( )
virtual

Destroys a context.

Member Function Documentation

void Rocket::Core::Context::AddEventListener ( const String &  event,
EventListener *  listener,
bool  in_capture_phase = false 
)

Adds an event listener to the context's root element.

Parameters
[in]eventThe name of the event to attach to.
[in]listenerListener object to be attached.
[in]in_capture_phaseTrue if the listener is to be attached to the capture phase, false for the bubble phase.
void Rocket::Core::Context::AddMouseCursor ( ElementDocument *  cursor_document)

Adds a previously-loaded cursor document as a mouse cursor within this context. This allows you to share cursors between contexts.

Parameters
[in]cursor_documentThe document to add as a cursor into this context.
ElementDocument* Rocket::Core::Context::CreateDocument ( const String &  tag = "body")

Creates a new, empty document and places it into this context.

Parameters
[in]tagThe document type to create.
Returns
The new document, or NULL if no document could be created. The document is returned with a reference owned by the caller.
bool Rocket::Core::Context::GetActiveClipRegion ( Vector2i &  origin,
Vector2i &  dimensions 
) const

Gets the current clipping region for the render traversal

Parameters
[out]originThe clipping origin
[out]dimensionsThe clipping dimensions
const Vector2i& Rocket::Core::Context::GetDimensions ( ) const

Returns the dimensions of the context.

Returns
The current dimensions of the context.
ElementDocument* Rocket::Core::Context::GetDocument ( const String &  id)

Returns the first document in the context with the given id.

Parameters
[in]idThe id of the desired document.
Returns
The document (if it was found), or NULL if no document exists with the ID. The document is returned with a borrowed reference.
ElementDocument* Rocket::Core::Context::GetDocument ( int  index)

Returns a document in the context by index.

Parameters
[in]indexThe index of the desired document.
Returns
The document (if one exists with this index), or NULL if the index was invalid. The document is returned with a borrowed reference.
Element* Rocket::Core::Context::GetFocusElement ( )

Returns the focus element.

Returns
The element with input focus. The element is returned with a borrowed reference.
Element* Rocket::Core::Context::GetHoverElement ( )

Returns the hover element.

Returns
The element the mouse cursor is hovering over. The element is returned with a borrowed reference.
const String& Rocket::Core::Context::GetName ( ) const

Returns the name of the context.

Returns
The context's name.
int Rocket::Core::Context::GetNumDocuments ( ) const

Returns the number of documents in the context.

Returns
The number of documents in the context.
RenderInterface* Rocket::Core::Context::GetRenderInterface ( ) const

Gets the context's render interface.

Returns
The render interface the context renders through.
Element* Rocket::Core::Context::GetRootElement ( )

Returns the root element that holds all the documents

Returns
The root element. The element is returned with a borrowed reference.
ElementDocument* Rocket::Core::Context::LoadDocument ( const String &  document_path)

Load a document into the context.

Parameters
[in]document_pathThe path to the document to load.
Returns
The loaded document, or NULL if no document was loaded. The document is returned with a reference owned by the caller.
ElementDocument* Rocket::Core::Context::LoadDocument ( Stream *  document_stream)

Load a document into the context.

Parameters
[in]document_streamThe opened stream, ready to read.
Returns
The loaded document, or NULL if no document was loaded. The document is returned with a reference owned by the caller.
ElementDocument* Rocket::Core::Context::LoadDocumentFromMemory ( const String &  string)

Load a document into the context.

Parameters
[in]stringThe string containing the document RML.
Returns
The loaded document, or NULL if no document was loaded. The document is returned with a reference owned by the caller.
ElementDocument* Rocket::Core::Context::LoadMouseCursor ( const String &  cursor_document_path)

Loads a document as a mouse cursor within this context.

Parameters
[in]cursor_document_pathThe path to the document to load as a cursor.
Returns
The loaded cursor document, or NULL if no document was loaded. The document is returned with a reference owned by the caller.
virtual void Rocket::Core::Context::OnReferenceDeactivate ( )
protectedvirtual

A hook method called when the reference count drops to 0.

Reimplemented from Rocket::Core::ReferenceCountable.

bool Rocket::Core::Context::ProcessKeyDown ( Input::KeyIdentifier  key_identifier,
int  key_modifier_state 
)

Sends a key down event into this context.

Parameters
[in]key_identifierThe key pressed.
[in]key_modifier_stateThe state of key modifiers (shift, control, caps-lock, etc) keys; this should be generated by ORing together members of the Input::KeyModifier enumeration.
Returns
True if the event was not consumed (ie, was prevented from propagating by an element), false if it was.
bool Rocket::Core::Context::ProcessKeyUp ( Input::KeyIdentifier  key_identifier,
int  key_modifier_state 
)

Sends a key up event into this context.

Parameters
[in]key_identifierThe key released.
[in]key_modifier_stateThe state of key modifiers (shift, control, caps-lock, etc) keys; this should be generated by ORing together members of the Input::KeyModifier enumeration.
Returns
True if the event was not consumed (ie, was prevented from propagating by an element), false if it was.
void Rocket::Core::Context::ProcessMouseButtonDown ( int  button_index,
int  key_modifier_state 
)

Sends a mouse-button down event into this context.

Parameters
[in]button_indexThe index of the button that was pressed; 0 for the left button, 1 for right, and any others from 2 onwards.
[in]key_modifier_stateThe state of key modifiers (shift, control, caps-lock, etc) keys; this should be generated by ORing together members of the Input::KeyModifier enumeration.
void Rocket::Core::Context::ProcessMouseButtonUp ( int  button_index,
int  key_modifier_state 
)

Sends a mouse-button up event into this context.

Parameters
[in]button_indexThe index of the button that was release; 0 for the left button, 1 for right, and any others from 2 onwards.
[in]key_modifier_stateThe state of key modifiers (shift, control, caps-lock, etc) keys; this should be generated by ORing together members of the Input::KeyModifier enumeration.
void Rocket::Core::Context::ProcessMouseMove ( int  x,
int  y,
int  key_modifier_state 
)

Sends a mouse movement event into this context.

Parameters
[in]xThe x-coordinate of the mouse cursor, in window-coordinates (ie, 0 should be the left of the client area).
[in]yThe y-coordinate of the mouse cursor, in window-coordinates (ie, 0 should be the top of the client area).
[in]key_modifier_stateThe state of key modifiers (shift, control, caps-lock, etc) keys; this should be generated by ORing together members of the Input::KeyModifier enumeration.
bool Rocket::Core::Context::ProcessMouseWheel ( int  wheel_delta,
int  key_modifier_state 
)

Sends a mouse-wheel movement event into this context.

Parameters
[in]wheel_deltaThe mouse-wheel movement this frame. Rocket treats a negative delta as up movement (away from the user), positive as down.
[in]key_modifier_stateThe state of key modifiers (shift, control, caps-lock, etc) keys; this should be generated by ORing together members of the Input::KeyModifier enumeration.
Returns
True if the event was not consumed (ie, was prevented from propagating by an element), false if it was.
bool Rocket::Core::Context::ProcessTextInput ( word  character)

Sends a single character of text as text input into this context.

Parameters
[in]characterThe UCS-2 character to send into this context.
Returns
True if the event was not consumed (ie, was prevented from propagating by an element), false if it was.
bool Rocket::Core::Context::ProcessTextInput ( const String &  string)

Sends a string of text as text input into this context.

Parameters
[in]stringThe UCS-2 string to send into this context.
Returns
True if the event was not consumed (ie, was prevented from propagating by an element), false if it was.
void Rocket::Core::Context::PullDocumentToFront ( ElementDocument *  document)

Brings the document to the front of the document stack.

Parameters
[in]documentThe document to pull to the front of the stack.
void Rocket::Core::Context::PushDocumentToBack ( ElementDocument *  document)

Sends the document to the back of the document stack.

Parameters
[in]documentThe document to push to the bottom of the stack.
void Rocket::Core::Context::RemoveEventListener ( const String &  event,
EventListener *  listener,
bool  in_capture_phase = false 
)

Removes an event listener from the context's root element.

Parameters
[in]eventThe name of the event to detach from.
[in]listenerListener object to be detached.
[in]in_capture_phaseTrue to detach from the capture phase, false from the bubble phase.
bool Rocket::Core::Context::Render ( )

Renders all visible elements in the context's documents.

void Rocket::Core::Context::SetActiveClipRegion ( const Vector2i &  origin,
const Vector2i &  dimensions 
)

Sets the current clipping region for the render traversal

Parameters
[out]originThe clipping origin
[out]dimensionsThe clipping dimensions
void Rocket::Core::Context::SetDimensions ( const Vector2i &  dimensions)

Changes the dimensions of the context.

Parameters
[in]dimensionsThe new dimensions of the context.
void Rocket::Core::Context::SetInstancer ( ContextInstancer *  instancer)

Sets the instancer to use for releasing this object.

Parameters
[in]instancerThe context's instancer.
bool Rocket::Core::Context::SetMouseCursor ( const String &  cursor_name)

Sets a cursor as the active cursor.

Parameters
[in]cursor_nameThe name of the cursor to activate.
Returns
True if a cursor exists with the given name, false if not.
void Rocket::Core::Context::ShowMouseCursor ( bool  show)

Shows or hides the cursor.

Parameters
[in]showTrue to show the cursor, false to hide it.
void Rocket::Core::Context::UnloadAllDocuments ( )

Unloads all loaded documents.

void Rocket::Core::Context::UnloadAllMouseCursors ( )

Unloads all currently loaded cursors.

void Rocket::Core::Context::UnloadDocument ( ElementDocument *  document)

Unload the given document.

Parameters
[in]documentThe document to unload.
void Rocket::Core::Context::UnloadMouseCursor ( const String &  cursor_name)

Unload the given cursor.

Parameters
[in]cursor_nameThe name of cursor to unload.
bool Rocket::Core::Context::Update ( )

Updates all elements in the context's documents.

Friends And Related Function Documentation

ROCKETCORE_API Context* CreateContext ( const String &  ,
const Vector2i &  ,
RenderInterface *   
)
friend

Creates a new element context.

Parameters
[in]nameThe new name of the context. This must be unique.
[in]dimensionsThe initial dimensions of the new context.
[in]render_interfaceThe custom render interface to use, or NULL to use the default.
Returns
The new context, or NULL if the context could not be created.
friend class Element
friend

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