obs-properties.h 15 KB

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