Revision: 3264
          http://skim-app.svn.sourceforge.net/skim-app/?rev=3264&view=rev
Author:   hofman
Date:     2007-11-25 14:36:59 -0800 (Sun, 25 Nov 2007)

Log Message:
-----------
Copy layer code from bibdesk to draw gradient in splitview.

Modified Paths:
--------------
    trunk/SKSplitView.h
    trunk/SKSplitView.m

Modified: trunk/SKSplitView.h
===================================================================
--- trunk/SKSplitView.h 2007-11-25 19:43:19 UTC (rev 3263)
+++ trunk/SKSplitView.h 2007-11-25 22:36:59 UTC (rev 3264)
@@ -42,6 +42,7 @@
 
 @interface SKSplitView : NSSplitView {
     BOOL blendEnds;
+    CGLayerRef dividerLayer;
 }
 + (CIColor *)startColor;
 + (CIColor *)endColor;

Modified: trunk/SKSplitView.m
===================================================================
--- trunk/SKSplitView.m 2007-11-25 19:43:19 UTC (rev 3263)
+++ trunk/SKSplitView.m 2007-11-25 22:36:59 UTC (rev 3264)
@@ -58,6 +58,20 @@
    return endColor;
 }
 
+- (id)initWithFrame:(NSRect)frameRect{
+    if (self = [super initWithFrame:frameRect]) {
+        blendEnds = NO;
+        dividerLayer = NULL;
+    }
+    return self;
+}
+
+- (void)dealloc {
+    if (dividerLayer)
+        CGLayerRelease(dividerLayer);
+    [super dealloc];
+}
+
 - (void)mouseDown:(NSEvent *)theEvent {
     if ([theEvent clickCount] > 1 && [[self delegate] 
respondsToSelector:@selector(splitView:doubleClickedDividerAt:)]) {
         NSPoint mouseLoc = [self convertPoint:[theEvent locationInWindow] 
fromView:nil];
@@ -87,14 +101,20 @@
 }
 
 - (void)drawDividerInRect:(NSRect)aRect {
-    NSPoint startPoint, endPoint;
-    float handleSize = 20.0;
-    NSColor *darkColor = [NSColor colorWithCalibratedWhite:0.6 alpha:1.0];
-    NSColor *lightColor = [NSColor colorWithCalibratedWhite:0.95 alpha:1.0];
+    CGContextRef currentContext = [[NSGraphicsContext currentContext] 
graphicsPort];
+    if (NULL == dividerLayer) {
+        CGSize dividerSize = CGSizeMake(aRect.size.width, aRect.size.height);
+        dividerLayer = CGLayerCreateWithContext(currentContext, dividerSize, 
NULL);
+        [NSGraphicsContext saveGraphicsState];
+        NSGraphicsContext *nsContext = [NSGraphicsContext 
graphicsContextWithGraphicsPort:CGLayerGetContext(dividerLayer) flipped:NO];
+        [NSGraphicsContext setCurrentContext:nsContext];
+        NSRect rectToFill = aRect;
+        rectToFill.origin = NSZeroPoint;
+        [[NSBezierPath bezierPathWithRect:rectToFill] fillPathVertically:NO == 
[self isVertical] withStartColor:[[self class] startColor] endColor:[[self 
class] endColor]];
+        [NSGraphicsContext restoreGraphicsState];
+    }
+    CGContextDrawLayerInRect(currentContext, *(CGRect *)&aRect, dividerLayer);
     
-    // Draw the gradient
-    [[NSBezierPath bezierPathWithRect:aRect] fillPathVertically:NO == [self 
isVertical] withStartColor:[[self class] startColor] endColor:[[self class] 
endColor]];
-    
     if (blendEnds) {
         NSRect endRect, ignored;
         NSDivideRect(aRect, &endRect, &ignored, END_JOIN_WIDTH, [self 
isVertical] ? NSMinYEdge : NSMinXEdge);
@@ -106,8 +126,12 @@
     [NSGraphicsContext saveGraphicsState];
     
     // Draw the handle
+    NSPoint startPoint, endPoint;
+    float handleSize = 20.0;
+    NSColor *darkColor = [NSColor colorWithCalibratedWhite:0.6 alpha:1.0];
+    NSColor *lightColor = [NSColor colorWithCalibratedWhite:0.95 alpha:1.0];
+    
     [NSBezierPath setDefaultLineWidth:1.0];
-    
     if ([self isVertical]) {
         handleSize = fminf(handleSize, 2.0 * floorf(0.5 * NSHeight(aRect)));
         startPoint = NSMakePoint(NSMinX(aRect) + 1.5, NSMidY(aRect) - 0.5 * 
handleSize);


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to