obs-ui.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 varaible 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. };
  60. /**
  61. * Regsiters a modal UI definition to the current obs context. This should be
  62. * used in obs_module_load.
  63. *
  64. * @param info Pointer to the modal definition structure
  65. */
  66. EXPORT void obs_register_modal_ui(const struct obs_modal_ui *info);
  67. /* ------------------------------------------------------------------------- */
  68. /** Modeless UI definition structure */
  69. struct obs_modeless_ui {
  70. const char *id; /**< Identifier associated with this UI */
  71. const char *task; /**< Task of the UI */
  72. const char *target; /**< UI target (UI toolkit or program name) */
  73. /**
  74. * Callback to create modeless interface.
  75. *
  76. * This function is almost identical to the modal exec function,
  77. * except modeless UI calls return immediately, and typically are
  78. * supposed to return a pointer or handle to the specific UI object
  79. * that was created. For example, a Qt object would ideally return a
  80. * pointer to a QWidget. Again, discretion and consistency is advised
  81. * for the return value.
  82. *
  83. * @param object Pointer/handle to the data associated with this
  84. * call.
  85. * @param ui_data UI data to pass associated with this specific
  86. * target, if any.
  87. * @return Pointer/handle to the modeless UI associated with
  88. * the specific target.
  89. */
  90. void *(*create)(void *object, void *ui_data);
  91. };
  92. /**
  93. * Registers a modeless UI definition to the current obs context. This should
  94. * be used in obs_module_load.
  95. *
  96. * @param info Pointer to the modal definition structure
  97. */
  98. EXPORT void obs_register_modeless_ui(const struct obs_modeless_ui *info);
  99. /* ------------------------------------------------------------------------- */
  100. #define OBS_UI_SUCCESS 0
  101. #define OBS_UI_CANCEL -1
  102. #define OBS_UI_NOTFOUND -2
  103. /**
  104. * Requests modal UI to be displayed. Returns when user is complete.
  105. *
  106. * @param name Name of the input/output/etc type that UI was requested for
  107. * @param task Task of the user interface (usually "config")
  108. * @param target Desired target (i.e. "qt", "wx", "gtk3", "win32", etc)
  109. * @param data Pointer to the obs input/output/etc
  110. * @param ui_data UI-specific data, usually a parent pointer/handle (if any)
  111. *
  112. * @return OBS_UI_SUCCESS if the UI was successful,
  113. * OBS_UI_CANCEL if the UI was cancelled by the user, or
  114. * OBS_UI_NOTFOUND if the UI callback was not found
  115. */
  116. EXPORT int obs_exec_ui(const char *id, const char *task, const char *target,
  117. void *data, void *ui_data);
  118. /**
  119. * Requests modeless UI to be created. Returns immediately.
  120. *
  121. * @param name Name of the input/output/etc type that UI was requested for
  122. * @param task Task of the user interface
  123. * @param target Desired target (i.e. "qt", "wx", "gtk3", "win32", etc)
  124. * @param data Pointer to the obs input/output/etc
  125. * @param ui_data UI-specific data, usually a parent pointer/handle (if any)
  126. *
  127. * @return Pointer/handle to the target-specific modeless object, or
  128. * NULL if not found or failed.
  129. */
  130. EXPORT void *obs_create_ui(const char *id, const char *task,
  131. const char *target, void *data, void *ui_data);
  132. #ifdef __cplusplus
  133. }
  134. #endif