Skip to content
Newer
Older
100644 128 lines (104 sloc) 3.83 KB
ee99867 @ccgus oh geeze
authored Mar 4, 2009
1 //
2 // MarkerTextView.m
3 // Line View Test
4 //
5 // Created by Paul Kim on 10/4/08.
6 // Copyright (c) 2008 Noodlesoft, LLC. All rights reserved.
7 //
8 // Permission is hereby granted, free of charge, to any person
9 // obtaining a copy of this software and associated documentation
10 // files (the "Software"), to deal in the Software without
11 // restriction, including without limitation the rights to use,
12 // copy, modify, merge, publish, distribute, sublicense, and/or sell
13 // copies of the Software, and to permit persons to whom the
14 // Software is furnished to do so, subject to the following
15 // conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22 // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25 // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 // OTHER DEALINGS IN THE SOFTWARE.
28 //
29
30 #import "MarkerLineNumberView.h"
31 #import "NoodleLineNumberMarker.h"
32
33 #define CORNER_RADIUS 3.0
34 #define MARKER_HEIGHT 13.0
35
36 @implementation MarkerLineNumberView
37
38 - (void)dealloc
39 {
40 [markerImage release];
41
42 [super dealloc];
43 }
44
75ba2de @ccgus Upgraded to the latest JSCocoa changes. 64bit goodness from what I un…
authored Sep 6, 2009
45 - (void)setRuleThickness:(CGFloat)thickness
ee99867 @ccgus oh geeze
authored Mar 5, 2009
46 {
47 [super setRuleThickness:thickness];
48
49 // Overridden to reset the size of the marker image forcing it to redraw with the new width.
50 // If doing this in a non-subclass of NoodleLineNumberView, you can set it to post frame
51 // notifications and listen for them.
52 [markerImage setSize:NSMakeSize(thickness, MARKER_HEIGHT)];
53 }
54
55 - (void)drawMarkerImageIntoRep:(id)rep
56 {
57 NSBezierPath *path;
58 NSRect rect;
59
60 rect = NSMakeRect(1.0, 2.0, [rep size].width - 2.0, [rep size].height - 3.0);
61
62 path = [NSBezierPath bezierPath];
63 [path moveToPoint:NSMakePoint(NSMaxX(rect), NSMinY(rect) + NSHeight(rect) / 2)];
64 [path lineToPoint:NSMakePoint(NSMaxX(rect) - 5.0, NSMaxY(rect))];
65
66 [path appendBezierPathWithArcWithCenter:NSMakePoint(NSMinX(rect) + CORNER_RADIUS, NSMaxY(rect) - CORNER_RADIUS) radius:CORNER_RADIUS startAngle:90 endAngle:180];
67
68 [path appendBezierPathWithArcWithCenter:NSMakePoint(NSMinX(rect) + CORNER_RADIUS, NSMinY(rect) + CORNER_RADIUS) radius:CORNER_RADIUS startAngle:180 endAngle:270];
69 [path lineToPoint:NSMakePoint(NSMaxX(rect) - 5.0, NSMinY(rect))];
70 [path closePath];
71
72 [[NSColor colorWithCalibratedRed:0.003 green:0.56 blue:0.85 alpha:1.0] set];
73 [path fill];
74
75 [[NSColor colorWithCalibratedRed:0 green:0.44 blue:0.8 alpha:1.0] set];
76
77 [path setLineWidth:2.0];
78 [path stroke];
79 }
80
81 - (NSImage *)markerImageWithSize:(NSSize)size
82 {
83 if (markerImage == nil)
84 {
85 NSCustomImageRep *rep;
86
87 markerImage = [[NSImage alloc] initWithSize:size];
88 rep = [[NSCustomImageRep alloc] initWithDrawSelector:@selector(drawMarkerImageIntoRep:) delegate:self];
89 [rep setSize:size];
90 [markerImage addRepresentation:rep];
91 [rep release];
92 }
93 return markerImage;
94 }
95
96 - (void)mouseDown:(NSEvent *)theEvent
97 {
98 NSPoint location;
75ba2de @ccgus Upgraded to the latest JSCocoa changes. 64bit goodness from what I un…
authored Sep 7, 2009
99 NSUInteger line;
ee99867 @ccgus oh geeze
authored Mar 5, 2009
100
101 location = [self convertPoint:[theEvent locationInWindow] fromView:nil];
102 line = [self lineNumberForLocation:location.y];
103
104 if (line != NSNotFound)
105 {
106 NoodleLineNumberMarker *marker;
107
108 marker = [self markerAtLine:line];
109
110 if (marker != nil)
111 {
112 [self removeMarker:marker];
113 }
114 else
115 {
116 marker = [[NoodleLineNumberMarker alloc] initWithRulerView:self
117 lineNumber:line
118 image:[self markerImageWithSize:NSMakeSize([self ruleThickness], MARKER_HEIGHT)]
119 imageOrigin:NSMakePoint(0, MARKER_HEIGHT / 2)];
120 [self addMarker:marker];
121 [marker release];
122 }
123 [self setNeedsDisplay:YES];
124 }
125 }
126
127 @end
Something went wrong with that request. Please try again.