Skip to content

Commit

Permalink
split eas in and out
Browse files Browse the repository at this point in the history
  • Loading branch information
exeldro committed Mar 30, 2020
1 parent 145888d commit 3dbe758
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
3 changes: 2 additions & 1 deletion data/locale/en-US.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Name="Move"
Description="Transition that moves all sources to a new position"
EaseInOut="Ease in and out"
EaseIn="Ease in"
EaseOut="Ease out"
PositionIn="Position in"
PositionOut="Position out"
ZoomIn="Zoom in"
Expand Down
3 changes: 2 additions & 1 deletion data/locale/nl-NL.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Name="Move"
Description="Transitie die alle bronnen naar een nieuwe plek verplaats"
EaseInOut="Soepel in en uit"
EaseIn="Soepel in"
EaseOut="Soepel uit"
PositionIn="Positie in"
PositionOut="Positie uit"
ZoomIn="Zoem in"
Expand Down
40 changes: 29 additions & 11 deletions move-transition.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
#define S_POSITION_OUT "position_out"
#define S_ZOOM_IN "zoom_in"
#define S_ZOOM_OUT "zoom_out"
#define S_EASE_IN_OUT "ease_in_out"
#define S_EASE_IN "ease_in"
#define S_EASE_OUT "ease_out"

#define POS_NONE 0
#define POS_CENTER (1 << 0)
Expand All @@ -26,7 +27,8 @@ struct move_info {
obs_source_t *scene_source_a;
obs_source_t *scene_source_b;
gs_samplerstate_t *point_sampler;
bool ease_in_out;
bool ease_in;
bool ease_out;
bool zoom_in;
bool zoom_out;
long long position_in;
Expand Down Expand Up @@ -87,7 +89,8 @@ static void move_destroy(void *data)
static void move_update(void *data, obs_data_t *settings)
{
struct move_info *move = data;
move->ease_in_out = obs_data_get_bool(settings, S_EASE_IN_OUT);
move->ease_in = obs_data_get_bool(settings, S_EASE_IN);
move->ease_out = obs_data_get_bool(settings, S_EASE_OUT);
move->position_in = obs_data_get_int(settings, S_POSITION_IN);
move->zoom_in = obs_data_get_bool(settings, S_ZOOM_IN);
move->position_out = obs_data_get_int(settings, S_POSITION_OUT);
Expand Down Expand Up @@ -237,8 +240,8 @@ void calc_edge_position(struct vec2 *pos, long long position,
// pos is center of object
float diff_x = pos->x - (canvas_width >> 1);
float diff_y = pos->y - (canvas_height >> 1);
float factor_x = fabs(diff_x) / (canvas_width >> 1);
float factor_y = fabs(diff_y) / (canvas_height >> 1);
float factor_x = fabsf(diff_x) / (canvas_width >> 1);
float factor_y = fabsf(diff_y) / (canvas_height >> 1);

if (diff_x == 0.0f && diff_y == 0.0f) {
diff_y = 1.0f;
Expand Down Expand Up @@ -738,13 +741,27 @@ bool match_item(obs_scene_t *scene, obs_sceneitem_t *scene_item, void *data)
return true;
}

float ease_in(const float t)
{
return t * t * t;
}

float ease_out(const float t)
{
return 1.0f - (1.0f - t) * (1.0f - t) * (1.0f - t);
}

static void move_video_render(void *data, gs_effect_t *effect)
{
struct move_info *move = data;

float t = obs_transition_get_time(move->source);
if (move->ease_in_out) {
if (move->ease_in && move->ease_out) {
move->t = cubic_ease_in_out(t);
} else if (move->ease_in) {
move->t = ease_in(t);
} else if (move->ease_out) {
move->t = ease_out(t);
} else {
move->t = t;
}
Expand Down Expand Up @@ -863,27 +880,28 @@ static obs_properties_t *move_properties(void *data)
{
obs_properties_t *ppts = obs_properties_create();
obs_property_t *p;
obs_properties_add_bool(ppts, S_EASE_IN_OUT,
obs_module_text("EaseInOut"));
obs_properties_add_bool(ppts, S_EASE_IN, obs_module_text("EaseIn"));
obs_properties_add_bool(ppts, S_ZOOM_IN, obs_module_text("ZoomIn"));
p = obs_properties_add_list(ppts, S_POSITION_IN,
obs_module_text("PositionIn"),
OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT);
prop_list_add_positions(p);
obs_properties_add_bool(ppts, S_ZOOM_IN, obs_module_text("ZoomIn"));

obs_properties_add_bool(ppts, S_EASE_OUT, obs_module_text("EaseOut"));
obs_properties_add_bool(ppts, S_ZOOM_OUT, obs_module_text("ZoomOut"));
p = obs_properties_add_list(ppts, S_POSITION_OUT,
obs_module_text("PositionOut"),
OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT);
prop_list_add_positions(p);
obs_properties_add_bool(ppts, S_ZOOM_OUT, obs_module_text("ZoomOut"));

UNUSED_PARAMETER(data);
return ppts;
}

void move_defaults(obs_data_t *settings)
{
obs_data_set_default_bool(settings, S_EASE_IN_OUT, true);
obs_data_set_default_bool(settings, S_EASE_IN, true);
obs_data_set_default_bool(settings, S_EASE_OUT, true);
obs_data_set_default_int(settings, S_POSITION_IN, POS_EDGE | POS_LEFT);
obs_data_set_default_bool(settings, S_ZOOM_IN, true);
obs_data_set_default_int(settings, S_POSITION_OUT,
Expand Down

0 comments on commit 3dbe758

Please sign in to comment.