Revision: 15184
http://sourceforge.net/p/skim-app/code/15184
Author: hofman
Date: 2025-05-11 14:14:19 +0000 (Sun, 11 May 2025)
Log Message:
-----------
Expose transition animation as block and let the caller execute the block.
Fully initialize rather than passing arguments.
Modified Paths:
--------------
trunk/SKPresentationView.m
trunk/SKTransitionController.h
trunk/SKTransitionController.m
Modified: trunk/SKPresentationView.m
===================================================================
--- trunk/SKPresentationView.m 2025-05-10 22:13:11 UTC (rev 15183)
+++ trunk/SKPresentationView.m 2025-05-11 14:14:19 UTC (rev 15184)
@@ -143,12 +143,15 @@
#pragma mark Accessors
+- (void)setPage:(PDFPage *)newPage completionHandler:(void
(^)(void))completionHandler {
+ page = newPage;
+ [self displayPage:completionHandler];
+ [[NSNotificationCenter defaultCenter]
postNotificationName:SKPresentationViewPageChangedNotification object:self];
+}
+
- (void)setPage:(PDFPage *)newPage {
- if (newPage != page) {
- page = newPage;
- [self displayPage:nil];
- [[NSNotificationCenter defaultCenter]
postNotificationName:SKPresentationViewPageChangedNotification object:self];
- }
+ if (newPage != page)
+ [self setPage:newPage completionHandler:nil];
}
- (BOOL)autoScales { return YES; }
@@ -155,10 +158,10 @@
#pragma mark Action
-- (NSRect)pageRect {
+- (NSRect)pageRect:(PDFPage *)aPage {
NSRect bounds = [self bounds];
- NSRect pageRect = [page boundsForBox:kPDFDisplayBoxCropBox];
- if (([page rotation] % 180) != 0)
+ NSRect pageRect = [aPage boundsForBox:kPDFDisplayBoxCropBox];
+ if (([aPage rotation] % 180) != 0)
pageRect = NSMakeRect(0.0, 0.0, NSHeight(pageRect), NSWidth(pageRect));
CGFloat scale = [self autoScales] ? fmin(NSHeight(bounds) /
NSHeight(pageRect), NSWidth(bounds) / NSWidth(pageRect)) : 1.0;
return NSInsetRect(bounds, 0.5 * (NSWidth(bounds) - scale *
NSWidth(pageRect)), 0.5 * (NSHeight(bounds) - scale * NSHeight(pageRect)));
@@ -169,18 +172,15 @@
}
- (BOOL)animateTransitionAtIndex:(NSUInteger)idx forward:(BOOL)forward
toPage:(PDFPage *)toPage {
- if ([transitionController pageTransitions] == nil &&
- ([[transitionController transition] style] == SKNoTransition ||
equalStrings([page label], [toPage label])))
- return NO;
- id animation = [transitionController animationAtIndex:idx forRect:[self
pageRect] inView:self];
- if (animation == nil)
- return NO;
- page = toPage;
- [[NSNotificationCenter defaultCenter]
postNotificationName:SKPresentationViewPageChangedNotification object:self];
- [self displayPage:^{
- [transitionController performAnimation:animation toRect:[self
pageRect] forward:forward completionHandler:nil];
- }];
- return YES;
+ if ([transitionController pageTransitions] ||
+ ([[transitionController transition] style] != SKNoTransition &&
equalStrings([page label], [toPage label]) == NO)) {
+ SKTransitionAnimation animation = [transitionController
animationAtIndex:idx forView:self fromRect:[self pageRect:page] toRect:[self
pageRect:toPage] forward:forward];
+ if (animation) {
+ [self setPage:toPage completionHandler:^{ animation(nil); }];
+ return YES;
+ }
+ }
+ return NO;
}
- (void)animateToNextPage:(void (^)(void))completionHandler {
@@ -188,12 +188,8 @@
NSUInteger idx = [page pageIndex];
if (idx + 1 < [pdfDoc pageCount]) {
PDFPage *toPage = [pdfDoc pageAtIndex:idx + 1];
- id animation = [transitionController animationAtIndex:idx
forRect:[self pageRect] inView:self];
- page = toPage;
- [[NSNotificationCenter defaultCenter]
postNotificationName:SKPresentationViewPageChangedNotification object:self];
- [self displayPage:^{
- [transitionController performAnimation:animation toRect:[self
pageRect] forward:YES completionHandler:completionHandler];
- }];
+ SKTransitionAnimation animation = [transitionController
animationAtIndex:idx forView:self fromRect:[self pageRect:page] toRect:[self
pageRect:toPage] forward:YES];
+ [self setPage:toPage completionHandler:animation ? ^{
animation(completionHandler); } : completionHandler];
} else {
completionHandler();
}
Modified: trunk/SKTransitionController.h
===================================================================
--- trunk/SKTransitionController.h 2025-05-10 22:13:11 UTC (rev 15183)
+++ trunk/SKTransitionController.h 2025-05-11 14:14:19 UTC (rev 15184)
@@ -40,6 +40,8 @@
NS_ASSUME_NONNULL_BEGIN
+typedef void (^SKTransitionAnimation)(void (^ _Nullable
completionHandler)(void));
+
@class SKTransitionView, SKTransitionInfo;
@interface SKTransitionController : NSObject {
@@ -56,8 +58,7 @@
@property (nonatomic) BOOL shouldScale;
-- (id)animationAtIndex:(NSUInteger)anIndex forRect:(NSRect)rect inView:(NSView
*)view;
-- (void)performAnimation:(nullable id)animation toRect:(NSRect)toRect
forward:(BOOL)forward completionHandler:(void (^
_Nullable)(void))completionHandler;
+- (nullable SKTransitionAnimation)animationAtIndex:(NSUInteger)anIndex
forView:(NSView *)view fromRect:(NSRect)rect toRect:(NSRect)toRect
forward:(BOOL)forward;
@end
Modified: trunk/SKTransitionController.m
===================================================================
--- trunk/SKTransitionController.m 2025-05-10 22:13:11 UTC (rev 15183)
+++ trunk/SKTransitionController.m 2025-05-11 14:14:19 UTC (rev 15184)
@@ -171,7 +171,7 @@
return image;
}
-- (id)animationAtIndex:(NSUInteger)idx forRect:(NSRect)rect inView:(NSView
*)view {
+- (SKTransitionAnimation)animationAtIndex:(NSUInteger)idx forView:(NSView
*)view fromRect:(NSRect)rect toRect:(NSRect)toRect forward:(BOOL)forward {
if (animating)
return nil;
@@ -186,7 +186,7 @@
CIImage *initialImage = [self currentImageForRect:rect inView:view
scale:NULL];
- return [^(NSRect toRect, BOOL forward, void (^completionHandler)(void)){
+ return ^(void (^completionHandler)(void)){
NSRect bounds = [view bounds];
CGFloat imageScale = 1.0;
@@ -223,16 +223,9 @@
completionHandler();
}];
- } copy];
+ };
}
-- (void)performAnimation:(id)animation toRect:(NSRect)toRect
forward:(BOOL)forward completionHandler:(void (^)(void))completionHandler {
- if (animation)
- ((void (^)(NSRect, BOOL, void(^)(void)))animation)(toRect, forward,
completionHandler);
- else if (completionHandler)
- completionHandler();
-}
-
@end
#pragma mark -
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit