Class ResizingTool

GoDiagram®
v10.0.12
by Northwoods Software®

The ResizingTool is used to interactively change the size of a GraphObject in the selected Part or Node by setting its DesiredSize property. You may want to save the size to the model by using a TwoWay Binding on the "DesiredSize" property of the GraphObject that is named by ResizeElementName. This tool does not operate on Links.

Namespace: Northwoods.Go.Tools
Assembly: Northwoods.GoDiagram.Avalonia.dll
Syntax
public class ResizingTool : Tool
Remarks

You can limit the permitted minimum and maximum dimensions by setting MinSize and MaxSize. The resizing will also respect the MinSize and MaxSize properties. Width or height values that are NaN do not constrain the resizing. Override ComputeMinSize() and/or ComputeMaxSize() to change this behavior.

You can also limit the width and/or height to be multiples of a particular size by setting ResizeCellSize. If either or both of these values are NaN, as they are by default, it will get the values from this tool's CellSize. Finally it will consider the Grid's GridCellSize if IsGridSnapEnabled is true. Override ComputeCellSize() to change this behavior.

Pressing the Shift key or resizing a Shape with a GeometryStretch of Uniform will maintain the aspect ratio during the resize. Override ComputeReshape() to change this behavior.

This tool makes use of an Adornment, shown when the Part or Node is selected, that includes some double of resize handles. The resize handles are normally copies of HandleArchetype, unless you specify a custom resize Adornment by setting ResizeAdornmentTemplate. The resize Adornment is normally a "Spot" Panel with eight resize handles, each with Alignment set to one of the eight standard Spot values -- the four corners and the four side middles. The Alignment is what identifies and distinguishes each of the handles and the behavior when the user drags the handle.

This tool conducts a transaction while the tool is active. A successful resizing will result in a "PartResized" DiagramEvent and a "Resizing" transaction.

For a general discussion of the sizing of objects, see: Introduction to the sizing of GraphObjects. For customizing the ResizingTool, see Introduction to the ResizingTool.

If you want to programmatically start a user's resizing of the ResizeElement of an existing selected node, you can set the Handle property to the specific resize handle and then start and activate the tool.

var node = ...;
myDiagram.Select(node);
var adorn = node.FindAdornment("Resizing");
var tool = myDiagram.ToolManager.ResizingTool;
// specify which resize handle of the "Resizing" Adornment of the selected node
tool.Handle = adorn.Elt(...);
myDiagram.CurrentTool = tool;  // starts the ResizingTool
tool.DoActivate();             // activates the ResizingTool

Constructors

ResizingTool()

You do not normally need to create an instance of this tool because one already exists as the ResizingTool, which you can modify.

The Name of this tool is "Resizing".

Declaration
public ResizingTool()

Properties

AdornedElement

Gets the GraphObject that is being resized.

Declaration
public GraphObject AdornedElement { get; set; }
Property Value
Type Description
GraphObject
Remarks

This may be the same element as the selected Part or it may be contained within that Part.

This property is also settable, but should only be set when overriding functions in ResizingTool, and not during normal operation.

CellSize

Gets or sets the width and height multiples with which the user must resize.

Declaration
public Size CellSize { get; set; }
Property Value
Type Description
Size
Remarks

The effective cell size is computed by first looking at the AdornedPart's ResizeCellSize. If either or both of its width and height are NaN, it will use this property, CellSize. If either or both of this property's width and height are NaN, it will consider the Grid's GridCellSize.

The default value is Size(NaN, NaN). Setting this property does not raise any events.

DragsMembers

Gets or sets whether the ResizingTool moves the member Parts of a Group that has no Placeholder.

Declaration
public bool DragsMembers { get; set; }
Property Value
Type Description
bool
Remarks

By default this property is false. Setting this property does not raise any events.

Handle

Returns the GraphObject that is the tool handle being dragged by the user.

Declaration
public GraphObject Handle { get; set; }
Property Value
Type Description
GraphObject
Remarks

This will be contained by an Adornment whose category is "ResizingTool". Its AdornedElement is the same as the AdornedElement. This is normally set by DoActivate(), remembering the result of the call to FindToolHandleAt(Point, string).

This property is also settable, but should only be set either within an override of DoActivate() or prior to calling DoActivate().

HandleArchetype

Gets or sets a small GraphObject that is copied as a resizing handle for the selected part.

Declaration
public GraphObject HandleArchetype { get; set; }
Property Value
Type Description
GraphObject
Remarks

By default this is a Shape that is a small blue rectangle. Setting this property does not raise any events.

Here is an example of changing the default handle to be larger yellow circles:

myDiagram.ToolManager.ResizingTool.HandleArchetype =
  new Shape("Circle") { Width = 10, Height = 10, Fill = "yellow" };

This property is ignored when a custom resizing Adornment is specified as the ResizeAdornmentTemplate. That property is normally null, in which case this tool will automatically construct Adornments holding eight copies of this handle archetype, each with a Alignment being one of the standard eight Spots.

IsGridSnapEnabled

Gets or sets whether the ResizingTool snaps object sizes to the diagram's background grid during the resize.

Declaration
public bool IsGridSnapEnabled { get; set; }
Property Value
Type Description
bool
Remarks

By default this property is false. Setting this property does not raise any events.

MaxSize

Gets or sets the maximum size to which the user can resize.

Declaration
public Size MaxSize { get; set; }
Property Value
Type Description
Size
Remarks

The effective maximum size is the minimum of this value and the MaxSize, independently in each direction.

The default value is Size(9999, 9999). Any new value must be of type Size; NaN width or height values are treated as double.PositiveInfinity. Setting this property does not raise any events.

MinSize

Gets or sets the minimum size to which the user can resize.

Declaration
public Size MinSize { get; set; }
Property Value
Type Description
Size
Remarks

The effective minimum size is the maximum of this value and the MinSize, independently in each direction.

The default value is Size(1, 1). Any new value must be of type Size; NaN width or height values are treated as zero. Setting this property does not raise any events.

OppositePoint

Gets or sets the Point opposite to the chosen, dragged handle of the "Resizing" Adornment.

Declaration
public Point OppositePoint { get; set; }
Property Value
Type Description
Point
Remarks

This property has no meaning until after DoActivate() has been called.

OriginalDesiredSize

This read-only property returns the Size that was the original value of the DesiredSize of the element that is being resized.

Declaration
public Size OriginalDesiredSize { get; }
Property Value
Type Description
Size

OriginalLocation

This read-only property returns the Point that was the original value of the Location of the Part that is being resized.

Declaration
public Point OriginalLocation { get; }
Property Value
Type Description
Point

Methods

CanStart()

This tool may run when there is a mouse-down event on a resize handle, the diagram is not read-only and it allows resizing, the left mouse button is being used, and this tool's adornment's resize handle is at the current mouse point.

Declaration
public override bool CanStart()
Returns
Type Description
bool
Overrides
Remarks

This method may be overridden. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

ComputeCellSize()

The size should be a multiple of the value returned by this method.

Declaration
public virtual Size ComputeCellSize()
Returns
Type Description
Size
Remarks

This is called once when the tool is activated.

This method may be overridden. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

ComputeMaxSize()

The effective maximum resizing size is the minimum of the MaxSize and the AdornedElement's MaxSize.

Declaration
public virtual Size ComputeMaxSize()
Returns
Type Description
Size
Remarks

This is called once when the tool is activated.

This method may be overridden. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

ComputeMinSize()

The effective minimum resizing size is the maximum of MinSize and the AdornedElement's MinSize.

Declaration
public virtual Size ComputeMinSize()
Returns
Type Description
Size
Remarks

This is called once when the tool is activated.

This method may be overridden. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

ComputeReshape()

Decide whether to allow arbitrary reshaping or whether to keep the same aspect ratio of the object being resized.

Declaration
public virtual bool ComputeReshape()
Returns
Type Description
bool

true to allow any aspect ratio; false to preserve the AdornedElement's height/width ratio

Remarks

If the AdornedElement is a Shape, then if the GeometryStretch is Uniform, this method will return false to restrict reshaping to maintain the object's current ratio of height to width. Also, if the user is holding down the Shift key, this method will return false.

This is called on each mouse-move and on mouse-up; the result is passed to the call to Resize(Rect). This permits the user to change the behavior dynamically during resizing.

This method may be overridden. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

For example, to always keep the object's original aspect ratio, override this method to return false. When overriding the method dynamically:

public class MyResizingTool : ResizingTool {
  public override bool ComputeReshape() => false;
}

Your override might want to look at the this.AdornedElement.Part.Data properties to decide whether to allow reshaping.

ComputeResize(Point, Spot, Size, Size, Size, bool)

Given a Spot in the original bounds of the object being resized and a new Point, compute the new Rect.

Declaration
public virtual Rect ComputeResize(Point newPoint, Spot spot, Size min, Size max, Size cell, bool reshape)
Parameters
Type Name Description
Point newPoint

a Point in local coordinates.

Spot spot

the alignment spot of the handle being dragged.

Size min

the result of the call to ComputeMinSize().

Size max

the result of the call to ComputeMaxSize().

Size cell

the result of the call to ComputeCellSize().

bool reshape

true if the new size may change the aspect ratio from that of the natural bounds of the AdornedElement.

Returns
Type Description
Rect

a Rectangle in the AdornedElement's local coordinates, not in document coordinates

Remarks

This method may be overridden. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

DoActivate()

Find the Handle, remember the object's original bounds, save the results of calling ComputeMinSize(), ComputeMaxSize(), and ComputeCellSize(), capture the mouse, and start a transaction.

Declaration
public override void DoActivate()
Overrides
Remarks

Normally when this method is called the value of Handle will be null, resulting in a call to FindToolHandleAt(Point, string) to find a "Resizing" tool handle, which is then remembered as the value of Handle. If when this method is called the value of Handle is already set, then there is no need to call FindToolHandleAt(Point, string), because the programmer has already set up which resize handle they want the user to be resizing.

DoCancel()

Restore the original size of the GraphObject.

Declaration
public override void DoCancel()
Overrides

DoDeactivate()

Stop the current transaction, forget the Handle and AdornedElement, and release the mouse.

Declaration
public override void DoDeactivate()
Overrides

DoMouseMove()

Call Resize(Rect) with a new size determined by the current mouse point.

Declaration
public override void DoMouseMove()
Overrides
Remarks

This determines the new bounds by calling ComputeResize(Point, Spot, Size, Size, Size, bool).

When this calls ComputeResize(Point, Spot, Size, Size, Size, bool) it passes as the reshape argument the result of calling ComputeReshape(). The min, max, and cell arguments will be the saved results of DoActivate()'s calls to ComputeMinSize(), ComputeMaxSize(), and ComputeCellSize().

DoMouseUp()

Call Resize(Rect) with the final bounds based on the most recent mouse point, commit the transaction, and raise the "PartResized" DiagramEvent.

Declaration
public override void DoMouseUp()
Overrides
Remarks

This determines the new bounds by calling ComputeResize(Point, Spot, Size, Size, Size, bool).

When this calls ComputeResize(Point, Spot, Size, Size, Size, bool) it passes as the reshape argument the result of calling ComputeReshape().

Resize(Rect)

Change the size of the selected part's ResizeElement to have the given bounds.

Declaration
public virtual void Resize(Rect newr)
Parameters
Type Name Description
Rect newr

a Rectangle in the AdornedElement's local coordinates, not in document coordinates

Remarks

This modifies its DesiredSize and maybe its Location.

This method may be overridden. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

StopTransaction()

This calls the base StopTransaction() method, and if the result is true, attempts to optimize the transaction by removing all changes except the first and last by calling Optimize().

Declaration
public override bool StopTransaction()
Returns
Type Description
bool

the result of the call to rollback or commit the transaction.

Overrides
Remarks

This method may be overridden. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

UpdateAdornments(Part)

Show an Adornment with the resize handles at points along the edge of the bounds of the selected Part's ResizeElement.

Declaration
public override void UpdateAdornments(Part part)
Parameters
Type Name Description
Part part
Overrides
Remarks

First this finds the object in the visual tree of the Part that should get the resize adornment and that the user will be able to resize interactively. It finds the object that has the ResizeElementName property of the Part. If the ResizeElementName property is an empty string, as it is by default, it uses the whole part.

It then builds the adornment, associating it with the chosen resize object. If ResizeAdornmentTemplate is non-null, it is copied. Otherwise it constructs a new Adornment with a Placeholder and eight copies of HandleArchetype, four at the corners and four at the middle of each side.

This method may be overridden. Please read the Introduction page on Extensions for how to override methods and how to call this base method.