Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 116 lines (85 sloc) 2.915 kB
0a600f5 @uliwitness Added a pixel-stamp-based brush tool.
authored
1 //
2 // UKPixelPaintbrushTool.m
6a767a7 @uliwitness Big clean-up. Adopted new prefix. Fixed support for line and fill col…
authored
3 // ULIPaintView
0a600f5 @uliwitness Added a pixel-stamp-based brush tool.
authored
4 //
5 // Created by Uli Kusterer on Fri Oct 31 2003.
6 // Copyright (c) 2003 M. Uli Kusterer. All rights reserved.
7 //
8
6a767a7 @uliwitness Big clean-up. Adopted new prefix. Fixed support for line and fill col…
authored
9 #import "ULIPaintBrushTool.h"
10 #import "ULIPaintView.h"
0a600f5 @uliwitness Added a pixel-stamp-based brush tool.
authored
11 #import "NSCursor+Box.h"
12 #import "UlisBresenham.h"
6a767a7 @uliwitness Big clean-up. Adopted new prefix. Fixed support for line and fill col…
authored
13 #import "UKHelperMacros.h"
0a600f5 @uliwitness Added a pixel-stamp-based brush tool.
authored
14
15
6a767a7 @uliwitness Big clean-up. Adopted new prefix. Fixed support for line and fill col…
authored
16 @implementation ULIPaintBrushTool
0a600f5 @uliwitness Added a pixel-stamp-based brush tool.
authored
17
18 @synthesize brushImage = mBrushImage;
19 @synthesize tintedBrushImage = mTintedBrushImage;
20
6a767a7 @uliwitness Big clean-up. Adopted new prefix. Fixed support for line and fill col…
authored
21 -(id) initWithPaintView: (ULIPaintView*)pv
0a600f5 @uliwitness Added a pixel-stamp-based brush tool.
authored
22 {
23 if(( self = [super initWithPaintView: pv] ))
24 {
25 mBrushImage = [[NSImage imageNamed: @"brush01"] retain];
26 }
27
28 return self;
29 }
30
31
32 -(void) dealloc
33 {
6a767a7 @uliwitness Big clean-up. Adopted new prefix. Fixed support for line and fill col…
authored
34 DESTROY_DEALLOC(mBrushImage);
35 DESTROY_DEALLOC(mTintedBrushImage);
0a600f5 @uliwitness Added a pixel-stamp-based brush tool.
authored
36
37 [super dealloc];
38 }
39
40
6a767a7 @uliwitness Big clean-up. Adopted new prefix. Fixed support for line and fill col…
authored
41 void ULIPaintbrushBresenhamPixelProc( float x, float y, void* data )
0a600f5 @uliwitness Added a pixel-stamp-based brush tool.
authored
42 {
6a767a7 @uliwitness Big clean-up. Adopted new prefix. Fixed support for line and fill col…
authored
43 ULIPaintBrushTool* tool = (ULIPaintBrushTool*) data;
0a600f5 @uliwitness Added a pixel-stamp-based brush tool.
authored
44 NSImage* brushImage = [tool tintedBrushImage];
45 NSSize brushSize = [brushImage size];
46 NSRect box = NSZeroRect;
47
48 box.origin.x = x -truncf(brushSize.width / 2);
49 box.origin.y = y -truncf(brushSize.height / 2);
50 box.size = brushSize;
51
52 [brushImage drawAtPoint: box.origin fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0];
53 [[tool owner] setNeedsDisplayInRect: box];
54 }
55
56
57 -(void) trackingWillStart
58 {
59 DESTROY(mTintedBrushImage);
60 mTintedBrushImage = [[NSImage alloc] initWithSize: [mBrushImage size]];
61 CGRect theBox = CGRectZero;
62 theBox.size = NSSizeToCGSize( [mBrushImage size] );
63
64 [mTintedBrushImage lockFocus];
65 CGContextRef theContext = [[NSGraphicsContext currentContext] graphicsPort];
66 CGImageRef brushCGImage = [mBrushImage CGImageForProposedRect: NULL context: [NSGraphicsContext currentContext] hints: nil];
67 CGContextClipToMask( theContext, theBox, brushCGImage );
68 [[owner lineColor] set];
4cbd833 @uliwitness Paint brush draws a bit nicer now.
authored
69 NSRectFillUsingOperation( NSRectFromCGRect(theBox), NSCompositeSourceOver );
0a600f5 @uliwitness Added a pixel-stamp-based brush tool.
authored
70 [mTintedBrushImage unlockFocus];
71 }
72
73
74 /* Override this to draw a brush during tracking:
75 The drawings you do in here will end up in the actual image buffer. */
76 -(void) drawTrackingToolShapeFrom: (NSPoint*)lastPos to: (NSPoint)currPos
77 {
78 // Draw a brush line using the owning paint view's line color:
79 DrawBresenhamLine( lastPos->x, lastPos->y, currPos.x, currPos.y,
6a767a7 @uliwitness Big clean-up. Adopted new prefix. Fixed support for line and fill col…
authored
80 ULIPaintbrushBresenhamPixelProc, self );
0a600f5 @uliwitness Added a pixel-stamp-based brush tool.
authored
81
82 *lastPos = currPos; // Make sure we continue drawing at end of this line segment.
83 }
84
85
86 // Return the name of an image to use as the icon for this tool in the tool palette.
87 -(NSString*) toolIconName
88 {
89 return @"UKPaintbrushTool";
90 }
91
92
93 -(NSCursor*) drawingCursor
94 {
4cbd833 @uliwitness Paint brush draws a bit nicer now.
authored
95 NSImage* brushImage = [self tintedBrushImage];
96 if( !brushImage )
97 brushImage = mBrushImage;
0a600f5 @uliwitness Added a pixel-stamp-based brush tool.
authored
98 NSPoint pos = { 0, 0 };
4cbd833 @uliwitness Paint brush draws a bit nicer now.
authored
99 NSSize brushSize = [brushImage size];
0a600f5 @uliwitness Added a pixel-stamp-based brush tool.
authored
100
101 pos.x = truncf(brushSize.width / 2);
102 pos.y = truncf(brushSize.height / 2);
103
4cbd833 @uliwitness Paint brush draws a bit nicer now.
authored
104 return [[[NSCursor alloc] initWithImage: brushImage hotSpot: pos] autorelease];
0a600f5 @uliwitness Added a pixel-stamp-based brush tool.
authored
105 }
106
107
108 -(BOOL) isSaveableTool
109 {
110 return NO;
111 }
112
113
114
115 @end
Something went wrong with that request. Please try again.