Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 113 lines (82 sloc) 2.796 kb
0a600f5 Uli Kusterer Added a pixel-stamp-based brush tool.
authored
1 //
2 // UKPixelPaintbrushTool.m
6a767a7 Uli Kusterer Big clean-up. Adopted new prefix. Fixed support for line and fill colors...
authored
3 // ULIPaintView
0a600f5 Uli Kusterer 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 Uli Kusterer Big clean-up. Adopted new prefix. Fixed support for line and fill colors...
authored
9 #import "ULIPaintBrushTool.h"
10 #import "ULIPaintView.h"
0a600f5 Uli Kusterer Added a pixel-stamp-based brush tool.
authored
11 #import "NSCursor+Box.h"
12 #import "UlisBresenham.h"
6a767a7 Uli Kusterer Big clean-up. Adopted new prefix. Fixed support for line and fill colors...
authored
13 #import "UKHelperMacros.h"
0a600f5 Uli Kusterer Added a pixel-stamp-based brush tool.
authored
14
15
6a767a7 Uli Kusterer Big clean-up. Adopted new prefix. Fixed support for line and fill colors...
authored
16 @implementation ULIPaintBrushTool
0a600f5 Uli Kusterer Added a pixel-stamp-based brush tool.
authored
17
18 @synthesize brushImage = mBrushImage;
19 @synthesize tintedBrushImage = mTintedBrushImage;
20
6a767a7 Uli Kusterer Big clean-up. Adopted new prefix. Fixed support for line and fill colors...
authored
21 -(id) initWithPaintView: (ULIPaintView*)pv
0a600f5 Uli Kusterer 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 Uli Kusterer Big clean-up. Adopted new prefix. Fixed support for line and fill colors...
authored
34 DESTROY_DEALLOC(mBrushImage);
35 DESTROY_DEALLOC(mTintedBrushImage);
0a600f5 Uli Kusterer Added a pixel-stamp-based brush tool.
authored
36
37 [super dealloc];
38 }
39
40
6a767a7 Uli Kusterer Big clean-up. Adopted new prefix. Fixed support for line and fill colors...
authored
41 void ULIPaintbrushBresenhamPixelProc( float x, float y, void* data )
0a600f5 Uli Kusterer Added a pixel-stamp-based brush tool.
authored
42 {
6a767a7 Uli Kusterer Big clean-up. Adopted new prefix. Fixed support for line and fill colors...
authored
43 ULIPaintBrushTool* tool = (ULIPaintBrushTool*) data;
0a600f5 Uli Kusterer 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];
69 [NSBezierPath fillRect: NSRectFromCGRect(theBox)];
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 Uli Kusterer Big clean-up. Adopted new prefix. Fixed support for line and fill colors...
authored
80 ULIPaintbrushBresenhamPixelProc, self );
0a600f5 Uli Kusterer 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 {
95 NSPoint pos = { 0, 0 };
96 NSSize brushSize = [mBrushImage size];
97
98 pos.x = truncf(brushSize.width / 2);
99 pos.y = truncf(brushSize.height / 2);
100
101 return [[[NSCursor alloc] initWithImage: mBrushImage hotSpot: pos] autorelease];
102 }
103
104
105 -(BOOL) isSaveableTool
106 {
107 return NO;
108 }
109
110
111
112 @end
Something went wrong with that request. Please try again.