Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonio Vazquez <blendergit@gmail.com>2020-03-09 18:27:24 +0300
committerAntonio Vazquez <blendergit@gmail.com>2020-03-09 18:27:24 +0300
commit29f3af95272590d26f610ae828b2eeee89c82a00 (patch)
treea696a58a2561c48f7ec6166e369e22081e0a64d8 /source/blender/editors/interface
parentdcb93126876879d969a30a7865700abd072066f8 (diff)
GPencil: Refactor of Draw Engine, Vertex Paint and all internal functions
This commit is a full refactor of the grease pencil modules including Draw Engine, Modifiers, VFX, depsgraph update, improvements in operators and conversion of Sculpt and Weight paint tools to real brushes. Also, a huge code cleanup has been done at all levels. Thanks to @fclem for his work and yo @pepeland and @mendio for the testing and help in the development. Differential Revision: https://developer.blender.org/D6293
Diffstat (limited to 'source/blender/editors/interface')
-rw-r--r--source/blender/editors/interface/interface.c6
-rw-r--r--source/blender/editors/interface/interface_eyedropper_gpencil_color.c114
-rw-r--r--source/blender/editors/interface/interface_handlers.c41
-rw-r--r--source/blender/editors/interface/interface_icons.c53
-rw-r--r--source/blender/editors/interface/interface_layout.c2
-rw-r--r--source/blender/editors/interface/interface_templates.c48
6 files changed, 220 insertions, 44 deletions
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 165a53203f3..a0a3d0a3b85 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -4115,9 +4115,9 @@ static void ui_def_but_rna__panel_type(bContext *C, uiLayout *layout, void *but_
void ui_but_rna_menu_convert_to_panel_type(uiBut *but, const char *panel_type)
{
- BLI_assert(but->type == UI_BTYPE_MENU);
- BLI_assert(but->menu_create_func == ui_def_but_rna__menu);
- BLI_assert((void *)but->poin == but);
+ BLI_assert(ELEM(but->type, UI_BTYPE_MENU, UI_BTYPE_COLOR));
+ // BLI_assert(but->menu_create_func == ui_def_but_rna__menu);
+ // BLI_assert((void *)but->poin == but);
but->menu_create_func = ui_def_but_rna__panel_type;
but->func_argN = BLI_strdup(panel_type);
}
diff --git a/source/blender/editors/interface/interface_eyedropper_gpencil_color.c b/source/blender/editors/interface/interface_eyedropper_gpencil_color.c
index 790609a17d8..f9f5c745e94 100644
--- a/source/blender/editors/interface/interface_eyedropper_gpencil_color.c
+++ b/source/blender/editors/interface/interface_eyedropper_gpencil_color.c
@@ -39,6 +39,7 @@
#include "BKE_gpencil.h"
#include "BKE_main.h"
#include "BKE_material.h"
+#include "BKE_paint.h"
#include "BKE_report.h"
#include "UI_interface.h"
@@ -65,6 +66,8 @@ typedef struct EyedropperGPencil {
struct ColorManagedDisplay *display;
/** color under cursor RGB */
float color[3];
+ /** Mode */
+ int mode;
} EyedropperGPencil;
/* Helper: Draw status message while the user is running the operator */
@@ -89,6 +92,7 @@ static bool eyedropper_gpencil_init(bContext *C, wmOperator *op)
display_device = scene->display_settings.display_device;
eye->display = IMB_colormanagement_display_get_named(display_device);
+ eye->mode = RNA_enum_get(op->ptr, "mode");
return true;
}
@@ -101,31 +105,15 @@ static void eyedropper_gpencil_exit(bContext *C, wmOperator *op)
MEM_SAFE_FREE(op->customdata);
}
-/* Set the material. */
-static void eyedropper_gpencil_color_set(bContext *C, const wmEvent *event, EyedropperGPencil *eye)
+static void eyedropper_add_material(
+ bContext *C, float col_conv[4], const bool only_stroke, const bool only_fill, const bool both)
{
Main *bmain = CTX_data_main(C);
Object *ob = CTX_data_active_object(C);
Material *ma = NULL;
- const bool only_stroke = ((!event->ctrl) && (!event->shift));
- const bool only_fill = ((!event->ctrl) && (event->shift));
- const bool both = ((event->ctrl) && (event->shift));
-
- float col_conv[4];
bool found = false;
- /* Convert from linear rgb space to display space because grease pencil colors are in display
- * space, and this conversion is needed to undo the conversion to linear performed by
- * eyedropper_color_sample_fl. */
- if (eye->display) {
- copy_v3_v3(col_conv, eye->color);
- IMB_colormanagement_scene_linear_to_display_v3(col_conv, eye->display);
- }
- else {
- copy_v3_v3(col_conv, eye->color);
- }
-
/* Look for a similar material in grease pencil slots. */
short *totcol = BKE_object_material_len_p(ob);
for (short i = 0; i < *totcol; i++) {
@@ -138,15 +126,15 @@ static void eyedropper_gpencil_color_set(bContext *C, const wmEvent *event, Eyed
if (gp_style != NULL) {
/* Check stroke color. */
bool found_stroke = compare_v3v3(gp_style->stroke_rgba, col_conv, 0.01f) &&
- (gp_style->flag & GP_STYLE_STROKE_SHOW);
+ (gp_style->flag & GP_MATERIAL_STROKE_SHOW);
/* Check fill color. */
bool found_fill = compare_v3v3(gp_style->fill_rgba, col_conv, 0.01f) &&
- (gp_style->flag & GP_STYLE_FILL_SHOW);
+ (gp_style->flag & GP_MATERIAL_FILL_SHOW);
- if ((only_stroke) && (found_stroke) && ((gp_style->flag & GP_STYLE_FILL_SHOW) == 0)) {
+ if ((only_stroke) && (found_stroke) && ((gp_style->flag & GP_MATERIAL_FILL_SHOW) == 0)) {
found = true;
}
- else if ((only_fill) && (found_fill) && ((gp_style->flag & GP_STYLE_STROKE_SHOW) == 0)) {
+ else if ((only_fill) && (found_fill) && ((gp_style->flag & GP_MATERIAL_STROKE_SHOW) == 0)) {
found = true;
}
else if ((both) && (found_stroke) && (found_fill)) {
@@ -180,22 +168,22 @@ static void eyedropper_gpencil_color_set(bContext *C, const wmEvent *event, Eyed
/* Only create Stroke (default option). */
if (only_stroke) {
/* Stroke color. */
- gp_style_new->flag |= GP_STYLE_STROKE_SHOW;
- gp_style_new->flag &= ~GP_STYLE_FILL_SHOW;
+ gp_style_new->flag |= GP_MATERIAL_STROKE_SHOW;
+ gp_style_new->flag &= ~GP_MATERIAL_FILL_SHOW;
copy_v3_v3(gp_style_new->stroke_rgba, col_conv);
zero_v4(gp_style_new->fill_rgba);
}
/* Fill Only. */
else if (only_fill) {
/* Fill color. */
- gp_style_new->flag &= ~GP_STYLE_STROKE_SHOW;
- gp_style_new->flag |= GP_STYLE_FILL_SHOW;
+ gp_style_new->flag &= ~GP_MATERIAL_STROKE_SHOW;
+ gp_style_new->flag |= GP_MATERIAL_FILL_SHOW;
zero_v4(gp_style_new->stroke_rgba);
copy_v3_v3(gp_style_new->fill_rgba, col_conv);
}
/* Stroke and Fill. */
else if (both) {
- gp_style_new->flag |= GP_STYLE_STROKE_SHOW | GP_STYLE_FILL_SHOW;
+ gp_style_new->flag |= GP_MATERIAL_STROKE_SHOW | GP_MATERIAL_FILL_SHOW;
copy_v3_v3(gp_style_new->stroke_rgba, col_conv);
copy_v3_v3(gp_style_new->fill_rgba, col_conv);
}
@@ -203,6 +191,69 @@ static void eyedropper_gpencil_color_set(bContext *C, const wmEvent *event, Eyed
ED_undo_push(C, "Add Grease Pencil Material");
}
+/* Create a new palette color and palette if needed. */
+static void eyedropper_add_palette_color(bContext *C, float col_conv[4])
+{
+ Main *bmain = CTX_data_main(C);
+ Scene *scene = CTX_data_scene(C);
+ ToolSettings *ts = scene->toolsettings;
+ GpPaint *gp_paint = ts->gp_paint;
+ GpVertexPaint *gp_vertexpaint = ts->gp_vertexpaint;
+ Paint *paint = &gp_paint->paint;
+ Paint *vertexpaint = &gp_vertexpaint->paint;
+
+ /* Check for Palette in Draw and Vertex Paint Mode. */
+ if (paint->palette == NULL) {
+ paint->palette = BKE_palette_add(bmain, "Grease Pencil");
+ if (vertexpaint->palette == NULL) {
+ vertexpaint->palette = paint->palette;
+ }
+ }
+ /* Check if the color exist already. */
+ Palette *palette = paint->palette;
+ for (PaletteColor *palcolor = palette->colors.first; palcolor; palcolor = palcolor->next) {
+ if (compare_v3v3(palcolor->rgb, col_conv, 0.01f)) {
+ return;
+ }
+ }
+
+ /* Create Colors. */
+ PaletteColor *palcol = BKE_palette_color_add(palette);
+ if (palcol) {
+ copy_v3_v3(palcol->rgb, col_conv);
+ }
+}
+
+/* Set the material or the palette color. */
+static void eyedropper_gpencil_color_set(bContext *C, const wmEvent *event, EyedropperGPencil *eye)
+{
+
+ const bool only_stroke = ((!event->ctrl) && (!event->shift));
+ const bool only_fill = ((!event->ctrl) && (event->shift));
+ const bool both = ((event->ctrl) && (event->shift));
+
+ float col_conv[4];
+
+ /* Convert from linear rgb space to display space because grease pencil colors are in display
+ * space, and this conversion is needed to undo the conversion to linear performed by
+ * eyedropper_color_sample_fl. */
+ if (eye->display) {
+ copy_v3_v3(col_conv, eye->color);
+ IMB_colormanagement_scene_linear_to_display_v3(col_conv, eye->display);
+ }
+ else {
+ copy_v3_v3(col_conv, eye->color);
+ }
+
+ /* Add material or Palette color*/
+ if (eye->mode == 0) {
+ eyedropper_add_material(C, col_conv, only_stroke, only_fill, both);
+ }
+ else {
+ eyedropper_add_palette_color(C, col_conv);
+ }
+}
+
/* Sample the color below cursor. */
static void eyedropper_gpencil_color_sample(bContext *C, EyedropperGPencil *eye, int mx, int my)
{
@@ -307,6 +358,12 @@ static bool eyedropper_gpencil_poll(bContext *C)
void UI_OT_eyedropper_gpencil_color(wmOperatorType *ot)
{
+ static const EnumPropertyItem items_mode[] = {
+ {0, "MATERIAL", 0, "Material", ""},
+ {1, "PALETTE", 0, "Palette", ""},
+ {0, NULL, 0, NULL, NULL},
+ };
+
/* identifiers */
ot->name = "Grease Pencil Eyedropper";
ot->idname = "UI_OT_eyedropper_gpencil_color";
@@ -321,4 +378,7 @@ void UI_OT_eyedropper_gpencil_color(wmOperatorType *ot)
/* flags */
ot->flag = OPTYPE_UNDO | OPTYPE_BLOCKING;
+
+ /* properties */
+ ot->prop = RNA_def_enum(ot->srna, "mode", items_mode, 0, "Mode", "");
}
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index 6a9632f54bb..088a904ec78 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -3994,7 +3994,12 @@ static void ui_block_open_begin(bContext *C, uiBut *but, uiHandleButtonData *dat
copy_v3_v3(data->vec, data->origvec);
but->editvec = data->vec;
- handlefunc = ui_block_func_COLOR;
+ if (ui_but_menu_draw_as_popover(but)) {
+ popoverfunc = but->menu_create_func;
+ }
+ else {
+ handlefunc = ui_block_func_COLOR;
+ }
arg = but;
break;
@@ -4063,8 +4068,8 @@ int ui_but_menu_direction(uiBut *but)
}
/**
- * Hack for #uiList #UI_BTYPE_LISTROW buttons to "give" events to overlaying #UI_BTYPE_TEXT buttons
- * (Ctrl-Click rename feature & co).
+ * Hack for #uiList #UI_BTYPE_LISTROW buttons to "give" events to overlaying #UI_BTYPE_TEXT
+ * buttons (Ctrl-Click rename feature & co).
*/
static uiBut *ui_but_list_row_text_activate(bContext *C,
uiBut *but,
@@ -5553,14 +5558,13 @@ static int ui_do_but_BLOCK(bContext *C, uiBut *but, uiHandleButtonData *data, co
button_activate_state(C, but, BUTTON_STATE_EXIT);
ui_apply_but(C, but->block, but, data, true);
- /* Button's state need to be changed to EXIT so moving mouse away from this mouse wouldn't
- * lead to cancel changes made to this button, but changing state to EXIT also makes no
- * button active for a while which leads to triggering operator
- * when doing fast scrolling mouse wheel.
- * using post activate stuff from button allows to make button be active again after
- * checking for all all that mouse leave and cancel stuff,
- * so quick scroll wouldn't be an issue anymore.
- * Same goes for scrolling wheel in another direction below (sergey).
+ /* Button's state need to be changed to EXIT so moving mouse away from this mouse
+ * wouldn't lead to cancel changes made to this button, but changing state to EXIT also
+ * makes no button active for a while which leads to triggering operator when doing fast
+ * scrolling mouse wheel. using post activate stuff from button allows to make button be
+ * active again after checking for all all that mouse leave and cancel stuff, so quick
+ * scroll wouldn't be an issue anymore. Same goes for scrolling wheel in another
+ * direction below (sergey).
*/
data->postbut = but;
data->posttype = BUTTON_ACTIVATE_OVER;
@@ -5797,15 +5801,27 @@ static int ui_do_but_COLOR(bContext *C, uiBut *but, uiHandleButtonData *data, co
}
else {
Scene *scene = CTX_data_scene(C);
+ bool updated = false;
if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA) {
RNA_property_float_get_array(&but->rnapoin, but->rnaprop, color);
BKE_brush_color_set(scene, brush, color);
+ updated = true;
}
else if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR) {
RNA_property_float_get_array(&but->rnapoin, but->rnaprop, color);
IMB_colormanagement_scene_linear_to_srgb_v3(color);
BKE_brush_color_set(scene, brush, color);
+ updated = true;
+ }
+
+ if (updated) {
+ PointerRNA brush_ptr;
+ PropertyRNA *brush_color_prop;
+
+ RNA_id_pointer_create(&brush->id, &brush_ptr);
+ brush_color_prop = RNA_struct_find_property(&brush_ptr, "color");
+ RNA_property_update(C, &brush_ptr, brush_color_prop);
}
}
@@ -9519,7 +9535,8 @@ static int ui_handle_menu_event(bContext *C,
/* Closing sub-levels of pull-downs.
*
* The actual event is handled by the button under the cursor.
- * This is done so we can right click on menu items even when they have sub-menus open. */
+ * This is done so we can right click on menu items even when they have sub-menus open.
+ */
case RIGHTMOUSE:
if (inside == false) {
if (event->val == KM_PRESS && (block->flag & UI_BLOCK_LOOP)) {
diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c
index c1018a67fb3..3e07023e52d 100644
--- a/source/blender/editors/interface/interface_icons.c
+++ b/source/blender/editors/interface/interface_icons.c
@@ -2050,7 +2050,10 @@ static int ui_id_brush_get_icon(const bContext *C, ID *id)
}
/* reset the icon */
- if ((ob != NULL) && (ob->mode & OB_MODE_PAINT_GPENCIL) && (br->gpencil_settings != NULL)) {
+ if ((ob != NULL) &&
+ (ob->mode & (OB_MODE_PAINT_GPENCIL | OB_MODE_VERTEX_GPENCIL | OB_MODE_SCULPT_GPENCIL |
+ OB_MODE_WEIGHT_GPENCIL)) &&
+ (br->gpencil_settings != NULL)) {
switch (br->gpencil_settings->icon_id) {
case GP_BRUSH_ICON_PENCIL:
br->id.icon_id = ICON_GPBRUSH_PENCIL;
@@ -2088,6 +2091,54 @@ static int ui_id_brush_get_icon(const bContext *C, ID *id)
case GP_BRUSH_ICON_ERASE_STROKE:
br->id.icon_id = ICON_GPBRUSH_ERASE_STROKE;
break;
+ case GP_BRUSH_ICON_TINT:
+ br->id.icon_id = ICON_BRUSH_TEXDRAW;
+ break;
+ case GP_BRUSH_ICON_VERTEX_DRAW:
+ br->id.icon_id = ICON_BRUSH_MIX;
+ break;
+ case GP_BRUSH_ICON_VERTEX_BLUR:
+ br->id.icon_id = ICON_BRUSH_BLUR;
+ break;
+ case GP_BRUSH_ICON_VERTEX_AVERAGE:
+ br->id.icon_id = ICON_BRUSH_BLUR;
+ break;
+ case GP_BRUSH_ICON_VERTEX_SMEAR:
+ br->id.icon_id = ICON_BRUSH_BLUR;
+ break;
+ case GP_BRUSH_ICON_VERTEX_REPLACE:
+ br->id.icon_id = ICON_BRUSH_MIX;
+ break;
+ case GP_BRUSH_ICON_GPBRUSH_SMOOTH:
+ br->id.icon_id = ICON_GPBRUSH_SMOOTH;
+ break;
+ case GP_BRUSH_ICON_GPBRUSH_THICKNESS:
+ br->id.icon_id = ICON_GPBRUSH_THICKNESS;
+ break;
+ case GP_BRUSH_ICON_GPBRUSH_STRENGTH:
+ br->id.icon_id = ICON_GPBRUSH_STRENGTH;
+ break;
+ case GP_BRUSH_ICON_GPBRUSH_RANDOMIZE:
+ br->id.icon_id = ICON_GPBRUSH_RANDOMIZE;
+ break;
+ case GP_BRUSH_ICON_GPBRUSH_GRAB:
+ br->id.icon_id = ICON_GPBRUSH_GRAB;
+ break;
+ case GP_BRUSH_ICON_GPBRUSH_PUSH:
+ br->id.icon_id = ICON_GPBRUSH_PUSH;
+ break;
+ case GP_BRUSH_ICON_GPBRUSH_TWIST:
+ br->id.icon_id = ICON_GPBRUSH_TWIST;
+ break;
+ case GP_BRUSH_ICON_GPBRUSH_PINCH:
+ br->id.icon_id = ICON_GPBRUSH_PINCH;
+ break;
+ case GP_BRUSH_ICON_GPBRUSH_CLONE:
+ br->id.icon_id = ICON_GPBRUSH_CLONE;
+ break;
+ case GP_BRUSH_ICON_GPBRUSH_WEIGHT:
+ br->id.icon_id = ICON_GPBRUSH_WEIGHT;
+ break;
default:
br->id.icon_id = ICON_GPBRUSH_PEN;
break;
diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c
index 8e65b818314..dd002f4e77f 100644
--- a/source/blender/editors/interface/interface_layout.c
+++ b/source/blender/editors/interface/interface_layout.c
@@ -2325,7 +2325,7 @@ void uiItemFullR_with_popover(uiLayout *layout,
uiItemFullR(layout, ptr, prop, index, value, flag, name, icon);
but = but->next;
while (but) {
- if (but->rnaprop == prop && but->type == UI_BTYPE_MENU) {
+ if (but->rnaprop == prop && ELEM(but->type, UI_BTYPE_MENU, UI_BTYPE_COLOR)) {
ui_but_rna_menu_convert_to_panel_type(but, panel_type);
break;
}
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index c80c5317735..b752a1a1429 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -5385,6 +5385,21 @@ void uiTemplateColorPicker(uiLayout *layout,
}
}
+static void ui_template_palette_menu(bContext *UNUSED(C), uiLayout *layout, void *UNUSED(but_p))
+{
+ uiLayout *row;
+
+ uiItemL(layout, IFACE_("Sort by:"), ICON_NONE);
+ row = uiLayoutRow(layout, false);
+ uiItemEnumO_value(row, IFACE_("Hue"), ICON_NONE, "PALETTE_OT_sort", "type", 1);
+ row = uiLayoutRow(layout, false);
+ uiItemEnumO_value(row, IFACE_("Saturation"), ICON_NONE, "PALETTE_OT_sort", "type", 2);
+ row = uiLayoutRow(layout, false);
+ uiItemEnumO_value(row, IFACE_("Value"), ICON_NONE, "PALETTE_OT_sort", "type", 3);
+ row = uiLayoutRow(layout, false);
+ uiItemEnumO_value(row, IFACE_("Luminance"), ICON_NONE, "PALETTE_OT_sort", "type", 4);
+}
+
void uiTemplatePalette(uiLayout *layout,
PointerRNA *ptr,
const char *propname,
@@ -5396,6 +5411,8 @@ void uiTemplatePalette(uiLayout *layout,
PaletteColor *color;
uiBlock *block;
uiLayout *col;
+ uiBut *but = NULL;
+
int row_cols = 0, col_id = 0;
int cols_per_row = MAX2(uiLayoutGetWidth(layout) / UI_UNIT_X, 1);
@@ -5437,6 +5454,37 @@ void uiTemplatePalette(uiLayout *layout,
UI_UNIT_X,
UI_UNIT_Y,
NULL);
+ if (color) {
+ but = uiDefIconButO(block,
+ UI_BTYPE_BUT,
+ "PALETTE_OT_color_move",
+ WM_OP_INVOKE_DEFAULT,
+ ICON_TRIA_UP,
+ 0,
+ 0,
+ UI_UNIT_X,
+ UI_UNIT_Y,
+ NULL);
+ UI_but_operator_ptr_get(but);
+ RNA_enum_set(but->opptr, "type", -1);
+
+ but = uiDefIconButO(block,
+ UI_BTYPE_BUT,
+ "PALETTE_OT_color_move",
+ WM_OP_INVOKE_DEFAULT,
+ ICON_TRIA_DOWN,
+ 0,
+ 0,
+ UI_UNIT_X,
+ UI_UNIT_Y,
+ NULL);
+ UI_but_operator_ptr_get(but);
+ RNA_enum_set(but->opptr, "type", 1);
+
+ /* Menu. */
+ uiDefIconMenuBut(
+ block, ui_template_palette_menu, NULL, ICON_SORTSIZE, 0, 0, UI_UNIT_X, UI_UNIT_Y, "");
+ }
col = uiLayoutColumn(layout, true);
uiLayoutRow(col, true);