fix for crash when mask editing if there is an active point but no active spline.
[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, 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 (point == NULL || 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(const bContext *C, 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 {
187         ScrArea *sa = CTX_wm_area(C);
188
189         MaskSplinePoint *prev_point = NULL;
190         MaskSplinePoint *next_point = NULL;
191         BezTriple *bezt;
192         int width, height;
193         float co[3];
194         const float len = 20.0; /* default length of handle in pixel space */
195
196         copy_v2_v2(co, point_co);
197         co[2] = 0.0f;
198
199         ED_mask_get_size(sa, &width, &height);
200
201         /* point coordinate */
202         bezt = &new_point->bezt;
203
204         bezt->h1 = bezt->h2 = HD_ALIGN;
205
206         if (reference_point) {
207                 bezt->h1 = bezt->h2 = MAX2(reference_point->bezt.h2, reference_point->bezt.h1);
208         }
209         else if (reference_adjacent) {
210                 if (spline->tot_point != 1) {
211                         int index = (int)(new_point - spline->points);
212                         prev_point = &spline->points[(index - 1) % spline->tot_point];
213                         next_point = &spline->points[(index + 1) % spline->tot_point];
214
215                         bezt->h1 = bezt->h2 = MAX2(prev_point->bezt.h2, next_point->bezt.h1);
216
217                         /* note, we may want to copy other attributes later, radius? pressure? color? */
218                 }
219         }
220
221         copy_v3_v3(bezt->vec[0], co);
222         copy_v3_v3(bezt->vec[1], co);
223         copy_v3_v3(bezt->vec[2], co);
224
225         /* initial offset for handles */
226         if (spline->tot_point == 1) {
227                 /* first point of splien is aligned horizontally */
228                 bezt->vec[0][0] -= len / width;
229                 bezt->vec[2][0] += len / width;
230         }
231         else if (tangent) {
232                 float vec[2];
233
234                 copy_v2_v2(vec, tangent);
235
236                 vec[0] *= width;
237                 vec[1] *= height;
238
239                 mul_v2_fl(vec, len / len_v2(vec));
240
241                 vec[0] /= width;
242                 vec[1] /= height;
243
244                 sub_v2_v2(bezt->vec[0], vec);
245                 add_v2_v2(bezt->vec[2], vec);
246
247                 if (reference_adjacent) {
248                         BKE_mask_calc_handle_adjacent_interp(spline, new_point, u);
249                 }
250         }
251         else {
252
253                 /* calculating auto handles works much nicer */
254 #if 0
255                 /* next points are aligning in the direction of previous/next point */
256                 MaskSplinePoint *point;
257                 float v1[2], v2[2], vec[2];
258                 float dir = 1.0f;
259
260                 if (new_point == spline->points) {
261                         point = new_point + 1;
262                         dir = -1.0f;
263                 }
264                 else
265                         point = new_point - 1;
266
267                 if (spline->tot_point < 3) {
268                         v1[0] = point->bezt.vec[1][0] * width;
269                         v1[1] = point->bezt.vec[1][1] * height;
270
271                         v2[0] = new_point->bezt.vec[1][0] * width;
272                         v2[1] = new_point->bezt.vec[1][1] * height;
273                 }
274                 else {
275                         if (new_point == spline->points) {
276                                 v1[0] = spline->points[1].bezt.vec[1][0] * width;
277                                 v1[1] = spline->points[1].bezt.vec[1][1] * height;
278
279                                 v2[0] = spline->points[spline->tot_point - 1].bezt.vec[1][0] * width;
280                                 v2[1] = spline->points[spline->tot_point - 1].bezt.vec[1][1] * height;
281                         }
282                         else {
283                                 v1[0] = spline->points[0].bezt.vec[1][0] * width;
284                                 v1[1] = spline->points[0].bezt.vec[1][1] * height;
285
286                                 v2[0] = spline->points[spline->tot_point - 2].bezt.vec[1][0] * width;
287                                 v2[1] = spline->points[spline->tot_point - 2].bezt.vec[1][1] * height;
288                         }
289                 }
290
291                 sub_v2_v2v2(vec, v1, v2);
292                 mul_v2_fl(vec, len * dir / len_v2(vec));
293
294                 vec[0] /= width;
295                 vec[1] /= height;
296
297                 add_v2_v2(bezt->vec[0], vec);
298                 sub_v2_v2(bezt->vec[2], vec);
299 #else
300                 BKE_mask_calc_handle_point_auto(spline, new_point, TRUE);
301                 BKE_mask_calc_handle_adjacent_interp(spline, new_point, u);
302
303 #endif
304         }
305
306         BKE_mask_parent_init(&new_point->parent);
307
308         /* select new point */
309         MASKPOINT_SEL_ALL(new_point);
310         ED_mask_select_flush_all(mask);
311 }
312
313
314 /* **** add extrude vertex **** */
315
316 static void finSelectedSplinePoint(MaskLayer *masklay, MaskSpline **spline, MaskSplinePoint **point, short check_active)
317 {
318         MaskSpline *cur_spline = masklay->splines.first;
319
320         *spline = NULL;
321         *point = NULL;
322
323         if (check_active) {
324                 /* TODO, having an active point but no active spline is possible, why? */
325                 if (masklay->act_spline && masklay->act_point && MASKPOINT_ISSEL_ANY(masklay->act_point)) {
326                         *spline = masklay->act_spline;
327                         *point = masklay->act_point;
328                         return;
329                 }
330         }
331
332         while (cur_spline) {
333                 int i;
334
335                 for (i = 0; i < cur_spline->tot_point; i++) {
336                         MaskSplinePoint *cur_point = &cur_spline->points[i];
337
338                         if (MASKPOINT_ISSEL_ANY(cur_point)) {
339                                 if (*spline != NULL && *spline != cur_spline) {
340                                         *spline = NULL;
341                                         *point = NULL;
342                                         return;
343                                 }
344                                 else if (*point) {
345                                         *point = NULL;
346                                 }
347                                 else {
348                                         *spline = cur_spline;
349                                         *point = cur_point;
350                                 }
351                         }
352                 }
353
354                 cur_spline = cur_spline->next;
355         }
356 }
357
358 /* **** add subdivide vertex **** */
359
360 static void mask_spline_add_point_at_index(MaskSpline *spline, int point_index)
361 {
362         MaskSplinePoint *new_point_array;
363
364         new_point_array = MEM_callocN(sizeof(MaskSplinePoint) * (spline->tot_point + 1), "add mask vert points");
365
366         memcpy(new_point_array, spline->points, sizeof(MaskSplinePoint) * (point_index + 1));
367         memcpy(new_point_array + point_index + 2, spline->points + point_index + 1,
368                sizeof(MaskSplinePoint) * (spline->tot_point - point_index - 1));
369
370         MEM_freeN(spline->points);
371         spline->points = new_point_array;
372         spline->tot_point++;
373 }
374
375 static int add_vertex_subdivide(const bContext *C, Mask *mask, const float co[2])
376 {
377         MaskLayer *masklay;
378         MaskSpline *spline;
379         MaskSplinePoint *point = NULL;
380         const float threshold = 9;
381         float tangent[2];
382         float u;
383
384         if (find_nearest_diff_point(C, mask, co, threshold, FALSE, &masklay, &spline, &point, &u, tangent, TRUE)) {
385                 MaskSplinePoint *new_point;
386                 int point_index = point - spline->points;
387
388                 ED_mask_select_toggle_all(mask, SEL_DESELECT);
389
390                 mask_spline_add_point_at_index(spline, point_index);
391
392                 new_point = &spline->points[point_index + 1];
393
394                 setup_vertex_point(C, mask, spline, new_point, co, tangent, u, NULL, TRUE);
395
396                 /* TODO - we could pass the spline! */
397                 BKE_mask_layer_shape_changed_add(masklay, BKE_mask_layer_shape_spline_to_index(masklay, spline) + point_index + 1, TRUE, TRUE);
398
399                 masklay->act_point = new_point;
400
401                 WM_event_add_notifier(C, NC_MASK | NA_EDITED, mask);
402
403                 return TRUE;
404         }
405
406         return FALSE;
407 }
408
409 static int add_vertex_extrude(const bContext *C, Mask *mask, MaskLayer *masklay, const float co[2])
410 {
411         MaskSpline *spline;
412         MaskSplinePoint *point;
413         MaskSplinePoint *new_point = NULL, *ref_point = NULL;
414
415         /* check on which side we want to add the point */
416         int point_index;
417         float tangent_point[2];
418         float tangent_co[2];
419         int do_cyclic_correct = FALSE;
420         int do_recalc_src = FALSE;  /* when extruding from endpoints only */
421         int do_prev;                /* use prev point rather then next?? */
422
423         if (!masklay) {
424                 return FALSE;
425         }
426         else {
427                 finSelectedSplinePoint(masklay, &spline, &point, TRUE);
428         }
429
430         ED_mask_select_toggle_all(mask, SEL_DESELECT);
431
432         point_index = (point - spline->points);
433
434         MASKPOINT_DESEL_ALL(point);
435
436         if ((spline->flag & MASK_SPLINE_CYCLIC) ||
437             (point_index > 0 && point_index != spline->tot_point - 1))
438         {
439                 BKE_mask_calc_tangent_polyline(spline, point, tangent_point);
440                 sub_v2_v2v2(tangent_co, co, point->bezt.vec[1]);
441
442                 if (dot_v2v2(tangent_point, tangent_co) < 0.0f) {
443                         do_prev = TRUE;
444                 }
445                 else {
446                         do_prev = FALSE;
447                 }
448         }
449         else if (((spline->flag & MASK_SPLINE_CYCLIC) == 0) && (point_index == 0)) {
450                 do_prev = TRUE;
451                 do_recalc_src = TRUE;
452         }
453         else if (((spline->flag & MASK_SPLINE_CYCLIC) == 0) && (point_index == spline->tot_point - 1)) {
454                 do_prev = FALSE;
455                 do_recalc_src = TRUE;
456         }
457         else {
458                 do_prev = FALSE;  /* quiet warning */
459                 /* should never get here */
460                 BLI_assert(0);
461         }
462
463         /* use the point before the active one */
464         if (do_prev) {
465                 point_index--;
466                 if (point_index < 0) {
467                         point_index += spline->tot_point; /* wrap index */
468                         if ((spline->flag & MASK_SPLINE_CYCLIC) == 0) {
469                                 do_cyclic_correct = TRUE;
470                                 point_index = 0;
471                         }
472                 }
473         }
474
475 //              print_v2("", tangent_point);
476 //              printf("%d\n", point_index);
477
478         mask_spline_add_point_at_index(spline, point_index);
479
480         if (do_cyclic_correct) {
481                 ref_point = &spline->points[point_index + 1];
482                 new_point = &spline->points[point_index];
483                 *ref_point = *new_point;
484                 memset(new_point, 0, sizeof(*new_point));
485         }
486         else {
487                 ref_point = &spline->points[point_index];
488                 new_point = &spline->points[point_index + 1];
489         }
490
491         masklay->act_point = new_point;
492
493         setup_vertex_point(C, mask, spline, new_point, co, NULL, 0.5f, ref_point, FALSE);
494
495         if (masklay->splines_shapes.first) {
496                 point_index = (((int)(new_point - spline->points) + 0) % spline->tot_point);
497                 BKE_mask_layer_shape_changed_add(masklay, BKE_mask_layer_shape_spline_to_index(masklay, spline) + point_index, TRUE, TRUE);
498         }
499
500         if (do_recalc_src) {
501                 /* TODO, update keyframes in time */
502                 BKE_mask_calc_handle_point_auto(spline, ref_point, FALSE);
503         }
504
505         WM_event_add_notifier(C, NC_MASK | NA_EDITED, mask);
506
507         return TRUE;
508 }
509
510 static int add_vertex_new(const bContext *C, Mask *mask, MaskLayer *masklay, const float co[2])
511 {
512         MaskSpline *spline;
513         MaskSplinePoint *point;
514         MaskSplinePoint *new_point = NULL, *ref_point = NULL;
515
516         if (!masklay) {
517                 /* if there's no masklay currently operationg on, create new one */
518                 masklay = BKE_mask_layer_new(mask, "");
519                 mask->masklay_act = mask->masklay_tot - 1;
520                 spline = NULL;
521                 point = NULL;
522         }
523         else {
524                 finSelectedSplinePoint(masklay, &spline, &point, TRUE);
525         }
526
527         ED_mask_select_toggle_all(mask, SEL_DESELECT);
528
529         if (!spline) {
530                 /* no selected splines in active masklay, create new spline */
531                 spline = BKE_mask_spline_add(masklay);
532         }
533
534         masklay->act_spline = spline;
535         new_point = spline->points;
536
537         masklay->act_point = new_point;
538
539         setup_vertex_point(C, mask, spline, new_point, co, NULL, 0.5f, ref_point, FALSE);
540
541         {
542                 int point_index = (((int)(new_point - spline->points) + 0) % spline->tot_point);
543                 BKE_mask_layer_shape_changed_add(masklay, BKE_mask_layer_shape_spline_to_index(masklay, spline) + point_index, TRUE, TRUE);
544         }
545
546         WM_event_add_notifier(C, NC_MASK | NA_EDITED, mask);
547
548         return TRUE;
549 }
550
551 static int add_vertex_exec(bContext *C, wmOperator *op)
552 {
553         Mask *mask = CTX_data_edit_mask(C);
554         MaskLayer *masklay;
555
556         float co[2];
557
558         masklay = BKE_mask_layer_active(mask);
559
560         if (masklay && masklay->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) {
561                 masklay = NULL;
562         }
563
564         RNA_float_get_array(op->ptr, "location", co);
565
566         /* TODO, having an active point but no active spline is possible, why? */
567         if (masklay && masklay->act_spline && masklay->act_point && MASKPOINT_ISSEL_ANY(masklay->act_point)) {
568
569                 /* cheap trick - double click for cyclic */
570                 MaskSpline *spline = masklay->act_spline;
571                 MaskSplinePoint *point = masklay->act_point;
572
573                 int is_sta = (point == spline->points);
574                 int is_end = (point == &spline->points[spline->tot_point - 1]);
575
576                 /* then check are we overlapping the mouse */
577                 if ((is_sta || is_end) && equals_v2v2(co, point->bezt.vec[1])) {
578                         if (spline->flag & MASK_SPLINE_CYCLIC) {
579                                 /* nothing to do */
580                                 return OPERATOR_CANCELLED;
581                         }
582                         else {
583                                 /* recalc the connecting point as well to make a nice even curve */
584                                 MaskSplinePoint *point_other = is_end ? spline->points : &spline->points[spline->tot_point - 1];
585                                 spline->flag |= MASK_SPLINE_CYCLIC;
586
587                                 /* TODO, update keyframes in time */
588                                 BKE_mask_calc_handle_point_auto(spline, point, FALSE);
589                                 BKE_mask_calc_handle_point_auto(spline, point_other, FALSE);
590
591                                 /* TODO: only update this spline */
592                                 BKE_mask_update_display(mask, CTX_data_scene(C)->r.cfra);
593
594                                 WM_event_add_notifier(C, NC_MASK | NA_EDITED, mask);
595                                 return OPERATOR_FINISHED;
596                         }
597                 }
598
599                 if (!add_vertex_subdivide(C, mask, co)) {
600                         if (!add_vertex_extrude(C, mask, masklay, co)) {
601                                 return OPERATOR_CANCELLED;
602                         }
603                 }
604         }
605         else {
606                 if (!add_vertex_subdivide(C, mask, co)) {
607                         if (!add_vertex_new(C, mask, masklay, co)) {
608                                 return OPERATOR_CANCELLED;
609                         }
610                 }
611         }
612
613         /* TODO: only update this spline */
614         BKE_mask_update_display(mask, CTX_data_scene(C)->r.cfra);
615
616         return OPERATOR_FINISHED;
617 }
618
619 static int add_vertex_invoke(bContext *C, wmOperator *op, wmEvent *event)
620 {
621         ScrArea *sa = CTX_wm_area(C);
622         ARegion *ar = CTX_wm_region(C);
623
624         float co[2];
625
626         ED_mask_mouse_pos(sa, ar, event->mval, co);
627
628         RNA_float_set_array(op->ptr, "location", co);
629
630         return add_vertex_exec(C, op);
631 }
632
633 void MASK_OT_add_vertex(wmOperatorType *ot)
634 {
635         /* identifiers */
636         ot->name = "Add Vertex";
637         ot->description = "Add vertex to active spline";
638         ot->idname = "MASK_OT_add_vertex";
639
640         /* api callbacks */
641         ot->exec = add_vertex_exec;
642         ot->invoke = add_vertex_invoke;
643         ot->poll = ED_maskedit_mask_poll;
644
645         /* flags */
646         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
647
648         /* properties */
649         RNA_def_float_vector(ot->srna, "location", 2, NULL, -FLT_MIN, FLT_MAX,
650                              "Location", "Location of vertex in normalized space", -1.0f, 1.0f);
651 }
652
653 /******************** add feather vertex *********************/
654
655 static int add_feather_vertex_exec(bContext *C, wmOperator *op)
656 {
657         Mask *mask = CTX_data_edit_mask(C);
658         MaskLayer *masklay;
659         MaskSpline *spline;
660         MaskSplinePoint *point = NULL;
661         const float threshold = 9;
662         float co[2], u;
663
664         RNA_float_get_array(op->ptr, "location", co);
665
666         point = ED_mask_point_find_nearest(C, mask, co, threshold, NULL, NULL, NULL, NULL);
667         if (point)
668                 return OPERATOR_FINISHED;
669
670         if (find_nearest_diff_point(C, mask, co, threshold, TRUE, &masklay, &spline, &point, &u, NULL, TRUE)) {
671                 Scene *scene = CTX_data_scene(C);
672                 float w = BKE_mask_point_weight(spline, point, u);
673                 float weight_scalar = BKE_mask_point_weight_scalar(spline, point, u);
674
675                 if (weight_scalar != 0.0f) {
676                         w = w / weight_scalar;
677                 }
678
679                 BKE_mask_point_add_uw(point, u, w);
680
681                 BKE_mask_update_display(mask, scene->r.cfra);
682
683                 WM_event_add_notifier(C, NC_MASK | NA_EDITED, mask);
684
685                 DAG_id_tag_update(&mask->id, 0);
686
687                 return OPERATOR_FINISHED;
688         }
689
690         return OPERATOR_CANCELLED;
691 }
692
693 static int add_feather_vertex_invoke(bContext *C, wmOperator *op, wmEvent *event)
694 {
695         ScrArea *sa = CTX_wm_area(C);
696         ARegion *ar = CTX_wm_region(C);
697
698         float co[2];
699
700         ED_mask_mouse_pos(sa, ar, event->mval, co);
701
702         RNA_float_set_array(op->ptr, "location", co);
703
704         return add_feather_vertex_exec(C, op);
705 }
706
707 void MASK_OT_add_feather_vertex(wmOperatorType *ot)
708 {
709         /* identifiers */
710         ot->name = "Add feather Vertex";
711         ot->description = "Add vertex to feather";
712         ot->idname = "MASK_OT_add_feather_vertex";
713
714         /* api callbacks */
715         ot->exec = add_feather_vertex_exec;
716         ot->invoke = add_feather_vertex_invoke;
717         ot->poll = ED_maskedit_mask_poll;
718
719         /* flags */
720         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
721
722         /* properties */
723         RNA_def_float_vector(ot->srna, "location", 2, NULL, -FLT_MIN, FLT_MAX,
724                              "Location", "Location of vertex in normalized space", -1.0f, 1.0f);
725 }