Add module UI export capability
Add the ability to be able to call and use toolkit-specific or program-specific user interface in modules. User interface code can be either bundled with the module, or 'split' out in to separate libraries (recommended). There are three reasons why splitting is recommended: 1.) It allows plugins to be able to create custom user interface for each toolkit if desired. 2.) Often, UI will be programmed in one language (the language of the toolkit), and core logic may be programmed in another. This allows plugins to keep the languages separated if necessary. 3.) It prevents direct linkage of UI toolkits libraries with core module logic. Splitting is not required, though is recommended if you want your plugin to be more flexible with other user interface toolkits or programs. Will implement a generic properties lookup next, which will be used for automatic UI handling so that plugin UI isn't necessarily required.
This commit is contained in:
32
libobs/obs.c
32
libobs/obs.c
@@ -326,6 +326,7 @@ void obs_shutdown(void)
|
||||
da_free(obs->transition_types);
|
||||
da_free(obs->output_types);
|
||||
da_free(obs->service_types);
|
||||
da_free(obs->ui_callbacks);
|
||||
|
||||
obs_free_data();
|
||||
obs_free_video();
|
||||
@@ -451,6 +452,37 @@ video_t obs_video(void)
|
||||
return (obs != NULL) ? obs->video.video : NULL;
|
||||
}
|
||||
|
||||
/* TODO: optimize this later so it's not just O(N) string lookups */
|
||||
static inline struct ui_callback *get_ui_callback(const char *name,
|
||||
const char *task, const char *target)
|
||||
{
|
||||
for (size_t i = 0; i < obs->ui_callbacks.num; i++) {
|
||||
struct ui_callback *callback = obs->ui_callbacks.array+i;
|
||||
|
||||
if (strcmp(callback->ui_info.name, name) == 0 &&
|
||||
strcmp(callback->ui_info.task, task) == 0 &&
|
||||
strcmp(callback->ui_info.target, target) == 0)
|
||||
return callback;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int obs_call_ui(const char *name, const char *task, const char *target,
|
||||
void *data, void *ui_data)
|
||||
{
|
||||
struct ui_callback *callback;
|
||||
int errorcode = OBS_UI_NOTFOUND;
|
||||
|
||||
callback = get_ui_callback(name, task, target);
|
||||
if (callback) {
|
||||
bool success = callback->callback(data, ui_data);
|
||||
errorcode = success ? OBS_UI_SUCCESS : OBS_UI_CANCEL;
|
||||
}
|
||||
|
||||
return errorcode;
|
||||
}
|
||||
|
||||
bool obs_add_source(obs_source_t source)
|
||||
{
|
||||
struct calldata params = {0};
|
||||
|
Reference in New Issue
Block a user