ofxDOM
A DOM Level 3 Events implementation for openFrameworks.
|
A class representing a DOM Element. More...
#include <Element.h>
Public Member Functions | |
Element (float x, float y, float width, float height) | |
Construct a new Element with the given parameters. More... | |
Element (const std::string &id, float x, float y, float width, float height) | |
Construct a new Element with the given parameters. More... | |
virtual | ~Element () |
Destroy the Element. | |
template<typename ElementType > | |
ElementType * | addChild (std::unique_ptr< ElementType > element) |
Take ownership of the passed std::unique_ptr<Element>. More... | |
template<typename ElementType , typename... Args> | |
ElementType * | addChild (Args &&...args) |
Create a child using a templated Element type. More... | |
std::unique_ptr< Element > | removeChild (Element *element) |
Release ownership of a child Element. More... | |
void | moveToFront () |
Move this Element in front of all of its siblings. | |
void | moveForward () |
Move this Element in front of its next sibling. | |
void | moveToBack () |
Move this Element in back of all of its siblings. | |
void | moveBackward () |
Move this Element in back of its next sibling. | |
void | moveChildToIndex (Element *element, std::size_t index) |
Move the given Element to the the given index. More... | |
void | moveChildToFront (Element *element) |
Move the given Element in front of all of its siblings. More... | |
void | moveChildForward (Element *element) |
Move the given Element in front of its next sibling. More... | |
void | moveChildToBack (Element *element) |
Move the given Element in back of all of its siblings. More... | |
void | moveChildBackward (Element *element) |
Move the given Element in back of its next sibling. More... | |
bool | isChild (Element *element) const |
Determine if the given Element is a child of this Element. More... | |
bool | isSibling (Element *element) const |
Determine if the given Element is a sibling of this Element. More... | |
std::size_t | numSiblings () const |
std::vector< Element * > | siblings () |
template<typename ElementType > | |
std::vector< ElementType * > | siblings () |
Get a list of siblings of a given Element or Element subclass. More... | |
bool | isParent (Element *element) const |
Determine if the given Element is the parent of this Element. More... | |
std::size_t | numChildren () const |
std::vector< Element * > | children () |
Get a list of pointers to the child elements. More... | |
template<typename ElementType > | |
std::vector< ElementType * > | children () |
Get a list of pointers to the child elements. More... | |
bool | hasParent () const |
Determine if this Element has a parent Element. More... | |
Element * | findFirstChildById (const std::string &id) |
Find this Element's first child by its id. More... | |
std::vector< Element * > | findChildrenById (const std::string &id) |
Find all of this Element's matching the given id. More... | |
Element * | parent () |
Get a pointer to the parent. More... | |
const Element * | parent () const |
Get a pointer to the parent. More... | |
Document * | document () |
Get a pointer to the parent Document. More... | |
const Document * | document () const |
Get a pointer to the parent Document. More... | |
template<typename LayoutType , typename... Args> | |
LayoutType * | createLayout (Args &&...args) |
Create a Layout using a templated Layout type. More... | |
template<typename LayoutType > | |
LayoutType * | setLayout (std::unique_ptr< LayoutType > layout) |
Take ownership of the passed std::unique_ptr<Layout>. More... | |
std::unique_ptr< Layout > | removeLayout () |
Release ownership of the Layout. More... | |
Layout * | layout () |
Get a pointer to the associated Layout. More... | |
virtual bool | hitTest (const Position &parentPosition) const |
Perform a hit test on the Element. More... | |
virtual bool | childHitTest (const Position &localPosition) const |
Perform a hit test on a child Element. More... | |
Position | localToScreen (const Position &localPosition) const |
Convert the local coordinates to screen coordinates. More... | |
Position | screenToLocal (const Position &screenPosition) const |
Convert the screen coordinates to local coordinates. More... | |
Position | parentToScreen (const Position &parentPosition) const |
Convert the parent coordinates to screen coordinates. More... | |
Position | screenToParent (const Position &screenPosition) const |
Convert the screen coordinates to parent coordinates. More... | |
void | setPosition (float x, float y) |
Set the position of the Element in its parent coordinates. More... | |
void | setPosition (const Position &position) |
Set the position of the Element in its parent coordinates. More... | |
Position | getPosition () const |
Get the position of the Element in its parent coordinates. More... | |
float | getX () const |
Get the X position of the Element in its parent coordinates. More... | |
float | getY () const |
Get the Y position of the Element in its parent coordinates. More... | |
Position | getScreenPosition () const |
Get the Position of the Element in screen coordinates. More... | |
float | getScreenX () const |
Get the X position of the Element in screen coordinates. More... | |
float | getScreenY () const |
Get the Y position of the Element in screen coordinates. More... | |
void | setSize (float width, float height) |
Set the size of the Element. More... | |
Size | getSize () const |
Get the Size of the Element. More... | |
float | getWidth () const |
Get the width of the Element. More... | |
float | getHeight () const |
Get the height of the Element. More... | |
Geometry | getGeometry () const |
Get the geometry of the Element in its parent coordinates. More... | |
void | setGeometry (const Geometry &geometry) |
Set the geometry of the Element in its parent coordinates. More... | |
Geometry | getChildGeometry () const |
Get the bounding box representing all child elements. More... | |
Geometry | getTotalGeometry () const |
Get the bounding box representing the union of the child geometry and the element geometry. More... | |
std::string | getId () const |
Get the id of this Element. More... | |
void | setId (const std::string &id) |
Set the id of the Element. More... | |
bool | hasAttribute (const std::string &name) const |
Determine of the Element has an attribute with the given name. More... | |
template<typename AnyType > | |
AnyType | getAttribute (const std::string &key, bool inherit=false) const |
Get a named attribute via its key. More... | |
void | setAttribute (const std::string &name, const Any &value) |
Set a value for a named attribute. More... | |
void | clearAttribute (const std::string &name) |
Clear a named attribute. More... | |
void | setPointerCapture (std::size_t id) |
Request that the parent Document capture the given pointer id. More... | |
void | releasePointerCapture (std::size_t id) |
Release a captured pointer with the given id. More... | |
bool | isEnabled () const |
void | setEnabled (bool enabled) |
Enable or disable this Element. More... | |
bool | isHidden () const |
void | setHidden (bool hidden) |
Hide or show this Element. More... | |
bool | isLocked () const |
void | setLocked (bool locked) |
Lock or unlock a this Element. More... | |
Public Member Functions inherited from ofx::DOM::EventTarget< Element > | |
EventTarget () | |
Create an EventTarget. | |
virtual | ~EventTarget () |
Destroy the EventTarget. | |
void | addEventListener (EventType &event, void(ListenerClass::*listenerMethod)(const void *, ArgumentsType &), bool useCapture=false, int priority=OF_EVENT_ORDER_AFTER_APP) |
void | addEventListener (EventType &event, void(ListenerClass::*listenerMethod)(ArgumentsType &), bool useCapture=false, int priority=OF_EVENT_ORDER_AFTER_APP) |
void | addEventListener (EventType &event, bool(ListenerClass::*listenerMethod)(const void *, ArgumentsType &), bool useCapture=false, int priority=OF_EVENT_ORDER_AFTER_APP) |
void | addEventListener (EventType &event, bool(ListenerClass::*listenerMethod)(ArgumentsType &), bool useCapture=false, int priority=OF_EVENT_ORDER_AFTER_APP) |
void | removeEventListener (EventType &event, void(ListenerClass::*listenerMethod)(const void *, ArgumentsType &), bool useCapture=false, int priority=OF_EVENT_ORDER_AFTER_APP) |
void | removeEventListener (EventType &event, void(ListenerClass::*listenerMethod)(ArgumentsType &), bool useCapture=false, int priority=OF_EVENT_ORDER_AFTER_APP) |
void | removeEventListener (EventType &event, bool(ListenerClass::*listenerMethod)(const void *, ArgumentsType &), bool useCapture=false, int priority=OF_EVENT_ORDER_AFTER_APP) |
void | removeEventListener (EventType &event, bool(ListenerClass::*listenerMethod)(ArgumentsType &), bool useCapture=false, int priority=OF_EVENT_ORDER_AFTER_APP) |
bool | dispatchEvent (EventType &event) |
Dispatch the given event. More... | |
bool | handleEvent (EventArgsType &e) |
Handle the given event. More... | |
bool | hasListenersForEventType (const std::string &type) const |
Determine if the EventTarget has listeners for an event. More... | |
bool | isEventTypeRegistered (const std::string &type) const |
Determine if the EventTarget is registered to receive the type of events. More... | |
void | registerEventType (const std::string &type, BaseDOMEvent *event) |
Register a new event type by name. More... | |
void | unregisterEventType (const std::string &type) |
Unregister a new event type by name. More... | |
virtual void | onSetup () |
virtual void | onUpdate () |
virtual void | onDraw () const |
virtual void | onExit () |
Protected Member Functions | |
void | _setup (ofEventArgs &e) |
Setup method called by parent Element. More... | |
void | _update (ofEventArgs &e) |
Update method called by parent Element. More... | |
void | _draw (ofEventArgs &e) |
Draw method called by parent Element. More... | |
void | _exit (ofEventArgs &e) |
Exit method called by parent Element. More... | |
Element * | recursiveHitTest (const Position &parentPosition) |
A recursive hit test to find a target element. More... | |
std::vector< std::unique_ptr< Element > >::iterator | findChild (Element *element) |
Find a child by a raw Element pointer. More... | |
bool | isPointerCaptured (std::size_t id) const |
Determine if a given pointer id is captured. More... | |
std::vector< CapturedPointer >::iterator | findCapturedPointerById (std::size_t id) |
Find the given CapturePointer info by id. More... | |
std::vector< CapturedPointer >::const_iterator | findCapturedPointerById (std::size_t id) const |
Find the given CapturePointer info by id. More... | |
std::vector< CapturedPointer > & | capturedPointers () |
Get a reference to the captured pointer vector. More... | |
const std::vector< CapturedPointer > & | capturedPointers () const |
Get a reference to the captured pointer vector. More... | |
virtual void | invalidateChildGeometry () const |
Called internally to invalidate the child geometry tree. | |
void | setImplicitPointerCapture (bool implicitPointerCapture) |
Set if the pointer is implicitly captured on pointer down. More... | |
bool | getImplicitPointerCapture () const |
Determine if pointer is automatically captured on pointer down. More... | |
Friends | |
class | Layout |
The Layout class has access to all private variables. | |
class | Document |
The Document class has access to all private variables. | |
Additional Inherited Members | |
Public Attributes inherited from ofx::DOM::EventTarget< Element > | |
DOMEvent< PointerUIEventArgs > | pointerOver |
DOMEvent< PointerUIEventArgs > | pointerEnter |
DOMEvent< PointerUIEventArgs > | pointerDown |
DOMEvent< PointerUIEventArgs > | pointerMove |
DOMEvent< PointerUIEventArgs > | pointerUp |
DOMEvent< PointerUIEventArgs > | pointerCancel |
DOMEvent< PointerUIEventArgs > | pointerOut |
DOMEvent< PointerUIEventArgs > | pointerLeave |
DOMEvent< PointerUIEventArgs > | pointerScroll |
DOMEvent< PointerCaptureUIEventArgs > | gotPointerCapture |
DOMEvent< PointerCaptureUIEventArgs > | lostPointerCapture |
DOMEvent< KeyboardUIEventArgs > | keyDown |
DOMEvent< KeyboardUIEventArgs > | keyUp |
DOMEvent< FocusEventArgs > | blur |
DOMEvent< FocusEventArgs > | focusIn |
DOMEvent< FocusEventArgs > | focus |
DOMEvent< FocusEventArgs > | focusOut |
ofEvent< ElementEventArgs > | addedTo |
ofEvent< ElementEventArgs > | removedFrom |
ofEvent< ElementOrderEventArgs > | reordered |
ofEvent< ElementEventArgs > | siblingAdded |
ofEvent< ElementEventArgs > | siblingRemoved |
ofEvent< ElementOrderEventArgs > | siblingReordered |
ofEvent< ElementEventArgs > | childAdded |
ofEvent< ElementEventArgs > | childRemoved |
ofEvent< ElementOrderEventArgs > | childReordered |
ofEvent< MoveEventArgs > | move |
ofEvent< ResizeEventArgs > | resize |
ofEvent< AttributeEventArgs > | attributeSet |
ofEvent< AttributeEventArgs > | attributeCleared |
ofEvent< EnablerEventArgs > | enabled |
ofEvent< EnablerEventArgs > | locked |
ofEvent< EnablerEventArgs > | hidden |
Protected Attributes inherited from ofx::DOM::EventTarget< Element > | |
std::unordered_map< std::string, BaseDOMEvent * > | _eventRegistry |
A class representing a DOM Element.
There are several DOM coordiante systems with respect to an Element.
ofx::DOM::Element::Element | ( | float | x, |
float | y, | ||
float | width, | ||
float | height | ||
) |
ofx::DOM::Element::Element | ( | const std::string & | id, |
float | x, | ||
float | y, | ||
float | width, | ||
float | height | ||
) |
|
protected |
Draw method called by parent Element.
e | The event data. |
|
protected |
Exit method called by parent Element.
e | The event data. |
|
protected |
Setup method called by parent Element.
e | The event data. |
|
protected |
Update method called by parent Element.
e | The event data. |
ElementType * ofx::DOM::Element::addChild | ( | std::unique_ptr< ElementType > | element | ) |
Take ownership of the passed std::unique_ptr<Element>.
This this is "sink" meaning that any child passed to this will be owned by this Node.
element | the rvalue reference to the child node. |
ElementType | The Element Type. |
Alert the node's siblings that they have a new sibling.
ElementType * ofx::DOM::Element::addChild | ( | Args &&... | args | ) |
Create a child using a templated Element type.
To create a child Element you can use this method like:
ElementType* element = parentElement->addChild<ElementType>(arguments ...);
ElementType | The subclass of Element that will be added. |
Args | The variable constructor arguments for the ElementType. |
args | The variable constructor arguments for the ElementType. |
ElementType | The Element Type. |
Args | the ElementType constructor arguments. |
|
protected |
Get a reference to the captured pointer vector.
|
protected |
Get a reference to the captured pointer vector.
|
virtual |
Perform a hit test on a child Element.
localPosition | The Position to test in local coordinates. |
std::vector< Element * > ofx::DOM::Element::children | ( | ) |
Get a list of pointers to the child elements.
The parent Element retains ownership.
std::vector< ElementType * > ofx::DOM::Element::children | ( | ) |
Get a list of pointers to the child elements.
The parent Element retains ownership.
void ofx::DOM::Element::clearAttribute | ( | const std::string & | name | ) |
Clear a named attribute.
The | name of the attribute to clear. |
LayoutType * ofx::DOM::Element::createLayout | ( | Args &&... | args | ) |
Create a Layout using a templated Layout type.
To create a Layout you can use this method like:
LayoutType* layout = parentElement->createLayout<LayoutType>(arguments ...);
ElementType | The subclass of Element that will be added. |
Args | The variable constructor arguments for the ElementType. |
args | The variable constructor arguments for the ElementType. |
ElementType | The Element Type. |
Args | the ElementType constructor arguments. |
Document * ofx::DOM::Element::document | ( | ) |
const Document * ofx::DOM::Element::document | ( | ) | const |
|
protected |
Find the given CapturePointer info by id.
id | The pointer id to find. |
|
protected |
Find the given CapturePointer info by id.
id | The pointer id to find. |
std::vector< Element * > ofx::DOM::Element::findChildrenById | ( | const std::string & | id | ) |
Find all of this Element's matching the given id.
id | The id of the child Elements to find. |
Element * ofx::DOM::Element::findFirstChildById | ( | const std::string & | id | ) |
AnyType ofx::DOM::Element::getAttribute | ( | const std::string & | key, |
bool | inherit = false |
||
) | const |
Get a named attribute via its key.
Users should check to see if the attribute exists using hasAttribute or catch the DOMException.
DOMException | if no such key. |
Poco::BadCastException | if the types do not match. |
key | The name of the attribute. |
inherit | True if the Element should query its ancestors for the attribute. |
Geometry ofx::DOM::Element::getChildGeometry | ( | ) | const |
Get the bounding box representing all child elements.
Geometry ofx::DOM::Element::getGeometry | ( | ) | const |
float ofx::DOM::Element::getHeight | ( | ) | const |
std::string ofx::DOM::Element::getId | ( | ) | const |
|
protected |
Determine if pointer is automatically captured on pointer down.
Position ofx::DOM::Element::getPosition | ( | ) | const |
Get the position of the Element in its parent coordinates.
Local coordinates are defined with reference to the position of the box. The Position of this element will be in its parent's local coordinates.
Position ofx::DOM::Element::getScreenPosition | ( | ) | const |
float ofx::DOM::Element::getScreenX | ( | ) | const |
float ofx::DOM::Element::getScreenY | ( | ) | const |
Size ofx::DOM::Element::getSize | ( | ) | const |
Geometry ofx::DOM::Element::getTotalGeometry | ( | ) | const |
Get the bounding box representing the union of the child geometry and the element geometry.
float ofx::DOM::Element::getWidth | ( | ) | const |
float ofx::DOM::Element::getX | ( | ) | const |
float ofx::DOM::Element::getY | ( | ) | const |
bool ofx::DOM::Element::hasAttribute | ( | const std::string & | name | ) | const |
bool ofx::DOM::Element::hasParent | ( | ) | const |
|
virtual |
Perform a hit test on the Element.
For a normal Element, the hit test will test the rectangular geometry of the Element. Subclasses can override this method for custom hit test geometry.
Parent coordinates are used because the geometry / position of the Element are in parent coordinates.
parentPosition | The Position to test in parent coordinates. |
bool ofx::DOM::Element::isChild | ( | Element * | element | ) | const |
bool ofx::DOM::Element::isEnabled | ( | ) | const |
bool ofx::DOM::Element::isHidden | ( | ) | const |
bool ofx::DOM::Element::isLocked | ( | ) | const |
bool ofx::DOM::Element::isParent | ( | Element * | element | ) | const |
|
protected |
Determine if a given pointer id is captured.
id | The pointer id to test. |
bool ofx::DOM::Element::isSibling | ( | Element * | element | ) | const |
Layout* ofx::DOM::Element::layout | ( | ) |
Position ofx::DOM::Element::localToScreen | ( | const Position & | localPosition | ) | const |
Convert the local coordinates to screen coordinates.
Local coordinates are defined with reference to the position of the box. The Position of this element will be in its parent's local coordinates.
localPosition | The local coordinates to convert. |
void ofx::DOM::Element::moveChildBackward | ( | Element * | element | ) |
Move the given Element in back of its next sibling.
element | The child element to move. |
DOMException(DOMException::INVALID_STATE_ERROR) | if no matching child element exists. |
void ofx::DOM::Element::moveChildForward | ( | Element * | element | ) |
Move the given Element in front of its next sibling.
element | The child element to move. |
DOMException(DOMException::INVALID_STATE_ERROR) | if no matching child element exists. |
void ofx::DOM::Element::moveChildToBack | ( | Element * | element | ) |
Move the given Element in back of all of its siblings.
element | The child element to move. |
DOMException(DOMException::INVALID_STATE_ERROR) | if no matching child element exists. |
void ofx::DOM::Element::moveChildToFront | ( | Element * | element | ) |
Move the given Element in front of all of its siblings.
DOMException(DOMException::INVALID_STATE_ERROR) | if no matching child element exists. |
void ofx::DOM::Element::moveChildToIndex | ( | Element * | element, |
std::size_t | index | ||
) |
Move the given Element to the the given index.
If the index value is greater than the number of children, the element will be moved into the last position.
element | The child element to move. |
index | The child index to move to. |
DOMException(DOMException::INVALID_STATE_ERROR) | if no matching child element exists. |
std::size_t ofx::DOM::Element::numChildren | ( | ) | const |
std::size_t ofx::DOM::Element::numSiblings | ( | ) | const |
Element * ofx::DOM::Element::parent | ( | ) |
Get a pointer to the parent.
const Element * ofx::DOM::Element::parent | ( | ) | const |
Get a pointer to the parent.
Position ofx::DOM::Element::parentToScreen | ( | const Position & | parentPosition | ) | const |
Convert the parent coordinates to screen coordinates.
parentPosition | The parent coordinates to convert. |
|
protected |
void ofx::DOM::Element::releasePointerCapture | ( | std::size_t | id | ) |
Release a captured pointer with the given id.
Usually this call is not required as the parent Document's pointer dispatching system will automatically release a pointer on the next POINTER_UP event. In some cases, the user may want to explicity release the event to fire the associated lostPointerCapture events.
id | The pointer id to release. |
std::unique_ptr<Layout> ofx::DOM::Element::removeLayout | ( | ) |
Position ofx::DOM::Element::screenToLocal | ( | const Position & | screenPosition | ) | const |
Convert the screen coordinates to local coordinates.
Local coordinates are defined with reference to the position of the box. The Position of this element will be in its parent's local coordinates.
screenPosition | The screen coordinates to convert. |
Position ofx::DOM::Element::screenToParent | ( | const Position & | screenPosition | ) | const |
Convert the screen coordinates to parent coordinates.
screenPosition | The screen coordinates to convert. |
void ofx::DOM::Element::setAttribute | ( | const std::string & | name, |
const Any & | value | ||
) |
Set a value for a named attribute.
If the given attribute exists, it will be overwritten with the given value.
name | The name of the attribute. |
value | The new value of the attribute called name. |
void ofx::DOM::Element::setEnabled | ( | bool | enabled | ) |
Enable or disable this Element.
enabled | The enabled state to set. True to enable, false to disable. |
void ofx::DOM::Element::setGeometry | ( | const Geometry & | geometry | ) |
void ofx::DOM::Element::setHidden | ( | bool | hidden | ) |
Hide or show this Element.
hidden | The visible state to set. True to hide, false to show. |
void ofx::DOM::Element::setId | ( | const std::string & | id | ) |
|
protected |
Set if the pointer is implicitly captured on pointer down.
This does not enable the pointer listener, only if the pointer should be automatically captured when a listener is enabled.
implicitPointerCapture | True if the pointer should be captured. |
LayoutType * ofx::DOM::Element::setLayout | ( | std::unique_ptr< LayoutType > | layout | ) |
Take ownership of the passed std::unique_ptr<Layout>.
This this is "sink" meaning that any Layout passed to this will be owned by this Element.
layout | the rvalue reference to the Layout. |
LayoutType | The Layout Type. |
void ofx::DOM::Element::setLocked | ( | bool | locked | ) |
Lock or unlock a this Element.
locked | The locked state to set. True to lock, false to unlock. |
void ofx::DOM::Element::setPointerCapture | ( | std::size_t | id | ) |
void ofx::DOM::Element::setPosition | ( | float | x, |
float | y | ||
) |
Set the position of the Element in its parent coordinates.
x | The new x position. |
y | The new y position. |
void ofx::DOM::Element::setPosition | ( | const Position & | position | ) |
Set the position of the Element in its parent coordinates.
position | The new position. |
void ofx::DOM::Element::setSize | ( | float | width, |
float | height | ||
) |
std::vector< Element * > ofx::DOM::Element::siblings | ( | ) |
std::vector< ElementType * > ofx::DOM::Element::siblings | ( | ) |