DrawingTool
public protocol DrawingTool : AnyObject
All drawing tools must implement this protocol.
-
If
true, the shape-in-progress buffer is not cleared at all during drawing operations. So if you’re implementing something like a pen tool, you only need to draw the tail of the line that hasn’t yet been drawn, and avoid the cost of re-rendering the whole shape as it gets longer.Declaration
Swift
var isProgressive: Bool { get } -
Arbitrary string identifier. Useful for the demo UI, and potentially associating icons with each tool.
Declaration
Swift
var name: String { get } -
activate(shapeUpdater:Default implementationcontext: shape: ) The user has picked this tool in the UI. The default implementation does nothing.
Default Implementation
Declaration
Swift
func activate(shapeUpdater: DrawsanaViewShapeUpdating, context: ToolOperationContext, shape: Shape?)Parameters
shapeUpdaterAn object which you may inform of out-of-band shape updates. Normally,
DrawsanaViewonly checks for changes during tool operations, but some tools (e.g.TextTool) make changes based on arbitrary user input and need a way to update the selection rect and such.contextshapeTools may be activate with “initial shapes.” One use case for this is the selection tool handling a double-tap on a text shape. The UI can choose to activate the text tool and immediately enter the edit state.
-
deactivate(context:Default implementation) This tool has become deselected. The default implementation does nothing.
Default Implementation
Declaration
Swift
func deactivate(context: ToolOperationContext) -
User tapped on the drawing
Declaration
Swift
func handleTap(context: ToolOperationContext, point: CGPoint) -
User has started to drag on the drawing
Declaration
Swift
func handleDragStart(context: ToolOperationContext, point: CGPoint) -
User has continued to drag on the drawing
Declaration
Swift
func handleDragContinue(context: ToolOperationContext, point: CGPoint, velocity: CGPoint) -
User has stopped to drag on the drawing
Declaration
Swift
func handleDragEnd(context: ToolOperationContext, point: CGPoint) -
The drag gesture has canceled for some reason. The intended use case is for when the user places a second finger down, and this becomes a pinch instead of a drag.
You probably want to clean up all in-progress updates and reset to a state as if the drag had never begun.
Declaration
Swift
func handleDragCancel(context: ToolOperationContext, point: CGPoint) -
apply(context:Default implementationuserSettings: ) User settings have changed. Update any local state or the shape, if relevant. The default implementation does nothing.
Default Implementation
Declaration
Swift
func apply(context: ToolOperationContext, userSettings: UserSettings) -
renderShapeInProgress(transientContext:Default implementation) After each invocation of
handleDragStart(context:point:),handleDragContinue(context:point:velocity:), andhandleDragEnd(context:point:), this method is called. If your tool is in the process of creating a shape but it isn’t yet committed to the drawing, render it to thisCGContext.If
isProgressiveistrue, you only need to render changes since the last call. Otherwise, you need to render the whole shape.The default implementation does nothing.
Default Implementation
Declaration
Swift
func renderShapeInProgress(transientContext: CGContext)
View on GitHub
DrawingTool Protocol Reference