1 /******************************************************************************
2     Copyright (C) 2014 by Hugh Bailey <obs.jim@gmail.com>
3 
4     This program is free software: you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation, either version 2 of the License, or
7     (at your option) any later version.
8 
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13 
14     You should have received a copy of the GNU General Public License
15     along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 ******************************************************************************/
17 
18 #pragma once
19 
20 #include "util/c99defs.h"
21 #include "obs-data.h"
22 #include "media-io/frame-rate.h"
23 
24 /**
25  * @file
26  * @brief libobs header for the properties system used in libobs
27  *
28  * @page properties Properties
29  * @brief Platform and Toolkit independent settings implementation
30  *
31  * @section prop_overview_sec Overview
32  *
33  * libobs uses a property system which lets for example sources specify
34  * settings that can be displayed to the user by the UI.
35  *
36  */
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 /** Only update when the user presses OK or Apply */
43 #define OBS_PROPERTIES_DEFER_UPDATE (1 << 0)
44 
45 enum obs_property_type {
46 	OBS_PROPERTY_INVALID,
47 	OBS_PROPERTY_BOOL,
48 	OBS_PROPERTY_INT,
49 	OBS_PROPERTY_FLOAT,
50 	OBS_PROPERTY_TEXT,
51 	OBS_PROPERTY_PATH,
52 	OBS_PROPERTY_LIST,
53 	OBS_PROPERTY_COLOR,
54 	OBS_PROPERTY_BUTTON,
55 	OBS_PROPERTY_FONT,
56 	OBS_PROPERTY_EDITABLE_LIST,
57 	OBS_PROPERTY_FRAME_RATE,
58 	OBS_PROPERTY_GROUP,
59 	OBS_PROPERTY_COLOR_ALPHA,
60 };
61 
62 enum obs_combo_format {
63 	OBS_COMBO_FORMAT_INVALID,
64 	OBS_COMBO_FORMAT_INT,
65 	OBS_COMBO_FORMAT_FLOAT,
66 	OBS_COMBO_FORMAT_STRING,
67 };
68 
69 enum obs_combo_type {
70 	OBS_COMBO_TYPE_INVALID,
71 	OBS_COMBO_TYPE_EDITABLE,
72 	OBS_COMBO_TYPE_LIST,
73 };
74 
75 enum obs_editable_list_type {
76 	OBS_EDITABLE_LIST_TYPE_STRINGS,
77 	OBS_EDITABLE_LIST_TYPE_FILES,
78 	OBS_EDITABLE_LIST_TYPE_FILES_AND_URLS,
79 };
80 
81 enum obs_path_type {
82 	OBS_PATH_FILE,
83 	OBS_PATH_FILE_SAVE,
84 	OBS_PATH_DIRECTORY,
85 };
86 
87 enum obs_text_type {
88 	OBS_TEXT_DEFAULT,
89 	OBS_TEXT_PASSWORD,
90 	OBS_TEXT_MULTILINE,
91 };
92 
93 enum obs_number_type {
94 	OBS_NUMBER_SCROLLER,
95 	OBS_NUMBER_SLIDER,
96 };
97 
98 enum obs_group_type {
99 	OBS_COMBO_INVALID,
100 	OBS_GROUP_NORMAL,
101 	OBS_GROUP_CHECKABLE,
102 };
103 
104 enum obs_button_type {
105 	OBS_BUTTON_DEFAULT,
106 	OBS_BUTTON_URL,
107 };
108 
109 #define OBS_FONT_BOLD (1 << 0)
110 #define OBS_FONT_ITALIC (1 << 1)
111 #define OBS_FONT_UNDERLINE (1 << 2)
112 #define OBS_FONT_STRIKEOUT (1 << 3)
113 
114 struct obs_properties;
115 struct obs_property;
116 typedef struct obs_properties obs_properties_t;
117 typedef struct obs_property obs_property_t;
118 
119 /* ------------------------------------------------------------------------- */
120 
121 EXPORT obs_properties_t *obs_properties_create(void);
122 EXPORT obs_properties_t *
123 obs_properties_create_param(void *param, void (*destroy)(void *param));
124 EXPORT void obs_properties_destroy(obs_properties_t *props);
125 
126 EXPORT void obs_properties_set_flags(obs_properties_t *props, uint32_t flags);
127 EXPORT uint32_t obs_properties_get_flags(obs_properties_t *props);
128 
129 EXPORT void obs_properties_set_param(obs_properties_t *props, void *param,
130 				     void (*destroy)(void *param));
131 EXPORT void *obs_properties_get_param(obs_properties_t *props);
132 
133 EXPORT obs_property_t *obs_properties_first(obs_properties_t *props);
134 
135 EXPORT obs_property_t *obs_properties_get(obs_properties_t *props,
136 					  const char *property);
137 
138 EXPORT obs_properties_t *obs_properties_get_parent(obs_properties_t *props);
139 
140 /** Remove a property from a properties list.
141  *
142  * Removes a property from a properties list. Only valid in either
143  * get_properties or modified_callback(2). modified_callback(2) must return
144  * true so that all UI properties are rebuilt and returning false is undefined
145  * behavior.
146  *
147  * @param props Properties to remove from.
148  * @param property Name of the property to remove.
149  */
150 EXPORT void obs_properties_remove_by_name(obs_properties_t *props,
151 					  const char *property);
152 
153 /**
154  * Applies settings to the properties by calling all the necessary
155  * modification callbacks
156  */
157 EXPORT void obs_properties_apply_settings(obs_properties_t *props,
158 					  obs_data_t *settings);
159 
160 /* ------------------------------------------------------------------------- */
161 
162 /**
163  * Callback for when a button property is clicked.  If the properties
164  * need to be refreshed due to changes to the property layout, return true,
165  * otherwise return false.
166  */
167 typedef bool (*obs_property_clicked_t)(obs_properties_t *props,
168 				       obs_property_t *property, void *data);
169 
170 EXPORT obs_property_t *obs_properties_add_bool(obs_properties_t *props,
171 					       const char *name,
172 					       const char *description);
173 
174 EXPORT obs_property_t *obs_properties_add_int(obs_properties_t *props,
175 					      const char *name,
176 					      const char *description, int min,
177 					      int max, int step);
178 
179 EXPORT obs_property_t *obs_properties_add_float(obs_properties_t *props,
180 						const char *name,
181 						const char *description,
182 						double min, double max,
183 						double step);
184 
185 EXPORT obs_property_t *obs_properties_add_int_slider(obs_properties_t *props,
186 						     const char *name,
187 						     const char *description,
188 						     int min, int max,
189 						     int step);
190 
191 EXPORT obs_property_t *obs_properties_add_float_slider(obs_properties_t *props,
192 						       const char *name,
193 						       const char *description,
194 						       double min, double max,
195 						       double step);
196 
197 EXPORT obs_property_t *obs_properties_add_text(obs_properties_t *props,
198 					       const char *name,
199 					       const char *description,
200 					       enum obs_text_type type);
201 
202 /**
203  * Adds a 'path' property.  Can be a directory or a file.
204  *
205  * If target is a file path, the filters should be this format, separated by
206  * double semi-colens, and extensions separated by space:
207  *   "Example types 1 and 2 (*.ex1 *.ex2);;Example type 3 (*.ex3)"
208  *
209  * @param  props        Properties object
210  * @param  name         Settings name
211  * @param  description  Description (display name) of the property
212  * @param  type         Type of path (directory or file)
213  * @param  filter       If type is a file path, then describes the file filter
214  *                      that the user can browse.  Items are separated via
215  *                      double semi-colens.  If multiple file types in a
216  *                      filter, separate with space.
217  */
218 EXPORT obs_property_t *
219 obs_properties_add_path(obs_properties_t *props, const char *name,
220 			const char *description, enum obs_path_type type,
221 			const char *filter, const char *default_path);
222 
223 EXPORT obs_property_t *obs_properties_add_list(obs_properties_t *props,
224 					       const char *name,
225 					       const char *description,
226 					       enum obs_combo_type type,
227 					       enum obs_combo_format format);
228 
229 EXPORT obs_property_t *obs_properties_add_color(obs_properties_t *props,
230 						const char *name,
231 						const char *description);
232 
233 EXPORT obs_property_t *obs_properties_add_color_alpha(obs_properties_t *props,
234 						      const char *name,
235 						      const char *description);
236 
237 EXPORT obs_property_t *
238 obs_properties_add_button(obs_properties_t *props, const char *name,
239 			  const char *text, obs_property_clicked_t callback);
240 
241 EXPORT obs_property_t *
242 obs_properties_add_button2(obs_properties_t *props, const char *name,
243 			   const char *text, obs_property_clicked_t callback,
244 			   void *priv);
245 
246 /**
247  * Adds a font selection property.
248  *
249  * A font is an obs_data sub-object which contains the following items:
250  *   face:   face name string
251  *   style:  style name string
252  *   size:   size integer
253  *   flags:  font flags integer (OBS_FONT_* defined above)
254  */
255 EXPORT obs_property_t *obs_properties_add_font(obs_properties_t *props,
256 					       const char *name,
257 					       const char *description);
258 
259 EXPORT obs_property_t *
260 obs_properties_add_editable_list(obs_properties_t *props, const char *name,
261 				 const char *description,
262 				 enum obs_editable_list_type type,
263 				 const char *filter, const char *default_path);
264 
265 EXPORT obs_property_t *obs_properties_add_frame_rate(obs_properties_t *props,
266 						     const char *name,
267 						     const char *description);
268 
269 EXPORT obs_property_t *obs_properties_add_group(obs_properties_t *props,
270 						const char *name,
271 						const char *description,
272 						enum obs_group_type type,
273 						obs_properties_t *group);
274 
275 /* ------------------------------------------------------------------------- */
276 
277 /**
278  * Optional callback for when a property is modified.  If the properties
279  * need to be refreshed due to changes to the property layout, return true,
280  * otherwise return false.
281  */
282 typedef bool (*obs_property_modified_t)(obs_properties_t *props,
283 					obs_property_t *property,
284 					obs_data_t *settings);
285 typedef bool (*obs_property_modified2_t)(void *priv, obs_properties_t *props,
286 					 obs_property_t *property,
287 					 obs_data_t *settings);
288 
289 EXPORT void
290 obs_property_set_modified_callback(obs_property_t *p,
291 				   obs_property_modified_t modified);
292 EXPORT void obs_property_set_modified_callback2(
293 	obs_property_t *p, obs_property_modified2_t modified, void *priv);
294 
295 EXPORT bool obs_property_modified(obs_property_t *p, obs_data_t *settings);
296 EXPORT bool obs_property_button_clicked(obs_property_t *p, void *obj);
297 
298 EXPORT void obs_property_set_visible(obs_property_t *p, bool visible);
299 EXPORT void obs_property_set_enabled(obs_property_t *p, bool enabled);
300 
301 EXPORT void obs_property_set_description(obs_property_t *p,
302 					 const char *description);
303 EXPORT void obs_property_set_long_description(obs_property_t *p,
304 					      const char *long_description);
305 
306 EXPORT const char *obs_property_name(obs_property_t *p);
307 EXPORT const char *obs_property_description(obs_property_t *p);
308 EXPORT const char *obs_property_long_description(obs_property_t *p);
309 EXPORT enum obs_property_type obs_property_get_type(obs_property_t *p);
310 EXPORT bool obs_property_enabled(obs_property_t *p);
311 EXPORT bool obs_property_visible(obs_property_t *p);
312 
313 EXPORT bool obs_property_next(obs_property_t **p);
314 
315 EXPORT int obs_property_int_min(obs_property_t *p);
316 EXPORT int obs_property_int_max(obs_property_t *p);
317 EXPORT int obs_property_int_step(obs_property_t *p);
318 EXPORT enum obs_number_type obs_property_int_type(obs_property_t *p);
319 EXPORT const char *obs_property_int_suffix(obs_property_t *p);
320 EXPORT double obs_property_float_min(obs_property_t *p);
321 EXPORT double obs_property_float_max(obs_property_t *p);
322 EXPORT double obs_property_float_step(obs_property_t *p);
323 EXPORT enum obs_number_type obs_property_float_type(obs_property_t *p);
324 EXPORT const char *obs_property_float_suffix(obs_property_t *p);
325 EXPORT enum obs_text_type obs_property_text_type(obs_property_t *p);
326 EXPORT enum obs_text_type obs_property_text_monospace(obs_property_t *p);
327 EXPORT enum obs_path_type obs_property_path_type(obs_property_t *p);
328 EXPORT const char *obs_property_path_filter(obs_property_t *p);
329 EXPORT const char *obs_property_path_default_path(obs_property_t *p);
330 EXPORT enum obs_combo_type obs_property_list_type(obs_property_t *p);
331 EXPORT enum obs_combo_format obs_property_list_format(obs_property_t *p);
332 
333 EXPORT void obs_property_int_set_limits(obs_property_t *p, int min, int max,
334 					int step);
335 EXPORT void obs_property_float_set_limits(obs_property_t *p, double min,
336 					  double max, double step);
337 EXPORT void obs_property_int_set_suffix(obs_property_t *p, const char *suffix);
338 EXPORT void obs_property_float_set_suffix(obs_property_t *p,
339 					  const char *suffix);
340 EXPORT void obs_property_text_set_monospace(obs_property_t *p, bool monospace);
341 
342 EXPORT void obs_property_button_set_type(obs_property_t *p,
343 					 enum obs_button_type type);
344 EXPORT void obs_property_button_set_url(obs_property_t *p, char *url);
345 
346 EXPORT void obs_property_list_clear(obs_property_t *p);
347 
348 EXPORT size_t obs_property_list_add_string(obs_property_t *p, const char *name,
349 					   const char *val);
350 EXPORT size_t obs_property_list_add_int(obs_property_t *p, const char *name,
351 					long long val);
352 EXPORT size_t obs_property_list_add_float(obs_property_t *p, const char *name,
353 					  double val);
354 
355 EXPORT void obs_property_list_insert_string(obs_property_t *p, size_t idx,
356 					    const char *name, const char *val);
357 EXPORT void obs_property_list_insert_int(obs_property_t *p, size_t idx,
358 					 const char *name, long long val);
359 EXPORT void obs_property_list_insert_float(obs_property_t *p, size_t idx,
360 					   const char *name, double val);
361 
362 EXPORT void obs_property_list_item_disable(obs_property_t *p, size_t idx,
363 					   bool disabled);
364 EXPORT bool obs_property_list_item_disabled(obs_property_t *p, size_t idx);
365 
366 EXPORT void obs_property_list_item_remove(obs_property_t *p, size_t idx);
367 
368 EXPORT size_t obs_property_list_item_count(obs_property_t *p);
369 EXPORT const char *obs_property_list_item_name(obs_property_t *p, size_t idx);
370 EXPORT const char *obs_property_list_item_string(obs_property_t *p, size_t idx);
371 EXPORT long long obs_property_list_item_int(obs_property_t *p, size_t idx);
372 EXPORT double obs_property_list_item_float(obs_property_t *p, size_t idx);
373 
374 EXPORT enum obs_editable_list_type
375 obs_property_editable_list_type(obs_property_t *p);
376 EXPORT const char *obs_property_editable_list_filter(obs_property_t *p);
377 EXPORT const char *obs_property_editable_list_default_path(obs_property_t *p);
378 
379 EXPORT void obs_property_frame_rate_clear(obs_property_t *p);
380 EXPORT void obs_property_frame_rate_options_clear(obs_property_t *p);
381 EXPORT void obs_property_frame_rate_fps_ranges_clear(obs_property_t *p);
382 
383 EXPORT size_t obs_property_frame_rate_option_add(obs_property_t *p,
384 						 const char *name,
385 						 const char *description);
386 EXPORT size_t obs_property_frame_rate_fps_range_add(
387 	obs_property_t *p, struct media_frames_per_second min,
388 	struct media_frames_per_second max);
389 
390 EXPORT void obs_property_frame_rate_option_insert(obs_property_t *p, size_t idx,
391 						  const char *name,
392 						  const char *description);
393 EXPORT void
394 obs_property_frame_rate_fps_range_insert(obs_property_t *p, size_t idx,
395 					 struct media_frames_per_second min,
396 					 struct media_frames_per_second max);
397 
398 EXPORT size_t obs_property_frame_rate_options_count(obs_property_t *p);
399 EXPORT const char *obs_property_frame_rate_option_name(obs_property_t *p,
400 						       size_t idx);
401 EXPORT const char *obs_property_frame_rate_option_description(obs_property_t *p,
402 							      size_t idx);
403 
404 EXPORT size_t obs_property_frame_rate_fps_ranges_count(obs_property_t *p);
405 EXPORT struct media_frames_per_second
406 obs_property_frame_rate_fps_range_min(obs_property_t *p, size_t idx);
407 EXPORT struct media_frames_per_second
408 obs_property_frame_rate_fps_range_max(obs_property_t *p, size_t idx);
409 
410 EXPORT enum obs_group_type obs_property_group_type(obs_property_t *p);
411 EXPORT obs_properties_t *obs_property_group_content(obs_property_t *p);
412 
413 EXPORT enum obs_button_type obs_property_button_type(obs_property_t *p);
414 EXPORT const char *obs_property_button_url(obs_property_t *p);
415 
416 #ifndef SWIG
417 OBS_DEPRECATED
418 EXPORT enum obs_text_type obs_proprety_text_type(obs_property_t *p);
419 #endif
420 
421 #ifdef __cplusplus
422 }
423 #endif
424