Blender  V2.93
paint_image.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * along with this program; if not, write to the Free Software Foundation,
13  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
14  *
15  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
16  * All rights reserved.
17  *
18  * The Original Code is: some of this file.
19  */
20 
26 #include <float.h>
27 #include <math.h>
28 #include <stdio.h>
29 #include <string.h>
30 
31 #include "MEM_guardedalloc.h"
32 
33 #include "BLI_blenlib.h"
34 #include "BLI_math.h"
35 #include "BLI_utildefines.h"
36 
37 #include "BLT_translation.h"
38 
39 #include "IMB_imbuf.h"
40 #include "IMB_imbuf_types.h"
41 
42 #include "DNA_brush_types.h"
43 #include "DNA_material_types.h"
44 #include "DNA_mesh_types.h"
45 #include "DNA_node_types.h"
46 #include "DNA_object_types.h"
47 
48 #include "BKE_brush.h"
49 #include "BKE_colorband.h"
50 #include "BKE_context.h"
51 #include "BKE_image.h"
52 #include "BKE_main.h"
53 #include "BKE_material.h"
54 #include "BKE_mesh.h"
55 #include "BKE_node.h"
56 #include "BKE_paint.h"
57 #include "BKE_undo_system.h"
58 
59 #include "DEG_depsgraph.h"
60 
61 #include "UI_interface.h"
62 #include "UI_view2d.h"
63 
64 #include "ED_image.h"
65 #include "ED_object.h"
66 #include "ED_paint.h"
67 #include "ED_screen.h"
68 #include "ED_view3d.h"
69 
70 #include "WM_api.h"
71 #include "WM_message.h"
72 #include "WM_toolsystem.h"
73 #include "WM_types.h"
74 
75 #include "RNA_access.h"
76 #include "RNA_define.h"
77 
78 #include "GPU_immediate.h"
79 #include "GPU_state.h"
80 
81 #include "IMB_colormanagement.h"
82 
83 #include "paint_intern.h"
84 
90 static ImagePaintPartialRedraw imapaintpartial = {0, 0, 0, 0, 0};
91 
93 {
94  return &imapaintpartial;
95 }
96 
98 {
99  imapaintpartial = *ippr;
100 }
101 
102 /* Imagepaint Partial Redraw & Dirty Region */
103 
105 {
106  memset(&imapaintpartial, 0, sizeof(imapaintpartial));
107 }
108 
110  ImBuf *ibuf, int x, int y, int w, int h, int *tx, int *ty, int *tw, int *th)
111 {
112  int srcx = 0, srcy = 0;
113 
114  IMB_rectclip(ibuf, NULL, &x, &y, &srcx, &srcy, &w, &h);
115 
116  *tw = ((x + w - 1) >> ED_IMAGE_UNDO_TILE_BITS);
117  *th = ((y + h - 1) >> ED_IMAGE_UNDO_TILE_BITS);
118  *tx = (x >> ED_IMAGE_UNDO_TILE_BITS);
119  *ty = (y >> ED_IMAGE_UNDO_TILE_BITS);
120 }
121 
123  Image *ima, ImBuf *ibuf, ImageUser *iuser, int x, int y, int w, int h, bool find_old)
124 {
125  ImBuf *tmpibuf = NULL;
126  int tilex, tiley, tilew, tileh, tx, ty;
127  int srcx = 0, srcy = 0;
128 
129  IMB_rectclip(ibuf, NULL, &x, &y, &srcx, &srcy, &w, &h);
130 
131  if (w == 0 || h == 0) {
132  return;
133  }
134 
135  if (!imapaintpartial.enabled) {
136  imapaintpartial.x1 = x;
137  imapaintpartial.y1 = y;
138  imapaintpartial.x2 = x + w;
139  imapaintpartial.y2 = y + h;
141  }
142  else {
147  }
148 
149  imapaint_region_tiles(ibuf, x, y, w, h, &tilex, &tiley, &tilew, &tileh);
150 
151  ListBase *undo_tiles = ED_image_paint_tile_list_get();
152 
153  for (ty = tiley; ty <= tileh; ty++) {
154  for (tx = tilex; tx <= tilew; tx++) {
156  undo_tiles, ima, ibuf, &tmpibuf, iuser, tx, ty, NULL, NULL, false, find_old);
157  }
158  }
159 
160  BKE_image_mark_dirty(ima, ibuf);
161 
162  if (tmpibuf) {
163  IMB_freeImBuf(tmpibuf);
164  }
165 }
166 
168  SpaceImage *sima, Image *image, ImBuf *ibuf, ImageUser *iuser, short texpaint)
169 {
173  }
174 
175  if (ibuf->mipmap[0]) {
176  ibuf->userflags |= IB_MIPMAP_INVALID;
177  }
178 
179  /* todo: should set_tpage create ->rect? */
180  if (texpaint || (sima && sima->lock)) {
183  if (w && h) {
184  /* Testing with partial update in uv editor too */
186  }
187  }
188 }
189 
190 /* paint blur kernels. Projective painting enforces use of a 2x2 kernel due to lagging */
192 {
193  int i, j;
194  BlurKernel *kernel = MEM_mallocN(sizeof(BlurKernel), "blur kernel");
195  float radius;
196  int side;
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 
212  radius = br->blur_kernel_radius;
213 
214  side = kernel->side = radius * 2 + 1;
215  kernel->side_squared = kernel->side * kernel->side;
216  kernel->wdata = MEM_mallocN(sizeof(float) * kernel->side_squared, "blur kernel data");
217  kernel->pixel_len = br->blur_kernel_radius;
218  }
219 
220  switch (type) {
221  case KERNEL_BOX:
222  for (i = 0; i < kernel->side_squared; i++) {
223  kernel->wdata[i] = 1.0;
224  }
225  break;
226 
227  case KERNEL_GAUSSIAN: {
228  /* at 3.0 standard deviations distance, kernel is about zero */
229  float standard_dev = radius / 3.0f;
230 
231  /* make the necessary adjustment to the value for use in the normal distribution formula */
232  standard_dev = -standard_dev * standard_dev * 2;
233 
234  for (i = 0; i < side; i++) {
235  for (j = 0; j < side; j++) {
236  float idist = radius - i;
237  float jdist = radius - j;
238  float value = exp((idist * idist + jdist * jdist) / standard_dev);
239 
240  kernel->wdata[i + j * side] = value;
241  }
242  }
243 
244  break;
245  }
246 
247  default:
248  printf("unidentified kernel type, aborting\n");
249  MEM_freeN(kernel->wdata);
250  MEM_freeN(kernel);
251  return NULL;
252  }
253 
254  return kernel;
255 }
256 
258 {
259  if (kernel->wdata) {
260  MEM_freeN(kernel->wdata);
261  }
262 }
263 
264 /************************ image paint poll ************************/
265 
267 {
269  ToolSettings *settings = scene->toolsettings;
270 
271  return BKE_paint_brush(&settings->imapaint.paint);
272 }
273 
274 static bool image_paint_poll_ex(bContext *C, bool check_tool)
275 {
276  Object *obact;
277 
278  if (!image_paint_brush(C)) {
279  return false;
280  }
281 
282  obact = CTX_data_active_object(C);
283  if ((obact && obact->mode & OB_MODE_TEXTURE_PAINT) && CTX_wm_region_view3d(C)) {
284  if (!check_tool || WM_toolsystem_active_tool_is_brush(C)) {
285  return true;
286  }
287  }
288  else {
290 
291  if (sima) {
292  if (sima->image != NULL && ID_IS_LINKED(sima->image)) {
293  return false;
294  }
295  ARegion *region = CTX_wm_region(C);
296 
297  if ((sima->mode == SI_MODE_PAINT) && region->regiontype == RGN_TYPE_WINDOW) {
298  return true;
299  }
300  }
301  }
302 
303  return false;
304 }
305 
307 {
308  return image_paint_poll_ex(C, true);
309 }
310 
312 {
313  return image_paint_poll_ex(C, false);
314 }
315 
317 {
318  Brush *brush = image_paint_brush(C);
319 
321  if (brush && (brush->imagepaint_tool == PAINT_TOOL_CLONE)) {
322  if (brush->clone.image) {
323  return true;
324  }
325  }
326  }
327 
328  return false;
329 }
330 
331 /************************ paint operator ************************/
332 typedef enum eTexPaintMode {
336 
337 typedef struct PaintOperation {
339 
341 
342  float prevmouse[2];
343  float startmouse[2];
344  double starttime;
345 
346  void *cursor;
349 
351 {
352  return ((brush->flag & BRUSH_AIRBRUSH) || (brush->flag & BRUSH_DRAG_DOT) ||
353  (brush->flag & BRUSH_ANCHORED) ||
355  (brush->imagepaint_tool == PAINT_TOOL_FILL) ||
356  (brush->flag & BRUSH_USE_GRADIENT) ||
357  (brush->mtex.tex && !ELEM(brush->mtex.brush_map_mode,
360  MTEX_MAP_MODE_3D)) ?
361  false :
362  true);
363 }
364 
366  struct Brush *br,
367  bool color_correction,
368  bool invert,
369  float distance,
370  float pressure,
371  float color[3],
372  struct ColorManagedDisplay *display)
373 {
374  if (invert) {
376  }
377  else {
378  if (br->flag & BRUSH_USE_GRADIENT) {
379  float color_gr[4];
380  switch (br->gradient_stroke_mode) {
382  BKE_colorband_evaluate(br->gradient, pressure, color_gr);
383  break;
385  float coord = fmod(distance / br->gradient_spacing, 1.0);
386  BKE_colorband_evaluate(br->gradient, coord, color_gr);
387  break;
388  }
391  break;
392  }
393  }
394  /* Gradient / Colorband colors are not considered PROP_COLOR_GAMMA.
395  * Brush colors are expected to be in sRGB though. */
397 
398  copy_v3_v3(color, color_gr);
399  }
400  else {
401  copy_v3_v3(color, BKE_brush_color_get(scene, br));
402  }
403  }
404  if (color_correction) {
406  }
407 }
408 
410 {
411  /* init mtex nodes */
412  if (brush) {
413  MTex *mtex = &brush->mtex;
414  if (mtex->tex && mtex->tex->nodetree) {
415  /* has internal flag to detect it only does it once */
417  }
418  mtex = &brush->mask_mtex;
419  if (mtex->tex && mtex->tex->nodetree) {
421  }
422  }
423 }
424 
426 {
427  if (brush) {
428  MTex *mtex = &brush->mtex;
429  if (mtex->tex && mtex->tex->nodetree) {
431  }
432  mtex = &brush->mask_mtex;
433  if (mtex->tex && mtex->tex->nodetree) {
435  }
436  }
437 }
438 
439 static void gradient_draw_line(bContext *UNUSED(C), int x, int y, void *customdata)
440 {
441  PaintOperation *pop = (PaintOperation *)customdata;
442 
443  if (pop) {
444  GPU_line_smooth(true);
446 
449 
450  ARegion *region = pop->vc.region;
451 
453 
454  GPU_line_width(4.0);
455  immUniformColor4ub(0, 0, 0, 255);
456 
458  immVertex2i(pos, x, y);
459  immVertex2i(
460  pos, pop->startmouse[0] + region->winrct.xmin, pop->startmouse[1] + region->winrct.ymin);
461  immEnd();
462 
463  GPU_line_width(2.0);
464  immUniformColor4ub(255, 255, 255, 255);
465 
467  immVertex2i(pos, x, y);
468  immVertex2i(
469  pos, pop->startmouse[0] + region->winrct.xmin, pop->startmouse[1] + region->winrct.ymin);
470  immEnd();
471 
473 
475  GPU_line_smooth(false);
476  }
477 }
478 
479 static PaintOperation *texture_paint_init(bContext *C, wmOperator *op, const float mouse[2])
480 {
483  ToolSettings *settings = scene->toolsettings;
484  PaintOperation *pop = MEM_callocN(sizeof(PaintOperation), "PaintOperation"); /* caller frees */
485  Brush *brush = BKE_paint_brush(&settings->imapaint.paint);
486  int mode = RNA_enum_get(op->ptr, "mode");
488 
489  copy_v2_v2(pop->prevmouse, mouse);
490  copy_v2_v2(pop->startmouse, mouse);
491 
492  /* initialize from context */
493  if (CTX_wm_region_view3d(C)) {
494  ViewLayer *view_layer = CTX_data_view_layer(C);
495  Object *ob = OBACT(view_layer);
496  bool uvs, mat, tex, stencil;
497  if (!ED_paint_proj_mesh_data_check(scene, ob, &uvs, &mat, &tex, &stencil)) {
498  ED_paint_data_warning(op->reports, uvs, mat, tex, stencil);
499  MEM_freeN(pop);
501  return NULL;
502  }
504  pop->custom_paint = paint_proj_new_stroke(C, ob, mouse, mode);
505  }
506  else {
507  pop->mode = PAINT_MODE_2D;
508  pop->custom_paint = paint_2d_new_stroke(C, op, mode);
509  }
510 
511  if (!pop->custom_paint) {
512  MEM_freeN(pop);
513  return NULL;
514  }
515 
516  if ((brush->imagepaint_tool == PAINT_TOOL_FILL) && (brush->flag & BRUSH_USE_GRADIENT)) {
519  }
520 
521  settings->imapaint.flag |= IMAGEPAINT_DRAWING;
523 
524  return pop;
525 }
526 
527 static void paint_stroke_update_step(bContext *C, struct PaintStroke *stroke, PointerRNA *itemptr)
528 {
529  PaintOperation *pop = paint_stroke_mode_data(stroke);
531  ToolSettings *toolsettings = CTX_data_tool_settings(C);
532  UnifiedPaintSettings *ups = &toolsettings->unified_paint_settings;
533  Brush *brush = BKE_paint_brush(&toolsettings->imapaint.paint);
534 
535  float alphafac = (brush->flag & BRUSH_ACCUMULATE) ? ups->overlap_factor : 1.0f;
536 
537  /* initial brush values. Maybe it should be considered moving these to stroke system */
538  float startalpha = BKE_brush_alpha_get(scene, brush);
539 
540  float mouse[2];
541  float pressure;
542  float size;
543  float distance = paint_stroke_distance_get(stroke);
544  int eraser;
545 
546  RNA_float_get_array(itemptr, "mouse", mouse);
547  pressure = RNA_float_get(itemptr, "pressure");
548  eraser = RNA_boolean_get(itemptr, "pen_flip");
549  size = RNA_float_get(itemptr, "size");
550 
551  /* stroking with fill tool only acts on stroke end */
552  if (brush->imagepaint_tool == PAINT_TOOL_FILL) {
553  copy_v2_v2(pop->prevmouse, mouse);
554  return;
555  }
556 
557  if (BKE_brush_use_alpha_pressure(brush)) {
558  BKE_brush_alpha_set(scene, brush, max_ff(0.0f, startalpha * pressure * alphafac));
559  }
560  else {
561  BKE_brush_alpha_set(scene, brush, max_ff(0.0f, startalpha * alphafac));
562  }
563 
564  if ((brush->flag & BRUSH_DRAG_DOT) || (brush->flag & BRUSH_ANCHORED)) {
565  UndoStack *ustack = CTX_wm_manager(C)->undo_stack;
567  }
568 
569  if (pop->mode == PAINT_MODE_3D_PROJECT) {
571  C, pop->custom_paint, pop->prevmouse, mouse, eraser, pressure, distance, size);
572  }
573  else {
574  paint_2d_stroke(pop->custom_paint, pop->prevmouse, mouse, eraser, pressure, distance, size);
575  }
576 
577  copy_v2_v2(pop->prevmouse, mouse);
578 
579  /* restore brush values */
580  BKE_brush_alpha_set(scene, brush, startalpha);
581 }
582 
583 static void paint_stroke_redraw(const bContext *C, struct PaintStroke *stroke, bool final)
584 {
585  PaintOperation *pop = paint_stroke_mode_data(stroke);
586 
587  if (pop->mode == PAINT_MODE_3D_PROJECT) {
588  paint_proj_redraw(C, pop->custom_paint, final);
589  }
590  else {
591  paint_2d_redraw(C, pop->custom_paint, final);
592  }
593 }
594 
595 static void paint_stroke_done(const bContext *C, struct PaintStroke *stroke)
596 {
598  ToolSettings *toolsettings = scene->toolsettings;
599  PaintOperation *pop = paint_stroke_mode_data(stroke);
600  Brush *brush = BKE_paint_brush(&toolsettings->imapaint.paint);
601 
602  toolsettings->imapaint.flag &= ~IMAGEPAINT_DRAWING;
603 
604  if (brush->imagepaint_tool == PAINT_TOOL_FILL) {
605  if (brush->flag & BRUSH_USE_GRADIENT) {
606  if (pop->mode == PAINT_MODE_2D) {
607  paint_2d_gradient_fill(C, brush, pop->startmouse, pop->prevmouse, pop->custom_paint);
608  }
609  else {
611  pop->custom_paint,
612  pop->startmouse,
613  pop->prevmouse,
614  paint_stroke_flipped(stroke),
615  1.0,
616  0.0,
617  BKE_brush_size_get(scene, brush));
618  /* two redraws, one for GPU update, one for notification */
619  paint_proj_redraw(C, pop->custom_paint, false);
620  paint_proj_redraw(C, pop->custom_paint, true);
621  }
622  }
623  else {
624  if (pop->mode == PAINT_MODE_2D) {
625  float color[3];
626  if (paint_stroke_inverted(stroke)) {
628  }
629  else {
631  }
632  paint_2d_bucket_fill(C, color, brush, pop->startmouse, pop->prevmouse, pop->custom_paint);
633  }
634  else {
636  pop->custom_paint,
637  pop->startmouse,
638  pop->prevmouse,
639  paint_stroke_flipped(stroke),
640  1.0,
641  0.0,
642  BKE_brush_size_get(scene, brush));
643  /* two redraws, one for GPU update, one for notification */
644  paint_proj_redraw(C, pop->custom_paint, false);
645  paint_proj_redraw(C, pop->custom_paint, true);
646  }
647  }
648  }
649  if (pop->mode == PAINT_MODE_3D_PROJECT) {
651  }
652  else {
654  }
655 
656  if (pop->cursor) {
658  }
659 
661 
662  /* duplicate warning, see texpaint_init */
663 #if 0
664  if (pop->s.warnmultifile) {
665  BKE_reportf(op->reports,
666  RPT_WARNING,
667  "Image requires 4 color channels to paint: %s",
668  pop->s.warnmultifile);
669  }
670  if (pop->s.warnpackedfile) {
671  BKE_reportf(op->reports,
672  RPT_WARNING,
673  "Packed MultiLayer files cannot be painted: %s",
674  pop->s.warnpackedfile);
675  }
676 #endif
677  MEM_freeN(pop);
678 }
679 
680 static bool paint_stroke_test_start(bContext *C, wmOperator *op, const float mouse[2])
681 {
682  PaintOperation *pop;
683 
684  /* TODO Should avoid putting this here. Instead, last position should be requested
685  * from stroke system. */
686 
687  if (!(pop = texture_paint_init(C, op, mouse))) {
688  return false;
689  }
690 
692 
693  return true;
694 }
695 
696 static int paint_invoke(bContext *C, wmOperator *op, const wmEvent *event)
697 {
698  int retval;
699 
701  op,
702  NULL,
707  event->type);
708 
709  if ((retval = op->type->modal(C, op, event)) == OPERATOR_FINISHED) {
710  paint_stroke_free(C, op);
711  return OPERATOR_FINISHED;
712  }
713  /* add modal handler */
715 
716  OPERATOR_RETVAL_CHECK(retval);
718 
719  return OPERATOR_RUNNING_MODAL;
720 }
721 
722 static int paint_exec(bContext *C, wmOperator *op)
723 {
724  PropertyRNA *strokeprop;
725  PointerRNA firstpoint;
726  float mouse[2];
727 
728  strokeprop = RNA_struct_find_property(op->ptr, "stroke");
729 
730  if (!RNA_property_collection_lookup_int(op->ptr, strokeprop, 0, &firstpoint)) {
731  return OPERATOR_CANCELLED;
732  }
733 
734  RNA_float_get_array(&firstpoint, "mouse", mouse);
735 
737  op,
738  NULL,
743  0);
744  /* frees op->customdata */
745  return paint_stroke_exec(C, op);
746 }
747 
749 {
750  /* identifiers */
751  ot->name = "Image Paint";
752  ot->idname = "PAINT_OT_image_paint";
753  ot->description = "Paint a stroke into the image";
754 
755  /* api callbacks */
758  ot->exec = paint_exec;
761 
762  /* flags */
764 
766 }
767 
768 bool get_imapaint_zoom(bContext *C, float *zoomx, float *zoomy)
769 {
771  if (area && area->spacetype == SPACE_IMAGE) {
772  SpaceImage *sima = area->spacedata.first;
773  if (sima->mode == SI_MODE_PAINT) {
774  ARegion *region = CTX_wm_region(C);
775  ED_space_image_get_zoom(sima, region, zoomx, zoomy);
776  return true;
777  }
778  }
779 
780  *zoomx = *zoomy = 1;
781 
782  return false;
783 }
784 
785 /************************ cursor drawing *******************************/
786 
787 static void toggle_paint_cursor(Scene *scene, bool enable)
788 {
789  ToolSettings *settings = scene->toolsettings;
790  Paint *p = &settings->imapaint.paint;
791 
792  if (p->paint_cursor && !enable) {
794  p->paint_cursor = NULL;
796  }
797  else if (enable) {
799  }
800 }
801 
802 /* enable the paint cursor if it isn't already.
803  *
804  * purpose is to make sure the paint cursor is shown if paint
805  * mode is enabled in the image editor. the paint poll will
806  * ensure that the cursor is hidden when not in paint mode */
808 {
809  ToolSettings *settings = scene->toolsettings;
810  ImagePaintSettings *imapaint = &settings->imapaint;
811  bool enabled = false;
812 
813  LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
814  bScreen *screen = WM_window_get_active_screen(win);
815 
816  LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
817  if (area->spacetype == SPACE_IMAGE) {
818  if (((SpaceImage *)area->spacedata.first)->mode == SI_MODE_PAINT) {
819  enabled = true;
820  }
821  }
822  }
823  }
824 
825  if (enabled) {
827 
829  }
830  else {
832  }
833 }
834 
835 /************************ grab clone operator ************************/
836 
837 typedef struct GrabClone {
838  float startoffset[2];
841 
843 {
844  Brush *brush = image_paint_brush(C);
845  float delta[2];
846 
847  RNA_float_get_array(op->ptr, "delta", delta);
848  add_v2_v2(brush->clone.offset, delta);
850 }
851 
853 {
854  grab_clone_apply(C, op);
855 
856  return OPERATOR_FINISHED;
857 }
858 
859 static int grab_clone_invoke(bContext *C, wmOperator *op, const wmEvent *event)
860 {
861  Brush *brush = image_paint_brush(C);
862  GrabClone *cmv;
863 
864  cmv = MEM_callocN(sizeof(GrabClone), "GrabClone");
865  copy_v2_v2(cmv->startoffset, brush->clone.offset);
866  cmv->startx = event->x;
867  cmv->starty = event->y;
868  op->customdata = cmv;
869 
871 
872  return OPERATOR_RUNNING_MODAL;
873 }
874 
875 static int grab_clone_modal(bContext *C, wmOperator *op, const wmEvent *event)
876 {
877  Brush *brush = image_paint_brush(C);
878  ARegion *region = CTX_wm_region(C);
879  GrabClone *cmv = op->customdata;
880  float startfx, startfy, fx, fy, delta[2];
881  int xmin = region->winrct.xmin, ymin = region->winrct.ymin;
882 
883  switch (event->type) {
884  case LEFTMOUSE:
885  case MIDDLEMOUSE:
886  case RIGHTMOUSE: /* XXX hardcoded */
887  MEM_freeN(op->customdata);
888  return OPERATOR_FINISHED;
889  case MOUSEMOVE:
890  /* mouse moved, so move the clone image */
892  &region->v2d, cmv->startx - xmin, cmv->starty - ymin, &startfx, &startfy);
893  UI_view2d_region_to_view(&region->v2d, event->x - xmin, event->y - ymin, &fx, &fy);
894 
895  delta[0] = fx - startfx;
896  delta[1] = fy - startfy;
897  RNA_float_set_array(op->ptr, "delta", delta);
898 
899  copy_v2_v2(brush->clone.offset, cmv->startoffset);
900 
901  grab_clone_apply(C, op);
902  break;
903  }
904 
905  return OPERATOR_RUNNING_MODAL;
906 }
907 
909 {
910  MEM_freeN(op->customdata);
911 }
912 
914 {
915  /* identifiers */
916  ot->name = "Grab Clone";
917  ot->idname = "PAINT_OT_grab_clone";
918  ot->description = "Move the clone source image";
919 
920  /* api callbacks */
926 
927  /* flags */
929 
930  /* properties */
932  "delta",
933  2,
934  NULL,
935  -FLT_MAX,
936  FLT_MAX,
937  "Delta",
938  "Delta offset of clone image in 0.0 to 1.0 coordinates",
939  -1.0f,
940  1.0f);
941 }
942 
943 /******************** sample color operator ********************/
944 typedef struct {
947  float initcolor[3];
950 
952 {
953  char msg[UI_MAX_DRAW_STR];
955 
956  if (area) {
957  BLI_snprintf(msg,
958  sizeof(msg),
959  TIP_("Sample color for %s"),
960  !data->sample_palette ?
961  TIP_("Brush. Use Left Click to sample for palette instead") :
962  TIP_("Palette. Use Left Click to sample more colors"));
964  }
965 }
966 
968 {
970  Brush *brush = BKE_paint_brush(paint);
972  ARegion *region = CTX_wm_region(C);
973  wmWindow *win = CTX_wm_window(C);
974  const bool show_cursor = ((paint->flags & PAINT_SHOW_BRUSH) != 0);
975  int location[2];
976  paint->flags &= ~PAINT_SHOW_BRUSH;
977 
978  /* force redraw without cursor */
979  WM_paint_cursor_tag_redraw(win, region);
981 
982  RNA_int_get_array(op->ptr, "location", location);
983  const bool use_palette = RNA_boolean_get(op->ptr, "palette");
984  const bool use_sample_texture = (mode == PAINT_MODE_TEXTURE_3D) &&
985  !RNA_boolean_get(op->ptr, "merged");
986 
987  paint_sample_color(C, region, location[0], location[1], use_sample_texture, use_palette);
988 
989  if (show_cursor) {
990  paint->flags |= PAINT_SHOW_BRUSH;
991  }
992 
994 
995  return OPERATOR_FINISHED;
996 }
997 
998 static int sample_color_invoke(bContext *C, wmOperator *op, const wmEvent *event)
999 {
1002  Brush *brush = BKE_paint_brush(paint);
1003  SampleColorData *data = MEM_mallocN(sizeof(SampleColorData), "sample color custom data");
1004  ARegion *region = CTX_wm_region(C);
1005  wmWindow *win = CTX_wm_window(C);
1006 
1007  data->launch_event = WM_userdef_event_type_from_keymap_type(event->type);
1008  data->show_cursor = ((paint->flags & PAINT_SHOW_BRUSH) != 0);
1009  copy_v3_v3(data->initcolor, BKE_brush_color_get(scene, brush));
1010  data->sample_palette = false;
1011  op->customdata = data;
1012  paint->flags &= ~PAINT_SHOW_BRUSH;
1013 
1015 
1017 
1018  /* force redraw without cursor */
1019  WM_paint_cursor_tag_redraw(win, region);
1021 
1022  RNA_int_set_array(op->ptr, "location", event->mval);
1023 
1025  const bool use_sample_texture = (mode == PAINT_MODE_TEXTURE_3D) &&
1026  !RNA_boolean_get(op->ptr, "merged");
1027 
1028  paint_sample_color(C, region, event->mval[0], event->mval[1], use_sample_texture, false);
1030 
1032 
1033  return OPERATOR_RUNNING_MODAL;
1034 }
1035 
1036 static int sample_color_modal(bContext *C, wmOperator *op, const wmEvent *event)
1037 {
1041  Brush *brush = BKE_paint_brush(paint);
1042 
1043  if ((event->type == data->launch_event) && (event->val == KM_RELEASE)) {
1044  if (data->show_cursor) {
1045  paint->flags |= PAINT_SHOW_BRUSH;
1046  }
1047 
1048  if (data->sample_palette) {
1049  BKE_brush_color_set(scene, brush, data->initcolor);
1050  RNA_boolean_set(op->ptr, "palette", true);
1051  }
1053  MEM_freeN(data);
1055 
1056  return OPERATOR_FINISHED;
1057  }
1058 
1060  const bool use_sample_texture = (mode == PAINT_MODE_TEXTURE_3D) &&
1061  !RNA_boolean_get(op->ptr, "merged");
1062 
1063  switch (event->type) {
1064  case MOUSEMOVE: {
1065  ARegion *region = CTX_wm_region(C);
1066  RNA_int_set_array(op->ptr, "location", event->mval);
1067  paint_sample_color(C, region, event->mval[0], event->mval[1], use_sample_texture, false);
1069  break;
1070  }
1071 
1072  case LEFTMOUSE:
1073  if (event->val == KM_PRESS) {
1074  ARegion *region = CTX_wm_region(C);
1075  RNA_int_set_array(op->ptr, "location", event->mval);
1076  paint_sample_color(C, region, event->mval[0], event->mval[1], use_sample_texture, true);
1077  if (!data->sample_palette) {
1078  data->sample_palette = true;
1080  }
1082  }
1083  break;
1084  }
1085 
1086  return OPERATOR_RUNNING_MODAL;
1087 }
1088 
1090 {
1092 }
1093 
1095 {
1096  /* identifiers */
1097  ot->name = "Sample Color";
1098  ot->idname = "PAINT_OT_sample_color";
1099  ot->description = "Use the mouse to sample a color in the image";
1100 
1101  /* api callbacks */
1106 
1107  /* flags */
1109 
1110  /* properties */
1111  PropertyRNA *prop;
1112 
1113  prop = RNA_def_int_vector(ot->srna, "location", 2, NULL, 0, INT_MAX, "Location", "", 0, 16384);
1115 
1116  RNA_def_boolean(ot->srna, "merged", 0, "Sample Merged", "Sample the output display color");
1117  RNA_def_boolean(ot->srna, "palette", 0, "Add to Palette", "");
1118 }
1119 
1120 /******************** texture paint toggle operator ********************/
1121 
1123 {
1124  Image *ima = NULL;
1126 
1127  /* This has to stay here to regenerate the texture paint
1128  * cache in case we are loading a file */
1130 
1132 
1133  /* entering paint mode also sets image to editors */
1134  if (imapaint->mode == IMAGEPAINT_MODE_MATERIAL) {
1135  /* set the current material active paint slot on image editor */
1136  Material *ma = BKE_object_material_get(ob, ob->actcol);
1137 
1138  if (ma && ma->texpaintslot) {
1139  ima = ma->texpaintslot[ma->paint_active_slot].ima;
1140  }
1141  }
1142  else if (imapaint->mode == IMAGEPAINT_MODE_IMAGE) {
1143  ima = imapaint->canvas;
1144  }
1145 
1146  if (ima) {
1147  wmWindowManager *wm = bmain->wm.first;
1148  for (wmWindow *win = wm->windows.first; win; win = win->next) {
1149  const bScreen *screen = WM_window_get_active_screen(win);
1150  for (ScrArea *area = screen->areabase.first; area; area = area->next) {
1151  SpaceLink *sl = area->spacedata.first;
1152  if (sl->spacetype == SPACE_IMAGE) {
1153  SpaceImage *sima = (SpaceImage *)sl;
1154 
1155  if (!sima->pin) {
1156  ED_space_image_set(bmain, sima, NULL, ima, true);
1157  }
1158  }
1159  }
1160  }
1161  }
1162 
1163  ob->mode |= OB_MODE_TEXTURE_PAINT;
1164 
1166 
1167  BKE_paint_toolslots_brush_validate(bmain, &imapaint->paint);
1168 
1169  if (U.glreslimit != 0) {
1171  }
1172  BKE_image_paint_set_mipmap(bmain, 0);
1173 
1174  toggle_paint_cursor(scene, true);
1175 
1176  Mesh *me = BKE_mesh_from_object(ob);
1177  BLI_assert(me != NULL);
1180 }
1181 
1183 {
1184  Main *bmain = CTX_data_main(C);
1188 }
1189 
1191 {
1192  ob->mode &= ~OB_MODE_TEXTURE_PAINT;
1193 
1194  if (U.glreslimit != 0) {
1196  }
1197  BKE_image_paint_set_mipmap(bmain, 1);
1198  toggle_paint_cursor(scene, false);
1199 
1200  Mesh *me = BKE_mesh_from_object(ob);
1201  BLI_assert(me != NULL);
1204 }
1205 
1207 {
1208  Main *bmain = CTX_data_main(C);
1212 }
1213 
1215 {
1217  if (ob == NULL || ob->type != OB_MESH) {
1218  return false;
1219  }
1220  if (!ob->data || ID_IS_LINKED(ob->data)) {
1221  return false;
1222  }
1223 
1224  return true;
1225 }
1226 
1228 {
1229  struct wmMsgBus *mbus = CTX_wm_message_bus(C);
1230  Main *bmain = CTX_data_main(C);
1233  const int mode_flag = OB_MODE_TEXTURE_PAINT;
1234  const bool is_mode_set = (ob->mode & mode_flag) != 0;
1235 
1236  if (!is_mode_set) {
1237  if (!ED_object_mode_compat_set(C, ob, mode_flag, op->reports)) {
1238  return OPERATOR_CANCELLED;
1239  }
1240  }
1241 
1242  if (ob->mode & mode_flag) {
1244  }
1245  else {
1247  }
1248 
1249  WM_msg_publish_rna_prop(mbus, &ob->id, ob, Object, mode);
1250 
1252 
1253  return OPERATOR_FINISHED;
1254 }
1255 
1257 {
1258  /* identifiers */
1259  ot->name = "Texture Paint Toggle";
1260  ot->idname = "PAINT_OT_texture_paint_toggle";
1261  ot->description = "Toggle texture paint mode in 3D view";
1262 
1263  /* api callbacks */
1266 
1267  /* flags */
1269 }
1270 
1272 {
1275 
1277  Brush *br = BKE_paint_brush(paint);
1278 
1279  if (ups->flag & UNIFIED_PAINT_COLOR) {
1280  swap_v3_v3(ups->rgb, ups->secondary_rgb);
1281  }
1282  else if (br) {
1283  swap_v3_v3(br->rgb, br->secondary_rgb);
1284  }
1285  else {
1286  return OPERATOR_CANCELLED;
1287  }
1288 
1290 
1291  return OPERATOR_FINISHED;
1292 }
1293 
1295 {
1296  if (image_paint_poll(C)) {
1297  Brush *br = image_paint_brush(C);
1299  return true;
1300  }
1301  }
1302  else {
1304  if (ob != NULL) {
1306  return true;
1307  }
1308  }
1309  }
1310  return false;
1311 }
1312 
1314 {
1315  /* identifiers */
1316  ot->name = "Swap Colors";
1317  ot->idname = "PAINT_OT_brush_colors_flip";
1318  ot->description = "Swap primary and secondary brush colors";
1319 
1320  /* api callbacks */
1323 
1324  /* flags */
1326 }
1327 
1329  float color[3],
1330  wmOperator *op,
1331  const int mouse[2])
1332 {
1333  SpaceImage *sima = CTX_wm_space_image(C);
1334 
1335  if (sima && sima->image) {
1336  Image *ima = sima->image;
1337 
1339 
1340  const float mouse_init[2] = {mouse[0], mouse[1]};
1341  paint_2d_bucket_fill(C, color, NULL, mouse_init, NULL, NULL);
1342 
1344 
1345  DEG_id_tag_update(&ima->id, 0);
1346  }
1347 }
1348 
1350 {
1353  return true;
1354  }
1355  }
1356 
1357  return false;
1358 }
1359 
1361 {
1362  return (texture_paint_poll(C) || image_paint_poll(C));
1363 }
1364 
1366 {
1368 }
1369 
1371 {
1373 }
1374 
1376 {
1378 }
void BKE_brush_alpha_set(struct Scene *scene, struct Brush *brush, float alpha)
Definition: brush.c:2313
const float * BKE_brush_secondary_color_get(const struct Scene *scene, const struct Brush *brush)
Definition: brush.c:2216
float BKE_brush_alpha_get(const struct Scene *scene, const struct Brush *brush)
const float * BKE_brush_color_get(const struct Scene *scene, const struct Brush *brush)
Definition: brush.c:2210
int BKE_brush_size_get(const struct Scene *scene, const struct Brush *brush)
void BKE_brush_color_set(struct Scene *scene, struct Brush *brush, const float color[3])
Definition: brush.c:2222
bool BKE_brush_use_alpha_pressure(const struct Brush *brush)
bool BKE_colorband_evaluate(const struct ColorBand *coba, float in, float out[4])
struct ScrArea * CTX_wm_area(const bContext *C)
Definition: context.c:714
struct Scene * CTX_data_scene(const bContext *C)
Definition: context.c:1034
struct wmWindowManager * CTX_wm_manager(const bContext *C)
Definition: context.c:689
struct ViewLayer * CTX_data_view_layer(const bContext *C)
Definition: context.c:1044
struct Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
Definition: context.c:1424
struct Object * CTX_data_active_object(const bContext *C)
Definition: context.c:1279
struct wmMsgBus * CTX_wm_message_bus(const bContext *C)
Definition: context.c:746
struct ARegion * CTX_wm_region(const bContext *C)
Definition: context.c:725
struct SpaceImage * CTX_wm_space_image(const bContext *C)
Definition: context.c:800
struct Main * CTX_data_main(const bContext *C)
Definition: context.c:1018
struct ToolSettings * CTX_data_tool_settings(const bContext *C)
Definition: context.c:1208
struct RegionView3D * CTX_wm_region_view3d(const bContext *C)
Definition: context.c:769
struct wmWindow * CTX_wm_window(const bContext *C)
Definition: context.c:699
void BKE_image_paint_set_mipmap(struct Main *bmain, bool mipmap)
Definition: image_gpu.c:914
void BKE_image_mark_dirty(struct Image *image, struct ImBuf *ibuf)
void BKE_image_free_all_gputextures(struct Main *bmain)
Definition: image_gpu.c:522
void BKE_image_update_gputexture(struct Image *ima, struct ImageUser *iuser, int x, int y, int w, int h)
Definition: image_gpu.c:821
General operations, lookup, etc. for materials.
struct Material * BKE_object_material_get(struct Object *ob, short act)
Definition: material.c:697
void BKE_texpaint_slots_refresh_object(struct Scene *scene, struct Object *ob)
Definition: material.c:1361
struct Mesh * BKE_mesh_from_object(struct Object *ob)
Definition: mesh.c:1271
void ntreeTexEndExecTree(struct bNodeTreeExec *exec)
struct bNodeTreeExec * ntreeTexBeginExecTree(struct bNodeTree *ntree)
bool BKE_paint_select_elem_test(struct Object *ob)
Definition: paint.c:987
ePaintMode BKE_paintmode_get_active_from_context(const struct bContext *C)
struct Brush * BKE_paint_brush(struct Paint *paint)
Definition: paint.c:604
void BKE_paint_init(struct Main *bmain, struct Scene *sce, ePaintMode mode, const char col[3])
Definition: paint.c:1115
struct Paint * BKE_paint_get_active_from_context(const struct bContext *C)
bool BKE_paint_select_vert_test(struct Object *ob)
Definition: paint.c:976
const char PAINT_CURSOR_TEXTURE_PAINT[3]
Definition: paint.c:235
bool BKE_paint_select_face_test(struct Object *ob)
Definition: paint.c:968
void BKE_paint_toolslots_brush_validate(struct Main *bmain, struct Paint *paint)
ePaintMode
Definition: BKE_paint.h:78
@ PAINT_MODE_TEXTURE_3D
Definition: BKE_paint.h:84
@ PAINT_MODE_TEXTURE_2D
Definition: BKE_paint.h:86
void BKE_reportf(ReportList *reports, ReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
#define BLI_assert(a)
Definition: BLI_assert.h:58
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:172
MINLINE float max_ff(float a, float b)
MINLINE int min_ii(int a, int b)
MINLINE int max_ii(int a, int b)
MINLINE void srgb_to_linearrgb_v3_v3(float linear[3], const float srgb[3])
MINLINE void copy_v2_v2(float r[2], const float a[2])
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void add_v2_v2(float r[2], const float a[2])
MINLINE void swap_v3_v3(float a[3], float b[3])
size_t BLI_snprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
unsigned int uint
Definition: BLI_sys_types.h:83
#define UNUSED(x)
#define ELEM(...)
#define TIP_(msgid)
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:51
void DEG_id_tag_update(struct ID *id, int flag)
@ ID_RECALC_COPY_ON_WRITE
Definition: DNA_ID.h:654
#define ID_IS_LINKED(_id)
Definition: DNA_ID.h:426
eBlurKernelType
@ KERNEL_BOX
@ KERNEL_GAUSSIAN
@ BRUSH_DRAG_DOT
@ BRUSH_ACCUMULATE
@ BRUSH_ANCHORED
@ BRUSH_USE_GRADIENT
@ BRUSH_AIRBRUSH
@ BRUSH_GRADIENT_SPACING_CLAMP
@ BRUSH_GRADIENT_PRESSURE
@ BRUSH_GRADIENT_SPACING_REPEAT
@ PAINT_TOOL_CLONE
@ PAINT_TOOL_SMEAR
@ PAINT_TOOL_SOFTEN
@ PAINT_TOOL_FILL
@ PAINT_TOOL_DRAW
@ OB_MODE_SCULPT
@ OB_MODE_TEXTURE_PAINT
@ OB_MODE_VERTEX_PAINT
Object is a sort of wrapper for general info.
@ OB_MESH
@ UNIFIED_PAINT_COLOR
@ PAINT_SHOW_BRUSH
@ IMAGEPAINT_MODE_IMAGE
@ IMAGEPAINT_MODE_MATERIAL
#define OBACT(_view_layer)
#define IMAGEPAINT_DRAWING
#define RGN_TYPE_ANY
@ RGN_TYPE_WINDOW
@ SPACE_IMAGE
@ SI_MODE_PAINT
#define SPACE_TYPE_ANY
#define MTEX_MAP_MODE_3D
#define MTEX_MAP_MODE_STENCIL
#define MTEX_MAP_MODE_TILED
@ OPERATOR_CANCELLED
@ OPERATOR_FINISHED
@ OPERATOR_RUNNING_MODAL
#define OPERATOR_RETVAL_CHECK(ret)
void ED_space_image_get_zoom(struct SpaceImage *sima, const struct ARegion *region, float *r_zoomx, float *r_zoomy)
void ED_space_image_set(struct Main *bmain, struct SpaceImage *sima, struct Object *obedit, struct Image *ima, bool automatic)
Definition: image_edit.c:60
bool ED_object_mode_compat_set(struct bContext *C, struct Object *ob, eObjectMode mode, struct ReportList *reports)
Definition: object_modes.c:165
void ED_paint_data_warning(struct ReportList *reports, bool uvs, bool mat, bool tex, bool stencil)
void ED_image_undo_push_begin(const char *name, int paint_mode)
Definition: image_undo.c:1066
void ED_image_undo_restore(struct UndoStep *us)
Definition: image_undo.c:1044
void ED_image_undo_push_end(void)
Definition: image_undo.c:1103
struct ListBase * ED_image_paint_tile_list_get(void)
Definition: image_undo.c:1027
bool ED_paint_proj_mesh_data_check(struct Scene *scene, struct Object *ob, bool *uvs, bool *mat, bool *tex, bool *stencil)
void * ED_image_paint_tile_push(struct ListBase *paint_tiles, struct Image *image, struct ImBuf *ibuf, struct ImBuf **tmpibuf, struct ImageUser *iuser, int x_tile, int y_tile, unsigned short **r_mask, bool **r_valid, bool use_thread_lock, bool find_prev)
Definition: image_undo.c:181
#define ED_IMAGE_UNDO_TILE_BITS
Definition: ED_paint.h:97
void ED_region_tag_redraw(struct ARegion *region)
Definition: area.c:667
void ED_workspace_status_text(struct bContext *C, const char *str)
Definition: area.c:840
void ED_view3d_viewcontext_init(struct bContext *C, struct ViewContext *vc, struct Depsgraph *depsgraph)
void immUnbindProgram(void)
void immBindBuiltinProgram(eGPUBuiltinShader shader_id)
void immVertex2i(uint attr_id, int x, int y)
void immUniformColor4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
GPUVertFormat * immVertexFormat(void)
void immBegin(GPUPrimType, uint vertex_len)
void immEnd(void)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
@ GPU_PRIM_LINES
Definition: GPU_primitive.h:36
@ GPU_SHADER_2D_UNIFORM_COLOR
Definition: GPU_shader.h:171
@ GPU_BLEND_NONE
Definition: GPU_state.h:55
@ GPU_BLEND_ALPHA
Definition: GPU_state.h:57
void GPU_blend(eGPUBlend blend)
Definition: gpu_state.cc:55
void GPU_line_width(float width)
Definition: gpu_state.cc:173
void GPU_line_smooth(bool enable)
Definition: gpu_state.cc:85
@ GPU_FETCH_INT_TO_FLOAT
uint GPU_vertformat_attr_add(GPUVertFormat *, const char *name, GPUVertCompType, uint comp_len, GPUVertFetchMode)
@ GPU_COMP_I32
void IMB_partial_display_buffer_update_delayed(struct ImBuf *ibuf, int xmin, int ymin, int xmax, int ymax)
void IMB_colormanagement_display_to_scene_linear_v3(float pixel[3], struct ColorManagedDisplay *display)
void IMB_colormanagement_scene_linear_to_srgb_v3(float pixel[3])
void IMB_rectclip(struct ImBuf *dbuf, const struct ImBuf *sbuf, int *destx, int *desty, int *srcx, int *srcy, int *width, int *height)
void IMB_freeImBuf(struct ImBuf *ibuf)
Definition: allocimbuf.c:211
Contains defines and structs used throughout the imbuf module.
@ IB_MIPMAP_INVALID
Read Guarded memory(de)allocation.
@ PROP_SKIP_SAVE
Definition: RNA_types.h:204
@ PROP_HIDDEN
Definition: RNA_types.h:202
#define C
Definition: RandGen.cpp:39
#define UI_MAX_DRAW_STR
Definition: UI_interface.h:90
void UI_view2d_region_to_view(const struct View2D *v2d, float x, float y, float *r_view_x, float *r_view_y) ATTR_NONNULL()
#define NC_BRUSH
Definition: WM_types.h:286
@ OPTYPE_BLOCKING
Definition: WM_types.h:157
@ OPTYPE_UNDO
Definition: WM_types.h:155
@ OPTYPE_REGISTER
Definition: WM_types.h:153
#define ND_MODE
Definition: WM_types.h:345
#define NC_SCENE
Definition: WM_types.h:279
#define ND_TOOLSETTINGS
Definition: WM_types.h:349
#define NA_EDITED
Definition: WM_types.h:462
#define KM_PRESS
Definition: WM_types.h:242
#define KM_RELEASE
Definition: WM_types.h:243
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
unsigned int U
Definition: btGjkEpa3.h:78
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition: btQuadWord.h:119
Scene scene
const Depsgraph * depsgraph
uint pos
bool enabled
format
Definition: logImageCore.h:47
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:45
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:47
INLINE Rall1d< T, V, S > exp(const Rall1d< T, V, S > &arg)
Definition: rall1d.h:295
static void area(int d1, int d2, int e1, int e2, float weights[2])
void paint_cursor_delete_textures(void)
Definition: paint_cursor.c:102
void paint_cursor_start(Paint *p, bool(*poll)(bContext *C))
void paint_delete_blur_kernel(BlurKernel *kernel)
Definition: paint_image.c:257
static void paint_stroke_update_step(bContext *C, struct PaintStroke *stroke, PointerRNA *itemptr)
Definition: paint_image.c:527
static bool image_paint_2d_clone_poll(bContext *C)
Definition: paint_image.c:316
static int texture_paint_toggle_exec(bContext *C, wmOperator *op)
Definition: paint_image.c:1227
BlurKernel * paint_new_blur_kernel(Brush *br, bool proj)
Definition: paint_image.c:191
static bool image_paint_poll_ex(bContext *C, bool check_tool)
Definition: paint_image.c:274
struct GrabClone GrabClone
static PaintOperation * texture_paint_init(bContext *C, wmOperator *op, const float mouse[2])
Definition: paint_image.c:479
void ED_imapaint_bucket_fill(struct bContext *C, float color[3], wmOperator *op, const int mouse[2])
Definition: paint_image.c:1328
static bool texture_paint_poll(bContext *C)
Definition: paint_image.c:1349
bool vert_paint_poll(bContext *C)
Definition: paint_image.c:1370
static int grab_clone_exec(bContext *C, wmOperator *op)
Definition: paint_image.c:852
void imapaint_image_update(SpaceImage *sima, Image *image, ImBuf *ibuf, ImageUser *iuser, short texpaint)
Definition: paint_image.c:167
static void paint_stroke_done(const bContext *C, struct PaintStroke *stroke)
Definition: paint_image.c:595
ImagePaintPartialRedraw * get_imapaintpartial(void)
Definition: paint_image.c:92
void paint_brush_init_tex(Brush *brush)
Definition: paint_image.c:409
static bool texture_paint_toggle_poll(bContext *C)
Definition: paint_image.c:1214
void ED_imapaint_dirty_region(Image *ima, ImBuf *ibuf, ImageUser *iuser, int x, int y, int w, int h, bool find_old)
Definition: paint_image.c:122
void ED_object_texture_paint_mode_exit_ex(Main *bmain, Scene *scene, Object *ob)
Definition: paint_image.c:1190
static int sample_color_exec(bContext *C, wmOperator *op)
Definition: paint_image.c:967
static Brush * image_paint_brush(bContext *C)
Definition: paint_image.c:266
static int grab_clone_modal(bContext *C, wmOperator *op, const wmEvent *event)
Definition: paint_image.c:875
void ED_object_texture_paint_mode_exit(bContext *C)
Definition: paint_image.c:1206
bool facemask_paint_poll(bContext *C)
Definition: paint_image.c:1365
bool image_texture_paint_poll(bContext *C)
Definition: paint_image.c:1360
void ED_imapaint_clear_partial_redraw(void)
Definition: paint_image.c:104
void ED_object_texture_paint_mode_enter_ex(Main *bmain, Scene *scene, Object *ob)
Definition: paint_image.c:1122
static bool image_paint_poll(bContext *C)
Definition: paint_image.c:306
void PAINT_OT_sample_color(wmOperatorType *ot)
Definition: paint_image.c:1094
void set_imapaintpartial(struct ImagePaintPartialRedraw *ippr)
Definition: paint_image.c:97
static void sample_color_update_header(SampleColorData *data, bContext *C)
Definition: paint_image.c:951
static ImagePaintPartialRedraw imapaintpartial
Definition: paint_image.c:90
void PAINT_OT_texture_paint_toggle(wmOperatorType *ot)
Definition: paint_image.c:1256
void ED_space_image_paint_update(Main *bmain, wmWindowManager *wm, Scene *scene)
Definition: paint_image.c:807
bool mask_paint_poll(bContext *C)
Definition: paint_image.c:1375
static int brush_colors_flip_exec(bContext *C, wmOperator *UNUSED(op))
Definition: paint_image.c:1271
static bool paint_stroke_test_start(bContext *C, wmOperator *op, const float mouse[2])
Definition: paint_image.c:680
bool paint_use_opacity_masking(Brush *brush)
Definition: paint_image.c:350
void paint_brush_color_get(struct Scene *scene, struct Brush *br, bool color_correction, bool invert, float distance, float pressure, float color[3], struct ColorManagedDisplay *display)
Definition: paint_image.c:365
static int grab_clone_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition: paint_image.c:859
struct PaintOperation PaintOperation
static void toggle_paint_cursor(Scene *scene, bool enable)
Definition: paint_image.c:787
static void grab_clone_cancel(bContext *UNUSED(C), wmOperator *op)
Definition: paint_image.c:908
void ED_object_texture_paint_mode_enter(bContext *C)
Definition: paint_image.c:1182
static void grab_clone_apply(bContext *C, wmOperator *op)
Definition: paint_image.c:842
void PAINT_OT_brush_colors_flip(wmOperatorType *ot)
Definition: paint_image.c:1313
bool get_imapaint_zoom(bContext *C, float *zoomx, float *zoomy)
Definition: paint_image.c:768
static bool brush_colors_flip_poll(bContext *C)
Definition: paint_image.c:1294
static int paint_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition: paint_image.c:696
void PAINT_OT_grab_clone(wmOperatorType *ot)
Definition: paint_image.c:913
void paint_brush_exit_tex(Brush *brush)
Definition: paint_image.c:425
static int sample_color_modal(bContext *C, wmOperator *op, const wmEvent *event)
Definition: paint_image.c:1036
static void gradient_draw_line(bContext *UNUSED(C), int x, int y, void *customdata)
Definition: paint_image.c:439
static bool sample_color_poll(bContext *C)
Definition: paint_image.c:1089
void imapaint_region_tiles(ImBuf *ibuf, int x, int y, int w, int h, int *tx, int *ty, int *tw, int *th)
Definition: paint_image.c:109
static bool image_paint_poll_ignore_tool(bContext *C)
Definition: paint_image.c:311
static int sample_color_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition: paint_image.c:998
void PAINT_OT_image_paint(wmOperatorType *ot)
Definition: paint_image.c:748
static int paint_exec(bContext *C, wmOperator *op)
Definition: paint_image.c:722
static void paint_stroke_redraw(const bContext *C, struct PaintStroke *stroke, bool final)
Definition: paint_image.c:583
eTexPaintMode
Definition: paint_image.c:332
@ PAINT_MODE_2D
Definition: paint_image.c:333
@ PAINT_MODE_3D_PROJECT
Definition: paint_image.c:334
void paint_2d_bucket_fill(const bContext *C, const float color[3], Brush *br, const float mouse_init[2], const float mouse_final[2], void *ps)
void paint_2d_gradient_fill(const bContext *C, Brush *br, const float mouse_init[2], const float mouse_final[2], void *ps)
void paint_2d_stroke_done(void *ps)
void paint_2d_stroke(void *ps, const float prev_mval[2], const float mval[2], const bool eraser, float pressure, float distance, float base_size)
void * paint_2d_new_stroke(bContext *C, wmOperator *op, int mode)
void paint_2d_redraw(const bContext *C, void *ps, bool final)
void * paint_proj_new_stroke(bContext *C, Object *ob, const float mouse[2], int mode)
void paint_proj_stroke(const bContext *C, void *ps_handle_p, const float prev_pos[2], const float pos[2], const bool eraser, float pressure, float distance, float size)
void paint_proj_redraw(const bContext *C, void *ps_handle_p, bool final)
void paint_proj_stroke_done(void *ps_handle_p)
bool paint_stroke_flipped(struct PaintStroke *stroke)
struct PaintStroke * paint_stroke_new(struct bContext *C, struct wmOperator *op, StrokeGetLocation get_location, StrokeTestStart test_start, StrokeUpdateStep update_step, StrokeRedraw redraw, StrokeDone done, int event_type)
Definition: paint_stroke.c:889
int paint_stroke_modal(struct bContext *C, struct wmOperator *op, const struct wmEvent *event)
bool vertex_paint_poll_ignore_tool(struct bContext *C)
Definition: paint_vertex.c:233
void paint_stroke_set_mode_data(struct PaintStroke *stroke, void *mode_data)
int paint_stroke_exec(struct bContext *C, struct wmOperator *op)
void paint_stroke_free(struct bContext *C, struct wmOperator *op)
Definition: paint_stroke.c:948
void * paint_stroke_mode_data(struct PaintStroke *stroke)
bool paint_stroke_inverted(struct PaintStroke *stroke)
void paint_sample_color(struct bContext *C, struct ARegion *region, int x, int y, bool texpaint_proj, bool palette)
Definition: paint_utils.c:453
void paint_stroke_cancel(struct bContext *C, struct wmOperator *op)
void paint_stroke_operator_properties(struct wmOperatorType *ot)
Definition: paint_utils.c:210
float paint_stroke_distance_get(struct PaintStroke *stroke)
void RNA_int_set_array(PointerRNA *ptr, const char *name, const int *values)
Definition: rna_access.c:6343
void RNA_int_get_array(PointerRNA *ptr, const char *name, int *values)
Definition: rna_access.c:6331
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
Definition: rna_access.c:6272
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
Definition: rna_access.c:866
int RNA_property_collection_lookup_int(PointerRNA *ptr, PropertyRNA *prop, int key, PointerRNA *r_ptr)
Definition: rna_access.c:4212
void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
Definition: rna_access.c:6378
float RNA_float_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6355
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6261
void RNA_float_set_array(PointerRNA *ptr, const char *name, const float *values)
Definition: rna_access.c:6390
int RNA_enum_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6402
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, bool default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3481
PropertyRNA * RNA_def_float_vector(StructOrFunctionRNA *cont_, const char *identifier, int len, const float *default_value, float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
Definition: rna_define.c:3851
PropertyRNA * RNA_def_int_vector(StructOrFunctionRNA *cont_, const char *identifier, int len, const int *default_value, int hardmin, int hardmax, const char *ui_name, const char *ui_description, int softmin, int softmax)
Definition: rna_define.c:3611
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1512
short regiontype
float * wdata
Definition: paint_intern.h:356
int side_squared
Definition: paint_intern.h:358
struct Image * image
float offset[2]
struct ColorBand * gradient
int blur_kernel_radius
struct BrushClone clone
struct MTex mtex
float rgb[3]
char imagepaint_tool
char gradient_stroke_mode
struct MTex mask_mtex
int gradient_spacing
float secondary_rgb[3]
int blur_mode
float startoffset[2]
Definition: paint_image.c:838
struct ImBuf * mipmap[IMB_MIPMAP_LEVELS]
int userflags
struct Image * canvas
void * first
Definition: DNA_listBase.h:47
char brush_map_mode
struct Tex * tex
Definition: BKE_main.h:116
ListBase wm
Definition: BKE_main.h:175
short paint_active_slot
struct TexPaintSlot * texpaintslot
void * data
double starttime
Definition: paint_image.c:344
float prevmouse[2]
Definition: paint_image.c:342
float startmouse[2]
Definition: paint_image.c:343
eTexPaintMode mode
Definition: paint_image.c:338
ViewContext vc
Definition: paint_image.c:347
void * custom_paint
Definition: paint_image.c:340
void * paint_cursor
struct ToolSettings * toolsettings
struct Image * image
struct Image * ima
struct bNodeTree * nodetree
struct ImagePaintSettings imapaint
struct UnifiedPaintSettings unified_paint_settings
struct UndoStep * step_init
struct ARegion * region
Definition: ED_view3d.h:80
struct bNodeTreeExec * execdata
ListBase areabase
int ymin
Definition: DNA_vec_types.h:80
int xmin
Definition: DNA_vec_types.h:79
int y
Definition: WM_types.h:581
short val
Definition: WM_types.h:579
int mval[2]
Definition: WM_types.h:583
int x
Definition: WM_types.h:581
short type
Definition: WM_types.h:577
int(* invoke)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:752
const char * name
Definition: WM_types.h:721
int(* modal)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:768
const char * idname
Definition: WM_types.h:723
bool(* poll)(struct bContext *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:776
void(* cancel)(struct bContext *, struct wmOperator *)
Definition: WM_types.h:760
struct StructRNA * srna
Definition: WM_types.h:802
const char * description
Definition: WM_types.h:726
int(* exec)(struct bContext *, struct wmOperator *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:736
struct ReportList * reports
struct wmOperatorType * type
struct PointerRNA * ptr
struct UndoStack * undo_stack
CCL_NAMESPACE_BEGIN ccl_device float invert(float color, float factor)
Definition: svm_invert.h:19
ccl_device_inline float distance(const float2 &a, const float2 &b)
void WM_cursor_modal_set(wmWindow *win, int val)
Definition: wm_cursors.c:207
void WM_cursor_modal_restore(wmWindow *win)
Definition: wm_cursors.c:216
@ WM_CURSOR_EYEDROPPER
Definition: wm_cursors.h:51
void WM_redraw_windows(bContext *C)
Definition: wm_draw.c:1105
void WM_paint_cursor_tag_redraw(wmWindow *win, ARegion *UNUSED(region))
Definition: wm_draw.c:1025
int WM_userdef_event_type_from_keymap_type(int kmitype)
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
void WM_main_add_notifier(unsigned int type, void *reference)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
@ RIGHTMOUSE
@ MOUSEMOVE
@ LEFTMOUSE
@ MIDDLEMOUSE
wmOperatorType * ot
Definition: wm_files.c:3156
#define WM_msg_publish_rna_prop(mbus, id_, data_, type_, prop_)
bool WM_paint_cursor_end(wmPaintCursor *handle)
wmPaintCursor * WM_paint_cursor_activate(short space_type, short region_type, bool(*poll)(bContext *C), wmPaintCursorDraw draw, void *customdata)
bool WM_toolsystem_active_tool_is_brush(const bContext *C)
void WM_toolsystem_update_from_context_view3d(bContext *C)
bScreen * WM_window_get_active_screen(const wmWindow *win)
Definition: wm_window.c:2372