Revision: 13160
          http://sourceforge.net/p/skim-app/code/13160
Author:   hofman
Date:     2022-11-09 18:16:11 +0000 (Wed, 09 Nov 2022)
Log Message:
-----------
use highlight layer also for temporary rectangular selection

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

Modified: trunk/SKPDFView.h
===================================================================
--- trunk/SKPDFView.h   2022-11-09 17:38:57 UTC (rev 13159)
+++ trunk/SKPDFView.h   2022-11-09 18:16:11 UTC (rev 13160)
@@ -149,8 +149,6 @@
     
     SKSyncDot *syncDot;
     
-    CAShapeLayer *rectLayer;
-    
     SKLayerController *highlightLayerController;
     _Atomic(NSInteger) highlightLayerState;
     

Modified: trunk/SKPDFView.m
===================================================================
--- trunk/SKPDFView.m   2022-11-09 17:38:57 UTC (rev 13159)
+++ trunk/SKPDFView.m   2022-11-09 18:16:11 UTC (rev 13160)
@@ -175,9 +175,11 @@
 @interface SKLayerController : NSObject <CALayerDelegate> {
     CALayer *layer;
     id<SKLayerDelegate> delegate;
+    NSRect rect;
 }
 @property (nonatomic, retain) CALayer *layer;
 @property (nonatomic, assign) id<SKLayerDelegate> delegate;
+@property (nonatomic) NSRect rect;
 @end
 
 #pragma mark -
@@ -363,7 +365,7 @@
     SKDESTROY(readingBar);
     SKDESTROY(editor);
     SKDESTROY(highlightAnnotation);
-    SKDESTROY(rectLayer);
+    SKDESTROY(highlightLayerController);
     SKDESTROY(rewindPage);
     [super dealloc];
 }
@@ -527,16 +529,27 @@
 }
 
 - (void)drawLayerController:(SKLayerController *)controller 
inContext:(CGContextRef)context {
-    if (activeAnnotation == nil)
-        return;
-    PDFPage *page = [activeAnnotation page];
-    NSPoint offset = SKSubstractPoints([self convertRect:[page 
boundsForBox:[self displayBox]]fromPage:page].origin, [self 
visibleContentRect].origin);
-    CGContextSaveGState(context);
-    CGContextTranslateCTM(context, offset.x, offset.y);
-    CGContextScaleCTM(context, [self scaleFactor], [self scaleFactor]);
-    [page transformContext:context forBox:[self displayBox]];
-    [activeAnnotation drawSelectionHighlightForView:self inContext:context];
-    CGContextRestoreGState(context);
+    if (atomic_load(&highlightLayerState) == SKLayerUse) {
+        if (activeAnnotation == nil)
+            return;
+        PDFPage *page = [activeAnnotation page];
+        NSPoint offset = SKSubstractPoints([self convertRect:[page 
boundsForBox:[self displayBox]]fromPage:page].origin, [self 
visibleContentRect].origin);
+        CGContextSaveGState(context);
+        CGContextTranslateCTM(context, offset.x, offset.y);
+        CGContextScaleCTM(context, [self scaleFactor], [self scaleFactor]);
+        [page transformContext:context forBox:[self displayBox]];
+        [activeAnnotation drawSelectionHighlightForView:self 
inContext:context];
+        CGContextRestoreGState(context);
+    } else {
+        NSRect rect = [controller rect];
+        if (NSEqualRects(rect, NSZeroRect))
+            
+        CGContextSaveGState(context);
+        CGContextSetStrokeColorWithColor(context, 
CGColorGetConstantColor(kCGColorBlack));
+        CGContextSetLineWidth(context, 1.0);
+        CGContextStrokeRect(context, NSRectToCGRect(rect));
+        CGContextRestoreGState(context);
+    }
 }
 
 - (void)makeHighlightLayer {
@@ -565,24 +578,6 @@
     SKDESTROY(highlightLayerController);
 }
 
-- (void)makeRectLayer {
-    if (rectLayer) {
-        [rectLayer removeFromSuperlayer];
-        [rectLayer release];
-    }
-    rectLayer = [[CAShapeLayer alloc] init];
-    [rectLayer setStrokeColor:CGColorGetConstantColor(kCGColorBlack)];
-    [rectLayer setFillColor:NULL];
-    [rectLayer setLineWidth:1.0];
-    [rectLayer setFrame:NSRectToCGRect([self visibleContentRect])];
-    [rectLayer setBounds:[rectLayer frame]];
-    [rectLayer setMasksToBounds:YES];
-    [rectLayer setZPosition:1.0];
-    [rectLayer setContentsScale:[[self layer] contentsScale]];
-    [rectLayer setFilters:SKColorEffectFilters()];
-    [[self layer] addSublayer:rectLayer];
-}
-
 #pragma mark Accessors
 
 - (void)setDocument:(PDFDocument *)document {
@@ -1018,16 +1013,13 @@
         [highlightAnnotation release];
         highlightAnnotation = [annotation retain];
         if (highlightAnnotation) {
-            if (rectLayer == nil)
-                [self makeRectLayer];
+            if (highlightLayerController == nil)
+                [self makeHighlightLayer];
             
             NSRect rect = [self backingAlignedRect:[self 
convertRect:[highlightAnnotation bounds] fromPage:[highlightAnnotation page]] 
options:NSAlignAllEdgesOutward];
-            CGPathRef path = 
CGPathCreateWithRect(CGRectInset(NSRectToCGRect(rect), -0.5, -0.5), NULL);
-            [rectLayer setPath:path];
-            CGPathRelease(path);
-        } else if (rectLayer) {
-            [rectLayer removeFromSuperlayer];
-            SKDESTROY(rectLayer);
+            [highlightLayerController setRect:NSInsetRect(rect, -0.5, -0.5)];
+        } else if (highlightLayerController) {
+            [self removeHighlightLayer];
         }
     }
 }
@@ -4847,7 +4839,7 @@
     BOOL dragged = NO;
     NSWindow *window = [self window];
     
-    [self makeRectLayer];
+    [self makeHighlightLayer];
     
     while (YES) {
         theEvent = [window nextEventMatchingMask: NSLeftMouseUpMask | 
NSLeftMouseDraggedMask | NSFlagsChangedMask];
@@ -4875,13 +4867,11 @@
         // intersect with the bounds, project on the bounds if necessary and 
allow zero width or height
         selRect = SKIntersectionRect(selRect, [[self documentView] bounds]);
         
-        CGPathRef path = 
CGPathCreateWithRect(NSRectToCGRect(NSInsetRect(NSIntegralRect([self 
convertRect:selRect fromView:[self documentView]]), 0.5, 0.5)), NULL);
-        [rectLayer setPath:path];
-        CGPathRelease(path);
+        [highlightLayerController setRect:NSInsetRect(NSIntegralRect([self 
convertRect:selRect fromView:[self documentView]]), 0.5, 0.5)];
+        [[highlightLayerController layer] setNeedsDisplay];
     }
     
-    [rectLayer removeFromSuperlayer];
-    SKDESTROY(rectLayer);
+    [self removeHighlightLayer];
 
     [self setCursorForMouse:theEvent];
     
@@ -5413,7 +5403,7 @@
 
 @implementation SKLayerController
 
-@synthesize layer, delegate;
+@synthesize layer, delegate, rect;
 
 - (void)dealloc {
     delegate = nil;

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



_______________________________________________
Skim-app-commit mailing list
Skim-app-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to