Vuo  2.1.2
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 "VuoScreenCommon.h"
22 #include "VuoText.h"
23 #include "VuoApp.h"
24 
26 #ifdef VUO_COMPILER
28  "title": "Window",
29  "version": "1.0.0",
30  "dependencies": [
31  "VuoApp",
32  "VuoGraphicsWindow",
33  "VuoGraphicsWindowDrag",
34  "VuoInteger",
35  "VuoReal",
36  "VuoScreenCommon",
37  "VuoText",
38  "AppKit.framework",
39  ],
40 });
41 #endif
42 
50 {
51  return (VuoWindowReference)window;
52 }
53 
59 {
60  json_object *o = NULL;
61 
62  if (json_object_object_get_ex(js, "pointer", &o))
63  return (VuoWindowReference)json_object_get_int64(o);
64 
65  return NULL;
66 }
67 
73 {
74  if (!value)
75  return NULL;
76 
77  json_object *js = json_object_new_object();
78  json_object_object_add(js, "pointer", json_object_new_int64((int64_t)value));
79  return js;
80 }
81 
87 {
88  return VuoWindowReference_getJson(value);
89 }
90 
96 {
97  if (value == 0)
98  return strdup("No window");
99 
100  __block const char *title;
102  VuoGraphicsWindow *window = (VuoGraphicsWindow *)value;
103  title = window.title.UTF8String;
104  });
105 
106  return VuoText_format("Title: ā€œ%sā€", title);
107 }
108 
113 {
114  VuoInteger width, height;
115  float backingScaleFactor;
116  VuoWindowReference_getContentSize(value, &width, &height, &backingScaleFactor);
117  return (VuoReal)width/(VuoReal)height;
118 }
119 
126 {
127  __block VuoPoint2d position;
129  VuoGraphicsWindow *window = (VuoGraphicsWindow *)value;
130  NSRect contentRect = [window contentRectForFrameRect:window.frame];
131  NSRect mainScreenRect = ((NSScreen *)NSScreen.screens[0]).frame;
132  position.x = contentRect.origin.x;
133  position.y = mainScreenRect.size.height - contentRect.size.height - contentRect.origin.y;
134  });
135  return position;
136 }
137 
145 void VuoWindowReference_getContentSize(const VuoWindowReference value, VuoInteger *width, VuoInteger *height, float *backingScaleFactor)
146 {
148  VuoGraphicsWindow *window = (VuoGraphicsWindow *)value;
149  NSRect contentRect = [window convertRectToBacking:[window contentRectCached]];
150  *width = contentRect.size.width;
151  *height = contentRect.size.height;
152  *backingScaleFactor = [window backingScaleFactorCached];
153  });
154 }
155 
161 {
162  NSWindow *window = (NSWindow *)value;
163  return [NSApp mainWindow] == window;
164 }
165 
170 {
171  VuoGraphicsWindow *window = (VuoGraphicsWindow *)value;
172  return window.isFullScreen;
173 }
174 
179 {
180  VuoGraphicsWindow *window = (VuoGraphicsWindow *)value;
181  return VuoScreen_makeFromNSScreen(window.screen);
182 }
183 
188  void (*dragEnteredCallback)(VuoDragEvent e),
189  void (*dragMovedToCallback)(VuoDragEvent e),
190  void (*dragCompletedCallback)(VuoDragEvent e),
191  void (*dragExitedCallback)(VuoDragEvent e))
192 {
193  if (!wr)
194  return;
195 
196  VuoGraphicsWindow *window = (VuoGraphicsWindow *)wr;
197  [window addDragEnteredCallback:dragEnteredCallback
198  dragMovedToCallback:dragMovedToCallback
199  dragCompletedCallback:dragCompletedCallback
200  dragExitedCallback:dragExitedCallback];
201 }
202 
207  void (*dragEnteredCallback)(VuoDragEvent e),
208  void (*dragMovedToCallback)(VuoDragEvent e),
209  void (*dragCompletedCallback)(VuoDragEvent e),
210  void (*dragExitedCallback)(VuoDragEvent e))
211 {
212  if (!wr)
213  return;
214 
215  VuoGraphicsWindow *window = (VuoGraphicsWindow *)wr;
216  [window removeDragEnteredCallback:dragEnteredCallback
217  dragMovedToCallback:dragMovedToCallback
218  dragCompletedCallback:dragCompletedCallback
219  dragExitedCallback:dragExitedCallback];
220 }