obs-ui.h 6.0 KB
Newer Older
J
jp9000 已提交
1
/******************************************************************************
J
jp9000 已提交
2
    Copyright (C) 2013-2014 by Hugh Bailey <obs.jim@gmail.com>
J
jp9000 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/

#pragma once

J
jp9000 已提交
20
#include "util/c99defs.h"
J
jp9000 已提交
21 22 23 24 25

#ifdef __cplusplus
extern "C" {
#endif

J
jp9000 已提交
26 27
/**
 *   @file
J
jp9000 已提交
28
 *
J
jp9000 已提交
29
 *   Modules can specify custom user-interface-specific exports.  UI functions
J
jp9000 已提交
30 31 32 33 34 35
 * can be within the same library as the actual core logic, or separated in to
 * different modules to split up UI logic and core module logic.
 *
 *   The reasoning for this is to allow for custom user interface of differing
 * toolkits or for automatically generated user interface, or to simply allow
 * separation of UI code from core code (which may often be in differing
J
jp9000 已提交
36
 * languages).
J
jp9000 已提交
37 38
 */

J
jp9000 已提交
39 40 41 42 43 44 45 46 47 48
/** Modal UI definition structure */
struct obs_modal_ui {
	const char *id;     /**< Identifier associated with this UI */
	const char *task;   /**< Task of the UI */
	const char *target; /**< UI target (UI toolkit or program name) */

	/**
	 * Callback to execute modal interface.
	 *
	 * The @b object variable points to the input/output/encoder/etc.  The
L
luz.paz 已提交
49
	 * @b ui_data variable points to the UI parent or UI-specific data to
J
jp9000 已提交
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
	 * be used with the custom user interface.
	 *
	 * What @b ui_data points to differs depending on the target, and you
	 * should use discretion and consistency when using this variable to
	 * relay information to the UI function.  For example, it would be
	 * ideal to have @b ui_data point to a parent, QWidget for Qt, or a
	 * wxWindow for wxWidgets, etc., though it's up to the discretion of
	 * the developer to define that value.  Because of the nature of void
	 * pointers, discretion and consistency is advised.
	 *
	 * @param  object   Pointer/handle to the data associated with this
	 *                  call.
	 * @param  ui_data  UI data to pass associated with this specific
	 *                  target, if any.
	 * @return          @b true if user completed the task, or
	 *                  @b false if user cancelled the task.
	 */
	bool (*exec)(void *object, void *ui_data);
68 69 70

	void *type_data;
	void (*free_type_data)(void *type_data);
J
jp9000 已提交
71 72
};

J
jp9000 已提交
73
/**
74
 * Registers a modal UI definition to the current obs context.  This should be
J
jp9000 已提交
75
 * used in obs_module_load.
J
jp9000 已提交
76
 *
J
jp9000 已提交
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
 * @param  info  Pointer to the modal definition structure
 */
EXPORT void obs_register_modal_ui(const struct obs_modal_ui *info);

/* ------------------------------------------------------------------------- */

/** Modeless UI definition structure */
struct obs_modeless_ui {
	const char *id;     /**< Identifier associated with this UI */
	const char *task;   /**< Task of the UI */
	const char *target; /**< UI target (UI toolkit or program name) */

	/**
	 * Callback to create modeless interface.
	 *
	 * This function is almost identical to the modal exec function,
	 * except modeless UI calls return immediately, and typically are
	 * supposed to return a pointer or handle to the specific UI object
	 * that was created.  For example, a Qt object would ideally return a
	 * pointer to a QWidget.  Again, discretion and consistency is advised
	 * for the return value.
	 *
	 * @param   object  Pointer/handle to the data associated with this
	 *                  call.
	 * @param  ui_data  UI data to pass associated with this specific
	 *                  target, if any.
	 * @return          Pointer/handle to the modeless UI associated with
	 *                  the specific target.
	 */
	void *(*create)(void *object, void *ui_data);
107 108 109

	void *type_data;
	void (*free_type_data)(void *type_data);
J
jp9000 已提交
110 111 112 113 114
};

/**
 * Registers a modeless UI definition to the current obs context.  This should
 * be used in obs_module_load.
J
jp9000 已提交
115
 *
J
jp9000 已提交
116
 * @param  info  Pointer to the modal definition structure
J
jp9000 已提交
117
 */
J
jp9000 已提交
118 119 120 121
EXPORT void obs_register_modeless_ui(const struct obs_modeless_ui *info);

/* ------------------------------------------------------------------------- */

J
jp9000 已提交
122 123
#define OBS_UI_SUCCESS 0
#define OBS_UI_CANCEL -1
J
jp9000 已提交
124 125
#define OBS_UI_NOTFOUND -2

J
jp9000 已提交
126 127 128 129 130 131 132 133 134 135 136 137 138 139
/**
 * Requests modal UI to be displayed.  Returns when user is complete.
 *
 * @param    name  Name of the input/output/etc type that UI was requested for
 * @param    task  Task of the user interface (usually "config")
 * @param  target  Desired target (i.e. "qt", "wx", "gtk3", "win32", etc)
 * @param    data  Pointer to the obs input/output/etc
 * @param ui_data  UI-specific data, usually a parent pointer/handle (if any)
 *
 * @return         OBS_UI_SUCCESS if the UI was successful,
 *                 OBS_UI_CANCEL if the UI was cancelled by the user, or
 *                 OBS_UI_NOTFOUND if the UI callback was not found
 */
EXPORT int obs_exec_ui(const char *id, const char *task, const char *target,
J
jp9000 已提交
140
		       void *data, void *ui_data);
J
jp9000 已提交
141

J
jp9000 已提交
142
/**
143
 * Requests modeless UI to be created.  Returns immediately.
J
jp9000 已提交
144
 *
J
jp9000 已提交
145 146 147 148 149
 * @param    name  Name of the input/output/etc type that UI was requested for
 * @param    task  Task of the user interface
 * @param  target  Desired target (i.e. "qt", "wx", "gtk3", "win32", etc)
 * @param    data  Pointer to the obs input/output/etc
 * @param ui_data  UI-specific data, usually a parent pointer/handle (if any)
J
jp9000 已提交
150
 *
J
jp9000 已提交
151 152
 * @return         Pointer/handle to the target-specific modeless object, or
 *                 NULL if not found or failed.
J
jp9000 已提交
153
 */
J
jp9000 已提交
154 155
EXPORT void *obs_create_ui(const char *id, const char *task, const char *target,
			   void *data, void *ui_data);
J
jp9000 已提交
156

J
jp9000 已提交
157 158 159
#ifdef __cplusplus
}
#endif