obs-properties.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /******************************************************************************
  2. Copyright (C) 2014 by Hugh 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. /**
  18. * @file
  19. * @brief libobs header for the properties system used in libobs
  20. *
  21. * @page properties Properties
  22. * @brief Platform and Toolkit independent settings implementation
  23. *
  24. * @section prop_overview_sec Overview
  25. *
  26. * libobs uses a property system which lets for example sources specify
  27. * settings that can be displayed to the user by the UI.
  28. *
  29. */
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. enum obs_property_type {
  34. OBS_PROPERTY_INVALID,
  35. OBS_PROPERTY_BOOL,
  36. OBS_PROPERTY_INT,
  37. OBS_PROPERTY_FLOAT,
  38. OBS_PROPERTY_TEXT,
  39. OBS_PROPERTY_PATH,
  40. OBS_PROPERTY_LIST,
  41. OBS_PROPERTY_COLOR,
  42. OBS_PROPERTY_BUTTON,
  43. OBS_PROPERTY_FONT,
  44. };
  45. enum obs_combo_format {
  46. OBS_COMBO_FORMAT_INVALID,
  47. OBS_COMBO_FORMAT_INT,
  48. OBS_COMBO_FORMAT_FLOAT,
  49. OBS_COMBO_FORMAT_STRING
  50. };
  51. enum obs_combo_type {
  52. OBS_COMBO_TYPE_INVALID,
  53. OBS_COMBO_TYPE_EDITABLE,
  54. OBS_COMBO_TYPE_LIST,
  55. };
  56. enum obs_path_type {
  57. OBS_PATH_FILE,
  58. OBS_PATH_DIRECTORY
  59. };
  60. enum obs_text_type {
  61. OBS_TEXT_DEFAULT,
  62. OBS_TEXT_PASSWORD,
  63. OBS_TEXT_MULTILINE,
  64. };
  65. #define OBS_FONT_BOLD (1<<0)
  66. #define OBS_FONT_ITALIC (1<<1)
  67. #define OBS_FONT_UNDERLINE (1<<2)
  68. #define OBS_FONT_STRIKEOUT (1<<3)
  69. struct obs_properties;
  70. struct obs_property;
  71. typedef struct obs_properties obs_properties_t;
  72. typedef struct obs_property obs_property_t;
  73. /* ------------------------------------------------------------------------- */
  74. EXPORT obs_properties_t *obs_properties_create(void);
  75. EXPORT obs_properties_t *obs_properties_create_param(void *param,
  76. void (*destroy)(void *param));
  77. EXPORT void obs_properties_destroy(obs_properties_t *props);
  78. EXPORT void obs_properties_set_param(obs_properties_t *props,
  79. void *param, void (*destroy)(void *param));
  80. EXPORT void *obs_properties_get_param(obs_properties_t *props);
  81. EXPORT obs_property_t *obs_properties_first(obs_properties_t *props);
  82. EXPORT obs_property_t *obs_properties_get(obs_properties_t *props,
  83. const char *property);
  84. /* used internally by libobs */
  85. extern void obs_properties_apply_settings(obs_properties_t *props,
  86. obs_data_t *settings);
  87. /* ------------------------------------------------------------------------- */
  88. /**
  89. * Callback for when a button property is clicked. If the properties
  90. * need to be refreshed due to changes to the property layout, return true,
  91. * otherwise return false.
  92. */
  93. typedef bool (*obs_property_clicked_t)(obs_properties_t *props,
  94. obs_property_t *property, void *data);
  95. EXPORT obs_property_t *obs_properties_add_bool(obs_properties_t *props,
  96. const char *name, const char *description);
  97. EXPORT obs_property_t *obs_properties_add_int(obs_properties_t *props,
  98. const char *name, const char *description,
  99. int min, int max, int step);
  100. EXPORT obs_property_t *obs_properties_add_float(obs_properties_t *props,
  101. const char *name, const char *description,
  102. double min, double max, double step);
  103. EXPORT obs_property_t *obs_properties_add_text(obs_properties_t *props,
  104. const char *name, const char *description,
  105. enum obs_text_type type);
  106. /**
  107. * Adds a 'path' property. Can be a directory or a file.
  108. *
  109. * If target is a file path, the filters should be this format, separated by
  110. * double semi-colens, and extensions separated by space:
  111. * "Example types 1 and 2 (*.ex1 *.ex2);;Example type 3 (*.ex3)"
  112. *
  113. * @param props Properties object
  114. * @param name Settings name
  115. * @param description Description (display name) of the property
  116. * @param type Type of path (directory or file)
  117. * @param filter If type is a file path, then describes the file filter
  118. * that the user can browse. Items are separated via
  119. * double semi-colens. If multiple file types in a
  120. * filter, separate with space.
  121. */
  122. EXPORT obs_property_t *obs_properties_add_path(obs_properties_t *props,
  123. const char *name, const char *description,
  124. enum obs_path_type type, const char *filter,
  125. const char *default_path);
  126. EXPORT obs_property_t *obs_properties_add_list(obs_properties_t *props,
  127. const char *name, const char *description,
  128. enum obs_combo_type type, enum obs_combo_format format);
  129. EXPORT obs_property_t *obs_properties_add_color(obs_properties_t *props,
  130. const char *name, const char *description);
  131. EXPORT obs_property_t *obs_properties_add_button(obs_properties_t *props,
  132. const char *name, const char *text,
  133. obs_property_clicked_t callback);
  134. /**
  135. * Adds a font selection property.
  136. *
  137. * A font is an obs_data sub-object which contains the following items:
  138. * face: face name string
  139. * style: style name string
  140. * size: size integer
  141. * flags: font flags integer (OBS_FONT_* defined above)
  142. */
  143. EXPORT obs_property_t *obs_properties_add_font(obs_properties_t *props,
  144. const char *name, const char *description);
  145. /* ------------------------------------------------------------------------- */
  146. /**
  147. * Optional callback for when a property is modified. If the properties
  148. * need to be refreshed due to changes to the property layout, return true,
  149. * otherwise return false.
  150. */
  151. typedef bool (*obs_property_modified_t)(obs_properties_t *props,
  152. obs_property_t *property, obs_data_t *settings);
  153. EXPORT void obs_property_set_modified_callback(obs_property_t *p,
  154. obs_property_modified_t modified);
  155. EXPORT bool obs_property_modified(obs_property_t *p, obs_data_t *settings);
  156. EXPORT bool obs_property_button_clicked(obs_property_t *p, void *obj);
  157. EXPORT void obs_property_set_visible(obs_property_t *p, bool visible);
  158. EXPORT void obs_property_set_enabled(obs_property_t *p, bool enabled);
  159. EXPORT const char * obs_property_name(obs_property_t *p);
  160. EXPORT const char * obs_property_description(obs_property_t *p);
  161. EXPORT enum obs_property_type obs_property_get_type(obs_property_t *p);
  162. EXPORT bool obs_property_enabled(obs_property_t *p);
  163. EXPORT bool obs_property_visible(obs_property_t *p);
  164. EXPORT bool obs_property_next(obs_property_t **p);
  165. EXPORT int obs_property_int_min(obs_property_t *p);
  166. EXPORT int obs_property_int_max(obs_property_t *p);
  167. EXPORT int obs_property_int_step(obs_property_t *p);
  168. EXPORT double obs_property_float_min(obs_property_t *p);
  169. EXPORT double obs_property_float_max(obs_property_t *p);
  170. EXPORT double obs_property_float_step(obs_property_t *p);
  171. EXPORT enum obs_text_type obs_proprety_text_type(obs_property_t *p);
  172. EXPORT enum obs_path_type obs_property_path_type(obs_property_t *p);
  173. EXPORT const char * obs_property_path_filter(obs_property_t *p);
  174. EXPORT const char * obs_property_path_default_path(obs_property_t *p);
  175. EXPORT enum obs_combo_type obs_property_list_type(obs_property_t *p);
  176. EXPORT enum obs_combo_format obs_property_list_format(obs_property_t *p);
  177. EXPORT void obs_property_list_clear(obs_property_t *p);
  178. EXPORT size_t obs_property_list_add_string(obs_property_t *p,
  179. const char *name, const char *val);
  180. EXPORT size_t obs_property_list_add_int(obs_property_t *p,
  181. const char *name, long long val);
  182. EXPORT size_t obs_property_list_add_float(obs_property_t *p,
  183. const char *name, double val);
  184. EXPORT void obs_property_list_item_disable(obs_property_t *p, size_t idx,
  185. bool disabled);
  186. EXPORT bool obs_property_list_item_disabled(obs_property_t *p, size_t idx);
  187. EXPORT void obs_property_list_item_remove(obs_property_t *p, size_t idx);
  188. EXPORT size_t obs_property_list_item_count(obs_property_t *p);
  189. EXPORT const char *obs_property_list_item_name(obs_property_t *p, size_t idx);
  190. EXPORT const char *obs_property_list_item_string(obs_property_t *p, size_t idx);
  191. EXPORT long long obs_property_list_item_int(obs_property_t *p, size_t idx);
  192. EXPORT double obs_property_list_item_float(obs_property_t *p, size_t idx);
  193. #ifdef __cplusplus
  194. }
  195. #endif