From 5c427f4b17700b0422022bb0796608a5ac89b55e Mon Sep 17 00:00:00 2001 From: Antonio Vazquez Date: Thu, 12 Mar 2020 16:33:51 +0100 Subject: GPencil: Fix unreliable comparison --- source/blender/editors/gpencil/gpencil_utils.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source/blender/editors/gpencil') diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c index a975af1c19a..7fe6f374766 100644 --- a/source/blender/editors/gpencil/gpencil_utils.c +++ b/source/blender/editors/gpencil/gpencil_utils.c @@ -2583,10 +2583,9 @@ bool ED_gpencil_stroke_check_collision(GP_SpaceConversion *gsc, bGPDspoint pt_dummy, pt_dummy_ps; float boundbox_min[2] = {0.0f}; float boundbox_max[2] = {0.0f}; - float zerov3[3]; /* Check we have something to use (only for old files). */ - if (equals_v3v3(zerov3, gps->boundbox_min)) { + if (is_zero_v3(gps->boundbox_min)) { BKE_gpencil_stroke_boundingbox_calc(gps); } -- cgit v1.2.3 From c1290a1d1f6beee8e60990d888fdb0a4d1a34e17 Mon Sep 17 00:00:00 2001 From: Antonio Vazquez Date: Thu, 12 Mar 2020 19:38:51 +0100 Subject: GPencil: Fix color management in Vertex Paint tools The brush is using sRGB and need to be Linear --- source/blender/editors/gpencil/gpencil_vertex_paint.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'source/blender/editors/gpencil') diff --git a/source/blender/editors/gpencil/gpencil_vertex_paint.c b/source/blender/editors/gpencil/gpencil_vertex_paint.c index c730d1b493e..9cdea22d45e 100644 --- a/source/blender/editors/gpencil/gpencil_vertex_paint.c +++ b/source/blender/editors/gpencil/gpencil_vertex_paint.c @@ -104,6 +104,7 @@ typedef struct tGP_BrushVertexpaintData { bGPdata *gpd; Brush *brush; + float linear_color[3]; eGPDvertex_brush_Flag flag; eGP_Vertex_SelectMaskFlag mask; @@ -444,7 +445,7 @@ static bool brush_tint_apply(tGP_BrushVertexpaintData *gso, /* Premult. */ mul_v3_fl(pt->vert_color, pt->vert_color[3]); /* "Alpha over" blending. */ - interp_v3_v3v3(pt->vert_color, pt->vert_color, brush->rgb, inf); + interp_v3_v3v3(pt->vert_color, pt->vert_color, gso->linear_color, inf); pt->vert_color[3] = pt->vert_color[3] * (1.0 - inf) + inf; /* Un-premult. */ if (pt->vert_color[3] > 0.0f) { @@ -463,7 +464,7 @@ static bool brush_tint_apply(tGP_BrushVertexpaintData *gso, /* Premult. */ mul_v3_fl(gps->vert_color_fill, gps->vert_color_fill[3]); /* "Alpha over" blending. */ - interp_v3_v3v3(gps->vert_color_fill, gps->vert_color_fill, brush->rgb, inf_fill); + interp_v3_v3v3(gps->vert_color_fill, gps->vert_color_fill, gso->linear_color, inf_fill); gps->vert_color_fill[3] = gps->vert_color_fill[3] * (1.0 - inf_fill) + inf_fill; /* Un-premult. */ if (gps->vert_color_fill[3] > 0.0f) { @@ -483,7 +484,7 @@ static bool brush_replace_apply(tGP_BrushVertexpaintData *gso, bGPDstroke *gps, /* Apply color to Stroke point. */ if (GPENCIL_TINT_VERTEX_COLOR_STROKE(brush)) { - copy_v3_v3(pt->vert_color, brush->rgb); + copy_v3_v3(pt->vert_color, gso->linear_color); /* If not mix color, full replace. */ if (pt->vert_color[3] == 0.0f) { pt->vert_color[3] = 1.0f; @@ -492,7 +493,7 @@ static bool brush_replace_apply(tGP_BrushVertexpaintData *gso, bGPDstroke *gps, /* Apply color to Fill area (all with same color and factor). */ if (GPENCIL_TINT_VERTEX_COLOR_FILL(brush)) { - copy_v3_v3(gps->vert_color_fill, brush->rgb); + copy_v3_v3(gps->vert_color_fill, gso->linear_color); /* If not mix color, full replace. */ if (gps->vert_color_fill[3] == 0.0f) { gps->vert_color_fill[3] = 1.0f; @@ -731,6 +732,7 @@ static bool gp_vertexpaint_brush_init(bContext *C, wmOperator *op) op->customdata = gso; gso->brush = paint->brush; + srgb_to_linearrgb_v3_v3(gso->linear_color, gso->brush->rgb); BKE_curvemapping_initialize(gso->brush->curve); gso->is_painting = false; -- cgit v1.2.3 From 7d56c425f8e64346eac6e78ed49d5c5ce2fe1025 Mon Sep 17 00:00:00 2001 From: Antonio Vazquez Date: Fri, 13 Mar 2020 21:54:42 +0100 Subject: GPencil: Don'r Replace color if vertex color is empty The replace tools only must work over previously vertex painted. --- source/blender/editors/gpencil/gpencil_vertex_paint.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'source/blender/editors/gpencil') diff --git a/source/blender/editors/gpencil/gpencil_vertex_paint.c b/source/blender/editors/gpencil/gpencil_vertex_paint.c index 9cdea22d45e..45dc22bafba 100644 --- a/source/blender/editors/gpencil/gpencil_vertex_paint.c +++ b/source/blender/editors/gpencil/gpencil_vertex_paint.c @@ -484,19 +484,15 @@ static bool brush_replace_apply(tGP_BrushVertexpaintData *gso, bGPDstroke *gps, /* Apply color to Stroke point. */ if (GPENCIL_TINT_VERTEX_COLOR_STROKE(brush)) { - copy_v3_v3(pt->vert_color, gso->linear_color); - /* If not mix color, full replace. */ - if (pt->vert_color[3] == 0.0f) { - pt->vert_color[3] = 1.0f; + if (pt->vert_color[3] > 0.0f) { + copy_v3_v3(pt->vert_color, gso->linear_color); } } /* Apply color to Fill area (all with same color and factor). */ if (GPENCIL_TINT_VERTEX_COLOR_FILL(brush)) { - copy_v3_v3(gps->vert_color_fill, gso->linear_color); - /* If not mix color, full replace. */ - if (gps->vert_color_fill[3] == 0.0f) { - gps->vert_color_fill[3] = 1.0f; + if (gps->vert_color_fill[3] > 0.0f) { + copy_v3_v3(gps->vert_color_fill, gso->linear_color); } } -- cgit v1.2.3 From 60e3f690cb66dfea9e078b70f12fc53611268f36 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 14 Mar 2020 15:22:04 +1100 Subject: Cleanup: sort file lists & struct declatations --- source/blender/editors/gpencil/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/editors/gpencil') diff --git a/source/blender/editors/gpencil/CMakeLists.txt b/source/blender/editors/gpencil/CMakeLists.txt index 512e1ec6270..4083169d65c 100644 --- a/source/blender/editors/gpencil/CMakeLists.txt +++ b/source/blender/editors/gpencil/CMakeLists.txt @@ -58,8 +58,8 @@ set(SRC gpencil_undo.c gpencil_utils.c gpencil_uv.c - gpencil_vertex_paint.c gpencil_vertex_ops.c + gpencil_vertex_paint.c gpencil_weight_paint.c gpencil_intern.h -- cgit v1.2.3 From 117ccb56ad7a7047b335de9bb5d6ea6e0acf3133 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 14 Mar 2020 15:34:03 +1100 Subject: Cleanup: remove unused ARegion from bGPdata_Runtime --- source/blender/editors/gpencil/gpencil_paint.c | 4 ---- source/blender/editors/gpencil/gpencil_primitive.c | 2 -- 2 files changed, 6 deletions(-) (limited to 'source/blender/editors/gpencil') diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c index 46788eba370..e7586d95d29 100644 --- a/source/blender/editors/gpencil/gpencil_paint.c +++ b/source/blender/editors/gpencil/gpencil_paint.c @@ -1653,9 +1653,6 @@ static void gp_session_validatebuffer(tGPsdata *p) /* reset flags */ gpd->runtime.sbuffer_sflag = 0; - /* reset region */ - gpd->runtime.ar = NULL; - /* reset inittime */ p->inittime = 0.0; @@ -1884,7 +1881,6 @@ static bool gp_session_initdata(bContext *C, wmOperator *op, tGPsdata *p) /* setup active color */ /* region where paint was originated */ - p->gpd->runtime.ar = CTX_wm_region(C); int totcol = p->ob->totcol; gp_init_colors(p); diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c index 96522d1750c..66c0131cd61 100644 --- a/source/blender/editors/gpencil/gpencil_primitive.c +++ b/source/blender/editors/gpencil/gpencil_primitive.c @@ -1157,8 +1157,6 @@ static void gpencil_primitive_init(bContext *C, wmOperator *op) /* set GP datablock */ tgpi->gpd = gpd; - /* region where paint was originated */ - tgpi->gpd->runtime.ar = tgpi->region; /* if brush doesn't exist, create a new set (fix damaged files from old versions) */ if ((paint->brush == NULL) || (paint->brush->gpencil_settings == NULL)) { -- cgit v1.2.3 From d50d410a7066549c69523ba3e0748e437de49949 Mon Sep 17 00:00:00 2001 From: Antonio Vazquez Date: Sat, 14 Mar 2020 10:30:59 +0100 Subject: GPencil: Rename operator color_select to select_material The old name was related to the old palettes. --- source/blender/editors/gpencil/gpencil_data.c | 12 ++++++------ source/blender/editors/gpencil/gpencil_intern.h | 2 +- source/blender/editors/gpencil/gpencil_ops.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'source/blender/editors/gpencil') diff --git a/source/blender/editors/gpencil/gpencil_data.c b/source/blender/editors/gpencil/gpencil_data.c index 9b33e999a25..e5d332a86de 100644 --- a/source/blender/editors/gpencil/gpencil_data.c +++ b/source/blender/editors/gpencil/gpencil_data.c @@ -3179,7 +3179,7 @@ void GPENCIL_OT_color_unlock_all(wmOperatorType *ot) /* ***************** Select all strokes using color ************************ */ -static int gpencil_color_select_exec(bContext *C, wmOperator *op) +static int gpencil_select_material_exec(bContext *C, wmOperator *op) { bGPdata *gpd = ED_gpencil_data_get_active(C); Object *ob = CTX_data_active_object(C); @@ -3249,15 +3249,15 @@ static int gpencil_color_select_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -void GPENCIL_OT_color_select(wmOperatorType *ot) +void GPENCIL_OT_select_material(wmOperatorType *ot) { /* identifiers */ - ot->name = "Select Color"; - ot->idname = "GPENCIL_OT_color_select"; - ot->description = "Select all Grease Pencil strokes using current color"; + ot->name = "Select Material"; + ot->idname = "GPENCIL_OT_select_material"; + ot->description = "Select/Deselect all Grease Pencil strokes using current material"; /* callbacks */ - ot->exec = gpencil_color_select_exec; + ot->exec = gpencil_select_material_exec; ot->poll = gpencil_active_color_poll; /* flags */ diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h index 2d36e426835..1a2ab8b47fb 100644 --- a/source/blender/editors/gpencil/gpencil_intern.h +++ b/source/blender/editors/gpencil/gpencil_intern.h @@ -552,7 +552,7 @@ void GPENCIL_OT_color_hide(struct wmOperatorType *ot); void GPENCIL_OT_color_reveal(struct wmOperatorType *ot); void GPENCIL_OT_color_lock_all(struct wmOperatorType *ot); void GPENCIL_OT_color_unlock_all(struct wmOperatorType *ot); -void GPENCIL_OT_color_select(struct wmOperatorType *ot); +void GPENCIL_OT_select_material(struct wmOperatorType *ot); void GPENCIL_OT_set_active_material(struct wmOperatorType *ot); /* convert old 2.7 files to 2.8 */ diff --git a/source/blender/editors/gpencil/gpencil_ops.c b/source/blender/editors/gpencil/gpencil_ops.c index 275075c38db..3170623e574 100644 --- a/source/blender/editors/gpencil/gpencil_ops.c +++ b/source/blender/editors/gpencil/gpencil_ops.c @@ -653,7 +653,7 @@ void ED_operatortypes_gpencil(void) WM_operatortype_append(GPENCIL_OT_color_reveal); WM_operatortype_append(GPENCIL_OT_color_lock_all); WM_operatortype_append(GPENCIL_OT_color_unlock_all); - WM_operatortype_append(GPENCIL_OT_color_select); + WM_operatortype_append(GPENCIL_OT_select_material); /* Editing (Time) --------------- */ -- cgit v1.2.3 From 466171d0ef46225bbf61195b5a6e5eff650bf015 Mon Sep 17 00:00:00 2001 From: Antonio Vazquez Date: Sat, 14 Mar 2020 10:33:33 +0100 Subject: GPencil: Rename operator select_color to select_vertex_color --- source/blender/editors/gpencil/gpencil_intern.h | 2 +- source/blender/editors/gpencil/gpencil_ops.c | 2 +- source/blender/editors/gpencil/gpencil_select.c | 16 ++++++++-------- 3 files changed, 10 insertions(+), 10 deletions(-) (limited to 'source/blender/editors/gpencil') diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h index 1a2ab8b47fb..a12fd81e032 100644 --- a/source/blender/editors/gpencil/gpencil_intern.h +++ b/source/blender/editors/gpencil/gpencil_intern.h @@ -407,7 +407,7 @@ void GPENCIL_OT_select_less(struct wmOperatorType *ot); void GPENCIL_OT_select_first(struct wmOperatorType *ot); void GPENCIL_OT_select_last(struct wmOperatorType *ot); void GPENCIL_OT_select_alternate(struct wmOperatorType *ot); -void GPENCIL_OT_select_color(struct wmOperatorType *ot); +void GPENCIL_OT_select_vertex_color(struct wmOperatorType *ot); void GPENCIL_OT_duplicate(struct wmOperatorType *ot); void GPENCIL_OT_delete(struct wmOperatorType *ot); diff --git a/source/blender/editors/gpencil/gpencil_ops.c b/source/blender/editors/gpencil/gpencil_ops.c index 3170623e574..233bebfc9b6 100644 --- a/source/blender/editors/gpencil/gpencil_ops.c +++ b/source/blender/editors/gpencil/gpencil_ops.c @@ -544,7 +544,7 @@ void ED_operatortypes_gpencil(void) WM_operatortype_append(GPENCIL_OT_select_first); WM_operatortype_append(GPENCIL_OT_select_last); WM_operatortype_append(GPENCIL_OT_select_alternate); - WM_operatortype_append(GPENCIL_OT_select_color); + WM_operatortype_append(GPENCIL_OT_select_vertex_color); WM_operatortype_append(GPENCIL_OT_duplicate); WM_operatortype_append(GPENCIL_OT_delete); diff --git a/source/blender/editors/gpencil/gpencil_select.c b/source/blender/editors/gpencil/gpencil_select.c index 26b68707d55..175b7b8c196 100644 --- a/source/blender/editors/gpencil/gpencil_select.c +++ b/source/blender/editors/gpencil/gpencil_select.c @@ -1655,7 +1655,7 @@ void GPENCIL_OT_select(wmOperatorType *ot) } /* Select by Vertex Color. */ -static bool gpencil_select_color_poll(bContext *C) +static bool gpencil_select_vertex_color_poll(bContext *C) { ToolSettings *ts = CTX_data_tool_settings(C); Object *ob = CTX_data_active_object(C); @@ -1678,7 +1678,7 @@ static bool gpencil_select_color_poll(bContext *C) return false; } -static int gpencil_select_color_exec(bContext *C, wmOperator *op) +static int gpencil_select_vertex_color_exec(bContext *C, wmOperator *op) { const float threshold = RNA_float_get(op->ptr, "threshold"); @@ -1736,18 +1736,18 @@ static int gpencil_select_color_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -void GPENCIL_OT_select_color(wmOperatorType *ot) +void GPENCIL_OT_select_vertex_color(wmOperatorType *ot) { PropertyRNA *prop; /* identifiers */ - ot->name = "Select Color"; - ot->idname = "GPENCIL_OT_select_color"; - ot->description = "Select all strokes with same color"; + ot->name = "Select Vertex Color"; + ot->idname = "GPENCIL_OT_select_vertex_color"; + ot->description = "Select all strokes with same vertex color"; /* callbacks */ - ot->exec = gpencil_select_color_exec; - ot->poll = gpencil_select_color_poll; + ot->exec = gpencil_select_vertex_color_exec; + ot->poll = gpencil_select_vertex_color_poll; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; -- cgit v1.2.3 From 428e65256e77d2939709b0dfe9c8a31c57a93369 Mon Sep 17 00:00:00 2001 From: Antonio Vazquez Date: Sat, 14 Mar 2020 10:46:28 +0100 Subject: GPencil: Use Linear color instead of sRGB for Select Vertex Color The brush color is sRGB but the Vertex Color is linear. --- source/blender/editors/gpencil/gpencil_select.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source/blender/editors/gpencil') diff --git a/source/blender/editors/gpencil/gpencil_select.c b/source/blender/editors/gpencil/gpencil_select.c index 175b7b8c196..12d4c7c4329 100644 --- a/source/blender/editors/gpencil/gpencil_select.c +++ b/source/blender/editors/gpencil/gpencil_select.c @@ -1693,8 +1693,9 @@ static int gpencil_select_vertex_color_exec(bContext *C, wmOperator *op) Brush *brush = paint->brush; bool done = false; - float hsv_brush[3], hsv_stroke[3]; - rgb_to_hsv_compat_v(brush->rgb, hsv_brush); + float hsv_brush[3], hsv_stroke[3], linear_color[3]; + srgb_to_linearrgb_v3_v3(linear_color, brush->rgb); + rgb_to_hsv_compat_v(linear_color, hsv_brush); /* Select any visible stroke that uses this color */ CTX_DATA_BEGIN (C, bGPDstroke *, gps, editable_gpencil_strokes) { -- cgit v1.2.3 From cc53900bafff2f353cea3f74759312105a5ff31f Mon Sep 17 00:00:00 2001 From: Antonio Vazquez Date: Sat, 14 Mar 2020 11:07:35 +0100 Subject: GPencil: Add option to keep selected in Select Vertex Color --- source/blender/editors/gpencil/gpencil_select.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'source/blender/editors/gpencil') diff --git a/source/blender/editors/gpencil/gpencil_select.c b/source/blender/editors/gpencil/gpencil_select.c index 12d4c7c4329..43e13e88b9c 100644 --- a/source/blender/editors/gpencil/gpencil_select.c +++ b/source/blender/editors/gpencil/gpencil_select.c @@ -1681,6 +1681,7 @@ static bool gpencil_select_vertex_color_poll(bContext *C) static int gpencil_select_vertex_color_exec(bContext *C, wmOperator *op) { const float threshold = RNA_float_get(op->ptr, "threshold"); + const bool keep = RNA_boolean_get(op->ptr, "keep"); ToolSettings *ts = CTX_data_tool_settings(C); Object *ob = CTX_data_active_object(C); @@ -1702,8 +1703,18 @@ static int gpencil_select_vertex_color_exec(bContext *C, wmOperator *op) bGPDspoint *pt; int i; bool gps_selected = false; + /* If clear unselect stroke. */ + if (!keep) { + gps->flag &= ~GP_STROKE_SELECT; + } + /* Check all stroke points. */ for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { + /* Clear any previous point selected. */ + if (!keep) { + pt->flag &= ~GP_SPOINT_SELECT; + } + if (pt->vert_color[3] < 0.03f) { continue; } @@ -1757,6 +1768,10 @@ void GPENCIL_OT_select_vertex_color(wmOperatorType *ot) prop = RNA_def_float(ot->srna, "threshold", 0.01f, 0.0f, 1.0f, "Threshold", "", 0.0f, 1.0f); /* avoid re-using last var */ RNA_def_property_flag(prop, PROP_SKIP_SAVE); + + prop = RNA_def_boolean( + ot->srna, "keep", true, "Keep Previous Selection", "Keep any previous selection"); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); } /** \} */ -- cgit v1.2.3 From a816a067ede6c8df3fc3a32bba2370a0ef179061 Mon Sep 17 00:00:00 2001 From: Antonio Vazquez Date: Sat, 14 Mar 2020 16:16:35 +0100 Subject: GPencil: Change Select Vertex Color to similar selection Now, instead to use the Brush color as selection patron, now it uses any previous selected color. --- source/blender/editors/gpencil/gpencil_select.c | 109 ++++++++++++++++++++---- 1 file changed, 91 insertions(+), 18 deletions(-) (limited to 'source/blender/editors/gpencil') diff --git a/source/blender/editors/gpencil/gpencil_select.c b/source/blender/editors/gpencil/gpencil_select.c index 43e13e88b9c..ee9e91d0e81 100644 --- a/source/blender/editors/gpencil/gpencil_select.c +++ b/source/blender/editors/gpencil/gpencil_select.c @@ -1655,6 +1655,49 @@ void GPENCIL_OT_select(wmOperatorType *ot) } /* Select by Vertex Color. */ +/* Helper to create a hash of colors. */ +static void gpencil_selected_hue_table(bContext *C, + Object *ob, + const int threshold, + GHash *hue_table) +{ + const float range = pow(10, 7 - threshold); + float hsv[3]; + + /* Extract all colors. */ + CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) { + LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { + LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { + if (ED_gpencil_stroke_can_use(C, gps) == false) { + continue; + } + if (ED_gpencil_stroke_color_use(ob, gpl, gps) == false) { + continue; + } + if ((gps->flag & GP_STROKE_SELECT) == 0) { + continue; + } + + /* Read all points to get all colors selected. */ + bGPDspoint *pt; + int i; + for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { + if (((pt->flag & GP_SPOINT_SELECT) == 0) || (pt->vert_color[3] == 0.0f)) { + continue; + } + /* Round Hue value. */ + rgb_to_hsv_compat_v(pt->vert_color, hsv); + uint key = truncf(hsv[0] * range); + if (!BLI_ghash_haskey(hue_table, POINTER_FROM_INT(key))) { + BLI_ghash_insert(hue_table, POINTER_FROM_INT(key), POINTER_FROM_INT(key)); + } + } + } + } + } + CTX_DATA_END; +} + static bool gpencil_select_vertex_color_poll(bContext *C) { ToolSettings *ts = CTX_data_tool_settings(C); @@ -1680,25 +1723,28 @@ static bool gpencil_select_vertex_color_poll(bContext *C) static int gpencil_select_vertex_color_exec(bContext *C, wmOperator *op) { - const float threshold = RNA_float_get(op->ptr, "threshold"); - const bool keep = RNA_boolean_get(op->ptr, "keep"); - ToolSettings *ts = CTX_data_tool_settings(C); Object *ob = CTX_data_active_object(C); + + const float threshold = RNA_int_get(op->ptr, "threshold"); + const bool keep = RNA_boolean_get(op->ptr, "keep"); + const int selectmode = gpencil_select_mode_from_vertex(ts->gpencil_selectmode_vertex); bGPdata *gpd = (bGPdata *)ob->data; - if (!GPENCIL_VERTEX_MODE(gpd)) { - return OPERATOR_CANCELLED; - } + const float range = pow(10, 7 - threshold); - Paint *paint = &ts->gp_vertexpaint->paint; - Brush *brush = paint->brush; bool done = false; - float hsv_brush[3], hsv_stroke[3], linear_color[3]; - srgb_to_linearrgb_v3_v3(linear_color, brush->rgb); - rgb_to_hsv_compat_v(linear_color, hsv_brush); + /* Create a hash table with all selected colors. */ + GHash *hue_table = BLI_ghash_int_new(__func__); + gpencil_selected_hue_table(C, ob, threshold, hue_table); + if (BLI_ghash_len(hue_table) == 0) { + BKE_report(op->reports, RPT_ERROR, "Select before some Vertex to use as a filter color"); + BLI_ghash_free(hue_table, NULL, NULL); - /* Select any visible stroke that uses this color */ + return OPERATOR_CANCELLED; + } + + /* Select any visible stroke that uses any of these colors. */ CTX_DATA_BEGIN (C, bGPDstroke *, gps, editable_gpencil_strokes) { bGPDspoint *pt; int i; @@ -1715,13 +1761,17 @@ static int gpencil_select_vertex_color_exec(bContext *C, wmOperator *op) pt->flag &= ~GP_SPOINT_SELECT; } - if (pt->vert_color[3] < 0.03f) { + if (pt->vert_color[3] == 0.0f) { continue; } - rgb_to_hsv_compat_v(pt->vert_color, hsv_stroke); - /* Only check Hue to get full value and saturation ranges. */ - if (compare_ff(hsv_stroke[0], hsv_brush[0], threshold)) { + /* Only check Hue to get value and saturation full ranges. */ + float hsv[3]; + /* Round Hue value. */ + rgb_to_hsv_compat_v(pt->vert_color, hsv); + uint key = truncf(hsv[0] * range); + + if (BLI_ghash_haskey(hue_table, POINTER_FROM_INT(key))) { pt->flag |= GP_SPOINT_SELECT; gps_selected = true; } @@ -1730,6 +1780,16 @@ static int gpencil_select_vertex_color_exec(bContext *C, wmOperator *op) if (gps_selected) { gps->flag |= GP_STROKE_SELECT; done = true; + + /* Extend stroke selection. */ + if (selectmode == GP_SELECTMODE_STROKE) { + bGPDspoint *pt1 = NULL; + int i; + + for (i = 0, pt1 = gps->points; i < gps->totpoints; i++, pt1++) { + pt1->flag |= GP_SPOINT_SELECT; + } + } } } CTX_DATA_END; @@ -1745,6 +1805,11 @@ static int gpencil_select_vertex_color_exec(bContext *C, wmOperator *op) WM_event_add_notifier(C, NC_GEOM | ND_SELECT, NULL); } + /* Free memory. */ + if (hue_table != NULL) { + BLI_ghash_free(hue_table, NULL, NULL); + } + return OPERATOR_FINISHED; } @@ -1755,7 +1820,7 @@ void GPENCIL_OT_select_vertex_color(wmOperatorType *ot) /* identifiers */ ot->name = "Select Vertex Color"; ot->idname = "GPENCIL_OT_select_vertex_color"; - ot->description = "Select all strokes with same vertex color"; + ot->description = "Select all points with similar vertex color of current selected"; /* callbacks */ ot->exec = gpencil_select_vertex_color_exec; @@ -1765,7 +1830,15 @@ void GPENCIL_OT_select_vertex_color(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ - prop = RNA_def_float(ot->srna, "threshold", 0.01f, 0.0f, 1.0f, "Threshold", "", 0.0f, 1.0f); + prop = RNA_def_int(ot->srna, + "threshold", + 0, + 0, + 6, + "Threshold", + "Tolerance of the selection. Higher values select a wider range of similar colors", + 0, + 6); /* avoid re-using last var */ RNA_def_property_flag(prop, PROP_SKIP_SAVE); -- cgit v1.2.3 From b037816980dee7a74128c23eface983b9850d4a9 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 15 Mar 2020 17:32:06 +1100 Subject: Cleanup: shadow warning, clang-format --- source/blender/editors/gpencil/gpencil_select.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'source/blender/editors/gpencil') diff --git a/source/blender/editors/gpencil/gpencil_select.c b/source/blender/editors/gpencil/gpencil_select.c index ee9e91d0e81..f479905f0d7 100644 --- a/source/blender/editors/gpencil/gpencil_select.c +++ b/source/blender/editors/gpencil/gpencil_select.c @@ -1784,7 +1784,6 @@ static int gpencil_select_vertex_color_exec(bContext *C, wmOperator *op) /* Extend stroke selection. */ if (selectmode == GP_SELECTMODE_STROKE) { bGPDspoint *pt1 = NULL; - int i; for (i = 0, pt1 = gps->points; i < gps->totpoints; i++, pt1++) { pt1->flag |= GP_SPOINT_SELECT; @@ -1830,15 +1829,16 @@ void GPENCIL_OT_select_vertex_color(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ - prop = RNA_def_int(ot->srna, - "threshold", - 0, - 0, - 6, - "Threshold", - "Tolerance of the selection. Higher values select a wider range of similar colors", - 0, - 6); + prop = RNA_def_int( + ot->srna, + "threshold", + 0, + 0, + 6, + "Threshold", + "Tolerance of the selection. Higher values select a wider range of similar colors", + 0, + 6); /* avoid re-using last var */ RNA_def_property_flag(prop, PROP_SKIP_SAVE); -- cgit v1.2.3 From 22925d0dd31e75feefde792da55a1fd1b77f53f2 Mon Sep 17 00:00:00 2001 From: Antonio Vazquez Date: Sun, 15 Mar 2020 19:22:33 +0100 Subject: GPencil: Remove Keep parameter from Select Vertex Color Also changed range of threshold from 0 to 10 --- source/blender/editors/gpencil/gpencil_select.c | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) (limited to 'source/blender/editors/gpencil') diff --git a/source/blender/editors/gpencil/gpencil_select.c b/source/blender/editors/gpencil/gpencil_select.c index f479905f0d7..e5813611915 100644 --- a/source/blender/editors/gpencil/gpencil_select.c +++ b/source/blender/editors/gpencil/gpencil_select.c @@ -1661,7 +1661,7 @@ static void gpencil_selected_hue_table(bContext *C, const int threshold, GHash *hue_table) { - const float range = pow(10, 7 - threshold); + const float range = pow(10, 10 - threshold); float hsv[3]; /* Extract all colors. */ @@ -1727,10 +1727,9 @@ static int gpencil_select_vertex_color_exec(bContext *C, wmOperator *op) Object *ob = CTX_data_active_object(C); const float threshold = RNA_int_get(op->ptr, "threshold"); - const bool keep = RNA_boolean_get(op->ptr, "keep"); const int selectmode = gpencil_select_mode_from_vertex(ts->gpencil_selectmode_vertex); bGPdata *gpd = (bGPdata *)ob->data; - const float range = pow(10, 7 - threshold); + const float range = pow(10, 10 - threshold); bool done = false; @@ -1749,18 +1748,8 @@ static int gpencil_select_vertex_color_exec(bContext *C, wmOperator *op) bGPDspoint *pt; int i; bool gps_selected = false; - /* If clear unselect stroke. */ - if (!keep) { - gps->flag &= ~GP_STROKE_SELECT; - } - /* Check all stroke points. */ for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { - /* Clear any previous point selected. */ - if (!keep) { - pt->flag &= ~GP_SPOINT_SELECT; - } - if (pt->vert_color[3] == 0.0f) { continue; } @@ -1834,17 +1823,13 @@ void GPENCIL_OT_select_vertex_color(wmOperatorType *ot) "threshold", 0, 0, - 6, + 10, "Threshold", "Tolerance of the selection. Higher values select a wider range of similar colors", 0, - 6); + 10); /* avoid re-using last var */ RNA_def_property_flag(prop, PROP_SKIP_SAVE); - - prop = RNA_def_boolean( - ot->srna, "keep", true, "Keep Previous Selection", "Keep any previous selection"); - RNA_def_property_flag(prop, PROP_SKIP_SAVE); } /** \} */ -- cgit v1.2.3 From 7a7b392b5422eeb5030f9b8c5504edc085f49892 Mon Sep 17 00:00:00 2001 From: Antonio Vazquez Date: Sun, 15 Mar 2020 19:40:21 +0100 Subject: GPencil: Reduce factor to 5 in previous commit 10 decimals is too high --- source/blender/editors/gpencil/gpencil_select.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source/blender/editors/gpencil') diff --git a/source/blender/editors/gpencil/gpencil_select.c b/source/blender/editors/gpencil/gpencil_select.c index e5813611915..133891cda13 100644 --- a/source/blender/editors/gpencil/gpencil_select.c +++ b/source/blender/editors/gpencil/gpencil_select.c @@ -1661,7 +1661,7 @@ static void gpencil_selected_hue_table(bContext *C, const int threshold, GHash *hue_table) { - const float range = pow(10, 10 - threshold); + const float range = pow(10, 5 - threshold); float hsv[3]; /* Extract all colors. */ @@ -1729,7 +1729,7 @@ static int gpencil_select_vertex_color_exec(bContext *C, wmOperator *op) const float threshold = RNA_int_get(op->ptr, "threshold"); const int selectmode = gpencil_select_mode_from_vertex(ts->gpencil_selectmode_vertex); bGPdata *gpd = (bGPdata *)ob->data; - const float range = pow(10, 10 - threshold); + const float range = pow(10, 5 - threshold); bool done = false; @@ -1823,11 +1823,11 @@ void GPENCIL_OT_select_vertex_color(wmOperatorType *ot) "threshold", 0, 0, - 10, + 5, "Threshold", "Tolerance of the selection. Higher values select a wider range of similar colors", 0, - 10); + 5); /* avoid re-using last var */ RNA_def_property_flag(prop, PROP_SKIP_SAVE); } -- cgit v1.2.3