Vuo  2.0.2
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
34 
46 {
47  VuoWindowProperty value = { -1, NULL, false, {-1, -1, -1, NULL, false, {0,0}, 0, 0, 0, 0}, -1, 0, 0, 0, 0, 0, false, -1, {{"", ""}, {0,0}, false, -1, {0,0}, 0, 0} };
48 
49  json_object *o = NULL;
50 
51  if (json_object_object_get_ex(js, "unit", &o))
52  value.unit = VuoCoordinateUnit_makeFromJson(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 
114  return value;
115 }
116 
121 {
122  json_object *js = json_object_new_object();
123 
124  if (value.type == VuoWindowProperty_Title)
125  json_object_object_add(js, "title", VuoText_getJson(value.title));
126  else if (value.type == VuoWindowProperty_FullScreen)
127  {
128  json_object_object_add(js, "fullScreen", VuoBoolean_getJson(value.fullScreen));
129  json_object_object_add(js, "screen", VuoScreen_getJson(value.screen));
130  }
131  else if (value.type == VuoWindowProperty_Position)
132  {
133  json_object_object_add(js, "left", VuoInteger_getJson(value.left));
134  json_object_object_add(js, "top", VuoInteger_getJson(value.top));
135  json_object_object_add(js, "unit", VuoCoordinateUnit_getJson(value.unit));
136  }
137  else if (value.type == VuoWindowProperty_Size)
138  {
139  json_object_object_add(js, "width", VuoInteger_getJson(value.width));
140  json_object_object_add(js, "height", VuoInteger_getJson(value.height));
141  json_object_object_add(js, "unit", VuoCoordinateUnit_getJson(value.unit));
142  }
143  else if (value.type == VuoWindowProperty_AspectRatio)
144  json_object_object_add(js, "aspectRatio", VuoReal_getJson(value.aspectRatio));
145  else if (value.type == VuoWindowProperty_AspectRatioReset)
146  json_object_object_add(js, "aspectRatioReset", VuoBoolean_getJson(true));
147  else if (value.type == VuoWindowProperty_Resizable)
148  json_object_object_add(js, "resizable", VuoBoolean_getJson(value.resizable));
149  else if (value.type == VuoWindowProperty_Cursor)
150  json_object_object_add(js, "cursor", VuoCursor_getJson(value.cursor));
151  else if (value.type == VuoWindowProperty_Interaction)
152  json_object_object_add(js, "interaction", VuoInteraction_getJson(value.interaction));
153 
154  return js;
155 }
156 
161 {
162  if (value.type == VuoWindowProperty_Title)
163  return VuoText_format("Change Window Title: \"%s\"", value.title);
164  else if (value.type == VuoWindowProperty_FullScreen)
165  {
166  char *screenSummary = VuoScreen_getSummary(value.screen);
167  char *summary = VuoText_format("<div>Change to %s</div><div>%s</div>",
168  value.fullScreen ? "Fullscreen" : "Windowed",
169  screenSummary);
170  free(screenSummary);
171  return summary;
172  }
173  else if (value.type == VuoWindowProperty_Position)
174  {
175  char *unit = VuoCoordinateUnit_getSummary(value.unit);
176  char *t = VuoText_format("Change Window Position: (%lld, %lld) %s", value.left, value.top, unit);
177  free(unit);
178  return t;
179  }
180  else if (value.type == VuoWindowProperty_Size)
181  {
182  char *unit = VuoCoordinateUnit_getSummary(value.unit);
183  char *t = VuoText_format("Change Window Size: %lldx%lld %s", value.width, value.height, unit);
184  free(unit);
185  return t;
186  }
187  else if (value.type == VuoWindowProperty_AspectRatio)
188  return VuoText_format("Change Window Aspect Ratio: %g", value.aspectRatio);
189  else if (value.type == VuoWindowProperty_AspectRatioReset)
190  return VuoText_format("Reset Window Aspect Ratio");
191  else if (value.type == VuoWindowProperty_Resizable)
192  return value.resizable ? strdup("Enable Window Resizing") : strdup("Disable Window Resizing");
193  else if (value.type == VuoWindowProperty_Cursor)
194  {
195  char *cursorSummary = VuoCursor_getSummary(value.cursor);
196  char *summary = VuoText_format("Change mouse cursor to %s", cursorSummary);
197  free(cursorSummary);
198  return summary;
199  }
200  else if (value.type == VuoWindowProperty_Interaction)
201  return VuoInteraction_getSummary(value.interaction);
202 
203  return strdup("Unknown window property");
204 }
205 
212 {
214 
215  for(int i = 1; i <= VuoListGetCount_VuoWindowProperty(windowProperties); i++)
216  {
217  VuoWindowProperty prop = VuoListGetValue_VuoWindowProperty(windowProperties, i);
218  if(prop.type == windowPropertyType)
219  VuoListAppendValue_VuoWindowProperty(properties, prop);
220  }
221 
222  return properties;
223 }