Skip to main content

Overview

The Canvas class represents a Pure Data patch’s visual canvas. It manages object creation, connections, selection, viewport, and rendering. Each canvas corresponds to one Pure Data patch (pd::Patch) and provides the interactive editing environment. Location: Source/Canvas.h and Source/Canvas.cpp

Class Hierarchy

Constructor

PluginEditor*
The plugin editor that owns this canvas.
pd::Patch::Ptr
The Pure Data patch this canvas represents.
Component*
default:"nullptr"
Optional parent graph component (for graph-on-parent subpatches).

Key Properties

PluginEditor*
Parent plugin editor.
PluginProcessor*
Reference to the plugin processor/Pure Data instance.
pd::Patch&
The underlying Pure Data patch.
std::unique_ptr<CanvasViewport>
Viewport for scrolling and zooming the canvas.
PooledPtrArray<Object>
All objects on this canvas.
PooledPtrArray<Connection>
All patch connections on this canvas.
SelectedItemSet<WeakReference<Component>>
Currently selected objects and connections.
Value
Whether the canvas is in locked (run) mode vs edit mode.
Value
Whether the canvas is in presentation mode (showing only GUI objects).
Value
Current zoom level (1.0 = 100%).

Object Management

void
Synchronize the visual canvas with the underlying Pure Data patch structure. Called after patch modifications to update the GUI.
void
Update all drawable components on the canvas.

Selection and Editing

void
Select or deselect a component on the canvas.
void
Clear all selections.
SmallArray<T*>
Get all selected components of a specific type.Example:

Clipboard Operations

void
Copy selected objects to clipboard.
void
Paste objects from clipboard.
void
Duplicate selected objects in place.
void
Delete selected objects or connections.
void
Paste objects at a specific position (used for drag-and-drop).

Advanced Editing

void
Wrap selected objects in a subpatch.
void
Auto-arrange selected objects neatly.
void
Align selected objects (left, right, top, bottom, center).
void
Auto-connect selected objects where possible.

Undo/Redo

void
Undo or redo the last action on this canvas.

Viewport and Navigation

void
Zoom to fit all objects in the viewport.
void
Reset viewport to origin (0, 0).
void
Save and restore viewport position and zoom.

Rendering

void
Render the canvas using NanoVG. Called automatically by the rendering system.

Overlays and Display Options

bool
Query current overlay display settings.

File Operations

void
Save the patch to disk. Optionally provide a callback to execute after save completes.

Message Handling

void
Receive messages from Pure Data (implements pd::MessageListener).

Suggestions and Autocomplete

void
Show or hide object name suggestions while typing.

Inspector Integration

ObjectParameters&
Get parameters for the inspector panel.

Constants

static constexpr int
Maximum canvas size: 128,000 pixels

Usage Example

See Also

  • Object - Individual patch objects
  • Connection - Patch cord connections
  • PluginEditor - Editor window
  • pd::Patch - Underlying Pure Data patch
  • CanvasViewport - Viewport and scrolling