forked from exeldro/obs-move-transition
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmove-transition.c
2461 lines (2301 loc) · 71.4 KB
/
move-transition.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "move-transition.h"
#include <obs-module.h>
#include <../UI/obs-frontend-api/obs-frontend-api.h>
#include "../obs-transitions/easings.h"
#include "graphics/math-defs.h"
#include "graphics/matrix4.h"
#include "easing.h"
#include "version.h"
struct move_info {
obs_source_t *source;
bool start_init;
DARRAY(struct move_item *) items_a;
DARRAY(struct move_item *) items_b;
float t;
float curve_move;
float curve_in;
float curve_out;
obs_source_t *scene_source_a;
obs_source_t *scene_source_b;
gs_samplerstate_t *point_sampler;
long long easing_move;
long long easing_in;
long long easing_out;
long long easing_function_move;
long long easing_function_in;
long long easing_function_out;
bool zoom_in;
bool zoom_out;
long long position_in;
long long position_out;
char *transition_move;
char *transition_in;
char *transition_out;
bool part_match;
bool number_match;
bool last_word_match;
enum obs_transition_scale_type transition_move_scale;
size_t item_pos;
uint32_t matched_items;
bool matched_scene_a;
bool matched_scene_b;
uint32_t item_order_switch_percentage;
bool cache_transitions;
DARRAY(obs_source_t *) transition_pool_move;
size_t transition_pool_move_index;
DARRAY(obs_source_t *) transition_pool_in;
size_t transition_pool_in_index;
DARRAY(obs_source_t *) transition_pool_out;
size_t transition_pool_out_index;
};
struct move_item {
obs_sceneitem_t *item_a;
obs_sceneitem_t *item_b;
gs_texrender_t *item_render;
obs_source_t *transition;
long long easing;
long long easing_function;
bool zoom;
long long position;
char *transition_name;
enum obs_transition_scale_type transition_scale;
float curve;
bool move_scene;
int start_percentage;
int end_percentage;
obs_scene_t *release_scene_a;
obs_scene_t *release_scene_b;
};
static const char *move_get_name(void *type_data)
{
UNUSED_PARAMETER(type_data);
return obs_module_text("Move");
}
static void *move_create(obs_data_t *settings, obs_source_t *source)
{
struct move_info *move = bzalloc(sizeof(struct move_info));
move->source = source;
da_init(move->items_a);
da_init(move->items_b);
da_init(move->transition_pool_out);
da_init(move->transition_pool_in);
da_init(move->transition_pool_out);
obs_source_update(source, settings);
return move;
}
static void clear_items(struct move_info *move, bool in_graphics)
{
bool graphics = false;
for (size_t i = 0; i < move->items_a.num; i++) {
struct move_item *item = move->items_a.array[i];
if (item->item_render) {
if (!graphics && !in_graphics) {
obs_enter_graphics();
graphics = true;
}
gs_texrender_destroy(item->item_render);
item->item_render = NULL;
}
}
if (graphics)
obs_leave_graphics();
for (size_t i = 0; i < move->items_a.num; i++) {
struct move_item *item = move->items_a.array[i];
obs_scene_release(item->release_scene_a);
item->release_scene_a = NULL;
obs_sceneitem_release(item->item_a);
item->item_a = NULL;
obs_scene_release(item->release_scene_b);
item->release_scene_b = NULL;
obs_sceneitem_release(item->item_b);
item->item_b = NULL;
if (item->transition) {
obs_transition_force_stop(item->transition);
obs_transition_clear(item->transition);
obs_source_release(item->transition);
item->transition = NULL;
}
bfree(item->transition_name);
bfree(item);
}
move->items_a.num = 0;
move->items_b.num = 0;
}
void clear_transition_pool(void *data)
{
DARRAY(obs_source_t *) *transition_pool = data;
for (size_t i = 0; i < transition_pool->num; i++) {
obs_source_release(transition_pool->array[i]);
}
transition_pool->num = 0;
}
static void move_destroy(void *data)
{
struct move_info *move = data;
clear_items(move, false);
da_free(move->items_a);
da_free(move->items_b);
clear_transition_pool(&move->transition_pool_move);
da_free(move->transition_pool_move);
clear_transition_pool(&move->transition_pool_in);
da_free(move->transition_pool_in);
clear_transition_pool(&move->transition_pool_out);
da_free(move->transition_pool_out);
obs_source_release(move->scene_source_a);
obs_source_release(move->scene_source_b);
bfree(move->transition_in);
bfree(move->transition_out);
bfree(move->transition_move);
if (move->point_sampler) {
obs_enter_graphics();
gs_samplerstate_destroy(move->point_sampler);
obs_leave_graphics();
}
bfree(move);
}
static void move_update(void *data, obs_data_t *settings)
{
struct move_info *move = data;
move->easing_move = obs_data_get_int(settings, S_EASING_MATCH);
move->easing_in = obs_data_get_int(settings, S_EASING_IN);
move->easing_out = obs_data_get_int(settings, S_EASING_OUT);
move->easing_function_move =
obs_data_get_int(settings, S_EASING_FUNCTION_MATCH);
move->easing_function_in =
obs_data_get_int(settings, S_EASING_FUNCTION_IN);
move->easing_function_out =
obs_data_get_int(settings, S_EASING_FUNCTION_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);
move->zoom_out = obs_data_get_bool(settings, S_ZOOM_OUT);
move->curve_move = (float)obs_data_get_double(settings, S_CURVE_MATCH);
move->curve_in = (float)obs_data_get_double(settings, S_CURVE_IN);
move->curve_out = (float)obs_data_get_double(settings, S_CURVE_OUT);
bfree(move->transition_in);
move->transition_in =
bstrdup(obs_data_get_string(settings, S_TRANSITION_IN));
if (move->transition_in && strlen(move->transition_in) &&
move->transition_pool_in.num &&
strcmp(obs_source_get_name(move->transition_pool_in.array[0]),
move->transition_in) != 0) {
clear_transition_pool(&move->transition_pool_in);
}
bfree(move->transition_out);
move->transition_out =
bstrdup(obs_data_get_string(settings, S_TRANSITION_OUT));
if (move->transition_out && strlen(move->transition_out) &&
move->transition_pool_out.num &&
strcmp(obs_source_get_name(move->transition_pool_out.array[0]),
move->transition_out) != 0) {
clear_transition_pool(&move->transition_pool_out);
}
move->part_match = obs_data_get_bool(settings, S_NAME_PART_MATCH);
move->number_match = obs_data_get_bool(settings, S_NAME_NUMBER_MATCH);
move->last_word_match =
obs_data_get_bool(settings, S_NAME_LAST_WORD_MATCH);
bfree(move->transition_move);
move->transition_move =
bstrdup(obs_data_get_string(settings, S_TRANSITION_MATCH));
if (move->transition_move && strlen(move->transition_move) &&
move->transition_pool_move.num &&
strcmp(obs_source_get_name(move->transition_pool_move.array[0]),
move->transition_move) != 0) {
clear_transition_pool(&move->transition_pool_move);
}
move->transition_move_scale =
obs_data_get_int(settings, S_TRANSITION_SCALE);
move->item_order_switch_percentage =
(uint32_t)obs_data_get_int(settings, S_SWITCH_PERCENTAGE);
move->cache_transitions =
obs_data_get_bool(settings, S_CACHE_TRANSITIONS);
}
void add_alignment(struct vec2 *v, uint32_t align, int cx, int cy)
{
if (align & OBS_ALIGN_RIGHT)
v->x += (float)cx;
else if ((align & OBS_ALIGN_LEFT) == 0)
v->x += (float)(cx >> 1);
if (align & OBS_ALIGN_BOTTOM)
v->y += (float)cy;
else if ((align & OBS_ALIGN_TOP) == 0)
v->y += (float)(cy >> 1);
}
void add_move_alignment(struct vec2 *v, uint32_t align_a, uint32_t align_b,
float t, int cx, int cy)
{
if (align_a & OBS_ALIGN_RIGHT)
v->x += (float)cx * (1.0f - t);
else if ((align_a & OBS_ALIGN_LEFT) == 0)
v->x += (float)(cx >> 1) * (1.0f - t);
if (align_a & OBS_ALIGN_BOTTOM)
v->y += (float)cy * (1.0f - t);
else if ((align_a & OBS_ALIGN_TOP) == 0)
v->y += (float)(cy >> 1) * (1.0f - t);
if (align_b & OBS_ALIGN_RIGHT)
v->x += (float)cx * t;
else if ((align_b & OBS_ALIGN_LEFT) == 0)
v->x += (float)(cx >> 1) * t;
if (align_b & OBS_ALIGN_BOTTOM)
v->y += (float)cy * t;
else if ((align_b & OBS_ALIGN_TOP) == 0)
v->y += (float)(cy >> 1) * t;
}
static void calculate_bounds_data(struct obs_scene_item *item,
struct vec2 *origin, struct vec2 *scale,
uint32_t *cx, uint32_t *cy,
struct vec2 *bounds)
{
float width = (float)(*cx) * fabsf(scale->x);
float height = (float)(*cy) * fabsf(scale->y);
const float item_aspect = width / height;
const float bounds_aspect = bounds->x / bounds->y;
uint32_t bounds_type = obs_sceneitem_get_bounds_type(item);
if (bounds_type == OBS_BOUNDS_MAX_ONLY)
if (width > bounds->x || height > bounds->y)
bounds_type = OBS_BOUNDS_SCALE_INNER;
if (bounds_type == OBS_BOUNDS_SCALE_INNER ||
bounds_type == OBS_BOUNDS_SCALE_OUTER) {
bool use_width = (bounds_aspect < item_aspect);
if (obs_sceneitem_get_bounds_type(item) ==
OBS_BOUNDS_SCALE_OUTER)
use_width = !use_width;
const float mul = use_width ? bounds->x / width
: bounds->y / height;
vec2_mulf(scale, scale, mul);
} else if (bounds_type == OBS_BOUNDS_SCALE_TO_WIDTH) {
vec2_mulf(scale, scale, bounds->x / width);
} else if (bounds_type == OBS_BOUNDS_SCALE_TO_HEIGHT) {
vec2_mulf(scale, scale, bounds->y / height);
} else if (bounds_type == OBS_BOUNDS_STRETCH) {
scale->x = bounds->x / (float)(*cx);
scale->y = bounds->y / (float)(*cy);
}
width = (float)(*cx) * scale->x;
height = (float)(*cy) * scale->y;
const float width_diff = bounds->x - width;
const float height_diff = bounds->y - height;
*cx = (uint32_t)bounds->x;
*cy = (uint32_t)bounds->y;
add_alignment(origin, obs_sceneitem_get_bounds_alignment(item),
(int)-width_diff, (int)-height_diff);
}
static void calculate_move_bounds_data(struct obs_scene_item *item_a,
struct obs_scene_item *item_b, float t,
struct vec2 *origin, struct vec2 *scale,
uint32_t *cx, uint32_t *cy,
struct vec2 *bounds)
{
struct vec2 origin_a;
vec2_set(&origin_a, origin->x, origin->y);
struct vec2 origin_b;
vec2_set(&origin_b, origin->x, origin->y);
struct vec2 scale_a;
vec2_set(&scale_a, scale->x, scale->y);
struct vec2 scale_b;
vec2_set(&scale_b, scale->x, scale->y);
uint32_t cxa = *cx;
uint32_t cxb = *cx;
uint32_t cya = *cy;
uint32_t cyb = *cy;
calculate_bounds_data(item_a, &origin_a, &scale_a, &cxa, &cya, bounds);
calculate_bounds_data(item_b, &origin_b, &scale_b, &cxb, &cyb, bounds);
vec2_set(origin, origin_a.x * (1.0f - t) + origin_b.x * t,
origin_a.y * (1.0f - t) + origin_b.y * t);
vec2_set(scale, scale_a.x * (1.0f - t) + scale_b.x * t,
scale_a.y * (1.0f - t) + scale_b.y * t);
*cx = (uint32_t)((float)cxa * (1.0f - t) + (float)cxb * t);
*cy = (uint32_t)((float)cya * (1.0f - t) + (float)cyb * t);
}
static inline bool item_is_scene(struct obs_scene_item *item)
{
obs_source_t *source = obs_sceneitem_get_source(item);
return source && obs_source_get_type(source) == OBS_SOURCE_TYPE_SCENE;
}
static inline bool scale_filter_enabled(struct obs_scene_item *item)
{
return obs_sceneitem_get_scale_filter(item) != OBS_SCALE_DISABLE;
}
static inline bool crop_enabled(const struct obs_sceneitem_crop *crop)
{
return crop->left || crop->right || crop->top || crop->bottom;
}
static inline bool item_texture_enabled(struct obs_scene_item *item)
{
if (!item)
false;
struct obs_sceneitem_crop crop;
obs_sceneitem_get_crop(item, &crop);
return crop_enabled(&crop) || scale_filter_enabled(item) ||
(item_is_scene(item) && !obs_sceneitem_is_group(item));
}
void pos_add_center(struct vec2 *pos, uint32_t alignment, uint32_t cx,
uint32_t cy)
{
if (alignment & OBS_ALIGN_LEFT) {
pos->x -= cx >> 1;
} else if (alignment & OBS_ALIGN_RIGHT) {
pos->x += cx >> 1;
}
if (alignment & OBS_ALIGN_TOP) {
pos->y -= cy >> 1;
} else if (alignment & OBS_ALIGN_BOTTOM) {
pos->y += cy >> 1;
}
}
void pos_subtract_center(struct vec2 *pos, uint32_t alignment, uint32_t cx,
uint32_t cy)
{
if (alignment & OBS_ALIGN_LEFT) {
pos->x += cx >> 1;
} else if (alignment & OBS_ALIGN_RIGHT) {
pos->x -= cx >> 1;
}
if (alignment & OBS_ALIGN_TOP) {
pos->y += cy >> 1;
} else if (alignment & OBS_ALIGN_BOTTOM) {
pos->y -= cy >> 1;
}
}
void calc_edge_position(struct vec2 *pos, long long position,
uint32_t canvas_width, uint32_t canvas_height,
uint32_t alignment, uint32_t cx, uint32_t cy, bool zoom)
{
uint32_t cx2 = cx >> 1;
uint32_t cy2 = cy >> 1;
if (zoom) {
cx2 = 0;
cy2 = 0;
}
if (position - POS_EDGE == 0) {
if (alignment & OBS_ALIGN_LEFT) {
pos->x += cx >> 1;
} else if (alignment & OBS_ALIGN_RIGHT) {
pos->x -= cx >> 1;
}
if (alignment & OBS_ALIGN_TOP) {
pos->y += cy >> 1;
} else if (alignment & OBS_ALIGN_BOTTOM) {
pos->y -= cy >> 1;
}
// pos is center of object
float diff_x = pos->x - (canvas_width >> 1);
float diff_y = pos->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;
}
if (factor_x > factor_y) {
if (diff_x < 0.0f) {
//left edge
const float move_x = -(pos->x + cx2);
const float move_y =
diff_y * (diff_x + move_x) / diff_x;
vec2_set(pos, -(float)cx2,
(float)(canvas_height >> 1) + move_y);
} else {
//right edge
const float move_x =
(canvas_width - pos->x) + cx2;
const float move_y =
diff_y * (diff_x + move_x) / diff_x;
vec2_set(pos, (float)canvas_width + cx2,
(float)(canvas_height >> 1) + move_y);
}
} else {
if (diff_y < 0.0f) {
//top edge
const float move_y = -(pos->y + cy2);
const float move_x =
diff_x * (diff_y + move_y) / diff_y;
vec2_set(pos,
(float)(canvas_width >> 1) + move_x,
-(float)cy2);
} else {
//bottom edge
const float move_y =
(canvas_height - pos->y) + cy2;
const float move_x =
diff_x * (diff_y + move_y) / diff_y;
vec2_set(pos,
(float)(canvas_width >> 1) + move_x,
(float)canvas_height + cy2);
}
}
if (alignment & OBS_ALIGN_LEFT) {
pos->x -= cx2;
} else if (alignment & OBS_ALIGN_RIGHT) {
pos->x += cx2;
}
if (alignment & OBS_ALIGN_TOP) {
pos->y -= cy2;
} else if (alignment & OBS_ALIGN_BOTTOM) {
pos->y += cy2;
}
return;
}
if (zoom) {
cx = 0;
cy = 0;
}
if (position & POS_EDGE)
vec2_set(pos, 0, 0);
if (position & POS_RIGHT) {
pos->x = (float)canvas_width;
if (alignment & OBS_ALIGN_RIGHT) {
pos->x += cx;
} else if (alignment & OBS_ALIGN_LEFT) {
} else {
pos->x += cx2;
}
} else if (position & POS_LEFT) {
pos->x = 0;
if (alignment & OBS_ALIGN_RIGHT) {
} else if (alignment & OBS_ALIGN_LEFT) {
pos->x -= cx;
} else {
pos->x -= cx2;
}
} else if (position & POS_EDGE) {
pos->x = (float)(canvas_width >> 1);
if (alignment & OBS_ALIGN_RIGHT) {
pos->x += cx2;
} else if (alignment & OBS_ALIGN_LEFT) {
pos->x -= cx2;
}
}
if (position & POS_BOTTOM) {
pos->y = (float)canvas_height;
if (alignment & OBS_ALIGN_TOP) {
} else if (alignment & OBS_ALIGN_BOTTOM) {
pos->y += cy;
} else {
pos->y += cy2;
}
} else if (position & POS_TOP) {
pos->y = 0;
if (alignment & OBS_ALIGN_BOTTOM) {
} else if (alignment & OBS_ALIGN_TOP) {
pos->y -= cy;
} else {
pos->y -= cy2;
}
} else if (position & POS_EDGE) {
pos->y = (float)(canvas_height >> 1);
if (alignment & OBS_ALIGN_TOP) {
pos->y -= cy2;
} else if (alignment & OBS_ALIGN_BOTTOM) {
pos->y += cy2;
}
}
}
float bezier(float point[], float t, int order)
{
const float p = 1.0f - t;
if (order < 1)
return point[0];
if (order == 1)
return p * point[0] + t * point[1];
return p * bezier(point, t, order - 1) +
t * bezier(&point[1], t, order - 1);
}
void vec2_bezier(struct vec2 *dst, struct vec2 *begin, struct vec2 *control,
struct vec2 *end, const float t)
{
float x[3] = {begin->x, control->x, end->x};
float y[3] = {begin->y, control->y, end->y};
dst->x = bezier(x, t, 2);
dst->y = bezier(y, t, 2);
}
static obs_source_t *obs_frontend_get_transition(const char *name)
{
if (!name)
return NULL;
struct obs_frontend_source_list transitions = {0};
obs_frontend_get_transitions(&transitions);
for (size_t i = 0; i < transitions.sources.num; i++) {
const char *n =
obs_source_get_name(transitions.sources.array[i]);
if (n && strcmp(n, name) == 0) {
obs_source_t *transition = transitions.sources.array[i];
obs_source_addref(transition);
obs_frontend_source_list_free(&transitions);
return transition;
}
}
obs_frontend_source_list_free(&transitions);
return NULL;
}
float get_eased(float f, long long easing, long long easing_function)
{
float t = f;
if (EASE_NONE == easing) {
} else if (EASE_IN == easing) {
switch (easing_function) {
case EASING_QUADRATIC:
t = QuadraticEaseIn(f);
break;
case EASING_CUBIC:
t = CubicEaseIn(f);
break;
case EASING_QUARTIC:
t = QuarticEaseIn(f);
break;
case EASING_QUINTIC:
t = QuinticEaseIn(f);
break;
case EASING_SINE:
t = SineEaseIn(f);
break;
case EASING_CIRCULAR:
t = CircularEaseIn(f);
break;
case EASING_EXPONENTIAL:
t = ExponentialEaseIn(f);
break;
case EASING_ELASTIC:
t = ElasticEaseIn(f);
break;
case EASING_BOUNCE:
t = BounceEaseIn(f);
break;
case EASING_BACK:
t = BackEaseIn(f);
break;
default:;
}
} else if (EASE_OUT == easing) {
switch (easing_function) {
case EASING_QUADRATIC:
t = QuadraticEaseOut(f);
break;
case EASING_CUBIC:
t = CubicEaseOut(f);
break;
case EASING_QUARTIC:
t = QuarticEaseOut(f);
break;
case EASING_QUINTIC:
t = QuinticEaseOut(f);
break;
case EASING_SINE:
t = SineEaseOut(f);
break;
case EASING_CIRCULAR:
t = CircularEaseOut(f);
break;
case EASING_EXPONENTIAL:
t = ExponentialEaseOut(f);
break;
case EASING_ELASTIC:
t = ElasticEaseOut(f);
break;
case EASING_BOUNCE:
t = BounceEaseOut(f);
break;
case EASING_BACK:
t = BackEaseOut(f);
break;
default:;
}
} else if (EASE_IN_OUT == easing) {
switch (easing_function) {
case EASING_QUADRATIC:
t = QuadraticEaseInOut(f);
break;
case EASING_CUBIC:
t = CubicEaseInOut(f);
break;
case EASING_QUARTIC:
t = QuarticEaseInOut(f);
break;
case EASING_QUINTIC:
t = QuinticEaseInOut(f);
break;
case EASING_SINE:
t = SineEaseInOut(f);
break;
case EASING_CIRCULAR:
t = CircularEaseInOut(f);
break;
case EASING_EXPONENTIAL:
t = ExponentialEaseInOut(f);
break;
case EASING_ELASTIC:
t = ElasticEaseInOut(f);
break;
case EASING_BOUNCE:
t = BounceEaseInOut(f);
break;
case EASING_BACK:
t = BackEaseInOut(f);
break;
default:;
}
}
return t;
}
obs_source_t *get_transition(const char *transition_name, void *pool_data,
size_t *index, bool cache)
{
if (!transition_name || strlen(transition_name) == 0 ||
strcmp(transition_name, "None") == 0)
return NULL;
DARRAY(obs_source_t *) *transition_pool = pool_data;
const size_t i = *index;
if (cache && transition_pool->num && *index < transition_pool->num) {
obs_source_t *transition = transition_pool->array[i];
obs_source_addref(transition);
*index = i + 1;
return transition;
}
obs_source_t *frontend_transition =
obs_frontend_get_transition(transition_name);
if (!frontend_transition)
return NULL;
obs_source_t *transition = obs_source_duplicate(frontend_transition,
transition_name, true);
obs_source_release(frontend_transition);
if (cache) {
darray_push_back(sizeof(obs_source_t *), &transition_pool->da,
&transition);
obs_source_addref(transition);
*index = i + 1;
}
return transition;
}
bool render2_item(struct move_info *move, struct move_item *item)
{
obs_sceneitem_t *scene_item = NULL;
if (item->item_a && item->item_b) {
if (move->t <= 0.5) {
scene_item = item->item_a;
} else {
scene_item = item->item_b;
}
} else if (item->item_a) {
scene_item = item->item_a;
} else if (item->item_b) {
scene_item = item->item_b;
}
obs_source_t *source = obs_sceneitem_get_source(scene_item);
uint32_t width = obs_source_get_width(source);
uint32_t height = obs_source_get_height(source);
bool move_out = item->item_a == scene_item;
if (item->move_scene) {
if (item->transition_name && !item->transition) {
item->transition = get_transition(
item->transition_name,
&move->transition_pool_move,
&move->transition_pool_move_index,
move->cache_transitions);
if (item->transition) {
obs_transition_set_size(item->transition, width,
height);
obs_transition_set_alignment(item->transition,
OBS_ALIGN_CENTER);
obs_transition_set_scale_type(
item->transition,
item->transition_scale);
obs_transition_set(
item->transition,
obs_sceneitem_get_source(scene_item));
obs_transition_start(
item->transition,
obs_transition_fixed(item->transition)
? OBS_TRANSITION_MODE_AUTO
: OBS_TRANSITION_MODE_MANUAL,
obs_frontend_get_transition_duration(),
obs_sceneitem_get_source(scene_item));
}
}
} else if (item->item_a && item->item_b) {
if (item->transition_name && !item->transition) {
item->transition = get_transition(
item->transition_name,
&move->transition_pool_move,
&move->transition_pool_move_index,
move->cache_transitions);
if (item->transition) {
obs_transition_set_size(item->transition, width,
height);
obs_transition_set_alignment(item->transition,
OBS_ALIGN_CENTER);
obs_transition_set_scale_type(
item->transition,
item->transition_scale);
obs_transition_set(
item->transition,
obs_sceneitem_get_source(item->item_a));
obs_transition_start(
item->transition,
obs_transition_fixed(item->transition)
? OBS_TRANSITION_MODE_AUTO
: OBS_TRANSITION_MODE_MANUAL,
obs_frontend_get_transition_duration(),
obs_sceneitem_get_source(item->item_b));
}
}
} else if (move_out && item->transition_name && !item->transition) {
item->transition = get_transition(
item->transition_name, &move->transition_pool_out,
&move->transition_pool_out_index,
move->cache_transitions);
if (item->transition) {
obs_transition_set_size(item->transition, width,
height);
obs_transition_set_alignment(item->transition,
OBS_ALIGN_CENTER);
obs_transition_set_scale_type(
item->transition, OBS_TRANSITION_SCALE_ASPECT);
obs_transition_set(item->transition, source);
obs_transition_start(
item->transition,
obs_transition_fixed(item->transition)
? OBS_TRANSITION_MODE_AUTO
: OBS_TRANSITION_MODE_MANUAL,
obs_frontend_get_transition_duration(), NULL);
}
} else if (!move_out && item->transition_name && !item->transition) {
item->transition = get_transition(
item->transition_name, &move->transition_pool_in,
&move->transition_pool_in_index,
move->cache_transitions);
if (item->transition) {
obs_transition_set_size(item->transition, width,
height);
obs_transition_set_alignment(item->transition,
OBS_ALIGN_CENTER);
obs_transition_set_scale_type(
item->transition, OBS_TRANSITION_SCALE_ASPECT);
obs_transition_set(item->transition, NULL);
obs_transition_start(
item->transition,
obs_transition_fixed(item->transition)
? OBS_TRANSITION_MODE_AUTO
: OBS_TRANSITION_MODE_MANUAL,
obs_frontend_get_transition_duration(), source);
}
}
float t = 0.0f;
if (item->start_percentage > 0 || item->end_percentage < 100) {
if (item->start_percentage > item->end_percentage) {
float avg_switch_point =
(float)(item->start_percentage +
item->end_percentage) /
200.0f;
if (move->t > avg_switch_point) {
t = 1.0f;
}
} else if (move->t * 100.0 < item->start_percentage) {
t = 0.0f;
} else if (move->t * 100.0 > item->end_percentage) {
t = 1.0f;
} else {
int duration_percentage =
item->end_percentage - item->start_percentage;
t = move->t - (float)item->start_percentage / 100.0f;
t = t / (float)duration_percentage * 100.0f;
t = get_eased(t, item->easing, item->easing_function);
}
} else {
t = get_eased(move->t, item->easing, item->easing_function);
}
float ot = t;
if (t > 1.0f)
ot = 1.0f;
else if (t < 0.0f)
ot = 0.0f;
if (item->item_a && item->item_b && item->transition &&
!move->start_init) {
uint32_t width_a = obs_source_get_width(
obs_sceneitem_get_source(item->item_a));
uint32_t width_b = obs_source_get_width(
obs_sceneitem_get_source(item->item_b));
uint32_t height_a = obs_source_get_height(
obs_sceneitem_get_source(item->item_a));
uint32_t height_b = obs_source_get_height(
obs_sceneitem_get_source(item->item_b));
width = (uint32_t)((1.0f - t) * width_a + t * width_b);
height = (uint32_t)((1.0f - t) * height_a + t * height_b);
obs_transition_set_size(item->transition, width, height);
}
uint32_t original_width = width;
uint32_t original_height = height;
struct obs_sceneitem_crop crop;
if (item->move_scene) {
obs_sceneitem_get_crop(scene_item, &crop);
if (item->item_a) {
crop.left =
(int)((float)(1.0f - ot) * (float)crop.left);
crop.top = (int)((float)(1.0f - ot) * (float)crop.top);
crop.right =
(int)((float)(1.0f - ot) * (float)crop.right);
crop.bottom =
(int)((float)(1.0f - ot) * (float)crop.bottom);
} else if (item->item_b) {
crop.left = (int)((float)ot * (float)crop.left);
crop.top = (int)((float)ot * (float)crop.top);
crop.right = (int)((float)ot * (float)crop.right);
crop.bottom = (int)((float)ot * (float)crop.bottom);
}
} else if (item->item_a && item->item_b) {
struct obs_sceneitem_crop crop_a;
obs_sceneitem_get_crop(item->item_a, &crop_a);
struct obs_sceneitem_crop crop_b;
obs_sceneitem_get_crop(item->item_b, &crop_b);
crop.left = (int)((float)(1.0f - ot) * (float)crop_a.left +
ot * (float)crop_b.left);
crop.top = (int)((float)(1.0f - ot) * (float)crop_a.top +
ot * (float)crop_b.top);
crop.right = (int)((float)(1.0f - ot) * (float)crop_a.right +
ot * (float)crop_b.right);
crop.bottom = (int)((float)(1.0f - ot) * (float)crop_a.bottom +
ot * (float)crop_b.bottom);
} else {
obs_sceneitem_get_crop(scene_item, &crop);
}
uint32_t crop_cx = crop.left + crop.right;
uint32_t cx = (crop_cx > width) ? 2 : (width - crop_cx);
uint32_t crop_cy = crop.top + crop.bottom;
uint32_t cy = (crop_cy > height) ? 2 : (height - crop_cy);
struct vec2 scale;
struct vec2 original_scale;
obs_sceneitem_get_scale(scene_item, &original_scale);
if (item->item_a && item->item_b) {
struct vec2 scale_a;
obs_sceneitem_get_scale(item->item_a, &scale_a);
struct vec2 scale_b;
obs_sceneitem_get_scale(item->item_b, &scale_b);
vec2_set(&scale, (1.0f - t) * scale_a.x + t * scale_b.x,
(1.0f - t) * scale_a.y + t * scale_b.y);
} else {
if (obs_sceneitem_get_bounds_type(scene_item) !=
OBS_BOUNDS_NONE) {
obs_sceneitem_get_scale(scene_item, &scale);
} else {
obs_sceneitem_get_scale(scene_item, &scale);
if (item->move_scene) {
if (item->item_a) {
vec2_set(&scale,
(1.0f - t) * scale.x + t,
(1.0f - t) * scale.y + t);
} else if (item->item_b) {
vec2_set(&scale,
(1.0f - t) + t * scale.x,
(1.0f - t) + t * scale.y);
}
} else if (!move_out && item->zoom) {
vec2_set(&scale, t * scale.x, t * scale.y);
} else if (move_out && item->zoom) {
vec2_set(&scale, (1.0f - t) * scale.x,
(1.0f - t) * scale.y);
}
}
}
width = cx;
height = cy;
uint32_t original_cx = cx;
uint32_t original_cy = cy;
struct vec2 base_origin;
struct vec2 origin;
struct vec2 origin2;
vec2_zero(&base_origin);
vec2_zero(&origin);
vec2_zero(&origin2);
uint32_t canvas_width = obs_source_get_width(move->source);
uint32_t canvas_height = obs_source_get_height(move->source);
if (obs_sceneitem_get_bounds_type(scene_item) != OBS_BOUNDS_NONE) {
struct vec2 bounds;
if (item->move_scene) {
obs_sceneitem_get_bounds(scene_item, &bounds);
if (item->item_a) {
vec2_set(&bounds,
(1.0f - t) * bounds.x +
t * canvas_width,
(1.0f - t) * bounds.y +
t * canvas_height);
} else if (item->item_b) {
vec2_set(&bounds,
(1.0f - t) * canvas_width +
t * bounds.x,
(1.0f - t) * canvas_height +
t * bounds.y);
}
} else if (item->item_a && item->item_b) {
struct vec2 bounds_a;
obs_sceneitem_get_bounds(item->item_a, &bounds_a);
struct vec2 bounds_b;
obs_sceneitem_get_bounds(item->item_b, &bounds_b);
vec2_set(&bounds,
(1.0f - t) * bounds_a.x + t * bounds_b.x,
(1.0f - t) * bounds_a.y + t * bounds_b.y);
} else {
obs_sceneitem_get_bounds(scene_item, &bounds);
if (!move_out && item->zoom) {
vec2_set(&bounds, t * bounds.x, t * bounds.y);
} else if (move_out && item->zoom) {
vec2_set(&bounds, (1.0f - t) * bounds.x,
(1.0f - t) * bounds.y);
}
}
if (item->item_a && item->item_b &&