[Bf-blender-cvs] [01799306e70] temp-gpencil-bezier-v2: GPencil: Implement generic selection for curves
Falk David
noreply at git.blender.org
Sat Mar 6 14:08:34 CET 2021
Commit: 01799306e70395641598d1997ad7ff07172c6c05
Author: Falk David
Date: Sat Mar 6 14:08:25 2021 +0100
Branches: temp-gpencil-bezier-v2
https://developer.blender.org/rB01799306e70395641598d1997ad7ff07172c6c05
GPencil: Implement generic selection for curves
This commits refactors generic (box & lasso) selection so
that it is possible to use with curves.
This also makes use of the newly added runtime data for curves.
===================================================================
M source/blender/editors/gpencil/gpencil_select.c
===================================================================
diff --git a/source/blender/editors/gpencil/gpencil_select.c b/source/blender/editors/gpencil/gpencil_select.c
index e379131fde2..0f61818c909 100644
--- a/source/blender/editors/gpencil/gpencil_select.c
+++ b/source/blender/editors/gpencil/gpencil_select.c
@@ -575,7 +575,6 @@ static bool gpencil_select_same_layer(bContext *C)
}
gps->flag |= GP_STROKE_SELECT;
-
}
BKE_gpencil_stroke_select_index_set(gpd, gps);
@@ -868,7 +867,7 @@ static int gpencil_select_last_exec(bContext *C, wmOperator *op)
else {
gps->points[gps->totpoints - 1].flag |= GP_SPOINT_SELECT;
gps->flag |= GP_STROKE_SELECT;
-
+
/* deselect rest? */
if ((extend == false) && (gps->totpoints > 1)) {
/* don't include the last point... */
@@ -1330,9 +1329,10 @@ static bool gpencil_curve_do_circle_sel(bContext *C,
const bool only_selected = (v3d->overlay.handle_display == CURVE_HANDLE_SELECTED);
bool hit = false;
- for (int i = 0; i < gpc->tot_curve_points; i++) {
+ for (int i = 0; i < gpc_active->tot_curve_points; i++) {
bGPDcurve_point *gpc_pt = &gpc->curve_points[i];
- bGPDcurve_point *gpc_active_pt = (gpc_pt->runtime.gpc_pt_orig) ? gpc_pt->runtime.gpc_pt_orig : gpc_pt;
+ bGPDcurve_point *gpc_active_pt = (gpc_pt->runtime.gpc_pt_orig) ? gpc_pt->runtime.gpc_pt_orig :
+ gpc_pt;
BezTriple *bezt = &gpc_active_pt->bezt;
if (bezt->hide == 1) {
@@ -1386,9 +1386,11 @@ static bool gpencil_curve_do_circle_sel(bContext *C,
/* select the entire curve */
if (hit && (selectmode == GP_SELECTMODE_STROKE)) {
- for (int i = 0; i < gpc->tot_curve_points; i++) {
+ for (int i = 0; i < gpc_active->tot_curve_points; i++) {
bGPDcurve_point *gpc_pt = &gpc->curve_points[i];
- bGPDcurve_point *gpc_active_pt = (gpc_pt->runtime.gpc_pt_orig) ? gpc_pt->runtime.gpc_pt_orig : gpc_pt;
+ bGPDcurve_point *gpc_active_pt = (gpc_pt->runtime.gpc_pt_orig) ?
+ gpc_pt->runtime.gpc_pt_orig :
+ gpc_pt;
BezTriple *bezt = &gpc_active_pt->bezt;
if (select) {
@@ -1400,9 +1402,17 @@ static bool gpencil_curve_do_circle_sel(bContext *C,
BEZT_DESEL_ALL(bezt);
}
}
- }
- BKE_gpencil_curve_sync_selection(gpd, gps);
+ if (select) {
+ gpc_active->flag |= GP_CURVE_SELECT;
+ }
+ else {
+ gpc_active->flag &= ~GP_CURVE_SELECT;
+ }
+ }
+ else {
+ BKE_gpencil_curve_sync_selection(gpd, gps);
+ }
return hit;
}
@@ -1470,7 +1480,7 @@ static int gpencil_circle_select_exec(bContext *C, wmOperator *op)
if (GPENCIL_STROKE_IS_CURVE(gps)) {
bGPDcurve *gpc = gps->editcurve;
changed |= gpencil_curve_do_circle_sel(
- C, gps, gpc, mx, my, radius, select, &rect, gpstroke_iter.diff_mat, selectmode);
+ C, gps, gpc, mx, my, radius, select, &rect, gpstroke_iter.diff_mat, selectmode);
}
else {
changed |= gpencil_stroke_do_circle_sel(gpd,
@@ -1613,278 +1623,252 @@ static bool gpencil_stroke_fill_isect_rect(ARegion *region,
static bool gpencil_generic_curve_select(bContext *C,
Object *ob,
+ bGPdata *gpd,
+ bGPDstroke *gps,
+ bGPDcurve *gpc,
+ struct GP_EditableStrokes_Iter *gpstroke_iter,
+ GP_SpaceConversion *gsc,
GPencilTestFn is_inside_fn,
- rcti UNUSED(box),
+ rcti box,
GP_SelectUserData *user_data,
const bool strokemode,
const eSelectOp sel_op)
{
- ARegion *region = CTX_wm_region(C);
View3D *v3d = CTX_wm_view3d(C);
- bGPdata *gpd = ob->data;
+ bGPDstroke *gps_active = (gps->runtime.gps_orig) ? gps->runtime.gps_orig : gps;
+ bGPDcurve *gpc_active = (gpc->runtime.gpc_orig) ? gpc->runtime.gpc_orig : gpc;
+
const bool handle_only_selected = (v3d->overlay.handle_display == CURVE_HANDLE_SELECTED);
const bool handle_all = (v3d->overlay.handle_display == CURVE_HANDLE_ALL);
bool hit = false;
bool changed = false;
bool whole = false;
+ bool any_select = false;
+ for (int i = 0; i < gpc->tot_curve_points; i++) {
+ bGPDcurve_point *gpc_pt = &gpc->curve_points[i];
+ BezTriple *bezt = &gpc_pt->bezt;
- GP_EDITABLE_CURVES_BEGIN(gps_iter, C, gpl, gps, gpc)
- {
- bool any_select = false;
- for (int i = 0; i < gpc->tot_curve_points; i++) {
- bGPDcurve_point *gpc_pt = &gpc->curve_points[i];
- BezTriple *bezt = &gpc_pt->bezt;
+ bGPDcurve_point *gpc_pt_active = (gpc_pt->runtime.gpc_pt_orig) ? gpc_pt->runtime.gpc_pt_orig :
+ gpc_pt;
+ BezTriple *bezt_active = &gpc_pt_active->bezt;
- if (bezt->hide == 1) {
- continue;
- }
+ if (bezt_active->hide == 1) {
+ continue;
+ }
- const bool handles_visible = (handle_all || (handle_only_selected &&
- (gpc_pt->flag & GP_CURVE_POINT_SELECT)));
+ const bool handles_visible = (handle_all || (handle_only_selected &&
+ (gpc_pt->flag & GP_CURVE_POINT_SELECT)));
- if (handles_visible) {
- for (int j = 0; j < 3; j++) {
- const bool is_select = BEZT_ISSEL_IDX(bezt, j);
- bool is_inside = is_inside_fn(region, gps_iter.diff_mat, bezt->vec[j], user_data);
- if (strokemode) {
- if (is_inside) {
- hit = true;
- any_select = true;
- break;
- }
- }
- else {
- const int sel_op_result = ED_select_op_action_deselected(sel_op, is_select, is_inside);
- if (sel_op_result != -1) {
- if (sel_op_result) {
- gpc_pt->flag |= GP_CURVE_POINT_SELECT;
- BEZT_SEL_IDX(bezt, j);
- any_select = true;
- }
- else {
- gpc_pt->flag &= ~GP_CURVE_POINT_SELECT;
- BEZT_DESEL_IDX(bezt, j);
- }
- changed = true;
- hit = true;
- }
- else {
- if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
- gpc_pt->flag &= ~GP_CURVE_POINT_SELECT;
- BEZT_DESEL_IDX(bezt, j);
- }
- }
- }
- }
- }
- /* if the handles are not visible only check ctrl point (vec[1])*/
- else {
- const bool is_select = bezt->f2;
- bool is_inside = is_inside_fn(region, gps_iter.diff_mat, bezt->vec[1], user_data);
+ if (handles_visible) {
+ for (int j = 0; j < 3; j++) {
+ const bool is_select = BEZT_ISSEL_IDX(bezt_active, j);
+ bool is_inside = is_inside_fn(
+ gsc->region, gpstroke_iter->diff_mat, bezt->vec[j], user_data);
if (strokemode) {
if (is_inside) {
hit = true;
any_select = true;
+ break;
}
}
else {
const int sel_op_result = ED_select_op_action_deselected(sel_op, is_select, is_inside);
if (sel_op_result != -1) {
if (sel_op_result) {
- gpc_pt->flag |= GP_CURVE_POINT_SELECT;
- bezt->f2 |= SELECT;
+ gpc_pt_active->flag |= GP_CURVE_POINT_SELECT;
+ BEZT_SEL_IDX(bezt_active, j);
any_select = true;
}
else {
- gpc_pt->flag &= ~GP_CURVE_POINT_SELECT;
- bezt->f2 &= ~SELECT;
+ gpc_pt_active->flag &= ~GP_CURVE_POINT_SELECT;
+ BEZT_DESEL_IDX(bezt_active, j);
}
changed = true;
hit = true;
}
else {
if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
- gpc_pt->flag &= ~GP_CURVE_POINT_SELECT;
- bezt->f2 &= ~SELECT;
+ gpc_pt_active->flag &= ~GP_CURVE_POINT_SELECT;
+ BEZT_DESEL_IDX(bezt_active, j);
}
}
}
}
}
-
- /* TODO: Fix selection for filled in curves. */
-#if 0
- if (!hit) {
- /* check if we selected the inside of a filled curve */
- MaterialGPencilStyle *gp_style = BKE_gpencil_material_settings(ob, gps->mat_nr + 1);
- if ((gp_style->flag & GP_MATERIAL_FILL_SHOW) == 0) {
- continue;
+ /* if the handles are not visible only check ctrl point (vec[1])*/
+ else {
+ const bool is_select = bezt_active->f2;
+ bool is_inside = is_inside_fn(gsc->region, gpstroke_iter->diff_mat, bezt->vec[1], user_data);
+ if (strokemode) {
+ if (is_inside) {
+ hit = true;
+ any_select = true;
+ }
}
-
- whole = gpencil_stroke_fill_isect_rect(region, gps, gps_iter.diff_mat, box);
- }
-#endif
- /* select the entire curve */
- if (strokemode || whole) {
- const int sel_op_result = ED_select_op_action_deselected(sel_op, any_select, hit || whole);
- if (sel_op_result != -1) {
- for (int i = 0; i < gpc->tot_curve_points; i++) {
- bGPDcurve_point *gpc_pt = &gpc->curve_points[i];
- BezTriple *bezt = &gpc_pt->bezt;
-
+ else {
+ const int sel_op_result = ED_select_op_action_deselected(sel_op, is_select, is_inside);
+ if (sel_op_result != -1) {
if (sel_op_result) {
- gpc_pt->flag |= GP_CURVE_POINT_SELECT;
- BEZT_SEL_ALL(bezt);
+ gpc_pt_active->flag |= GP_CURVE_POINT_SELECT;
+ bezt_active->f2 |= SELECT;
+ any_select = true;
}
else {
- gpc_pt->flag &= ~GP_CURVE_POINT_SELECT;
- BEZT_DESEL_ALL(bezt);
+ gpc_pt_active->flag &= ~GP_CURVE_POINT_SELECT;
+ bezt_active->f
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list