Revision: 4908
http://skim-app.svn.sourceforge.net/skim-app/?rev=4908&view=rev
Author: hofman
Date: 2008-11-03 11:26:08 +0000 (Mon, 03 Nov 2008)
Log Message:
-----------
Implement pinch zoom in snapshot and split PDF
Modified Paths:
--------------
trunk/BDSKZoomablePDFView.h
trunk/BDSKZoomablePDFView.m
trunk/SKSecondaryPDFView.h
trunk/SKSecondaryPDFView.m
Modified: trunk/BDSKZoomablePDFView.h
===================================================================
--- trunk/BDSKZoomablePDFView.h 2008-11-01 13:25:05 UTC (rev 4907)
+++ trunk/BDSKZoomablePDFView.h 2008-11-03 11:26:08 UTC (rev 4908)
@@ -45,6 +45,7 @@
PDFPage *autoFitPage;
NSRect autoFitRect;
BOOL autoFits;
+ float pinchZoomFactor;
}
- (BOOL)autoFits;
Modified: trunk/BDSKZoomablePDFView.m
===================================================================
--- trunk/BDSKZoomablePDFView.m 2008-11-01 13:25:05 UTC (rev 4907)
+++ trunk/BDSKZoomablePDFView.m 2008-11-03 11:26:08 UTC (rev 4908)
@@ -41,6 +41,16 @@
#import "NSScrollView_SKExtensions.h"
[EMAIL PROTECTED] NSResponder (BDSKGesturesPrivate)
+- (void)magnifyWithEvent:(NSEvent *)theEvent;
+- (void)beginGestureWithEvent:(NSEvent *)theEvent;
+- (void)endGestureWithEvent:(NSEvent *)theEvent;
[EMAIL PROTECTED]
+
[EMAIL PROTECTED] NSEvent (BDSKGesturesPrivate)
+- (float)magnification;
[EMAIL PROTECTED]
+
@implementation BDSKZoomablePDFView
/* For genstrings:
@@ -74,6 +84,7 @@
scalePopUpButton = nil;
autoFitPage = nil;
autoFitRect = NSZeroRect;
+ pinchZoomFactor = 1.0;
[self makeScalePopUpButton];
@@ -90,6 +101,7 @@
scalePopUpButton = nil;
autoFitPage = nil;
autoFitRect = NSZeroRect;
+ pinchZoomFactor = 1.0;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handlePDFViewFrameChangedNotification:)
name:NSViewFrameDidChangeNotification object:self];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handlePDFViewFrameChangedNotification:)
@@ -241,6 +253,13 @@
return count - 1;
}
+- (unsigned int)indexForScaleFactor:(float)scaleFactor {
+ unsigned int lower = [self lowerIndexForScaleFactor:scaleFactor], upper =
[self upperIndexForScaleFactor:scaleFactor];
+ if (upper > lower && scaleFactor < 0.5 *
(BDSKDefaultScaleMenuFactors[lower] + BDSKDefaultScaleMenuFactors[upper]))
+ return lower;
+ return upper;
+}
+
- (void)setScaleFactor:(float)newScaleFactor {
[self setScaleFactor:newScaleFactor adjustPopup:YES];
}
@@ -251,11 +270,7 @@
if (newScaleFactor < 0.01) {
newScaleFactor = 0.0;
} else {
- unsigned int i = [self lowerIndexForScaleFactor:newScaleFactor],
upper = [self upperIndexForScaleFactor:newScaleFactor];
- if (upper > i) {
- if (newScaleFactor > 0.5 * (BDSKDefaultScaleMenuFactors[i] +
BDSKDefaultScaleMenuFactors[upper]))
- i = upper;
- }
+ unsigned int i = [self indexForScaleFactor:newScaleFactor];
[scalePopUpButton selectItemAtIndex:i];
newScaleFactor = BDSKDefaultScaleMenuFactors[i];
}
@@ -390,6 +405,34 @@
}
}
+#pragma mark Gestures
+
+- (void)beginGestureWithEvent:(NSEvent *)theEvent {
+ if ([[BDSKZoomablePDFView superclass] instancesRespondToSelector:_cmd])
+ [super beginGestureWithEvent:theEvent];
+ pinchZoomFactor = 1.0;
+}
+
+- (void)endGestureWithEvent:(NSEvent *)theEvent {
+ if (fabsf(pinchZoomFactor - 1.0) > 0.1)
+ [self setScaleFactor:fmaxf(pinchZoomFactor * [self scaleFactor],
BDSKDefaultScaleMenuFactors[1])];
+ pinchZoomFactor = 1.0;
+ if ([[BDSKZoomablePDFView superclass] instancesRespondToSelector:_cmd])
+ [super endGestureWithEvent:theEvent];
+}
+
+- (void)magnifyWithEvent:(NSEvent *)theEvent {
+ if ([theEvent respondsToSelector:@selector(magnification)]) {
+ pinchZoomFactor *= 1.0 + fmaxf(-0.5, fminf(1.0 , [theEvent
magnification]));
+ float scaleFactor = pinchZoomFactor * [self scaleFactor];
+ unsigned int i = [self indexForScaleFactor:fmaxf(scaleFactor,
BDSKDefaultScaleMenuFactors[1])];
+ if (i != [self indexForScaleFactor:[self scaleFactor]]) {
+ [self setScaleFactor:BDSKDefaultScaleMenuFactors[i]];
+ pinchZoomFactor = scaleFactor / [self scaleFactor];
+ }
+ }
+}
+
#pragma mark Dragging
- (void)mouseDown:(NSEvent *)theEvent{
Modified: trunk/SKSecondaryPDFView.h
===================================================================
--- trunk/SKSecondaryPDFView.h 2008-11-01 13:25:05 UTC (rev 4907)
+++ trunk/SKSecondaryPDFView.h 2008-11-03 11:26:08 UTC (rev 4908)
@@ -46,6 +46,7 @@
PDFView *synchronizedPDFView;
BOOL synchronizeZoom;
BOOL switching;
+ float pinchZoomFactor;
}
- (PDFView *)synchronizedPDFView;
Modified: trunk/SKSecondaryPDFView.m
===================================================================
--- trunk/SKSecondaryPDFView.m 2008-11-01 13:25:05 UTC (rev 4907)
+++ trunk/SKSecondaryPDFView.m 2008-11-03 11:26:08 UTC (rev 4908)
@@ -44,6 +44,16 @@
#import "SKStringConstants.h"
[EMAIL PROTECTED] NSResponder (BDSKGesturesPrivate)
+- (void)magnifyWithEvent:(NSEvent *)theEvent;
+- (void)beginGestureWithEvent:(NSEvent *)theEvent;
+- (void)endGestureWithEvent:(NSEvent *)theEvent;
[EMAIL PROTECTED]
+
[EMAIL PROTECTED] NSEvent (BDSKGesturesPrivate)
+- (float)magnification;
[EMAIL PROTECTED]
+
@interface SKSecondaryPDFView (SKPrivate)
- (void)makePopUpButtons;
@@ -94,6 +104,7 @@
pagePopUpButton = nil;
synchronizedPDFView = nil;
synchronizeZoom = NO;
+ pinchZoomFactor = 1.0;
[self makePopUpButtons];
@@ -364,6 +375,13 @@
return count - 1;
}
+- (unsigned int)indexForScaleFactor:(float)scaleFactor {
+ unsigned int lower = [self lowerIndexForScaleFactor:scaleFactor], upper =
[self upperIndexForScaleFactor:scaleFactor];
+ if (upper > lower && scaleFactor < 0.5 * (SKDefaultScaleMenuFactors[lower]
+ SKDefaultScaleMenuFactors[upper]))
+ return lower;
+ return upper;
+}
+
- (void)setScaleFactor:(float)newScaleFactor {
BOOL savedSwitching = switching;
switching = YES;
@@ -384,11 +402,7 @@
if (newScaleFactor < 0.01) {
newScaleFactor = 0.0;
} else {
- unsigned int i = [self lowerIndexForScaleFactor:newScaleFactor],
upper = [self upperIndexForScaleFactor:newScaleFactor];
- if (upper > i) {
- if (newScaleFactor > 0.5 * (SKDefaultScaleMenuFactors[i] +
SKDefaultScaleMenuFactors[upper]))
- i = upper;
- }
+ unsigned int i = [self indexForScaleFactor:newScaleFactor];
[scalePopUpButton selectItemAtIndex:i];
newScaleFactor = SKDefaultScaleMenuFactors[i];
}
@@ -522,6 +536,34 @@
}
}
+#pragma mark Gestures
+
+- (void)beginGestureWithEvent:(NSEvent *)theEvent {
+ if ([[SKSecondaryPDFView superclass] instancesRespondToSelector:_cmd])
+ [super beginGestureWithEvent:theEvent];
+ pinchZoomFactor = 1.0;
+}
+
+- (void)endGestureWithEvent:(NSEvent *)theEvent {
+ if (fabsf(pinchZoomFactor - 1.0) > 0.1)
+ [self setScaleFactor:fmaxf(pinchZoomFactor * [self scaleFactor],
SKDefaultScaleMenuFactors[2])];
+ pinchZoomFactor = 1.0;
+ if ([[SKSecondaryPDFView superclass] instancesRespondToSelector:_cmd])
+ [super endGestureWithEvent:theEvent];
+}
+
+- (void)magnifyWithEvent:(NSEvent *)theEvent {
+ if ([theEvent respondsToSelector:@selector(magnification)]) {
+ pinchZoomFactor *= 1.0 + fmaxf(-0.5, fminf(1.0 , [theEvent
magnification]));
+ float scaleFactor = pinchZoomFactor * [self scaleFactor];
+ unsigned int i = [self indexForScaleFactor:fmaxf(scaleFactor,
SKDefaultScaleMenuFactors[2])];
+ if (i != [self indexForScaleFactor:[self scaleFactor]]) {
+ [self setScaleFactor:SKDefaultScaleMenuFactors[i]];
+ pinchZoomFactor = scaleFactor / [self scaleFactor];
+ }
+ }
+}
+
#pragma mark Dragging
- (void)mouseDown:(NSEvent *)theEvent{
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 the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit