DrawKit
Vector and illustration framework for Mac OS X
Instance Methods | Class Methods | List of all members
DKDrawingTool Class Reference

DKDrawingTool is the semi-abstract base class for all types of drawing tool. More...

Inheritance diagram for DKDrawingTool:
Inheritance graph
[legend]

Instance Methods

(void) - drawRect:inView:
 
(void) - flagsChanged:inLayer:
 
(BOOL- isSelectionTool
 Return whether the tool is some sort of object selection tool. More...
 
(BOOL- isValidTargetLayer:
 
(NSString *) - keyboardEquivalent
 
(NSUInteger- keyboardModifierFlags
 
(void) - mouseMoved:inView:
 
(NSData *) - persistentData
 
(NSString *) - registeredName
 Return the registry name for this tool. More...
 
(void) - set
 Sets the tool as the current tool for the key view in the main window, if possible. More...
 
(void) - setCursorForPoint:targetObject:inLayer:event:
 
(void) - setKeyboardEquivalent:modifierFlags:
 
(void) - shouldLoadPersistentData:
 
(void) - toolControllerDidSetTool:
 Called when this tool is set by a tool controller. More...
 
(void) - toolControllerDidUnsetTool:
 Called when this tool is unset by a tool controller. More...
 
(void) - toolControllerWillUnsetTool:
 Called when this tool is about to be unset by a tool controller. More...
 
- Instance Methods inherited from NSObject
(NSString *) - address
 
(DKStyleRegistry *) - applicationWillReturnStyleRegistry
 
(BOOL- canBeUsedWithSelectionTool
 
(id- categoryManager:shouldReplaceObject:withObject:
 
(Class- classForCoder
 
(NSColor *) - colorValue
 
(NSColor *) - colourValue
 
(id- copy
 
(void) - dealloc
 
(id- deepCopy
 
(NSDictionary *) - dimensionValuesForArrowStroke:
 
(CGFloat- drawing:convertDistanceToExternalCoordinates:
 
(NSPoint) - drawing:convertLocationToExternalCoordinates:
 
(void) - drawing:didDrawRect:inView:
 
(void) - drawing:willDrawRect:inView:
 
(NSString *) - drawing:willReturnAbbreviationForUnit:
 
(NSString *) - drawing:willReturnFormattedCoordinateForDistance:
 
(CGFloat- drawingWillReturnUnitToPointsConversonFactor:
 
(void) - finalize
 
(NSString *) - hexString
 
(void) - hotspot:didEndTrackingWithEvent:inView:
 
(void) - hotspot:isTrackingWithEvent:inView:
 
(void) - hotspot:willBeginTrackingWithEvent:inView:
 
(NSData *) - imageData
 
(NSImage *) - imageResourceNamed:
 
(id- init
 
(id- initWithExpression:
 
(id- instantiateObjectWithShortName:parameters:
 
(BOOL- isLiteralValue
 
(void) - layoutManager:willPlaceGlyphAtIndex:atLocation:pathAngle:yOffset:
 
(void) - menuItem:wasAddedForObject:inCategory:
 
(BOOL- moveObjectTo:position:slope:userInfo:
 
(id- mutableCopy
 
(void) - oneShotComplete
 
(void) - oneShotHasReached:
 
(void) - oneShotWillBegin
 
(void) - path:elementIndex:type:points:subPathIndex:subPathClosed:contextInfo:
 
(id- placeLinkFromPoint:toPoint:onPath:linkNumber:userInfo:
 
(id- placeObjectAtPoint:onPath:position:slope:userInfo:
 
(NSPoint) - point
 
(NSPoint) - pointForTextLayout
 
(DKStyle *) - registry:shouldReplaceStyle:withStyle:
 
(NSBezierPath *) - renderer:willRenderPath:
 
(void) - routeFinder:progressHasReached:
 
(void) - setValue:forNumericParameter:
 
(NSString *) - stringValue
 
(CGFloat- taperFactorAtDistance:onPath:ofLength:
 
(void) - toolDidPerformUndoableAction:
 
(void) - toolWillPerformUndoableAction:
 
(NSURL *) - url
 
- Instance Methods inherited from <NSObject>
(NSString *) - description
 
(NSUInteger- hash
 
(BOOL- isEqual:
 
- Instance Methods inherited from <NSKeyValueBindingCreation>
(void) - bind:toObject:withKeyPath:options:
 
(NSArray *) - exposedBindings
 
(NSDictionary *) - infoForBinding:
 
(NSArray *) - optionDescriptionsForBinding:
 
(void) - unbind:
 
(Class- valueClassForBinding:
 
- Instance Methods inherited from <DKDrawingTool>
(NSString *) - actionName
 
(NSCursor *) - cursor
 
(NSInteger- mouseDownAtPoint:targetObject:layer:event:delegate:
 
(void) - mouseDraggedToPoint:partCode:layer:event:delegate:
 
(BOOL- mouseUpAtPoint:partCode:layer:event:delegate:
 

Class Methods

(DKDrawingTool *) + drawingToolWithKeyboardEquivalent:
 Retrieve a tool from the registry matching the key equivalent indicated by the key event passed. More...
 
(DKDrawingTool *) + drawingToolWithName:
 Retrieve a tool from the registry with the given name. More...
 
(id+ firstResponderAbleToSetTool
 
(void) + loadDefaults
 Load tool defaults from the user defaults. More...
 
(void) + registerDrawingTool:withName:
 Register a tool in th eregistry with the given name. More...
 
(void) + registerStandardTools
 Set a "standard" set of tools in the registry. More...
 
(void) + saveDefaults
 Save tool defaults to the user defaults. More...
 
(NSDictionary *) + sharedToolRegistry
 Return the shared instance of the tool registry. More...
 
(NSArray *) + toolNames
 Return a list of registered tools' names, sorted alphabetically. More...
 
(BOOL+ toolPerformsUndoableAction
 Does the tool ever implement undoable actions? More...
 
- Class Methods inherited from NSObject
(id+ alloc
 
(Class+ class
 
(void) + initialize
 
(void) + load
 
(id+ new
 
- Class Methods inherited from <NSKeyValueBindingCreation>
(void) + exposeBinding:
 

Detailed Description

DKDrawingTool is the semi-abstract base class for all types of drawing tool.

DKDrawingTool is the semi-abstract base class for all types of drawing tool. The point of a tool is to act as a translator for basic mouse events and convert those events into meaningful operations on the target layer or object(s). One tool can be set at a time (see DKToolController) and establishes a "mode" of operation for handling mouse events.

The tool also supplies a cursor for the view when that tool is selected.

A tool typically targets a layer or the objects within it. The calling sequence to a tool is coordinated by the DKToolController, targeting the current active layer. Tools can change the data content of the layer or not - for example a zoom zool would only change the scale of a view, not change any data.

Tools should be considered to be controllers, and sit between the view and the drawing data model.

Note: do not confuse "tools" as DK defines them with a palette of buttons or other UI - an application might implement an interface to select a tool in such a way, but the buttons are not tools. A button could store a tool as its representedObject however. These UI con- siderations are outside the scope of DK itself.

Method Documentation

+ (DKDrawingTool*) drawingToolWithKeyboardEquivalent: (NSEvent *)  keyEvent

Retrieve a tool from the registry matching the key equivalent indicated by the key event passed.

See DKToolController

Parameters
keyEventa keyDown event.
Returns
the tool if it can be matched, or nil

Provided by category DKDrawingTool(Deprecated).

+ (DKDrawingTool*) drawingToolWithName: (NSString *)  name

Retrieve a tool from the registry with the given name.

Registered tools may be conveniently set by name - see DKToolController

Parameters
namethe registry name of the tool required.
Returns
the tool if it exists, or nil

Provided by category DKDrawingTool(Deprecated).

- (void) drawRect: (NSRect aRect
inView: (NSView *)  aView 
+ (id) firstResponderAbleToSetTool
- (void) flagsChanged: (NSEvent *)  event
inLayer: (DKLayer *)  layer 
- (BOOL) isSelectionTool

Return whether the tool is some sort of object selection tool.

This method is used to assist the tool controller in making sensible decisions about certain automatic operations. Subclasses that implement a selection tool should override this to return YES.

Returns
YES if the tool selects objects, NO otherwise
- (BOOL) isValidTargetLayer: (DKLayer *)  aLayer
- (NSString*) keyboardEquivalent
- (NSUInteger) keyboardModifierFlags
+ (void) loadDefaults

Load tool defaults from the user defaults.

If used, this sets up the state of the tools and the styles they are set to to whatever was saved by the saveDefaults method in an earlier session. Someone (such as the app delegate) needs to call this on app launch after the tools have all been set up and registered.

- (void) mouseMoved: (NSEvent *)  event
inView: (NSView *)  view 

Provided by category DKDrawingTool(OptionalMethods).

- (NSData*) persistentData
+ (void) registerDrawingTool: (DKDrawingTool *)  tool
withName: (NSString *)  name 

Register a tool in th eregistry with the given name.

Registered tools may be conveniently set by name - see DKToolController

Parameters
toola tool object to register
namea name to register it against.

Provided by category DKDrawingTool(Deprecated).

- (NSString*) registeredName

Return the registry name for this tool.

If the tool isn't registered, returns nil

Returns
a string, the name this tool is registerd under, if any:
+ (void) registerStandardTools

Set a "standard" set of tools in the registry.

"Standard" tools are creation tools for various basic shapes, the selection tool, zoom tool and launch time, may be safely called more than once - subsequent calls are no-ops. If the conversion table has been set up prior to this, the tools will automatically pick up the class from the table, so that apps don't need to swap out all the tools for subclasses, but can simply set up the table.

Provided by category DKDrawingTool(Deprecated).

+ (void) saveDefaults

Save tool defaults to the user defaults.

Saves the persistent data, if any, of each registered tool. The main use for this is to restore the styles associated with each tool when the app is next launched.

- (void) set

Sets the tool as the current tool for the key view in the main window, if possible.

This follows the -set approach that cocoa uses for many objects. It looks for the key view in the main window. If it's a DKDrawingView that has a tool controller, it sets itself as the controller's current tool. This might be more convenient than other ways of setting a tool.

- (void) setCursorForPoint: (NSPoint)  mp
targetObject: (DKDrawableObject *)  obj
inLayer: (DKLayer *)  aLayer
event: (NSEvent *)  event 
- (void) setKeyboardEquivalent: (NSString *)  str
modifierFlags: (NSUInteger flags 
+ (NSDictionary*) sharedToolRegistry

Return the shared instance of the tool registry.

Creates a new empty registry if it doesn't yet exist

Returns
a dictionary - contains drawing tool objects keyed by name

Provided by category DKDrawingTool(Deprecated).

- (void) shouldLoadPersistentData: (NSData *)  data
- (void) toolControllerDidSetTool: (DKToolController *)  aController

Called when this tool is set by a tool controller.

Subclasses can make use of this message to prepare themselves when they are set if necessary

Parameters
aControllerthe controller that set this tool
- (void) toolControllerDidUnsetTool: (DKToolController *)  aController

Called when this tool is unset by a tool controller.

Subclasses can make use of this message to prepare themselves when they are unset if necessary

Parameters
aControllerthe controller that set this tool
- (void) toolControllerWillUnsetTool: (DKToolController *)  aController

Called when this tool is about to be unset by a tool controller.

Subclasses can make use of this message to prepare themselves when they are unset if necessary, for example by finishing the work they were doing and cleaning up.

Parameters
aControllerthe controller that set this tool
+ (NSArray*) toolNames

Return a list of registered tools' names, sorted alphabetically.

May be useful for supporting a UI

Returns
an array, a list of NSStrings

Provided by category DKDrawingTool(Deprecated).

+ (BOOL) toolPerformsUndoableAction

Does the tool ever implement undoable actions?

Classes must override this and say YES if the tool does indeed perform an undoable action (i.e. it does something to an object)

Returns
NO