From 1baae6f0f11e544c8652d6f6d76cd32cd05a6561 Mon Sep 17 00:00:00 2001 From: Casey Bianco-Davis Date: Tue, 4 Apr 2023 14:53:36 -0700 Subject: [PATCH 1/2] GPencil: Add "Brush" option to Grease Pencil Eyedropper modes This mode adds the selected color to the active brush. This is useful for quicker switching between Eyedropper and drawing. --- .../eyedroppers/eyedropper_gpencil_color.cc | 57 ++++++++++++++++--- 1 file changed, 49 insertions(+), 8 deletions(-) diff --git a/source/blender/editors/interface/eyedroppers/eyedropper_gpencil_color.cc b/source/blender/editors/interface/eyedroppers/eyedropper_gpencil_color.cc index 20592636fe7..768f9aa2e24 100644 --- a/source/blender/editors/interface/eyedroppers/eyedropper_gpencil_color.cc +++ b/source/blender/editors/interface/eyedroppers/eyedropper_gpencil_color.cc @@ -52,6 +52,7 @@ typedef enum eGP_EyeMode { GP_EYE_MATERIAL = 0, GP_EYE_PALETTE = 1, + GP_EYE_BRUSH = 2, } eGP_EyeMode; struct EyedropperGPencil { @@ -223,6 +224,40 @@ static void eyedropper_add_palette_color(bContext *C, const float col_conv[4]) } } +/* Set the active brush's color. */ +static void eyedropper_set_brush_color(bContext *C, const float col_conv[4]) +{ + Scene *scene = CTX_data_scene(C); + ToolSettings *ts = scene->toolsettings; + + const enum eContextObjectMode mode = CTX_data_mode_enum(C); + + Paint *paint = nullptr; + + switch (mode) { + case CTX_MODE_PAINT_GPENCIL: + paint = &ts->gp_paint->paint; + break; + case CTX_MODE_VERTEX_GPENCIL: + paint = &ts->gp_vertexpaint->paint; + break; + default: + return; + break; + } + + if (paint == nullptr) { + return; + } + + Brush *brush = paint->brush; + if (brush == nullptr) { + return; + } + + copy_v3_v3(brush->rgb, col_conv); +} + /* Set the material or the palette color. */ static void eyedropper_gpencil_color_set(bContext *C, const wmEvent *event, EyedropperGPencil *eye) { @@ -233,10 +268,10 @@ static void eyedropper_gpencil_color_set(bContext *C, const wmEvent *event, Eyed float col_conv[4]; - /* Convert from linear rgb space to display space because palette colors are in display + /* Convert from linear rgb space to display space because palette and brush 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) && (eye->mode == GP_EYE_PALETTE)) { + if ((eye->display) && (eye->mode == GP_EYE_PALETTE || eye->mode == GP_EYE_BRUSH)) { copy_v3_v3(col_conv, eye->color); IMB_colormanagement_scene_linear_to_display_v3(col_conv, eye->display); } @@ -244,12 +279,17 @@ static void eyedropper_gpencil_color_set(bContext *C, const wmEvent *event, Eyed copy_v3_v3(col_conv, eye->color); } - /* Add material or Palette color. */ - if (eye->mode == GP_EYE_MATERIAL) { - eyedropper_add_material(C, col_conv, only_stroke, only_fill, both); - } - else { - eyedropper_add_palette_color(C, col_conv); + /* Add material, Palette color or set Brush. */ + switch (eye->mode) { + case GP_EYE_MATERIAL: + eyedropper_add_material(C, col_conv, only_stroke, only_fill, both); + break; + case GP_EYE_PALETTE: + eyedropper_add_palette_color(C, col_conv); + break; + case GP_EYE_BRUSH: + eyedropper_set_brush_color(C, col_conv); + break; } } @@ -355,6 +395,7 @@ void UI_OT_eyedropper_gpencil_color(wmOperatorType *ot) static const EnumPropertyItem items_mode[] = { {GP_EYE_MATERIAL, "MATERIAL", 0, "Material", ""}, {GP_EYE_PALETTE, "PALETTE", 0, "Palette", ""}, + {GP_EYE_BRUSH, "BRUSH", 0, "Brush", ""}, {0, nullptr, 0, nullptr, nullptr}, }; -- 2.30.2 From 689b4f1fd3f58ecc7930df2e037613fc1c7a6694 Mon Sep 17 00:00:00 2001 From: casey bianco-davis Date: Tue, 19 Sep 2023 17:05:53 -0700 Subject: [PATCH 2/2] Fix: merge error and update --- .../interface/eyedroppers/eyedropper_gpencil_color.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/blender/editors/interface/eyedroppers/eyedropper_gpencil_color.cc b/source/blender/editors/interface/eyedroppers/eyedropper_gpencil_color.cc index f826a207880..e10fca6f244 100644 --- a/source/blender/editors/interface/eyedroppers/eyedropper_gpencil_color.cc +++ b/source/blender/editors/interface/eyedroppers/eyedropper_gpencil_color.cc @@ -53,6 +53,7 @@ enum eGP_EyeMode { GP_EYE_MATERIAL = 0, GP_EYE_PALETTE = 1, + GP_EYE_BRUSH = 2, }; struct EyedropperGPencil { @@ -234,10 +235,10 @@ static void eyedropper_set_brush_color(bContext *C, const float col_conv[4]) Paint *paint = nullptr; switch (mode) { - case CTX_MODE_PAINT_GPENCIL: + case CTX_MODE_PAINT_GPENCIL_LEGACY: paint = &ts->gp_paint->paint; break; - case CTX_MODE_VERTEX_GPENCIL: + case CTX_MODE_VERTEX_GPENCIL_LEGACY: paint = &ts->gp_vertexpaint->paint; break; default: -- 2.30.2