Canvas

FlexControlDrawablePanelContainerControlBindableWidgetWidgetReferences
public sealed class Canvas : FlexControl
Canvas control for hosting Grasshopper documents.

Constructors

Canvas

#
Create a new canvas control.
public Canvas()

Fields

ThumbnailHeight

#
The default height of document thumbnail images.
public const int ThumbnailHeight = 300

ThumbnailWidth

#
The default width of document thumbnail images.
public const int ThumbnailWidth = 500

Properties

AllowedActions

#
Access the set of allowed actions on a canvas. It is highly recommended to never change these settings on a canvas which you (the developer) did not create.
public CanvasActions AllowedActions { get; }

AllowPan

Gets whether this control supports mouse panning.
public bool AllowPan { get; set; }
inherited fromFlexControl
AllowPan

AllowScrollGesture

Gets or sets whether this control captures two-finger trackpad scroll and mouse-wheel events via its ScrollGesture. Set to false for FlexControls hosted in a Scrollable so the parent receives the scroll natively (native direction, momentum, rubber-band).
protected bool AllowScrollGesture { get; set; }
inherited fromFlexControl

AllowZoom

Gets whether this control supports mouse zooming.
public bool AllowZoom { get; set; }
inherited fromFlexControl
AllowZoom

AutoWindowSelect

Gets or sets whether a window selection automatically starts if a primary mousedown goes unhandled.
public bool AutoWindowSelect { get; set; }
inherited fromFlexControl

Border

Gets or sets the border drawn around this control.
public ControlBorder Border { get; set; }
inherited fromFlexControl
Border

ContentBounds

Gets or sets the bounding box of the content. Use an empty rectangle to indicate boundless content.
public RectangleF ContentBounds { get; set; }
inherited fromFlexControl
ContentBounds

ContentToControl

Gets the transformation matrix from content coordinates to control coordinates.
public IMatrix ContentToControl { get; }
inherited fromFlexControl
ContentToControl

ControlToContent

Gets the transformation matrix from control coordinates to content coordinates.
public IMatrix ControlToContent { get; }
inherited fromFlexControl
ControlToContent

CurrentlyDrawingCanvas

#
Gets the canvas which is currently drawing itself. Due to the non-concurrent nature of UI framework updates it's a fair bet that only one control at any given time is being drawn. However, if you need this property to make code work the way it was intended, it's an indication something has been poorly designed.
public static Canvas CurrentlyDrawingCanvas { get; }

CurrentWindowSelection

Gets the current window selection. This field will only be non-null during a window selection process. If you wish to respond to a completes window selection, handle the WindowSelection event.
public WindowSelection CurrentWindowSelection { get; }
inherited fromFlexControl

CursorEditActive

#
Gets the default cursor used for active edit mode.
public static Cursor CursorEditActive { get; }

CursorEditArmed

#
Gets the default cursor used for armed edit mode.
public static Cursor CursorEditArmed { get; }

CursorMode

#
Gets the current high-level cursor mode. Setting this property updates the displayed cursor as a side effect, ensuring the on-screen cursor always matches the logical state.
public CursorMode CursorMode { get; }

CursorQuestion

#
Gets the default question mark cursor used for component lookup.
public static Cursor CursorQuestion { get; }

CursorWireIn

#
Gets the default cursor used for input grips.
public static Cursor CursorWireIn { get; }

CursorWireOut

#
Gets the default cursor used for input grips.
public static Cursor CursorWireOut { get; }

Document

#
Gets or sets the document displayed in this canvas. This will never return null as a new document is created on an is-needed basis.
public Document Document { get; set; }

DrawContentBoundary

Gets or sets whether the content boundary ought to be drawn when visible.
public bool DrawContentBoundary { get; set; }
inherited fromFlexControl

DrawScrollbars

Gets whether this control should display scrollbars when needed. Scrollbars will only be displayed when the content exceeds the inner bounds. If AllowPan is set to False, then scrollbars will never be shown.
public bool DrawScrollbars { get; set; }
inherited fromFlexControl
DrawScrollbars

FloatingButtonRail

Gets the rail along which floating buttons are positioned. By default, the rail is equal to the inner bounds offset by the button size. Override this property to define a custom rail, for example if some regions near the control boundary need to remain free of buttons.
protected virtual RectangleF FloatingButtonRail { get; }
inherited fromFlexControl

FloatingButtons

Gets the floating button collection for this control.
public FloatingButtonCollection FloatingButtons { get; }
inherited fromFlexControl
FloatingButtons

FocusObject

Gets the object which currently has focus, if any. Focused objects are most likely either IInteractions or IResponsives.
public IResponsive FocusObject { get; }
inherited fromFlexControl
FocusObject

FullFrameDuration

#
public TimeSpan FullFrameDuration { get; }

GridDuration

#
public TimeSpan GridDuration { get; }

IconDuration

#
public TimeSpan IconDuration { get; }

InnerBounds

Gets the area in control coordinates for the content of the control. This area does not include the control border.
public RectangleF InnerBounds { get; }
inherited fromFlexControl
InnerBounds

InnerScreenBounds

Gets the inner bounds of this control in screen coordinates.
public RectangleF InnerScreenBounds { get; }
inherited fromFlexControl
InnerScreenBounds

InNestedNavigationMode

#
Gets whether this canvas is currently in nested navigation mode. That is, whether current modifiers are either SHIFT or CTRL+SHIFT.
public bool InNestedNavigationMode { get; }

IntegerOrigin

Gets or sets whether this control only allows integer accuracy coordinates for the origin point.
public bool IntegerOrigin { get; set; }
inherited fromFlexControl
IntegerOrigin

IsDragSource

Gets or sets whether this control is potentially a source for drag+drop operations.
public bool IsDragSource { get; set; }
inherited fromFlexControl
IsDragSource

IsDropTarget

Gets or sets whether this control is potentially a target for drag+drop operations.
public bool IsDropTarget { get; set; }
inherited fromFlexControl
IsDropTarget

LayoutDuration

#
public TimeSpan LayoutDuration { get; }

MaximumZoom

Gets or sets the maximum allowed zoom.
public float MaximumZoom { get; set; }
inherited fromFlexControl
MaximumZoom

MinimumZoom

Gets or sets the minimum allowed zoom.
public float MinimumZoom { get; set; }
inherited fromFlexControl
MinimumZoom

MouseDwellDelay

Gets or sets the duration required before a FlexControl.MouseDwell event is raised. Negative or zero length durations mean the FlexControl.MouseDwell event is never raised.
public TimeSpan MouseDwellDelay { get; set; }
inherited fromFlexControl

OuterBounds

Gets the bounds of this control in container coordinates.
public RectangleF OuterBounds { get; }
inherited fromFlexControl
OuterBounds

ParentControl

Gets or sets the parent control.
public IFlexControl ParentControl { get; set; }
inherited fromFlexControl
ParentControl

Projection

Gets or sets the projection for this control.
public Projection Projection { get; set; }
inherited fromFlexControl
Projection

RedrawOnMouseMove

#
Gets or sets whether the canvas needs to trigger a redraw on every mouse-move event. Note that this field is set to false on every redraw, so it must be assigned anew every time.
public bool RedrawOnMouseMove { get; set; }

ResizeBehaviour

Gets or sets the projection behaviour of the content during control resizing events.
public ContentResizeBehaviour ResizeBehaviour { get; set; }
inherited fromFlexControl
ResizeBehaviour

ResponsivesBackwards

Enumerate over all registered responsive objects in reverse order.
public IEnumerable<IResponsive> ResponsivesBackwards { get; }
inherited fromFlexControl

ResponsivesForwards

Enumerate over all registered responsive objects.
public IEnumerable<IResponsive> ResponsivesForwards { get; }
inherited fromFlexControl

ScreenBounds

Gets the bounds of this control in screen coordinates.
public RectangleF ScreenBounds { get; }
inherited fromFlexControl
ScreenBounds

ShapeDuration

#
public TimeSpan ShapeDuration { get; }

ShowTilesWhenEmpty

#
Gets whether or not tiles are shown when the canvas contains an empty document.
public bool ShowTilesWhenEmpty { get; set; }

ShowUndoHistory

#
Gets or sets whether the undo history browser ought to be displayed.
public bool ShowUndoHistory { get; set; }

Skin

#
Gets the skin to use in this canvas.
public Skin Skin { get; }

SkinDim

#
Gets or sets the dark mode skin.
public Skin SkinDim { get; set; }

SkinLit

#
Gets or sets the bright mode skin.
public Skin SkinLit { get; set; }

SnapXAction

#
Gets or sets the snapping action for the X-direction to draw.
public SnappingAction SnapXAction { get; set; }

SnapYAction

#
Gets or sets the snapping action for the Y-direction to draw.
public SnappingAction SnapYAction { get; set; }

TextDuration

#
public TimeSpan TextDuration { get; }

Tiles

#
Gets the tiles currently shown on the canvas.
public TileSet Tiles { get; }

ViewportDragging

#
Gets or sets whether draggable geometry can currently be dragged by directly clicking on it in the viewports. The state is mirrored into the loaded document, and restored from it whenever a different document is loaded.
public bool ViewportDragging { get; set; }

VisibleFrame

Gets the rectangle in content coordinates which represents the visible portion. This basically means the InnerBounds mapped into content coordinates.
public RectangleF VisibleFrame { get; }
inherited fromFlexControl
VisibleFrame

WindowSelectGroups

#
Gets or sets whether a window selection will include groups.
public bool WindowSelectGroups { get; set; }

WindowSelectObjects

#
Gets or sets whether a window selection will include objects.
public bool WindowSelectObjects { get; set; }

WindowSelectWires

#
Gets or sets whether a window selection will include wires.
public bool WindowSelectWires { get; set; }

WireDuration

#
public TimeSpan WireDuration { get; }

ZoomFeedbackLocation

Gets or sets the location for zoom change feedback.
public FeedbackLocation ZoomFeedbackLocation { get; set; }
inherited fromFlexControl

ZuiVariableParameterState

#
Gets the current state of the variable parameter ZUI based on recent zooming history.
public float ZuiVariableParameterState { get; }

ZuiVariableParameterThreshold

#
Gets or sets the zoom threshold at which variable parameter UI appears.
public float ZuiVariableParameterThreshold { get; set; }

ZuiWireDetailingState

#
Gets the current state of the wire detailing based on recent zooming history.
public float ZuiWireDetailingState { get; }

ZuiWireDetailingThreshold

#
Gets or sets the zoom threshold at which wires are drawn in full detail.
public float ZuiWireDetailingThreshold { get; set; }

Methods

AddSparkle

Add a sparkle to this control.
public void AddSparkle(
sparkle
Sparkle to add.
)
inherited fromFlexControl

Animate<T>

Evaluate an animator. This method automatically schedules redraw events if those are needed for smooth animations.
public T Animate<T>(
animated
Animator to evaluate.
)
inherited fromFlexControl
Animated value.
Animate

AnimatedZoomFactor

Gets the normalised factor (0.0, 1.0) which indicates to what extend the display is in the given state.
public float AnimatedZoomFactor(
threshold
Threshold.
)
inherited fromFlexControl
Normalised value.
AnimatedZoomFactor

BeginWindowSelect

Start a window selection process.
public void BeginWindowSelect()
inherited fromFlexControl
BeginWindowSelect

ComputeWrappingBounds

Determine the implied wrapping bounds given the control and the screen containing the location. The wrapping bounds are either the bounds of the screen containing the location, or the intersection of the screen containing the location and the bounds of the control if this intersection is not empty.
public RectangleF ComputeWrappingBounds(
PointF
location
Hint location in control coordinates.
)
inherited fromFlexControl
Wrapping bounds in control coordinates.

CreateFloatingButtons

Override this method to add a set of floating buttons to your control. It will automatically be called at the end of the constructor. You can always choose to add buttons later, but why not Zoidberg?
protected virtual void CreateFloatingButtons()
inherited fromFlexControl

DeleteSelection

#
Delete all selected objects in the current document.
public void DeleteSelection()

DispatchRotation

#
After the generic FlexControl dispatch returns Ignored, route the rotation gesture through a document hit-test so attributes on canvas objects can participate via their Responses. The hit-test runs once per gesture session and the result is cached, so the gesture stays on the original object even if its rotation moves it away from the cursor.
protected override Response DispatchRotation()

DrawPickMap

#
Draw the picking index map for the current canvas state.
public Bitmap DrawPickMap()

DrawToBitmap

#
Draw this canvas to a bitmap using the default thumbnail size.
public Bitmap DrawToBitmap()

DrawToBitmap

#
Draw this canvas to a bitmap. Content is drawn at its own coordinates from the top left corner, and only objects near the visible frame of this canvas take part.
public Bitmap DrawToBitmap(
width,
height,
drawBackground,
drawWires,
drawMessages
)

DrawToBitmap

#
Draw a region of this canvas to a bitmap.
public Bitmap DrawToBitmap(
RectangleF
region,
Region to draw, in content coordinates. The region is scaled to fit the bitmap without distorting it. An empty region draws content at its own coordinates from the top left corner, framed by whatever this canvas can see.
width,
Bitmap width in pixels.
height,
Bitmap height in pixels.
drawBackground,
True to fill the canvas background colour.
drawWires,
True to draw wires.
drawMessages
True to draw warning and error balloons.
)

DrawWindowSelectionEdge

If a window selection is currently in progress, draw the fill of that window selection fence. By calling this method you override the default window selection drawing pipeline, which allows you to have finer control over the layering of the window rectangle background and foreground.
public void DrawWindowSelectionEdge()
inherited fromFlexControl

DrawWindowSelectionEdge

If a window selection is currently in progress, draw the fill of that window selection fence. By calling this method you override the default window selection drawing pipeline, which allows you to have finer control over the layering of the window rectangle background and foreground.
public void DrawWindowSelectionEdge(
Pen
edge
Edge edge to use.
)
inherited fromFlexControl

DrawWindowSelectionFill

If a window selection is currently in progress, draw the fill of that window selection fence. By calling this method you override the default window selection drawing pipeline, which allows you to have finer control over the layering of the window rectangle background and foreground.
public void DrawWindowSelectionFill()
inherited fromFlexControl

DrawWindowSelectionFill

If a window selection is currently in progress, draw the fill of that window selection fence. By calling this method you override the default window selection drawing pipeline, which allows you to have finer control over the layering of the window rectangle background and foreground.
public void DrawWindowSelectionFill(
Brush
fill
Fill brush to use.
)
inherited fromFlexControl

EndWindowSelect

If, for any reason, you wish to terminate a window selection process prematurely, call this method.
public void EndWindowSelect()
inherited fromFlexControl
EndWindowSelect

FloatingButtonTooltipOverride

Override this method to provide a custom tooltip for floating buttons.
protected virtual bool FloatingButtonTooltipOverride(
button
Button for tooltip.
)
inherited fromFlexControl
True if the standard tooltip ought to be suppressed.

LooksLikeSingleClick

Test whether the given mouse event is compatible with a single-click-event given the most recent MouseDown event cache.
protected bool LooksLikeSingleClick(
MouseEventArgs
e
)
inherited fromFlexControl

Map

Map a point from one coordinate system to another.
public PointF Map(
PointF
point,
Point to map.
CoordinateSystem
from,
Coordinate system in which the point is currently defined.
CoordinateSystem
to
Target coordinate system.
)
inherited fromFlexControl
Mapped point.
Map

Map

Map a rectangle from one coordinate system to another.
public RectangleF Map(
RectangleF
rectangle,
Rectangle to map.
CoordinateSystem
from,
Coordinate system in which the rectangle is currently defined.
CoordinateSystem
to
Target coordinate system.
)
inherited fromFlexControl
Mapped rectangle.
Map

OnKeyDown

Key down handler.
protected override void OnKeyDown(
KeyEventArgs
e
)
inherited fromFlexControl
Control.OnKeyDown

OnKeyUp

Key up handler.
protected override void OnKeyUp(
KeyEventArgs
e
)
inherited fromFlexControl
Control.OnKeyUp

OnLoad

Raises the Load event, and recurses to this container's children
protected override void OnLoad(
e
Event arguments
)
inherited fromFlexControl
Container.OnLoad

OnLoadComplete

Raises the LoadComplete event, and recurses to this container's children
protected override void OnLoadComplete(
e
Event arguments
)
inherited fromFlexControl
Container.OnLoadComplete

OnMouseDoubleClick

Default mousedoubleclick handler for IControl. The default handling includes event delegation to the entire IInteraction stack.
protected sealed override void OnMouseDoubleClick(
MouseEventArgs
e
)
inherited fromFlexControl
Control.OnMouseDoubleClick

OnMouseDown

Default mousedown handler for IControl. The default handling includes event delegation to the entire IInteraction stack, as well as the creation of Pan and Zoom interactions if needed.
protected sealed override void OnMouseDown(
MouseEventArgs
e
)
inherited fromFlexControl
Control.OnMouseDown

OnMouseLeave

Default mouseleave handler for IControl. The default handling deals with the hover tracking mechanism.
protected sealed override void OnMouseLeave(
MouseEventArgs
e
)
inherited fromFlexControl
Control.OnMouseLeave

OnMouseMove

Default mousemove handler for IControl. The default handling includes event delegation to the entire IInteraction stack, as well as the updating of any active window selection and hover delay tracking.
protected sealed override void OnMouseMove(
MouseEventArgs
e
)
inherited fromFlexControl
Control.OnMouseMove

OnMouseUp

Default mouseup handler for IControl. The default handling includes event delegation to the entire IInteraction stack, as well as the terminating of any window selections and the popping of context menus. Furthermore, this method decides whether to provide a Click event for interaction objects.
protected sealed override void OnMouseUp(
MouseEventArgs
e
)
inherited fromFlexControl
Control.OnMouseUp

OnMouseWheel

Default mousewheel handler for IControl. The default handling includes event delegation to the entire IInteraction stack, as well as scroll zooming.
protected sealed override void OnMouseWheel(
MouseEventArgs
e
)
inherited fromFlexControl
Control.OnMouseWheel

OnPaint

Runs the drawing pipeline. Do not override this method unless you know *exactly* what you are doing. Handle the Draw(object, ControlDrawEventArgs) event instead.
protected override void OnPaint(
PaintEventArgs
e
)
inherited fromFlexControl
Drawable.OnPaint

OnPinchGesture

#
SHIFT + pinch relays the pinch into the nested navigation target under the cursor, driving its zoom. Any other modifier falls through to the base implementation, which zooms the canvas projection.
protected override void OnPinchGesture(
PointF
cursor,
magnification
)

OnPopulateContextMenu

Override this method to populate the context menu, or handle the PopulateContextMenu event. This method will automatically show the menu if it contains any items.
protected virtual bool OnPopulateContextMenu(
MouseEventArgs
e
Mouse event arguments associated with this menu popup.
)
inherited fromFlexControl
True if menu was shown.

OnScrollGesture

#
SHIFT + two-finger scroll relays the scroll into the nested navigation target under the cursor, driving its pan. Any other modifier falls through to the base implementation, which pans the canvas projection.
protected override void OnScrollGesture(
SizeF
motion
)

OnSizeChanged

Raises the SizeChanged event.
protected override void OnSizeChanged(
e
Event arguments
)
inherited fromFlexControl
Control.OnSizeChanged

OnTextInput

Text input handler.
protected override void OnTextInput(
TextInputEventArgs
e
)
inherited fromFlexControl
Control.OnTextInput

PopFocus

Pop a responsive object off the focus stack. It doesn't matter if it's at the head of the stack, but if it is, the new head will receive focus.
public void PopFocus(
responsive
)
inherited fromFlexControl

PushFocus

Push a new responsive object into the top of the focus stack. This does not register the object with this control.
public void PushFocus(
responsive
)
inherited fromFlexControl

RegisterIResponsive

Add a responsive object to this control's awareness. Responsive objects which have been properly registered will automatically have their response methods invoked in case of mouse/keyboard events on the control. The object will not be drawn though, that is the responsibility of the owner.
public void RegisterIResponsive(
responsive
Responsive to add.
)
inherited fromFlexControl

ResolvePick

#
Resolve the target of a pick operation on all the objects and wires in the document currently on display in this canvas.
public SelectionResult ResolvePick(
PointF
point,
Pick location.
includeGrips,
If true, parameter inlets and outlets will be considered.
includeForeground,
If true, objects drawn on top of wires will be considered.
includeBackground,
If true, objects drawn undernath wires will be considered. I.e. groups.
includeWires,
If true, wires drawn between the background and foreground objects will be considered.
recursive
If true, subobjects are considered inside top level objects.
)
Pick result.

ScheduleRedraw

Schedule a redraw in the near future. Redraw will happen as quickly as possible, though the message queue will be emptied first.
public void ScheduleRedraw()
inherited fromFlexControl
ScheduleRedraw

ScheduleRedraw

Schedule a redraw at a roughly defined delay.
public void ScheduleRedraw(
delay
Time until redraw after the current drawing operation completes.
)
inherited fromFlexControl
ScheduleRedraw

ShowInlineEditor

#
Show a single-line text editor anchored to a rectangle in canvas content (world) coordinates. The editor tracks the canvas projection so it remains anchored to the same content rectangle when the user pans or zooms while editing, with its font scaled to match the current zoom.

The apply callback is invoked on every change to the text and is responsible for applying the change to the underlying model. If IResult.Success is true the editor displays a neutral state. If IResult.Success is false the editor tints its background and exposes IResult.Error as a tooltip, but no other action is taken — the most recently applied valid state is retained.

The editor closes automatically when it loses focus, and when the user presses Enter or Tab. In all these cases the last successfully applied value is kept. When the user presses Escape the cancel callback is invoked first (so the caller can restore the original state) and the editor then closes. The cancel callback is only invoked on Escape.

Only one inline editor can be active at a time; calling this method while another editor is open closes the existing one (without invoking its cancel) before opening the new one.

public void ShowInlineEditor(
RectangleF
frame,
Anchor rectangle in canvas content coordinates.
initial,
Initial text shown in the editor. The contents are pre-selected so the user can immediately overtype.
apply,
Called on every text change. The caller applies the parsed value when the result is successful. Must not be null.
cancel = null
Optional callback invoked only when the user presses Escape, to allow the caller to revert their model to the original state.
)

ShowInstantiationPopup

#
Show the object instantiation window.
public void ShowInstantiationPopup(
mouseCentred,
initialText = null
)

ShowSearchPopup

#
Show the search window.
public void ShowSearchPopup()

UnregisterIResponsive

Remove a responsive object from this control's awareness.
public void UnregisterIResponsive(
responsive
)
inherited fromFlexControl

UpdateMapping

Update the mapping matrices. You *must* call this method whenever you change something that might affect the positioning of the content. For example origin, zoom, bounds...
protected void UpdateMapping()
inherited fromFlexControl

Events

AfterPaintBackground

#
Raised after the default background grid has been drawn.
public event EventHandler<CanvasPaintEventArgs> AfterPaintBackground

AfterPaintGroups

#
Raised after the groups have been drawn.
public event EventHandler<CanvasPaintEventArgs> AfterPaintGroups

AfterPaintObjects

#
Raised after the objects have been drawn.
public event EventHandler<CanvasPaintEventArgs> AfterPaintObjects

AfterPaintWires

#
Raised after the wires have been drawn.
public event EventHandler<CanvasPaintEventArgs> AfterPaintWires

BeforePaintBackground

#
Raised before the default background grid is drawn. It is possible to override the default background painting by handling this event.
public event EventHandler<CanvasBackgroundPaintEventArgs> BeforePaintBackground

BeforePaintGroups

#
Raised before the groups are drawn.
public event EventHandler<CanvasPaintEventArgs> BeforePaintGroups

BeforePaintObjects

#
Raised before the objects are drawn.
public event EventHandler<CanvasPaintEventArgs> BeforePaintObjects

BeforePaintWires

#
Raised before the wires are drawn.
public event EventHandler<CanvasPaintEventArgs> BeforePaintWires

DocumentChanged

#
Raised whenever a different document is loaded in this canvas.
public event EventHandler DocumentChanged

DocumentModified

#
Raised whenever the document loaded in this canvas changes its Document.Modified property.
public event EventHandler DocumentModified

Draw

This event is raised whenever the control paints itself.
inherited fromFlexControl
Draw

MouseDwell

Raised when the mouse dwells over some pixel without moving for a while.
public event EventHandler<MouseDwellEventArgs> MouseDwell
inherited fromFlexControl

PopulateContextMenu

Raised whenever the context menu ought to be populated.
public event EventHandler<PopulateContextMenuEventArgs> PopulateContextMenu
inherited fromFlexControl

ProjectionChanged

Raised whenever the projection of a control changes.
public event EventHandler<ProjectionChangedEventArgs> ProjectionChanged
inherited fromFlexControl
ProjectionChanged

WindowSelection

Raised whenever a window selection completes.
public event EventHandler<WindowSelectionEventArgs> WindowSelection
inherited fromFlexControl
WindowSelection