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 
24 #ifdef VUO_COMPILER
26  "title" : "Window",
27  "version" : "1.0.0",
28  "dependencies" : [
29  "VuoGraphicsWindow",
30  "VuoGraphicsWindowDrag",
31  "VuoInteger",
32  "VuoReal",
33  "VuoText",
34  "AppKit.framework"
35  ]
36  });
37 #endif
38 
46 {
47  return (VuoWindowReference)window;
48 }
49 
55 {
56  json_object *o = NULL;
57 
58  if (json_object_object_get_ex(js, "pointer", &o))
59  return (VuoWindowReference)json_object_get_int64(o);
60 
61  return NULL;
62 }
63 
69 {
70  if (!value)
71  return NULL;
72 
73  json_object *js = json_object_new_object();
74  json_object_object_add(js, "pointer", json_object_new_int64((int64_t)value));
75  return js;
76 }
77 
83 {
84  return VuoWindowReference_getJson(value);
85 }
86 
92 {
93  if (value == 0)
94  return strdup("No window");
95 
96  return VuoText_format("window ID %p", value);
97 }
98 
103 {
104  VuoInteger width, height;
105  float backingScaleFactor;
106  VuoWindowReference_getContentSize(value, &width, &height, &backingScaleFactor);
107  return (VuoReal)width/(VuoReal)height;
108 }
109 
117 void VuoWindowReference_getContentSize(const VuoWindowReference value, VuoInteger *width, VuoInteger *height, float *backingScaleFactor)
118 {
119  VuoGraphicsWindow *window = (VuoGraphicsWindow *)value;
120  NSRect contentRect = [window convertRectToBacking:[window contentRectCached]];
121  *width = contentRect.size.width;
122  *height = contentRect.size.height;
123  *backingScaleFactor = [window backingScaleFactorCached];
124 }
125 
131 {
132  NSWindow *window = (NSWindow *)value;
133  return [NSApp mainWindow] == window;
134 }
135 
140 {
141  VuoGraphicsWindow *window = (VuoGraphicsWindow *)value;
142  return window.isFullScreen;
143 }
144 
149  void (*dragEnteredCallback)(VuoDragEvent e),
150  void (*dragMovedToCallback)(VuoDragEvent e),
151  void (*dragCompletedCallback)(VuoDragEvent e),
152  void (*dragExitedCallback)(VuoDragEvent e))
153 {
154  if (!wr)
155  return;
156 
157  VuoGraphicsWindow *window = (VuoGraphicsWindow *)wr;
158  [window addDragEnteredCallback:dragEnteredCallback
159  dragMovedToCallback:dragMovedToCallback
160  dragCompletedCallback:dragCompletedCallback
161  dragExitedCallback:dragExitedCallback];
162 }
163 
168  void (*dragEnteredCallback)(VuoDragEvent e),
169  void (*dragMovedToCallback)(VuoDragEvent e),
170  void (*dragCompletedCallback)(VuoDragEvent e),
171  void (*dragExitedCallback)(VuoDragEvent e))
172 {
173  if (!wr)
174  return;
175 
176  VuoGraphicsWindow *window = (VuoGraphicsWindow *)wr;
177  [window removeDragEnteredCallback:dragEnteredCallback
178  dragMovedToCallback:dragMovedToCallback
179  dragCompletedCallback:dragCompletedCallback
180  dragExitedCallback:dragExitedCallback];
181 }