a254a6a9278a18f085ae3c1a8816eb4017adb636
[blender.git] / source / blender / editors / mask / mask_add.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2012 Blender Foundation.
19  * All rights reserved.
20  *
21  *
22  * Contributor(s): Blender Foundation,
23  *                 Sergey Sharybin
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  */
27
28 /** \file blender/editors/mask/mask_add.c
29  *  \ingroup edmask
30  */
31
32 #include "MEM_guardedalloc.h"
33
34 #include "BLI_math.h"
35
36 #include "BKE_context.h"
37 #include "BKE_depsgraph.h"
38 #include "BKE_mask.h"
39
40 #include "DNA_scene_types.h"
41 #include "DNA_screen_types.h"
42 #include "DNA_mask_types.h"
43 #include "DNA_object_types.h"  /* SELECT */
44
45 #include "WM_api.h"
46 #include "WM_types.h"
47
48 #include "ED_mask.h"  /* own include */
49
50 #include "RNA_access.h"
51 #include "RNA_define.h"
52
53 #include "mask_intern.h"  /* own include */
54
55
56 static int find_nearest_diff_point(const bContext *C, Mask *mask, const float normal_co[2], int threshold, int feather,
57                                    MaskLayer **masklay_r, MaskSpline **spline_r, MaskSplinePoint **point_r,
58                                    float *u_r, float tangent[2],
59                                    const short use_deform)
60 {
61         ScrArea *sa = CTX_wm_area(C);
62         ARegion *ar = CTX_wm_region(C);
63
64         MaskLayer *masklay, *point_masklay;
65         MaskSpline *point_spline;
66         MaskSplinePoint *point = NULL;
67         float dist = FLT_MAX, co[2];
68         int width, height;
69         float u;
70         float scalex, scaley;
71
72         ED_mask_get_size(sa, &width, &height);
73         ED_mask_pixelspace_factor(sa, ar, &scalex, &scaley);
74
75         co[0] = normal_co[0] * scalex;
76         co[1] = normal_co[1] * scaley;
77
78         for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) {
79                 MaskSpline *spline;
80
81                 if (masklay->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) {
82                         continue;
83                 }
84
85                 for (spline = masklay->splines.first; spline; spline = spline->next) {
86                         int i;
87                         MaskSplinePoint *cur_point;
88
89                         for (i = 0, cur_point = use_deform ? spline->points_deform : spline->points;
90                              i < spline->tot_point;
91                              i++, cur_point++)
92                         {
93                                 float *diff_points;
94                                 unsigned int tot_diff_point;
95
96                                 diff_points = BKE_mask_point_segment_diff_with_resolution(spline, cur_point, width, height,
97                                                                                           &tot_diff_point);
98
99                                 if (diff_points) {
100                                         int i, tot_point;
101                                         unsigned int tot_feather_point;
102                                         float *feather_points = NULL, *points;
103
104                                         if (feather) {
105                                                 feather_points = BKE_mask_point_segment_feather_diff_with_resolution(spline, cur_point,
106                                                                                                                      width, height,
107                                                                                                                      &tot_feather_point);
108
109                                                 points = feather_points;
110                                                 tot_point = tot_feather_point;
111                                         }
112                                         else {
113                                                 points = diff_points;
114                                                 tot_point = tot_diff_point;
115                                         }
116
117                                         for (i = 0; i < tot_point - 1; i++) {
118                                                 float cur_dist, a[2], b[2];
119
120                                                 a[0] = points[2 * i] * scalex;
121                                                 a[1] = points[2 * i + 1] * scaley;
122
123                                                 b[0] = points[2 * i + 2] * scalex;
124                                                 b[1] = points[2 * i + 3] * scaley;
125
126                                                 cur_dist = dist_to_line_segment_v2(co, a, b);
127
128                                                 if (cur_dist < dist) {
129                                                         if (tangent)
130                                                                 sub_v2_v2v2(tangent, &diff_points[2 * i + 2], &diff_points[2 * i]);
131
132                                                         point_masklay = masklay;
133                                                         point_spline = spline;
134                                                         point = use_deform ? &spline->points[(cur_point - spline->points_deform)] : cur_point;
135                                                         dist = cur_dist;
136                                                         u = (float)i / tot_point;
137
138                                                 }
139                                         }
140
141                                         if (feather_points)
142                                                 MEM_freeN(feather_points);
143
144                                         MEM_freeN(diff_points);
145                                 }
146                         }
147                 }
148         }
149
150         if (point && dist < threshold) {
151                 if (masklay_r)
152                         *masklay_r = point_masklay;
153
154                 if (spline_r)
155                         *spline_r = point_spline;
156
157                 if (point_r)
158                         *point_r = point;
159
160                 if (u_r) {
161                         u = BKE_mask_spline_project_co(point_spline, point, u, normal_co, MASK_PROJ_ANY);
162
163                         *u_r = u;
164                 }
165
166                 return TRUE;
167         }
168
169         if (masklay_r)
170                 *masklay_r = NULL;
171
172         if (spline_r)
173                 *spline_r = NULL;
174
175         if (point_r)
176                 *point_r = NULL;
177
178         return FALSE;
179 }
180
181 /******************** add vertex *********************/
182
183 static void setup_vertex_point(Mask *mask, MaskSpline *spline, MaskSplinePoint *new_point,
184                                const float point_co[2], const float tangent[2], const float u,
185                                MaskSplinePoint *reference_point, const short reference_adjacent,
186                                const float view_zoom)
187 {
188         MaskSplinePoint *prev_point = NULL;
189         MaskSplinePoint *next_point = NULL;
190         BezTriple *bezt;
191         float co[3];
192         const float len = 10.0; /* default length of handle in pixel space */
193
194         copy_v2_v2(co, point_co);
195         co[2] = 0.0f;
196
197         /* point coordinate */
198         bezt = &new_point->bezt;
199
200         bezt->h1 = bezt->h2 = HD_ALIGN;
201
202         if (reference_point) {
203                 bezt->h1 = bezt->h2 = MAX2(reference_point->bezt.h2, reference_point->bezt.h1);
204         }
205         else if (reference_adjacent) {
206                 if (spline->tot_point != 1) {
207                         int index = (int)(new_point - spline->points);
208                         prev_point = &spline->points[(index - 1) % spline->tot_point];
209                         next_point = &spline->points[(index + 1) % spline->tot_point];
210
211                         bezt->h1 = bezt->h2 = MAX2(prev_point->bezt.h2, next_point->bezt.h1);
212
213                         /* note, we may want to copy other attributes later, radius? pressure? color? */
214                 }
215         }
216
217         copy_v3_v3(bezt->vec[0], co);
218         copy_v3_v3(bezt->vec[1], co);
219         copy_v3_v3(bezt->vec[2], co);
220
221         /* initial offset for handles */
222         if (spline->tot_point == 1) {
223                 /* first point of splien is aligned horizontally */
224                 bezt->vec[0][0] -= len * view_zoom;
225                 bezt->vec[2][0] += len * view_zoom;
226         }
227         else if (tangent) {
228                 float vec[2];
229
230                 copy_v2_v2(vec, tangent);
231
232                 mul_v2_fl(vec, len);
233
234                 sub_v2_v2(bezt->vec[0], vec);
235                 add_v2_v2(bezt->vec[2], vec);
236
237                 if (reference_adjacent) {
238                         BKE_mask_calc_handle_adjacent_interp(spline, new_point, u);
239                 }
240         }
241         else {
242
243                 /* calculating auto handles works much nicer */
244 #if 0
245                 /* next points are aligning in the direction of previous/next point */
246                 MaskSplinePoint *point;
247                 float v1[2], v2[2], vec[2];
248                 float dir = 1.0f;
249
250                 if (new_point == spline->points) {
251                         point = new_point + 1;
252                         dir = -1.0f;
253                 }
254                 else
255                         point = new_point - 1;
256
257                 if (spline->tot_point < 3) {
258                         v1[0] = point->bezt.vec[1][0] * width;
259                         v1[1] = point->bezt.vec[1][1] * height;
260
261                         v2[0] = new_point->bezt.vec[1][0] * width;
262                         v2[1] = new_point->bezt.vec[1][1] * height;
263                 }
264                 else {
265                         if (new_point == spline->points) {
266                                 v1[0] = spline->points[1].bezt.vec[1][0] * width;
267                                 v1[1] = spline->points[1].bezt.vec[1][1] * height;
268
269                                 v2[0] = spline->points[spline->tot_point - 1].bezt.vec[1][0] * width;
270                                 v2[1] = spline->points[spline->tot_point - 1].bezt.vec[1][1] * height;
271                         }
272                         else {
273                                 v1[0] = spline->points[0].bezt.vec[1][0] * width;
274                                 v1[1] = spline->points[0].bezt.vec[1][1] * height;
275
276                                 v2[0] = spline->points[spline->tot_point - 2].bezt.vec[1][0] * width;
277                                 v2[1] = spline->points[spline->tot_point - 2].bezt.vec[1][1] * height;
278                         }
279                 }
280
281                 sub_v2_v2v2(vec, v1, v2);
282                 mul_v2_fl(vec, len * dir / len_v2(vec));
283
284                 vec[0] /= width;
285                 vec[1] /= height;
286
287                 add_v2_v2(bezt->vec[0], vec);
288                 sub_v2_v2(bezt->vec[2], vec);
289 #else
290                 BKE_mask_calc_handle_point_auto(spline, new_point, TRUE);
291                 BKE_mask_calc_handle_adjacent_interp(spline, new_point, u);
292
293 #endif
294         }
295
296         BKE_mask_parent_init(&new_point->parent);
297
298         /* select new point */
299         MASKPOINT_SEL_ALL(new_point);
300         ED_mask_select_flush_all(mask);
301 }
302
303
304 /* **** add extrude vertex **** */
305
306 static void finSelectedSplinePoint(MaskLayer *masklay, MaskSpline **spline, MaskSplinePoint **point, short check_active)
307 {
308         MaskSpline *cur_spline = masklay->splines.first;
309
310         *spline = NULL;
311         *point = NULL;
312
313         if (check_active) {
314                 /* TODO, having an active point but no active spline is possible, why? */
315                 if (masklay->act_spline && masklay->act_point && MASKPOINT_ISSEL_ANY(masklay->act_point)) {
316                         *spline = masklay->act_spline;
317                         *point = masklay->act_point;
318                         return;
319                 }
320         }
321
322         while (cur_spline) {
323                 int i;
324
325                 for (i = 0; i < cur_spline->tot_point; i++) {
326                         MaskSplinePoint *cur_point = &cur_spline->points[i];
327
328                         if (MASKPOINT_ISSEL_ANY(cur_point)) {
329                                 if (*spline != NULL && *spline != cur_spline) {
330                                         *spline = NULL;
331                                         *point = NULL;
332                                         return;
333                                 }
334                                 else if (*point) {
335                                         *point = NULL;
336                                 }
337                                 else {
338                                         *spline = cur_spline;
339                                         *point = cur_point;
340                                 }
341                         }
342                 }
343
344                 cur_spline = cur_spline->next;
345         }
346 }
347
348 /* **** add subdivide vertex **** */
349
350 static void mask_spline_add_point_at_index(MaskSpline *spline, int point_index)
351 {
352         MaskSplinePoint *new_point_array;
353
354         new_point_array = MEM_callocN(sizeof(MaskSplinePoint) * (spline->tot_point + 1), "add mask vert points");
355
356         memcpy(new_point_array, spline->points, sizeof(MaskSplinePoint) * (point_index + 1));
357         memcpy(new_point_array + point_index + 2, spline->points + point_index + 1,
358                sizeof(MaskSplinePoint) * (spline->tot_point - point_index - 1));
359
360         MEM_freeN(spline->points);
361         spline->points = new_point_array;
362         spline->tot_point++;
363 }
364
365 static int add_vertex_subdivide(const bContext *C, Mask *mask, const float co[2])
366 {
367         MaskLayer *masklay;
368         MaskSpline *spline;
369         MaskSplinePoint *point = NULL;
370         const float threshold = 9;
371         float tangent[2];
372         float u;
373
374         if (find_nearest_diff_point(C, mask, co, threshold, FALSE, &masklay, &spline, &point, &u, tangent, TRUE)) {
375                 MaskSplinePoint *new_point;
376                 int point_index = point - spline->points;
377
378                 ED_mask_select_toggle_all(mask, SEL_DESELECT);
379
380                 mask_spline_add_point_at_index(spline, point_index);
381
382                 new_point = &spline->points[point_index + 1];
383
384                 setup_vertex_point(mask, spline, new_point, co, tangent, u, NULL, TRUE, 1.0f);
385
386                 /* TODO - we could pass the spline! */
387                 BKE_mask_layer_shape_changed_add(masklay, BKE_mask_layer_shape_spline_to_index(masklay, spline) + point_index + 1, TRUE, TRUE);
388
389                 masklay->act_point = new_point;
390
391                 WM_event_add_notifier(C, NC_MASK | NA_EDITED, mask);
392
393                 return TRUE;
394         }
395
396         return FALSE;
397 }
398
399 static int add_vertex_extrude(const bContext *C, Mask *mask, MaskLayer *masklay, const float co[2])
400 {
401         MaskSpline *spline;
402         MaskSplinePoint *point;
403         MaskSplinePoint *new_point = NULL, *ref_point = NULL;
404
405         /* check on which side we want to add the point */
406         int point_index;
407         float tangent_point[2];
408         float tangent_co[2];
409         int do_cyclic_correct = FALSE;
410         int do_recalc_src = FALSE;  /* when extruding from endpoints only */
411         int do_prev;                /* use prev point rather then next?? */
412
413         if (!masklay) {
414                 return FALSE;
415         }
416         else {
417                 finSelectedSplinePoint(masklay, &spline, &point, TRUE);
418         }
419
420         ED_mask_select_toggle_all(mask, SEL_DESELECT);
421
422         point_index = (point - spline->points);
423
424         MASKPOINT_DESEL_ALL(point);
425
426         if ((spline->flag & MASK_SPLINE_CYCLIC) ||
427             (point_index > 0 && point_index != spline->tot_point - 1))
428         {
429                 BKE_mask_calc_tangent_polyline(spline, point, tangent_point);
430                 sub_v2_v2v2(tangent_co, co, point->bezt.vec[1]);
431
432                 if (dot_v2v2(tangent_point, tangent_co) < 0.0f) {
433                         do_prev = TRUE;
434                 }
435                 else {
436                         do_prev = FALSE;
437                 }
438         }
439         else if (((spline->flag & MASK_SPLINE_CYCLIC) == 0) && (point_index == 0)) {
440                 do_prev = TRUE;
441                 do_recalc_src = TRUE;
442         }
443         else if (((spline->flag & MASK_SPLINE_CYCLIC) == 0) && (point_index == spline->tot_point - 1)) {
444                 do_prev = FALSE;
445                 do_recalc_src = TRUE;
446         }
447         else {
448                 do_prev = FALSE;  /* quiet warning */
449                 /* should never get here */
450                 BLI_assert(0);
451         }
452
453         /* use the point before the active one */
454         if (do_prev) {
455                 point_index--;
456                 if (point_index < 0) {
457                         point_index += spline->tot_point; /* wrap index */
458                         if ((spline->flag & MASK_SPLINE_CYCLIC) == 0) {
459                                 do_cyclic_correct = TRUE;
460                                 point_index = 0;
461                         }
462                 }
463         }
464
465 //              print_v2("", tangent_point);
466 //              printf("%d\n", point_index);
467
468         mask_spline_add_point_at_index(spline, point_index);
469
470         if (do_cyclic_correct) {
471                 ref_point = &spline->points[point_index + 1];
472                 new_point = &spline->points[point_index];
473                 *ref_point = *new_point;
474                 memset(new_point, 0, sizeof(*new_point));
475         }
476         else {
477                 ref_point = &spline->points[point_index];
478                 new_point = &spline->points[point_index + 1];
479         }
480
481         masklay->act_point = new_point;
482
483         setup_vertex_point(mask, spline, new_point, co, NULL, 0.5f, ref_point, FALSE, 1.0f);
484
485         if (masklay->splines_shapes.first) {
486                 point_index = (((int)(new_point - spline->points) + 0) % spline->tot_point);
487                 BKE_mask_layer_shape_changed_add(masklay, BKE_mask_layer_shape_spline_to_index(masklay, spline) + point_index, TRUE, TRUE);
488         }
489
490         if (do_recalc_src) {
491                 /* TODO, update keyframes in time */
492                 BKE_mask_calc_handle_point_auto(spline, ref_point, FALSE);
493         }
494
495         WM_event_add_notifier(C, NC_MASK | NA_EDITED, mask);
496
497         return TRUE;
498 }
499
500 static int add_vertex_new(const bContext *C, Mask *mask, MaskLayer *masklay, const float co[2])
501 {
502         MaskSpline *spline;
503         MaskSplinePoint *point;
504         MaskSplinePoint *new_point = NULL, *ref_point = NULL;
505         float view_zoom;
506
507         if (!masklay) {
508                 /* if there's no masklay currently operationg on, create new one */
509                 masklay = BKE_mask_layer_new(mask, "");
510                 mask->masklay_act = mask->masklay_tot - 1;
511                 spline = NULL;
512                 point = NULL;
513         }
514         else {
515                 finSelectedSplinePoint(masklay, &spline, &point, TRUE);
516         }
517
518         ED_mask_select_toggle_all(mask, SEL_DESELECT);
519
520         if (!spline) {
521                 /* no selected splines in active masklay, create new spline */
522                 spline = BKE_mask_spline_add(masklay);
523         }
524
525         masklay->act_spline = spline;
526         new_point = spline->points;
527
528         masklay->act_point = new_point;
529
530         {
531                 ScrArea *sa = CTX_wm_area(C);
532                 ARegion *ar = CTX_wm_region(C);
533
534                 float zoom_x, zoom_y;
535                 /* calc view zoom in a simplistic way */
536                 ED_mask_zoom(sa, ar, &zoom_x, &zoom_y);
537
538                 view_zoom = zoom_x + zoom_y / 2.0f;
539                 view_zoom = 1.0f / view_zoom;
540
541                 /* arbitrary but gives good results */
542                 view_zoom /= 500.0f;
543         }
544
545         setup_vertex_point(mask, spline, new_point, co, NULL, 0.5f, ref_point, FALSE, view_zoom);
546
547         {
548                 int point_index = (((int)(new_point - spline->points) + 0) % spline->tot_point);
549                 BKE_mask_layer_shape_changed_add(masklay, BKE_mask_layer_shape_spline_to_index(masklay, spline) + point_index, TRUE, TRUE);
550         }
551
552         WM_event_add_notifier(C, NC_MASK | NA_EDITED, mask);
553
554         return TRUE;
555 }
556
557 static int add_vertex_exec(bContext *C, wmOperator *op)
558 {
559         Scene *scene = CTX_data_scene(C);
560         Mask *mask = CTX_data_edit_mask(C);
561         MaskLayer *masklay;
562
563         float co[2];
564
565         masklay = BKE_mask_layer_active(mask);
566
567         if (masklay && masklay->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) {
568                 masklay = NULL;
569         }
570
571         RNA_float_get_array(op->ptr, "location", co);
572
573         /* TODO, having an active point but no active spline is possible, why? */
574         if (masklay && masklay->act_spline && masklay->act_point && MASKPOINT_ISSEL_ANY(masklay->act_point)) {
575
576                 /* cheap trick - double click for cyclic */
577                 MaskSpline *spline = masklay->act_spline;
578                 MaskSplinePoint *point = masklay->act_point;
579
580                 int is_sta = (point == spline->points);
581                 int is_end = (point == &spline->points[spline->tot_point - 1]);
582
583                 /* then check are we overlapping the mouse */
584                 if ((is_sta || is_end) && equals_v2v2(co, point->bezt.vec[1])) {
585                         if (spline->flag & MASK_SPLINE_CYCLIC) {
586                                 /* nothing to do */
587                                 return OPERATOR_CANCELLED;
588                         }
589                         else {
590                                 /* recalc the connecting point as well to make a nice even curve */
591                                 MaskSplinePoint *point_other = is_end ? spline->points : &spline->points[spline->tot_point - 1];
592                                 spline->flag |= MASK_SPLINE_CYCLIC;
593
594                                 /* TODO, update keyframes in time */
595                                 BKE_mask_calc_handle_point_auto(spline, point, FALSE);
596                                 BKE_mask_calc_handle_point_auto(spline, point_other, FALSE);
597
598                                 /* TODO: only update this spline */
599                                 BKE_mask_update_display(mask, CFRA);
600
601                                 WM_event_add_notifier(C, NC_MASK | NA_EDITED, mask);
602                                 return OPERATOR_FINISHED;
603                         }
604                 }
605
606                 if (!add_vertex_subdivide(C, mask, co)) {
607                         if (!add_vertex_extrude(C, mask, masklay, co)) {
608                                 return OPERATOR_CANCELLED;
609                         }
610                 }
611         }
612         else {
613                 if (!add_vertex_subdivide(C, mask, co)) {
614                         if (!add_vertex_new(C, mask, masklay, co)) {
615                                 return OPERATOR_CANCELLED;
616                         }
617                 }
618         }
619
620         /* TODO: only update this spline */
621         BKE_mask_update_display(mask, CFRA);
622
623         return OPERATOR_FINISHED;
624 }
625
626 static int add_vertex_invoke(bContext *C, wmOperator *op, wmEvent *event)
627 {
628         ScrArea *sa = CTX_wm_area(C);
629         ARegion *ar = CTX_wm_region(C);
630
631         float co[2];
632
633         ED_mask_mouse_pos(sa, ar, event->mval, co);
634
635         RNA_float_set_array(op->ptr, "location", co);
636
637         return add_vertex_exec(C, op);
638 }
639
640 void MASK_OT_add_vertex(wmOperatorType *ot)
641 {
642         /* identifiers */
643         ot->name = "Add Vertex";
644         ot->description = "Add vertex to active spline";
645         ot->idname = "MASK_OT_add_vertex";
646
647         /* api callbacks */
648         ot->exec = add_vertex_exec;
649         ot->invoke = add_vertex_invoke;
650         ot->poll = ED_maskedit_mask_poll;
651
652         /* flags */
653         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
654
655         /* properties */
656         RNA_def_float_vector(ot->srna, "location", 2, NULL, -FLT_MAX, FLT_MAX,
657                              "Location", "Location of vertex in normalized space", -1.0f, 1.0f);
658 }
659
660 /******************** add feather vertex *********************/
661
662 static int add_feather_vertex_exec(bContext *C, wmOperator *op)
663 {
664         Mask *mask = CTX_data_edit_mask(C);
665         MaskLayer *masklay;
666         MaskSpline *spline;
667         MaskSplinePoint *point = NULL;
668         const float threshold = 9;
669         float co[2], u;
670
671         RNA_float_get_array(op->ptr, "location", co);
672
673         point = ED_mask_point_find_nearest(C, mask, co, threshold, NULL, NULL, NULL, NULL);
674         if (point)
675                 return OPERATOR_FINISHED;
676
677         if (find_nearest_diff_point(C, mask, co, threshold, TRUE, &masklay, &spline, &point, &u, NULL, TRUE)) {
678                 Scene *scene = CTX_data_scene(C);
679                 float w = BKE_mask_point_weight(spline, point, u);
680                 float weight_scalar = BKE_mask_point_weight_scalar(spline, point, u);
681
682                 if (weight_scalar != 0.0f) {
683                         w = w / weight_scalar;
684                 }
685
686                 BKE_mask_point_add_uw(point, u, w);
687
688                 BKE_mask_update_display(mask, scene->r.cfra);
689
690                 WM_event_add_notifier(C, NC_MASK | NA_EDITED, mask);
691
692                 DAG_id_tag_update(&mask->id, 0);
693
694                 return OPERATOR_FINISHED;
695         }
696
697         return OPERATOR_CANCELLED;
698 }
699
700 static int add_feather_vertex_invoke(bContext *C, wmOperator *op, wmEvent *event)
701 {
702         ScrArea *sa = CTX_wm_area(C);
703         ARegion *ar = CTX_wm_region(C);
704
705         float co[2];
706
707         ED_mask_mouse_pos(sa, ar, event->mval, co);
708
709         RNA_float_set_array(op->ptr, "location", co);
710
711         return add_feather_vertex_exec(C, op);
712 }
713
714 void MASK_OT_add_feather_vertex(wmOperatorType *ot)
715 {
716         /* identifiers */
717         ot->name = "Add feather Vertex";
718         ot->description = "Add vertex to feather";
719         ot->idname = "MASK_OT_add_feather_vertex";
720
721         /* api callbacks */
722         ot->exec = add_feather_vertex_exec;
723         ot->invoke = add_feather_vertex_invoke;
724         ot->poll = ED_maskedit_mask_poll;
725
726         /* flags */
727         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
728
729         /* properties */
730         RNA_def_float_vector(ot->srna, "location", 2, NULL, -FLT_MAX, FLT_MAX,
731                              "Location", "Location of vertex in normalized space", -1.0f, 1.0f);
732 }