Vuo 2.4.4
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 "VuoWindowReference.h"
16#include "VuoGraphicsWindow.h"
18#include "VuoScreenCommon.h"
19#include "VuoText.h"
20#include "VuoApp.h"
21
23#ifdef VUO_COMPILER
25 "title": "Window",
26 "version": "1.0.0",
27 "dependencies": [
28 "VuoApp",
29 "VuoGraphicsWindow",
30 "VuoGraphicsWindowDrag",
31 "VuoInteger",
32 "VuoReal",
33 "VuoScreenCommon",
34 "VuoText",
35 "AppKit.framework",
36 ],
37});
38#endif
40
47{
48 return (VuoWindowReference)window;
49}
50
54static void VuoWindowReference_releaseCallback(struct json_object *js, void *value)
55{
56 VuoRelease(value);
57}
58
64{
65 json_object *o = NULL;
66
67 if (json_object_object_get_ex(js, "pointer", &o))
68 {
69 VuoWindowReference value = (VuoWindowReference)json_object_get_int64(o);
70 json_object_set_userdata(js, (void *)value, VuoWindowReference_releaseCallback);
71 return value;
72 }
73
74 return NULL;
75}
76
82{
83 if (!value)
84 return NULL;
85
86 VuoRetain(value);
87
88 json_object *js = json_object_new_object();
89 json_object_object_add(js, "pointer", json_object_new_int64((int64_t)value));
90 return js;
91}
92
98{
99 return VuoWindowReference_getJson(value);
100}
101
107{
108 if (value == 0)
109 return strdup("No window");
110
111 __block const char *title;
113 VuoGraphicsWindow *window = (VuoGraphicsWindow *)value;
114 title = window.title.UTF8String;
115 });
116
117 return VuoText_format("Title: ā€œ%sā€", title);
118}
119
124{
125 VuoInteger width, height;
126 float backingScaleFactor;
127 VuoWindowReference_getContentSize(value, &width, &height, &backingScaleFactor);
128 return (VuoReal)width/(VuoReal)height;
129}
130
137{
138 __block VuoPoint2d position;
140 VuoGraphicsWindow *window = (VuoGraphicsWindow *)value;
141 NSRect contentRect = [window contentRectForFrameRect:window.frame];
142 NSRect mainScreenRect = ((NSScreen *)NSScreen.screens[0]).frame;
143 position.x = contentRect.origin.x;
144 position.y = mainScreenRect.size.height - contentRect.size.height - contentRect.origin.y;
145 });
146 return position;
147}
148
156void VuoWindowReference_getContentSize(const VuoWindowReference value, VuoInteger *width, VuoInteger *height, float *backingScaleFactor)
157{
159 VuoGraphicsWindow *window = (VuoGraphicsWindow *)value;
160 NSRect contentRect = [window convertRectToBacking:[window contentRectCached]];
161 *width = contentRect.size.width;
162 *height = contentRect.size.height;
163 *backingScaleFactor = [window backingScaleFactorCached];
164 });
165}
166
172{
173 NSWindow *window = (NSWindow *)value;
174 return [NSApp mainWindow] == window;
175}
176
181{
182 VuoGraphicsWindow *window = (VuoGraphicsWindow *)value;
183 return window.isFullScreen;
184}
185
190{
191 VuoGraphicsWindow *window = (VuoGraphicsWindow *)value;
192 return VuoScreen_makeFromNSScreen(window.screen);
193}
194
199 void (*dragEnteredCallback)(VuoDragEvent e),
200 void (*dragMovedToCallback)(VuoDragEvent e),
201 void (*dragCompletedCallback)(VuoDragEvent e),
202 void (*dragExitedCallback)(VuoDragEvent e))
203{
204 if (!wr)
205 return;
206
207 VuoGraphicsWindow *window = (VuoGraphicsWindow *)wr;
208 [window addDragEnteredCallback:dragEnteredCallback
209 dragMovedToCallback:dragMovedToCallback
210 dragCompletedCallback:dragCompletedCallback
211 dragExitedCallback:dragExitedCallback];
212}
213
218 void (*dragEnteredCallback)(VuoDragEvent e),
219 void (*dragMovedToCallback)(VuoDragEvent e),
220 void (*dragCompletedCallback)(VuoDragEvent e),
221 void (*dragExitedCallback)(VuoDragEvent e))
222{
223 if (!wr)
224 return;
225
226 VuoGraphicsWindow *window = (VuoGraphicsWindow *)wr;
227 [window removeDragEnteredCallback:dragEnteredCallback
228 dragMovedToCallback:dragMovedToCallback
229 dragCompletedCallback:dragCompletedCallback
230 dragExitedCallback:dragExitedCallback];
231}