-
Notifications
You must be signed in to change notification settings - Fork 4
/
ETDrawingStrokeShape.m
74 lines (60 loc) · 1.76 KB
/
ETDrawingStrokeShape.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#import "ETDrawingStrokeShape.h"
@implementation ETDrawingStrokeShape
- (id) initWithObjectGraphContext: (COObjectGraphContext *)aContext
{
self = [super initWithBezierPath: [NSBezierPath bezierPath] objectGraphContext: aContext];
if (nil == self)
{
return nil;
}
[[self path] moveToPoint: NSZeroPoint];
_pressures = [[NSMutableArray alloc] initWithCapacity:1000];
// Change this to ETPenStyle to get a vector pen tool instead..
_brushStyle = [[ETBrushStyle alloc] initWithObjectGraphContext: aContext];
_origin = NSMakePoint(0.0, 0.0);
return self;
}
- (void) dealloc
{
[_brushStyle release];
[_pressures release];
[super dealloc];
}
- (void) addPoint: (NSPoint)point withPressure: (float)pressure
{
[[self path] lineToPoint: point];
[_pressures addObject: [NSNumber numberWithFloat:pressure]];
[self didChangeItemBounds: [[self path] bounds]];
}
- (void) render: (NSMutableDictionary *)inputValues
layoutItem: (ETLayoutItem *)item
dirtyRect: (NSRect)dirtyRect;
{
// FIXME: May be we should better support dirtyRect. The next drawing
// methods don't take in account it and simply redraw all their content.
NSMutableDictionary *newInputValues = [D([self path], @"path",
_pressures, @"pressures",
[NSValue valueWithPoint: _origin], @"origin") mutableCopy];
[newInputValues addEntriesFromDictionary: inputValues];
[[self brushStyle] render: newInputValues
layoutItem: item
dirtyRect: dirtyRect];
if ([item isSelected])
{
[self drawSelectionIndicatorInRect: [item drawingBoundsForStyle: self]];
}
}
- (ETStyle *) brushStyle
{
return _brushStyle;
}
- (void) setBrushStyle: (ETStyle *)style;
{
ASSIGN(_brushStyle, style);
// TODO: redraw?
}
- (void) setDrawingOrigin: (NSPoint)origin
{
_origin = origin;
}
@end