Blender  V2.93
paint_ops.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  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #include "MEM_guardedalloc.h"
22 
23 #include "BLI_listbase.h"
24 #include "BLI_math_vector.h"
25 #include "BLI_string.h"
26 #include "BLI_utildefines.h"
27 #include <stdlib.h>
28 
29 #include "IMB_imbuf.h"
30 #include "IMB_imbuf_types.h"
31 
32 #include "DNA_brush_types.h"
33 #include "DNA_customdata_types.h"
34 #include "DNA_object_types.h"
35 #include "DNA_scene_types.h"
36 
37 #include "BKE_brush.h"
38 #include "BKE_context.h"
39 #include "BKE_image.h"
40 #include "BKE_lib_id.h"
41 #include "BKE_main.h"
42 #include "BKE_paint.h"
43 #include "BKE_report.h"
44 
45 #include "ED_image.h"
46 #include "ED_paint.h"
47 #include "ED_screen.h"
48 
49 #include "WM_api.h"
50 #include "WM_toolsystem.h"
51 #include "WM_types.h"
52 
53 #include "RNA_access.h"
54 #include "RNA_define.h"
55 
56 #include "paint_intern.h"
57 #include "sculpt_intern.h"
58 
59 #include <stddef.h>
60 #include <string.h>
61 
62 /* Brush operators */
64 {
65  /*int type = RNA_enum_get(op->ptr, "type");*/
67  Brush *br = BKE_paint_brush(paint);
68  Main *bmain = CTX_data_main(C);
70 
71  if (br) {
72  br = (Brush *)BKE_id_copy(bmain, &br->id);
73  }
74  else {
75  br = BKE_brush_add(bmain, "Brush", BKE_paint_object_mode_from_paintmode(mode));
76  }
77  id_us_min(&br->id); /* fake user only */
78 
79  BKE_paint_brush_set(paint, br);
80 
81  return OPERATOR_FINISHED;
82 }
83 
85 {
86  /* identifiers */
87  ot->name = "Add Brush";
88  ot->description = "Add brush by mode type";
89  ot->idname = "BRUSH_OT_add";
90 
91  /* api callbacks */
93 
94  /* flags */
96 }
97 
99 {
100  /*int type = RNA_enum_get(op->ptr, "type");*/
102  Paint *paint = &ts->gp_paint->paint;
103  Brush *br = BKE_paint_brush(paint);
104  Main *bmain = CTX_data_main(C);
105 
106  if (br) {
107  br = (Brush *)BKE_id_copy(bmain, &br->id);
108  }
109  else {
110  br = BKE_brush_add(bmain, "Brush", OB_MODE_PAINT_GPENCIL);
111 
112  /* Init grease pencil specific data. */
114  }
115 
116  id_us_min(&br->id); /* fake user only */
117 
118  BKE_paint_brush_set(paint, br);
119 
120  return OPERATOR_FINISHED;
121 }
122 
124 {
125  /* identifiers */
126  ot->name = "Add Drawing Brush";
127  ot->description = "Add brush for Grease Pencil";
128  ot->idname = "BRUSH_OT_add_gpencil";
129 
130  /* api callbacks */
132 
133  /* flags */
135 }
136 
138 {
141  Brush *brush = BKE_paint_brush(paint);
142  // Object *ob = CTX_data_active_object(C);
143  float scalar = RNA_float_get(op->ptr, "scalar");
144 
145  if (brush) {
146  /* pixel radius */
147  {
148  const int old_size = BKE_brush_size_get(scene, brush);
149  int size = (int)(scalar * old_size);
150 
151  if (abs(old_size - size) < U.pixelsize) {
152  if (scalar > 1) {
153  size += U.pixelsize;
154  }
155  else if (scalar < 1) {
156  size -= U.pixelsize;
157  }
158  }
159 
160  BKE_brush_size_set(scene, brush, size);
161  }
162 
163  /* unprojected radius */
164  {
165  float unprojected_radius = scalar * BKE_brush_unprojected_radius_get(scene, brush);
166 
167  if (unprojected_radius < 0.001f) { /* XXX magic number */
168  unprojected_radius = 0.001f;
169  }
170 
171  BKE_brush_unprojected_radius_set(scene, brush, unprojected_radius);
172  }
173 
175  }
176 
177  return OPERATOR_FINISHED;
178 }
179 
181 {
182  /* identifiers */
183  ot->name = "Scale Sculpt/Paint Brush Size";
184  ot->description = "Change brush size by a scalar";
185  ot->idname = "BRUSH_OT_scale_size";
186 
187  /* api callbacks */
189 
190  /* flags */
191  ot->flag = 0;
192 
193  RNA_def_float(ot->srna, "scalar", 1, 0, 2, "Scalar", "Factor to scale brush size by", 0, 2);
194 }
195 
196 /* Palette operators */
197 
199 {
201  Main *bmain = CTX_data_main(C);
202  Palette *palette;
203 
204  palette = BKE_palette_add(bmain, "Palette");
205 
206  BKE_paint_palette_set(paint, palette);
207 
208  return OPERATOR_FINISHED;
209 }
210 
212 {
213  /* identifiers */
214  ot->name = "Add New Palette";
215  ot->description = "Add new palette";
216  ot->idname = "PALETTE_OT_new";
217 
218  /* api callbacks */
220 
221  /* flags */
223 }
224 
225 static bool palette_poll(bContext *C)
226 {
228 
229  if (paint && paint->palette != NULL) {
230  return true;
231  }
232 
233  return false;
234 }
235 
237 {
240  Brush *brush = paint->brush;
242  Palette *palette = paint->palette;
243  PaletteColor *color;
244 
245  color = BKE_palette_color_add(palette);
246  palette->active_color = BLI_listbase_count(&palette->colors) - 1;
247 
248  if (ELEM(mode,
253  copy_v3_v3(color->rgb, BKE_brush_color_get(scene, brush));
254  color->value = 0.0;
255  }
256  else if (mode == PAINT_MODE_WEIGHT) {
257  zero_v3(color->rgb);
258  color->value = brush->weight;
259  }
260 
261  return OPERATOR_FINISHED;
262 }
263 
265 {
266  /* identifiers */
267  ot->name = "New Palette Color";
268  ot->description = "Add new color to active palette";
269  ot->idname = "PALETTE_OT_color_add";
270 
271  /* api callbacks */
273  ot->poll = palette_poll;
274  /* flags */
276 }
277 
279 {
281  Palette *palette = paint->palette;
282  PaletteColor *color = BLI_findlink(&palette->colors, palette->active_color);
283 
284  if (color) {
285  BKE_palette_color_remove(palette, color);
286  }
287 
288  return OPERATOR_FINISHED;
289 }
290 
292 {
293  /* identifiers */
294  ot->name = "Delete Palette Color";
295  ot->description = "Remove active color from palette";
296  ot->idname = "PALETTE_OT_color_delete";
297 
298  /* api callbacks */
300  ot->poll = palette_poll;
301  /* flags */
303 }
304 
305 /* --- Extract Palette from Image. */
307 {
309  if ((sl != NULL) && (sl->spacetype == SPACE_IMAGE)) {
311  Image *image = sima->image;
312  ImageUser iuser = sima->iuser;
313  return BKE_image_has_ibuf(image, &iuser);
314  }
315 
316  return false;
317 }
318 
320 {
321  const int threshold = RNA_int_get(op->ptr, "threshold");
322 
323  Main *bmain = CTX_data_main(C);
324  bool done = false;
325 
327  Image *image = sima->image;
328  ImageUser iuser = sima->iuser;
329  void *lock;
330  ImBuf *ibuf;
331  GHash *color_table = BLI_ghash_int_new(__func__);
332 
333  ibuf = BKE_image_acquire_ibuf(image, &iuser, &lock);
334 
335  if (ibuf && ibuf->rect) {
336  /* Extract all colors. */
337  const int range = (int)pow(10.0f, threshold);
338  for (int row = 0; row < ibuf->y; row++) {
339  for (int col = 0; col < ibuf->x; col++) {
340  float color[4];
341  IMB_sampleImageAtLocation(ibuf, (float)col, (float)row, false, color);
342  for (int i = 0; i < 3; i++) {
343  color[i] = truncf(color[i] * range) / range;
344  }
345 
346  uint key = rgb_to_cpack(color[0], color[1], color[2]);
347  if (!BLI_ghash_haskey(color_table, POINTER_FROM_INT(key))) {
348  BLI_ghash_insert(color_table, POINTER_FROM_INT(key), POINTER_FROM_INT(key));
349  }
350  }
351  }
352 
353  done = BKE_palette_from_hash(bmain, color_table, image->id.name + 2, false);
354  }
355 
356  /* Free memory. */
357  BLI_ghash_free(color_table, NULL, NULL);
358  BKE_image_release_ibuf(image, ibuf, lock);
359 
360  if (done) {
361  BKE_reportf(op->reports, RPT_INFO, "Palette created");
362  }
363 
364  return OPERATOR_FINISHED;
365 }
366 
368 {
369  PropertyRNA *prop;
370 
371  /* identifiers */
372  ot->name = "Extract Palette from Image";
373  ot->idname = "PALETTE_OT_extract_from_image";
374  ot->description = "Extract all colors used in Image and create a Palette";
375 
376  /* api callbacks */
379 
380  /* flags */
382 
383  /* properties */
384  prop = RNA_def_int(ot->srna, "threshold", 1, 1, 1, "Threshold", "", 1, 1);
386 }
387 
388 /* Sort Palette color by Hue and Saturation. */
390 {
391  const int type = RNA_enum_get(op->ptr, "type");
392 
394  Palette *palette = paint->palette;
395 
396  if (palette == NULL) {
397  return OPERATOR_CANCELLED;
398  }
399 
400  tPaletteColorHSV *color_array = NULL;
401  tPaletteColorHSV *col_elm = NULL;
402 
403  const int totcol = BLI_listbase_count(&palette->colors);
404 
405  if (totcol > 0) {
406  color_array = MEM_calloc_arrayN(totcol, sizeof(tPaletteColorHSV), __func__);
407  /* Put all colors in an array. */
408  int t = 0;
409  LISTBASE_FOREACH (PaletteColor *, color, &palette->colors) {
410  float h, s, v;
411  rgb_to_hsv(color->rgb[0], color->rgb[1], color->rgb[2], &h, &s, &v);
412  col_elm = &color_array[t];
413  copy_v3_v3(col_elm->rgb, color->rgb);
414  col_elm->value = color->value;
415  col_elm->h = h;
416  col_elm->s = s;
417  col_elm->v = v;
418  t++;
419  }
420  /* Sort */
421  if (type == 1) {
422  BKE_palette_sort_hsv(color_array, totcol);
423  }
424  else if (type == 2) {
425  BKE_palette_sort_svh(color_array, totcol);
426  }
427  else if (type == 3) {
428  BKE_palette_sort_vhs(color_array, totcol);
429  }
430  else {
431  BKE_palette_sort_luminance(color_array, totcol);
432  }
433 
434  /* Clear old color swatches. */
435  PaletteColor *color_next = NULL;
436  for (PaletteColor *color = palette->colors.first; color; color = color_next) {
437  color_next = color->next;
438  BKE_palette_color_remove(palette, color);
439  }
440 
441  /* Recreate swatches sorted. */
442  for (int i = 0; i < totcol; i++) {
443  col_elm = &color_array[i];
444  PaletteColor *palcol = BKE_palette_color_add(palette);
445  if (palcol) {
446  copy_v3_v3(palcol->rgb, col_elm->rgb);
447  }
448  }
449  }
450 
451  /* Free memory. */
452  if (totcol > 0) {
453  MEM_SAFE_FREE(color_array);
454  }
455 
457 
458  return OPERATOR_FINISHED;
459 }
460 
462 {
463  static const EnumPropertyItem sort_type[] = {
464  {1, "HSV", 0, "Hue, Saturation, Value", ""},
465  {2, "SVH", 0, "Saturation, Value, Hue", ""},
466  {3, "VHS", 0, "Value, Hue, Saturation", ""},
467  {4, "LUMINANCE", 0, "Luminance", ""},
468  {0, NULL, 0, NULL, NULL},
469  };
470 
471  /* identifiers */
472  ot->name = "Sort Palette";
473  ot->idname = "PALETTE_OT_sort";
474  ot->description = "Sort Palette Colors";
475 
476  /* api callbacks */
478  ot->poll = palette_poll;
479 
480  /* flags */
482 
483  ot->prop = RNA_def_enum(ot->srna, "type", sort_type, 1, "Type", "");
484 }
485 
486 /* Move colors in palette. */
488 {
490  Palette *palette = paint->palette;
491  PaletteColor *palcolor = BLI_findlink(&palette->colors, palette->active_color);
492 
493  if (palcolor == NULL) {
494  return OPERATOR_CANCELLED;
495  }
496 
497  const int direction = RNA_enum_get(op->ptr, "type");
498 
499  BLI_assert(ELEM(direction, -1, 0, 1)); /* we use value below */
500  if (BLI_listbase_link_move(&palette->colors, palcolor, direction)) {
501  palette->active_color += direction;
503  }
504 
505  return OPERATOR_FINISHED;
506 }
507 
509 {
510  static const EnumPropertyItem slot_move[] = {
511  {-1, "UP", 0, "Up", ""},
512  {1, "DOWN", 0, "Down", ""},
513  {0, NULL, 0, NULL, NULL},
514  };
515 
516  /* identifiers */
517  ot->name = "Move Palette Color";
518  ot->idname = "PALETTE_OT_color_move";
519  ot->description = "Move the active Color up/down in the list";
520 
521  /* api callbacks */
523  ot->poll = palette_poll;
524 
525  /* flags */
527 
528  ot->prop = RNA_def_enum(ot->srna, "type", slot_move, 0, "Type", "");
529 }
530 
531 /* Join Palette swatches. */
533 {
534  Main *bmain = CTX_data_main(C);
536  Palette *palette = paint->palette;
537  Palette *palette_join = NULL;
538  bool done = false;
539 
540  char name[MAX_ID_NAME - 2];
541  RNA_string_get(op->ptr, "palette", name);
542 
543  if ((palette == NULL) || (name[0] == '\0')) {
544  return OPERATOR_CANCELLED;
545  }
546 
547  palette_join = (Palette *)BKE_libblock_find_name(bmain, ID_PAL, name);
548  if (palette_join == NULL) {
549  return OPERATOR_CANCELLED;
550  }
551 
552  const int totcol = BLI_listbase_count(&palette_join->colors);
553 
554  if (totcol > 0) {
555  LISTBASE_FOREACH (PaletteColor *, color, &palette_join->colors) {
556  PaletteColor *palcol = BKE_palette_color_add(palette);
557  if (palcol) {
558  copy_v3_v3(palcol->rgb, color->rgb);
559  palcol->value = color->value;
560  done = true;
561  }
562  }
563  }
564 
565  if (done) {
566  /* Clear old color swatches. */
567  PaletteColor *color_next = NULL;
568  for (PaletteColor *color = palette_join->colors.first; color; color = color_next) {
569  color_next = color->next;
570  BKE_palette_color_remove(palette_join, color);
571  }
572 
573  /* Notifier. */
575  }
576 
577  return OPERATOR_FINISHED;
578 }
579 
581 {
582  /* identifiers */
583  ot->name = "Join Palette Swatches";
584  ot->idname = "PALETTE_OT_join";
585  ot->description = "Join Palette Swatches";
586 
587  /* api callbacks */
589  ot->poll = palette_poll;
590 
591  /* flags */
593 
594  /* properties */
595  RNA_def_string(ot->srna, "palette", NULL, MAX_ID_NAME - 2, "Palette", "Name of the Palette");
596 }
597 
599 {
601  Brush *brush = BKE_paint_brush(paint);
603 
604  if (!ob || !brush) {
605  return OPERATOR_CANCELLED;
606  }
607 
608  /* TODO: other modes */
609  if (ob->mode & OB_MODE_SCULPT) {
610  BKE_brush_sculpt_reset(brush);
611  }
612  else {
613  return OPERATOR_CANCELLED;
614  }
616 
617  return OPERATOR_FINISHED;
618 }
619 
621 {
622  /* identifiers */
623  ot->name = "Reset Brush";
624  ot->description = "Return brush to defaults based on current tool";
625  ot->idname = "BRUSH_OT_reset";
626 
627  /* api callbacks */
629 
630  /* flags */
632 }
633 
634 static int brush_tool(const Brush *brush, size_t tool_offset)
635 {
636  return *(((char *)brush) + tool_offset);
637 }
638 
639 static void brush_tool_set(const Brush *brush, size_t tool_offset, int tool)
640 {
641  *(((char *)brush) + tool_offset) = tool;
642 }
643 
644 static Brush *brush_tool_cycle(Main *bmain, Paint *paint, Brush *brush_orig, const int tool)
645 {
646  Brush *brush, *first_brush;
647 
648  if (!brush_orig && !(brush_orig = bmain->brushes.first)) {
649  return NULL;
650  }
651 
652  if (brush_tool(brush_orig, paint->runtime.tool_offset) != tool) {
653  /* If current brush's tool is different from what we need,
654  * start cycling from the beginning of the list.
655  * Such logic will activate the same exact brush not relating from
656  * which tool user requests other tool.
657  */
658 
659  /* Try to tool-slot first. */
660  first_brush = BKE_paint_toolslots_brush_get(paint, tool);
661  if (first_brush == NULL) {
662  first_brush = bmain->brushes.first;
663  }
664  }
665  else {
666  /* If user wants to switch to brush with the same tool as
667  * currently active brush do a cycling via all possible
668  * brushes with requested tool.
669  */
670  first_brush = brush_orig->id.next ? brush_orig->id.next : bmain->brushes.first;
671  }
672 
673  /* get the next brush with the active tool */
674  brush = first_brush;
675  do {
676  if ((brush->ob_mode & paint->runtime.ob_mode) &&
677  (brush_tool(brush, paint->runtime.tool_offset) == tool)) {
678  return brush;
679  }
680 
681  brush = brush->id.next ? brush->id.next : bmain->brushes.first;
682  } while (brush != first_brush);
683 
684  return NULL;
685 }
686 
687 static Brush *brush_tool_toggle(Main *bmain, Paint *paint, Brush *brush_orig, const int tool)
688 {
689  if (!brush_orig || brush_tool(brush_orig, paint->runtime.tool_offset) != tool) {
690  Brush *br;
691  /* if the current brush is not using the desired tool, look
692  * for one that is */
693  br = brush_tool_cycle(bmain, paint, brush_orig, tool);
694  /* store the previously-selected brush */
695  if (br) {
696  br->toggle_brush = brush_orig;
697  }
698 
699  return br;
700  }
701  if (brush_orig->toggle_brush) {
702  /* if current brush is using the desired tool, try to toggle
703  * back to the previously selected brush. */
704  return brush_orig->toggle_brush;
705  }
706  return NULL;
707 }
708 
710  Main *bmain,
711  Paint *paint,
712  const int tool,
713  const char *tool_name,
714  const bool create_missing,
715  const bool toggle)
716 {
717  Brush *brush, *brush_orig = BKE_paint_brush(paint);
718 
719  if (toggle) {
720  brush = brush_tool_toggle(bmain, paint, brush_orig, tool);
721  }
722  else {
723  brush = brush_tool_cycle(bmain, paint, brush_orig, tool);
724  }
725 
726  if (((brush == NULL) && create_missing) &&
727  ((brush_orig == NULL) || brush_tool(brush_orig, paint->runtime.tool_offset) != tool)) {
728  brush = BKE_brush_add(bmain, tool_name, paint->runtime.ob_mode);
729  id_us_min(&brush->id); /* fake user only */
730  brush_tool_set(brush, paint->runtime.tool_offset, tool);
731  brush->toggle_brush = brush_orig;
732  }
733 
734  if (brush) {
735  BKE_paint_brush_set(paint, brush);
737 
739 
740  /* Tool System
741  * This is needed for when there is a non-sculpt tool active (transform for e.g.).
742  * In case we are toggling (and the brush changed to the toggle_brush), we need to get the
743  * tool_name again. */
744  int tool_result = brush_tool(brush, paint->runtime.tool_offset);
746  const EnumPropertyItem *items = BKE_paint_get_tool_enum_from_paintmode(paint_mode);
747  RNA_enum_name_from_value(items, tool_result, &tool_name);
748 
749  char tool_id[MAX_NAME];
750  SNPRINTF(tool_id, "builtin_brush.%s", tool_name);
751  WM_toolsystem_ref_set_by_id(C, tool_id);
752 
753  return true;
754  }
755  return false;
756 }
757 
767 };
768 
770 {
771  Main *bmain = CTX_data_main(C);
773  const bool create_missing = RNA_boolean_get(op->ptr, "create_missing");
774  const bool toggle = RNA_boolean_get(op->ptr, "toggle");
775  const char *tool_name = "Brush";
776  int tool = 0;
777 
778  ePaintMode paint_mode = PAINT_MODE_INVALID;
779  for (int i = 0; i < ARRAY_SIZE(brush_select_paint_modes); i++) {
780  paint_mode = brush_select_paint_modes[i];
781  const char *op_prop_id = BKE_paint_get_tool_prop_id_from_paintmode(paint_mode);
782  PropertyRNA *prop = RNA_struct_find_property(op->ptr, op_prop_id);
783  if (RNA_property_is_set(op->ptr, prop)) {
784  tool = RNA_property_enum_get(op->ptr, prop);
785  break;
786  }
787  }
788 
789  if (paint_mode == PAINT_MODE_INVALID) {
790  return OPERATOR_CANCELLED;
791  }
792 
793  Paint *paint = BKE_paint_get_active_from_paintmode(scene, paint_mode);
794  if (paint == NULL) {
795  return OPERATOR_CANCELLED;
796  }
797  const EnumPropertyItem *items = BKE_paint_get_tool_enum_from_paintmode(paint_mode);
798  RNA_enum_name_from_value(items, tool, &tool_name);
799 
800  if (brush_generic_tool_set(C, bmain, paint, tool, tool_name, create_missing, toggle)) {
801  return OPERATOR_FINISHED;
802  }
803  return OPERATOR_CANCELLED;
804 }
805 
807 {
808  PropertyRNA *prop;
809 
810  /* identifiers */
811  ot->name = "Brush Select";
812  ot->description = "Select a paint mode's brush by tool type";
813  ot->idname = "PAINT_OT_brush_select";
814 
815  /* api callbacks */
817 
818  /* flags */
819  ot->flag = 0;
820 
821  /* props */
822  /* All properties are hidden, so as not to show the redo panel. */
823  for (int i = 0; i < ARRAY_SIZE(brush_select_paint_modes); i++) {
824  const ePaintMode paint_mode = brush_select_paint_modes[i];
825  const char *prop_id = BKE_paint_get_tool_prop_id_from_paintmode(paint_mode);
826  prop = RNA_def_enum(
827  ot->srna, prop_id, BKE_paint_get_tool_enum_from_paintmode(paint_mode), 0, prop_id, "");
829  }
830 
831  prop = RNA_def_boolean(
832  ot->srna, "toggle", 0, "Toggle", "Toggle between two brushes rather than cycling");
834  prop = RNA_def_boolean(ot->srna,
835  "create_missing",
836  0,
837  "Create Missing",
838  "If the requested brush type does not exist, create a new brush");
840 }
841 
842 /***** Stencil Control *****/
843 
844 typedef enum {
849 
850 typedef enum {
854 
855 typedef enum {
859 
860 typedef struct {
861  float init_mouse[2];
862  float init_spos[2];
863  float init_sdim[2];
864  float init_rot;
865  float init_angle;
866  float lenorig;
867  float area_size[2];
871  int mask;
873  float *dim_target;
874  float *rot_target;
875  float *pos_target;
878 
880 {
881  Brush *br = scd->br;
882  float mdiff[2];
883  if (scd->mask) {
886  scd->init_rot = br->mask_mtex.rot;
887 
889  scd->rot_target = &br->mask_mtex.rot;
890  scd->pos_target = br->mask_stencil_pos;
891 
892  sub_v2_v2v2(mdiff, scd->init_mouse, br->mask_stencil_pos);
893  }
894  else {
896  copy_v2_v2(scd->init_spos, br->stencil_pos);
897  scd->init_rot = br->mtex.rot;
898 
899  scd->dim_target = br->stencil_dimension;
900  scd->rot_target = &br->mtex.rot;
901  scd->pos_target = br->stencil_pos;
902 
903  sub_v2_v2v2(mdiff, scd->init_mouse, br->stencil_pos);
904  }
905 
906  scd->lenorig = len_v2(mdiff);
907 
908  scd->init_angle = atan2f(mdiff[1], mdiff[0]);
909 }
910 
911 static int stencil_control_invoke(bContext *C, wmOperator *op, const wmEvent *event)
912 {
914  Brush *br = BKE_paint_brush(paint);
915  const float mvalf[2] = {event->mval[0], event->mval[1]};
916  ARegion *region = CTX_wm_region(C);
917  StencilControlData *scd;
918  int mask = RNA_enum_get(op->ptr, "texmode");
919 
920  if (mask) {
922  return OPERATOR_CANCELLED;
923  }
924  }
925  else {
927  return OPERATOR_CANCELLED;
928  }
929  }
930 
931  scd = MEM_mallocN(sizeof(StencilControlData), "stencil_control");
932  scd->mask = mask;
933  scd->br = br;
934 
935  copy_v2_v2(scd->init_mouse, mvalf);
936 
937  stencil_set_target(scd);
938 
939  scd->mode = RNA_enum_get(op->ptr, "mode");
941  scd->area_size[0] = region->winx;
942  scd->area_size[1] = region->winy;
943 
944  op->customdata = scd;
946 
947  return OPERATOR_RUNNING_MODAL;
948 }
949 
951 {
952  copy_v2_v2(scd->dim_target, scd->init_sdim);
953  copy_v2_v2(scd->pos_target, scd->init_spos);
954  *scd->rot_target = scd->init_rot;
955 }
956 
958 {
959  StencilControlData *scd = op->customdata;
960 
961  stencil_restore(scd);
962  MEM_freeN(op->customdata);
963 }
964 
965 static void stencil_control_calculate(StencilControlData *scd, const int mval[2])
966 {
967 #define PIXEL_MARGIN 5
968 
969  float mdiff[2];
970  const float mvalf[2] = {mval[0], mval[1]};
971  switch (scd->mode) {
972  case STENCIL_TRANSLATE:
973  sub_v2_v2v2(mdiff, mvalf, scd->init_mouse);
974  add_v2_v2v2(scd->pos_target, scd->init_spos, mdiff);
975  CLAMP(scd->pos_target[0],
976  -scd->dim_target[0] + PIXEL_MARGIN,
977  scd->area_size[0] + scd->dim_target[0] - PIXEL_MARGIN);
978 
979  CLAMP(scd->pos_target[1],
980  -scd->dim_target[1] + PIXEL_MARGIN,
981  scd->area_size[1] + scd->dim_target[1] - PIXEL_MARGIN);
982 
983  break;
984  case STENCIL_SCALE: {
985  float len, factor;
986  sub_v2_v2v2(mdiff, mvalf, scd->pos_target);
987  len = len_v2(mdiff);
988  factor = len / scd->lenorig;
989  copy_v2_v2(mdiff, scd->init_sdim);
990  if (scd->constrain_mode != STENCIL_CONSTRAINT_Y) {
991  mdiff[0] = factor * scd->init_sdim[0];
992  }
993  if (scd->constrain_mode != STENCIL_CONSTRAINT_X) {
994  mdiff[1] = factor * scd->init_sdim[1];
995  }
996  clamp_v2(mdiff, 5.0f, 10000.0f);
997  copy_v2_v2(scd->dim_target, mdiff);
998  break;
999  }
1000  case STENCIL_ROTATE: {
1001  float angle;
1002  sub_v2_v2v2(mdiff, mvalf, scd->pos_target);
1003  angle = atan2f(mdiff[1], mdiff[0]);
1004  angle = scd->init_rot + angle - scd->init_angle;
1005  if (angle < 0.0f) {
1006  angle += (float)(2 * M_PI);
1007  }
1008  if (angle > (float)(2 * M_PI)) {
1009  angle -= (float)(2 * M_PI);
1010  }
1011  *scd->rot_target = angle;
1012  break;
1013  }
1014  }
1015 #undef PIXEL_MARGIN
1016 }
1017 
1018 static int stencil_control_modal(bContext *C, wmOperator *op, const wmEvent *event)
1019 {
1020  StencilControlData *scd = op->customdata;
1021 
1022  if (event->type == scd->launch_event && event->val == KM_RELEASE) {
1023  MEM_freeN(op->customdata);
1025  return OPERATOR_FINISHED;
1026  }
1027 
1028  switch (event->type) {
1029  case MOUSEMOVE:
1030  stencil_control_calculate(scd, event->mval);
1031  break;
1032  case EVT_ESCKEY:
1033  if (event->val == KM_PRESS) {
1036  return OPERATOR_CANCELLED;
1037  }
1038  break;
1039  case EVT_XKEY:
1040  if (event->val == KM_PRESS) {
1041 
1042  if (scd->constrain_mode == STENCIL_CONSTRAINT_X) {
1043  scd->constrain_mode = 0;
1044  }
1045  else {
1047  }
1048 
1049  stencil_control_calculate(scd, event->mval);
1050  }
1051  break;
1052  case EVT_YKEY:
1053  if (event->val == KM_PRESS) {
1054  if (scd->constrain_mode == STENCIL_CONSTRAINT_Y) {
1055  scd->constrain_mode = 0;
1056  }
1057  else {
1059  }
1060 
1061  stencil_control_calculate(scd, event->mval);
1062  }
1063  break;
1064  default:
1065  break;
1066  }
1067 
1069 
1070  return OPERATOR_RUNNING_MODAL;
1071 }
1072 
1074 {
1076 
1077  Paint *paint;
1078  Brush *br;
1079 
1080  if (!paint_supports_texture(mode)) {
1081  return false;
1082  }
1083 
1085  br = BKE_paint_brush(paint);
1086  return (br && (br->mtex.brush_map_mode == MTEX_MAP_MODE_STENCIL ||
1088 }
1089 
1091 {
1092  static const EnumPropertyItem stencil_control_items[] = {
1093  {STENCIL_TRANSLATE, "TRANSLATION", 0, "Translation", ""},
1094  {STENCIL_SCALE, "SCALE", 0, "Scale", ""},
1095  {STENCIL_ROTATE, "ROTATION", 0, "Rotation", ""},
1096  {0, NULL, 0, NULL, NULL},
1097  };
1098 
1099  static const EnumPropertyItem stencil_texture_items[] = {
1100  {STENCIL_PRIMARY, "PRIMARY", 0, "Primary", ""},
1101  {STENCIL_SECONDARY, "SECONDARY", 0, "Secondary", ""},
1102  {0, NULL, 0, NULL, NULL},
1103  };
1104  /* identifiers */
1105  ot->name = "Stencil Brush Control";
1106  ot->description = "Control the stencil brush";
1107  ot->idname = "BRUSH_OT_stencil_control";
1108 
1109  /* api callbacks */
1114 
1115  /* flags */
1116  ot->flag = 0;
1117 
1118  PropertyRNA *prop;
1119  prop = RNA_def_enum(ot->srna, "mode", stencil_control_items, STENCIL_TRANSLATE, "Tool", "");
1121  prop = RNA_def_enum(ot->srna, "texmode", stencil_texture_items, STENCIL_PRIMARY, "Tool", "");
1123 }
1124 
1126 {
1128  Brush *br = BKE_paint_brush(paint);
1129  bool use_scale = RNA_boolean_get(op->ptr, "use_scale");
1130  bool use_repeat = RNA_boolean_get(op->ptr, "use_repeat");
1131  bool do_mask = RNA_boolean_get(op->ptr, "mask");
1132  Tex *tex = NULL;
1133  MTex *mtex = NULL;
1134  if (br) {
1135  mtex = do_mask ? &br->mask_mtex : &br->mtex;
1136  tex = mtex->tex;
1137  }
1138 
1139  if (tex && tex->type == TEX_IMAGE && tex->ima) {
1140  float aspx, aspy;
1141  Image *ima = tex->ima;
1142  float orig_area, stencil_area, factor;
1143  ED_image_get_uv_aspect(ima, NULL, &aspx, &aspy);
1144 
1145  if (use_scale) {
1146  aspx *= mtex->size[0];
1147  aspy *= mtex->size[1];
1148  }
1149 
1150  if (use_repeat && tex->extend == TEX_REPEAT) {
1151  aspx *= tex->xrepeat;
1152  aspy *= tex->yrepeat;
1153  }
1154 
1155  orig_area = fabsf(aspx * aspy);
1156 
1157  if (do_mask) {
1158  stencil_area = fabsf(br->mask_stencil_dimension[0] * br->mask_stencil_dimension[1]);
1159  }
1160  else {
1161  stencil_area = fabsf(br->stencil_dimension[0] * br->stencil_dimension[1]);
1162  }
1163 
1164  factor = sqrtf(stencil_area / orig_area);
1165 
1166  if (do_mask) {
1167  br->mask_stencil_dimension[0] = fabsf(factor * aspx);
1168  br->mask_stencil_dimension[1] = fabsf(factor * aspy);
1169  }
1170  else {
1171  br->stencil_dimension[0] = fabsf(factor * aspx);
1172  br->stencil_dimension[1] = fabsf(factor * aspy);
1173  }
1174  }
1175 
1177 
1178  return OPERATOR_FINISHED;
1179 }
1180 
1182 {
1183  /* identifiers */
1184  ot->name = "Image Aspect";
1185  ot->description =
1186  "When using an image texture, adjust the stencil size to fit the image aspect ratio";
1187  ot->idname = "BRUSH_OT_stencil_fit_image_aspect";
1188 
1189  /* api callbacks */
1192 
1193  /* flags */
1195 
1196  RNA_def_boolean(ot->srna, "use_repeat", 1, "Use Repeat", "Use repeat mapping values");
1197  RNA_def_boolean(ot->srna, "use_scale", 1, "Use Scale", "Use texture scale values");
1199  ot->srna, "mask", 0, "Modify Mask Stencil", "Modify either the primary or mask stencil");
1200 }
1201 
1203 {
1205  Brush *br = BKE_paint_brush(paint);
1206  bool do_mask = RNA_boolean_get(op->ptr, "mask");
1207 
1208  if (!br) {
1209  return OPERATOR_CANCELLED;
1210  }
1211 
1212  if (do_mask) {
1213  br->mask_stencil_pos[0] = 256;
1214  br->mask_stencil_pos[1] = 256;
1215 
1216  br->mask_stencil_dimension[0] = 256;
1217  br->mask_stencil_dimension[1] = 256;
1218 
1219  br->mask_mtex.rot = 0;
1220  }
1221  else {
1222  br->stencil_pos[0] = 256;
1223  br->stencil_pos[1] = 256;
1224 
1225  br->stencil_dimension[0] = 256;
1226  br->stencil_dimension[1] = 256;
1227 
1228  br->mtex.rot = 0;
1229  }
1230 
1232 
1233  return OPERATOR_FINISHED;
1234 }
1235 
1237 {
1238  /* identifiers */
1239  ot->name = "Reset Transform";
1240  ot->description = "Reset the stencil transformation to the default";
1241  ot->idname = "BRUSH_OT_stencil_reset_transform";
1242 
1243  /* api callbacks */
1246 
1247  /* flags */
1249 
1251  ot->srna, "mask", 0, "Modify Mask Stencil", "Modify either the primary or mask stencil");
1252 }
1253 
1254 /**************************** registration **********************************/
1255 
1257 {
1258  wmOperatorType *ot;
1259  wmOperatorTypeMacro *otmacro;
1260 
1261  ot = WM_operatortype_append_macro("PAINTCURVE_OT_add_point_slide",
1262  "Add Curve Point and Slide",
1263  "Add new curve point and slide it",
1264  OPTYPE_UNDO);
1265  ot->description = "Add new curve point and slide it";
1266  WM_operatortype_macro_define(ot, "PAINTCURVE_OT_add_point");
1267  otmacro = WM_operatortype_macro_define(ot, "PAINTCURVE_OT_slide");
1268  RNA_boolean_set(otmacro->ptr, "align", true);
1269  RNA_boolean_set(otmacro->ptr, "select", false);
1270 }
1271 
1273 {
1274  /* palette */
1278 
1283 
1284  /* paint curve */
1292 
1293  /* brush */
1302 
1303  /* note, particle uses a different system, can be added with existing operators in wm.py */
1305 
1306  /* image */
1316 
1317  /* weight */
1325 
1326  /* uv */
1328 
1329  /* vertex selection */
1332 
1333  /* vertex */
1338 
1344 
1345  /* face-select */
1351 
1352  /* partial visibility */
1354 
1355  /* paint masking */
1360 }
1361 
1363 {
1364  wmKeyMap *keymap;
1365 
1366  keymap = WM_keymap_ensure(keyconf, "Paint Curve", 0, 0);
1367  keymap->poll = paint_curve_poll;
1368 
1369  /* Sculpt mode */
1370  keymap = WM_keymap_ensure(keyconf, "Sculpt", 0, 0);
1371  keymap->poll = SCULPT_mode_poll;
1372 
1373  /* Vertex Paint mode */
1374  keymap = WM_keymap_ensure(keyconf, "Vertex Paint", 0, 0);
1375  keymap->poll = vertex_paint_mode_poll;
1376 
1377  /* Weight Paint mode */
1378  keymap = WM_keymap_ensure(keyconf, "Weight Paint", 0, 0);
1379  keymap->poll = weight_paint_mode_poll;
1380 
1381  /*Weight paint's Vertex Selection Mode */
1382  keymap = WM_keymap_ensure(keyconf, "Paint Vertex Selection (Weight, Vertex)", 0, 0);
1383  keymap->poll = vert_paint_poll;
1384 
1385  /* Image/Texture Paint mode */
1386  keymap = WM_keymap_ensure(keyconf, "Image Paint", 0, 0);
1387  keymap->poll = image_texture_paint_poll;
1388 
1389  /* face-mask mode */
1390  keymap = WM_keymap_ensure(keyconf, "Paint Face Mask (Weight, Vertex, Texture)", 0, 0);
1391  keymap->poll = facemask_paint_poll;
1392 
1393  /* paint stroke */
1394  keymap = paint_stroke_modal_keymap(keyconf);
1395  WM_modalkeymap_assign(keymap, "SCULPT_OT_brush_stroke");
1396 
1397  /* sculpt expand. */
1398  sculpt_expand_modal_keymap(keyconf);
1399 }
typedef float(TangentPoint)[2]
void BKE_brush_size_set(struct Scene *scene, struct Brush *brush, int size)
Definition: brush.c:2234
void BKE_brush_init_gpencil_settings(struct Brush *brush)
Definition: brush.c:504
const float * BKE_brush_color_get(const struct Scene *scene, const struct Brush *brush)
Definition: brush.c:2210
void BKE_brush_sculpt_reset(struct Brush *brush)
Definition: brush.c:1677
int BKE_brush_size_get(const struct Scene *scene, const struct Brush *brush)
float BKE_brush_unprojected_radius_get(const struct Scene *scene, const struct Brush *brush)
void BKE_brush_unprojected_radius_set(struct Scene *scene, struct Brush *brush, float unprojected_radius)
Definition: brush.c:2294
struct Brush * BKE_brush_add(struct Main *bmain, const char *name, const eObjectMode ob_mode)
Definition: brush.c:492
struct Scene * CTX_data_scene(const bContext *C)
Definition: context.c:1034
struct Object * CTX_data_active_object(const bContext *C)
Definition: context.c:1279
struct SpaceLink * CTX_wm_space_data(const bContext *C)
Definition: context.c:719
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
void BKE_image_release_ibuf(struct Image *ima, struct ImBuf *ibuf, void *lock)
Definition: image.c:5113
bool BKE_image_has_ibuf(struct Image *ima, struct ImageUser *iuser)
Definition: image.c:5134
struct ImBuf * BKE_image_acquire_ibuf(struct Image *ima, struct ImageUser *iuser, void **r_lock)
Definition: image.c:5100
struct ID * BKE_id_copy(struct Main *bmain, const struct ID *id)
void id_us_min(struct ID *id)
Definition: lib_id.c:297
struct ID * BKE_libblock_find_name(struct Main *bmain, const short type, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: lib_id.c:1333
eObjectMode BKE_paint_object_mode_from_paintmode(ePaintMode mode)
Definition: paint.c:1009
void BKE_paint_brush_set(struct Paint *paint, struct Brush *br)
Definition: paint.c:609
struct Palette * BKE_palette_add(struct Main *bmain, const char *name)
Definition: paint.c:751
void BKE_palette_sort_svh(struct tPaletteColorHSV *color_array, const int totcol)
Definition: paint.c:887
struct Paint * BKE_paint_get_active_from_paintmode(struct Scene *sce, ePaintMode mode)
Definition: paint.c:354
ePaintMode BKE_paintmode_get_active_from_context(const struct bContext *C)
void BKE_palette_sort_luminance(struct tPaletteColorHSV *color_array, const int totcol)
Definition: paint.c:899
struct Brush * BKE_paint_toolslots_brush_get(struct Paint *paint, int slot_index)
struct Brush * BKE_paint_brush(struct Paint *paint)
Definition: paint.c:604
bool BKE_palette_from_hash(struct Main *bmain, struct GHash *color_table, const char *name, const bool linear)
Definition: paint.c:905
void BKE_paint_palette_set(struct Paint *p, struct Palette *palette)
Definition: paint.c:705
void BKE_palette_color_remove(struct Palette *palette, struct PaletteColor *color)
Definition: paint.c:729
struct Paint * BKE_paint_get_active_from_context(const struct bContext *C)
const struct EnumPropertyItem * BKE_paint_get_tool_enum_from_paintmode(ePaintMode mode)
Definition: paint.c:389
void BKE_palette_sort_vhs(struct tPaletteColorHSV *color_array, const int totcol)
Definition: paint.c:893
void BKE_palette_sort_hsv(struct tPaletteColorHSV *color_array, const int totcol)
Definition: paint.c:881
void BKE_paint_invalidate_overlay_all(void)
Definition: paint.c:272
ePaintMode
Definition: BKE_paint.h:78
@ PAINT_MODE_INVALID
Definition: BKE_paint.h:95
@ PAINT_MODE_GPENCIL
Definition: BKE_paint.h:88
@ PAINT_MODE_VERTEX_GPENCIL
Definition: BKE_paint.h:90
@ PAINT_MODE_TEXTURE_3D
Definition: BKE_paint.h:84
@ PAINT_MODE_WEIGHT_GPENCIL
Definition: BKE_paint.h:92
@ PAINT_MODE_SCULPT
Definition: BKE_paint.h:79
@ PAINT_MODE_SCULPT_GPENCIL
Definition: BKE_paint.h:91
@ PAINT_MODE_WEIGHT
Definition: BKE_paint.h:82
@ PAINT_MODE_TEXTURE_2D
Definition: BKE_paint.h:86
@ PAINT_MODE_VERTEX
Definition: BKE_paint.h:81
const char * BKE_paint_get_tool_prop_id_from_paintmode(ePaintMode mode)
Definition: paint.c:417
struct PaletteColor * BKE_palette_color_add(struct Palette *palette)
Definition: paint.c:757
void BKE_reportf(ReportList *reports, ReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
#define BLI_assert(a)
Definition: BLI_assert.h:58
bool BLI_ghash_haskey(GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
Definition: BLI_ghash.c:941
GHash * BLI_ghash_int_new(const char *info) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
void BLI_ghash_insert(GHash *gh, void *key, void *val)
Definition: BLI_ghash.c:756
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition: BLI_ghash.c:1008
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:172
void void void bool BLI_listbase_link_move(ListBase *listbase, void *vlink, int step) ATTR_NONNULL()
Definition: listbase.c:475
void * BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
int BLI_listbase_count(const struct ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
#define M_PI
Definition: BLI_math_base.h:38
unsigned int rgb_to_cpack(float r, float g, float b)
Definition: math_color.c:379
void rgb_to_hsv(float r, float g, float b, float *r_h, float *r_s, float *r_v)
Definition: math_color.c:229
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 clamp_v2(float vec[2], const float min, const float max)
MINLINE void add_v2_v2v2(float r[2], const float a[2], const float b[2])
MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2])
MINLINE float len_v2(const float a[2]) ATTR_WARN_UNUSED_RESULT
MINLINE void zero_v3(float r[3])
#define SNPRINTF(dst, format,...)
Definition: BLI_string.h:165
unsigned int uint
Definition: BLI_sys_types.h:83
#define ARRAY_SIZE(arr)
#define POINTER_FROM_INT(i)
#define UNUSED(x)
#define ELEM(...)
#define MAX_ID_NAME
Definition: DNA_ID.h:269
@ ID_PAL
Definition: DNA_ID_enums.h:88
#define MAX_NAME
Definition: DNA_defs.h:62
@ OB_MODE_SCULPT
@ OB_MODE_PAINT_GPENCIL
Object is a sort of wrapper for general info.
@ SPACE_IMAGE
#define TEX_REPEAT
#define MTEX_MAP_MODE_STENCIL
@ OPERATOR_CANCELLED
@ OPERATOR_FINISHED
@ OPERATOR_RUNNING_MODAL
void ED_image_get_uv_aspect(struct Image *ima, struct ImageUser *iuser, float *r_aspx, float *r_aspy)
Definition: image_edit.c:302
void ED_region_tag_redraw(struct ARegion *region)
Definition: area.c:667
_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 GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
void IMB_sampleImageAtLocation(struct ImBuf *ibuf, float x, float y, bool make_linear_rgb, float color[4])
Definition: imageprocess.c:505
Contains defines and structs used throughout the imbuf module.
Read Guarded memory(de)allocation.
#define MEM_SAFE_FREE(v)
Group RGB to Bright Vector Camera CLAMP
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume TEX_IMAGE
@ PROP_SKIP_SAVE
Definition: RNA_types.h:204
@ PROP_HIDDEN
Definition: RNA_types.h:202
#define C
Definition: RandGen.cpp:39
#define NC_WINDOW
Definition: WM_types.h:277
#define NC_BRUSH
Definition: WM_types.h:286
@ OPTYPE_UNDO
Definition: WM_types.h:155
@ OPTYPE_REGISTER
Definition: WM_types.h:153
#define NA_EDITED
Definition: WM_types.h:462
#define KM_PRESS
Definition: WM_types.h:242
#define KM_RELEASE
Definition: WM_types.h:243
ATTR_WARN_UNUSED_RESULT const BMVert * v
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
unsigned int U
Definition: btGjkEpa3.h:78
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition: btVector3.h:356
Scene scene
uint col
#define atan2f(x, y)
#define fabsf(x)
#define sqrtf(x)
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
void *(* MEM_calloc_arrayN)(size_t len, size_t size, const char *str)
Definition: mallocn.c:46
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:47
INLINE Rall1d< T, V, S > pow(const Rall1d< T, V, S > &arg, double m)
Definition: rall1d.h:359
bool paint_curve_poll(bContext *C)
Definition: paint_curve.c:54
void PAINTCURVE_OT_new(wmOperatorType *ot)
Definition: paint_curve.c:172
void PAINTCURVE_OT_add_point(wmOperatorType *ot)
Definition: paint_curve.c:270
void PAINTCURVE_OT_delete_point(wmOperatorType *ot)
Definition: paint_curve.c:362
void PAINTCURVE_OT_draw(wmOperatorType *ot)
Definition: paint_curve.c:700
void PAINTCURVE_OT_cursor(wmOperatorType *ot)
Definition: paint_curve.c:743
void PAINTCURVE_OT_slide(wmOperatorType *ot)
Definition: paint_curve.c:652
void PAINTCURVE_OT_select(wmOperatorType *ot)
Definition: paint_curve.c:506
void PAINT_OT_hide_show(struct wmOperatorType *ot)
Definition: paint_hide.c:421
bool vert_paint_poll(bContext *C)
Definition: paint_image.c:1370
bool facemask_paint_poll(bContext *C)
Definition: paint_image.c:1365
bool image_texture_paint_poll(bContext *C)
Definition: paint_image.c:1360
void PAINT_OT_sample_color(wmOperatorType *ot)
Definition: paint_image.c:1094
void PAINT_OT_texture_paint_toggle(wmOperatorType *ot)
Definition: paint_image.c:1256
void PAINT_OT_brush_colors_flip(wmOperatorType *ot)
Definition: paint_image.c:1313
void PAINT_OT_grab_clone(wmOperatorType *ot)
Definition: paint_image.c:913
void PAINT_OT_image_paint(wmOperatorType *ot)
Definition: paint_image.c:748
void PAINT_OT_add_texture_paint_slot(wmOperatorType *ot)
void PAINT_OT_add_simple_uvs(wmOperatorType *ot)
void PAINT_OT_project_image(wmOperatorType *ot)
void PAINT_OT_image_from_view(wmOperatorType *ot)
bool vertex_paint_mode_poll(struct bContext *C)
Definition: paint_vertex.c:205
void PAINT_OT_vertex_color_set(struct wmOperatorType *ot)
void PAINT_OT_weight_from_bones(struct wmOperatorType *ot)
void PAINT_OT_face_select_linked_pick(struct wmOperatorType *ot)
Definition: paint_utils.c:689
void PAINT_OT_mask_line_gesture(struct wmOperatorType *ot)
Definition: paint_mask.c:1685
void PAINT_OT_weight_set(struct wmOperatorType *ot)
void PAINT_OT_face_select_hide(struct wmOperatorType *ot)
Definition: paint_utils.c:792
void PAINT_OT_mask_lasso_gesture(struct wmOperatorType *ot)
Definition: paint_mask.c:1643
void PAINT_OT_weight_paint_toggle(struct wmOperatorType *ot)
void PAINT_OT_vertex_color_hsv(struct wmOperatorType *ot)
bool paint_supports_texture(enum ePaintMode mode)
void PAINT_OT_mask_box_gesture(struct wmOperatorType *ot)
Definition: paint_mask.c:1664
void PAINT_OT_face_select_all(struct wmOperatorType *ot)
Definition: paint_utils.c:713
void PAINT_OT_weight_sample_group(struct wmOperatorType *ot)
void SCULPT_OT_uv_sculpt_stroke(struct wmOperatorType *ot)
Definition: sculpt_uv.c:822
void PAINT_OT_vertex_color_brightness_contrast(struct wmOperatorType *ot)
void PAINT_OT_mask_flood_fill(struct wmOperatorType *ot)
Definition: paint_mask.c:203
bool weight_paint_mode_poll(struct bContext *C)
Definition: paint_vertex.c:238
void PAINT_OT_weight_paint(struct wmOperatorType *ot)
void PAINT_OT_face_select_reveal(struct wmOperatorType *ot)
Definition: paint_utils.c:816
void PAINT_OT_vertex_paint(struct wmOperatorType *ot)
void PAINT_OT_vertex_color_smooth(struct wmOperatorType *ot)
void PAINT_OT_vert_select_all(struct wmOperatorType *ot)
Definition: paint_utils.c:736
void PAINT_OT_vert_select_ungrouped(struct wmOperatorType *ot)
Definition: paint_utils.c:766
void PAINT_OT_face_select_linked(struct wmOperatorType *ot)
Definition: paint_utils.c:668
void PAINT_OT_weight_gradient(struct wmOperatorType *ot)
void PAINT_OT_vertex_color_levels(struct wmOperatorType *ot)
struct wmKeyMap * paint_stroke_modal_keymap(struct wmKeyConfig *keyconf)
void PAINT_OT_vertex_paint_toggle(struct wmOperatorType *ot)
void PAINT_OT_vertex_color_invert(struct wmOperatorType *ot)
void PAINT_OT_weight_sample(struct wmOperatorType *ot)
void PAINT_OT_vertex_color_from_weight(struct wmOperatorType *ot)
void BRUSH_OT_curve_preset(struct wmOperatorType *ot)
Definition: paint_utils.c:636
static void BRUSH_OT_scale_size(wmOperatorType *ot)
Definition: paint_ops.c:180
static int palette_color_move_exec(bContext *C, wmOperator *op)
Definition: paint_ops.c:487
static void brush_tool_set(const Brush *brush, size_t tool_offset, int tool)
Definition: paint_ops.c:639
static int stencil_fit_image_aspect_exec(bContext *C, wmOperator *op)
Definition: paint_ops.c:1125
static void PALETTE_OT_join(wmOperatorType *ot)
Definition: paint_ops.c:580
StencilConstraint
Definition: paint_ops.c:855
@ STENCIL_CONSTRAINT_Y
Definition: paint_ops.c:857
@ STENCIL_CONSTRAINT_X
Definition: paint_ops.c:856
static bool stencil_control_poll(bContext *C)
Definition: paint_ops.c:1073
static void PAINT_OT_brush_select(wmOperatorType *ot)
Definition: paint_ops.c:806
static void PALETTE_OT_extract_from_image(wmOperatorType *ot)
Definition: paint_ops.c:367
static void BRUSH_OT_stencil_reset_transform(wmOperatorType *ot)
Definition: paint_ops.c:1236
static bool palette_poll(bContext *C)
Definition: paint_ops.c:225
static void BRUSH_OT_stencil_fit_image_aspect(wmOperatorType *ot)
Definition: paint_ops.c:1181
static void BRUSH_OT_add(wmOperatorType *ot)
Definition: paint_ops.c:84
static void stencil_control_calculate(StencilControlData *scd, const int mval[2])
Definition: paint_ops.c:965
static int brush_add_exec(bContext *C, wmOperator *UNUSED(op))
Definition: paint_ops.c:63
static int palette_join_exec(bContext *C, wmOperator *op)
Definition: paint_ops.c:532
static bool brush_generic_tool_set(bContext *C, Main *bmain, Paint *paint, const int tool, const char *tool_name, const bool create_missing, const bool toggle)
Definition: paint_ops.c:709
static int brush_reset_exec(bContext *C, wmOperator *UNUSED(op))
Definition: paint_ops.c:598
static int stencil_control_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition: paint_ops.c:911
static void stencil_set_target(StencilControlData *scd)
Definition: paint_ops.c:879
static Brush * brush_tool_cycle(Main *bmain, Paint *paint, Brush *brush_orig, const int tool)
Definition: paint_ops.c:644
static void BRUSH_OT_add_gpencil(wmOperatorType *ot)
Definition: paint_ops.c:123
static int palette_color_add_exec(bContext *C, wmOperator *UNUSED(op))
Definition: paint_ops.c:236
static int palette_extract_img_exec(bContext *C, wmOperator *op)
Definition: paint_ops.c:319
static int brush_add_gpencil_exec(bContext *C, wmOperator *UNUSED(op))
Definition: paint_ops.c:98
static int brush_select_exec(bContext *C, wmOperator *op)
Definition: paint_ops.c:769
static void BRUSH_OT_reset(wmOperatorType *ot)
Definition: paint_ops.c:620
static int brush_tool(const Brush *brush, size_t tool_offset)
Definition: paint_ops.c:634
static void PALETTE_OT_new(wmOperatorType *ot)
Definition: paint_ops.c:211
static void PALETTE_OT_color_delete(wmOperatorType *ot)
Definition: paint_ops.c:291
StencilControlMode
Definition: paint_ops.c:844
@ STENCIL_SCALE
Definition: paint_ops.c:846
@ STENCIL_TRANSLATE
Definition: paint_ops.c:845
@ STENCIL_ROTATE
Definition: paint_ops.c:847
StencilTextureMode
Definition: paint_ops.c:850
@ STENCIL_SECONDARY
Definition: paint_ops.c:852
@ STENCIL_PRIMARY
Definition: paint_ops.c:851
static int stencil_control_modal(bContext *C, wmOperator *op, const wmEvent *event)
Definition: paint_ops.c:1018
static void PALETTE_OT_color_move(wmOperatorType *ot)
Definition: paint_ops.c:508
static int palette_new_exec(bContext *C, wmOperator *UNUSED(op))
Definition: paint_ops.c:198
static int palette_color_delete_exec(bContext *C, wmOperator *UNUSED(op))
Definition: paint_ops.c:278
static int palette_sort_exec(bContext *C, wmOperator *op)
Definition: paint_ops.c:389
static Brush * brush_tool_toggle(Main *bmain, Paint *paint, Brush *brush_orig, const int tool)
Definition: paint_ops.c:687
static void PALETTE_OT_color_add(wmOperatorType *ot)
Definition: paint_ops.c:264
static const ePaintMode brush_select_paint_modes[]
Definition: paint_ops.c:758
#define PIXEL_MARGIN
static int stencil_reset_transform_exec(bContext *C, wmOperator *op)
Definition: paint_ops.c:1202
static void BRUSH_OT_stencil_control(wmOperatorType *ot)
Definition: paint_ops.c:1090
static int brush_scale_size_exec(bContext *C, wmOperator *op)
Definition: paint_ops.c:137
static void stencil_restore(StencilControlData *scd)
Definition: paint_ops.c:950
static void stencil_control_cancel(bContext *UNUSED(C), wmOperator *op)
Definition: paint_ops.c:957
static bool palette_extract_img_poll(bContext *C)
Definition: paint_ops.c:306
static void PALETTE_OT_sort(wmOperatorType *ot)
Definition: paint_ops.c:461
void ED_operatormacros_paint(void)
Definition: paint_ops.c:1256
void ED_operatortypes_paint(void)
Definition: paint_ops.c:1272
void ED_keymap_paint(wmKeyConfig *keyconf)
Definition: paint_ops.c:1362
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
Definition: rna_access.c:6272
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:6655
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
Definition: rna_access.c:866
void RNA_string_get(PointerRNA *ptr, const char *name, char *value)
Definition: rna_access.c:6514
int RNA_int_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6308
bool RNA_enum_name_from_value(const EnumPropertyItem *item, int value, const char **r_name)
Definition: rna_access.c:6504
float RNA_float_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6355
int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:3543
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6261
int RNA_enum_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6402
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, float default_value, float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
Definition: rna_define.c:3825
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_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, int maxlen, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3675
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1512
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, int default_value, int hardmin, int hardmax, const char *ui_name, const char *ui_description, int softmin, int softmax)
Definition: rna_define.c:3585
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, int default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3771
bool SCULPT_mode_poll(bContext *C)
Definition: sculpt.c:6601
void sculpt_expand_modal_keymap(wmKeyConfig *keyconf)
struct MTex mtex
float stencil_pos[2]
short ob_mode
float stencil_dimension[2]
float mask_stencil_pos[2]
struct Brush * toggle_brush
struct MTex mask_mtex
float mask_stencil_dimension[2]
float weight
void * next
Definition: DNA_ID.h:274
char name[66]
Definition: DNA_ID.h:283
unsigned int * rect
void * first
Definition: DNA_listBase.h:47
char brush_map_mode
float rot
float size[3]
struct Tex * tex
Definition: BKE_main.h:116
ListBase brushes
Definition: BKE_main.h:171
unsigned short ob_mode
unsigned int tool_offset
struct Paint_Runtime runtime
struct Palette * palette
struct Brush * brush
struct PaletteColor * next
int active_color
ListBase colors
struct ImageUser iuser
struct Image * image
StencilConstraint constrain_mode
Definition: paint_ops.c:869
float init_sdim[2]
Definition: paint_ops.c:863
float * rot_target
Definition: paint_ops.c:874
float init_spos[2]
Definition: paint_ops.c:862
float area_size[2]
Definition: paint_ops.c:867
StencilControlMode mode
Definition: paint_ops.c:868
float * dim_target
Definition: paint_ops.c:873
float init_mouse[2]
Definition: paint_ops.c:861
float * pos_target
Definition: paint_ops.c:875
short xrepeat
short type
struct Image * ima
short extend
short yrepeat
GpPaint * gp_paint
short val
Definition: WM_types.h:579
int mval[2]
Definition: WM_types.h:583
short type
Definition: WM_types.h:577
bool(* poll)(struct bContext *)
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
PropertyRNA * prop
Definition: WM_types.h:814
struct ReportList * reports
struct PointerRNA * ptr
__forceinline const avxi abs(const avxi &a)
Definition: util_avxi.h:186
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)
uint len
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)
@ EVT_YKEY
@ EVT_XKEY
@ MOUSEMOVE
@ EVT_ESCKEY
wmOperatorType * ot
Definition: wm_files.c:3156
wmKeyMap * WM_keymap_ensure(wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid)
Definition: wm_keymap.c:852
void WM_modalkeymap_assign(wmKeyMap *km, const char *opname)
Definition: wm_keymap.c:985
wmOperatorType * WM_operatortype_append_macro(const char *idname, const char *name, const char *description, int flag)
wmOperatorTypeMacro * WM_operatortype_macro_define(wmOperatorType *ot, const char *idname)
void WM_operatortype_append(void(*opfunc)(wmOperatorType *))
bToolRef * WM_toolsystem_ref_set_by_id(bContext *C, const char *name)