Revision: 15181
          http://sourceforge.net/p/skim-app/code/15181
Author:   hofman
Date:     2025-05-10 21:29:58 +0000 (Sat, 10 May 2025)
Log Message:
-----------
Separate methods for preparing transition animation and performing it after 
display, pass completion handler to be called when animation has completed.

Modified Paths:
--------------
    trunk/SKPresentationOptionsSheetController.m
    trunk/SKPresentationView.h
    trunk/SKPresentationView.m
    trunk/SKTransitionController.h
    trunk/SKTransitionController.m

Modified: trunk/SKPresentationOptionsSheetController.m
===================================================================
--- trunk/SKPresentationOptionsSheetController.m        2025-05-10 16:25:52 UTC 
(rev 15180)
+++ trunk/SKPresentationOptionsSheetController.m        2025-05-10 21:29:58 UTC 
(rev 15181)
@@ -375,7 +375,7 @@
         
         [previewView animateToNextPage:^{
             
-            DISPATCH_MAIN_AFTER_SEC(1.0 + [info duration], ^{
+            DISPATCH_MAIN_AFTER_SEC(1.0 , ^{
                 
                 if ([previewWindow isKeyWindow])
                     [[self window] makeKeyWindow];

Modified: trunk/SKPresentationView.h
===================================================================
--- trunk/SKPresentationView.h  2025-05-10 16:25:52 UTC (rev 15180)
+++ trunk/SKPresentationView.h  2025-05-10 21:29:58 UTC (rev 15181)
@@ -58,7 +58,7 @@
 - (void)goToNextPage:(nullable id)sender;
 - (void)goToPreviousPage:(nullable id)sender;
 
-- (void)animateToNextPage:(void (^)(void))didDisplay;
+- (void)animateToNextPage:(void (^)(void))completionHandler;
 
 @end
 

Modified: trunk/SKPresentationView.m
===================================================================
--- trunk/SKPresentationView.m  2025-05-10 16:25:52 UTC (rev 15180)
+++ trunk/SKPresentationView.m  2025-05-10 21:29:58 UTC (rev 15181)
@@ -155,10 +155,10 @@
 
 #pragma mark Action
 
-- (NSRect)pageRect:(PDFPage *)aPage {
+- (NSRect)pageRect {
     NSRect bounds = [self bounds];
-    NSRect pageRect = [aPage boundsForBox:kPDFDisplayBoxCropBox];
-    if (([aPage rotation] % 180) != 0)
+    NSRect pageRect = [page boundsForBox:kPDFDisplayBoxCropBox];
+    if (([page 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)));
@@ -172,26 +172,30 @@
     if ([transitionController pageTransitions] == nil &&
         ([[transitionController transition] style] == SKNoTransition || 
equalStrings([page label], [toPage label])))
         return NO;
-    [transitionController animateView:self forRect:[self pageRect:page] 
toRect:[self pageRect:toPage] atIndex:idx forward:forward change:^(void 
(^done)(void)){
-        page = toPage;
-        [self displayPage:done];
-        [[NSNotificationCenter defaultCenter] 
postNotificationName:SKPresentationViewPageChangedNotification object:self];
+    id animation = [transitionController animationForView:self atIndex:idx 
fomRect:[self pageRect]];
+    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;
 }
 
-- (void)animateToNextPage:(void (^)(void))didDisplay {
+- (void)animateToNextPage:(void (^)(void))completionHandler {
     PDFDocument *pdfDoc = [page document];
     NSUInteger idx = [page pageIndex];
     if (idx + 1 < [pdfDoc pageCount]) {
         PDFPage *toPage = [pdfDoc pageAtIndex:idx + 1];
-        [transitionController animateView:self forRect:[self pageRect:page] 
toRect:[self pageRect:toPage] atIndex:idx forward:YES change:^(void 
(^done)(void)){
-            page = toPage;
-            [self displayPage:done ? ^{ done(); didDisplay(); } : didDisplay];
-            [[NSNotificationCenter defaultCenter] 
postNotificationName:SKPresentationViewPageChangedNotification object:self];
+        id animation = [transitionController animationForView:self atIndex:idx 
fomRect:[self pageRect]];
+        page = toPage;
+        [[NSNotificationCenter defaultCenter] 
postNotificationName:SKPresentationViewPageChangedNotification object:self];
+        [self displayPage:^{
+            [transitionController performAnimation:animation toRect:[self 
pageRect] forward:YES completionHandler:completionHandler];
         }];
     } else {
-        didDisplay();
+        completionHandler();
     }
 }
 

Modified: trunk/SKTransitionController.h
===================================================================
--- trunk/SKTransitionController.h      2025-05-10 16:25:52 UTC (rev 15180)
+++ trunk/SKTransitionController.h      2025-05-10 21:29:58 UTC (rev 15181)
@@ -56,7 +56,8 @@
 
 @property (nonatomic) BOOL shouldScale;
 
-- (void)animateView:(NSView *)view forRect:(NSRect)rect toRect:(NSRect)toRect 
atIndex:(NSUInteger)anIndex forward:(BOOL)forward change:(void (^)(void (^ 
_Nullable done)(void)))change;
+- (id)animationForView:(NSView *)view atIndex:(NSUInteger)anIndex 
fomRect:(NSRect)rect;
+- (void)performAnimation:(id)animation toRect:(NSRect)toRect 
forward:(BOOL)forward completionHandler:(void (^ 
_Nullable)(void))completionHandler;
 
 @end
 

Modified: trunk/SKTransitionController.m
===================================================================
--- trunk/SKTransitionController.m      2025-05-10 16:25:52 UTC (rev 15180)
+++ trunk/SKTransitionController.m      2025-05-10 21:29:58 UTC (rev 15181)
@@ -171,69 +171,68 @@
     return image;
 }
 
-- (void)animateView:(NSView *)view forRect:(NSRect)rect toRect:(NSRect)toRect 
atIndex:(NSUInteger)idx forward:(BOOL)forward change:(void (^)(void 
(^done)(void)))change {
-    if (animating) {
-        change(nil);
-        return;
-    }
+- (id)animationForView:(NSView *)view atIndex:(NSUInteger)idx 
fomRect:(NSRect)rect {
+    if (animating)
+        return nil;
     
     SKTransitionInfo *currentTransition = transition;
     if (idx < [pageTransitions count])
         currentTransition = [[SKTransitionInfo alloc] 
initWithProperties:[pageTransitions objectAtIndex:idx]];
     
-    if ([currentTransition style] == SKNoTransition) {
+    if ([currentTransition style] == SKNoTransition)
+        return nil;
+    
+    animating = YES;
+    
+    CIImage *initialImage = [self currentImageForRect:rect inView:view 
scale:NULL];
+    
+    return [^(NSRect toRect, BOOL forward, void (^completionHandler)(void)){
         
-        change(nil);
+        NSRect bounds = [view bounds];
+        CGFloat imageScale = 1.0;
+        CIImage *finalImage = [self currentImageForRect:toRect inView:view 
scale:&imageScale];
+        CGRect cgRect = 
CGRectIntegral(scaleRect(NSIntersectionRect(NSUnionRect(rect, toRect), bounds), 
imageScale));
+        CGRect cgBounds = scaleRect(bounds, imageScale);
+        CGRect extent = [currentTransition shouldRestrict] ? cgRect : cgBounds;
+        NSString *filterName = [currentTransition styleName];
+        CGFloat scale = shouldScale ? imageScale * NSHeight(bounds) / 
NSHeight([[[view window] screen] frame]) : imageScale;
+        CIFilter *transitionFilter = [self transitionFilterWithName:filterName
+                                                               rect:cgRect
+                                                             extent:extent
+                                                              scale:scale
+                                                            forward:forward
+                                                       
initialImage:initialImage
+                                                         
finalImage:finalImage];
         
-    } else {
-        
-        animating = YES;
-        
-        CIImage *initialImage = [self currentImageForRect:rect inView:view 
scale:NULL];
-        
-        change(^{
-            
-            NSRect bounds = [view bounds];
-            CGFloat imageScale = 1.0;
-            CIImage *finalImage = [self currentImageForRect:toRect inView:view 
scale:&imageScale];
-            CGRect cgRect = 
CGRectIntegral(scaleRect(NSIntersectionRect(NSUnionRect(rect, toRect), bounds), 
imageScale));
-            CGRect cgBounds = scaleRect(bounds, imageScale);
-            CGRect extent = [currentTransition shouldRestrict] ? cgRect : 
cgBounds;
-            NSString *filterName = [currentTransition styleName];
-            CGFloat scale = shouldScale ? imageScale * NSHeight(bounds) / 
NSHeight([[[view window] screen] frame]) : imageScale;
-            CIFilter *transitionFilter = [self 
transitionFilterWithName:filterName
-                                                                   rect:cgRect
-                                                                 extent:extent
-                                                                  scale:scale
-                                                                forward:forward
-                                                           
initialImage:initialImage
-                                                             
finalImage:finalImage];
-            
-            if (transitionView == nil)
-                transitionView = [[SKTransitionView alloc] 
initWithFrame:bounds];
-            else
-                [transitionView setFrame:bounds];
-            [transitionView setExtent:cgBounds];
-            [transitionView setFilter:transitionFilter];
-            [view addSubview:transitionView positioned:NSWindowAbove 
relativeTo:nil];
+        if (transitionView == nil)
+            transitionView = [[SKTransitionView alloc] initWithFrame:bounds];
+        else
+            [transitionView setFrame:bounds];
+        [transitionView setExtent:cgBounds];
+        [transitionView setFilter:transitionFilter];
+        [view addSubview:transitionView positioned:NSWindowAbove 
relativeTo:nil];
 
-            // Update the view and its window, so it shows the correct state 
when it is shown.
-            [view display];
-            
-            [NSAnimationContext runAnimationGroup:^(NSAnimationContext 
*context){
-                    [context setDuration:[currentTransition duration]];
-                    [[transitionView animator] setProgress:1.0];
-                } completionHandler:^{
-                    [transitionView removeFromSuperview];
-                    [transitionView setFilter:nil];
-                    animating = NO;
-                }];
-            
-        });
+        [NSAnimationContext runAnimationGroup:^(NSAnimationContext *context){
+                [context setDuration:[currentTransition duration]];
+                [[transitionView animator] setProgress:1.0];
+            } completionHandler:^{
+                [transitionView removeFromSuperview];
+                [transitionView setFilter:nil];
+                animating = NO;
+                if (completionHandler)
+                    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
Skim-app-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to