obs-ui.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /******************************************************************************
  2. Copyright (C) 2013-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. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. /**
  20. * @file
  21. *
  22. * Modules can specify custom user-interface-specific exports. UI functions
  23. * can be within the same library as the actual core logic, or separated in to
  24. * different modules to split up UI logic and core module logic.
  25. *
  26. * The reasoning for this is to allow for custom user interface of differing
  27. * toolkits or for automatically generated user interface, or to simply allow
  28. * separation of UI code from core code (which may often be in differing
  29. * languages).
  30. */
  31. /** Modal UI definition structure */
  32. struct obs_modal_ui {
  33. const char *id; /**< Identifier associated with this UI */
  34. const char *task; /**< Task of the UI */
  35. const char *target; /**< UI target (UI toolkit or program name) */
  36. /**
  37. * Callback to execute modal interface.
  38. *
  39. * The @b object variable points to the input/output/encoder/etc. The
  40. * @b ui_data variable points to the UI parent or UI-specific data to
  41. * be used with the custom user interface.
  42. *
  43. * What @b ui_data points to differs depending on the target, and you
  44. * should use discretion and consistency when using this variable to
  45. * relay information to the UI function. For example, it would be
  46. * ideal to have @b ui_data point to a parent, QWidget for Qt, or a
  47. * wxWindow for wxWidgets, etc., though it's up to the discretion of
  48. * the developer to define that value. Because of the nature of void
  49. * pointers, discretion and consistency is advised.
  50. *
  51. * @param object Pointer/handle to the data associated with this
  52. * call.
  53. * @param ui_data UI data to pass associated with this specific
  54. * target, if any.
  55. * @return @b true if user completed the task, or
  56. * @b false if user cancelled the task.
  57. */
  58. bool (*exec)(void *object, void *ui_data);
  59. void *type_data;
  60. void (*free_type_data)(void *type_data);
  61. };
  62. /**
  63. * Registers a modal UI definition to the current obs context. This should be
  64. * used in obs_module_load.
  65. *
  66. * @param info Pointer to the modal definition structure
  67. */
  68. EXPORT void obs_register_modal_ui(const struct obs_modal_ui *info);
  69. /* ------------------------------------------------------------------------- */
  70. /** Modeless UI definition structure */
  71. struct obs_modeless_ui {
  72. const char *id; /**< Identifier associated with this UI */
  73. const char *task; /**< Task of the UI */
  74. const char *target; /**< UI target (UI toolkit or program name) */
  75. /**
  76. * Callback to create modeless interface.
  77. *
  78. * This function is almost identical to the modal exec function,
  79. * except modeless UI calls return immediately, and typically are
  80. * supposed to return a pointer or handle to the specific UI object
  81. * that was created. For example, a Qt object would ideally return a
  82. * pointer to a QWidget. Again, discretion and consistency is advised
  83. * for the return value.
  84. *
  85. * @param object Pointer/handle to the data associated with this
  86. * call.
  87. * @param ui_data UI data to pass associated with this specific
  88. * target, if any.
  89. * @return Pointer/handle to the modeless UI associated with
  90. * the specific target.
  91. */
  92. void *(*create)(void *object, void *ui_data);
  93. void *type_data;
  94. void (*free_type_data)(void *type_data);
  95. };
  96. /**
  97. * Registers a modeless UI definition to the current obs context. This should
  98. * be used in obs_module_load.
  99. *
  100. * @param info Pointer to the modal definition structure
  101. */
  102. EXPORT void obs_register_modeless_ui(const struct obs_modeless_ui *info);
  103. /* ------------------------------------------------------------------------- */
  104. #define OBS_UI_SUCCESS 0
  105. #define OBS_UI_CANCEL -1
  106. #define OBS_UI_NOTFOUND -2
  107. /**
  108. * Requests modal UI to be displayed. Returns when user is complete.
  109. *
  110. * @param name Name of the input/output/etc type that UI was requested for
  111. * @param task Task of the user interface (usually "config")
  112. * @param target Desired target (i.e. "qt", "wx", "gtk3", "win32", etc)
  113. * @param data Pointer to the obs input/output/etc
  114. * @param ui_data UI-specific data, usually a parent pointer/handle (if any)
  115. *
  116. * @return OBS_UI_SUCCESS if the UI was successful,
  117. * OBS_UI_CANCEL if the UI was cancelled by the user, or
  118. * OBS_UI_NOTFOUND if the UI callback was not found
  119. */
  120. EXPORT int obs_exec_ui(const char *id, const char *task, const char *target,
  121. void *data, void *ui_data);
  122. /**
  123. * Requests modeless UI to be created. Returns immediately.
  124. *
  125. * @param name Name of the input/output/etc type that UI was requested for
  126. * @param task Task of the user interface
  127. * @param target Desired target (i.e. "qt", "wx", "gtk3", "win32", etc)
  128. * @param data Pointer to the obs input/output/etc
  129. * @param ui_data UI-specific data, usually a parent pointer/handle (if any)
  130. *
  131. * @return Pointer/handle to the target-specific modeless object, or
  132. * NULL if not found or failed.
  133. */
  134. EXPORT void *obs_create_ui(const char *id, const char *task, const char *target,
  135. void *data, void *ui_data);
  136. #ifdef __cplusplus
  137. }
  138. #endif