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