Vuo 2.4.2
Loading...
Searching...
No Matches
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
55static void VuoWindowReference_releaseCallback(struct json_object *js, void *value)
56{
57 VuoRelease(value);
58}
59
65{
66 json_object *o = NULL;
67
68 if (json_object_object_get_ex(js, "pointer", &o))
69 {
70 VuoWindowReference value = (VuoWindowReference)json_object_get_int64(o);
71 json_object_set_userdata(js, (void *)value, VuoWindowReference_releaseCallback);
72 return value;
73 }
74
75 return NULL;
76}
77
83{
84 if (!value)
85 return NULL;
86
87 VuoRetain(value);
88
89 json_object *js = json_object_new_object();
90 json_object_object_add(js, "pointer", json_object_new_int64((int64_t)value));
91 return js;
92}
93
99{
100 return VuoWindowReference_getJson(value);
101}
102
108{
109 if (value == 0)
110 return strdup("No window");
111
112 __block const char *title;
114 VuoGraphicsWindow *window = (VuoGraphicsWindow *)value;
115 title = window.title.UTF8String;
116 });
117
118 return VuoText_format("Title: ā€œ%sā€", title);
119}
120
125{
126 VuoInteger width, height;
127 float backingScaleFactor;
128 VuoWindowReference_getContentSize(value, &width, &height, &backingScaleFactor);
129 return (VuoReal)width/(VuoReal)height;
130}
131
138{
139 __block VuoPoint2d position;
141 VuoGraphicsWindow *window = (VuoGraphicsWindow *)value;
142 NSRect contentRect = [window contentRectForFrameRect:window.frame];
143 NSRect mainScreenRect = ((NSScreen *)NSScreen.screens[0]).frame;
144 position.x = contentRect.origin.x;
145 position.y = mainScreenRect.size.height - contentRect.size.height - contentRect.origin.y;
146 });
147 return position;
148}
149
157void VuoWindowReference_getContentSize(const VuoWindowReference value, VuoInteger *width, VuoInteger *height, float *backingScaleFactor)
158{
160 VuoGraphicsWindow *window = (VuoGraphicsWindow *)value;
161 NSRect contentRect = [window convertRectToBacking:[window contentRectCached]];
162 *width = contentRect.size.width;
163 *height = contentRect.size.height;
164 *backingScaleFactor = [window backingScaleFactorCached];
165 });
166}
167
173{
174 NSWindow *window = (NSWindow *)value;
175 return [NSApp mainWindow] == window;
176}
177
182{
183 VuoGraphicsWindow *window = (VuoGraphicsWindow *)value;
184 return window.isFullScreen;
185}
186
191{
192 VuoGraphicsWindow *window = (VuoGraphicsWindow *)value;
193 return VuoScreen_makeFromNSScreen(window.screen);
194}
195
200 void (*dragEnteredCallback)(VuoDragEvent e),
201 void (*dragMovedToCallback)(VuoDragEvent e),
202 void (*dragCompletedCallback)(VuoDragEvent e),
203 void (*dragExitedCallback)(VuoDragEvent e))
204{
205 if (!wr)
206 return;
207
208 VuoGraphicsWindow *window = (VuoGraphicsWindow *)wr;
209 [window addDragEnteredCallback:dragEnteredCallback
210 dragMovedToCallback:dragMovedToCallback
211 dragCompletedCallback:dragCompletedCallback
212 dragExitedCallback:dragExitedCallback];
213}
214
219 void (*dragEnteredCallback)(VuoDragEvent e),
220 void (*dragMovedToCallback)(VuoDragEvent e),
221 void (*dragCompletedCallback)(VuoDragEvent e),
222 void (*dragExitedCallback)(VuoDragEvent e))
223{
224 if (!wr)
225 return;
226
227 VuoGraphicsWindow *window = (VuoGraphicsWindow *)wr;
228 [window removeDragEnteredCallback:dragEnteredCallback
229 dragMovedToCallback:dragMovedToCallback
230 dragCompletedCallback:dragCompletedCallback
231 dragExitedCallback:dragExitedCallback];
232}