Merge pull request #2285 from cg2121/source-defaults

obs-plugins: Change defaults of various plugins
This commit is contained in:
Jim 2020-01-15 03:19:14 -08:00 committed by GitHub
commit 8c7a6518a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 113 additions and 41 deletions

View File

@ -99,22 +99,49 @@ static uint32_t color_source_getheight(void *data)
return context->height;
}
static void color_source_defaults(obs_data_t *settings)
static void color_source_defaults_v1(obs_data_t *settings)
{
obs_data_set_default_int(settings, "color", 0xFFFFFFFF);
obs_data_set_default_int(settings, "width", 400);
obs_data_set_default_int(settings, "height", 400);
}
struct obs_source_info color_source_info = {
static void color_source_defaults_v2(obs_data_t *settings)
{
struct obs_video_info ovi;
obs_get_video_info(&ovi);
obs_data_set_default_int(settings, "color", 0xFFFFFFFF);
obs_data_set_default_int(settings, "width", ovi.base_width);
obs_data_set_default_int(settings, "height", ovi.base_width);
}
struct obs_source_info color_source_info_v1 = {
.id = "color_source",
.type = OBS_SOURCE_TYPE_INPUT,
.output_flags = OBS_SOURCE_VIDEO | OBS_SOURCE_CUSTOM_DRAW,
.output_flags = OBS_SOURCE_VIDEO | OBS_SOURCE_CUSTOM_DRAW |
OBS_SOURCE_CAP_OBSOLETE,
.create = color_source_create,
.destroy = color_source_destroy,
.update = color_source_update,
.get_name = color_source_get_name,
.get_defaults = color_source_defaults,
.get_defaults = color_source_defaults_v1,
.get_width = color_source_getwidth,
.get_height = color_source_getheight,
.video_render = color_source_render,
.get_properties = color_source_properties,
.icon_type = OBS_ICON_TYPE_COLOR,
};
struct obs_source_info color_source_info_v2 = {
.id = "color_source_v2",
.type = OBS_SOURCE_TYPE_INPUT,
.output_flags = OBS_SOURCE_VIDEO | OBS_SOURCE_CUSTOM_DRAW,
.create = color_source_create,
.destroy = color_source_destroy,
.update = color_source_update,
.get_name = color_source_get_name,
.get_defaults = color_source_defaults_v2,
.get_width = color_source_getwidth,
.get_height = color_source_getheight,
.video_render = color_source_render,

View File

@ -277,12 +277,14 @@ MODULE_EXPORT const char *obs_module_description(void)
}
extern struct obs_source_info slideshow_info;
extern struct obs_source_info color_source_info;
extern struct obs_source_info color_source_info_v1;
extern struct obs_source_info color_source_info_v2;
bool obs_module_load(void)
{
obs_register_source(&image_source_info);
obs_register_source(&color_source_info);
obs_register_source(&color_source_info_v1);
obs_register_source(&color_source_info_v2);
obs_register_source(&slideshow_info);
return true;
}

View File

@ -1035,12 +1035,41 @@ static obs_properties_t *get_properties(void *data)
return props;
}
static void defaults(obs_data_t *settings, int ver)
{
obs_data_t *font_obj = obs_data_create();
obs_data_set_default_string(font_obj, "face", "Arial");
obs_data_set_default_int(font_obj, "size", ver == 1 ? 36 : 256);
obs_data_set_default_obj(settings, S_FONT, font_obj);
obs_data_set_default_string(settings, S_ALIGN, S_ALIGN_LEFT);
obs_data_set_default_string(settings, S_VALIGN, S_VALIGN_TOP);
obs_data_set_default_int(settings, S_COLOR, 0xFFFFFF);
obs_data_set_default_int(settings, S_OPACITY, 100);
obs_data_set_default_int(settings, S_GRADIENT_COLOR, 0xFFFFFF);
obs_data_set_default_int(settings, S_GRADIENT_OPACITY, 100);
obs_data_set_default_double(settings, S_GRADIENT_DIR, 90.0);
obs_data_set_default_int(settings, S_BKCOLOR, 0x000000);
obs_data_set_default_int(settings, S_BKOPACITY, 0);
obs_data_set_default_int(settings, S_OUTLINE_SIZE, 2);
obs_data_set_default_int(settings, S_OUTLINE_COLOR, 0xFFFFFF);
obs_data_set_default_int(settings, S_OUTLINE_OPACITY, 100);
obs_data_set_default_int(settings, S_CHATLOG_LINES, 6);
obs_data_set_default_bool(settings, S_EXTENTS_WRAP, true);
obs_data_set_default_int(settings, S_EXTENTS_CX, 100);
obs_data_set_default_int(settings, S_EXTENTS_CY, 100);
obs_data_set_default_int(settings, S_TRANSFORM, S_TRANSFORM_NONE);
obs_data_release(font_obj);
};
bool obs_module_load(void)
{
obs_source_info si = {};
si.id = "text_gdiplus";
si.type = OBS_SOURCE_TYPE_INPUT;
si.output_flags = OBS_SOURCE_VIDEO | OBS_SOURCE_CUSTOM_DRAW;
si.output_flags = OBS_SOURCE_VIDEO | OBS_SOURCE_CUSTOM_DRAW |
OBS_SOURCE_CAP_OBSOLETE;
si.get_properties = get_properties;
si.icon_type = OBS_ICON_TYPE_TEXT;
@ -1057,33 +1086,7 @@ bool obs_module_load(void)
si.get_height = [](void *data) {
return reinterpret_cast<TextSource *>(data)->cy;
};
si.get_defaults = [](obs_data_t *settings) {
obs_data_t *font_obj = obs_data_create();
obs_data_set_default_string(font_obj, "face", "Arial");
obs_data_set_default_int(font_obj, "size", 36);
obs_data_set_default_obj(settings, S_FONT, font_obj);
obs_data_set_default_string(settings, S_ALIGN, S_ALIGN_LEFT);
obs_data_set_default_string(settings, S_VALIGN, S_VALIGN_TOP);
obs_data_set_default_int(settings, S_COLOR, 0xFFFFFF);
obs_data_set_default_int(settings, S_OPACITY, 100);
obs_data_set_default_int(settings, S_GRADIENT_COLOR, 0xFFFFFF);
obs_data_set_default_int(settings, S_GRADIENT_OPACITY, 100);
obs_data_set_default_double(settings, S_GRADIENT_DIR, 90.0);
obs_data_set_default_int(settings, S_BKCOLOR, 0x000000);
obs_data_set_default_int(settings, S_BKOPACITY, 0);
obs_data_set_default_int(settings, S_OUTLINE_SIZE, 2);
obs_data_set_default_int(settings, S_OUTLINE_COLOR, 0xFFFFFF);
obs_data_set_default_int(settings, S_OUTLINE_OPACITY, 100);
obs_data_set_default_int(settings, S_CHATLOG_LINES, 6);
obs_data_set_default_bool(settings, S_EXTENTS_WRAP, true);
obs_data_set_default_int(settings, S_EXTENTS_CX, 100);
obs_data_set_default_int(settings, S_EXTENTS_CY, 100);
obs_data_set_default_int(settings, S_TRANSFORM,
S_TRANSFORM_NONE);
obs_data_release(font_obj);
};
si.get_defaults = [](obs_data_t *settings) { defaults(settings, 1); };
si.update = [](void *data, obs_data_t *settings) {
reinterpret_cast<TextSource *>(data)->Update(settings);
};
@ -1094,7 +1097,15 @@ bool obs_module_load(void)
reinterpret_cast<TextSource *>(data)->Render();
};
obs_source_info si_v2 = si;
si_v2.id = "text_gdiplus_v2";
si_v2.output_flags &= ~OBS_SOURCE_CAP_OBSOLETE;
si_v2.get_defaults = [](obs_data_t *settings) {
defaults(settings, 2);
};
obs_register_source(&si);
obs_register_source(&si_v2);
const GdiplusStartupInput gdip_input;
GdiplusStartup(&gdip_token, &gdip_input, nullptr);

View File

@ -35,16 +35,33 @@ MODULE_EXPORT const char *obs_module_description(void)
uint32_t texbuf_w = 2048, texbuf_h = 2048;
static struct obs_source_info freetype2_source_info = {
static struct obs_source_info freetype2_source_info_v1 = {
.id = "text_ft2_source",
.type = OBS_SOURCE_TYPE_INPUT,
.output_flags = OBS_SOURCE_VIDEO | OBS_SOURCE_CAP_OBSOLETE |
OBS_SOURCE_CUSTOM_DRAW,
.get_name = ft2_source_get_name,
.create = ft2_source_create_v1,
.destroy = ft2_source_destroy,
.update = ft2_source_update,
.get_width = ft2_source_get_width,
.get_height = ft2_source_get_height,
.video_render = ft2_source_render,
.video_tick = ft2_video_tick,
.get_properties = ft2_source_properties,
.icon_type = OBS_ICON_TYPE_TEXT,
};
static struct obs_source_info freetype2_source_info_v2 = {
.id = "text_ft2_source_v2",
.type = OBS_SOURCE_TYPE_INPUT,
.output_flags = OBS_SOURCE_VIDEO |
#ifdef _WIN32
OBS_SOURCE_DEPRECATED |
#endif
OBS_SOURCE_CUSTOM_DRAW,
.get_name = ft2_source_get_name,
.create = ft2_source_create,
.create = ft2_source_create_v2,
.destroy = ft2_source_destroy,
.update = ft2_source_update,
.get_width = ft2_source_get_width,
@ -83,7 +100,8 @@ bool obs_module_load()
bfree(config_dir);
}
obs_register_source(&freetype2_source_info);
obs_register_source(&freetype2_source_info_v1);
obs_register_source(&freetype2_source_info_v2);
return true;
}
@ -469,7 +487,8 @@ error:
#define DEFAULT_FACE "Sans Serif"
#endif
static void *ft2_source_create(obs_data_t *settings, obs_source_t *source)
static void *ft2_source_create(obs_data_t *settings, obs_source_t *source,
int ver)
{
struct ft2_source *srcdata = bzalloc(sizeof(struct ft2_source));
obs_data_t *font_obj = obs_data_create();
@ -477,10 +496,12 @@ static void *ft2_source_create(obs_data_t *settings, obs_source_t *source)
init_plugin();
srcdata->font_size = 32;
const uint16_t font_size = ver == 1 ? 32 : 256;
srcdata->font_size = font_size;
obs_data_set_default_string(font_obj, "face", DEFAULT_FACE);
obs_data_set_default_int(font_obj, "size", 32);
obs_data_set_default_int(font_obj, "size", font_size);
obs_data_set_default_obj(settings, "font", font_obj);
obs_data_set_default_int(settings, "log_lines", 6);
@ -494,3 +515,13 @@ static void *ft2_source_create(obs_data_t *settings, obs_source_t *source)
return srcdata;
}
static void *ft2_source_create_v1(obs_data_t *settings, obs_source_t *source)
{
return ft2_source_create(settings, source, 1);
}
static void *ft2_source_create_v2(obs_data_t *settings, obs_source_t *source)
{
return ft2_source_create(settings, source, 2);
}

View File

@ -69,7 +69,8 @@ struct ft2_source {
extern FT_Library ft2_lib;
static void *ft2_source_create(obs_data_t *settings, obs_source_t *source);
static void *ft2_source_create_v1(obs_data_t *settings, obs_source_t *source);
static void *ft2_source_create_v2(obs_data_t *settings, obs_source_t *source);
static void ft2_source_destroy(void *data);
static void ft2_source_update(void *data, obs_data_t *settings);
static void ft2_source_render(void *data, gs_effect_t *effect);