DIWNE::Link
#include "DIWNE/Core/Elements/Link.h"
Inherits from DIWNE::DiwneObject, std::enable_shared_from_this< DiwneObject >
Inherited by Workspace::CoreLink
Public Functions
Name | |
---|---|
Link(NodeEditor & diwne, std::string labelDiwne ="DiwneLink") | |
virtual bool | allowDrawing() override<br>Decide whether the object should be drawn (when outside the window for example) |
virtual void | begin(DrawInfo & context) override<br>Link isn't an ImGui item, nothing to begin. |
virtual bool | connect(Pin * startPin, Pin * endPin, bool logEvent =true)<br>Connect the two pins using this link. |
virtual void | content(DrawInfo & context) override<br>Called after begin() during drawing. |
virtual bool | disconnect(bool logEvent =true)<br>Disconnect all pins. |
virtual bool | disconnectPin(bool startOrEndPin, bool logEvent =true)<br>Disconnect one of the pins. |
virtual bool | disconnectPin(Pin * pin, bool logEvent =true) |
virtual void | end(DrawInfo & context) override<br>No need to set m_internalHover as we handle hovering ourself. |
Pin * | getAnyPin() const<br>Get any of the two pins or nullptr if neither are connected. |
ImVec2 | getEndControlPoint() const |
Pin * | getEndPin() const |
ImVec2 | getEndPoint() const |
Pin * | getOtherPin(Pin * pin) const<br>Get the other pin that this link connects with the specified pin. |
Pin * | getSinglePin() const<br>Get the pin on either end in cases when only one pin is plugged in. |
ImVec2 | getStartControlPoint() const |
Pin * | getStartPin() const |
ImVec2 | getStartPoint() const |
virtual void | initialize(DrawInfo & context) override<br>First method to be called every frame. |
bool | isLinkOnWorkArea() const |
bool | isOnePinPlugged() const<br>Whether the link has exactly one pin plugged in at either end. |
bool | isPlugged() const<br>Whether the link is connected on both ends. |
virtual void | onDestroy(bool logEvent) override<br>Gets called the moment the object is marked for deletion by destroy(). |
virtual void | onHover(DrawInfo & context) override<br>This method gets called when the object is hovered. |
void | setEndPin(Pin * pin) |
void | setEndPoint(const ImVec2 & mEndDiwne) |
void | setStartPin(Pin * pin) |
void | setStartPoint(const ImVec2 & mStartDiwne) |
virtual void | updateLayout(DrawInfo & context) override<br>Updates object's m_rect, m_displayRect and any other object size variables. |
Protected Functions
Name | |
---|---|
virtual ImRect | getBounds()<br>Get the rect formed by the starting and ending point, as well as any curve control points. |
virtual void | initializeDiwne(DrawInfo & context) override |
virtual bool | isHoveredDiwne() override<br>Link isn't represented by an ImGui item so we need to detect hovering manually. |
virtual void | setInitialPositionDiwne() override<br>Internal helper for setting the object's initial position. |
virtual void | updateControlPoints() |
virtual void | updateEndpoints() |
void | updateSquareDistanceMouseFromLink() |
Public Attributes
Name | |
---|---|
bool | m_previewPlugged <br>Style the link as if it was plugged in. |
Protected Attributes
Name | |
---|---|
ImVec4 | m_color |
ImVec2 | m_controlPointEndDiwne |
ImVec2 | m_controlPointStartDiwne |
ImVec2 | m_endDiwne |
Pin * | m_endPin |
float | m_squaredDistanceMouseFromLink |
ImVec2 | m_startDiwne |
Pin * | m_startPin |
float | m_widthOffset |
Additional inherited members
Public Functions inherited from DIWNE::DiwneObject
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 | 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 | 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 | 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 |
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 | onDrag(DrawInfo & context, bool dragStart, bool dragEnd)<br>This method gets called when the object is being dragged. |
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. |
Protected Functions inherited from DIWNE::DiwneObject
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 bool | isDraggedDiwne()<br>Is the object being dragged? (usually by mouse or some key combo) |
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. |
void | setSize(const ImVec2 & size) |
void | updateRectFromImGuiItem() |
Public Attributes inherited from DIWNE::DiwneObject
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 inherited from DIWNE::DiwneObject
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 Link
Link(
NodeEditor & diwne,
std::string labelDiwne ="DiwneLink"
)
Link(
NodeEditor & diwne,
std::string labelDiwne ="DiwneLink"
)
function allowDrawing
virtual bool allowDrawing() override
virtual bool allowDrawing() override
Decide whether the object should be drawn (when outside the window for example)
Reimplements: DIWNE::DiwneObject::allowDrawing
function begin
inline virtual void begin(
DrawInfo & context
) override
inline virtual void begin(
DrawInfo & context
) override
Link isn't an ImGui item, nothing to begin.
Reimplements: DIWNE::DiwneObject::begin
function connect
virtual bool connect(
Pin * startPin,
Pin * endPin,
bool logEvent =true
)
virtual bool connect(
Pin * startPin,
Pin * endPin,
bool logEvent =true
)
Connect the two pins using this link.
Parameters:
- startPin
- endPin
- logEvent The boolean flag passed to onPlug() on successful connect
Return: True when the link was already registered with one of the pins
On success this method calls onPlug() on both pins. If the link has different pins plugged in already, the corresponding pins get unplugged.
function content
virtual void content(
DrawInfo & context
) override
virtual void content(
DrawInfo & context
) override
Called after begin() during drawing.
Reimplements: DIWNE::DiwneObject::content
Draws object content.
function disconnect
virtual bool disconnect(
bool logEvent =true
)
virtual bool disconnect(
bool logEvent =true
)
Disconnect all pins.
Parameters:
- logEvent The boolean flag passed to onPlug() on successful connect
Return: True on success, false otherwise (if it wasn't connected)
On success this method calls onUnplug() on both pins.
function disconnectPin
virtual bool disconnectPin(
bool startOrEndPin,
bool logEvent =true
)
virtual bool disconnectPin(
bool startOrEndPin,
bool logEvent =true
)
Disconnect one of the pins.
Parameters:
- startOrEndPin Whether to disconnect the start or end pin.
- logEvent The boolean flag passed to onPlug() on successful connect.
Return: True on success, false otherwise (if it wasn't connected)
On success this method calls onUnplug() on the disconnected pin.
function disconnectPin
virtual bool disconnectPin(
Pin * pin,
bool logEvent =true
)
virtual bool disconnectPin(
Pin * pin,
bool logEvent =true
)
function end
virtual void end(
DrawInfo & context
) override
virtual void end(
DrawInfo & context
) override
No need to set m_internalHover as we handle hovering ourself.
Reimplements: DIWNE::DiwneObject::end
function getAnyPin
Pin * getAnyPin() const
Pin * getAnyPin() const
Get any of the two pins or nullptr if neither are connected.
function getEndControlPoint
inline ImVec2 getEndControlPoint() const
inline ImVec2 getEndControlPoint() const
function getEndPin
inline Pin * getEndPin() const
inline Pin * getEndPin() const
function getEndPoint
inline ImVec2 getEndPoint() const
inline ImVec2 getEndPoint() const
function getOtherPin
Pin * getOtherPin(
Pin * pin
) const
Pin * getOtherPin(
Pin * pin
) const
Get the other pin that this link connects with the specified pin.
Assumes the link is connected on both ends Returns nullptr when neither of the two pins are the passed one.
function getSinglePin
Pin * getSinglePin() const
Pin * getSinglePin() const
Get the pin on either end in cases when only one pin is plugged in.
Returns nullptr no pins are connected or if both ends are connected.
function getStartControlPoint
inline ImVec2 getStartControlPoint() const
inline ImVec2 getStartControlPoint() const
function getStartPin
inline Pin * getStartPin() const
inline Pin * getStartPin() const
function getStartPoint
inline ImVec2 getStartPoint() const
inline ImVec2 getStartPoint() const
function initialize
virtual void initialize(
DrawInfo & context
) override
virtual void initialize(
DrawInfo & context
) override
First method to be called every frame.
Reimplements: DIWNE::DiwneObject::initialize
Does not handle drawing.
function isLinkOnWorkArea
bool isLinkOnWorkArea() const
bool isLinkOnWorkArea() const
in fact just rectangle (from startPoint to endPoint) check - so could return true while Link is not visible
function isOnePinPlugged
bool isOnePinPlugged() const
bool isOnePinPlugged() const
Whether the link has exactly one pin plugged in at either end.
function isPlugged
bool isPlugged() const
bool isPlugged() const
Whether the link is connected on both ends.
function onDestroy
virtual void onDestroy(
bool logEvent
) override
virtual void onDestroy(
bool logEvent
) override
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().
Reimplements: DIWNE::DiwneObject::onDestroy
It is called only once per object.
function onHover
virtual void onHover(
DrawInfo & context
) override
virtual void onHover(
DrawInfo & context
) override
This method gets called when the object is hovered.
Parameters:
- context
See: processHoverDiwne()
Reimplements: DIWNE::DiwneObject::onHover
This generally indicates mouse hover, but the behavior can be changed via isHoveredDiwne().
function setEndPin
inline void setEndPin(
Pin * pin
)
inline void setEndPin(
Pin * pin
)
function setEndPoint
void setEndPoint(
const ImVec2 & mEndDiwne
)
void setEndPoint(
const ImVec2 & mEndDiwne
)
function setStartPin
inline void setStartPin(
Pin * pin
)
inline void setStartPin(
Pin * pin
)
function setStartPoint
void setStartPoint(
const ImVec2 & mStartDiwne
)
void setStartPoint(
const ImVec2 & mStartDiwne
)
function updateLayout
virtual void updateLayout(
DrawInfo & context
) override
virtual void updateLayout(
DrawInfo & context
) override
Updates object's m_rect, m_displayRect and any other object size variables.
See: m_rect, m_displayRect
Reimplements: DIWNE::DiwneObject::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 getBounds
virtual ImRect getBounds()
virtual ImRect getBounds()
Get the rect formed by the starting and ending point, as well as any curve control points.
This method is used in updateLayout() to update the object's rect as well as in allowDrawing().
function initializeDiwne
virtual void initializeDiwne(
DrawInfo & context
) override
virtual void initializeDiwne(
DrawInfo & context
) override
Reimplements: DIWNE::DiwneObject::initializeDiwne
function isHoveredDiwne
virtual bool isHoveredDiwne() override
virtual bool isHoveredDiwne() override
Link isn't represented by an ImGui item so we need to detect hovering manually.
Reimplements: DIWNE::DiwneObject::isHoveredDiwne
function setInitialPositionDiwne
virtual void setInitialPositionDiwne() override
virtual void setInitialPositionDiwne() override
Internal helper for setting the object's initial position.
Reimplements: DIWNE::DiwneObject::setInitialPositionDiwne
function updateControlPoints
virtual void updateControlPoints()
virtual void updateControlPoints()
Reimplemented by: Workspace::CoreLink::updateControlPoints
function updateEndpoints
virtual void updateEndpoints()
virtual void updateEndpoints()
function updateSquareDistanceMouseFromLink
void updateSquareDistanceMouseFromLink()
void updateSquareDistanceMouseFromLink()
Public Attributes Documentation
variable m_previewPlugged
bool m_previewPlugged {false};
bool m_previewPlugged {false};
Style the link as if it was plugged in.
Protected Attributes Documentation
variable m_color
ImVec4 m_color;
ImVec4 m_color;
variable m_controlPointEndDiwne
ImVec2 m_controlPointEndDiwne;
ImVec2 m_controlPointEndDiwne;
variable m_controlPointStartDiwne
ImVec2 m_controlPointStartDiwne;
ImVec2 m_controlPointStartDiwne;
variable m_endDiwne
ImVec2 m_endDiwne;
ImVec2 m_endDiwne;
variable m_endPin
Pin * m_endPin {nullptr};
Pin * m_endPin {nullptr};
variable m_squaredDistanceMouseFromLink
float m_squaredDistanceMouseFromLink {std::numeric_limits<float>::max()};
float m_squaredDistanceMouseFromLink {std::numeric_limits<float>::max()};
variable m_startDiwne
ImVec2 m_startDiwne;
ImVec2 m_startDiwne;
variable m_startPin
Pin * m_startPin {nullptr};
Pin * m_startPin {nullptr};
variable m_widthOffset
float m_widthOffset {0.f};
float m_widthOffset {0.f};
Updated on 2025-05-31 at 12:55:31 +0000