Revision: 5696
http://skim-app.svn.sourceforge.net/skim-app/?rev=5696&view=rev
Author: hofman
Date: 2009-09-06 21:44:13 +0000 (Sun, 06 Sep 2009)
Log Message:
-----------
use NSGradient for gradient view and status bar
Modified Paths:
--------------
trunk/BDSKGradientView.h
trunk/BDSKGradientView.m
trunk/SKStatusBar.h
trunk/SKStatusBar.m
Modified: trunk/BDSKGradientView.h
===================================================================
--- trunk/BDSKGradientView.h 2009-09-06 18:43:55 UTC (rev 5695)
+++ trunk/BDSKGradientView.h 2009-09-06 21:44:13 UTC (rev 5696)
@@ -42,16 +42,15 @@
@interface BDSKGradientView : NSView
{
@private
- CIColor *lowerColor;
- CIColor *upperColor;
- CGLayerRef layer;
+ NSColor *lowerColor;
+ NSColor *upperColor;
}
- (void)setLowerColor:(NSColor *)color;
- (void)setUpperColor:(NSColor *)color;
// for subclassers
-- (CIColor *)lowerColor;
-- (CIColor *)upperColor;
+- (NSColor *)lowerColor;
+- (NSColor *)upperColor;
@end
Modified: trunk/BDSKGradientView.m
===================================================================
--- trunk/BDSKGradientView.m 2009-09-06 18:43:55 UTC (rev 5695)
+++ trunk/BDSKGradientView.m 2009-09-06 21:44:13 UTC (rev 5696)
@@ -37,8 +37,6 @@
*/
#import "BDSKGradientView.h"
-#import "NSBezierPath_CoreImageExtensions.h"
-#import "CIImage_BDSKExtensions.h"
@interface BDSKGradientView (Private)
@@ -52,101 +50,43 @@
{
self = [super initWithFrame:frame];
[self setDefaultColors];
- layer = NULL;
return self;
}
- (void)dealloc
{
- CGLayerRelease(layer);
[lowerColor release];
[upperColor release];
[super dealloc];
}
-- (void)setBounds:(NSRect)aRect
-{
- // since the gradient is vertical, we only have to reset the layer if the
height changes; for most of our gradient views, this isn't likely to happen
- if (ABS(NSHeight(aRect) - NSHeight([self bounds])) > 0.01) {
- CGLayerRelease(layer);
- layer = NULL;
- }
- [super setBounds:aRect];
-}
-
-- (void)setBoundsSize:(NSSize)aSize
-{
- // since the gradient is vertical, we only have to reset the layer if the
height changes; for most of our gradient views, this isn't likely to happen
- if (ABS(aSize.height - NSHeight([self bounds])) > 0.01) {
- CGLayerRelease(layer);
- layer = NULL;
- }
- [super setBoundsSize:aSize];
-}
-
-- (void)setFrame:(NSRect)aRect
-{
- // since the gradient is vertical, we only have to reset the layer if the
height changes; for most of our gradient views, this isn't likely to happen
- if (ABS(NSHeight(aRect) - NSHeight([self frame])) > 0.01) {
- CGLayerRelease(layer);
- layer = NULL;
- }
- [super setFrame:aRect];
-}
-
-- (void)setFrameSize:(NSSize)aSize
-{
- // since the gradient is vertical, we only have to reset the layer if the
height changes; for most of our gradient views, this isn't likely to happen
- if (ABS(aSize.height - NSHeight([self frame])) > 0.01) {
- CGLayerRelease(layer);
- layer = NULL;
- }
- [super setFrameSize:aSize];
-}
-
- (void)drawRect:(NSRect)aRect
{
// fill entire view, not just the (possibly clipped) aRect
if ([[self window] styleMask] & NSClosableWindowMask) {
-
- CGContextRef viewContext = [[NSGraphicsContext currentContext]
graphicsPort];
- NSRect bounds = [self bounds];
-
- if (NULL == layer) {
- NSSize layerSize = bounds.size;
- layer = CGLayerCreateWithContext(viewContext,
NSSizeToCGSize(layerSize), NULL);
-
- CGContextRef layerContext = CGLayerGetContext(layer);
- [NSGraphicsContext saveGraphicsState];
- [NSGraphicsContext setCurrentContext:[NSGraphicsContext
graphicsContextWithGraphicsPort:layerContext flipped:NO]];
- NSRect layerRect = NSZeroRect;
- layerRect.size = layerSize;
-
- [[NSBezierPath bezierPathWithRect:bounds]
fillPathVerticallyWithStartColor:[self lowerColor] endColor:[self upperColor]];
- [NSGraphicsContext restoreGraphicsState];
- }
-
- // normal blend mode is copy
- CGContextSetBlendMode(viewContext, kCGBlendModeNormal);
- CGContextDrawLayerInRect(viewContext, NSRectToCGRect(bounds), layer);
+ NSGradient *gradient = [[[NSGradient alloc]
initWithStartingColor:lowerColor endingColor:upperColor] autorelease];
+ [gradient drawInRect:[self bounds] angle:90.0];
}
}
-// -[CIColor initWithColor:] fails (returns nil) with +[NSColor gridColor]
rdar://problem/4789043
- (void)setLowerColor:(NSColor *)color
{
- [lowerColor autorelease];
- lowerColor = [[CIColor colorWithNSColor:color] retain];
+ if (lowerColor != color) {
+ [lowerColor release];
+ lowerColor = [color retain];
+ }
}
- (void)setUpperColor:(NSColor *)color
{
- [upperColor autorelease];
- upperColor = [[CIColor colorWithNSColor:color] retain];
+ if (upperColor != color) {
+ [upperColor release];
+ upperColor = [color retain];
+ }
}
-- (CIColor *)lowerColor { return lowerColor; }
-- (CIColor *)upperColor { return upperColor; }
+- (NSColor *)lowerColor { return lowerColor; }
+- (NSColor *)upperColor { return upperColor; }
// required in order for redisplay to work properly with the controls
- (BOOL)isOpaque{ return ([[self window] styleMask] & NSClosableWindowMask)
!= 0; }
Modified: trunk/SKStatusBar.h
===================================================================
--- trunk/SKStatusBar.h 2009-09-06 18:43:55 UTC (rev 5695)
+++ trunk/SKStatusBar.h 2009-09-06 21:44:13 UTC (rev 5696)
@@ -50,13 +50,12 @@
id leftCell;
id rightCell;
NSProgressIndicator *progressIndicator;
- CGLayerRef layer;
NSTrackingRectTag leftTrackingRectTag;
NSTrackingRectTag rightTrackingRectTag;
}
-+ (CIColor *)lowerColor;
-+ (CIColor *)upperColor;
++ (NSColor *)lowerColor;
++ (NSColor *)upperColor;
- (void)toggleBelowView:(NSView *)view offset:(CGFloat)offset;
Modified: trunk/SKStatusBar.m
===================================================================
--- trunk/SKStatusBar.m 2009-09-06 18:43:55 UTC (rev 5695)
+++ trunk/SKStatusBar.m 2009-09-06 21:44:13 UTC (rev 5696)
@@ -37,7 +37,6 @@
*/
#import "SKStatusBar.h"
-#import "NSBezierPath_CoreImageExtensions.h"
#import "NSGeometry_SKExtensions.h"
#define LEFT_MARGIN 5.0
@@ -58,17 +57,17 @@
@implementation SKStatusBar
-+ (CIColor *)lowerColor{
- static CIColor *lowerColor = nil;
++ (NSColor *)lowerColor{
+ static NSColor *lowerColor = nil;
if (lowerColor == nil)
- lowerColor = [[CIColor alloc] initWithColor:[NSColor
colorWithCalibratedWhite:0.75 alpha:1.0]];
+ lowerColor = [[NSColor colorWithCalibratedWhite:0.75 alpha:1.0]
retain];
return lowerColor;
}
-+ (CIColor *)upperColor{
- static CIColor *upperColor = nil;
++ (NSColor *)upperColor{
+ static NSColor *upperColor = nil;
if (upperColor == nil)
- upperColor = [[CIColor alloc] initWithColor:[NSColor
colorWithCalibratedWhite:0.9 alpha:1.0]];
+ upperColor = [[NSColor colorWithCalibratedWhite:0.9 alpha:1.0] retain];
return upperColor;
}
@@ -86,7 +85,6 @@
[rightCell setControlView:self];
[rightCell setBackgroundStyle:NSBackgroundStyleRaised];
progressIndicator = nil;
- layer = NULL;
leftTrackingRectTag = 0;
rightTrackingRectTag = 0;
}
@@ -94,7 +92,6 @@
}
- (void)dealloc {
- CGLayerRelease(layer);
[leftCell release];
[rightCell release];
[super dealloc];
@@ -104,46 +101,6 @@
- (BOOL)isFlipped { return NO; }
-- (void)setBounds:(NSRect)aRect
-{
- // since the gradient is vertical, we only have to reset the layer if the
height changes; for most of our gradient views, this isn't likely to happen
- if (ABS(NSHeight(aRect) - NSHeight([self bounds])) > 0.01) {
- CGLayerRelease(layer);
- layer = NULL;
- }
- [super setBounds:aRect];
-}
-
-- (void)setBoundsSize:(NSSize)aSize
-{
- // since the gradient is vertical, we only have to reset the layer if the
height changes; for most of our gradient views, this isn't likely to happen
- if (ABS(aSize.height - NSHeight([self bounds])) > 0.01) {
- CGLayerRelease(layer);
- layer = NULL;
- }
- [super setBoundsSize:aSize];
-}
-
-- (void)setFrame:(NSRect)aRect
-{
- // since the gradient is vertical, we only have to reset the layer if the
height changes; for most of our gradient views, this isn't likely to happen
- if (ABS(NSHeight(aRect) - NSHeight([self frame])) > 0.01) {
- CGLayerRelease(layer);
- layer = NULL;
- }
- [super setFrame:aRect];
-}
-
-- (void)setFrameSize:(NSSize)aSize
-{
- // since the gradient is vertical, we only have to reset the layer if the
height changes; for most of our gradient views, this isn't likely to happen
- if (ABS(aSize.height - NSHeight([self frame])) > 0.01) {
- CGLayerRelease(layer);
- layer = NULL;
- }
- [super setFrameSize:aSize];
-}
-
- (void)getLeftFrame:(NSRect *)leftFrame rightFrame:(NSRect *)rightFrame {
CGFloat leftWidth = [[leftCell stringValue] length] ? [leftCell
cellSize].width : 0.0;
CGFloat rightWidth = [[rightCell stringValue] length] ? [rightCell
cellSize].width : 0.0;
@@ -160,36 +117,17 @@
}
- (void)drawRect:(NSRect)rect {
-
- CGContextRef viewContext = [[NSGraphicsContext currentContext]
graphicsPort];
NSRect bounds = [self bounds];
+ NSGradient *gradient = [[[NSGradient alloc] initWithStartingColor:[[self
class] lowerColor] endingColor:[[self class] upperColor]] autorelease];
- if (NULL == layer) {
- NSSize layerSize = bounds.size;
- layer = CGLayerCreateWithContext(viewContext,
NSSizeToCGSize(layerSize), NULL);
-
- CGContextRef layerContext = CGLayerGetContext(layer);
- [NSGraphicsContext saveGraphicsState];
- [NSGraphicsContext setCurrentContext:[NSGraphicsContext
graphicsContextWithGraphicsPort:layerContext flipped:NO]];
- NSRect layerRect = NSZeroRect;
- layerRect.size = layerSize;
-
- [[NSBezierPath bezierPathWithRect:bounds]
fillPathVerticallyWithStartColor:[[self class] lowerColor] endColor:[[self
class] upperColor]];
- [NSGraphicsContext restoreGraphicsState];
- }
+ [gradient drawInRect:bounds angle:90.0];
- // normal blend mode is copy
- CGContextSaveGState(viewContext);
- CGContextSetBlendMode(viewContext, kCGBlendModeNormal);
- CGContextDrawLayerInRect(viewContext, NSRectToCGRect(bounds), layer);
- CGContextRestoreGState(viewContext);
-
NSRect textRect, ignored;
CGFloat rightMargin = RIGHT_MARGIN;
-
+
if (progressIndicator)
rightMargin += NSWidth([progressIndicator frame]) + SEPARATION;
- NSDivideRect([self bounds], &ignored, &textRect, LEFT_MARGIN, NSMinXEdge);
+ NSDivideRect(bounds, &ignored, &textRect, LEFT_MARGIN, NSMinXEdge);
NSDivideRect(textRect, &ignored, &textRect, rightMargin, NSMaxXEdge);
if (textRect.size.width < 0.0)
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit