Vuo
2.4.4
Loading...
Searching...
No Matches
type
VuoWindowReference.m
Go to the documentation of this file.
1
10
#include <string.h>
11
12
#include "
VuoMacOSSDKWorkaround.h
"
13
#include <AppKit/AppKit.h>
14
15
#include "
VuoWindowReference.h
"
16
#include "
VuoGraphicsWindow.h
"
17
#include "
VuoGraphicsWindowDrag.h
"
18
#include "
VuoScreenCommon.h
"
19
#include "
VuoText.h
"
20
#include "
VuoApp.h
"
21
23
#ifdef VUO_COMPILER
24
VuoModuleMetadata
({
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
46
VuoWindowReference
VuoWindowReference_make
(
void
*window)
47
{
48
return
(
VuoWindowReference
)window;
49
}
50
54
static
void
VuoWindowReference_releaseCallback
(
struct
json_object *js,
void
*value)
55
{
56
VuoRelease
(value);
57
}
58
63
VuoWindowReference
VuoWindowReference_makeFromJson
(json_object * js)
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
81
json_object *
VuoWindowReference_getJson
(
const
VuoWindowReference
value)
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
97
json_object *
VuoWindowReference_getInterprocessJson
(
const
VuoWindowReference
value)
98
{
99
return
VuoWindowReference_getJson
(value);
100
}
101
106
char
*
VuoWindowReference_getSummary
(
const
VuoWindowReference
value)
107
{
108
if
(value == 0)
109
return
strdup(
"No window"
);
110
111
__block
const
char
*title;
112
VuoApp_executeOnMainThread
(^{
113
VuoGraphicsWindow
*window = (
VuoGraphicsWindow
*)value;
114
title = window.title.UTF8String;
115
});
116
117
return
VuoText_format
(
"Title: ā%sā"
, title);
118
}
119
123
VuoReal
VuoWindowReference_getAspectRatio
(
const
VuoWindowReference
value)
124
{
125
VuoInteger
width, height;
126
float
backingScaleFactor;
127
VuoWindowReference_getContentSize
(value, &width, &height, &backingScaleFactor);
128
return
(
VuoReal
)width/(
VuoReal
)height;
129
}
130
136
VuoPoint2d
VuoWindowReference_getPosition
(
const
VuoWindowReference
value)
137
{
138
__block VuoPoint2d position;
139
VuoApp_executeOnMainThread
(^{
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
156
void
VuoWindowReference_getContentSize
(
const
VuoWindowReference
value,
VuoInteger
*width,
VuoInteger
*height,
float
*backingScaleFactor)
157
{
158
VuoApp_executeOnMainThread
(^{
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
171
bool
VuoWindowReference_isFocused
(
const
VuoWindowReference
value)
172
{
173
NSWindow *window = (NSWindow *)value;
174
return
[NSApp mainWindow] == window;
175
}
176
180
bool
VuoWindowReference_isFullscreen
(
const
VuoWindowReference
value)
181
{
182
VuoGraphicsWindow
*window = (
VuoGraphicsWindow
*)value;
183
return
window.
isFullScreen
;
184
}
185
189
VuoScreen
VuoWindowReference_getScreen
(
const
VuoWindowReference
value)
190
{
191
VuoGraphicsWindow
*window = (
VuoGraphicsWindow
*)value;
192
return
VuoScreen_makeFromNSScreen
(window.screen);
193
}
194
198
void
VuoWindowReference_addDragCallbacks
(
const
VuoWindowReference
wr,
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
217
void
VuoWindowReference_removeDragCallbacks
(
const
VuoWindowReference
wr,
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
}
Generated on Thu Nov 9 2023 16:59:30 for Vuo by
1.9.8