Merge branch 'blender2.7'
[blender.git] / source / blender / editors / sculpt_paint / paint_image.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  * along with this program; if not, write to the Free Software Foundation,
15  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16  *
17  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
18  * All rights reserved.
19  *
20  * The Original Code is: some of this file.
21  *
22  * Contributor(s): Jens Ole Wund (bjornmose), Campbell Barton (ideasman42)
23  *
24  * ***** END GPL LICENSE BLOCK *****
25  */
26
27 /** \file blender/editors/sculpt_paint/paint_image.c
28  *  \ingroup edsculpt
29  *  \brief Functions to paint images in 2D and 3D.
30  */
31
32 #include <float.h>
33 #include <string.h>
34 #include <stdio.h>
35 #include <math.h>
36
37 #include "MEM_guardedalloc.h"
38
39 #include "BLI_math.h"
40 #include "BLI_blenlib.h"
41 #include "BLI_utildefines.h"
42
43 #include "BLT_translation.h"
44
45 #include "IMB_imbuf.h"
46 #include "IMB_imbuf_types.h"
47
48 #include "DNA_brush_types.h"
49 #include "DNA_mesh_types.h"
50 #include "DNA_node_types.h"
51 #include "DNA_object_types.h"
52
53 #include "BKE_colorband.h"
54 #include "BKE_context.h"
55 #include "BKE_brush.h"
56 #include "BKE_main.h"
57 #include "BKE_material.h"
58 #include "BKE_mesh.h"
59 #include "BKE_node.h"
60 #include "BKE_paint.h"
61 #include "BKE_undo_system.h"
62
63
64 #include "DEG_depsgraph.h"
65
66 #include "UI_interface.h"
67 #include "UI_view2d.h"
68
69 #include "ED_image.h"
70 #include "ED_object.h"
71 #include "ED_paint.h"
72 #include "ED_screen.h"
73 #include "ED_view3d.h"
74
75 #include "WM_api.h"
76 #include "WM_types.h"
77 #include "WM_message.h"
78 #include "WM_toolsystem.h"
79
80 #include "RNA_access.h"
81 #include "RNA_define.h"
82
83 #include "GPU_draw.h"
84 #include "GPU_immediate.h"
85 #include "GPU_state.h"
86
87 #include "BIF_gl.h"
88
89 #include "IMB_colormanagement.h"
90
91 #include "paint_intern.h"
92
93 /* this is a static resource for non-globality,
94  * Maybe it should be exposed as part of the
95  * paint operation, but for now just give a public interface */
96 static ImagePaintPartialRedraw imapaintpartial = {0, 0, 0, 0, 0};
97
98 ImagePaintPartialRedraw *get_imapaintpartial(void)
99 {
100         return &imapaintpartial;
101 }
102
103 void set_imapaintpartial(struct ImagePaintPartialRedraw *ippr)
104 {
105         imapaintpartial = *ippr;
106 }
107
108 /* Imagepaint Partial Redraw & Dirty Region */
109
110 void ED_imapaint_clear_partial_redraw(void)
111 {
112         memset(&imapaintpartial, 0, sizeof(imapaintpartial));
113 }
114
115 void imapaint_region_tiles(ImBuf *ibuf, int x, int y, int w, int h, int *tx, int *ty, int *tw, int *th)
116 {
117         int srcx = 0, srcy = 0;
118
119         IMB_rectclip(ibuf, NULL, &x, &y, &srcx, &srcy, &w, &h);
120
121         *tw = ((x + w - 1) >> IMAPAINT_TILE_BITS);
122         *th = ((y + h - 1) >> IMAPAINT_TILE_BITS);
123         *tx = (x >> IMAPAINT_TILE_BITS);
124         *ty = (y >> IMAPAINT_TILE_BITS);
125 }
126
127 void ED_imapaint_dirty_region(Image *ima, ImBuf *ibuf, int x, int y, int w, int h, bool find_old)
128 {
129         ImBuf *tmpibuf = NULL;
130         int tilex, tiley, tilew, tileh, tx, ty;
131         int srcx = 0, srcy = 0;
132
133         IMB_rectclip(ibuf, NULL, &x, &y, &srcx, &srcy, &w, &h);
134
135         if (w == 0 || h == 0)
136                 return;
137
138         if (!imapaintpartial.enabled) {
139                 imapaintpartial.x1 = x;
140                 imapaintpartial.y1 = y;
141                 imapaintpartial.x2 = x + w;
142                 imapaintpartial.y2 = y + h;
143                 imapaintpartial.enabled = 1;
144         }
145         else {
146                 imapaintpartial.x1 = min_ii(imapaintpartial.x1, x);
147                 imapaintpartial.y1 = min_ii(imapaintpartial.y1, y);
148                 imapaintpartial.x2 = max_ii(imapaintpartial.x2, x + w);
149                 imapaintpartial.y2 = max_ii(imapaintpartial.y2, y + h);
150         }
151
152         imapaint_region_tiles(ibuf, x, y, w, h, &tilex, &tiley, &tilew, &tileh);
153
154         ListBase *undo_tiles = ED_image_undo_get_tiles();
155
156         for (ty = tiley; ty <= tileh; ty++)
157                 for (tx = tilex; tx <= tilew; tx++)
158                         image_undo_push_tile(undo_tiles, ima, ibuf, &tmpibuf, tx, ty, NULL, NULL, false, find_old);
159
160         ibuf->userflags |= IB_BITMAPDIRTY;
161
162         if (tmpibuf)
163                 IMB_freeImBuf(tmpibuf);
164 }
165
166 void imapaint_image_update(SpaceImage *sima, Image *image, ImBuf *ibuf, short texpaint)
167 {
168         if (imapaintpartial.x1 != imapaintpartial.x2 &&
169             imapaintpartial.y1 != imapaintpartial.y2)
170         {
171                 IMB_partial_display_buffer_update_delayed(
172                         ibuf, imapaintpartial.x1, imapaintpartial.y1,
173                         imapaintpartial.x2, imapaintpartial.y2);
174         }
175
176         if (ibuf->mipmap[0])
177                 ibuf->userflags |= IB_MIPMAP_INVALID;
178
179         /* todo: should set_tpage create ->rect? */
180         if (texpaint || (sima && sima->lock)) {
181                 int w = imapaintpartial.x2 - imapaintpartial.x1;
182                 int h = imapaintpartial.y2 - imapaintpartial.y1;
183                 if (w && h) {
184                         /* Testing with partial update in uv editor too */
185                         GPU_paint_update_image(image, (sima ? &sima->iuser : NULL), imapaintpartial.x1, imapaintpartial.y1, w, h);
186                 }
187         }
188 }
189
190 /* paint blur kernels. Projective painting enforces use of a 2x2 kernel due to lagging */
191 BlurKernel *paint_new_blur_kernel(Brush *br, bool proj)
192 {
193         int i, j;
194         BlurKernel *kernel = MEM_mallocN(sizeof(BlurKernel), "blur kernel");
195         float radius;
196         int side;
197         eBlurKernelType type = br->blur_mode;
198
199         if (proj) {
200                 radius = 0.5f;
201
202                 side = kernel->side = 2;
203                 kernel->side_squared = kernel->side * kernel->side;
204                 kernel->wdata = MEM_mallocN(sizeof(float) * kernel->side_squared, "blur kernel data");
205                 kernel->pixel_len = radius;
206         }
207         else {
208                 if (br->blur_kernel_radius <= 0)
209                         br->blur_kernel_radius = 1;
210
211                 radius = br->blur_kernel_radius;
212
213                 side = kernel->side = radius * 2 + 1;
214                 kernel->side_squared = kernel->side * kernel->side;
215                 kernel->wdata = MEM_mallocN(sizeof(float) * kernel->side_squared, "blur kernel data");
216                 kernel->pixel_len = br->blur_kernel_radius;
217         }
218
219         switch (type) {
220                 case KERNEL_BOX:
221                         for (i = 0; i < kernel->side_squared; i++)
222                                 kernel->wdata[i] = 1.0;
223                         break;
224
225                 case KERNEL_GAUSSIAN:
226                 {
227                         /* at 3.0 standard deviations distance, kernel is about zero */
228                         float standard_dev = radius / 3.0f;
229
230                         /* make the necessary adjustment to the value for use in the normal distribution formula */
231                         standard_dev = -standard_dev * standard_dev * 2;
232
233                         for (i = 0; i < side; i++) {
234                                 for (j = 0; j < side; j++) {
235                                         float idist = radius - i;
236                                         float jdist = radius - j;
237                                         float value = exp((idist * idist + jdist * jdist) / standard_dev);
238
239                                         kernel->wdata[i + j * side] = value;
240                                 }
241                         }
242
243                         break;
244                 }
245
246                 default:
247                         printf("unidentified kernel type, aborting\n");
248                         MEM_freeN(kernel->wdata);
249                         MEM_freeN(kernel);
250                         return NULL;
251         }
252
253         return kernel;
254 }
255
256 void paint_delete_blur_kernel(BlurKernel *kernel)
257 {
258         if (kernel->wdata)
259                 MEM_freeN(kernel->wdata);
260 }
261
262 /************************ image paint poll ************************/
263
264 static Brush *image_paint_brush(bContext *C)
265 {
266         Scene *scene = CTX_data_scene(C);
267         ToolSettings *settings = scene->toolsettings;
268
269         return BKE_paint_brush(&settings->imapaint.paint);
270 }
271
272 static bool image_paint_poll_ex(bContext *C, bool check_tool)
273 {
274         Object *obact;
275
276         if (!image_paint_brush(C))
277                 return 0;
278
279         obact = CTX_data_active_object(C);
280         if ((obact && obact->mode & OB_MODE_TEXTURE_PAINT) && CTX_wm_region_view3d(C)) {
281                 if (!check_tool || WM_toolsystem_active_tool_is_brush(C)) {
282                         return 1;
283                 }
284         }
285         else {
286                 SpaceImage *sima = CTX_wm_space_image(C);
287
288                 if (sima) {
289                         ARegion *ar = CTX_wm_region(C);
290
291                         if ((sima->mode == SI_MODE_PAINT) && ar->regiontype == RGN_TYPE_WINDOW) {
292                                 return 1;
293                         }
294                 }
295         }
296
297         return 0;
298 }
299
300 static bool image_paint_poll(bContext *C)
301 {
302         return image_paint_poll_ex(C, true);
303 }
304
305 static bool image_paint_poll_ignore_tool(bContext *C)
306 {
307         return image_paint_poll_ex(C, false);
308 }
309
310 static bool image_paint_2d_clone_poll(bContext *C)
311 {
312         Brush *brush = image_paint_brush(C);
313
314         if (!CTX_wm_region_view3d(C) && image_paint_poll(C))
315                 if (brush && (brush->imagepaint_tool == PAINT_TOOL_CLONE))
316                         if (brush->clone.image)
317                                 return 1;
318
319         return 0;
320 }
321
322 /************************ paint operator ************************/
323 typedef enum eTexPaintMode {
324         PAINT_MODE_2D,
325         PAINT_MODE_3D_PROJECT
326 } eTexPaintMode;
327
328 typedef struct PaintOperation {
329         eTexPaintMode mode;
330
331         void *custom_paint;
332
333         float prevmouse[2];
334         float startmouse[2];
335         double starttime;
336
337         void *cursor;
338         ViewContext vc;
339 } PaintOperation;
340
341 bool paint_use_opacity_masking(Brush *brush)
342 {
343         return ((brush->flag & BRUSH_AIRBRUSH) ||
344                 (brush->flag & BRUSH_DRAG_DOT) ||
345                 (brush->flag & BRUSH_ANCHORED) ||
346                 (brush->imagepaint_tool == PAINT_TOOL_SMEAR) ||
347                 (brush->imagepaint_tool == PAINT_TOOL_SOFTEN) ||
348                 (brush->imagepaint_tool == PAINT_TOOL_FILL) ||
349                 (brush->flag & BRUSH_USE_GRADIENT) ||
350                 (brush->mtex.tex &&
351                  !ELEM(brush->mtex.brush_map_mode, MTEX_MAP_MODE_TILED, MTEX_MAP_MODE_STENCIL, MTEX_MAP_MODE_3D)) ?
352                 false : true);
353 }
354
355 void paint_brush_color_get(
356         struct Scene *scene, struct Brush *br, bool color_correction, bool invert, float distance,
357         float pressure, float color[3], struct ColorManagedDisplay *display)
358 {
359         if (invert)
360                 copy_v3_v3(color, BKE_brush_secondary_color_get(scene, br));
361         else {
362                 if (br->flag & BRUSH_USE_GRADIENT) {
363                         float color_gr[4];
364                         switch (br->gradient_stroke_mode) {
365                                 case BRUSH_GRADIENT_PRESSURE:
366                                         BKE_colorband_evaluate(br->gradient, pressure, color_gr);
367                                         break;
368                                 case BRUSH_GRADIENT_SPACING_REPEAT:
369                                 {
370                                         float coord = fmod(distance / br->gradient_spacing, 1.0);
371                                         BKE_colorband_evaluate(br->gradient, coord, color_gr);
372                                         break;
373                                 }
374                                 case BRUSH_GRADIENT_SPACING_CLAMP:
375                                 {
376                                         BKE_colorband_evaluate(br->gradient, distance / br->gradient_spacing, color_gr);
377                                         break;
378                                 }
379                         }
380                         copy_v3_v3(color, color_gr);
381                 }
382                 else
383                         copy_v3_v3(color, BKE_brush_color_get(scene, br));
384         }
385         if (color_correction)
386                 IMB_colormanagement_display_to_scene_linear_v3(color, display);
387 }
388
389 void paint_brush_init_tex(Brush *brush)
390 {
391         /* init mtex nodes */
392         if (brush) {
393                 MTex *mtex = &brush->mtex;
394                 if (mtex->tex && mtex->tex->nodetree)
395                         ntreeTexBeginExecTree(mtex->tex->nodetree);  /* has internal flag to detect it only does it once */
396                 mtex = &brush->mask_mtex;
397                 if (mtex->tex && mtex->tex->nodetree)
398                         ntreeTexBeginExecTree(mtex->tex->nodetree);
399         }
400 }
401
402 void paint_brush_exit_tex(Brush *brush)
403 {
404         if (brush) {
405                 MTex *mtex = &brush->mtex;
406                 if (mtex->tex && mtex->tex->nodetree)
407                         ntreeTexEndExecTree(mtex->tex->nodetree->execdata);
408                 mtex = &brush->mask_mtex;
409                 if (mtex->tex && mtex->tex->nodetree)
410                         ntreeTexEndExecTree(mtex->tex->nodetree->execdata);
411         }
412 }
413
414 static void gradient_draw_line(bContext *UNUSED(C), int x, int y, void *customdata)
415 {
416         PaintOperation *pop = (PaintOperation *)customdata;
417
418         if (pop) {
419                 GPU_line_smooth(true);
420                 GPU_blend(true);
421
422                 GPUVertFormat *format = immVertexFormat();
423                 uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT);
424
425                 immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
426
427                 GPU_line_width(4.0);
428                 immUniformColor4ub(0, 0, 0, 255);
429
430                 immBegin(GPU_PRIM_LINES, 2);
431                 immVertex2i(pos, x, y);
432                 immVertex2i(pos, pop->startmouse[0], pop->startmouse[1]);
433                 immEnd();
434
435                 GPU_line_width(2.0);
436                 immUniformColor4ub(255, 255, 255, 255);
437
438                 immBegin(GPU_PRIM_LINES, 2);
439                 immVertex2i(pos, x, y);
440                 immVertex2i(pos, pop->startmouse[0], pop->startmouse[1]);
441                 immEnd();
442
443                 immUnbindProgram();
444
445                 GPU_blend(false);
446                 GPU_line_smooth(false);
447         }
448 }
449
450
451 static PaintOperation *texture_paint_init(bContext *C, wmOperator *op, const float mouse[2])
452 {
453         Scene *scene = CTX_data_scene(C);
454         ToolSettings *settings = scene->toolsettings;
455         PaintOperation *pop = MEM_callocN(sizeof(PaintOperation), "PaintOperation"); /* caller frees */
456         Brush *brush = BKE_paint_brush(&settings->imapaint.paint);
457         int mode = RNA_enum_get(op->ptr, "mode");
458         ED_view3d_viewcontext_init(C, &pop->vc);
459
460         copy_v2_v2(pop->prevmouse, mouse);
461         copy_v2_v2(pop->startmouse, mouse);
462
463         /* initialize from context */
464         if (CTX_wm_region_view3d(C)) {
465                 ViewLayer *view_layer = CTX_data_view_layer(C);
466                 Object *ob = OBACT(view_layer);
467                 bool uvs, mat, tex, stencil;
468                 if (!BKE_paint_proj_mesh_data_check(scene, ob, &uvs, &mat, &tex, &stencil)) {
469                         BKE_paint_data_warning(op->reports, uvs, mat, tex, stencil);
470                         MEM_freeN(pop);
471                         WM_event_add_notifier(C, NC_SCENE | ND_TOOLSETTINGS, NULL);
472                         return NULL;
473                 }
474                 pop->mode = PAINT_MODE_3D_PROJECT;
475                 pop->custom_paint = paint_proj_new_stroke(C, ob, mouse, mode);
476         }
477         else {
478                 pop->mode = PAINT_MODE_2D;
479                 pop->custom_paint = paint_2d_new_stroke(C, op, mode);
480         }
481
482         if (!pop->custom_paint) {
483                 MEM_freeN(pop);
484                 return NULL;
485         }
486
487         if ((brush->imagepaint_tool == PAINT_TOOL_FILL) && (brush->flag & BRUSH_USE_GRADIENT)) {
488                 pop->cursor = WM_paint_cursor_activate(
489                         CTX_wm_manager(C),
490                         SPACE_TYPE_ANY, RGN_TYPE_ANY,
491                         image_paint_poll, gradient_draw_line,
492                         pop);
493         }
494
495         settings->imapaint.flag |= IMAGEPAINT_DRAWING;
496         ED_image_undo_push_begin(op->type->name);
497
498         return pop;
499 }
500
501 static void paint_stroke_update_step(bContext *C, struct PaintStroke *stroke, PointerRNA *itemptr)
502 {
503         PaintOperation *pop = paint_stroke_mode_data(stroke);
504         Scene *scene = CTX_data_scene(C);
505         ToolSettings *toolsettings = CTX_data_tool_settings(C);
506         UnifiedPaintSettings *ups = &toolsettings->unified_paint_settings;
507         Brush *brush = BKE_paint_brush(&toolsettings->imapaint.paint);
508
509         float alphafac = (brush->flag & BRUSH_ACCUMULATE) ? ups->overlap_factor : 1.0f;
510
511         /* initial brush values. Maybe it should be considered moving these to stroke system */
512         float startalpha = BKE_brush_alpha_get(scene, brush);
513
514         float mouse[2];
515         float pressure;
516         float size;
517         float distance = paint_stroke_distance_get(stroke);
518         int eraser;
519
520         RNA_float_get_array(itemptr, "mouse", mouse);
521         pressure = RNA_float_get(itemptr, "pressure");
522         eraser = RNA_boolean_get(itemptr, "pen_flip");
523         size = max_ff(1.0f, RNA_float_get(itemptr, "size"));
524
525         /* stroking with fill tool only acts on stroke end */
526         if (brush->imagepaint_tool == PAINT_TOOL_FILL) {
527                 copy_v2_v2(pop->prevmouse, mouse);
528                 return;
529         }
530
531         if (BKE_brush_use_alpha_pressure(scene, brush))
532                 BKE_brush_alpha_set(scene, brush, max_ff(0.0f, startalpha * pressure * alphafac));
533         else
534                 BKE_brush_alpha_set(scene, brush, max_ff(0.0f, startalpha * alphafac));
535
536         if ((brush->flag & BRUSH_DRAG_DOT) || (brush->flag & BRUSH_ANCHORED)) {
537                 UndoStack *ustack = CTX_wm_manager(C)->undo_stack;
538                 ED_image_undo_restore(ustack->step_init);
539         }
540
541         if (pop->mode == PAINT_MODE_3D_PROJECT) {
542                 paint_proj_stroke(C, pop->custom_paint, pop->prevmouse, mouse, eraser, pressure, distance, size);
543         }
544         else {
545                 paint_2d_stroke(pop->custom_paint, pop->prevmouse, mouse, eraser, pressure, distance, size);
546         }
547
548         copy_v2_v2(pop->prevmouse, mouse);
549
550         /* restore brush values */
551         BKE_brush_alpha_set(scene, brush, startalpha);
552 }
553
554 static void paint_stroke_redraw(const bContext *C, struct PaintStroke *stroke, bool final)
555 {
556         PaintOperation *pop = paint_stroke_mode_data(stroke);
557
558         if (pop->mode == PAINT_MODE_3D_PROJECT) {
559                 paint_proj_redraw(C, pop->custom_paint, final);
560         }
561         else {
562                 paint_2d_redraw(C, pop->custom_paint, final);
563         }
564 }
565
566 static void paint_stroke_done(const bContext *C, struct PaintStroke *stroke)
567 {
568         Scene *scene = CTX_data_scene(C);
569         ToolSettings *toolsettings = scene->toolsettings;
570         PaintOperation *pop = paint_stroke_mode_data(stroke);
571         Brush *brush = BKE_paint_brush(&toolsettings->imapaint.paint);
572
573         toolsettings->imapaint.flag &= ~IMAGEPAINT_DRAWING;
574
575         if (brush->imagepaint_tool == PAINT_TOOL_FILL) {
576                 if (brush->flag & BRUSH_USE_GRADIENT) {
577                         if (pop->mode == PAINT_MODE_2D) {
578                                 paint_2d_gradient_fill(C, brush, pop->startmouse, pop->prevmouse, pop->custom_paint);
579                         }
580                         else {
581                                 paint_proj_stroke(
582                                         C, pop->custom_paint, pop->startmouse, pop->prevmouse, paint_stroke_flipped(stroke),
583                                         1.0, 0.0, BKE_brush_size_get(scene, brush));
584                                 /* two redraws, one for GPU update, one for notification */
585                                 paint_proj_redraw(C, pop->custom_paint, false);
586                                 paint_proj_redraw(C, pop->custom_paint, true);
587                         }
588                 }
589                 else {
590                         if (pop->mode == PAINT_MODE_2D) {
591                                 float color[3];
592
593                                 srgb_to_linearrgb_v3_v3(color, BKE_brush_color_get(scene, brush));
594                                 paint_2d_bucket_fill(C, color, brush, pop->prevmouse, pop->custom_paint);
595                         }
596                         else {
597                                 paint_proj_stroke(
598                                         C, pop->custom_paint, pop->startmouse, pop->prevmouse, paint_stroke_flipped(stroke),
599                                         1.0, 0.0, BKE_brush_size_get(scene, brush));
600                                 /* two redraws, one for GPU update, one for notification */
601                                 paint_proj_redraw(C, pop->custom_paint, false);
602                                 paint_proj_redraw(C, pop->custom_paint, true);
603                         }
604                 }
605         }
606         if (pop->mode == PAINT_MODE_3D_PROJECT) {
607                 paint_proj_stroke_done(pop->custom_paint);
608         }
609         else {
610                 paint_2d_stroke_done(pop->custom_paint);
611         }
612
613         if (pop->cursor) {
614                 WM_paint_cursor_end(CTX_wm_manager(C), pop->cursor);
615         }
616
617         ED_image_undo_push_end();
618
619         /* duplicate warning, see texpaint_init */
620 #if 0
621         if (pop->s.warnmultifile)
622                 BKE_reportf(op->reports, RPT_WARNING, "Image requires 4 color channels to paint: %s", pop->s.warnmultifile);
623         if (pop->s.warnpackedfile)
624                 BKE_reportf(op->reports, RPT_WARNING, "Packed MultiLayer files cannot be painted: %s", pop->s.warnpackedfile);
625 #endif
626         MEM_freeN(pop);
627 }
628
629 static bool paint_stroke_test_start(bContext *C, wmOperator *op, const float mouse[2])
630 {
631         PaintOperation *pop;
632
633         /* TODO Should avoid putting this here. Instead, last position should be requested
634          * from stroke system. */
635
636         if (!(pop = texture_paint_init(C, op, mouse))) {
637                 return false;
638         }
639
640         paint_stroke_set_mode_data(op->customdata, pop);
641
642         return true;
643 }
644
645
646 static int paint_invoke(bContext *C, wmOperator *op, const wmEvent *event)
647 {
648         int retval;
649
650         op->customdata = paint_stroke_new(
651                 C, op, NULL, paint_stroke_test_start,
652                 paint_stroke_update_step,
653                 paint_stroke_redraw,
654                 paint_stroke_done, event->type);
655
656         if ((retval = op->type->modal(C, op, event)) == OPERATOR_FINISHED) {
657                 paint_stroke_data_free(op);
658                 return OPERATOR_FINISHED;
659         }
660         /* add modal handler */
661         WM_event_add_modal_handler(C, op);
662
663         OPERATOR_RETVAL_CHECK(retval);
664         BLI_assert(retval == OPERATOR_RUNNING_MODAL);
665
666         return OPERATOR_RUNNING_MODAL;
667 }
668
669 static int paint_exec(bContext *C, wmOperator *op)
670 {
671         PropertyRNA *strokeprop;
672         PointerRNA firstpoint;
673         float mouse[2];
674
675         strokeprop = RNA_struct_find_property(op->ptr, "stroke");
676
677         if (!RNA_property_collection_lookup_int(op->ptr, strokeprop, 0, &firstpoint))
678                 return OPERATOR_CANCELLED;
679
680         RNA_float_get_array(&firstpoint, "mouse", mouse);
681
682         op->customdata = paint_stroke_new(
683                 C, op, NULL, paint_stroke_test_start,
684                 paint_stroke_update_step,
685                 paint_stroke_redraw,
686                 paint_stroke_done, 0);
687         /* frees op->customdata */
688         return paint_stroke_exec(C, op);
689 }
690
691 void PAINT_OT_image_paint(wmOperatorType *ot)
692 {
693         /* identifiers */
694         ot->name = "Image Paint";
695         ot->idname = "PAINT_OT_image_paint";
696         ot->description = "Paint a stroke into the image";
697
698         /* api callbacks */
699         ot->invoke = paint_invoke;
700         ot->modal = paint_stroke_modal;
701         ot->exec = paint_exec;
702         ot->poll = image_paint_poll;
703         ot->cancel = paint_stroke_cancel;
704
705         /* flags */
706         ot->flag = OPTYPE_BLOCKING;
707
708         paint_stroke_operator_properties(ot);
709 }
710
711
712 int get_imapaint_zoom(bContext *C, float *zoomx, float *zoomy)
713 {
714         RegionView3D *rv3d = CTX_wm_region_view3d(C);
715
716         if (!rv3d) {
717                 SpaceImage *sima = CTX_wm_space_image(C);
718
719                 if (sima->mode == SI_MODE_PAINT) {
720                         ARegion *ar = CTX_wm_region(C);
721                         ED_space_image_get_zoom(sima, ar, zoomx, zoomy);
722
723                         return 1;
724                 }
725         }
726
727         *zoomx = *zoomy = 1;
728
729         return 0;
730 }
731
732 /************************ cursor drawing *******************************/
733
734 static void toggle_paint_cursor(bContext *C, int enable)
735 {
736         wmWindowManager *wm = CTX_wm_manager(C);
737         Scene *scene = CTX_data_scene(C);
738         ToolSettings *settings = scene->toolsettings;
739
740         if (settings->imapaint.paintcursor && !enable) {
741                 WM_paint_cursor_end(wm, settings->imapaint.paintcursor);
742                 settings->imapaint.paintcursor = NULL;
743                 paint_cursor_delete_textures();
744         }
745         else if (enable)
746                 paint_cursor_start(C, image_paint_poll);
747 }
748
749 /* enable the paint cursor if it isn't already.
750  *
751  * purpose is to make sure the paint cursor is shown if paint
752  * mode is enabled in the image editor. the paint poll will
753  * ensure that the cursor is hidden when not in paint mode */
754 void ED_space_image_paint_update(Main *bmain, wmWindowManager *wm, Scene *scene)
755 {
756         ToolSettings *settings = scene->toolsettings;
757         ImagePaintSettings *imapaint = &settings->imapaint;
758         bool enabled = false;
759
760         for (wmWindow *win = wm->windows.first; win; win = win->next) {
761                 bScreen *screen = WM_window_get_active_screen(win);
762
763                 for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
764                         if (sa->spacetype == SPACE_IMAGE) {
765                                 if (((SpaceImage *)sa->spacedata.first)->mode == SI_MODE_PAINT) {
766                                         enabled = true;
767                                 }
768                         }
769                 }
770         }
771
772         if (enabled) {
773                 BKE_paint_init(bmain, scene, PAINT_MODE_TEXTURE_2D, PAINT_CURSOR_TEXTURE_PAINT);
774
775                 paint_cursor_start_explicit(&imapaint->paint, wm, image_paint_poll);
776         }
777         else {
778                 paint_cursor_delete_textures();
779         }
780 }
781
782 /************************ grab clone operator ************************/
783
784 typedef struct GrabClone {
785         float startoffset[2];
786         int startx, starty;
787 } GrabClone;
788
789 static void grab_clone_apply(bContext *C, wmOperator *op)
790 {
791         Brush *brush = image_paint_brush(C);
792         float delta[2];
793
794         RNA_float_get_array(op->ptr, "delta", delta);
795         add_v2_v2(brush->clone.offset, delta);
796         ED_region_tag_redraw(CTX_wm_region(C));
797 }
798
799 static int grab_clone_exec(bContext *C, wmOperator *op)
800 {
801         grab_clone_apply(C, op);
802
803         return OPERATOR_FINISHED;
804 }
805
806 static int grab_clone_invoke(bContext *C, wmOperator *op, const wmEvent *event)
807 {
808         Brush *brush = image_paint_brush(C);
809         GrabClone *cmv;
810
811         cmv = MEM_callocN(sizeof(GrabClone), "GrabClone");
812         copy_v2_v2(cmv->startoffset, brush->clone.offset);
813         cmv->startx = event->x;
814         cmv->starty = event->y;
815         op->customdata = cmv;
816
817         WM_event_add_modal_handler(C, op);
818
819         return OPERATOR_RUNNING_MODAL;
820 }
821
822 static int grab_clone_modal(bContext *C, wmOperator *op, const wmEvent *event)
823 {
824         Brush *brush = image_paint_brush(C);
825         ARegion *ar = CTX_wm_region(C);
826         GrabClone *cmv = op->customdata;
827         float startfx, startfy, fx, fy, delta[2];
828         int xmin = ar->winrct.xmin, ymin = ar->winrct.ymin;
829
830         switch (event->type) {
831                 case LEFTMOUSE:
832                 case MIDDLEMOUSE:
833                 case RIGHTMOUSE: // XXX hardcoded
834                         MEM_freeN(op->customdata);
835                         return OPERATOR_FINISHED;
836                 case MOUSEMOVE:
837                         /* mouse moved, so move the clone image */
838                         UI_view2d_region_to_view(&ar->v2d, cmv->startx - xmin, cmv->starty - ymin, &startfx, &startfy);
839                         UI_view2d_region_to_view(&ar->v2d, event->x - xmin, event->y - ymin, &fx, &fy);
840
841                         delta[0] = fx - startfx;
842                         delta[1] = fy - startfy;
843                         RNA_float_set_array(op->ptr, "delta", delta);
844
845                         copy_v2_v2(brush->clone.offset, cmv->startoffset);
846
847                         grab_clone_apply(C, op);
848                         break;
849         }
850
851         return OPERATOR_RUNNING_MODAL;
852 }
853
854 static void grab_clone_cancel(bContext *UNUSED(C), wmOperator *op)
855 {
856         MEM_freeN(op->customdata);
857 }
858
859 void PAINT_OT_grab_clone(wmOperatorType *ot)
860 {
861         /* identifiers */
862         ot->name = "Grab Clone";
863         ot->idname = "PAINT_OT_grab_clone";
864         ot->description = "Move the clone source image";
865
866         /* api callbacks */
867         ot->exec = grab_clone_exec;
868         ot->invoke = grab_clone_invoke;
869         ot->modal = grab_clone_modal;
870         ot->cancel = grab_clone_cancel;
871         ot->poll = image_paint_2d_clone_poll;
872
873         /* flags */
874         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
875
876         /* properties */
877         RNA_def_float_vector(ot->srna, "delta", 2, NULL, -FLT_MAX, FLT_MAX, "Delta", "Delta offset of clone image in 0.0..1.0 coordinates", -1.0f, 1.0f);
878 }
879
880 /******************** sample color operator ********************/
881 typedef struct {
882         bool show_cursor;
883         short event_type;
884         float initcolor[3];
885         bool sample_palette;
886 }       SampleColorData;
887
888
889 static void sample_color_update_header(SampleColorData *data, bContext *C)
890 {
891         char msg[UI_MAX_DRAW_STR];
892         ScrArea *sa = CTX_wm_area(C);
893
894         if (sa) {
895                 BLI_snprintf(
896                         msg, sizeof(msg),
897                         IFACE_("Sample color for %s"),
898                         !data->sample_palette ?
899                         IFACE_("Brush. Use Left Click to sample for palette instead") :
900                         IFACE_("Palette. Use Left Click to sample more colors"));
901                 ED_workspace_status_text(C, msg);
902         }
903 }
904
905 static int sample_color_exec(bContext *C, wmOperator *op)
906 {
907         Paint *paint = BKE_paint_get_active_from_context(C);
908         Brush *brush = BKE_paint_brush(paint);
909         ePaintMode mode = BKE_paintmode_get_active_from_context(C);
910         ARegion *ar = CTX_wm_region(C);
911         wmWindow *win = CTX_wm_window(C);
912         const bool show_cursor = ((paint->flags & PAINT_SHOW_BRUSH) != 0);
913         int location[2];
914         paint->flags &= ~PAINT_SHOW_BRUSH;
915
916         /* force redraw without cursor */
917         WM_paint_cursor_tag_redraw(win, ar);
918         WM_redraw_windows(C);
919
920         RNA_int_get_array(op->ptr, "location", location);
921         const bool use_palette = RNA_boolean_get(op->ptr, "palette");
922         const bool use_sample_texture = (mode == PAINT_MODE_TEXTURE_3D) && !RNA_boolean_get(op->ptr, "merged");
923
924         paint_sample_color(C, ar, location[0], location[1], use_sample_texture, use_palette);
925
926         if (show_cursor) {
927                 paint->flags |= PAINT_SHOW_BRUSH;
928         }
929
930         WM_event_add_notifier(C, NC_BRUSH | NA_EDITED, brush);
931
932         return OPERATOR_FINISHED;
933 }
934
935 static int sample_color_invoke(bContext *C, wmOperator *op, const wmEvent *event)
936 {
937         Scene *scene = CTX_data_scene(C);
938         Paint *paint = BKE_paint_get_active_from_context(C);
939         Brush *brush = BKE_paint_brush(paint);
940         SampleColorData *data = MEM_mallocN(sizeof(SampleColorData), "sample color custom data");
941         ARegion *ar = CTX_wm_region(C);
942         wmWindow *win = CTX_wm_window(C);
943
944         data->event_type = event->type;
945         data->show_cursor = ((paint->flags & PAINT_SHOW_BRUSH) != 0);
946         copy_v3_v3(data->initcolor, BKE_brush_color_get(scene, brush));
947         data->sample_palette = false;
948         op->customdata = data;
949         paint->flags &= ~PAINT_SHOW_BRUSH;
950
951         sample_color_update_header(data, C);
952
953         WM_event_add_modal_handler(C, op);
954
955         /* force redraw without cursor */
956         WM_paint_cursor_tag_redraw(win, ar);
957         WM_redraw_windows(C);
958
959         RNA_int_set_array(op->ptr, "location", event->mval);
960
961         ePaintMode mode = BKE_paintmode_get_active_from_context(C);
962         const bool use_sample_texture = (mode == PAINT_MODE_TEXTURE_3D) && !RNA_boolean_get(op->ptr, "merged");
963
964         paint_sample_color(C, ar, event->mval[0], event->mval[1], use_sample_texture, false);
965         WM_cursor_modal_set(win, BC_EYEDROPPER_CURSOR);
966
967         WM_event_add_notifier(C, NC_BRUSH | NA_EDITED, brush);
968
969         return OPERATOR_RUNNING_MODAL;
970 }
971
972 static int sample_color_modal(bContext *C, wmOperator *op, const wmEvent *event)
973 {
974         Scene *scene = CTX_data_scene(C);
975         SampleColorData *data = op->customdata;
976         Paint *paint = BKE_paint_get_active_from_context(C);
977         Brush *brush = BKE_paint_brush(paint);
978
979         if ((event->type == data->event_type) && (event->val == KM_RELEASE)) {
980                 if (data->show_cursor) {
981                         paint->flags |= PAINT_SHOW_BRUSH;
982                 }
983
984                 if (data->sample_palette) {
985                         BKE_brush_color_set(scene, brush, data->initcolor);
986                         RNA_boolean_set(op->ptr, "palette", true);
987                 }
988                 WM_cursor_modal_restore(CTX_wm_window(C));
989                 MEM_freeN(data);
990                 ED_workspace_status_text(C, NULL);
991
992                 return OPERATOR_FINISHED;
993         }
994
995         ePaintMode mode = BKE_paintmode_get_active_from_context(C);
996         const bool use_sample_texture = (mode == PAINT_MODE_TEXTURE_3D) && !RNA_boolean_get(op->ptr, "merged");
997
998         switch (event->type) {
999                 case MOUSEMOVE:
1000                 {
1001                         ARegion *ar = CTX_wm_region(C);
1002                         RNA_int_set_array(op->ptr, "location", event->mval);
1003                         paint_sample_color(C, ar, event->mval[0], event->mval[1], use_sample_texture, false);
1004                         WM_event_add_notifier(C, NC_BRUSH | NA_EDITED, brush);
1005                         break;
1006                 }
1007
1008                 case LEFTMOUSE:
1009                         if (event->val == KM_PRESS) {
1010                                 ARegion *ar = CTX_wm_region(C);
1011                                 RNA_int_set_array(op->ptr, "location", event->mval);
1012                                 paint_sample_color(C, ar, event->mval[0], event->mval[1], use_sample_texture, true);
1013                                 if (!data->sample_palette) {
1014                                         data->sample_palette = true;
1015                                         sample_color_update_header(data, C);
1016                                 }
1017                                 WM_event_add_notifier(C, NC_BRUSH | NA_EDITED, brush);
1018                         }
1019                         break;
1020         }
1021
1022         return OPERATOR_RUNNING_MODAL;
1023 }
1024
1025 static bool sample_color_poll(bContext *C)
1026 {
1027         return (image_paint_poll_ignore_tool(C) || vertex_paint_poll_ignore_tool(C));
1028 }
1029
1030 void PAINT_OT_sample_color(wmOperatorType *ot)
1031 {
1032         /* identifiers */
1033         ot->name = "Sample Color";
1034         ot->idname = "PAINT_OT_sample_color";
1035         ot->description = "Use the mouse to sample a color in the image";
1036
1037         /* api callbacks */
1038         ot->exec = sample_color_exec;
1039         ot->invoke = sample_color_invoke;
1040         ot->modal = sample_color_modal;
1041         ot->poll = sample_color_poll;
1042
1043         /* flags */
1044         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1045
1046         /* properties */
1047         PropertyRNA *prop;
1048
1049         prop = RNA_def_int_vector(ot->srna, "location", 2, NULL, 0, INT_MAX, "Location", "", 0, 16384);
1050         RNA_def_property_flag(prop, PROP_SKIP_SAVE | PROP_HIDDEN);
1051
1052         RNA_def_boolean(ot->srna, "merged", 0, "Sample Merged", "Sample the output display color");
1053         RNA_def_boolean(ot->srna, "palette", 0, "Add to Palette", "");
1054 }
1055
1056 /******************** texture paint toggle operator ********************/
1057
1058 static bool texture_paint_toggle_poll(bContext *C)
1059 {
1060         Object *ob = CTX_data_active_object(C);
1061         if (ob == NULL || ob->type != OB_MESH)
1062                 return 0;
1063         if (!ob->data || ID_IS_LINKED(ob->data))
1064                 return 0;
1065         if (CTX_data_edit_object(C))
1066                 return 0;
1067
1068         return 1;
1069 }
1070
1071 static int texture_paint_toggle_exec(bContext *C, wmOperator *op)
1072 {
1073         struct wmMsgBus *mbus = CTX_wm_message_bus(C);
1074         Main *bmain = CTX_data_main(C);
1075         Scene *scene = CTX_data_scene(C);
1076         Object *ob = CTX_data_active_object(C);
1077         const int mode_flag = OB_MODE_TEXTURE_PAINT;
1078         const bool is_mode_set = (ob->mode & mode_flag) != 0;
1079
1080         if (!is_mode_set) {
1081                 if (!ED_object_mode_compat_set(C, ob, mode_flag, op->reports)) {
1082                         return OPERATOR_CANCELLED;
1083                 }
1084         }
1085
1086         if (ob->mode & mode_flag) {
1087                 ob->mode &= ~mode_flag;
1088
1089                 if (U.glreslimit != 0)
1090                         GPU_free_images(bmain);
1091                 GPU_paint_set_mipmap(bmain, 1);
1092
1093                 toggle_paint_cursor(C, 0);
1094         }
1095         else {
1096                 bScreen *sc;
1097                 Image *ima = NULL;
1098                 ImagePaintSettings *imapaint = &scene->toolsettings->imapaint;
1099
1100                 /* This has to stay here to regenerate the texture paint
1101                  * cache in case we are loading a file */
1102                 BKE_texpaint_slots_refresh_object(scene, ob);
1103
1104                 BKE_paint_proj_mesh_data_check(scene, ob, NULL, NULL, NULL, NULL);
1105
1106                 /* entering paint mode also sets image to editors */
1107                 if (imapaint->mode == IMAGEPAINT_MODE_MATERIAL) {
1108                         Material *ma = give_current_material(ob, ob->actcol); /* set the current material active paint slot on image editor */
1109
1110                         if (ma && ma->texpaintslot)
1111                                 ima = ma->texpaintslot[ma->paint_active_slot].ima;
1112                 }
1113                 else if (imapaint->mode == IMAGEPAINT_MODE_IMAGE) {
1114                         ima = imapaint->canvas;
1115                 }
1116
1117                 if (ima) {
1118                         for (sc = bmain->screen.first; sc; sc = sc->id.next) {
1119                                 ScrArea *sa;
1120                                 for (sa = sc->areabase.first; sa; sa = sa->next) {
1121                                         SpaceLink *sl;
1122                                         for (sl = sa->spacedata.first; sl; sl = sl->next) {
1123                                                 if (sl->spacetype == SPACE_IMAGE) {
1124                                                         SpaceImage *sima = (SpaceImage *)sl;
1125
1126                                                         if (!sima->pin) {
1127                                                                 Object *obedit = CTX_data_edit_object(C);
1128                                                                 ED_space_image_set(bmain, sima, scene, obedit, ima);
1129                                                         }
1130                                                 }
1131                                         }
1132                                 }
1133                         }
1134                 }
1135
1136                 ob->mode |= mode_flag;
1137
1138                 BKE_paint_init(bmain, scene, PAINT_MODE_TEXTURE_3D, PAINT_CURSOR_TEXTURE_PAINT);
1139
1140                 BKE_paint_toolslots_brush_validate(bmain, &imapaint->paint);
1141
1142                 if (U.glreslimit != 0)
1143                         GPU_free_images(bmain);
1144                 GPU_paint_set_mipmap(bmain, 0);
1145
1146                 toggle_paint_cursor(C, 1);
1147         }
1148
1149         Mesh *me = BKE_mesh_from_object(ob);
1150         BLI_assert(me != NULL);
1151         DEG_id_tag_update(&me->id, ID_RECALC_COPY_ON_WRITE);
1152
1153         WM_event_add_notifier(C, NC_SCENE | ND_MODE, scene);
1154
1155         WM_msg_publish_rna_prop(mbus, &ob->id, ob, Object, mode);
1156
1157         WM_toolsystem_update_from_context_view3d(C);
1158
1159         return OPERATOR_FINISHED;
1160 }
1161
1162 void PAINT_OT_texture_paint_toggle(wmOperatorType *ot)
1163 {
1164         /* identifiers */
1165         ot->name = "Texture Paint Toggle";
1166         ot->idname = "PAINT_OT_texture_paint_toggle";
1167         ot->description = "Toggle texture paint mode in 3D view";
1168
1169         /* api callbacks */
1170         ot->exec = texture_paint_toggle_exec;
1171         ot->poll = texture_paint_toggle_poll;
1172
1173         /* flags */
1174         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA;
1175 }
1176
1177
1178 static int brush_colors_flip_exec(bContext *C, wmOperator *UNUSED(op))
1179 {
1180         UnifiedPaintSettings *ups = &CTX_data_tool_settings(C)->unified_paint_settings;
1181
1182         Object *ob = CTX_data_active_object(C);
1183         Brush *br;
1184         if (!(ob && (ob->mode & OB_MODE_VERTEX_PAINT))) {
1185                 br = image_paint_brush(C);
1186         }
1187         else {
1188                 /* At the moment, wpaint does not support the color flipper.
1189                  * So for now we're only handling vpaint */
1190                 ToolSettings *ts = CTX_data_tool_settings(C);
1191                 VPaint *vp = ts->vpaint;
1192                 br = BKE_paint_brush(&vp->paint);
1193         }
1194
1195         if (ups->flag & UNIFIED_PAINT_COLOR) {
1196                 swap_v3_v3(ups->rgb, ups->secondary_rgb);
1197         }
1198         else if (br) {
1199                 swap_v3_v3(br->rgb, br->secondary_rgb);
1200         }
1201         WM_event_add_notifier(C, NC_BRUSH | NA_EDITED, br);
1202
1203         return OPERATOR_FINISHED;
1204 }
1205
1206 static bool brush_colors_flip_poll(bContext *C)
1207 {
1208         if (image_paint_poll(C)) {
1209                 Brush *br = image_paint_brush(C);
1210                 if (br->imagepaint_tool == PAINT_TOOL_DRAW)
1211                         return 1;
1212         }
1213         else {
1214                 Object *ob = CTX_data_active_object(C);
1215                 if (ob && (ob->mode & OB_MODE_VERTEX_PAINT)) {
1216                         return 1;
1217                 }
1218         }
1219         return 0;
1220 }
1221
1222 void PAINT_OT_brush_colors_flip(wmOperatorType *ot)
1223 {
1224         /* identifiers */
1225         ot->name = "Brush Colors Flip";
1226         ot->idname = "PAINT_OT_brush_colors_flip";
1227         ot->description = "Toggle foreground and background brush colors";
1228
1229         /* api callbacks */
1230         ot->exec = brush_colors_flip_exec;
1231         ot->poll = brush_colors_flip_poll;
1232
1233         /* flags */
1234         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1235 }
1236
1237
1238 void ED_imapaint_bucket_fill(struct bContext *C, float color[3], wmOperator *op)
1239 {
1240         wmWindowManager *wm = CTX_wm_manager(C);
1241         SpaceImage *sima = CTX_wm_space_image(C);
1242         Image *ima = sima->image;
1243
1244         BKE_undosys_step_push_init_with_type(wm->undo_stack, C, op->type->name, BKE_UNDOSYS_TYPE_IMAGE);
1245
1246         ED_image_undo_push_begin(op->type->name);
1247
1248         paint_2d_bucket_fill(C, color, NULL, NULL, NULL);
1249
1250         BKE_undosys_step_push(wm->undo_stack, C, op->type->name);
1251
1252         DEG_id_tag_update(&ima->id, 0);
1253 }
1254
1255
1256 static bool texture_paint_poll(bContext *C)
1257 {
1258         if (texture_paint_toggle_poll(C))
1259                 if (CTX_data_active_object(C)->mode & OB_MODE_TEXTURE_PAINT)
1260                         return 1;
1261
1262         return 0;
1263 }
1264
1265 bool image_texture_paint_poll(bContext *C)
1266 {
1267         return (texture_paint_poll(C) || image_paint_poll(C));
1268 }
1269
1270 bool facemask_paint_poll(bContext *C)
1271 {
1272         return BKE_paint_select_face_test(CTX_data_active_object(C));
1273 }
1274
1275 bool vert_paint_poll(bContext *C)
1276 {
1277         return BKE_paint_select_vert_test(CTX_data_active_object(C));
1278 }
1279
1280 bool mask_paint_poll(bContext *C)
1281 {
1282         return BKE_paint_select_elem_test(CTX_data_active_object(C));
1283 }