Merge pull request #1917 from VodBox/scroll-loop-option
libobs/obs-filters: Add toggle for scroll filter looping
This commit is contained in:
commit
3542e4eac1
@ -1088,6 +1088,18 @@ void obs_source_video_tick(obs_source_t *source, float seconds)
|
||||
hide_source(source);
|
||||
}
|
||||
|
||||
if (source->filters.num) {
|
||||
for (size_t i = source->filters.num; i > 0; i--) {
|
||||
obs_source_t *filter =
|
||||
source->filters.array[i - 1];
|
||||
if (now_showing) {
|
||||
show_source(filter);
|
||||
} else {
|
||||
hide_source(filter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
source->showing = now_showing;
|
||||
}
|
||||
|
||||
@ -1100,6 +1112,18 @@ void obs_source_video_tick(obs_source_t *source, float seconds)
|
||||
deactivate_source(source);
|
||||
}
|
||||
|
||||
if (source->filters.num) {
|
||||
for (size_t i = source->filters.num; i > 0; i--) {
|
||||
obs_source_t *filter =
|
||||
source->filters.array[i - 1];
|
||||
if (now_active) {
|
||||
activate_source(filter);
|
||||
} else {
|
||||
deactivate_source(filter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
source->active = now_active;
|
||||
}
|
||||
|
||||
|
@ -46,6 +46,7 @@ ScrollFilter.SpeedX="Horizontal Speed"
|
||||
ScrollFilter.SpeedY="Vertical Speed"
|
||||
ScrollFilter.LimitWidth="Limit Width"
|
||||
ScrollFilter.LimitHeight="Limit Height"
|
||||
ScrollFilter.Loop="Loop"
|
||||
CustomColor="Custom Color"
|
||||
Red="Red"
|
||||
Green="Green"
|
||||
|
@ -18,6 +18,8 @@ struct scroll_filter_data {
|
||||
|
||||
struct vec2 size_i;
|
||||
struct vec2 offset;
|
||||
|
||||
bool loop;
|
||||
};
|
||||
|
||||
static const char *scroll_filter_get_name(void *unused)
|
||||
@ -31,15 +33,10 @@ static void *scroll_filter_create(obs_data_t *settings, obs_source_t *context)
|
||||
struct scroll_filter_data *filter = bzalloc(sizeof(*filter));
|
||||
char *effect_path = obs_module_file("crop_filter.effect");
|
||||
|
||||
struct gs_sampler_info sampler_info = {.filter = GS_FILTER_LINEAR,
|
||||
.address_u = GS_ADDRESS_WRAP,
|
||||
.address_v = GS_ADDRESS_WRAP};
|
||||
|
||||
filter->context = context;
|
||||
|
||||
obs_enter_graphics();
|
||||
filter->effect = gs_effect_create_from_file(effect_path, NULL);
|
||||
filter->sampler = gs_samplerstate_create(&sampler_info);
|
||||
obs_leave_graphics();
|
||||
|
||||
bfree(effect_path);
|
||||
@ -86,6 +83,19 @@ static void scroll_filter_update(void *data, obs_data_t *settings)
|
||||
filter->scroll_speed.y =
|
||||
(float)obs_data_get_double(settings, "speed_y");
|
||||
|
||||
filter->loop = obs_data_get_bool(settings, "loop");
|
||||
|
||||
struct gs_sampler_info sampler_info = {
|
||||
.filter = GS_FILTER_LINEAR,
|
||||
.address_u = filter->loop ? GS_ADDRESS_WRAP : GS_ADDRESS_BORDER,
|
||||
.address_v = filter->loop ? GS_ADDRESS_WRAP : GS_ADDRESS_BORDER,
|
||||
};
|
||||
|
||||
obs_enter_graphics();
|
||||
gs_samplerstate_destroy(filter->sampler);
|
||||
filter->sampler = gs_samplerstate_create(&sampler_info);
|
||||
obs_leave_graphics();
|
||||
|
||||
if (filter->scroll_speed.x == 0.0f)
|
||||
filter->offset.x = 0.0f;
|
||||
if (filter->scroll_speed.y == 0.0f)
|
||||
@ -136,6 +146,9 @@ static obs_properties_t *scroll_filter_properties(void *data)
|
||||
obs_properties_add_int(props, "cy", obs_module_text("Crop.Height"), 1,
|
||||
8192, 1);
|
||||
|
||||
obs_properties_add_bool(props, "loop",
|
||||
obs_module_text("ScrollFilter.Loop"));
|
||||
|
||||
UNUSED_PARAMETER(data);
|
||||
return props;
|
||||
}
|
||||
@ -145,6 +158,7 @@ static void scroll_filter_defaults(obs_data_t *settings)
|
||||
obs_data_set_default_bool(settings, "limit_size", false);
|
||||
obs_data_set_default_int(settings, "cx", 100);
|
||||
obs_data_set_default_int(settings, "cy", 100);
|
||||
obs_data_set_default_bool(settings, "loop", true);
|
||||
}
|
||||
|
||||
static void scroll_filter_tick(void *data, float seconds)
|
||||
@ -154,10 +168,17 @@ static void scroll_filter_tick(void *data, float seconds)
|
||||
filter->offset.x += filter->size_i.x * filter->scroll_speed.x * seconds;
|
||||
filter->offset.y += filter->size_i.y * filter->scroll_speed.y * seconds;
|
||||
|
||||
if (filter->offset.x > 1.0f)
|
||||
filter->offset.x -= 1.0f;
|
||||
if (filter->offset.y > 1.0f)
|
||||
filter->offset.y -= 1.0f;
|
||||
if (filter->loop) {
|
||||
if (filter->offset.x > 1.0f)
|
||||
filter->offset.x -= 1.0f;
|
||||
if (filter->offset.y > 1.0f)
|
||||
filter->offset.y -= 1.0f;
|
||||
} else {
|
||||
if (filter->offset.x > 1.0f)
|
||||
filter->offset.x = 1.0f;
|
||||
if (filter->offset.y > 1.0f)
|
||||
filter->offset.y = 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
static void scroll_filter_render(void *data, gs_effect_t *effect)
|
||||
@ -220,6 +241,13 @@ static uint32_t scroll_filter_height(void *data)
|
||||
: obs_source_get_base_height(target);
|
||||
}
|
||||
|
||||
static void scroll_filter_show(void *data)
|
||||
{
|
||||
struct scroll_filter_data *filter = data;
|
||||
filter->offset.x = 0.0f;
|
||||
filter->offset.y = 0.0f;
|
||||
}
|
||||
|
||||
struct obs_source_info scroll_filter = {
|
||||
.id = "scroll_filter",
|
||||
.type = OBS_SOURCE_TYPE_FILTER,
|
||||
@ -234,4 +262,5 @@ struct obs_source_info scroll_filter = {
|
||||
.video_render = scroll_filter_render,
|
||||
.get_width = scroll_filter_width,
|
||||
.get_height = scroll_filter_height,
|
||||
.show = scroll_filter_show,
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user