DIWNE::DiwneObject
The base class for all DIWNE elements containing common functionality.
#include "DIWNE/Core/Elements/DiwneObject.h"
Inherits from std::enable_shared_from_this< DiwneObject >
Inherited by DIWNE::Link, DIWNE::Node, DIWNE::NodeDropZone, DIWNE::NodeEditor, DIWNE::Pin
Public Functions
Name | |
---|---|
DiwneObject(DIWNE::NodeEditor & diwne, std::string labelDiwne) | |
virtual | ~DiwneObject() |
virtual void | afterDraw(DrawInfo & context)<br>Called last during drawing. |
virtual bool | allowDragStart() const<br>Determines whether a drag operation can start from this object. |
virtual bool | allowDrawing()<br>Decide whether the object should be drawn (when outside the window for example) |
virtual bool | allowHover() const<br>Determines whether the object can be hovered. |
virtual bool | allowInteraction() const<br>Decide whether the object should react to user input in general. |
virtual bool | allowPopup() const<br>Determines whether a popup can be raised over the object. |
virtual bool | allowPress(const DrawInfo & context) const<br>Determines whether the object can be pressed. |
virtual bool | allowSelectOnClick(const DrawInfo & context) const<br>Determines whether the object can be selected by clicking it (eg. |
template <typename T =DiwneObject> <br>T * | as()<br>Returns a raw pointer to itself casted to a type. |
virtual void | begin(DrawInfo & context) =0<br>First method to be called during object drawing. |
virtual void | content(DrawInfo & context) =0<br>Called after begin() during drawing. |
virtual void | destroy(bool logEvent =true)<br>Marks the object for lazy destruction/deallocation and removal from any containers (like the node editor). |
virtual void | draw(DrawMode drawMode =DrawMode_Interactive)<br>Generic draw method meant to be used by external code. |
virtual void | drawDiwne(DrawInfo & context, DrawMode drawMode =DrawMode_Interactive)<br>Internal draw method. |
DrawInfo | drawDiwneEx(DrawInfo & context, DrawMode drawMode =DrawMode_Interactive) |
virtual void | end(DrawInfo & context) =0<br>Called after content(). |
virtual void | finalize(DrawInfo & context)<br>The final method to be called, gets called every frame and doesn't do any drawing. |
ImRect | getDisplayRect() const<br>Object's bounds aligned to current viewport pixel boundaries. |
ID | getId() const |
DiwneObject * | getParentObject() const |
ImVec2 | getPosition() const<br>Returns the top left corner of the object's rect. |
virtual ImRect | getRect() const<br>Rectangle bounds of the object in DIWNE coordinates (editor canvas coordinates). |
bool | getSelectable() |
virtual bool | getSelected() const<br>Whether the object is selected or not. |
StyleOverride * | getStyleOverride() const |
virtual void | initialize(DrawInfo & context)<br>First method to be called every frame. |
bool | isAnyParentSelected() |
bool | isChildObject() const |
bool | isChildOfObject(DiwneObject * parent) |
bool | isDestroyed() const |
bool | isDragging(DrawInfo & context)<br>Is this object the source of an active dragging operation? |
bool | isFixed() const<br>Fixed objects are ones rendered at a position determined by some other object. |
bool | isRendered() const |
bool | isToBeBroughtToFront() |
virtual void | onDestroy(bool logEvent)<br>Gets called the moment the object is marked for deletion by destroy(). |
virtual void | onDrag(DrawInfo & context, bool dragStart, bool dragEnd)<br>This method gets called when the object is being dragged. |
virtual void | onHover(DrawInfo & context)<br>This method gets called when the object is hovered. |
virtual void | onPopup() |
virtual void | onPressed(bool justPressed, DrawInfo & context)<br>Called when the object is pressed, meaning a key is pressed over it. |
virtual void | onReleased(bool justReleased, DrawInfo & context)<br>Called when the object is not pressed. |
virtual void | onSelection(bool selected) |
void | openPopup()<br>Request to open the object's popup if possible. |
bool | operator!=(const DiwneObject & rhs) const |
bool | operator==(const DiwneObject & rhs) const |
virtual void | popupContent(DrawInfo & context)<br>Content of popup menu raised on this objec. |
virtual void | processInteractions(DrawInfo & context)<br>Method for reacting to user input after the object is fully drawn and its dimensions are known. |
void | setBringToFront(bool val)<br>Marks the object to be brought to front (be drawn first). |
void | setFixed(bool val) |
void | setForceDraw(bool val)<br>When true, makes the object automatically add the ForceDraw DrawMode flag. |
void | setParentObject(DiwneObject * parent) |
void | setPopupEnabled(bool val) |
void | setPosition(const ImVec2 & position)<br>Move the object's rect and any other associated positional data to the specified position. |
void | setRendered(bool val) |
void | setSelectable(bool selectable)<br>Whether the object can be selected. |
virtual bool | setSelected(bool selected)<br>Set the selection state of the object. |
void | setStyleOverride(StyleOverride * styleOverride)<br>Assign a StyleOverride object to this DiwneObject. |
void | setTooltip(const std::string & text) |
void | setTooltipEnabled(bool val) |
template <typename T =DiwneObject> <br>std::shared_ptr< T > | sharedPtr()<br>Returns a shared pointer to this object. |
void | showTooltip(const std::string & label, const ImColor && color, DrawInfo & context)<br>Immediately show a tooltip next to the mouse cursor with the specified text. |
void | showTooltip(const std::string & label, const std::string & desc, const ImColor && color, DrawInfo & context, float wrapWidth =35.f)<br>Immediately show a tooltip next to the mouse cursor with the specified text. |
void | stopDrag(DrawInfo & context)<br>End an active drag operation this object is a source of. |
virtual Style & | style() const<br>Get the style for this object. |
virtual void | tooltipContent(DrawInfo & context)<br>Content of the object's tooltip. |
virtual void | translate(const ImVec2 & vec)<br>Move the object's rect and any other associated positional data. |
virtual void | updateLayout(DrawInfo & context) =0<br>Updates object's m_rect, m_displayRect and any other object size variables. |
Protected Functions
Name | |
---|---|
virtual void | afterDrawDiwne(DrawInfo & context)<br>Updates layout, processes interactions and then calls the user afterDraw() method. |
virtual void | beginDiwne(DrawInfo & context) |
virtual void | endDiwne(DrawInfo & context) |
virtual void | finalizeDiwne(DrawInfo & context) |
virtual void | initializeDiwne(DrawInfo & context) |
virtual bool | isDraggedDiwne()<br>Is the object being dragged? (usually by mouse or some key combo) |
virtual bool | isHoveredDiwne()<br>Is the object being hovered? The default implementation mostly gets this information from ImGui::IsItemHovered() but the behavior can be changed or restricted. |
virtual bool | isJustPressedDiwne()<br>Determine whether a key/s of interest was/were just pressed. |
virtual bool | isPressedDiwne()<br>Determine whether a key/s of interest is/are pressed down over the object. |
virtual bool | popupShouldBeOpenedDiwne() const<br>Determine whether a popup should be opened, that is, by default, that right mouse button was pressed and isn't dragging. |
virtual void | processDragDiwne(DrawInfo & context) |
virtual void | processHoverDiwne(DrawInfo & context)<br>Processes whether the object is currently hovered. |
virtual void | processInteractionsDiwne(DrawInfo & context) |
virtual void | processPopupAndTooltipDiwne(DrawInfo & context)<br>Processes whether a popup should be opened over this object. |
virtual void | processPressAndReleaseDiwne(DrawInfo & context)<br>Processes whether the object is currently pressed (held) and further if it was just pressed or released. |
virtual bool | processSelectDiwne(DrawInfo & context)<br>Processes any interactions related to whether the object should be selected. |
virtual void | setInitialPositionDiwne()<br>Internal helper for setting the object's initial position. |
void | setSize(const ImVec2 & size) |
void | updateRectFromImGuiItem() |
Public Attributes
Name | |
---|---|
NodeEditor & | diwne <br>Reference to the NodeEditor instance (also named 'editor' in some classes) |
bool | m_deletable <br>Whether the object can be destroyed by the user. |
bool | m_destroy <br>Indicates the object is to be deleted (and deallocated) |
ImRect | m_displayRect <br>Rectangle bounds aligned with the last viewport. |
bool | m_draggable <br>Whether dragging of the object is allowed by default. |
DrawMode | m_drawMode <br>Read-only flag thats updated on each drawDiwne(). |
bool | m_drawnThisFrame <br>Read only flag indicating whether the object has been drawn this frame. |
bool | m_fixed <br>Whether the object can be moved by user operations. |
bool | m_forceHoverDiwne <br>Special flag that can be used to enforce hover state, used by pin drag assist. |
bool | m_hoverable <br>Whether hovering is enabled by default. |
bool | m_hovered <br>Is the object hovered (usually by the mouse or whatever isHoveredDiwne() tracks) |
bool | m_hoverRoot <br>Whether hovering this object should prevent other objects from hovering. |
ID | m_idDiwne <br>Unique numeric identifier of the object. |
bool | m_isDragged <br>Is the object dragged? Returns false immediately on drag end (unlike isDragging()). |
bool | m_isPressed <br>Is the object pressed down (held)? Requirement for dragging. |
bool | m_justHidden <br>Read only flag indicating that this object was drawn last frame, but not this one. |
bool | m_justPressed <br>Read only flag indicating the object was pressed this frame (eg. |
bool | m_justReleased <br>Read only flag indicating the object was released this frame (eg. |
std::string | m_labelDiwne <br>Unique string identifier, consists of <some string>:<m_idDiwne>. |
ImRect | m_rect <br>Rectangle bounds of the object in diwne coordinates. |
StyleOverride * | m_styleOverride <br>Style override to allow uniquely styled object types. |
Protected Attributes
Name | |
---|---|
unsigned long long | g_diwneIDCounter <br>Static unique ID generator, unique only for current application run. |
bool | m_bringToFront <br>Request the object's rendering order to be moved to the front above other objects. |
bool | m_forceDraw <br>Request the next draw of the object to have the ForceDraw DrawMode flag. |
bool | m_internalHover <br>Temporary storage for an internal ImGui::IsItemHovered() check Can be set in the end() method to determine if object is hovered if applicable. |
bool | m_openPopup <br>Request to open popup. |
bool | m_openTooltip <br>Request to open tooltip. |
DiwneObject * | m_parentObject <br>Sets the parent object of object, relevant in node container and hover hierarchy. |
bool | m_popupEnabled <br>Whether this object has popup enabled. |
std::string | m_popupLabelDiwne <br>ImGui popup identifier. |
bool | m_rendered <br>Whether the object should be drawn, this is a general flag that overrides behavior of the allowDrawing() method. |
bool | m_selectable <br>Should not be accessed directly. |
bool | m_selected <br>Should not be accessed directly. |
bool | m_tooltipEnabled <br>Whether this object has tooltip enabled. |
std::string | m_tooltipText |
Public Functions Documentation
function DiwneObject
DiwneObject(
DIWNE::NodeEditor & diwne,
std::string labelDiwne
)
DiwneObject(
DIWNE::NodeEditor & diwne,
std::string labelDiwne
)
Parameters:
- diwne is node editor object that this object belongs to
- id used to identification
- labelDiwne used to identification
function ~DiwneObject
virtual ~DiwneObject()
virtual ~DiwneObject()
function afterDraw
virtual void afterDraw(
DrawInfo & context
)
virtual void afterDraw(
DrawInfo & context
)
Called last during drawing.
Reimplemented by: Workspace::CoreNodeWithPins::afterDraw, Workspace::Camera::afterDraw, Workspace::Model::afterDraw, Workspace::Sequence::afterDraw, DIWNE::BasicNodeWithPins::afterDraw, DIWNE::NodeDropZone::afterDraw, DIWNE::Node::afterDraw, DIWNE::Pin::afterDraw, DIWNE::NodeEditor::afterDraw
At this point the m_rect of the object should be calculated in the updateLayout() method and this method should be able to work with it. Because of that the drawing code within shouldn't affect the objects size anymore. Interactions are processed before this method and thus interaction related member variables can be used within.
function allowDragStart
virtual bool allowDragStart() const
virtual bool allowDragStart() const
Determines whether a drag operation can start from this object.
See: isDraggedDiwne(), allowPress()
Reimplemented by: DIWNE::NodeDropZone::allowDragStart, DIWNE::Pin::allowDragStart, Workspace::Node::allowDragStart
By default the only requirement is the object to be pressed.
function allowDrawing
virtual bool allowDrawing()
virtual bool allowDrawing()
Decide whether the object should be drawn (when outside the window for example)
Reimplemented by: DIWNE::Link::allowDrawing, DIWNE::Node::allowDrawing, Workspace::CoreNode::allowDrawing, Workspace::CorePin::allowDrawing, Workspace::Sequence::allowDrawing, Workspace::TransformationBase::allowDrawing
function allowHover
virtual bool allowHover() const
virtual bool allowHover() const
Determines whether the object can be hovered.
See: isHoveredDiwne()
Reimplemented by: DIWNE::NodeDropZone::allowHover
Is always allowed by default.
function allowInteraction
virtual bool allowInteraction() const
virtual bool allowInteraction() const
Decide whether the object should react to user input in general.
Dear ImGui components might require special handling.
function allowPopup
virtual bool allowPopup() const
virtual bool allowPopup() const
Determines whether a popup can be raised over the object.
See: processPopupDiwne()
Reimplemented by: DIWNE::Pin::allowPopup
Allowed by default.
function allowPress
virtual bool allowPress(
const DrawInfo & context
) const
virtual bool allowPress(
const DrawInfo & context
) const
Determines whether the object can be pressed.
See: isPressedDiwne(), allowHover(), DrawInfo::inputConsumed, InteractionState::dragging
Reimplemented by: Workspace::CoreNodeWithPins::allowPress, DIWNE::BasicNodeWithPins::allowPress
By default this requires the object to be hovered, input not being consumed and nothing else being dragged.
function allowSelectOnClick
virtual bool allowSelectOnClick(
const DrawInfo & context
) const
virtual bool allowSelectOnClick(
const DrawInfo & context
) const
Determines whether the object can be selected by clicking it (eg.
See: processSelectDiwne()
Reimplemented by: Workspace::CoreLink::allowSelectOnClick
pressing and then releasing it). This is a type of interaction and not related to whether the object is "selectable" or not. Programmatical selection using DiwneObject::setSelected() is not affected.
function as
template <typename T =DiwneObject>
inline T * as()
template <typename T =DiwneObject>
inline T * as()
Returns a raw pointer to itself casted to a type.
Template Parameters:
- T The pointer will be statically cast to this type. Ensure the cast won't fail. There are runtime checks in debug mode.
Useful as a shorthand for casting to derived object type.
function begin
virtual void begin(
DrawInfo & context
) =0
virtual void begin(
DrawInfo & context
) =0
First method to be called during object drawing.
Reimplemented by: Workspace::CoreNode::begin, Workspace::CoreNodeWithPins::begin, Workspace::Cycle::begin, Workspace::Sequence::begin, Workspace::WorkspaceDiwne::begin, DIWNE::BasicNode::begin, DIWNE::BasicNodeWithPins::begin, DIWNE::NodeDropZone::begin, DIWNE::Link::begin, DIWNE::Node::begin, DIWNE::Pin::begin, DIWNE::NodeEditor::begin
Can be used to initialize drawing code.
function content
virtual void content(
DrawInfo & context
) =0
virtual void content(
DrawInfo & context
) =0
Called after begin() during drawing.
Reimplemented by: Workspace::CoreLink::content, Workspace::CorePin::content, Workspace::WorkspaceDiwne::content, DIWNE::BasicNode::content, DIWNE::NodeDropZone::content, DIWNE::Link::content, DIWNE::Node::content, DIWNE::Pin::content, DIWNE::NodeEditor::content
Draws object content.
function destroy
virtual void destroy(
bool logEvent =true
)
virtual void destroy(
bool logEvent =true
)
Marks the object for lazy destruction/deallocation and removal from any containers (like the node editor).
Parameters:
- logEvent The boolean flag passed to onDestroy(), can be used to determine where was destroy() called from.
See: onDestroy(), isDestroyed(), ~DiwneObject()
An object can be destroyed only once, which will invoke the onDestroy() callback. Repeated calls have no effect. When the actual deallocation and destruction occurs depends on the specific object. For example deletion of nodes and links is handled by the NodeEditor in the next frame. This methods needs to be called before the objects destructor. Internally DIWNE does not use RAII. The node editor object is an exception in that it calls destroy on itself automatically in a RAII manner. When an object gets destructed without being marked for destruction a warning message is printed.
function draw
virtual void draw(
DrawMode drawMode =DrawMode_Interactive
)
virtual void draw(
DrawMode drawMode =DrawMode_Interactive
)
Generic draw method meant to be used by external code.
Parameters:
- drawMode Drawing mode
See: drawDiwne()
Reimplemented by: DIWNE::NodeEditor::draw
Note that some objects are meant to only by drawn using the internal drawDiwne() method instead.
function drawDiwne
virtual void drawDiwne(
DrawInfo & context,
DrawMode drawMode =DrawMode_Interactive
)
virtual void drawDiwne(
DrawInfo & context,
DrawMode drawMode =DrawMode_Interactive
)
Internal draw method.
Parameters:
- context The drawing context of the current frame.
- drawMode The drawing mode of this draw.
function drawDiwneEx
DrawInfo drawDiwneEx(
DrawInfo & context,
DrawMode drawMode =DrawMode_Interactive
)
DrawInfo drawDiwneEx(
DrawInfo & context,
DrawMode drawMode =DrawMode_Interactive
)
function end
virtual void end(
DrawInfo & context
) =0
virtual void end(
DrawInfo & context
) =0
Called after content().
Reimplemented by: Workspace::TransformationBase::end, Workspace::WorkspaceDiwne::end, DIWNE::BasicNode::end, DIWNE::NodeDropZone::end, DIWNE::Link::end, DIWNE::Node::end, DIWNE::Pin::end, DIWNE::NodeEditor::end
Used to end content drawing.
function finalize
virtual void finalize(
DrawInfo & context
)
virtual void finalize(
DrawInfo & context
)
The final method to be called, gets called every frame and doesn't do any drawing.
Reimplemented by: Workspace::Screen::finalize, Workspace::WorkspaceDiwne::finalize
function getDisplayRect
inline ImRect getDisplayRect() const
inline ImRect getDisplayRect() const
Object's bounds aligned to current viewport pixel boundaries.
See: getRect(), m_displayRect
Should be within ~1.0 margin of m_rect (but might be more). This rectangle should be used instead of m_rect when drawing backgrounds/borders etc, as it better aligns with ImGui content. The reason is that ImGui content is aligned on screen pixel boundaries, but m_rect isn't as it would then shift around, depending on the viewport position / zoom levels.
This rectangle is updated in DiwneObject::begin() can can be considered valid for the duration of the draw.
function getId
inline ID getId() const
inline ID getId() const
function getParentObject
DiwneObject * getParentObject() const
DiwneObject * getParentObject() const
function getPosition
inline ImVec2 getPosition() const
inline ImVec2 getPosition() const
Returns the top left corner of the object's rect.
function getRect
inline virtual ImRect getRect() const
inline virtual ImRect getRect() const
Rectangle bounds of the object in DIWNE coordinates (editor canvas coordinates).
See: getDisplayRect(), updateLayout(), m_rect
The top left corner of the rectangle (.Min) represents the objects position. Dimensions are the differences between the .Min and .Max (bottom right corner) coordinates.
The objects rectangle gets updated every frame by the updateLayout() method.
DiwneObjects are mostly drawn at the position of the ImGui cursor and this rect is updated accordingly. Some objects (like nodes) instead set the cursor position based on this rect.
Converting the objects position to screen coordinates will inevitably yield fractional pixel positions, since Dear ImGui does not handle fractional coordinates well, these initial screen coordinates get truncated to a pixel boundary, this new position, when converted back to diwne coordinates is slightly different. The m_rect position cannot be rounded as it would then change depending on the viewport position / zoom. Hence the slightly offset position is captured in m_displayRect and can be used for more precise, pixel aligned drawing.
function getSelectable
bool getSelectable()
bool getSelectable()
function getSelected
virtual bool getSelected() const
virtual bool getSelected() const
Whether the object is selected or not.
function getStyleOverride
StyleOverride * getStyleOverride() const
StyleOverride * getStyleOverride() const
See: setStyleOverride()
function initialize
virtual void initialize(
DrawInfo & context
)
virtual void initialize(
DrawInfo & context
)
First method to be called every frame.
Reimplemented by: Workspace::CoreLink::initialize, Workspace::Camera::initialize, Workspace::Model::initialize, DIWNE::NodeDropZone::initialize, DIWNE::Link::initialize, DIWNE::Pin::initialize
Does not handle drawing.
function isAnyParentSelected
inline bool isAnyParentSelected()
inline bool isAnyParentSelected()
function isChildObject
bool isChildObject() const
bool isChildObject() const
function isChildOfObject
inline bool isChildOfObject(
DiwneObject * parent
)
inline bool isChildOfObject(
DiwneObject * parent
)
function isDestroyed
inline bool isDestroyed() const
inline bool isDestroyed() const
See: destroy()
function isDragging
bool isDragging(
DrawInfo & context
)
bool isDragging(
DrawInfo & context
)
Is this object the source of an active dragging operation?
See:
- onDrag()
- dragging
function isFixed
bool isFixed() const
bool isFixed() const
Fixed objects are ones rendered at a position determined by some other object.
In such a case their position is "read only" as it will get overwritten. Top level nodes aren't fixed, as the editor adjust the ImGui cursor to their position before drawing. Objects drawn inside other objects will usually be fixed.
function isRendered
bool isRendered() const
bool isRendered() const
function isToBeBroughtToFront
bool isToBeBroughtToFront()
bool isToBeBroughtToFront()
function onDestroy
virtual void onDestroy(
bool logEvent
)
virtual void onDestroy(
bool logEvent
)
Gets called the moment the object is marked for deletion by destroy().
See: destroy()
Warning: It is possible that the onDestroy() callback is never called when destroy() wasn't properly called. DiwneObjects containing other DiwneObjects should always ensure to destroy their children in their onDestroy().
Reimplemented by: Workspace::Node::onDestroy, DIWNE::BasicNodeWithPins::onDestroy, DIWNE::SequenceNodeContainer::onDestroy, DIWNE::NodeDropZone::onDestroy, DIWNE::Link::onDestroy, DIWNE::Node::onDestroy, DIWNE::Pin::onDestroy, DIWNE::NodeEditor::onDestroy, Workspace::CoreNode::onDestroy, Workspace::CoreNodeWithPins::onDestroy, Workspace::Camera::onDestroy, Workspace::Sequence::onDestroy, Workspace::TransformationBase::onDestroy
It is called only once per object.
function onDrag
virtual void onDrag(
DrawInfo & context,
bool dragStart,
bool dragEnd
)
virtual void onDrag(
DrawInfo & context,
bool dragStart,
bool dragEnd
)
This method gets called when the object is being dragged.
Parameters:
- dragStart The drag has just started this frame.
- dragEnd The drag is ending this frame.
See: processDragDiwne(), processPressAndReleaseDiwne()
Reimplemented by: Workspace::WorkspaceDiwne::onDrag, DIWNE::Node::onDrag, DIWNE::Pin::onDrag, DIWNE::NodeEditor::onDrag
Drag begins when the object is pressed and isDraggedDiwne() returns true.
A call with dragStart true, should always be followed by a call with dragEnd true.
function onHover
virtual void onHover(
DrawInfo & context
)
virtual void onHover(
DrawInfo & context
)
This method gets called when the object is hovered.
Parameters:
- context
See: processHoverDiwne()
Reimplemented by: DIWNE::Link::onHover, DIWNE::Node::onHover
This generally indicates mouse hover, but the behavior can be changed via isHoveredDiwne().
function onPopup
inline virtual void onPopup()
inline virtual void onPopup()
Reimplemented by: Workspace::CoreNode::onPopup, Workspace::WorkspaceDiwne::onPopup
function onPressed
virtual void onPressed(
bool justPressed,
DrawInfo & context
)
virtual void onPressed(
bool justPressed,
DrawInfo & context
)
Called when the object is pressed, meaning a key is pressed over it.
Parameters:
- justPressed True on the frame of the actual press, false otherwise when the key is held down.
See: isPressedDiwne(), processPressAndReleaseDiwne()
Note: This isn't a general method for reacting to any input. This method signals a specific "pressed" or "held" state of the object which is only triggered for certain keys specified by isPressedDiwne(). By default this means being "pressed by the left mouse button", but this behavior can vary in subclasses.
Which key or keys trigger this state is determined by is isPressedDiwne() and isJustPressedDiwne(). An object is allowed to be pressed only when allowPress() returns true.
function onReleased
virtual void onReleased(
bool justReleased,
DrawInfo & context
)
virtual void onReleased(
bool justReleased,
DrawInfo & context
)
Called when the object is not pressed.
Parameters:
- justPressed True on the frame the object is released (becomes no longer pressed)
See: onPressed()
Reimplemented by: Workspace::CoreNode::onReleased, Workspace::CorePin::onReleased, DIWNE::NodeEditor::onReleased
Every frame either this or the onPressed() method is called.
function onSelection
virtual void onSelection(
bool selected
)
virtual void onSelection(
bool selected
)
Reimplemented by: DIWNE::Node::onSelection, Workspace::CoreNode::onSelection, Workspace::Camera::onSelection, Workspace::Model::onSelection, Workspace::Screen::onSelection
function openPopup
void openPopup()
void openPopup()
Request to open the object's popup if possible.
function operator!=
inline bool operator!=(
const DiwneObject & rhs
) const
inline bool operator!=(
const DiwneObject & rhs
) const
function operator==
inline bool operator==(
const DiwneObject & rhs
) const
inline bool operator==(
const DiwneObject & rhs
) const
function popupContent
virtual void popupContent(
DrawInfo & context
)
virtual void popupContent(
DrawInfo & context
)
Content of popup menu raised on this objec.
Reimplemented by: Workspace::CoreLink::popupContent, Workspace::CoreNode::popupContent, Workspace::Node::popupContent, Workspace::Camera::popupContent, Workspace::Model::popupContent, Workspace::Screen::popupContent, Workspace::ScriptingNode::popupContent, Workspace::Sequence::popupContent, Workspace::TransformationBase::popupContent, Workspace::WorkspaceDiwne::popupContent
function processInteractions
inline virtual void processInteractions(
DrawInfo & context
)
inline virtual void processInteractions(
DrawInfo & context
)
Method for reacting to user input after the object is fully drawn and its dimensions are known.
Reimplemented by: Workspace::WorkspaceDiwne::processInteractions, DIWNE::NodeDropZone::processInteractions, DIWNE::Pin::processInteractions, DIWNE::NodeEditor::processInteractions
It is called after end() and updateLayout(), but before the afterDraw() lifecycle method. Internal interactions are processed right before.
function setBringToFront
void setBringToFront(
bool val
)
void setBringToFront(
bool val
)
Marks the object to be brought to front (be drawn first).
Is handled by the object's parent / container. For nodes, they are brought forward in rendering order next frame by the NodeEditor / NodeContainer.
function setFixed
void setFixed(
bool val
)
void setFixed(
bool val
)
function setForceDraw
void setForceDraw(
bool val
)
void setForceDraw(
bool val
)
When true, makes the object automatically add the ForceDraw DrawMode flag.
This flag is true by default and is reset after drawing. Can be used to ensure that size information is obtained no matter the drawing criteria for the first frame.
function setParentObject
void setParentObject(
DiwneObject * parent
)
void setParentObject(
DiwneObject * parent
)
function setPopupEnabled
void setPopupEnabled(
bool val
)
void setPopupEnabled(
bool val
)
function setPosition
void setPosition(
const ImVec2 & position
)
void setPosition(
const ImVec2 & position
)
Move the object's rect and any other associated positional data to the specified position.
See: translate()
function setRendered
void setRendered(
bool val
)
void setRendered(
bool val
)
function setSelectable
void setSelectable(
bool selectable
)
void setSelectable(
bool selectable
)
Whether the object can be selected.
When this is set to true the object cannot be selected anymore. Although it may remain selected if it was selected beforehand.
function setSelected
virtual bool setSelected(
bool selected
)
virtual bool setSelected(
bool selected
)
Set the selection state of the object.
See: setSelectable()
Return:
- The new state of selection
- New state of selection
This method can be used to select the object. If the selection state is changed by the call the onSelection() method is invoked.
function setStyleOverride
void setStyleOverride(
StyleOverride * styleOverride
)
void setStyleOverride(
StyleOverride * styleOverride
)
Assign a StyleOverride object to this DiwneObject.
Warning: StyleOverride objects ARE NOT managed by DIWNE, meaning this pointer is assumed to be always valid. Handle lifetime of StyleOverride objects in your own code.
This object acts as a proxy of the overarching NodeEditor's style. It can replace certain style variables with different ones to change style of a particular set of DiwneObject's it has been assigned to. A single StyleOverride object can be shared among many objects (to style a particular Node type for example).
function setTooltip
void setTooltip(
const std::string & text
)
void setTooltip(
const std::string & text
)
function setTooltipEnabled
void setTooltipEnabled(
bool val
)
void setTooltipEnabled(
bool val
)
function sharedPtr
template <typename T =DiwneObject>
inline std::shared_ptr< T > sharedPtr()
template <typename T =DiwneObject>
inline std::shared_ptr< T > sharedPtr()
Returns a shared pointer to this object.
Template Parameters:
- T The pointer will be statically cast to this type. Ensure the cast won't fail. There are runtime checks in debug mode.
All DiwneObjects are assumed to be stored somewhere as a shared pointer. This can be used to retrieve an owning shared pointer from a "weak" raw pointer to a DiwneObject.
function showTooltip
void showTooltip(
const std::string & label,
const ImColor && color,
DrawInfo & context
)
void showTooltip(
const std::string & label,
const ImColor && color,
DrawInfo & context
)
Immediately show a tooltip next to the mouse cursor with the specified text.
Parameters:
- label Text to show
- color is the color of the tooltip
Prevents other tooltips from showing this frame.
function showTooltip
void showTooltip(
const std::string & label,
const std::string & desc,
const ImColor && color,
DrawInfo & context,
float wrapWidth =35.f
)
void showTooltip(
const std::string & label,
const std::string & desc,
const ImColor && color,
DrawInfo & context,
float wrapWidth =35.f
)
Immediately show a tooltip next to the mouse cursor with the specified text.
Parameters:
- label Text to show
- desc Smaller text description
- color Color of the tooltip
- wrapWidth Max number of characters before text wrap.
Prevents other tooltips from showing this frame.
function stopDrag
void stopDrag(
DrawInfo & context
)
void stopDrag(
DrawInfo & context
)
End an active drag operation this object is a source of.
See: onDrag()
function style
virtual Style & style() const
virtual Style & style() const
Get the style for this object.
See: setStyleOverride(), StyleBase
Reimplemented by: DIWNE::NodeEditor::style
NodeEditor subclass is where the base style is stored. Other objects however can override the base style.
function tooltipContent
virtual void tooltipContent(
DrawInfo & context
)
virtual void tooltipContent(
DrawInfo & context
)
Content of the object's tooltip.
Reimplemented by: Workspace::CorePin::tooltipContent
function translate
virtual void translate(
const ImVec2 & vec
)
virtual void translate(
const ImVec2 & vec
)
Move the object's rect and any other associated positional data.
Reimplemented by: DIWNE::BasicNode::translate, DIWNE::BasicNodeWithPins::translate, DIWNE::Pin::translate, Workspace::CoreNodeWithPins::translate
function updateLayout
virtual void updateLayout(
DrawInfo & context
) =0
virtual void updateLayout(
DrawInfo & context
) =0
Updates object's m_rect, m_displayRect and any other object size variables.
See: m_rect, m_displayRect
Reimplemented by: DIWNE::BasicNode::updateLayout, DIWNE::NodeDropZone::updateLayout, DIWNE::Link::updateLayout, DIWNE::Node::updateLayout, DIWNE::Pin::updateLayout, DIWNE::NodeEditor::updateLayout
In other words this method is responsible for keeping track of the objects size.
IMPORTANT: This method should only update the m_rect's size, NOT it's position.
The object's rectangle is often set directly from ImGui's last item rectangle. But ImGui coordinates are aligned to pixel boundries via truncation of the coordinates, if the object's rect was updated directly using the screen space ImGui rectangle, there might be a slight discrepancy in the new position converted back to DIWNE coordinates which would cause the object to drift in a feedback loop.
m_displayRect should be updated together with m_rect to preserve correct pixel-aligned rendering in afterDraw(). TODO: Figure out if m_displayRect.Max should be aligned as well or not
This method is called after end() and before the afterDraw() method which can use the calculated size values for final drawing.
Protected Functions Documentation
function afterDrawDiwne
virtual void afterDrawDiwne(
DrawInfo & context
)
virtual void afterDrawDiwne(
DrawInfo & context
)
Updates layout, processes interactions and then calls the user afterDraw() method.
Reimplemented by: DIWNE::Node::afterDrawDiwne
function beginDiwne
virtual void beginDiwne(
DrawInfo & context
)
virtual void beginDiwne(
DrawInfo & context
)
function endDiwne
virtual void endDiwne(
DrawInfo & context
)
virtual void endDiwne(
DrawInfo & context
)
Reimplemented by: Workspace::CoreNode::endDiwne
function finalizeDiwne
virtual void finalizeDiwne(
DrawInfo & context
)
virtual void finalizeDiwne(
DrawInfo & context
)
function initializeDiwne
virtual void initializeDiwne(
DrawInfo & context
)
virtual void initializeDiwne(
DrawInfo & context
)
Reimplemented by: DIWNE::Link::initializeDiwne, DIWNE::NodeEditor::initializeDiwne
function isDraggedDiwne
virtual bool isDraggedDiwne()
virtual bool isDraggedDiwne()
Is the object being dragged? (usually by mouse or some key combo)
Reimplemented by: DIWNE::NodeEditor::isDraggedDiwne
function isHoveredDiwne
virtual bool isHoveredDiwne()
virtual bool isHoveredDiwne()
Is the object being hovered? The default implementation mostly gets this information from ImGui::IsItemHovered() but the behavior can be changed or restricted.
Reimplemented by: DIWNE::Link::isHoveredDiwne
This implementation assumes that the last ImGui item represents the entirety of the object.
It is possible the object is hovered but some other object inside of it captured the hover beforehand and didn't propagate it towards this one. Being hovered is used as a prerequisite for most interactions.
This method is indirectly called from processInteractionsDiwne() which is called right after end() method.
If the DiwneObject isn't represented by an ImGui item, this method has to be overridden and modified accordingly. This default implementation uses ImGui::IsItemHovered() call as it handles all various cases of other UI elements or windows overlapping this object.
function isJustPressedDiwne
virtual bool isJustPressedDiwne()
virtual bool isJustPressedDiwne()
Determine whether a key/s of interest was/were just pressed.
See: isPressedDiwne()
Reimplemented by: DIWNE::NodeEditor::isJustPressedDiwne
For the press action to be carried out this method must return true at least once during the key press and release cycle. This method is needed to avoid starting the press and release cycle when the key was not pressed initially over this object (Dragging pressed mouse over the object).
function isPressedDiwne
virtual bool isPressedDiwne()
virtual bool isPressedDiwne()
Determine whether a key/s of interest is/are pressed down over the object.
See: When overriding also modify isJustPressedDiwne()
Note: Overriding the pressed state behavior will modify the dragging and selection behavior.
Reimplemented by: DIWNE::NodeEditor::isPressedDiwne
While the key is down this method should return true until the key is released.
When this method returns true and other conditions are met (hovered, press allowed), the object pressed flag is set to true and onPress() method is called.
If multiple keys make this method return true it is necessary to distinguish between them later in the implementation if different functionality for each key is desired.
function popupShouldBeOpenedDiwne
virtual bool popupShouldBeOpenedDiwne() const
virtual bool popupShouldBeOpenedDiwne() const
Determine whether a popup should be opened, that is, by default, that right mouse button was pressed and isn't dragging.
function processDragDiwne
virtual void processDragDiwne(
DrawInfo & context
)
virtual void processDragDiwne(
DrawInfo & context
)
function processHoverDiwne
virtual void processHoverDiwne(
DrawInfo & context
)
virtual void processHoverDiwne(
DrawInfo & context
)
Processes whether the object is currently hovered.
See: isHoveredDiwne(), allowHover()
Hover is a prerequisite for most other interactions. Hover processing is often delegated to ImGui items forming the objects using the m_internalHover flag. Otherwise a manual mouse intersection test is needed. Hover state can also be forced using the m_forceHoverDiwne flag, which gets reset every frame.
function processInteractionsDiwne
virtual void processInteractionsDiwne(
DrawInfo & context
)
virtual void processInteractionsDiwne(
DrawInfo & context
)
function processPopupAndTooltipDiwne
virtual void processPopupAndTooltipDiwne(
DrawInfo & context
)
virtual void processPopupAndTooltipDiwne(
DrawInfo & context
)
Processes whether a popup should be opened over this object.
Parameters:
- context
If it is, the popupContent() method is called.
function processPressAndReleaseDiwne
virtual void processPressAndReleaseDiwne(
DrawInfo & context
)
virtual void processPressAndReleaseDiwne(
DrawInfo & context
)
Processes whether the object is currently pressed (held) and further if it was just pressed or released.
By default, being pressed means that the mouse is pressed down when hovering over it. The first frame of the press is considered just pressed, same for the last with just released.
What key or keys trigger the pressed state depends on the implementation of isPressedDiwne() and isJustPressedDiwne().
Regarding clicks or key presses: The concept of a "click" is often ambiguous. In ImGui it generally means the moment the mouse is just pressed. However clicks are more traditionally considered to be a rapid sequence of press and release. In DIWNE the click terminology isn't really used, an equivalent would be just released whilist not dragging. Meaning if you want to react to a click put an if (!context.state.dragging) in the onReleased() callback.
function processSelectDiwne
virtual bool processSelectDiwne(
DrawInfo & context
)
virtual bool processSelectDiwne(
DrawInfo & context
)
Processes any interactions related to whether the object should be selected.
Parameters:
- context
See: processPressAndReleaseDiwne()
Return: Whether selection processing should end. Can be used to exit early from derived methods.
Note: This is not the only method which can select the object.
Reimplemented by: DIWNE::Node::processSelectDiwne
The default behavior is selection when the object is pressed and then released (clicked).
function setInitialPositionDiwne
virtual void setInitialPositionDiwne()
virtual void setInitialPositionDiwne()
Internal helper for setting the object's initial position.
Reimplemented by: DIWNE::Link::setInitialPositionDiwne, DIWNE::Node::setInitialPositionDiwne
function setSize
void setSize(
const ImVec2 & size
)
void setSize(
const ImVec2 & size
)
function updateRectFromImGuiItem
void updateRectFromImGuiItem()
void updateRectFromImGuiItem()
Public Attributes Documentation
variable diwne
NodeEditor & diwne;
NodeEditor & diwne;
Reference to the NodeEditor instance (also named 'editor' in some classes)
variable m_deletable
bool m_deletable {true};
bool m_deletable {true};
Whether the object can be destroyed by the user.
variable m_destroy
bool m_destroy {false};
bool m_destroy {false};
Indicates the object is to be deleted (and deallocated)
variable m_displayRect
ImRect m_displayRect;
ImRect m_displayRect;
Rectangle bounds aligned with the last viewport.
See: getDisplayRect()
variable m_draggable
bool m_draggable {true};
bool m_draggable {true};
Whether dragging of the object is allowed by default.
variable m_drawMode
DrawMode m_drawMode {DrawMode_Interactive};
DrawMode m_drawMode {DrawMode_Interactive};
Read-only flag thats updated on each drawDiwne().
Essentially just a way to avoid passing this along everywhere as it should stay constant for each object.
variable m_drawnThisFrame
bool m_drawnThisFrame {false};
bool m_drawnThisFrame {false};
Read only flag indicating whether the object has been drawn this frame.
variable m_fixed
bool m_fixed {false};
bool m_fixed {false};
Whether the object can be moved by user operations.
See: isFixed()
variable m_forceHoverDiwne
bool m_forceHoverDiwne {false};
bool m_forceHoverDiwne {false};
Special flag that can be used to enforce hover state, used by pin drag assist.
variable m_hoverable
bool m_hoverable {true};
bool m_hoverable {true};
Whether hovering is enabled by default.
variable m_hovered
bool m_hovered {false};
bool m_hovered {false};
Is the object hovered (usually by the mouse or whatever isHoveredDiwne() tracks)
variable m_hoverRoot
bool m_hoverRoot {false};
bool m_hoverRoot {false};
Whether hovering this object should prevent other objects from hovering.
variable m_idDiwne
ID m_idDiwne;
ID m_idDiwne;
Unique numeric identifier of the object.
variable m_isDragged
bool m_isDragged {false};
bool m_isDragged {false};
Is the object dragged? Returns false immediately on drag end (unlike isDragging()).
variable m_isPressed
bool m_isPressed {false};
bool m_isPressed {false};
Is the object pressed down (held)? Requirement for dragging.
See: onPressed()
When dragged it is still pressed. This flag becomes valid since the processInteractions() lifecycle step.
variable m_justHidden
bool m_justHidden {false};
bool m_justHidden {false};
Read only flag indicating that this object was drawn last frame, but not this one.
variable m_justPressed
bool m_justPressed {false};
bool m_justPressed {false};
Read only flag indicating the object was pressed this frame (eg.
See: onPressed() Is object just pressed? Eg. was the button pressed down this frame.
onPressed() with justPressed=true was called) This flag becomes valid since the processInteractions() lifecycle step.
variable m_justReleased
bool m_justReleased {false};
bool m_justReleased {false};
Read only flag indicating the object was released this frame (eg.
See: onReleased() Is object just released? Eg. was the button released this frame.
onReleased() with justReleased true was called) This flag becomes valid since the processInteractions() lifecycle step.
variable m_labelDiwne
std::string m_labelDiwne;
std::string m_labelDiwne;
Unique string identifier, consists of <some string>:<m_idDiwne>.
variable m_rect
ImRect m_rect;
ImRect m_rect;
Rectangle bounds of the object in diwne coordinates.
See: getRect()
variable m_styleOverride
StyleOverride * m_styleOverride {nullptr};
StyleOverride * m_styleOverride {nullptr};
Style override to allow uniquely styled object types.
Protected Attributes Documentation
variable g_diwneIDCounter
static unsigned long long g_diwneIDCounter = 1;
static unsigned long long g_diwneIDCounter = 1;
Static unique ID generator, unique only for current application run.
variable m_bringToFront
bool m_bringToFront {false};
bool m_bringToFront {false};
Request the object's rendering order to be moved to the front above other objects.
variable m_forceDraw
bool m_forceDraw {true};
bool m_forceDraw {true};
Request the next draw of the object to have the ForceDraw DrawMode flag.
variable m_internalHover
bool m_internalHover {false};
bool m_internalHover {false};
Temporary storage for an internal ImGui::IsItemHovered() check Can be set in the end() method to determine if object is hovered if applicable.
variable m_openPopup
bool m_openPopup {false};
bool m_openPopup {false};
Request to open popup.
variable m_openTooltip
bool m_openTooltip {false};
bool m_openTooltip {false};
Request to open tooltip.
variable m_parentObject
DiwneObject * m_parentObject {nullptr};
DiwneObject * m_parentObject {nullptr};
Sets the parent object of object, relevant in node container and hover hierarchy.
variable m_popupEnabled
bool m_popupEnabled {true};
bool m_popupEnabled {true};
Whether this object has popup enabled.
variable m_popupLabelDiwne
std::string m_popupLabelDiwne;
std::string m_popupLabelDiwne;
ImGui popup identifier.
variable m_rendered
bool m_rendered {true};
bool m_rendered {true};
Whether the object should be drawn, this is a general flag that overrides behavior of the allowDrawing() method.
variable m_selectable
bool m_selectable {true};
bool m_selectable {true};
Should not be accessed directly.
See: setSelectable()
variable m_selected
bool m_selected {false};
bool m_selected {false};
Should not be accessed directly.
See: setSelected()
variable m_tooltipEnabled
bool m_tooltipEnabled {false};
bool m_tooltipEnabled {false};
Whether this object has tooltip enabled.
variable m_tooltipText
std::string m_tooltipText;
std::string m_tooltipText;
Updated on 2025-05-31 at 12:55:31 +0000