Vuo  2.4.0
VuoWindowReference.m
Go to the documentation of this file.
1
10#include <string.h>
11
13#include <AppKit/AppKit.h>
14
15#include "type.h"
16#include "VuoWindowReference.h"
17#include "VuoGraphicsWindow.h"
19#include "VuoScreenCommon.h"
20#include "VuoText.h"
21#include "VuoApp.h"
22
24#ifdef VUO_COMPILER
26 "title": "Window",
27 "version": "1.0.0",
28 "dependencies": [
29 "VuoApp",
30 "VuoGraphicsWindow",
31 "VuoGraphicsWindowDrag",
32 "VuoInteger",
33 "VuoReal",
34 "VuoScreenCommon",
35 "VuoText",
36 "AppKit.framework",
37 ],
38});
39#endif
41
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 __block const char *title;
100 VuoGraphicsWindow *window = (VuoGraphicsWindow *)value;
101 title = window.title.UTF8String;
102 });
103
104 return VuoText_format("Title: ā€œ%sā€", title);
105}
106
111{
112 VuoInteger width, height;
113 float backingScaleFactor;
114 VuoWindowReference_getContentSize(value, &width, &height, &backingScaleFactor);
115 return (VuoReal)width/(VuoReal)height;
116}
117
124{
125 __block VuoPoint2d position;
127 VuoGraphicsWindow *window = (VuoGraphicsWindow *)value;
128 NSRect contentRect = [window contentRectForFrameRect:window.frame];
129 NSRect mainScreenRect = ((NSScreen *)NSScreen.screens[0]).frame;
130 position.x = contentRect.origin.x;
131 position.y = mainScreenRect.size.height - contentRect.size.height - contentRect.origin.y;
132 });
133 return position;
134}
135
143void VuoWindowReference_getContentSize(const VuoWindowReference value, VuoInteger *width, VuoInteger *height, float *backingScaleFactor)
144{
146 VuoGraphicsWindow *window = (VuoGraphicsWindow *)value;
147 NSRect contentRect = [window convertRectToBacking:[window contentRectCached]];
148 *width = contentRect.size.width;
149 *height = contentRect.size.height;
150 *backingScaleFactor = [window backingScaleFactorCached];
151 });
152}
153
159{
160 NSWindow *window = (NSWindow *)value;
161 return [NSApp mainWindow] == window;
162}
163
168{
169 VuoGraphicsWindow *window = (VuoGraphicsWindow *)value;
170 return window.isFullScreen;
171}
172
177{
178 VuoGraphicsWindow *window = (VuoGraphicsWindow *)value;
179 return VuoScreen_makeFromNSScreen(window.screen);
180}
181
186 void (*dragEnteredCallback)(VuoDragEvent e),
187 void (*dragMovedToCallback)(VuoDragEvent e),
188 void (*dragCompletedCallback)(VuoDragEvent e),
189 void (*dragExitedCallback)(VuoDragEvent e))
190{
191 if (!wr)
192 return;
193
194 VuoGraphicsWindow *window = (VuoGraphicsWindow *)wr;
195 [window addDragEnteredCallback:dragEnteredCallback
196 dragMovedToCallback:dragMovedToCallback
197 dragCompletedCallback:dragCompletedCallback
198 dragExitedCallback:dragExitedCallback];
199}
200
205 void (*dragEnteredCallback)(VuoDragEvent e),
206 void (*dragMovedToCallback)(VuoDragEvent e),
207 void (*dragCompletedCallback)(VuoDragEvent e),
208 void (*dragExitedCallback)(VuoDragEvent e))
209{
210 if (!wr)
211 return;
212
213 VuoGraphicsWindow *window = (VuoGraphicsWindow *)wr;
214 [window removeDragEnteredCallback:dragEnteredCallback
215 dragMovedToCallback:dragMovedToCallback
216 dragCompletedCallback:dragCompletedCallback
217 dragExitedCallback:dragExitedCallback];
218}