Vuo 2.4.2
Loading...
Searching...
No Matches
VuoWindowProperty.c
Go to the documentation of this file.
1
10#include <stdlib.h>
11#include <string.h>
12#include "type.h"
13
15#ifdef VUO_COMPILER
17 "title" : "Window Property",
18 "description" : "A window setting, such as its title, or whether it is full-screen.",
19 "keywords" : [ ],
20 "version" : "1.0.0",
21 "dependencies" : [
22 "VuoBoolean",
23 "VuoCoordinateUnit",
24 "VuoCursor",
25 "VuoInteger",
26 "VuoReal",
27 "VuoScreen",
28 "VuoText",
29 "VuoInteraction",
30 "VuoList_VuoWindowProperty"
31 ]
32 });
33#endif
35
46{
47 VuoWindowProperty value = { -1, VuoCoordinateUnit_Points, { NULL } };
48
49 json_object *o = NULL;
50
51 if (json_object_object_get_ex(js, "unit", &o))
53
54 if (json_object_object_get_ex(js, "title", &o))
55 {
56 value.type = VuoWindowProperty_Title;
57 value.title = VuoText_makeFromJson(o);
58 return value;
59 }
60 else if (json_object_object_get_ex(js, "fullScreen", &o))
61 {
62 value.type = VuoWindowProperty_FullScreen;
63 value.fullScreen = VuoBoolean_makeFromJson(o);
64 if (json_object_object_get_ex(js, "screen", &o))
65 value.screen = VuoScreen_makeFromJson(o);
66 return value;
67 }
68 else if (json_object_object_get_ex(js, "left", &o))
69 {
70 value.type = VuoWindowProperty_Position;
71 value.left = VuoInteger_makeFromJson(o);
72 if (json_object_object_get_ex(js, "top", &o))
73 value.top = VuoInteger_makeFromJson(o);
74 return value;
75 }
76 else if (json_object_object_get_ex(js, "width", &o))
77 {
78 value.type = VuoWindowProperty_Size;
79 value.width = VuoInteger_makeFromJson(o);
80 if (json_object_object_get_ex(js, "height", &o))
81 value.height = VuoInteger_makeFromJson(o);
82 return value;
83 }
84 else if (json_object_object_get_ex(js, "aspectRatio", &o))
85 {
86 value.type = VuoWindowProperty_AspectRatio;
87 value.aspectRatio = VuoReal_makeFromJson(o);
88 return value;
89 }
90 else if (json_object_object_get_ex(js, "aspectRatioReset", &o))
91 {
92 value.type = VuoWindowProperty_AspectRatioReset;
93 return value;
94 }
95 else if (json_object_object_get_ex(js, "resizable", &o))
96 {
97 value.type = VuoWindowProperty_Resizable;
98 value.resizable = VuoBoolean_makeFromJson(o);
99 return value;
100 }
101 else if (json_object_object_get_ex(js, "cursor", &o))
102 {
103 value.type = VuoWindowProperty_Cursor;
104 value.cursor = VuoCursor_makeFromJson(o);
105 return value;
106 }
107 else if (json_object_object_get_ex(js, "interaction", &o))
108 {
109 value.type = VuoWindowProperty_Interaction;
110 value.interaction = VuoInteraction_makeFromJson(o);
111 return value;
112 }
113 else if (json_object_object_get_ex(js, "level", &o))
114 {
115 value.type = VuoWindowProperty_Level;
116 value.level = VuoInteger_makeFromJson(o);
117 return value;
118 }
119
120 return value;
121}
122
127{
128 json_object *js = json_object_new_object();
129
130 if (value.type == VuoWindowProperty_Title)
131 json_object_object_add(js, "title", VuoText_getJson(value.title));
132 else if (value.type == VuoWindowProperty_FullScreen)
133 {
134 json_object_object_add(js, "fullScreen", VuoBoolean_getJson(value.fullScreen));
135 json_object_object_add(js, "screen", VuoScreen_getJson(value.screen));
136 }
137 else if (value.type == VuoWindowProperty_Position)
138 {
139 json_object_object_add(js, "left", VuoInteger_getJson(value.left));
140 json_object_object_add(js, "top", VuoInteger_getJson(value.top));
141 json_object_object_add(js, "unit", VuoCoordinateUnit_getJson(value.unit));
142 }
143 else if (value.type == VuoWindowProperty_Size)
144 {
145 json_object_object_add(js, "width", VuoInteger_getJson(value.width));
146 json_object_object_add(js, "height", VuoInteger_getJson(value.height));
147 json_object_object_add(js, "unit", VuoCoordinateUnit_getJson(value.unit));
148 }
149 else if (value.type == VuoWindowProperty_AspectRatio)
150 json_object_object_add(js, "aspectRatio", VuoReal_getJson(value.aspectRatio));
151 else if (value.type == VuoWindowProperty_AspectRatioReset)
152 json_object_object_add(js, "aspectRatioReset", VuoBoolean_getJson(true));
153 else if (value.type == VuoWindowProperty_Resizable)
154 json_object_object_add(js, "resizable", VuoBoolean_getJson(value.resizable));
155 else if (value.type == VuoWindowProperty_Cursor)
156 json_object_object_add(js, "cursor", VuoCursor_getJson(value.cursor));
157 else if (value.type == VuoWindowProperty_Interaction)
158 json_object_object_add(js, "interaction", VuoInteraction_getJson(value.interaction));
159 else if (value.type == VuoWindowProperty_Level)
160 json_object_object_add(js, "level", VuoInteger_getJson(value.level));
161
162 return js;
163}
164
169{
170 if (level == VuoWindowLevel_Background)
171 return "Background";
172 else if (level == VuoWindowLevel_Normal)
173 return "Normal";
174 else if (level == VuoWindowLevel_Floating)
175 return "Floating";
176
177 return "Unknown";
178}
179
184{
185 if (value.type == VuoWindowProperty_Title)
186 return VuoText_format("Change Window Title: \"%s\"", value.title);
187 else if (value.type == VuoWindowProperty_FullScreen)
188 {
189 char *screenSummary = VuoScreen_getSummary(value.screen);
190 char *summary = VuoText_format("<div>Change to %s</div>\n<div>%s</div>",
191 value.fullScreen ? "Fullscreen" : "Windowed",
192 screenSummary);
193 free(screenSummary);
194 return summary;
195 }
196 else if (value.type == VuoWindowProperty_Position)
197 {
198 char *unit = VuoCoordinateUnit_getSummary(value.unit);
199 char *t = VuoText_format("Change Window Position: (%lld, %lld) %s", value.left, value.top, unit);
200 free(unit);
201 return t;
202 }
203 else if (value.type == VuoWindowProperty_Size)
204 {
205 char *unit = VuoCoordinateUnit_getSummary(value.unit);
206 char *t = VuoText_format("Change Window Size: %lldx%lld %s", value.width, value.height, unit);
207 free(unit);
208 return t;
209 }
210 else if (value.type == VuoWindowProperty_AspectRatio)
211 return VuoText_format("Change Window Aspect Ratio: %g", value.aspectRatio);
212 else if (value.type == VuoWindowProperty_AspectRatioReset)
213 return VuoText_format("Reset Window Aspect Ratio");
214 else if (value.type == VuoWindowProperty_Resizable)
215 return value.resizable ? strdup("Enable Window Resizing") : strdup("Disable Window Resizing");
216 else if (value.type == VuoWindowProperty_Cursor)
217 {
218 char *cursorSummary = VuoCursor_getSummary(value.cursor);
219 char *summary = VuoText_format("Change mouse cursor to %s", cursorSummary);
220 free(cursorSummary);
221 return summary;
222 }
223 else if (value.type == VuoWindowProperty_Interaction)
224 return VuoInteraction_getSummary(value.interaction);
225 else if (value.type == VuoWindowProperty_Level)
226 return VuoText_format("Change Window Level: %s", VuoWindowLevel_getLabel(value.level));
227
228 return strdup("Unknown window property");
229}
230
237{
239
240 for(int i = 1; i <= VuoListGetCount_VuoWindowProperty(windowProperties); i++)
241 {
242 VuoWindowProperty prop = VuoListGetValue_VuoWindowProperty(windowProperties, i);
243 if(prop.type == windowPropertyType)
244 VuoListAppendValue_VuoWindowProperty(properties, prop);
245 }
246
247 return properties;
248}