Blender V5.3
mask_ops.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2012 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <algorithm>
10
11#include "MEM_guardedalloc.h"
12
13#include "BLI_listbase.hh"
14#include "BLI_math_matrix_c.hh"
15#include "BLI_math_vector_c.hh"
16#include "BLI_string.hh"
17#include "BLI_string_utils.hh"
18#include "BLI_utildefines.hh"
19
20#include "BKE_context.hh"
21#include "BKE_lib_id.hh"
22#include "BKE_mask.hh"
23
24#include "BLT_translation.hh"
25
26#include "DEG_depsgraph.hh"
28
29#include "DNA_mask_types.h"
30#include "DNA_object_types.h" /* SELECT */
31#include "DNA_scene_types.h"
32
33#include "WM_api.hh"
34#include "WM_types.hh"
35
36#include "ED_clip.hh"
37#include "ED_image.hh"
38#include "ED_mask.hh"
39#include "ED_select_utils.hh"
40
41#include "ANIM_keyframing.hh"
42
43#include "UI_interface.hh"
44#include "UI_interface_icons.hh"
45
46#include "RNA_access.hh"
47#include "RNA_define.hh"
48
49#include "mask_intern.hh" /* own include */
50
51namespace blender {
52
53/******************** create new mask *********************/
54
55Mask *ED_mask_new(bContext *C, const char *name)
56{
57 ScrArea *area = CTX_wm_area(C);
58 Main *bmain = CTX_data_main(C);
59 Mask *mask;
60
61 mask = BKE_mask_new(bmain, name);
62
63 if (area && area->spacedata.first_) {
64 switch (area->spacetype) {
65 case SPACE_CLIP: {
66 SpaceClip *sc = area->spacedata.first_as<SpaceClip>();
68 break;
69 }
70 case SPACE_SEQ: {
71 /* do nothing */
72 break;
73 }
74 case SPACE_IMAGE: {
75 SpaceImage *sima = area->spacedata.first_as<SpaceImage>();
77 break;
78 }
79 }
80 }
81
82 return mask;
83}
84
86{
88 MaskLayer *mask_layer;
89
90 if (mask == nullptr) {
91 /* If there's no active mask, create one. */
92 mask = ED_mask_new(C, nullptr);
93 *r_added_mask = true;
94 }
95
96 mask_layer = BKE_mask_layer_active(mask);
97 if (mask_layer == nullptr) {
98 /* If there's no active mask layer, create one. */
99 mask_layer = BKE_mask_layer_new(mask, "");
100 }
101
102 return mask_layer;
103}
104
106{
107 char name[MAX_ID_NAME - 2];
108
109 RNA_string_get(op->ptr, "name", name);
110
111 Main *bmain = CTX_data_main(C);
112
113 PointerRNA ptr;
114 PropertyRNA *prop;
116
117 Mask *mask;
118
119 if (prop) {
120 mask = BKE_mask_new(bmain, name);
121
122 /* When creating new ID blocks, use is already 1, but RNA
123 * pointer use also increases user, so this compensates it. */
124 id_us_min(&mask->id);
125
126 if (ptr.owner_id) {
127 BKE_id_move_to_same_lib(*bmain, mask->id, *ptr.owner_id);
128 }
129
131 RNA_property_pointer_set(&ptr, prop, idptr, nullptr);
132 RNA_property_update(C, &ptr, prop);
133 }
134 else {
135 mask = ED_mask_new(C, name);
136 }
137
139
140 return OPERATOR_FINISHED;
141}
142
144{
145 PropertyPointerRNA pprop;
147
148 /* Allow if invoked from a template_ID button. */
149 if (pprop.prop != nullptr) {
150 return true;
151 }
152
153 return ED_maskedit_poll(C);
154}
155
157{
158 /* identifiers */
159 ot->name = "New Mask";
160 ot->description = "Create new mask";
161 ot->idname = "MASK_OT_new";
162
163 /* flags */
165
166 /* API callbacks. */
167 ot->exec = mask_new_exec;
168 ot->poll = mask_new_poll;
169
170 /* properties */
171 RNA_def_string(ot->srna, "name", nullptr, MAX_ID_NAME - 2, "Name", "Name of new mask");
172}
173
174/******************** create new mask layer *********************/
175
177{
179 char name[MAX_ID_NAME - 2];
180
181 RNA_string_get(op->ptr, "name", name);
182
184 mask->masklay_act = mask->masklay_tot - 1;
185
188
189 return OPERATOR_FINISHED;
190}
191
193{
194 /* identifiers */
195 ot->name = "Add Mask Layer";
196 ot->description = "Add new mask layer for masking";
197 ot->idname = "MASK_OT_layer_new";
198
199 /* API callbacks. */
202
203 /* flags */
205
206 /* properties */
207 RNA_def_string(ot->srna, "name", nullptr, MAX_ID_NAME - 2, "Name", "Name of new mask layer");
208}
209
210/******************** remove mask layer *********************/
211
213{
215 MaskLayer *mask_layer = BKE_mask_layer_active(mask);
216
217 if (mask_layer) {
218 BKE_mask_layer_remove(mask, mask_layer);
219
222 }
223
224 return OPERATOR_FINISHED;
225}
226
228{
229 /* identifiers */
230 ot->name = "Remove Mask Layer";
231 ot->description = "Remove mask layer";
232 ot->idname = "MASK_OT_layer_remove";
233
234 /* API callbacks. */
237
238 /* flags */
240}
241
242/******************** slide *********************/
243
244enum {
250};
251
253 /* Generic fields. */
263
265
266 /* Previous clip coordinate which was resolved from mouse position (0, 0).
267 * Is used to compensate for view offset moving in-between of mouse events when
268 * lock-to-selection is enabled. */
270
271 float no[2];
272
274
276
277 /* Data needed to restore the state. */
278 float vec[3][3];
280
281 /* Point sliding. */
282
283 /* Handle sliding. */
285
286 /* Feather sliding. */
289};
290
291static void mask_point_undistort_pos(SpaceClip *sc, float r_co[2], const float co[2])
292{
293 BKE_mask_coord_to_movieclip(sc->clip, &sc->user, r_co, co);
294 ED_clip_point_undistorted_pos(sc, r_co, r_co);
295 BKE_mask_coord_from_movieclip(sc->clip, &sc->user, r_co, r_co);
296}
297
299 Mask *mask_orig,
300 const float co[2],
301 MaskLayer **r_mask_layer,
302 MaskSpline **r_mask_spline)
303{
304 const float threshold = 19.0f;
305 ScrArea *area = CTX_wm_area(C);
307 float closest_dist_squared = 0.0f;
308 MaskLayer *closest_layer = nullptr;
309 MaskSpline *closest_spline = nullptr;
310 bool undistort = false;
311 *r_mask_layer = nullptr;
312 *r_mask_spline = nullptr;
313
314 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
315 Mask *mask_eval = DEG_get_evaluated(depsgraph, mask_orig);
316
317 int width, height;
318 ED_mask_get_size(area, &width, &height);
319 float pixel_co[2];
320 pixel_co[0] = co[0] * width;
321 pixel_co[1] = co[1] * height;
322 if (sc != nullptr) {
323 undistort = (sc->clip != nullptr) &&
325 }
326
327 for (MaskLayer *mask_layer_orig = mask_orig->masklayers.first(),
328 *mask_layer_eval = mask_eval->masklayers.first();
329 mask_layer_orig != nullptr;
330 mask_layer_orig = mask_layer_orig->next, mask_layer_eval = mask_layer_eval->next)
331 {
332 if (mask_layer_orig->visibility_flag & (MASK_HIDE_VIEW | MASK_HIDE_SELECT)) {
333 continue;
334 }
335 for (MaskSpline *spline_orig = mask_layer_orig->splines.first(),
336 *spline_eval = mask_layer_eval->splines.first();
337 spline_orig != nullptr;
338 spline_orig = spline_orig->next, spline_eval = spline_eval->next)
339 {
340 if ((spline_orig->flag & SELECT) == 0) {
341 continue;
342 }
343 MaskSplinePoint *points_array = BKE_mask_spline_point_array(spline_eval);
344 float min[2], max[2], center[2];
346 for (int i = 0; i < spline_orig->tot_point; i++) {
347 MaskSplinePoint *point_deform = &points_array[i];
348 BezTriple *bezt = &point_deform->bezt;
349
350 float vert[2];
351
352 copy_v2_v2(vert, bezt->vec[1]);
353
354 if (undistort) {
355 mask_point_undistort_pos(sc, vert, vert);
356 }
357
358 minmax_v2v2_v2(min, max, vert);
359 }
360
361 center[0] = (min[0] + max[0]) / 2.0f * width;
362 center[1] = (min[1] + max[1]) / 2.0f * height;
363 float dist_squared = len_squared_v2v2(pixel_co, center);
364 float max_bb_side = min_ff((max[0] - min[0]) * width, (max[1] - min[1]) * height);
365 if (dist_squared <= max_bb_side * max_bb_side * 0.5f &&
366 (closest_spline == nullptr || dist_squared < closest_dist_squared))
367 {
368 closest_layer = mask_layer_orig;
369 closest_spline = spline_orig;
370 closest_dist_squared = dist_squared;
371 }
372 }
373 }
374 if (closest_dist_squared < square_f(threshold) && closest_spline != nullptr) {
375 float diff_score;
377 mask_orig,
378 co,
379 threshold,
380 false,
381 nullptr,
382 true,
383 false,
384 nullptr,
385 nullptr,
386 nullptr,
387 nullptr,
388 &diff_score))
389 {
390 if (square_f(diff_score) < closest_dist_squared) {
391 return false;
392 }
393 }
394
395 *r_mask_layer = closest_layer;
396 *r_mask_spline = closest_spline;
397 return true;
398 }
399 return false;
400}
401
403{
404 for (int i = 0; i < spline->tot_point; i++) {
405 MaskSplinePoint *point = &spline->points[i];
406
407 if (point->bezt.weight != 0.0f) {
408 return false;
409 }
410 }
411
412 return true;
413}
414
416 MaskLayer *mask_layer,
417 MaskSpline *spline,
418 MaskSplinePoint *point,
419 eMaskWhichHandle which_handle)
420{
422
423 switch (which_handle) {
425 BKE_mask_point_select_set(point, true);
426 break;
428 point->bezt.f1 |= BEZT_FLAG_SELECT;
429 break;
431 point->bezt.f3 |= BEZT_FLAG_SELECT;
432 break;
434 point->bezt.f1 |= BEZT_FLAG_SELECT;
435 point->bezt.f3 |= BEZT_FLAG_SELECT;
436 break;
437 default:
438 BLI_assert_msg(0, "Unexpected situation in select_sliding_point()");
439 }
440
441 mask_layer->act_spline = spline;
442 mask_layer->act_point = point;
444}
445
447{
448 BezTriple *bezt = &point->bezt;
449
450 if (which_handle == MASK_WHICH_HANDLE_LEFT) {
451 if (bezt->h1 == HD_VECT) {
452 bezt->h1 = HD_FREE;
453 }
454 else if (bezt->h1 == HD_AUTO) {
455 bezt->h1 = HD_ALIGN_DOUBLESIDE;
456 bezt->h2 = HD_ALIGN_DOUBLESIDE;
457 }
458 }
459 else if (which_handle == MASK_WHICH_HANDLE_RIGHT) {
460 if (bezt->h2 == HD_VECT) {
461 bezt->h2 = HD_FREE;
462 }
463 else if (bezt->h2 == HD_AUTO) {
464 bezt->h1 = HD_ALIGN_DOUBLESIDE;
465 bezt->h2 = HD_ALIGN_DOUBLESIDE;
466 }
467 }
468}
469
471{
472 ScrArea *area = CTX_wm_area(C);
473 ARegion *region = CTX_wm_region(C);
474
476 SlidePointData *customdata = nullptr;
477 MaskLayer *mask_layer, *cv_mask_layer, *feather_mask_layer;
478 MaskSpline *spline, *cv_spline, *feather_spline;
479 MaskSplinePoint *point, *cv_point, *feather_point;
480 MaskSplinePointUW *uw = nullptr;
481 int width, height, action = SLIDE_ACTION_NONE;
482 const bool slide_feather = RNA_boolean_get(op->ptr, "slide_feather");
483 float co[2], cv_score, feather_score;
484 const float threshold = 19;
485 eMaskWhichHandle which_handle;
486
487 MaskViewLockState lock_state;
488 ED_mask_view_lock_state_store(C, &lock_state);
489
490 ED_mask_mouse_pos(area, region, event->mval, co);
491 ED_mask_get_size(area, &width, &height);
492
494 C, mask, co, threshold, &cv_mask_layer, &cv_spline, &which_handle, &cv_score);
495
497 mask,
498 co,
499 threshold,
500 &feather_mask_layer,
501 &feather_spline,
502 &feather_point,
503 &uw,
504 &feather_score))
505 {
506 if (slide_feather || !cv_point || feather_score < cv_score) {
507 action = SLIDE_ACTION_FEATHER;
508
509 mask_layer = feather_mask_layer;
510 spline = feather_spline;
511 point = feather_point;
512 }
513 }
514
515 if (cv_point && action == SLIDE_ACTION_NONE) {
516 if (which_handle != MASK_WHICH_HANDLE_NONE) {
517 action = SLIDE_ACTION_HANDLE;
518 }
519 else {
520 action = SLIDE_ACTION_POINT;
521 }
522
523 mask_layer = cv_mask_layer;
524 spline = cv_spline;
525 point = cv_point;
526 }
527
528 if (action == SLIDE_ACTION_NONE) {
529 if (spline_under_mouse_get(C, mask, co, &mask_layer, &spline)) {
530 action = SLIDE_ACTION_SPLINE;
531 point = nullptr;
532 }
533 }
534
535 if (action != SLIDE_ACTION_NONE) {
536 customdata = MEM_new_zeroed<SlidePointData>("mask slide point data");
537 customdata->event_invoke_type = event->type;
538 customdata->mask = mask;
539 customdata->mask_layer = mask_layer;
540 customdata->spline = spline;
541 customdata->point = point;
542 customdata->width = width;
543 customdata->height = height;
544 customdata->action = action;
545 customdata->uw = uw;
546
547 customdata->is_sliding_new_point = RNA_boolean_get(op->ptr, "is_new_point");
548
549 if (customdata->action != SLIDE_ACTION_SPLINE) {
550 customdata->old_h1 = point->bezt.h1;
551 customdata->old_h2 = point->bezt.h2;
552 select_sliding_point(mask, mask_layer, spline, point, which_handle);
553 check_sliding_handle_type(point, which_handle);
554 }
555
556 if (uw) {
557 float co_uw[2];
558 float weight_scalar = BKE_mask_point_weight_scalar(spline, point, uw->u);
559
560 customdata->weight = uw->w;
561 customdata->weight_scalar = weight_scalar;
562 BKE_mask_point_segment_co(spline, point, uw->u, co_uw);
563 BKE_mask_point_normal(spline, point, uw->u, customdata->no);
564
565 madd_v2_v2v2fl(customdata->prev_feather_coord, co_uw, customdata->no, uw->w * weight_scalar);
566 }
567 else if (customdata->action != SLIDE_ACTION_SPLINE) {
568 BezTriple *bezt = &point->bezt;
569
570 customdata->weight = bezt->weight;
571 customdata->weight_scalar = 1.0f;
572 BKE_mask_point_normal(spline, point, 0.0f, customdata->no);
573
574 madd_v2_v2v2fl(customdata->prev_feather_coord, bezt->vec[1], customdata->no, bezt->weight);
575 }
576
577 if (customdata->action == SLIDE_ACTION_FEATHER) {
579 }
580
581 if (customdata->action != SLIDE_ACTION_SPLINE) {
582 copy_m3_m3(customdata->vec, point->bezt.vec);
583 if (which_handle != MASK_WHICH_HANDLE_NONE) {
584 BKE_mask_point_handle(point, which_handle, customdata->orig_handle_coord);
585 copy_v2_v2(customdata->prev_handle_coord, customdata->orig_handle_coord);
586 }
587 }
588 customdata->which_handle = which_handle;
589
590 {
592 DEG_id_tag_update(&mask->id, 0);
593
595 }
596
597 ED_mask_mouse_pos(area, region, event->mval, customdata->prev_mouse_coord);
598
599 const int zero_mouse[2] = {0, 0};
600 ED_mask_mouse_pos(area, region, zero_mouse, customdata->prev_zero_coord);
601 }
602
603 return customdata;
604}
605
607{
609 SlidePointData *slidedata;
610
611 if (mask == nullptr) {
613 }
614
615 slidedata = slide_point_customdata(C, op, event);
616
617 if (slidedata) {
618 op->customdata = slidedata;
619
621
622 slidedata->mask_layer->act_spline = slidedata->spline;
623 slidedata->mask_layer->act_point = slidedata->point;
624
626
628 }
629
631}
632
634{
635 for (int i = 0; i < data->spline->tot_point; i++) {
636 MaskSplinePoint *point = &data->spline->points[i];
637 MaskSplinePoint *orig_point = &data->orig_spline->points[i];
638
639 point->bezt.weight = orig_point->bezt.weight + delta;
640 point->bezt.weight = std::max(point->bezt.weight, 0.0f);
641 }
642}
643
645{
646 for (int i = 0; i < data->spline->tot_point; i++) {
647 MaskSplinePoint *point = &data->spline->points[i];
648 MaskSplinePoint *orig_point = &data->orig_spline->points[i];
649
650 point->bezt = orig_point->bezt;
651
652 for (int j = 0; j < point->tot_uw; j++) {
653 point->uw[j] = orig_point->uw[j];
654 }
655 }
656}
657
659{
660 /* cancel sliding */
661
662 if (data->orig_spline) {
664 }
665 else {
666 if (data->action == SLIDE_ACTION_FEATHER) {
667 if (data->uw) {
668 data->uw->w = data->weight;
669 }
670 else {
671 data->point->bezt.weight = data->weight;
672 }
673 }
674 else if (data->action != SLIDE_ACTION_SPLINE) {
675 copy_m3_m3(data->point->bezt.vec, data->vec);
676 data->point->bezt.h1 = data->old_h1;
677 data->point->bezt.h2 = data->old_h2;
678 }
679 }
680}
681
683{
684 if (data->orig_spline) {
685 BKE_mask_spline_free(data->orig_spline);
686 }
687
688 MEM_delete(data);
689}
690
692{
693 SlidePointData *data = static_cast<SlidePointData *>(op->customdata);
694 BezTriple *bezt = &data->point->bezt;
695 float co[2];
696
697 switch (event->type) {
698 case EVT_LEFTALTKEY:
699 case EVT_RIGHTALTKEY:
700 case EVT_LEFTSHIFTKEY:
702 if (ELEM(event->type, EVT_LEFTALTKEY, EVT_RIGHTALTKEY)) {
703 if (data->action == SLIDE_ACTION_FEATHER) {
704 data->is_overall_feather = (event->val == KM_PRESS);
705 }
706 else {
707 data->is_curvature_only = (event->val == KM_PRESS);
708 }
709 }
710
712 data->is_accurate = (event->val == KM_PRESS);
713 }
714
715 ATTR_FALLTHROUGH; /* update CV position */
716 case MOUSEMOVE: {
717 ScrArea *area = CTX_wm_area(C);
718 ARegion *region = CTX_wm_region(C);
719 float2 delta;
720
721 ED_mask_mouse_pos(area, region, event->mval, co);
722 sub_v2_v2v2(delta, co, data->prev_mouse_coord);
723 copy_v2_v2(data->prev_mouse_coord, co);
724
725 /* Compensate for possibly moved view offset since the last event.
726 * The idea is to see how mapping of a fixed and known position did change. */
727 {
728 const int zero_mouse[2] = {0, 0};
729 float zero_coord[2];
730 ED_mask_mouse_pos(area, region, zero_mouse, zero_coord);
731
732 float zero_delta[2];
733 sub_v2_v2v2(zero_delta, zero_coord, data->prev_zero_coord);
734 sub_v2_v2(delta, zero_delta);
735
736 copy_v2_v2(data->prev_zero_coord, zero_coord);
737 }
738
739 if (data->is_accurate) {
740 mul_v2_fl(delta, 0.2f);
741 }
742
743 if (data->action == SLIDE_ACTION_HANDLE) {
744 float new_handle[2];
745
746 if (data->is_sliding_new_point && data->which_handle == MASK_WHICH_HANDLE_STICK) {
747 if (ELEM(data->point,
748 &data->spline->points[0],
749 &data->spline->points[data->spline->tot_point - 1]))
750 {
751 std::swap(delta[0], delta[1]);
752 delta[1] *= -1;
753
754 /* flip last point */
755 if (data->point != &data->spline->points[0]) {
756 delta *= -1.0f;
757 }
758 }
759 }
760
761 add_v2_v2v2(new_handle, data->prev_handle_coord, delta);
762
764 data->which_handle,
765 new_handle,
766 data->is_curvature_only,
767 data->orig_handle_coord,
768 data->vec);
769 BKE_mask_point_handle(data->point, data->which_handle, data->prev_handle_coord);
770
771 if (data->is_sliding_new_point) {
773 float vec[2];
774 short self_handle = (data->which_handle == MASK_WHICH_HANDLE_LEFT) ? 0 : 2;
775 short other_handle = (data->which_handle == MASK_WHICH_HANDLE_LEFT) ? 2 : 0;
776
777 sub_v2_v2v2(vec, bezt->vec[1], bezt->vec[self_handle]);
778 add_v2_v2v2(bezt->vec[other_handle], bezt->vec[1], vec);
779 }
780 }
781 }
782 else if (data->action == SLIDE_ACTION_POINT) {
783 add_v2_v2(bezt->vec[0], delta);
784 add_v2_v2(bezt->vec[1], delta);
785 add_v2_v2(bezt->vec[2], delta);
786 }
787 else if (data->action == SLIDE_ACTION_FEATHER) {
788 float vec[2], no[2], p[2], c[2], w, offco[2];
789 float *weight = nullptr;
790 float weight_scalar = 1.0f;
791 bool is_overall_feather = data->is_overall_feather || data->is_initial_feather;
792
793 add_v2_v2v2(offco, data->prev_feather_coord, delta);
794
795 if (data->uw) {
796 /* project on both sides and find the closest one,
797 * prevents flickering when projecting onto both sides can happen */
798 const float u_pos = BKE_mask_spline_project_co(
799 data->spline, data->point, data->uw->u, offco, MASK_PROJ_NEG);
800 const float u_neg = BKE_mask_spline_project_co(
801 data->spline, data->point, data->uw->u, offco, MASK_PROJ_POS);
802 float dist_pos = FLT_MAX;
803 float dist_neg = FLT_MAX;
804 float co_pos[2];
805 float co_neg[2];
806 float u;
807
808 if (u_pos > 0.0f && u_pos < 1.0f) {
809 BKE_mask_point_segment_co(data->spline, data->point, u_pos, co_pos);
810 dist_pos = len_squared_v2v2(offco, co_pos);
811 }
812
813 if (u_neg > 0.0f && u_neg < 1.0f) {
814 BKE_mask_point_segment_co(data->spline, data->point, u_neg, co_neg);
815 dist_neg = len_squared_v2v2(offco, co_neg);
816 }
817
818 u = dist_pos < dist_neg ? u_pos : u_neg;
819
820 if (u > 0.0f && u < 1.0f) {
821 data->uw->u = u;
822
823 data->uw = BKE_mask_point_sort_uw(data->point, data->uw);
824 weight = &data->uw->w;
825 weight_scalar = BKE_mask_point_weight_scalar(data->spline, data->point, u);
826 if (weight_scalar != 0.0f) {
827 weight_scalar = 1.0f / weight_scalar;
828 }
829
830 BKE_mask_point_normal(data->spline, data->point, data->uw->u, no);
831 BKE_mask_point_segment_co(data->spline, data->point, data->uw->u, p);
832 }
833 }
834 else {
835 weight = &bezt->weight;
836 /* weight_scalar = 1.0f; keep as is */
837 copy_v2_v2(no, data->no);
838 copy_v2_v2(p, bezt->vec[1]);
839 }
840
841 if (weight) {
842 sub_v2_v2v2(c, offco, p);
843 project_v2_v2v2_normalized(vec, c, no);
844
845 w = len_v2(vec);
846
847 if (is_overall_feather) {
848 float w_delta;
849
850 if (dot_v2v2(no, vec) <= 0.0f) {
851 w = -w;
852 }
853
854 w_delta = w - data->weight * data->weight_scalar;
855
856 if (data->orig_spline == nullptr) {
857 /* restore weight for currently sliding point, so orig_spline would be created
858 * with original weights used
859 */
860 *weight = data->weight;
861
862 data->orig_spline = BKE_mask_spline_copy(data->spline);
863 }
864
865 if (data->is_initial_feather) {
866 *weight = w * weight_scalar;
867 }
868
870 }
871 else {
872 if (dot_v2v2(no, vec) <= 0.0f) {
873 w = 0.0f;
874 }
875
876 if (data->orig_spline) {
877 /* restore possible overall feather changes */
879
880 BKE_mask_spline_free(data->orig_spline);
881 data->orig_spline = nullptr;
882 }
883
884 if (weight_scalar != 0.0f) {
885 *weight = w * weight_scalar;
886 }
887 }
888
889 copy_v2_v2(data->prev_feather_coord, offco);
890 }
891 }
892 else if (data->action == SLIDE_ACTION_SPLINE) {
893 if (data->orig_spline == nullptr) {
894 data->orig_spline = BKE_mask_spline_copy(data->spline);
895 }
896
897 for (int i = 0; i < data->spline->tot_point; i++) {
898 MaskSplinePoint *point = &data->spline->points[i];
899 add_v2_v2(point->bezt.vec[0], delta);
900 add_v2_v2(point->bezt.vec[1], delta);
901 add_v2_v2(point->bezt.vec[2], delta);
902 }
903 }
904
906 DEG_id_tag_update(&data->mask->id, 0);
907
908 break;
909 }
910
911 case LEFTMOUSE:
912 case RIGHTMOUSE:
913 if (event->type == data->event_invoke_type && event->val == KM_RELEASE) {
914 Scene *scene = CTX_data_scene(C);
915
916 /* Don't key sliding feather UW's. */
917 if ((data->action == SLIDE_ACTION_FEATHER && data->uw) == false) {
918 if (animrig::is_autokey_on(scene)) {
919 ED_mask_layer_shape_auto_key(C, data->mask_layer, scene->r.cfra);
920 }
921 }
922
923 if (data->is_sliding_new_point) {
924 if (len_squared_v2v2(bezt->vec[0], bezt->vec[1]) < FLT_EPSILON) {
925 bezt->h1 = HD_VECT;
926 }
927 if (len_squared_v2v2(bezt->vec[2], bezt->vec[1]) < FLT_EPSILON) {
928 bezt->h2 = HD_VECT;
929 }
930 }
931
933 DEG_id_tag_update(&data->mask->id, 0);
934
935 free_slide_point_data(data); /* keep this last! */
936 return OPERATOR_FINISHED;
937 }
938 else if (event->type != data->event_invoke_type && event->val == KM_PRESS) {
939 /* pass to ESCKEY */
941 }
942 else {
943 break;
944 }
945
946 case EVT_ESCKEY:
948
950 DEG_id_tag_update(&data->mask->id, 0);
951
952 free_slide_point_data(data); /* keep this last! */
953 return OPERATOR_CANCELLED;
954 default: {
955 break;
956 }
957 }
958
960}
961
963{
964 PropertyRNA *prop;
965
966 /* identifiers */
967 ot->name = "Slide Point";
968 ot->description = "Slide control points";
969 ot->idname = "MASK_OT_slide_point";
970
971 /* API callbacks. */
975
976 /* flags */
978
980 "slide_feather",
981 false,
982 "Slide Feather",
983 "First try to slide feather instead of vertex");
984
985 prop = RNA_def_boolean(
986 ot->srna, "is_new_point", false, "Slide New Point", "Newly created vertex is being slid");
988}
989
990/******************** slide spline curvature *********************/
991
1010
1012{
1013 *slide_data->adjust_bezt = slide_data->bezt_backup;
1014 *slide_data->other_bezt = slide_data->other_bezt_backup;
1015}
1016
1018{
1019 MEM_delete(slide_data);
1020}
1021
1023{
1025 float co[2];
1026 const float threshold = 19.0f;
1027
1029
1030 if (ED_mask_point_find_nearest(C, mask, co, threshold, nullptr, nullptr, nullptr, nullptr)) {
1031 return false;
1032 }
1033
1035 C, mask, co, threshold, nullptr, nullptr, nullptr, nullptr, nullptr))
1036 {
1037 return false;
1038 }
1039
1040 return true;
1041}
1042
1044 const wmEvent *event)
1045{
1046 const float threshold = 19.0f;
1047
1049 SlideSplineCurvatureData *slide_data;
1050 MaskLayer *mask_layer;
1051 MaskSpline *spline;
1052 MaskSplinePoint *point;
1053 float u, co[2];
1054 BezTriple *next_bezt;
1055
1056 MaskViewLockState lock_state;
1057 ED_mask_view_lock_state_store(C, &lock_state);
1058
1060
1062 mask,
1063 co,
1064 threshold,
1065 false,
1066 nullptr,
1067 true,
1068 false,
1069 &mask_layer,
1070 &spline,
1071 &point,
1072 &u,
1073 nullptr))
1074 {
1075 return nullptr;
1076 }
1077
1078 next_bezt = BKE_mask_spline_point_next_bezt(spline, spline->points, point);
1079 if (next_bezt == nullptr) {
1080 return nullptr;
1081 }
1082
1083 slide_data = MEM_new<SlideSplineCurvatureData>("slide curvature slide");
1084 slide_data->event_invoke_type = event->type;
1085 slide_data->mask = mask;
1086 slide_data->mask_layer = mask_layer;
1087 slide_data->spline = spline;
1088 slide_data->point = point;
1089 slide_data->u = u;
1090
1091 copy_v2_v2(slide_data->prev_mouse_coord, co);
1092 BKE_mask_point_segment_co(spline, point, u, slide_data->prev_spline_coord);
1093
1094 copy_v2_v2(slide_data->P0, point->bezt.vec[1]);
1095 copy_v2_v2(slide_data->P1, point->bezt.vec[2]);
1096 copy_v2_v2(slide_data->P2, next_bezt->vec[0]);
1097 copy_v2_v2(slide_data->P3, next_bezt->vec[1]);
1098
1099 /* Depending to which end we're closer to adjust either left or right side of the spline. */
1100 if (u <= 0.5f) {
1101 slide_data->adjust_bezt = &point->bezt;
1102 slide_data->other_bezt = next_bezt;
1103 }
1104 else {
1105 slide_data->adjust_bezt = next_bezt;
1106 slide_data->other_bezt = &point->bezt;
1107 }
1108
1109 /* Data needed for restoring state. */
1110 slide_data->bezt_backup = *slide_data->adjust_bezt;
1111 slide_data->other_bezt_backup = *slide_data->other_bezt;
1112
1113 /* Let's don't touch other side of the point for now, so set handle to FREE. */
1114 if (u < 0.5f) {
1115 if (slide_data->adjust_bezt->h2 <= HD_VECT) {
1116 slide_data->adjust_bezt->h2 = HD_FREE;
1117 }
1118 }
1119 else {
1120 if (slide_data->adjust_bezt->h1 <= HD_VECT) {
1121 slide_data->adjust_bezt->h1 = HD_FREE;
1122 }
1123 }
1124
1125 /* Change selection */
1127 slide_data->adjust_bezt->f2 |= BEZT_FLAG_SELECT;
1128 slide_data->other_bezt->f2 |= BEZT_FLAG_SELECT;
1129 if (u < 0.5f) {
1130 slide_data->adjust_bezt->f3 |= BEZT_FLAG_SELECT;
1131 slide_data->other_bezt->f1 |= BEZT_FLAG_SELECT;
1132 }
1133 else {
1134 slide_data->adjust_bezt->f1 |= BEZT_FLAG_SELECT;
1135 slide_data->other_bezt->f3 |= BEZT_FLAG_SELECT;
1136 }
1137 mask_layer->act_spline = spline;
1138 mask_layer->act_point = point;
1140
1141 DEG_id_tag_update(&mask->id, 0);
1143
1144 return slide_data;
1145}
1146
1148 wmOperator *op,
1149 const wmEvent *event)
1150{
1152 SlideSplineCurvatureData *slide_data;
1153
1154 if (mask == nullptr) {
1155 return OPERATOR_PASS_THROUGH;
1156 }
1157
1158 /* Be sure we don't conflict with point slide here. */
1159 if (!slide_spline_curvature_check(C, event)) {
1160 return OPERATOR_PASS_THROUGH;
1161 }
1162
1163 slide_data = slide_spline_curvature_customdata(C, event);
1164 if (slide_data != nullptr) {
1165 op->customdata = slide_data;
1169 }
1170
1171 return OPERATOR_PASS_THROUGH;
1172}
1173
1174static void slide_spline_solve_P1(const float u,
1175 const float B[2],
1176 const float P0[2],
1177 const float P2[2],
1178 const float P3[2],
1179 float solution[2])
1180{
1181 const float u2 = u * u, u3 = u * u * u;
1182 const float v = 1.0f - u;
1183 const float v2 = v * v, v3 = v * v * v;
1184 const float inv_divider = 1.0f / (3.0f * v2 * u);
1185 const float t = 3.0f * v * u2;
1186 solution[0] = -(v3 * P0[0] + t * P2[0] + u3 * P3[0] - B[0]) * inv_divider;
1187 solution[1] = -(v3 * P0[1] + t * P2[1] + u3 * P3[1] - B[1]) * inv_divider;
1188}
1189
1190static void slide_spline_solve_P2(const float u,
1191 const float B[2],
1192 const float P0[2],
1193 const float P1[2],
1194 const float P3[2],
1195 float solution[2])
1196{
1197 const float u2 = u * u, u3 = u * u * u;
1198 const float v = 1.0f - u;
1199 const float v2 = v * v, v3 = v * v * v;
1200 const float inv_divider = 1.0f / (3.0f * v * u2);
1201 const float t = 3.0f * v2 * u;
1202 solution[0] = -(v3 * P0[0] + t * P1[0] + u3 * P3[0] - B[0]) * inv_divider;
1203 solution[1] = -(v3 * P0[1] + t * P1[1] + u3 * P3[1] - B[1]) * inv_divider;
1204}
1205
1207 wmOperator *op,
1208 const wmEvent *event)
1209{
1210 Scene *scene = CTX_data_scene(C);
1211 const float margin = 0.2f;
1212 SlideSplineCurvatureData *slide_data = static_cast<SlideSplineCurvatureData *>(op->customdata);
1213 float u = slide_data->u;
1214
1215 switch (event->type) {
1216 case EVT_LEFTSHIFTKEY:
1217 case EVT_RIGHTSHIFTKEY:
1218 case EVT_LEFTCTRLKEY:
1219 case EVT_RIGHTCTRLKEY:
1221 slide_data->accurate = (event->val == KM_PRESS);
1222 }
1223
1224 if (ELEM(event->type, EVT_LEFTCTRLKEY, EVT_RIGHTCTRLKEY)) {
1225 if (event->val == KM_PRESS) {
1226 slide_data->adjust_bezt->h1 = slide_data->adjust_bezt->h2 = HD_FREE;
1227 if ((u > margin && u < 0.5f) || (u >= 0.5f && u < 1.0f - margin)) {
1228 slide_data->other_bezt->h1 = slide_data->other_bezt->h2 = HD_FREE;
1229 }
1230 }
1231 else if (event->val == KM_RELEASE) {
1232 slide_data->adjust_bezt->h1 = slide_data->bezt_backup.h1;
1233 slide_data->adjust_bezt->h2 = slide_data->bezt_backup.h2;
1234 slide_data->other_bezt->h1 = slide_data->other_bezt_backup.h1;
1235 slide_data->other_bezt->h2 = slide_data->other_bezt_backup.h2;
1236 }
1237
1238 if (u < 0.5f) {
1239 copy_v2_v2(slide_data->adjust_bezt->vec[0], slide_data->bezt_backup.vec[0]);
1240 copy_v2_v2(slide_data->other_bezt->vec[2], slide_data->other_bezt_backup.vec[2]);
1241 }
1242 else {
1243 copy_v2_v2(slide_data->adjust_bezt->vec[2], slide_data->bezt_backup.vec[2]);
1244 copy_v2_v2(slide_data->other_bezt->vec[0], slide_data->other_bezt_backup.vec[0]);
1245 }
1246 }
1247
1248 ATTR_FALLTHROUGH; /* update CV position */
1249 case MOUSEMOVE: {
1250 float B[2], mouse_coord[2], delta[2];
1251
1252 /* Get coordinate spline is expected to go through. */
1253 ED_mask_mouse_pos(CTX_wm_area(C), CTX_wm_region(C), event->mval, mouse_coord);
1254 sub_v2_v2v2(delta, mouse_coord, slide_data->prev_mouse_coord);
1255 if (slide_data->accurate) {
1256 mul_v2_fl(delta, 0.2f);
1257 }
1258 add_v2_v2v2(B, slide_data->prev_spline_coord, delta);
1259 copy_v2_v2(slide_data->prev_spline_coord, B);
1260 copy_v2_v2(slide_data->prev_mouse_coord, mouse_coord);
1261
1262 if (u < 0.5f) {
1263 float oldP2[2];
1264 bool need_restore_P2 = false;
1265
1266 if (u > margin) {
1267 float solution[2];
1268 float x = (u - margin) * 0.5f / (0.5f - margin);
1269 float weight = (3 * x * x - 2 * x * x * x);
1270
1271 slide_spline_solve_P2(u, B, slide_data->P0, slide_data->P1, slide_data->P3, solution);
1272
1273 copy_v2_v2(oldP2, slide_data->P2);
1274 interp_v2_v2v2(slide_data->P2, slide_data->P2, solution, weight);
1275 copy_v2_v2(slide_data->other_bezt->vec[0], slide_data->P2);
1276 need_restore_P2 = true;
1277
1278 /* Tweak handle type in order to be able to apply the delta. */
1279 if (weight > 0.0f) {
1280 if (slide_data->other_bezt->h1 <= HD_VECT) {
1281 slide_data->other_bezt->h1 = HD_FREE;
1282 }
1283 }
1284 }
1285
1287 u, B, slide_data->P0, slide_data->P2, slide_data->P3, slide_data->adjust_bezt->vec[2]);
1288
1289 if (need_restore_P2) {
1290 copy_v2_v2(slide_data->P2, oldP2);
1291 }
1292 }
1293 else {
1294 float oldP1[2];
1295 bool need_restore_P1 = false;
1296
1297 if (u < 1.0f - margin) {
1298 float solution[2];
1299 float x = ((1.0f - u) - margin) * 0.5f / (0.5f - margin);
1300 float weight = 3 * x * x - 2 * x * x * x;
1301
1302 slide_spline_solve_P1(u, B, slide_data->P0, slide_data->P2, slide_data->P3, solution);
1303
1304 copy_v2_v2(oldP1, slide_data->P1);
1305 interp_v2_v2v2(slide_data->P1, slide_data->P1, solution, weight);
1306 copy_v2_v2(slide_data->other_bezt->vec[2], slide_data->P1);
1307 need_restore_P1 = true;
1308
1309 /* Tweak handle type in order to be able to apply the delta. */
1310 if (weight > 0.0f) {
1311 if (slide_data->other_bezt->h2 <= HD_VECT) {
1312 slide_data->other_bezt->h2 = HD_FREE;
1313 }
1314 }
1315 }
1316
1318 u, B, slide_data->P0, slide_data->P1, slide_data->P3, slide_data->adjust_bezt->vec[0]);
1319
1320 if (need_restore_P1) {
1321 copy_v2_v2(slide_data->P1, oldP1);
1322 }
1323 }
1324
1325 WM_event_add_notifier(C, NC_MASK | NA_EDITED, slide_data->mask);
1326 DEG_id_tag_update(&slide_data->mask->id, 0);
1327
1328 break;
1329 }
1330
1331 case LEFTMOUSE:
1332 case RIGHTMOUSE:
1333 if (event->type == slide_data->event_invoke_type && event->val == KM_RELEASE) {
1334 /* Don't key sliding feather UW's. */
1335 if (animrig::is_autokey_on(scene)) {
1336 ED_mask_layer_shape_auto_key(C, slide_data->mask_layer, scene->r.cfra);
1337 }
1338
1339 WM_event_add_notifier(C, NC_MASK | NA_EDITED, slide_data->mask);
1340 DEG_id_tag_update(&slide_data->mask->id, 0);
1341
1342 free_slide_spline_curvature_data(slide_data); /* keep this last! */
1343 return OPERATOR_FINISHED;
1344 }
1345
1346 break;
1347
1348 case EVT_ESCKEY:
1350
1351 WM_event_add_notifier(C, NC_MASK | NA_EDITED, slide_data->mask);
1352 DEG_id_tag_update(&slide_data->mask->id, 0);
1353
1354 free_slide_spline_curvature_data(slide_data); /* keep this last! */
1355 return OPERATOR_CANCELLED;
1356 default: {
1357 break;
1358 }
1359 }
1360
1362}
1363
1365{
1366 /* identifiers */
1367 ot->name = "Slide Spline Curvature";
1368 ot->description = "Slide a point on the spline to define its curvature";
1369 ot->idname = "MASK_OT_slide_spline_curvature";
1370
1371 /* API callbacks. */
1375
1376 /* flags */
1378}
1379
1380/******************** toggle cyclic *********************/
1381
1383{
1385
1386 for (MaskLayer &mask_layer : mask->masklayers) {
1387 if (mask_layer.visibility_flag & (MASK_HIDE_VIEW | MASK_HIDE_SELECT)) {
1388 continue;
1389 }
1390
1391 for (MaskSpline &spline : mask_layer.splines) {
1392 if (ED_mask_spline_select_check(&spline)) {
1393 spline.flag ^= MASK_SPLINE_CYCLIC;
1394 }
1395 }
1396 }
1397
1398 DEG_id_tag_update(&mask->id, 0);
1400
1401 return OPERATOR_FINISHED;
1402}
1403
1405{
1406 /* identifiers */
1407 ot->name = "Toggle Cyclic";
1408 ot->description = "Toggle cyclic for selected splines";
1409 ot->idname = "MASK_OT_cyclic_toggle";
1410
1411 /* API callbacks. */
1414
1415 /* flags */
1417}
1418
1419/******************** delete *********************/
1420
1422{
1423 int count = 0;
1424
1425 if (!point->tot_uw) {
1426 return;
1427 }
1428
1429 for (int i = 0; i < point->tot_uw; i++) {
1430 if ((point->uw[i].flag & SELECT) == 0) {
1431 count++;
1432 }
1433 }
1434
1435 if (count == 0) {
1436 MEM_delete(point->uw);
1437 point->uw = nullptr;
1438 point->tot_uw = 0;
1439 }
1440 else {
1441 MaskSplinePointUW *new_uw;
1442 int j = 0;
1443
1444 new_uw = MEM_new_array<MaskSplinePointUW>(count, "new mask uw points");
1445
1446 for (int i = 0; i < point->tot_uw; i++) {
1447 if ((point->uw[i].flag & SELECT) == 0) {
1448 new_uw[j++] = point->uw[i];
1449 }
1450 }
1451
1452 MEM_delete(point->uw);
1453
1454 point->uw = new_uw;
1455 point->tot_uw = count;
1456 }
1457}
1458
1460{
1462 bool changed = false;
1463
1464 for (MaskLayer &mask_layer : mask->masklayers) {
1465 MaskSpline *spline;
1466 int mask_layer_shape_ofs = 0;
1467
1468 if (mask_layer.visibility_flag & (MASK_HIDE_VIEW | MASK_HIDE_SELECT)) {
1469 continue;
1470 }
1471
1472 spline = mask_layer.splines.first();
1473
1474 while (spline) {
1475 const int tot_point_orig = spline->tot_point;
1476 int count = 0;
1477 MaskSpline *next_spline = spline->next;
1478
1479 /* count unselected points */
1480 for (int i = 0; i < spline->tot_point; i++) {
1481 MaskSplinePoint *point = &spline->points[i];
1482
1483 if (!BKE_mask_point_selected(point)) {
1484 count++;
1485 }
1486 }
1487
1488 if (count == 0) {
1489
1490 /* Update active. */
1491 if (mask_layer.act_point) {
1492 if (ARRAY_HAS_ITEM(mask_layer.act_point, spline->points, spline->tot_point)) {
1493 mask_layer.act_point = nullptr;
1494 }
1495 }
1496 if (spline == mask_layer.act_spline) {
1497 mask_layer.act_spline = nullptr;
1498 }
1499
1500 /* delete the whole spline */
1501 BLI_remlink(&mask_layer.splines, spline);
1502 BKE_mask_spline_free(spline);
1503
1504 BKE_mask_layer_shape_changed_remove(&mask_layer, mask_layer_shape_ofs, tot_point_orig);
1505 }
1506 else {
1507 MaskSplinePoint *new_points;
1508
1509 new_points = MEM_new_array<MaskSplinePoint>(count, "deleteMaskPoints");
1510
1511 for (int i = 0, j = 0; i < tot_point_orig; i++) {
1512 MaskSplinePoint *point = &spline->points[i];
1513
1514 if (!BKE_mask_point_selected(point)) {
1515 if (point == mask_layer.act_point) {
1516 mask_layer.act_point = &new_points[j];
1517 }
1518
1519 delete_feather_points(point);
1520
1521 new_points[j] = *point;
1522 j++;
1523 }
1524 else {
1525 if (point == mask_layer.act_point) {
1526 mask_layer.act_point = nullptr;
1527 }
1528
1529 BKE_mask_point_free(point);
1530 spline->tot_point--;
1531
1532 BKE_mask_layer_shape_changed_remove(&mask_layer, mask_layer_shape_ofs + j, 1);
1533 }
1534 }
1535
1536 mask_layer_shape_ofs += spline->tot_point;
1537
1538 MEM_delete(spline->points);
1539 spline->points = new_points;
1540
1542 }
1543
1544 changed = true;
1545 spline = next_spline;
1546 }
1547
1548 /* Not essential but confuses users when there are keys with no data!
1549 * Assume if they delete all data from the layer they also don't care about keys. */
1550 if (mask_layer.splines.is_empty()) {
1551 BKE_mask_layer_free_shapes(&mask_layer);
1552 }
1553 }
1554
1555 if (!changed) {
1556 return OPERATOR_CANCELLED;
1557 }
1558
1560
1562
1563 return OPERATOR_FINISHED;
1564}
1565
1567{
1568 if (RNA_boolean_get(op->ptr, "confirm")) {
1570 op,
1571 IFACE_("Delete selected control points and splines?"),
1572 nullptr,
1573 IFACE_("Delete"),
1575 false);
1576 }
1577 return delete_exec(C, op);
1578}
1579
1581{
1582 /* identifiers */
1583 ot->name = "Delete";
1584 ot->description = "Delete selected control points or splines";
1585 ot->idname = "MASK_OT_delete";
1586
1587 /* API callbacks. */
1588 ot->invoke = delete_invoke;
1589 ot->exec = delete_exec;
1591
1592 /* flags */
1595}
1596
1597/* *** switch direction *** */
1599{
1600 Scene *scene = CTX_data_scene(C);
1602
1603 bool changed = false;
1604
1605 /* do actual selection */
1606 for (MaskLayer &mask_layer : mask->masklayers) {
1607 bool changed_layer = false;
1608
1609 if (mask_layer.visibility_flag & (MASK_HIDE_VIEW | MASK_HIDE_SELECT)) {
1610 continue;
1611 }
1612
1613 for (MaskSpline &spline : mask_layer.splines) {
1614 if (ED_mask_spline_select_check(&spline)) {
1615 BKE_mask_spline_direction_switch(&mask_layer, &spline);
1616 changed = true;
1617 changed_layer = true;
1618 }
1619 }
1620
1621 if (changed_layer) {
1622 if (animrig::is_autokey_on(scene)) {
1623 ED_mask_layer_shape_auto_key(C, &mask_layer, scene->r.cfra);
1624 }
1625 }
1626 }
1627
1628 if (changed) {
1630
1633
1634 return OPERATOR_FINISHED;
1635 }
1636
1637 return OPERATOR_CANCELLED;
1638}
1639
1641{
1642 /* identifiers */
1643 ot->name = "Switch Direction";
1644 ot->description = "Switch direction of selected splines";
1645 ot->idname = "MASK_OT_switch_direction";
1646
1647 /* API callbacks. */
1650
1651 /* flags */
1653}
1654
1655/* *** recalc normals *** */
1657{
1658 Scene *scene = CTX_data_scene(C);
1660
1661 bool changed = false;
1662
1663 /* do actual selection */
1664 for (MaskLayer &mask_layer : mask->masklayers) {
1665 bool changed_layer = false;
1666
1667 if (mask_layer.visibility_flag & (MASK_HIDE_VIEW | MASK_HIDE_SELECT)) {
1668 continue;
1669 }
1670
1671 for (MaskSpline &spline : mask_layer.splines) {
1672 for (int i = 0; i < spline.tot_point; i++) {
1673 MaskSplinePoint *point = &spline.points[i];
1674
1675 if (BKE_mask_point_selected(point)) {
1676 BKE_mask_calc_handle_point_auto(&spline, point, false);
1677 changed = true;
1678 changed_layer = true;
1679 }
1680 }
1681 }
1682
1683 if (changed_layer) {
1684 if (animrig::is_autokey_on(scene)) {
1685 ED_mask_layer_shape_auto_key(C, &mask_layer, scene->r.cfra);
1686 }
1687 }
1688 }
1689
1690 if (changed) {
1692
1695
1696 return OPERATOR_FINISHED;
1697 }
1698
1699 return OPERATOR_CANCELLED;
1700}
1701
1703{
1704 /* identifiers */
1705 ot->name = "Recalculate Handles";
1706 ot->description = "Recalculate the direction of selected handles";
1707 ot->idname = "MASK_OT_normals_make_consistent";
1708
1709 /* API callbacks. */
1712
1713 /* flags */
1715}
1716
1717/******************** set handle type *********************/
1718
1720{
1722 eBezTriple_Handle handle_type = eBezTriple_Handle(RNA_enum_get(op->ptr, "type"));
1723
1724 bool changed = false;
1725
1726 for (MaskLayer &mask_layer : mask->masklayers) {
1727 if (mask_layer.visibility_flag & (MASK_HIDE_VIEW | MASK_HIDE_SELECT)) {
1728 continue;
1729 }
1730
1731 for (MaskSpline &spline : mask_layer.splines) {
1732 for (int i = 0; i < spline.tot_point; i++) {
1733 MaskSplinePoint *point = &spline.points[i];
1734
1735 if (BKE_mask_point_selected(point)) {
1736 BezTriple *bezt = &point->bezt;
1737
1738 if (bezt->f2 & SELECT) {
1739 bezt->h1 = handle_type;
1740 bezt->h2 = handle_type;
1741 }
1742 else {
1743 if (bezt->f1 & SELECT) {
1744 bezt->h1 = handle_type;
1745 }
1746 if (bezt->f3 & SELECT) {
1747 bezt->h2 = handle_type;
1748 }
1749 }
1750
1751 if (handle_type == HD_ALIGN) {
1752 float vec[3];
1753 sub_v3_v3v3(vec, bezt->vec[0], bezt->vec[1]);
1754 add_v3_v3v3(bezt->vec[2], bezt->vec[1], vec);
1755 }
1756
1757 changed = true;
1758 }
1759 }
1760 }
1761 }
1762
1763 if (changed) {
1765 DEG_id_tag_update(&mask->id, 0);
1766
1767 return OPERATOR_FINISHED;
1768 }
1769 return OPERATOR_CANCELLED;
1770}
1771
1773{
1774 static const EnumPropertyItem editcurve_handle_type_items[] = {
1775 {HD_AUTO, "AUTO", 0, "Auto", ""},
1776 {HD_VECT, "VECTOR", 0, "Vector", ""},
1777 {HD_ALIGN, "ALIGNED", 0, "Aligned Single", ""},
1778 {HD_ALIGN_DOUBLESIDE, "ALIGNED_DOUBLESIDE", 0, "Aligned", ""},
1779 {HD_FREE, "FREE", 0, "Free", ""},
1780 {0, nullptr, 0, nullptr, nullptr},
1781 };
1782
1783 /* identifiers */
1784 ot->name = "Set Handle Type";
1785 ot->description = "Set type of handles for selected control points";
1786 ot->idname = "MASK_OT_handle_type_set";
1787
1788 /* API callbacks. */
1789 ot->invoke = WM_menu_invoke;
1792
1793 /* flags */
1795
1796 /* properties */
1797 ot->prop = RNA_def_enum(ot->srna, "type", editcurve_handle_type_items, 1, "Type", "Spline type");
1798}
1799
1800/* ********* clear/set restrict view *********/
1802{
1804 bool changed = false;
1805 const bool select = RNA_boolean_get(op->ptr, "select");
1806
1807 for (MaskLayer &mask_layer : mask->masklayers) {
1808
1809 if (mask_layer.visibility_flag & MASK_HIDE_VIEW) {
1810 ED_mask_layer_select_set(&mask_layer, select);
1811 mask_layer.visibility_flag &= ~MASK_HIDE_VIEW;
1812 changed = true;
1813 }
1814 }
1815
1816 if (changed) {
1818 DEG_id_tag_update(&mask->id, 0);
1819
1820 return OPERATOR_FINISHED;
1821 }
1822 return OPERATOR_CANCELLED;
1823}
1824
1826{
1827
1828 /* identifiers */
1829 ot->name = "Clear Restrict View";
1830 ot->description = "Reveal temporarily hidden mask layers";
1831 ot->idname = "MASK_OT_hide_view_clear";
1832
1833 /* API callbacks. */
1836
1837 /* flags */
1839
1840 RNA_def_boolean(ot->srna, "select", true, "Select", "");
1841}
1842
1844{
1846 const bool unselected = RNA_boolean_get(op->ptr, "unselected");
1847 bool changed = false;
1848
1849 for (MaskLayer &mask_layer : mask->masklayers) {
1850
1851 if (mask_layer.visibility_flag & MASK_HIDE_SELECT) {
1852 continue;
1853 }
1854
1855 if (!unselected) {
1856 if (ED_mask_layer_select_check(&mask_layer)) {
1857 ED_mask_layer_select_set(&mask_layer, false);
1858
1859 mask_layer.visibility_flag |= MASK_HIDE_VIEW;
1860 changed = true;
1861 if (&mask_layer == BKE_mask_layer_active(mask)) {
1863 }
1864 }
1865 }
1866 else {
1867 if (!ED_mask_layer_select_check(&mask_layer)) {
1868 mask_layer.visibility_flag |= MASK_HIDE_VIEW;
1869 changed = true;
1870 if (&mask_layer == BKE_mask_layer_active(mask)) {
1872 }
1873 }
1874 }
1875 }
1876
1877 if (changed) {
1879 DEG_id_tag_update(&mask->id, 0);
1880
1881 return OPERATOR_FINISHED;
1882 }
1883 return OPERATOR_CANCELLED;
1884}
1885
1887{
1888 /* identifiers */
1889 ot->name = "Set Restrict View";
1890 ot->description = "Temporarily hide mask layers";
1891 ot->idname = "MASK_OT_hide_view_set";
1892
1893 /* API callbacks. */
1896
1897 /* flags */
1899
1901 ot->srna, "unselected", false, "Unselected", "Hide unselected rather than selected layers");
1902}
1903
1905{
1907 bool changed = false;
1908
1909 for (MaskLayer &mask_layer : mask->masklayers) {
1910 if (mask_layer.visibility_flag & (MASK_HIDE_SELECT | MASK_HIDE_VIEW)) {
1911 continue;
1912 }
1913
1914 for (MaskSpline &spline : mask_layer.splines) {
1915 for (int i = 0; i < spline.tot_point; i++) {
1916 MaskSplinePoint *point = &spline.points[i];
1917
1918 if (BKE_mask_point_selected(point)) {
1919 BezTriple *bezt = &point->bezt;
1920 bezt->weight = 0.0f;
1921 changed = true;
1922 }
1923 }
1924 }
1925 }
1926
1927 if (changed) {
1929
1931 DEG_id_tag_update(&mask->id, 0);
1932
1933 return OPERATOR_FINISHED;
1934 }
1935 return OPERATOR_CANCELLED;
1936}
1937
1939{
1940 /* identifiers */
1941 ot->name = "Clear Feather Weight";
1942 ot->description = "Reset the feather weight to zero";
1943 ot->idname = "MASK_OT_feather_weight_clear";
1944
1945 /* API callbacks. */
1948
1949 /* flags */
1951}
1952
1953/******************** move mask layer operator *********************/
1954
1956{
1957 if (ED_maskedit_mask_poll(C)) {
1959
1960 return mask->masklay_tot > 0;
1961 }
1962
1963 return false;
1964}
1965
1967{
1969 MaskLayer *mask_layer = static_cast<MaskLayer *>(
1970 BLI_findlink(&mask->masklayers, mask->masklay_act));
1971 MaskLayer *mask_layer_other;
1972 int direction = RNA_enum_get(op->ptr, "direction");
1973
1974 if (!mask_layer) {
1975 return OPERATOR_CANCELLED;
1976 }
1977
1978 if (direction == -1) {
1979 mask_layer_other = mask_layer->prev;
1980
1981 if (!mask_layer_other) {
1982 return OPERATOR_CANCELLED;
1983 }
1984
1985 BLI_remlink(&mask->masklayers, mask_layer);
1986 BLI_insertlinkbefore(&mask->masklayers, mask_layer_other, mask_layer);
1987 mask->masklay_act--;
1988 }
1989 else if (direction == 1) {
1990 mask_layer_other = mask_layer->next;
1991
1992 if (!mask_layer_other) {
1993 return OPERATOR_CANCELLED;
1994 }
1995
1996 BLI_remlink(&mask->masklayers, mask_layer);
1997 BLI_insertlinkafter(&mask->masklayers, mask_layer_other, mask_layer);
1998 mask->masklay_act++;
1999 }
2000
2003
2004 return OPERATOR_FINISHED;
2005}
2006
2008{
2009 static const EnumPropertyItem direction_items[] = {
2010 {-1, "UP", 0, "Up", ""},
2011 {1, "DOWN", 0, "Down", ""},
2012 {0, nullptr, 0, nullptr, nullptr},
2013 };
2014
2015 /* identifiers */
2016 ot->name = "Move Layer";
2017 ot->description = "Move the active layer up/down in the list";
2018 ot->idname = "MASK_OT_layer_move";
2019
2020 /* API callbacks. */
2023
2024 /* flags */
2026
2027 /* properties */
2028 RNA_def_enum(ot->srna,
2029 "direction",
2030 direction_items,
2031 0,
2032 "Direction",
2033 "Direction to move the active layer");
2034}
2035
2036/******************** mask move to layer operator *********************/
2037
2039{
2040 if (ED_maskedit_mask_poll(C)) {
2042
2043 return mask->masklay_tot > 0;
2044 }
2045
2046 return false;
2047}
2048
2050{
2052
2053 MaskLayer *target_mask_layer = nullptr;
2054 const std::string target_layer_name = RNA_string_get(op->ptr, "target_layer_name");
2055 if (RNA_boolean_get(op->ptr, "add_new_layer")) {
2056 target_mask_layer = BKE_mask_layer_new(mask, target_layer_name.c_str());
2057 }
2058 else {
2059 target_mask_layer = BKE_mask_layer_by_name(mask, target_layer_name.c_str());
2060 }
2061
2062 for (MaskLayer &mask_layer : mask->masklayers) {
2063 if (&mask_layer == target_mask_layer) {
2064 continue;
2065 }
2066
2067 if (mask_layer.visibility_flag & (MASK_HIDE_VIEW | MASK_HIDE_SELECT)) {
2068 continue;
2069 }
2070
2071 for (MaskSpline &spline : mask_layer.splines.items_mutable()) {
2072 if (ED_mask_spline_select_check(&spline)) {
2073 BKE_mask_spline_move_to_layer(&spline, &mask_layer, target_mask_layer);
2074 }
2075 }
2076 }
2077
2080
2081 return OPERATOR_FINISHED;
2082}
2083
2085{
2087 for (const MaskLayer &mask_layer : mask->masklayers) {
2088 names.add(mask_layer.name);
2089 }
2090 return names;
2091}
2092
2093static std::string unique_layer_name(Mask *mask, const StringRef name)
2094{
2095 BLI_assert(!name.is_empty());
2097 return BLI_uniquename_cb(
2098 [&](const StringRef check_name) { return names.contains(check_name); }, '.', name);
2099}
2100
2102 wmOperator *op,
2103 const wmEvent *event)
2104{
2105 const bool add_new_layer = RNA_boolean_get(op->ptr, "add_new_layer");
2106 if (add_new_layer) {
2108 std::string unique_name_string = unique_layer_name(mask, DATA_("MaskLayer"));
2109 const char *unique_name = unique_name_string.c_str();
2110 RNA_string_set(op->ptr, "target_layer_name", unique_name);
2111
2113 C, op, event, IFACE_("Move to New Layer"), IFACE_("Create"));
2114 }
2115
2116 /* Show the move menu if this operator is invoked from operator search without any property
2117 * pre-set. */
2118 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "target_layer_name");
2119 if (!RNA_property_is_set(op->ptr, prop)) {
2120 WM_menu_name_call(C, "MASK_MT_move_to_layer", wm::OpCallContext::InvokeDefault);
2121 return OPERATOR_FINISHED;
2122 }
2123
2124 return mask_move_to_layer_exec(C, op);
2125}
2126
2128{
2129 PropertyRNA *prop;
2130
2131 /* identifiers */
2132 ot->name = "Move to Layer";
2133 ot->description = "Move the active spline to layer";
2134 ot->idname = "MASK_OT_move_to_layer";
2135
2136 /* api callbacks */
2140
2141 /* flags */
2143
2144 /* properties */
2145 prop = RNA_def_string(
2146 ot->srna, "target_layer_name", nullptr, INT16_MAX, "Name", "Target Mask Layer");
2148 prop = RNA_def_boolean(
2149 ot->srna, "add_new_layer", false, "New Layer", "Move selection to a new layer");
2151}
2152
2153/******************** duplicate *********************/
2154
2156{
2158
2159 for (MaskLayer &mask_layer : mask->masklayers) {
2160 for (MaskSpline &spline : mask_layer.splines.items_reversed()) {
2161 const bool act_point_in_spline = mask_layer.act_point && ARRAY_HAS_ITEM(mask_layer.act_point,
2162 spline.points,
2163 spline.tot_point);
2164 const void *act_point_prev = mask_layer.act_point;
2165
2166 MaskSplinePoint *point = spline.points;
2167 int i = 0;
2168 while (i < spline.tot_point) {
2169 int start = i, end = -1;
2170 /* Find next selected segment. */
2171 while (BKE_mask_point_selected(point)) {
2172 BKE_mask_point_select_set(point, false);
2173 end = i;
2174 if (i >= spline.tot_point - 1) {
2175 break;
2176 }
2177 i++;
2178 point++;
2179 }
2180 if (end >= start) {
2181 int tot_point;
2182 int tot_point_shape_start = 0;
2183 MaskSpline *new_spline = BKE_mask_spline_add(&mask_layer);
2184 MaskSplinePoint *new_point;
2185 int b;
2186
2187 /* BKE_mask_spline_add might allocate the points,
2188 * need to free them in this case. */
2189 if (new_spline->points) {
2190 MEM_delete(new_spline->points);
2191 }
2192
2193 /* Copy options from old spline. */
2194 new_spline->flag = spline.flag;
2195 new_spline->offset_mode = spline.offset_mode;
2196 new_spline->weight_interp = spline.weight_interp;
2197 new_spline->parent = spline.parent;
2198
2199 /* Allocate new points and copy them from old spline. */
2200 new_spline->tot_point = end - start + 1;
2201 new_spline->points = MEM_new_array<MaskSplinePoint>(new_spline->tot_point,
2202 "duplicated mask points");
2203
2204 memcpy(new_spline->points,
2205 spline.points + start,
2206 new_spline->tot_point * sizeof(MaskSplinePoint));
2207
2208 tot_point = new_spline->tot_point;
2209
2210 /* Update the active. */
2211 if (mask_layer.act_point) {
2212 ptrdiff_t act_index = mask_layer.act_point - &spline.points[start];
2213 if (size_t(act_index) < new_spline->tot_point) {
2214 mask_layer.act_point = &new_spline->points[act_index];
2215 }
2216 }
2217 if (mask_layer.act_spline) {
2218 if (mask_layer.act_spline == &spline) {
2219 mask_layer.act_spline = new_spline;
2220 }
2221 }
2222
2223 /* animation requires points added one by one */
2224 if (mask_layer.splines_shapes.first_) {
2225 new_spline->tot_point = 0;
2226 tot_point_shape_start = BKE_mask_layer_shape_spline_to_index(&mask_layer, new_spline);
2227 }
2228
2229 /* Select points and duplicate their UWs (if needed). */
2230 for (b = 0, new_point = new_spline->points; b < tot_point; b++, new_point++) {
2231 if (new_point->uw) {
2232 new_point->uw = MEM_dupalloc(new_point->uw);
2233 }
2234 BKE_mask_point_select_set(new_point, true);
2235
2236 if (mask_layer.splines_shapes.first_) {
2237 new_spline->tot_point++;
2239 &mask_layer, tot_point_shape_start + b, true, false);
2240 }
2241 }
2242
2243 /* Clear cyclic flag if we didn't copy the whole spline. */
2244 if (new_spline->flag & MASK_SPLINE_CYCLIC) {
2245 if (start != 0 || end != spline.tot_point - 1) {
2246 new_spline->flag &= ~MASK_SPLINE_CYCLIC;
2247 }
2248 }
2249
2250 /* Flush selection to splines. */
2251 new_spline->flag |= MASK_SPLINE_SELECT;
2252 spline.flag &= ~MASK_SPLINE_SELECT;
2253 }
2254 i++;
2255 point++;
2256 }
2257
2258 if (act_point_in_spline && (mask_layer.act_point == act_point_prev)) {
2259 /* The active point was part of this spline but not copied,
2260 * clear it to avoid confusion with the active spline & point getting out of sync. */
2261 mask_layer.act_point = nullptr;
2262 }
2263 }
2264 }
2265
2267
2269
2270 return OPERATOR_FINISHED;
2271}
2272
2274{
2275 /* identifiers */
2276 ot->name = "Duplicate Mask";
2277 ot->description = "Duplicate selected control points and segments between them";
2278 ot->idname = "MASK_OT_duplicate";
2279
2280 /* API callbacks. */
2283
2284 /* flags */
2286}
2287
2288/********************** copy splines to clipboard operator *********************/
2289
2291{
2293 MaskLayer *mask_layer = BKE_mask_layer_active(mask);
2294
2295 if (mask_layer == nullptr) {
2296 return OPERATOR_CANCELLED;
2297 }
2298
2300
2301 return OPERATOR_FINISHED;
2302}
2303
2305{
2306 /* identifiers */
2307 ot->name = "Copy Splines";
2308 ot->description = "Copy the selected splines to the internal clipboard";
2309 ot->idname = "MASK_OT_copy_splines";
2310
2311 /* API callbacks. */
2312 ot->exec = copy_splines_exec;
2314
2315 /* flags */
2316 ot->flag = OPTYPE_REGISTER;
2317}
2318
2319/********************** paste tracks from clipboard operator *********************/
2320
2322{
2324 return BKE_mask_clipboard_is_empty() == false;
2325 }
2326
2327 return false;
2328}
2329
2331{
2333 MaskLayer *mask_layer = BKE_mask_layer_active(mask);
2334
2335 if (mask_layer == nullptr) {
2336 mask_layer = BKE_mask_layer_new(mask, "");
2337 }
2338
2340
2342
2344
2345 return OPERATOR_FINISHED;
2346}
2347
2349{
2350 /* identifiers */
2351 ot->name = "Paste Splines";
2352 ot->description = "Paste splines from the internal clipboard";
2353 ot->idname = "MASK_OT_paste_splines";
2354
2355 /* API callbacks. */
2358
2359 /* flags */
2361}
2362
2363} // namespace blender
Functions to insert, delete or modify keyframes.
#define SELECT
Definition BKE_mask.hh:19
#define ATTR_FALLTHROUGH
#define INT16_MAX
#define IFACE_(msgid)
#define DATA_(msgid)
#define MAX_ID_NAME
Definition DNA_ID.h:367
Object is a sort of wrapper for general info.
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define ND_DRAW
Definition WM_types.hh:502
#define ND_DATA
Definition WM_types.hh:552
#define NA_ADDED
Definition WM_types.hh:636
#define NA_EDITED
Definition WM_types.hh:634
#define ND_SELECT
Definition WM_types.hh:551
#define NC_MASK
Definition WM_types.hh:411
#define INIT_MINMAX2(min, max)
#define ARRAY_HAS_ITEM(arr_item, arr_start, arr_len)
#define ELEM(...)
#define BLI_assert_msg(a, msg)
btScalar max
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
bool add(const Key &key)
bool contains(const Key &key) const
constexpr bool is_empty() const
#define FLT_MAX
#define FLT_EPSILON
#define B
bool is_autokey_on(const Scene *scene)
void context_active_but_prop_get_templateID(const bContext *C, PointerRNA *r_ptr, PropertyRNA **r_prop)
BMesh Iterators.
MINLINE float min_ff(float a, float b)
eMaskWhichHandle
Definition BKE_mask.hh:44
@ MASK_WHICH_HANDLE_LEFT
Definition BKE_mask.hh:47
@ MASK_WHICH_HANDLE_RIGHT
Definition BKE_mask.hh:48
@ MASK_WHICH_HANDLE_STICK
Definition BKE_mask.hh:46
@ MASK_WHICH_HANDLE_NONE
Definition BKE_mask.hh:45
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
wmOperatorStatus WM_menu_invoke(bContext *C, wmOperator *op, const wmEvent *)
static wmOperatorStatus mask_hide_view_set_exec(bContext *C, wmOperator *op)
Definition mask_ops.cc:1843
ScrArea * CTX_wm_area(const bContext *C)
bool BKE_mask_clipboard_is_empty()
static bool spline_under_mouse_get(const bContext *C, Mask *mask_orig, const float co[2], MaskLayer **r_mask_layer, MaskSpline **r_mask_spline)
Definition mask_ops.cc:298
static wmOperatorStatus mask_layer_new_exec(bContext *C, wmOperator *op)
Definition mask_ops.cc:176
void BKE_mask_spline_free(MaskSpline *spline)
int RNA_enum_get(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
void RNA_property_update(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
void RNA_property_pointer_set(PointerRNA *ptr, PropertyRNA *prop, PointerRNA ptr_value, ReportList *reports)
void MASK_OT_switch_direction(wmOperatorType *ot)
Definition mask_ops.cc:1640
void BKE_mask_layer_shape_changed_remove(MaskLayer *masklay, int index, int count)
static void slide_spline_solve_P2(const float u, const float B[2], const float P0[2], const float P1[2], const float P3[2], float solution[2])
Definition mask_ops.cc:1190
MINLINE void add_v2_v2v2(float r[2], const float a[2], const float b[2])
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
void copy_m3_m3(float m1[3][3], const float m2[3][3])
void BKE_mask_point_handle(const MaskSplinePoint *point, eMaskWhichHandle which_handle, float r_handle[2])
PointerRNA RNA_id_pointer_create(ID *id)
void BKE_mask_clipboard_copy_from_layer(MaskLayer *mask_layer)
MINLINE void mul_v2_fl(float r[2], float f)
Mask * BKE_mask_new(Main *bmain, const char *name)
static wmOperatorStatus delete_invoke(bContext *C, wmOperator *op, const wmEvent *)
Definition mask_ops.cc:1566
MINLINE void copy_v2_v2(float r[2], const float a[2])
void ED_mask_select_toggle_all(Mask *mask, int action)
void ED_mask_view_lock_state_store(const bContext *C, MaskViewLockState *state)
Definition mask_edit.cc:209
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
MaskLayer * BKE_mask_layer_new(Mask *mask, const char *name)
static bool slide_spline_curvature_check(bContext *C, const wmEvent *event)
Definition mask_ops.cc:1022
void ED_clip_point_undistorted_pos(const SpaceClip *sc, const float co[2], float r_co[2])
static wmOperatorStatus mask_move_to_layer_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition mask_ops.cc:2101
@ MASK_PROJ_POS
Definition BKE_mask.hh:121
@ MASK_PROJ_NEG
Definition BKE_mask.hh:119
void project_v2_v2v2_normalized(float out[2], const float p[2], const float v_proj[2])
@ SLIDE_ACTION_POINT
Definition mask_ops.cc:246
@ SLIDE_ACTION_FEATHER
Definition mask_ops.cc:248
@ SLIDE_ACTION_HANDLE
Definition mask_ops.cc:247
@ SLIDE_ACTION_SPLINE
Definition mask_ops.cc:249
static void cancel_slide_point(SlidePointData *data)
Definition mask_ops.cc:658
MaskSpline * BKE_mask_spline_copy(const MaskSpline *spline)
static void mask_point_undistort_pos(SpaceClip *sc, float r_co[2], const float co[2])
Definition mask_draw.cc:83
SpaceClip * CTX_wm_space_clip(const bContext *C)
static wmOperatorStatus slide_spline_curvature_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition mask_ops.cc:1147
static void select_sliding_point(Mask *mask, MaskLayer *mask_layer, MaskSpline *spline, MaskSplinePoint *point, eMaskWhichHandle which_handle)
Definition mask_ops.cc:415
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
static void cancel_slide_spline_curvature(SlideSplineCurvatureData *slide_data)
Definition mask_ops.cc:1011
MaskSplinePoint * ED_mask_point_find_nearest(const bContext *C, Mask *mask_orig, const float normal_co[2], float threshold, MaskLayer **r_mask_layer, MaskSpline **r_spline, eMaskWhichHandle *r_which_handle, float *r_score)
MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2])
static wmOperatorStatus delete_exec(bContext *C, wmOperator *op)
Definition editfont.cc:1731
void MASK_OT_layer_remove(wmOperatorType *ot)
Definition mask_ops.cc:227
void MASK_OT_delete(wmOperatorType *ot)
Definition mask_ops.cc:1580
ATTR_WARN_UNUSED_RESULT const BMVert * v
static wmOperatorStatus slide_point_modal(bContext *C, wmOperator *op, const wmEvent *event)
Definition mask_ops.cc:691
static wmOperatorStatus slide_spline_curvature_modal(bContext *C, wmOperator *op, const wmEvent *event)
Definition mask_ops.cc:1206
@ MCLIP_PROXY_RENDER_UNDISTORT
void MASK_OT_hide_view_set(wmOperatorType *ot)
Definition mask_ops.cc:1886
void MASK_OT_slide_point(wmOperatorType *ot)
Definition mask_ops.cc:962
static wmOperatorStatus mask_move_to_layer_exec(bContext *C, wmOperator *op)
Definition mask_ops.cc:2049
MaskLayer * ED_mask_layer_ensure(bContext *C, bool *r_added_mask)
Definition mask_ops.cc:85
void MASK_OT_layer_move(wmOperatorType *ot)
Definition mask_ops.cc:2007
void MASK_OT_duplicate(wmOperatorType *ot)
Definition mask_ops.cc:2273
void MASK_OT_cyclic_toggle(wmOperatorType *ot)
Definition mask_ops.cc:1404
void ED_space_clip_set_mask(bContext *C, SpaceClip *sc, Mask *mask)
@ SLIDE_ACTION_NONE
Definition mask_ops.cc:245
void BKE_mask_layer_active_set(Mask *mask, MaskLayer *masklay)
void MASK_OT_feather_weight_clear(wmOperatorType *ot)
Definition mask_ops.cc:1938
size_t void BLI_uniquename_cb(FunctionRef< bool(StringRefNull)> unique_check, const char *defname, char delim, char *name, size_t name_maxncpy) ATTR_NONNULL(2
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:541
bool ED_mask_spline_select_check(const MaskSpline *spline)
void WM_operator_properties_confirm_or_exec(wmOperatorType *ot)
void BKE_mask_coord_to_movieclip(MovieClip *clip, MovieClipUser *user, float r_co[2], const float co[2])
VecBase< float, 2 > float2
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
MINLINE void add_v2_v2(float r[2], const float a[2])
bool BKE_mask_point_selected(const MaskSplinePoint *p)
Definition BKE_mask.hh:155
void minmax_v2v2_v2(float min[2], float max[2], const float vec[2])
BezTriple * BKE_mask_spline_point_next_bezt(MaskSpline *spline, MaskSplinePoint *points_array, MaskSplinePoint *point)
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:138
void DEG_id_tag_update(ID *id, unsigned int flags)
static bool slide_point_check_initial_feather(MaskSpline *spline)
Definition mask_ops.cc:402
float BKE_mask_point_weight_scalar(MaskSpline *spline, MaskSplinePoint *point, float u)
BMesh const char void * data
void BLI_insertlinkafter(ListBase *listbase, void *vprevlink, void *vnewlink) ATTR_NONNULL(1)
Definition listbase.cc:339
bool ED_maskedit_poll(bContext *C)
Definition mask_edit.cc:29
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
MaskSplinePointUW * BKE_mask_point_sort_uw(MaskSplinePoint *point, MaskSplinePointUW *uw)
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C, bool rna_write_check=false)
void BKE_mask_point_set_handle(MaskSplinePoint *point, eMaskWhichHandle which_handle, float loc[2], bool keep_direction, float orig_handle[2], float orig_vec[3][3])
MaskLayer * BKE_mask_layer_by_name(Mask *mask, const char *layer_name)
MaskSpline * BKE_mask_spline_add(MaskLayer *masklay)
void BKE_mask_coord_from_movieclip(MovieClip *clip, MovieClipUser *user, float r_co[2], const float co[2])
void MASK_OT_new(wmOperatorType *ot)
Definition mask_ops.cc:156
void WM_menu_name_call(bContext *C, const char *menu_name, wm::OpCallContext context)
MaskLayer * BKE_mask_layer_active(Mask *mask)
@ MASK_SPLINE_CYCLIC
@ MASK_SPLINE_SELECT
void BKE_mask_point_select_set(MaskSplinePoint *point, bool do_select)
void ED_mask_get_size(ScrArea *area, int *r_width, int *r_height)
static void free_slide_point_data(SlidePointData *data)
Definition mask_ops.cc:682
void BKE_mask_spline_move_to_layer(MaskSpline *spline, MaskLayer *src_mask_layer, MaskLayer *dst_mask_layer)
void BKE_mask_point_normal(MaskSpline *spline, MaskSplinePoint *point, float u, float n[2])
void ED_mask_layer_shape_auto_key(const bContext *C, MaskLayer *mask_layer, int frame)
void BKE_mask_clipboard_paste_to_layer(Main *bmain, MaskLayer *mask_layer)
Mask * CTX_data_edit_mask(const bContext *C)
void ED_mask_select_flush_all(Mask *mask)
static void slide_spline_solve_P1(const float u, const float B[2], const float P0[2], const float P2[2], const float P3[2], float solution[2])
Definition mask_ops.cc:1174
void ED_mask_view_lock_state_restore_no_jump(const bContext *C, const MaskViewLockState *state)
Definition mask_edit.cc:217
static bool paste_splines_poll(bContext *C)
Definition mask_ops.cc:2321
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
static wmOperatorStatus mask_normals_make_consistent_exec(bContext *C, wmOperator *)
Definition mask_ops.cc:1656
wmOperatorStatus WM_operator_confirm_ex(bContext *C, wmOperator *op, const char *title, const char *message, const char *confirm_text, ui::AlertIcon icon, bool cancel_default)
static wmOperatorStatus mask_duplicate_exec(bContext *C, wmOperator *)
Definition mask_ops.cc:2155
static VectorSet< StringRef > get_layer_names(Mask *mask)
Definition mask_ops.cc:2084
MINLINE float dot_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
void MASK_OT_normals_make_consistent(wmOperatorType *ot)
Definition mask_ops.cc:1702
static wmOperatorStatus copy_splines_exec(bContext *C, wmOperator *)
Definition mask_ops.cc:2290
bool ED_maskedit_mask_poll(bContext *C)
Definition mask_edit.cc:61
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
bool ED_maskedit_mask_visible_splines_poll(bContext *C)
Definition mask_edit.cc:77
void BLI_insertlinkbefore(ListBase *listbase, void *vnextlink, void *vnewlink) ATTR_NONNULL(1)
Definition listbase.cc:378
static wmOperatorStatus mask_feather_weight_clear_exec(bContext *C, wmOperator *)
Definition mask_ops.cc:1904
static wmOperatorStatus mask_layer_remove_exec(bContext *C, wmOperator *)
Definition mask_ops.cc:212
static void free_slide_spline_curvature_data(SlideSplineCurvatureData *slide_data)
Definition mask_ops.cc:1017
wmOperatorStatus WM_operator_props_popup_confirm_ex(bContext *C, wmOperator *op, const wmEvent *, std::optional< std::string > title, std::optional< std::string > confirm_text, const bool cancel_default, std::optional< std::string > message)
void MASK_OT_paste_splines(wmOperatorType *ot)
Definition mask_ops.cc:2348
static std::string unique_layer_name(Mask *mask, const StringRef name)
Definition mask_ops.cc:2093
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
void ED_mask_layer_select_set(MaskLayer *mask_layer, bool do_select)
Main * CTX_data_main(const bContext *C)
int BKE_mask_layer_shape_spline_to_index(MaskLayer *masklay, MaskSpline *spline)
ATTR_WARN_UNUSED_RESULT const BMVert * v2
static bool mask_move_to_layer_poll(bContext *C)
Definition mask_ops.cc:2038
static wmOperatorStatus paste_splines_exec(bContext *C, wmOperator *)
Definition mask_ops.cc:2330
void interp_v2_v2v2(float r[2], const float a[2], const float b[2], float t)
void MASK_OT_copy_splines(wmOperatorType *ot)
Definition mask_ops.cc:2304
void BKE_mask_point_free(MaskSplinePoint *point)
@ ID_RECALC_SYNC_TO_EVAL
Definition DNA_ID.h:1118
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
static wmOperatorStatus mask_switch_direction_exec(bContext *C, wmOperator *)
Definition mask_ops.cc:1598
@ PROP_SKIP_SAVE
Definition RNA_types.hh:414
@ PROP_HIDDEN
Definition RNA_types.hh:408
static wmOperatorStatus cyclic_toggle_exec(bContext *C, wmOperator *)
Definition mask_ops.cc:1382
MINLINE float square_f(float a)
static wmOperatorStatus slide_point_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition mask_ops.cc:606
void MASK_OT_move_to_layer(wmOperatorType *ot)
Definition mask_ops.cc:2127
void ED_space_image_set_mask(bContext *C, SpaceImage *sima, Mask *mask)
void MASK_OT_handle_type_set(wmOperatorType *ot)
Definition mask_ops.cc:1772
@ KM_RELEASE
Definition WM_types.hh:325
void BKE_id_move_to_same_lib(Main &bmain, ID &id, const ID &owner_id)
Definition lib_id.cc:953
void BKE_mask_layer_free_shapes(MaskLayer *masklay)
Free all animation keys for a mask layer.
void MASK_OT_hide_view_clear(wmOperatorType *ot)
Definition mask_ops.cc:1825
static wmOperatorStatus mask_new_exec(bContext *C, wmOperator *op)
Definition mask_ops.cc:105
Scene * CTX_data_scene(const bContext *C)
static void slide_point_delta_all_feather(SlidePointData *data, float delta)
Definition mask_ops.cc:633
MINLINE void sub_v2_v2(float r[2], const float a[2])
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
static bool mask_layer_move_poll(bContext *C)
Definition mask_ops.cc:1955
static wmOperatorStatus set_handle_type_exec(bContext *C, wmOperator *op)
std::string RNA_string_get(PointerRNA *ptr, const char *name)
MINLINE float len_v2(const float v[2]) ATTR_WARN_UNUSED_RESULT
bool ED_mask_layer_select_check(const MaskLayer *mask_layer)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
MINLINE float len_squared_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
void ED_mask_mouse_pos(ScrArea *area, ARegion *region, const int mval[2], float r_co[2])
Mask * ED_mask_new(bContext *C, const char *name)
Definition mask_ops.cc:55
MaskSplinePoint * BKE_mask_spline_point_array(MaskSpline *spline)
static void slide_point_restore_spline(SlidePointData *data)
Definition mask_ops.cc:644
void BKE_mask_spline_direction_switch(MaskLayer *masklay, MaskSpline *spline)
void MASK_OT_slide_spline_curvature(wmOperatorType *ot)
Definition mask_ops.cc:1364
void id_us_min(ID *id)
Definition lib_id.cc:441
static wmOperatorStatus mask_hide_view_clear_exec(bContext *C, wmOperator *op)
Definition mask_ops.cc:1801
ARegion * CTX_wm_region(const bContext *C)
static void check_sliding_handle_type(MaskSplinePoint *point, eMaskWhichHandle which_handle)
Definition mask_ops.cc:446
static wmOperatorStatus mask_layer_move_exec(bContext *C, wmOperator *op)
Definition mask_ops.cc:1966
void BKE_mask_layer_remove(Mask *mask, MaskLayer *masklay)
void BKE_mask_point_segment_co(MaskSpline *spline, MaskSplinePoint *point, float u, float co[2])
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
static bool mask_new_poll(bContext *C)
Definition mask_ops.cc:143
void BKE_mask_layer_shape_changed_add(MaskLayer *masklay, int index, bool do_init, bool do_init_interpolate)
static SlideSplineCurvatureData * slide_spline_curvature_customdata(bContext *C, const wmEvent *event)
Definition mask_ops.cc:1043
float BKE_mask_spline_project_co(MaskSpline *spline, MaskSplinePoint *point, float start_u, const float co[2], eMaskSign sign)
MINLINE void madd_v2_v2v2fl(float r[2], const float a[2], const float b[2], float f)
void BKE_mask_calc_handle_point_auto(MaskSpline *spline, MaskSplinePoint *point, bool do_recalc_length)
Resets auto handles even for non-auto bezier points.
static void delete_feather_points(MaskSplinePoint *point)
Definition mask_ops.cc:1421
void MASK_OT_layer_new(wmOperatorType *ot)
Definition mask_ops.cc:192
static SlidePointData * slide_point_customdata(bContext *C, wmOperator *op, const wmEvent *event)
Definition mask_ops.cc:470
bool ED_mask_find_nearest_diff_point(const bContext *C, Mask *mask_orig, const float normal_co[2], int threshold, bool feather, float tangent[2], bool use_deform, bool use_project, MaskLayer **r_mask_layer, MaskSpline **r_spline, MaskSplinePoint **r_point, float *r_u, float *r_score)
Definition mask_query.cc:37
bool ED_mask_feather_find_nearest(const bContext *C, Mask *mask_orig, const float normal_co[2], float threshold, MaskLayer **r_mask_layer, MaskSpline **r_spline, MaskSplinePoint **r_point, MaskSplinePointUW **r_uw, float *r_score)
#define min(a, b)
Definition sort.cc:38
eBezTriple_Flag f2
eBezTriple_Handle h2
eBezTriple_Flag f3
eBezTriple_Flag f1
eBezTriple_Handle h1
struct MaskSplinePoint * act_point
struct MaskSpline * act_spline
ListBaseT< MaskLayerShape > splines_shapes
MaskLayerVisibility visibility_flag
struct MaskLayer * prev
ListBaseT< MaskSpline > splines
struct MaskLayer * next
MaskSplinePointUW * uw
MaskSplineInterp weight_interp
MaskSplinePoint * points
struct MaskSpline * next
MaskSplineFlag flag
MaskSplineOffset offset_mode
ListBaseT< struct MaskLayer > masklayers
eMovieClipProxy_RenderFlag render_flag
struct RenderData r
ListBaseT< SpaceLink > spacedata
eBezTriple_Handle old_h2
Definition mask_ops.cc:279
eMaskWhichHandle which_handle
Definition mask_ops.cc:261
MaskSplinePoint * point
Definition mask_ops.cc:259
MaskSplinePointUW * uw
Definition mask_ops.cc:260
eBezTriple_Handle old_h1
Definition mask_ops.cc:279
MaskSpline * orig_spline
Definition mask_ops.cc:258
struct MovieClip * clip
struct MovieClipUser user
wmEventType type
Definition WM_types.hh:817
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
wmOperatorStatus(*) modal(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1157