Skip to content

Commit a0cd56e

Browse files
committed
• Eliminated -lockFocus and -unlockFocus in -drawRect methods, where it was never needed.
• Replaced -lockFocus and -unlockFocus in offscreen drawing methods with -[NSImage imageWithSize:flipped:drawingHandler:], for compatibility with resolution-independent graphics.. FILES WITH THIS CHANGE NOW REQUIRE OS X 10.8 OR LATER.
1 parent 3fafec9 commit a0cd56e

7 files changed

+58
-53
lines changed

SSYGrayRect.m

-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ - (void)awakeFromNib {
1313

1414
- (void)drawRect:(NSRect)dirtyRect {
1515
[super drawRect:dirtyRect] ;
16-
17-
[self lockFocus] ;
18-
1916
NSGradient* gradient = [[NSGradient alloc] initWithStartingColor:[NSColor colorWithCalibratedWhite:[self topWhite]
2017
alpha:1.0]
2118
endingColor:[NSColor colorWithCalibratedWhite:[self bottomWhite]
@@ -30,7 +27,6 @@ - (void)drawRect:(NSRect)dirtyRect {
3027
frame.size.height = [self frame].size.height ;
3128
[gradient drawInRect:frame
3229
angle:270.0] ;
33-
[self unlockFocus] ;
3430
[gradient release] ;
3531
}
3632

SSYHintArrow.m

+26-28
Original file line numberDiff line numberDiff line change
@@ -108,31 +108,30 @@ - (NSBezierPath *)backgroundPath {
108108
}
109109

110110
- (NSColor *)backgroundColorPatternImage {
111-
NSImage* bg = [[NSImage alloc] initWithSize:[self frame].size] ;
112-
NSRect bgRect = NSZeroRect ;
113-
bgRect.size = [bg size] ;
114-
115-
[bg lockFocus] ;
116-
NSBezierPath* bgPath = [self backgroundPath] ;
117-
[NSGraphicsContext saveGraphicsState] ;
118-
[bgPath addClip] ;
119-
120-
// Draw background gradient.
121-
[m_gradient drawInBezierPath:bgPath
122-
angle:270.0] ;
123-
124-
// Draw border if appropriate.
125-
if (m_borderWidth > 0) {
126-
// Double the borderWidth since we're drawing inside the path.
127-
[bgPath setLineWidth:(m_borderWidth * 2.0) * SSYHINTARROW_SCALE_FACTOR] ;
128-
[m_borderColor set] ;
129-
[bgPath stroke] ;
130-
}
131-
132-
[NSGraphicsContext restoreGraphicsState] ;
133-
[bg unlockFocus] ;
134-
135-
return [NSColor colorWithPatternImage:[bg autorelease]] ;
111+
NSImage* bg = [NSImage imageWithSize:[self frame].size
112+
flipped:NO
113+
drawingHandler:^(NSRect dstRect) {
114+
NSBezierPath* bgPath = [self backgroundPath] ;
115+
[NSGraphicsContext saveGraphicsState] ;
116+
[bgPath addClip] ;
117+
118+
// Draw background gradient.
119+
[m_gradient drawInBezierPath:bgPath
120+
angle:270.0] ;
121+
122+
// Draw border if appropriate.
123+
if (m_borderWidth > 0) {
124+
// Double the borderWidth since we're drawing inside the path.
125+
[bgPath setLineWidth:(m_borderWidth * 2.0) * SSYHINTARROW_SCALE_FACTOR] ;
126+
[m_borderColor set] ;
127+
[bgPath stroke] ;
128+
}
129+
[NSGraphicsContext restoreGraphicsState] ;
130+
131+
return YES ;
132+
}] ;
133+
134+
return [NSColor colorWithPatternImage:bg] ;
136135
}
137136

138137
- (void)updateBackground {
@@ -298,9 +297,8 @@ + (CAKeyframeAnimation *)shakeAnimation:(NSRect)frame {
298297
+ (void)showHelpArrowAtPoint:(NSPoint)point
299298
inWindow:(NSWindow*)window {
300299
if (static_helpArrow) {
301-
// Only one SSYHintArrow at a time!!
302-
NSLog(@"Internal Error 892-8178 Intercepted call to display > 1 SSYHintArrow") ;
303-
return ;
300+
// Only one SSYHintArrow at a time! Destroy the prior one.
301+
[static_helpArrow endWithNote:nil] ;
304302
}
305303

306304
static_helpArrow = [[SSYHintArrow alloc] initAttachedToPoint:point

SSYMenuAddButton.m

-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ @implementation SSYMenuAddButton
77
- (void)drawRect:(NSRect)dirtyRect {
88
[super drawRect:dirtyRect] ;
99

10-
[self lockFocus] ;
11-
1210
// Draw the "+"
1311
// The y-axis seems to be flipped in here.
1412
NSImage* image = [NSImage imageNamed:@"NSAddTemplate"] ;
@@ -28,8 +26,6 @@ - (void)drawRect:(NSRect)dirtyRect {
2826
[path relativeLineToPoint:NSMakePoint(-4, 4)] ;
2927
[path closePath] ;
3028
[path fill] ;
31-
32-
[self unlockFocus] ;
3329
}
3430

3531
@end

SSYMenuGearButton.m

-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ @implementation SSYMenuGearButton
66
- (void)drawRect:(NSRect)dirtyRect {
77
[super drawRect:dirtyRect] ;
88

9-
[self lockFocus] ;
10-
119
// Draw the Gear
1210
NSImage* image = [NSImage imageNamed:@"NSActionTemplate"] ;
1311
[image drawInRect:NSMakeRect(3,
@@ -25,8 +23,6 @@ - (void)drawRect:(NSRect)dirtyRect {
2523
[path relativeLineToPoint:NSMakePoint(-4, 4)] ;
2624
[path closePath] ;
2725
[path fill] ;
28-
29-
[self unlockFocus] ;
3026
}
3127

3228
@end

SSYTokenField.m

-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@ - (void)drawRect:(NSRect)rect {
1515
[bp relativeLineToPoint:NSMakePoint(frame.size.width, frame.size.height)] ;
1616
[bp moveToPoint:NSMakePoint(frame.origin.x, frame.origin.y+frame.size.height)] ;
1717
[bp relativeLineToPoint:NSMakePoint(frame.size.width, -frame.size.height)] ;
18-
[self lockFocus] ;
1918
[bp setLineWidth:4.0] ;
2019
[[NSColor redColor] set] ;
2120
[bp stroke] ;
22-
[self unlockFocus] ;
2321
[super drawRect:rect] ;
2422
}
2523
@end

SSYToolbarButton.m

+1-3
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,8 @@ - (IBAction)doDaClick:(id)sender {
125125
if ([self flashDuration] > 0.0) {
126126
NSImage* image = [self image] ;
127127
[self setOriginalImage:image] ;
128-
NSImage* darkerImage = [image copy] ;
129-
[darkerImage darken] ;
128+
NSImage* darkerImage = [image darkenedImage] ;
130129
[self setImage:darkerImage] ;
131-
[darkerImage release] ;
132130
NSTimer* timer = [NSTimer scheduledTimerWithTimeInterval:[self flashDuration]
133131
target:self
134132
selector:@selector(restoreOriginalImage:)

SSYVectorImages.m

+31-8
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,9 @@ + (void)glyphOnPath:(NSBezierPath*)path
1616
inFont:font] ;
1717
}
1818

19-
+ (NSImage*)imageWithGlyphName:(NSString*)glyphName
20-
fattenBy:(CGFloat)fattenBy
21-
fill:(BOOL)fill {
22-
NSSize size = NSMakeSize(100/fattenBy, 100) ;
23-
NSImage* image = [[NSImage alloc] initWithSize:size] ;
24-
[image lockFocus] ;
19+
+ (void)drawGlyphName:(NSString*)glyphName
20+
size:(NSSize)size
21+
fill:(BOOL)fill {
2522
NSBezierPath* bezier = [NSBezierPath bezierPath] ;
2623
[self glyphOnPath:bezier
2724
name:glyphName
@@ -33,8 +30,33 @@ + (NSImage*)imageWithGlyphName:(NSString*)glyphName
3330
[[NSColor blackColor] setFill] ;
3431
[bezier fill] ;
3532
}
36-
[image unlockFocus] ;
37-
[image autorelease] ;
33+
}
34+
35+
+ (NSImage*)imageWithGlyphName:(NSString*)glyphName
36+
fattenBy:(CGFloat)fattenBy
37+
fill:(BOOL)fill {
38+
NSSize size = NSMakeSize(100/fattenBy, 100) ;
39+
NSImage* image ;
40+
if ([NSImage respondsToSelector:@selector(imageWithSize:flipped:drawingHandler:)]) {
41+
// We must be in OS X 10.8 or later
42+
image = [NSImage imageWithSize:size
43+
flipped:NO
44+
drawingHandler:^(NSRect dstRect) {
45+
[self drawGlyphName:glyphName
46+
size:size
47+
fill:fill] ;
48+
return YES ;
49+
}] ;
50+
}
51+
else {
52+
image = [[NSImage alloc] initWithSize:size] ;
53+
[image lockFocus] ;
54+
[self drawGlyphName:glyphName
55+
size:size
56+
fill:fill] ;
57+
[image unlockFocus] ;
58+
[image autorelease] ;
59+
}
3860

3961
return image ;
4062
}
@@ -496,6 +518,7 @@ + (NSImage*)imageStyle:(SSYVectorImageStyle)style
496518
NSImage* rotatedImage ;
497519

498520
if ([NSImage respondsToSelector:@selector(imageWithSize:flipped:drawingHandler:)]) {
521+
// We must be in OS X 10.8 or later
499522
image = [NSImage imageWithSize:size
500523
flipped:NO
501524
drawingHandler:^(NSRect dstRect) {

0 commit comments

Comments
 (0)