Vuo  2.0.0
VuoWindowReference.m
Go to the documentation of this file.
1 
10 #include <string.h>
11 
12 #ifndef NS_RETURNS_INNER_POINTER
13 #define NS_RETURNS_INNER_POINTER
14 #endif
15 #include <AppKit/AppKit.h>
16 
17 #include "type.h"
18 #include "VuoWindowReference.h"
19 #include "VuoGraphicsWindow.h"
20 #include "VuoGraphicsWindowDrag.h"
21 #include "VuoText.h"
22 #include "VuoApp.h"
23 
25 #ifdef VUO_COMPILER
27  "title" : "Window",
28  "version" : "1.0.0",
29  "dependencies" : [
30  "VuoApp",
31  "VuoGraphicsWindow",
32  "VuoGraphicsWindowDrag",
33  "VuoInteger",
34  "VuoReal",
35  "VuoText",
36  "AppKit.framework"
37  ]
38  });
39 #endif
40 
48 {
49  return (VuoWindowReference)window;
50 }
51 
57 {
58  json_object *o = NULL;
59 
60  if (json_object_object_get_ex(js, "pointer", &o))
61  return (VuoWindowReference)json_object_get_int64(o);
62 
63  return NULL;
64 }
65 
71 {
72  if (!value)
73  return NULL;
74 
75  json_object *js = json_object_new_object();
76  json_object_object_add(js, "pointer", json_object_new_int64((int64_t)value));
77  return js;
78 }
79 
85 {
86  return VuoWindowReference_getJson(value);
87 }
88 
94 {
95  if (value == 0)
96  return strdup("No window");
97 
98  return VuoText_format("window ID %p", value);
99 }
100 
105 {
106  VuoInteger width, height;
107  float backingScaleFactor;
108  VuoWindowReference_getContentSize(value, &width, &height, &backingScaleFactor);
109  return (VuoReal)width/(VuoReal)height;
110 }
111 
119 void VuoWindowReference_getContentSize(const VuoWindowReference value, VuoInteger *width, VuoInteger *height, float *backingScaleFactor)
120 {
122  VuoGraphicsWindow *window = (VuoGraphicsWindow *)value;
123  NSRect contentRect = [window convertRectToBacking:[window contentRectCached]];
124  *width = contentRect.size.width;
125  *height = contentRect.size.height;
126  *backingScaleFactor = [window backingScaleFactorCached];
127  });
128 }
129 
135 {
136  NSWindow *window = (NSWindow *)value;
137  return [NSApp mainWindow] == window;
138 }
139 
144 {
145  VuoGraphicsWindow *window = (VuoGraphicsWindow *)value;
146  return window.isFullScreen;
147 }
148 
153  void (*dragEnteredCallback)(VuoDragEvent e),
154  void (*dragMovedToCallback)(VuoDragEvent e),
155  void (*dragCompletedCallback)(VuoDragEvent e),
156  void (*dragExitedCallback)(VuoDragEvent e))
157 {
158  if (!wr)
159  return;
160 
161  VuoGraphicsWindow *window = (VuoGraphicsWindow *)wr;
162  [window addDragEnteredCallback:dragEnteredCallback
163  dragMovedToCallback:dragMovedToCallback
164  dragCompletedCallback:dragCompletedCallback
165  dragExitedCallback:dragExitedCallback];
166 }
167 
172  void (*dragEnteredCallback)(VuoDragEvent e),
173  void (*dragMovedToCallback)(VuoDragEvent e),
174  void (*dragCompletedCallback)(VuoDragEvent e),
175  void (*dragExitedCallback)(VuoDragEvent e))
176 {
177  if (!wr)
178  return;
179 
180  VuoGraphicsWindow *window = (VuoGraphicsWindow *)wr;
181  [window removeDragEnteredCallback:dragEnteredCallback
182  dragMovedToCallback:dragMovedToCallback
183  dragCompletedCallback:dragCompletedCallback
184  dragExitedCallback:dragExitedCallback];
185 }