Revision: 12670
          http://sourceforge.net/p/skim-app/code/12670
Author:   hofman
Date:     2022-01-01 22:02:55 +0000 (Sat, 01 Jan 2022)
Log Message:
-----------
move repeated code to select a rect to separate method

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

Modified: trunk/SKPDFView.m
===================================================================
--- trunk/SKPDFView.m   2022-01-01 21:26:05 UTC (rev 12669)
+++ trunk/SKPDFView.m   2022-01-01 22:02:55 UTC (rev 12670)
@@ -4648,10 +4648,11 @@
     [self performSelector:@selector(setCursorForMouse:) withObject:theEvent 
afterDelay:0];
 }
 
-- (void)doSelectSnapshotWithEvent:(NSEvent *)theEvent {
+
+- (NSRect)doSelectRectWithEvent:(NSEvent *)theEvent didDrag:(BOOL *)didDrag {
     NSPoint mouseLoc = [theEvent locationInWindow];
-       NSPoint startPoint = [[self documentView] convertPoint:mouseLoc 
fromView:nil];
-       NSPoint currentPoint;
+    NSPoint startPoint = [[self documentView] convertPoint:mouseLoc 
fromView:nil];
+    NSPoint currentPoint;
     NSRect selRect = {startPoint, NSZeroSize};
     BOOL dragged = NO;
     CAShapeLayer *layer = nil;
@@ -4658,8 +4659,6 @@
     NSWindow *overlay = nil;
     NSWindow *window = [self window];
     
-    [[NSCursor cameraCursor] set];
-       
     CGRect layerRect = NSRectToCGRect([self visibleContentRect]);
     layer = [CAShapeLayer layer];
     [layer setStrokeColor:CGColorGetConstantColor(kCGColorBlack)];
@@ -4672,8 +4671,8 @@
     
     overlay = [self newOverlayLayer:layer];
     
-       while (YES) {
-               theEvent = [window nextEventMatchingMask: NSLeftMouseUpMask | 
NSLeftMouseDraggedMask | NSFlagsChangedMask];
+    while (YES) {
+        theEvent = [window nextEventMatchingMask: NSLeftMouseUpMask | 
NSLeftMouseDraggedMask | NSFlagsChangedMask];
         
         if ([theEvent type] == NSLeftMouseUp)
             break;
@@ -4706,6 +4705,18 @@
     [self removeLayer:layer overlay:overlay];
     [overlay release];
 
+    [self setCursorForMouse:theEvent];
+    
+    *didDrag = dragged;
+    return selRect;
+}
+
+- (void)doSelectSnapshotWithEvent:(NSEvent *)theEvent {
+    [[NSCursor cameraCursor] set];
+    
+    BOOL dragged = NO;
+    NSRect selRect = [self doSelectRectWithEvent:theEvent didDrag:&dragged];
+    
        [self setCursorForMouse:theEvent];
     
     NSPoint point = [self convertPoint:SKCenterPoint(selRect) fromView:[self 
documentView]];
@@ -5059,63 +5070,11 @@
 }
 
 - (void)doMarqueeZoomWithEvent:(NSEvent *)theEvent {
-    NSPoint mouseLoc = [theEvent locationInWindow];
-    NSPoint startPoint = [[self documentView] convertPoint:mouseLoc 
fromView:nil];
-    NSPoint    currentPoint;
-    NSRect selRect = {startPoint, NSZeroSize};
-    BOOL dragged = NO;
-    CAShapeLayer *layer = nil;
-    NSWindow *overlay = nil;
-    NSWindow *window = [self window];
-    
     [[NSCursor zoomInCursor] set];
     
-    CGRect layerRect = NSRectToCGRect([self visibleContentRect]);
-    layer = [CAShapeLayer layer];
-    [layer setStrokeColor:CGColorGetConstantColor(kCGColorBlack)];
-    [layer setFillColor:NULL];
-    [layer setLineWidth:1.0];
-    [layer setFrame:layerRect];
-    [layer setBounds:layerRect];
-    [layer setMasksToBounds:YES];
-    [layer setZPosition:1.0];
+    BOOL dragged = NO;
+    NSRect selRect = [self doSelectRectWithEvent:theEvent didDrag:&dragged];
     
-    overlay = [self newOverlayLayer:layer];
-    
-    while (YES) {
-        theEvent = [window nextEventMatchingMask: NSLeftMouseUpMask | 
NSLeftMouseDraggedMask | NSFlagsChangedMask];
-        
-        if ([theEvent type] == NSLeftMouseUp)
-            break;
-        
-        if ([theEvent type] == NSLeftMouseDragged) {
-            // change mouseLoc
-            [[[self scrollView] contentView] autoscroll:theEvent];
-            mouseLoc = [theEvent locationInWindow];
-            dragged = YES;
-        }
-        
-        // dragging or flags changed
-        
-        currentPoint = [[self documentView] convertPoint:mouseLoc 
fromView:nil];
-        
-        // center around startPoint when holding down the Shift key
-        if (([theEvent modifierFlags] & NSShiftKeyMask))
-            selRect = SKRectFromCenterAndPoint(startPoint, currentPoint);
-        else
-            selRect = SKRectFromPoints(startPoint, currentPoint);
-        
-        // 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);
-        [layer setPath:path];
-        CGPathRelease(path);
-    }
-    
-    [self removeLayer:layer overlay:overlay];
-    [overlay release];
-    
     [self setCursorForMouse:theEvent];
     
     if (dragged && NSIsEmptyRect(selRect) == NO) {

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