Vuo  2.3.2
VuoAppSplashWindow.m
Go to the documentation of this file.
1 
10 #include "VuoMacOSSDKWorkaround.h"
11 #import <AppKit/AppKit.h>
12 
13 #import "VuoAppSplashWindow.h"
14 
15 #import "VuoApp.h"
16 #import "VuoAppSplashView.h"
17 
18 #import "VuoConfig.h"
19 
21 NSWindow *VuoApp_splashWindow = nil;
23 const double VuoApp_splashWindowWidth = 640;
25 const double VuoApp_splashWindowHeight = 384;
26 
31 {
32  VuoApp_splashWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, VuoApp_splashWindowWidth, VuoApp_splashWindowHeight)
33  styleMask:NSWindowStyleMaskBorderless
34  backing:NSBackingStoreBuffered
35  defer:NO];
36  VuoApp_splashWindow.animationBehavior = NSWindowAnimationBehaviorNone;
37  VuoApp_splashWindow.hasShadow = YES;
38 
39  NSView *view = [VuoAppSplashView new];
40  VuoApp_splashWindow.contentView = view;
41  [view release];
42 
43  [VuoApp_splashWindow center];
44  VuoApp_splashWindow.alphaValue = 0;
45  [VuoApp_splashWindow makeKeyAndOrderFront:nil];
46 
47  [NSCursor.pointingHandCursor push];
48 
49 
50  // Fade in.
51  // Can't simply use `+[NSAnimationContext runAnimationGroup:]` here,
52  // since it has no effect on OS X 10.10 and macOS 10.12,
53  // possibly because we're processing events ourselves below
54  // rather than using the main event loop.
55  // (But `-[NSRunLoop.mainRunLoop runUntilDate:…]` and `-[NSRunLoop.currentRunLoop runUntilDate:…]` don't work either.)
56 
57  double splashFadeSeconds = VuoApp_windowFadeSeconds * 2;
58 // [NSAnimationContext runAnimationGroup:^(NSAnimationContext *context){
59 // context.duration = splashFadeSeconds;
60 // VuoApp_splashWindow.animator.alphaValue = 0;
61 // } completionHandler:^{
62 // VLog("finished fading in: %g",VuoApp_splashWindow.alphaValue);
63 // }];
64  double t0 = VuoLogGetElapsedTime();
65  do
66  {
67  NSEvent *event = [VuoApp_splashWindow nextEventMatchingMask:NSEventMaskAny
68  untilDate:[NSDate dateWithTimeIntervalSinceNow:1./60]
69  inMode:NSDefaultRunLoopMode
70  dequeue:YES];
71  [VuoApp_splashWindow sendEvent:event];
72  VuoApp_splashWindow.alphaValue = (VuoLogGetElapsedTime() - t0) / splashFadeSeconds;
73  } while (t0 + splashFadeSeconds > VuoLogGetElapsedTime());
74 
75 
76  // Hold.
77  // Can't simply use `-[NSRunLoop runUntilDate:]` here,
78  // since that doesn't immediately process the `-[NSWorkspace openURL:]` message.
79  double splashHoldSeconds = 1;
80  t0 = VuoLogGetElapsedTime();
81  do
82  {
83  NSEvent *event = [VuoApp_splashWindow nextEventMatchingMask:NSEventMaskAny
84  untilDate:[NSDate dateWithTimeIntervalSinceNow:splashHoldSeconds]
85  inMode:NSDefaultRunLoopMode
86  dequeue:YES];
87  [VuoApp_splashWindow sendEvent:event];
88  } while (t0 + splashHoldSeconds > VuoLogGetElapsedTime());
89 
90 
91  // Fade out.
92  // `+[NSAnimationContext runAnimationGroup:]` does work here on OS X 10.10,
93  // possibly because we're using the main event loop (see below).
94  [NSAnimationContext runAnimationGroup:^(NSAnimationContext *context){
95  context.duration = splashFadeSeconds;
96  VuoApp_splashWindow.animator.alphaValue = 0;
97  } completionHandler:^{
98  [VuoApp_splashWindow close];
99  VuoApp_splashWindow = nil;
100  }];
101 
102  [NSCursor.pointingHandCursor pop];
103 
104  // Return immediately and let the main event loop handle the fadeout
105  // (so the composition's windows can simultaneously fade in).
106 }