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

A layer group is a layer which maintains a list of other layers. More...

Inheritance diagram for DKLayerGroup:
Inheritance graph
[legend]

Instance Methods

(void) - addLayer:
 
(void) - addLayer:aboveLayerIndex:
 
(DKLayer *) - addNewLayerOfClass:
 
(DKLayer *) - bottomLayer
 
(BOOL- containsLayer:
 
(NSUInteger- countOfLayers
 
(DKLayer *) - findLayerForPoint:
 
(DKLayer *) - firstLayerOfClass:
 
(DKLayer *) - firstLayerOfClass:performDeepSearch:
 
(NSArray *) - flattenedLayers
 
(NSArray *) - flattenedLayersIncludingGroups:
 
(NSArray *) - flattenedLayersOfClass:
 
(NSArray *) - flattenedLayersOfClass:includeGroups:
 
(BOOL- hasHiddenLayers
 Returns YES if the receiver or any of its contained layers is hidden. More...
 
(BOOL- hasVisibleLayersOtherThan:
 Returns YES if the receiver or any of its contained layers is visible, ignoring the one passed. More...
 
(void) - hideAllExcept:
 Makes all layers in the group and in any subgroups hidden except <aLayer>, which is made visible. More...
 
(NSUInteger- indexOfHighestOpaqueLayer
 
(NSUInteger- indexOfLayer:
 
(id- initWithLayers:
 Initialize a layer group. More...
 
(void) - insertObject:inLayersAtIndex:
 
(NSEnumerator *) - layerBottomToTopEnumerator
 
(NSArray *) - layers
 
(NSArray *) - layersOfClass:
 
(NSArray *) - layersOfClass:performDeepSearch:
 
(NSEnumerator *) - layerTopToBottomEnumerator
 
(DKLayer *) - layerWithUniqueKey:
 Returns a layer or layer group having the given unique key. More...
 
(NSUInteger- level
 Returns the hierarchical level of this group, i.e. More...
 
(void) - moveDownLayer:
 
(void) - moveLayer:aboveLayer:
 
(void) - moveLayer:belowLayer:
 
(void) - moveLayer:toIndex:
 
(void) - moveLayerToBottom:
 
(void) - moveLayerToTop:
 
(void) - moveUpLayer:
 
(DKLayer *) - objectInLayersAtIndex:
 
(void) - removeAllLayers
 
(void) - removeLayer:
 
(void) - removeObjectFromLayersAtIndex:
 
(void) - setLayers:
 
(void) - showAll
 Makes all layers in the group and in any subgroups visible. More...
 
(DKLayer *) - topLayer
 
(NSString *) - uniqueLayerNameForName:
 
- Instance Methods inherited from DKLayer
(NSRect- activeCursorRect
 Return a rect where the layer's cursor is shown when the mouse is within it. More...
 
(void) - addMetadata:
 
(void) - addUserInfo:
 
(NSSet *) - allRegisteredStyles
 Return all of registered styles used by the layer. More...
 
(NSSet *) - allStyles
 Return all of styles used by the layer. More...
 
(CGFloat- alpha
 Returns the alpha level for the layer as a whole. More...
 
(void) - beginDrawing
 Called before the layer starts drawing its content. More...
 
(NSBitmapImageRep *) - bitmapRepresentationWithDPI:
 Returns the layer's content as a transparent bitmap having the given DPI. More...
 
(BOOL- clipsDrawingToInterior
 Whether the drawing will be clipped to the interior or not. More...
 
(NSColor *) - colourForKey:
 
(IBAction) - copy:
 
(NSView *) - currentView
 Returns the view which is either currently drawing the layer, or the one that mouse events are coming from. More...
 
(NSCursor *) - cursor
 Returns the cursor to display while the mouse is over this layer while it's active. More...
 
(DKDrawing *) - drawing
 Returns the drawing that the layer belongs to. More...
 
(void) - drawingDidChangeMargins:
 
(void) - drawingDidChangeToSize:
 Called when the drawing's size is changed - this gives layers that need to know about this a direct notification. More...
 
(void) - drawingHasNewUndoManager:
 Called when the drawing's undo manager is changed - this gives objects that cache the UM a chance to update their references. More...
 
(void) - drawRect:inView:
 Main entry point for drawing the layer and its contents to the drawing's views. More...
 
(void) - endDrawing
 Called after the layer has finished drawing its content. More...
 
(void) - flagsChanged:
 Respond to a change in the modifier key state. More...
 
(CGFloat- floatValueForKey:
 
(BOOL- hasMetadataForKey:
 
(void) - hideInfoWindow
 Hides the info window if it's visible. More...
 
(IBAction) - hideLayer:
 User interface level method can be linked to a menu or other appropriate UI widget. More...
 
(void) - hideRulerMarkers
 
(BOOL- hitLayer:
 Detect whether the layer was "hit" by a point. More...
 
(DKDrawableObject *) - hitTest:
 Detect what object was hit by a point. More...
 
(NSUInteger- indexInGroup
 Gets the layer's index within the group that the layer is contained in. More...
 
(NSInteger- intValueForKey:
 
(BOOL- isActive
 Is the layer the active layer? More...
 
(BOOL- isChildOfGroup:
 Determine whether a given group is the parent of this layer, or anywhere above it in the hierarchy. More...
 
(BOOL- isOpaque
 Is the layer opaque or transparent? More...
 
(DKKnob *) - knobs
 
(BOOL- knobsShouldAdjustToViewScale
 
(void) - layerDidBecomeActiveLayer
 The layer was made the active layer by the owning drawing. More...
 
(void) - layerDidResignActiveLayer
 The layer is no longer the active layer. More...
 
(DKLayerGroup *) - layerGroup
 Gets the group that the layer is contained in. More...
 
(BOOL- layerMayBecomeActive
 Returns whether the layer can become the active layer. More...
 
(BOOL- layerMayBeDeleted
 Return whether the layer can be deleted. More...
 
(NSString *) - layerName
 Returns the layer's name. More...
 
(BOOL- locked
 Returns whether the layer is locked or not. More...
 
(BOOL- lockedOrHidden
 Returns whether the layer is locked or hidden. More...
 
(IBAction) - lockLayer:
 User interface level method can be linked to a menu or other appropriate UI widget. More...
 
(IBAction) - logDescription:
 Debugging method. More...
 
(NSMenu *) - menuForEvent:inView:
 Allows a contextual menu to be built for the layer or its contents. More...
 
(NSMutableDictionary *) - metadata
 
(NSUInteger- metadataChecksum
 
(void) - metadataDidChangeKey:
 
(DKMetadataItem *) - metadataItemForKey:
 
(NSArray *) - metadataKeys
 
(id- metadataObjectForKey:
 
(void) - metadataWillChangeKey:
 
(void) - mouseDown:inView:
 The mouse went down in this layer. More...
 
(void) - mouseDragged:inView:
 Subclasses must override to be notified of mouse dragged events. More...
 
(void) - mouseMoved:inView:
 
(void) - mouseUp:inView:
 Override to respond to the event. More...
 
(BOOL- pasteboard:hasAvailableTypeForOperation:
 Tests whether the pasteboard has any of the types the layer is interested in receiving for the given operation. More...
 
(NSArray *) - pasteboardTypesForOperation:
 Return the pasteboard types this layer is able to receive in a given operation (drop or paste) More...
 
(NSData *) - pdf
 Returns the content of the layer as a pdf. More...
 
(void) - removeMetadataForKey:
 
(void) - replaceMatchingStylesFromSet:
 Substitute styles with those in the given set. More...
 
(BOOL- rulerMarkerUpdatesEnabled
 
(DKLayerMetadataSchema) - schema
 
(NSColor *) - selectionColour
 Returns the currently preferred selection colour for this layer. More...
 
(void) - setAlpha:
 Sets the alpha level for the layer. More...
 
(void) - setClipsDrawingToInterior:
 Sets whether drawing is limited to the interior area or not. More...
 
(void) - setColour:forKey:
 
(void) - setFloatValue:forKey:
 
(void) - setInfoWindowBackgroundColour:
 Sets the background colour of the small floating info window. More...
 
(void) - setIntValue:forKey:
 
(void) - setKnobs:
 
(void) - setKnobsShouldAdustToViewScale:
 
(void) - setLayerGroup:
 Sets the group that the layer is contained in - called automatically when the layer is added to a group. More...
 
(void) - setLayerName:
 Sets the user-readable name of the layer. More...
 
(void) - setLocked:
 Sets whether the layer is locked or not. More...
 
(void) - setMetadata:
 
(void) - setMetadataItem:forKey:
 
(void) - setMetadataItemType:forKey:
 
(void) - setMetadataItemValue:forKey:
 
(void) - setMetadataObject:forKey:
 
(void) - setNeedsDisplay:
 Flags the whole layer as needing redrawing. More...
 
(void) - setNeedsDisplayInRect:
 Flags part of a layer as needing redrawing. More...
 
(void) - setNeedsDisplayInRects:
 Marks several areas for update at once. More...
 
(void) - setNeedsDisplayInRects:withExtraPadding:
 Marks several areas for update at once. More...
 
(void) - setRulerMarkerUpdatesEnabled:
 
(void) - setSelectionColour:
 Sets the colour preference to use for selected objects within this layer. More...
 
(void) - setShouldDrawToPrinter:
 Set whether this layer should be included in printed output. More...
 
(void) - setSize:forKey:
 
(void) - setString:forKey:
 
(void) - setupMetadata
 
(void) - setUserInfo:
 
(void) - setUserInfoObject:forKey:
 
(void) - setVisible:
 Sets whether the layer is visible or not. More...
 
(BOOL- shouldAutoActivateWithEvent:
 Should the layer automatically activate on a click if the view has this behaviour set? More...
 
(BOOL- shouldDrawToPrinter
 Return whether the layer should be part of the printed output or not. More...
 
(void) - showInfoWindowWithString:atPoint:
 Displays a small floating info window near the point p containg the string. More...
 
(IBAction) - showLayer:
 User interface level method can be linked to a menu or other appropriate UI widget. More...
 
(NSSize) - sizeForKey:
 
(NSString *) - stringForKey:
 
(BOOL- supportsMetadata
 
(NSImage *) - thumbnail
 
(NSImage *) - thumbnailImageWithSize:
 Returns an image of the layer a the given size. More...
 
(IBAction) - toggleLayerLock:
 User interface level method can be linked to a menu or other appropriate UI widget. More...
 
(IBAction) - toggleLayerVisible:
 User interface level method can be linked to a menu or other appropriate UI widget. More...
 
(NSUndoManager *) - undoManager
 Obtains the undo manager that is handling undo for the drawing and hence, this layer. More...
 
(NSString *) - uniqueKey
 Returns the layer's unique key. More...
 
(IBAction) - unlockLayer:
 User interface level method can be linked to a menu or other appropriate UI widget. More...
 
(void) - updateMetadataKeys
 
(void) - updateRulerMarkersForRect:
 
(NSMutableDictionary *) - userInfo
 Return the attached user info. More...
 
(id- userInfoObjectForKey:
 Return an item of user info. More...
 
(BOOL- visible
 Is the layer visible? More...
 
(void) - wasAddedToDrawing:
 Notifies the layer that it or a group containing it was added to a drawing. More...
 
(BOOL- writePDFDataToPasteboard:
 Writes the content of the layer as a pdf to a nominated pasteboard. 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 <NSCoding>
(void) - encodeWithCoder:
 
(id- initWithCoder:
 
- Instance Methods inherited from <DKKnobOwner>
(BOOL- knobsWantDrawingActiveState
 
(CGFloat- knobsWantDrawingScale
 

Class Methods

(DKLayerGroup *) + layerGroupWithLayers:
 Convenience method for building a new layer group from an existing list of layers. More...
 
- Class Methods inherited from DKLayer
(BOOL+ metadataChangesAreUndoable
 
(NSColor *) + selectionColourForIndex:
 
(NSArray *) + selectionColours
 Returns the list of colours used for supplying the selection colours. More...
 
(void) + setMetadataChangesAreUndoable:
 
(void) + setSelectionColours:
 Allows a list of colours to be set for supplying the selection colours. 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

A layer group is a layer which maintains a list of other layers.

Author
Contributions from the community; see CONTRIBUTORS.md
Date
2005-2015

A layer group is a layer which maintains a list of other layers. This permits layers to be organised hierarchically if the application wishes to do so.

DKDrawing is a subclass of this, so it inherits the ability to maintain a list of layers. However it doesn't honour every possible feature of a layer group, particularly those the group inherits from DKLayer. This is because DKLayerGroup is actually a refactoring of DKDrawing and backward compatibility with existing files is required. In particular one should take care not to add a DKDrawing instance to a layer group belonging to another drawing (or create circular references).

The stacking order of layers is arranged so that the top layer always has the index zero, and the bottom is at (count -1). In general your code should minimise its exposure to the actual layer index, but the reason that layers are stacked this way is so that a layer UI such as a NSTableView doesn't have to do anything special to view layers in a natural way, with the top layer at the top of such a table. Prior to beta 3, layers were stacked the other way so such tables appeared to be upside-down. This class automatically reverses the stacking order in an archive if it detects an older version.

Method Documentation

- (void) addLayer: (DKLayer *)  aLayer
- (void) addLayer: (DKLayer *)  aLayer
aboveLayerIndex: (NSUInteger layerIndex 
- (DKLayer*) addNewLayerOfClass: (Class layerClass
- (DKLayer*) bottomLayer
- (BOOL) containsLayer: (DKLayer *)  aLayer
- (NSUInteger) countOfLayers
- (DKLayer*) findLayerForPoint: (NSPoint)  aPoint
- (DKLayer*) firstLayerOfClass: (Class cl
- (DKLayer*) firstLayerOfClass: (Class cl
performDeepSearch: (BOOL deep 
- (NSArray*) flattenedLayers
- (NSArray*) flattenedLayersIncludingGroups: (BOOL includeGroups
- (NSArray*) flattenedLayersOfClass: (Class layerClass
- (NSArray*) flattenedLayersOfClass: (Class layerClass
includeGroups: (BOOL includeGroups 
- (BOOL) hasHiddenLayers

Returns YES if the receiver or any of its contained layers is hidden.

Recurses on any subgroups.

Returns
YES if there are hidden layers below this, or this is hidden itself
- (BOOL) hasVisibleLayersOtherThan: (DKLayer *)  aLayer

Returns YES if the receiver or any of its contained layers is visible, ignoring the one passed.

Recurses on any subgroups. Typically <aLayer> is the active layer - may be nil.

Parameters
aLayera layer to exclude when testing this
Returns
YES if there are visible layers below this, or this is visible itself
- (void) hideAllExcept: (DKLayer *)  aLayer

Makes all layers in the group and in any subgroups hidden except <aLayer>, which is made visible.

ALayer may be nil in which case this performs a hideAll. Recurses on any subgroups.

Parameters
aLayera layer to leave visible
- (NSUInteger) indexOfHighestOpaqueLayer
- (NSUInteger) indexOfLayer: (DKLayer *)  aLayer
- (id) initWithLayers: (NSArray *)  layers

Initialize a layer group.

A layer group must be added to another group or drawing before it can be used

Parameters
layersa list of existing layers
Returns
a new layer group
- (void) insertObject: (DKLayer *)  aLayer
inLayersAtIndex: (NSUInteger layerIndex 
- (NSEnumerator*) layerBottomToTopEnumerator
+ (DKLayerGroup*) layerGroupWithLayers: (NSArray *)  layers

Convenience method for building a new layer group from an existing list of layers.

The group must be added to a drawing to be useful. If the layers are already part of a drawing, or other group, they need to be removed first. It is an error to attach a layer in more than one group (or drawing, which is a group) at a time. Layers should be stacked with the top at index #0, the bottom at #(count -1)

Parameters
layersa list of existing layers
Returns
a new layer group containing the passed layers
- (NSArray*) layers
- (NSArray*) layersOfClass: (Class cl
- (NSArray*) layersOfClass: (Class cl
performDeepSearch: (BOOL deep 
- (NSEnumerator*) layerTopToBottomEnumerator
- (DKLayer*) layerWithUniqueKey: (NSString *)  key

Returns a layer or layer group having the given unique key.

Unique keys are assigned to layers for the lifetime of the app. They are not persistent and must only

Parameters
keythe layer's key
Returns
the layer if found, nil otherwise.
- (NSUInteger) level

Returns the hierarchical level of this group, i.e.

how deeply nested it is

The root group returns 0, next level is 1 and so on.

Returns
the group's level

Implements DKLayer.

- (void) moveDownLayer: (DKLayer *)  aLayer
- (void) moveLayer: (DKLayer *)  aLayer
aboveLayer: (DKLayer *)  otherLayer 
- (void) moveLayer: (DKLayer *)  aLayer
belowLayer: (DKLayer *)  otherLayer 
- (void) moveLayer: (DKLayer *)  aLayer
toIndex: (NSUInteger i 
- (void) moveLayerToBottom: (DKLayer *)  aLayer
- (void) moveLayerToTop: (DKLayer *)  aLayer
- (void) moveUpLayer: (DKLayer *)  aLayer
- (DKLayer*) objectInLayersAtIndex: (NSUInteger layerIndex
- (void) removeAllLayers
- (void) removeLayer: (DKLayer *)  aLayer
- (void) removeObjectFromLayersAtIndex: (NSUInteger layerIndex
- (void) setLayers: (NSArray *)  layers
- (void) showAll

Makes all layers in the group and in any subgroups visible.

Recurses when nested groups are found

- (DKLayer*) topLayer
- (NSString*) uniqueLayerNameForName: (NSString *)  aName