Revision: 15615 http://sourceforge.net/p/skim-app/code/15615 Author: hofman Date: 2025-07-07 16:02:37 +0000 (Mon, 07 Jul 2025) Log Message: ----------- calculate point and page if needed in main dragging handler
Modified Paths: -------------- trunk/SKPDFView.m Modified: trunk/SKPDFView.m =================================================================== --- trunk/SKPDFView.m 2025-07-07 09:31:34 UTC (rev 15614) +++ trunk/SKPDFView.m 2025-07-07 16:02:37 UTC (rev 15615) @@ -3825,20 +3825,17 @@ } } -- (void)doMoveAnnotationWithEvent:(NSEvent *)theEvent offset:(NSPoint)offset { +- (void)doMoveAnnotationToPoint:(NSPoint)point onPage:(PDFPage *)page { // Move annotation. - NSPoint point = NSZeroPoint; - PDFPage *newActivePage = [self pageAndPoint:&point forEvent:theEvent nearest:YES]; - - if (newActivePage) { // newActivePage should never be nil, but just to be sure - if (newActivePage != [currentAnnotation page]) + if (page) { // page should never be nil, but just to be sure + if (page != [currentAnnotation page]) // move the annotation to the new page - [[self document] moveAnnotation:currentAnnotation toPage:newActivePage]; + [[self document] moveAnnotation:currentAnnotation toPage:page]; NSRect newBounds = [currentAnnotation bounds]; - newBounds.origin = SKIntegralPoint(SKSubstractPoints(point, offset)); + newBounds.origin = SKIntegralPoint(point); // constrain bounds inside page bounds - newBounds = SKConstrainRect(newBounds, [newActivePage boundsForBox:[self displayBox]]); + newBounds = SKConstrainRect(newBounds, [page boundsForBox:[self displayBox]]); // Change annotation's location. [currentAnnotation setBounds:newBounds]; @@ -3845,21 +3842,19 @@ } } -- (void)doResizeLineAnnotationWithEvent:(NSEvent *)theEvent fromPoint:(NSPoint)originalPagePoint originalStartPoint:(NSPoint)originalStartPoint originalEndPoint:(NSPoint)originalEndPoint resizeHandle:(SKRectEdges)resizeHandle { +- (void)doResizeLineAnnotationWithRelativePoint:(NSPoint)relPoint originalStartPoint:(NSPoint)originalStartPoint originalEndPoint:(NSPoint)originalEndPoint dragStartPoint:(BOOL)dragStartPoint shiftDown:(BOOL)shiftDown { PDFPage *page = [currentAnnotation page]; NSRect pageBounds = [page boundsForBox:[self displayBox]]; - NSPoint currentPagePoint = [self convertPoint:[theEvent locationInView:self] toPage:page]; - NSPoint relPoint = SKSubstractPoints(currentPagePoint, originalPagePoint); NSPoint endPoint = originalEndPoint; NSPoint startPoint = originalStartPoint; - NSPoint *draggedPoint = (resizeHandle & SKMinXEdgeMask) ? &startPoint : &endPoint; + NSPoint *draggedPoint = dragStartPoint ? &startPoint : &endPoint; *draggedPoint = SKConstrainPointInRect(SKAddPoints(*draggedPoint, relPoint), pageBounds); draggedPoint->x = floor(draggedPoint->x); draggedPoint->y = floor(draggedPoint->y); - if (([theEvent modifierFlags] & NSEventModifierFlagShift)) { - NSPoint *fixedPoint = (resizeHandle & SKMinXEdgeMask) ? &endPoint : &startPoint; + if (shiftDown) { + NSPoint *fixedPoint = dragStartPoint ? &endPoint : &startPoint; NSPoint diffPoint = SKSubstractPoints(*draggedPoint, *fixedPoint); CGFloat dx = fabs(diffPoint.x), dy = fabs(diffPoint.y); @@ -3893,25 +3888,14 @@ } } -- (void)doResizeAnnotationWithEvent:(NSEvent *)theEvent fromPoint:(NSPoint)originalPagePoint originalBounds:(NSRect)originalBounds originalPaths:(NSArray *)originalPaths margin:(CGFloat)margin resizeHandle:(SKRectEdges *)resizeHandlePtr { +- (void)doResizeAnnotationWithRelativePoint:(NSPoint)relPoint originalBounds:(NSRect)originalBounds originalPaths:(NSArray *)originalPaths margin:(CGFloat)margin resizeHandle:(SKRectEdges)resizeHandle shiftDown:(BOOL)shiftDown { PDFPage *page = [currentAnnotation page]; NSRect newBounds = originalBounds; NSRect pageBounds = [page boundsForBox:[self displayBox]]; - NSPoint currentPagePoint = [self convertPoint:[theEvent locationInView:self] toPage:page]; - NSPoint relPoint = SKSubstractPoints(currentPagePoint, originalPagePoint); - SKRectEdges resizeHandle = *resizeHandlePtr; CGFloat minSize = fmax(MIN_NOTE_SIZE, 2.0 * margin + 2.0); BOOL isInk = [currentAnnotation isInk]; - if (NSEqualSizes(originalBounds.size, NSZeroSize)) { - SKRectEdges currentResizeHandle = (relPoint.x < 0.0 ? SKMinXEdgeMask : SKMaxXEdgeMask) | (relPoint.y <= 0.0 ? SKMinYEdgeMask : SKMaxYEdgeMask); - if (currentResizeHandle != resizeHandle) { - *resizeHandlePtr = resizeHandle = currentResizeHandle; - [self setCursorForAreaOfInterest:SKAreaOfInterestForResizeHandle(resizeHandle, page)]; - } - } - - if (([theEvent modifierFlags] & NSEventModifierFlagShift) == 0) { + if (shiftDown == NO) { if ((resizeHandle & SKMaxXEdgeMask)) { newBounds.size.width += relPoint.x; @@ -4031,7 +4015,7 @@ CGFloat sy = fmax(1.0, NSHeight(newBounds) - 2.0 * margin) / fmax(1.0, NSHeight(originalBounds) - 2.0 * margin); [transform translateXBy:margin yBy:margin]; - if (([theEvent modifierFlags] & NSEventModifierFlagShift)) + if (shiftDown) [transform scaleBy:fmin(sx, sy)]; else [transform scaleXBy:sx yBy:sy]; @@ -4052,8 +4036,8 @@ // Old (current) annotation location and click point relative to it NSRect originalBounds = [currentAnnotation bounds]; BOOL isLine = [currentAnnotation isLine]; - NSPoint pagePoint = NSZeroPoint; - PDFPage *page = [self pageAndPoint:&pagePoint forEvent:theEvent nearest:YES]; + NSPoint initialPoint = NSZeroPoint; + PDFPage *page = [self pageAndPoint:&initialPoint forEvent:theEvent nearest:YES]; SKNoteType noteType = annotationMode; BOOL shouldAddAnnotation = currentAnnotation == nil; NSPoint originalStartPoint = NSZeroPoint; @@ -4060,23 +4044,21 @@ NSPoint originalEndPoint = NSZeroPoint; NSArray *originalPaths = nil; CGFloat margin = 0.0; - // Hit-test for resize box. - SKRectEdges resizeHandle = [currentAnnotation resizeHandleForPoint:pagePoint scaleFactor:[self scaleFactor]]; + SKRectEdges resizeHandle = [currentAnnotation resizeHandleForPoint:initialPoint scaleFactor:[self scaleFactor]]; - if (shouldAddAnnotation && temporaryToolMode >= SKToolModeFreeText) - noteType = NOTE_TYPE_FROM_TEMP_TOOL_MODE(temporaryToolMode); - atomic_store(&highlightLayerState, SKLayerAdd); - if (currentAnnotation) + if (shouldAddAnnotation == NO) [self updatedAnnotation:currentAnnotation]; if (shouldAddAnnotation) { + if (temporaryToolMode >= SKToolModeFreeText) + noteType = NOTE_TYPE_FROM_TEMP_TOOL_MODE(temporaryToolMode); if (noteType == SKNoteTypeAnchored) { - [self addAnnotationWithType:SKNoteTypeAnchored selection:nil page:page bounds:SKRectFromCenterAndSquareSize(SKIntegralPoint(pagePoint), 0.0)]; + [self addAnnotationWithType:SKNoteTypeAnchored selection:nil page:page bounds:SKRectFromCenterAndSquareSize(SKIntegralPoint(initialPoint), 0.0)]; originalBounds = [[self currentAnnotation] bounds]; } else { - originalBounds = SKRectFromCenterAndSquareSize(SKIntegralPoint(pagePoint), 0.0); + originalBounds = SKRectFromCenterAndSquareSize(SKIntegralPoint(initialPoint), 0.0); if (noteType == SKNoteTypeLine) { isLine = YES; resizeHandle = SKMaxXEdgeMask; @@ -4096,7 +4078,6 @@ // we move or resize the annotation in an event loop, which ensures it's enclosed in a single undo group BOOL draggedAnnotation = NO; NSEvent *lastMouseEvent = theEvent; - NSPoint offset = SKSubstractPoints(pagePoint, originalBounds.origin); NSUInteger eventMask = NSEventMaskLeftMouseUp | NSEventMaskLeftMouseDragged; [self setCursorForAreaOfInterest:SKAreaOfInterestForResizeHandle(resizeHandle, page)]; @@ -4104,6 +4085,8 @@ [[NSCursor closedHandCursor] push]; [NSEvent startPeriodicEventsAfterDelay:0.1 withPeriod:0.1]; eventMask |= NSEventMaskPeriodic; + + initialPoint = SKSubstractPoints(initialPoint, originalBounds.origin); } while (YES) { @@ -4125,12 +4108,25 @@ if (currentAnnotation == nil || [[[self scrollView] contentView] autoscroll:lastMouseEvent] == NO) continue; } + BOOL shiftDown = ([theEvent modifierFlags] & NSEventModifierFlagShift) != 0; + NSPoint point = [lastMouseEvent locationInView:self]; if (resizeHandle == 0) - [self doMoveAnnotationWithEvent:lastMouseEvent offset:offset]; - else if (isLine) - [self doResizeLineAnnotationWithEvent:lastMouseEvent fromPoint:pagePoint originalStartPoint:originalStartPoint originalEndPoint:originalEndPoint resizeHandle:resizeHandle]; - else - [self doResizeAnnotationWithEvent:lastMouseEvent fromPoint:pagePoint originalBounds:originalBounds originalPaths:originalPaths margin:margin resizeHandle:&resizeHandle]; + page = [self pageForPoint:point nearest:YES]; + point = SKSubstractPoints([self convertPoint:point toPage:page], initialPoint); + if (resizeHandle == 0) { + [self doMoveAnnotationToPoint:point onPage:page]; + } else if (isLine) { + [self doResizeLineAnnotationWithRelativePoint:point originalStartPoint:originalStartPoint originalEndPoint:originalEndPoint dragStartPoint:(resizeHandle & SKMinXEdgeMask) != 0 shiftDown:shiftDown]; + } else { + if (shouldAddAnnotation) { + SKRectEdges currentResizeHandle = (point.x < 0.0 ? SKMinXEdgeMask : SKMaxXEdgeMask) | (point.y <= 0.0 ? SKMinYEdgeMask : SKMaxYEdgeMask); + if (currentResizeHandle != resizeHandle) { + resizeHandle = currentResizeHandle; + [self setCursorForAreaOfInterest:SKAreaOfInterestForResizeHandle(resizeHandle, page)]; + } + } + [self doResizeAnnotationWithRelativePoint:point originalBounds:originalBounds originalPaths:originalPaths margin:margin resizeHandle:resizeHandle shiftDown:shiftDown]; + } [[highlightLayerController layer] setNeedsDisplay]; } 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