Vuo  2.3.2
VuoWindow.m
Go to the documentation of this file.
1 
10 #import "VuoWindow.h"
12 #import "VuoGraphicsWindow.h"
13 #include "VuoEventLoop.h"
14 #include "VuoCompositionState.h"
15 #include "VuoApp.h"
16 #import "VuoAppSplashWindow.h"
17 
18 #include "module.h"
19 
20 #ifdef VUO_COMPILER
22  "title" : "VuoWindow",
23  "dependencies" : [
24  "AppKit.framework",
25  "VuoGraphicsWindow",
26  "VuoWindowTextInternal"
27  ]
28  });
29 #endif
30 
32 
41 {
42  void *compositionState = vuoCopyCompositionStateFromThreadLocalStorage();
43 
44  __block VuoWindowTextInternal *window = NULL;
45  VUOLOG_PROFILE_BEGIN(mainQueue);
46  dispatch_sync(dispatch_get_main_queue(), ^{
47  VUOLOG_PROFILE_END(mainQueue);
49 
50  VuoApp_init(true);
51  window = [[VuoWindowTextInternal alloc] init];
52 
53  window.alphaValue = 0;
55  [window orderWindow:NSWindowBelow relativeTo:VuoApp_splashWindow.windowNumber];
56  else
57  [window orderFront:NSApp];
58  [window makeKeyWindow];
59 
60  [NSAnimationContext runAnimationGroup:^(NSAnimationContext *context){
61  context.duration = VuoApp_windowFadeSeconds;
62  window.animator.alphaValue = 1;
63  } completionHandler:^{}];
64 
66  free(compositionState);
67  });
69  return (VuoWindowText *)window;
70 }
71 
78 (
79  VuoWindowText w,
80  VuoOutputTrigger(typedLine, VuoText),
81  VuoOutputTrigger(typedWord, VuoText),
82  VuoOutputTrigger(typedCharacter, VuoText)
83 )
84 {
86  VUOLOG_PROFILE_BEGIN(mainQueue);
87  dispatch_sync(dispatch_get_main_queue(), ^{
88  VUOLOG_PROFILE_END(mainQueue);
89  [window enableTriggersWithTypedLine:typedLine typedWord:typedWord typedCharacter:typedCharacter];
90  });
91 }
92 
99 {
101  VUOLOG_PROFILE_BEGIN(mainQueue);
102  dispatch_sync(dispatch_get_main_queue(), ^{
103  VUOLOG_PROFILE_END(mainQueue);
104  [window disableTriggers];
105  });
106 }
107 
113 void VuoWindowText_appendLine(VuoWindowText vw, const char *text)
114 {
116  char *textCopy = text ? strdup(text) : strdup(""); // ... in case the caller frees text before the asynchronous block uses it.
117  VUOLOG_PROFILE_BEGIN(mainQueue);
118  dispatch_async(dispatch_get_main_queue(), ^{
119  VUOLOG_PROFILE_END(mainQueue);
120  [window appendLine:textCopy];
121  free(textCopy);
122  });
123 }
124 
131 {
134  [window clear];
135  });
136 }
137 
144 {
146  VuoRetain(window);
147  VUOLOG_PROFILE_BEGIN(mainQueue);
148  dispatch_sync(dispatch_get_main_queue(), ^{
149  VUOLOG_PROFILE_END(mainQueue);
150 
151  void (^completionHandler)(void) = ^{
152  [window close];
153  VuoRelease(window);
154  };
155 
156  // When fullscreen, macOS performs its own close animation, so only apply our fade-out animation when windowed.
157  if (window.styleMask & NSWindowStyleMaskFullScreen)
158  completionHandler();
159  else
160  [NSAnimationContext runAnimationGroup:^(NSAnimationContext *context){
161  context.duration = VuoApp_windowFadeSeconds;
162  window.animator.alphaValue = 0;
163  } completionHandler:completionHandler];
164  });
165 }
166 
173 {
176  [window release];
177  });
178 }
179 
180 
182 
191 (
192  void (*initCallback)(void *, float backingScaleFactor),
193  void (*updateBackingCallback)(void *, float backingScaleFactor),
194  void (*resizeCallback)(void *, unsigned int, unsigned int),
195  VuoIoSurface (*drawCallback)(void *),
196  void *context
197 )
198 {
199  __block VuoGraphicsWindow *window = NULL;
200  void *compositionState = vuoCopyCompositionStateFromThreadLocalStorage();
201 
202  VUOLOG_PROFILE_BEGIN(mainQueue);
203  dispatch_sync(dispatch_get_main_queue(), ^{
204  VUOLOG_PROFILE_END(mainQueue);
206 
207  VuoApp_init(true);
208  window = [[VuoGraphicsWindow alloc] initWithInitCallback:initCallback
209  updateBackingCallback:updateBackingCallback
210  resizeCallback:resizeCallback
211  drawCallback:drawCallback
212  userData:context];
213  window.compositionUid = vuoGetCompositionUniqueIdentifier(compositionState);
214 
215  window.alphaValue = 0;
217  [window orderWindow:NSWindowBelow relativeTo:VuoApp_splashWindow.windowNumber];
218  else
219  [window orderFront:NSApp];
220  [window makeKeyWindow];
221 
222  [NSAnimationContext runAnimationGroup:^(NSAnimationContext *context){
223  context.duration = VuoApp_windowFadeSeconds;
224  window.animator.alphaValue = 1;
225  } completionHandler:^{}];
226 
228  free(compositionState);
229  });
231  return (VuoWindowOpenGl *)window;
232 }
233 
241 (
242  VuoWindowOpenGl w,
243  VuoOutputTrigger(updatedWindow, VuoRenderedLayers)
244 )
245 {
246  VuoGraphicsWindow *window = (VuoGraphicsWindow *)w;
247  [window enableUpdatedWindowTrigger:updatedWindow];
248 }
249 
257 (
258  VuoWindowOpenGl w,
259  VuoOutputTrigger(showedWindow, VuoWindowReference),
260  VuoOutputTrigger(requestedFrame, VuoReal)
261 )
262 {
263  VuoGraphicsWindow *window = (VuoGraphicsWindow *)w;
264  [window enableShowedWindowTrigger:showedWindow requestedFrameTrigger:requestedFrame];
265 }
266 
273 {
274  VuoGraphicsWindow *window = (VuoGraphicsWindow *)w;
275  [window disableTriggers];
276 }
277 
285 {
286  VuoGraphicsWindow *window = (VuoGraphicsWindow *)w;
287  [window draw];
288 }
289 
296 {
297  VuoGraphicsWindow *window = (VuoGraphicsWindow *)w;
298  VUOLOG_PROFILE_BEGIN(mainQueue);
299  dispatch_sync(dispatch_get_main_queue(), ^{
300  VUOLOG_PROFILE_END(mainQueue);
301  [window setProperties:properties];
302  });
303 }
304 
311 void VuoWindowOpenGl_setAspectRatio(VuoWindowOpenGl w, unsigned int pixelsWide, unsigned int pixelsHigh)
312 {
313  VuoGraphicsWindow *window = (VuoGraphicsWindow *)w;
314  VUOLOG_PROFILE_BEGIN(mainQueue);
315  dispatch_async(dispatch_get_main_queue(), ^{
316  VUOLOG_PROFILE_END(mainQueue);
317  [window setAspectRatioToWidth:pixelsWide height:pixelsHigh];
318  });
319 }
320 
327 {
328  VuoGraphicsWindow *window = (VuoGraphicsWindow *)w;
329  VUOLOG_PROFILE_BEGIN(mainQueue);
330  dispatch_async(dispatch_get_main_queue(), ^{
331  VUOLOG_PROFILE_END(mainQueue);
332  [window unlockAspectRatio];
333  });
334 }
335 
342 void VuoWindowOpenGl_close(VuoWindowOpenGl vw, void (^closedHandler)(void))
343 {
344  VuoGraphicsWindow *window = (VuoGraphicsWindow *)vw;
345  VuoRetain(window);
346  VUOLOG_PROFILE_BEGIN(mainQueue);
347  dispatch_sync(dispatch_get_main_queue(), ^{
348  VUOLOG_PROFILE_END(mainQueue);
349 
350  void (^completionHandler)(void) = ^{
351  [window close];
352  VuoRelease(window);
353  closedHandler();
354  };
355 
356  // When fullscreen, macOS performs its own close animation, so only apply our fade-out animation when windowed.
357  if (window.isFullScreen)
358  completionHandler();
359  else
360  [NSAnimationContext runAnimationGroup:^(NSAnimationContext *context){
361  context.duration = VuoApp_windowFadeSeconds;
362  window.animator.alphaValue = 0;
363  } completionHandler:completionHandler];
364  });
365 }
366 
373 {
374  VuoGraphicsWindow *window = (VuoGraphicsWindow *)vw;
376  [window release];
377  });
378 }