Revision: 15141
          http://sourceforge.net/p/skim-app/code/15141
Author:   hofman
Date:     2025-05-02 16:10:26 +0000 (Fri, 02 May 2025)
Log Message:
-----------
Generate tooltip image on thread immediately, so it has a good change to be 
available after the delay. Show when both the image is generated and the 
delayed message is delivered.

Modified Paths:
--------------
    trunk/SKImageToolTipWindow.h
    trunk/SKImageToolTipWindow.m

Modified: trunk/SKImageToolTipWindow.h
===================================================================
--- trunk/SKImageToolTipWindow.h        2025-05-02 08:45:04 UTC (rev 15140)
+++ trunk/SKImageToolTipWindow.h        2025-05-02 16:10:26 UTC (rev 15141)
@@ -47,6 +47,8 @@
     NSPoint point;
     CGFloat scale;
     NSImageView *imageView;
+    NSImage *image;
+    BOOL shouldShow;
 }
 
 @property (class, nonatomic, readonly) SKImageToolTipWindow 
*sharedToolTipWindow;

Modified: trunk/SKImageToolTipWindow.m
===================================================================
--- trunk/SKImageToolTipWindow.m        2025-05-02 08:45:04 UTC (rev 15140)
+++ trunk/SKImageToolTipWindow.m        2025-05-02 16:10:26 UTC (rev 15141)
@@ -111,6 +111,8 @@
 - (void)orderOut:(id)sender {
     context = nil;
     point = NSZeroPoint;
+    image = nil;
+    shouldShow = NO;
     [super orderOut:sender];
 }
 
@@ -118,57 +120,43 @@
     // ignore any currently generating image
     context = nil;
     point = NSZeroPoint;
+    image = nil;
+    shouldShow = NO;
     [super fadeOut];
 }
 
-- (void)showDelayed {
-    id<SKImageToolTipContext> theContext = context;
-    NSNumber *usedScaleNumber = [[NSUserDefaults standardUserDefaults] 
objectForKey:SKToolTipScaleKey];
-    CGFloat usedScale = [usedScaleNumber 
respondsToSelector:@selector(doubleValue)] ? [usedScaleNumber doubleValue] : 
DEFAULT_SCALE;
-    if (usedScale <= 0.0)
-        usedScale = usedScale < 0.0 ? fmin(scale, -usedScale) : scale;
+- (void)show {
+    [imageView setImage:image];
     
-    dispatch_async([[self class] imageQueue], ^{
-        
-        NSImage *image = [theContext toolTipImageWithScale:usedScale];
-        
-        dispatch_async(dispatch_get_main_queue(), ^{
-            // check if another image is enerated or we are fading out
-            if (theContext != context)
-                return;
-            
-            if (image) {
-                BOOL isOpaque = [[[image representations] firstObject] 
isOpaque];
-                
-                [imageView setImage:image];
-                
-                [[self contentView] setContentFilters:isOpaque ? 
SKColorEffectFilters() : @[]];
-                
-                NSPoint thePoint = NSEqualPoints(point, NSZeroPoint) ? 
[NSEvent mouseLocation] : point;
-                NSRect screenRect = [[NSScreen screenForPoint:thePoint] frame];
-                NSRect contentRect = NSZeroRect;
-                contentRect.size = [image size];
-                contentRect.origin.x = fmin(thePoint.x, NSMaxX(screenRect) - 
NSWidth(contentRect));
-                contentRect.origin.y = thePoint.y - WINDOW_OFFSET - 
NSHeight(contentRect);
-                contentRect = [self frameRectForContentRect:contentRect];
-                if (NSMinY(contentRect) < NSMinX(screenRect))
-                    contentRect.origin.y = thePoint.y + WINDOW_OFFSET;
-                [self setFrame:contentRect display:NO];
-                
-                if ([self isVisible] && [self alphaValue] > 
CRITICAL_ALPHA_VALUE)
-                    [self orderFront:self];
-                else
-                    [self fadeIn];
-                
-            } else {
-                
-                [self fadeOut];
-                
-            }
-        });
-    });
+    BOOL isOpaque = [[[image representations] firstObject] isOpaque];
+    [[self contentView] setContentFilters:isOpaque ? SKColorEffectFilters() : 
@[]];
+    
+    NSPoint thePoint = NSEqualPoints(point, NSZeroPoint) ? [NSEvent 
mouseLocation] : point;
+    NSRect screenRect = [[NSScreen screenForPoint:thePoint] frame];
+    NSRect contentRect = NSZeroRect;
+    contentRect.size = [image size];
+    contentRect.origin.x = fmin(thePoint.x, NSMaxX(screenRect) - 
NSWidth(contentRect));
+    contentRect.origin.y = thePoint.y - WINDOW_OFFSET - NSHeight(contentRect);
+    contentRect = [self frameRectForContentRect:contentRect];
+    if (NSMinY(contentRect) < NSMinX(screenRect))
+        contentRect.origin.y = thePoint.y + WINDOW_OFFSET;
+    [self setFrame:contentRect display:NO];
+    
+    if ([self isVisible] && [self alphaValue] > CRITICAL_ALPHA_VALUE)
+        [self orderFront:self];
+    else
+        [self fadeIn];
+    
+    image = nil;
+    shouldShow = NO;
 }
 
+- (void)showDelayed {
+    shouldShow = YES;
+    if (image)
+        [self show];
+}
+
 - (void)stopAnimation {
     [super stopAnimation];
     [[self class] cancelPreviousPerformRequestsWithTarget:self 
selector:@selector(showDelayed) object:nil];
@@ -182,7 +170,29 @@
         [self stopAnimation];
         
         context = aContext;
+        image = nil;
+        shouldShow = NO;
         
+        NSNumber *usedScaleNumber = [[NSUserDefaults standardUserDefaults] 
objectForKey:SKToolTipScaleKey];
+        CGFloat usedScale = [usedScaleNumber 
respondsToSelector:@selector(doubleValue)] ? [usedScaleNumber doubleValue] : 
DEFAULT_SCALE;
+        if (usedScale <= 0.0)
+            usedScale = usedScale < 0.0 ? fmin(scale, -usedScale) : scale;
+        dispatch_async([[self class] imageQueue], ^{
+            
+            NSImage *anImage = [aContext toolTipImageWithScale:usedScale];
+            
+            dispatch_async(dispatch_get_main_queue(), ^{
+                // check if another image is enerated or we are fading out
+                if (aContext == context) {
+                    image = anImage;
+                    if (image == nil)
+                        [self fadeOut];
+                    else if (shouldShow)
+                        [self show];
+                }
+            });
+        });
+        
         [self performSelector:@selector(showDelayed) withObject:nil 
afterDelay:[self isVisible] ? ALT_SHOW_DELAY : DEFAULT_SHOW_DELAY];
     }
 }

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