[Bf-blender-cvs] [2e232248294] greasepencil-edit-curve: GPencil: Apply all GSoC changes
Antonio Vazquez
noreply at git.blender.org
Wed Jul 15 12:18:36 CEST 2020
Commit: 2e232248294191722c61f089225b2c5c21732331
Author: Antonio Vazquez
Date: Wed Jul 15 12:18:30 2020 +0200
Branches: greasepencil-edit-curve
https://developer.blender.org/rB2e232248294191722c61f089225b2c5c21732331
GPencil: Apply all GSoC changes
===================================================================
M source/blender/editors/gpencil/gpencil_edit_curve.c
M source/blender/editors/gpencil/gpencil_select.c
===================================================================
diff --git a/source/blender/editors/gpencil/gpencil_edit_curve.c b/source/blender/editors/gpencil/gpencil_edit_curve.c
index b8d2ecf2474..64e5867309f 100644
--- a/source/blender/editors/gpencil/gpencil_edit_curve.c
+++ b/source/blender/editors/gpencil/gpencil_edit_curve.c
@@ -70,7 +70,7 @@ static bool gpencil_curve_edit_mode_poll(bContext *C)
return (gpl != NULL);
}
-static int gpencil_stroke_enter_editcurve_mode(bContext *C, wmOperator *op)
+static int gpencil_stroke_enter_editcurve_mode_exec(bContext *C, wmOperator *op)
{
Object *ob = CTX_data_active_object(C);
bGPdata *gpd = ob->data;
@@ -90,10 +90,10 @@ static int gpencil_stroke_enter_editcurve_mode(bContext *C, wmOperator *op)
if ((gps->flag & GP_STROKE_SELECT && gps->editcurve == NULL) ||
(gps->editcurve != NULL && gps->editcurve->flag & GP_CURVE_NEEDS_STROKE_UPDATE)) {
BKE_gpencil_stroke_editcurve_update(gps, gpd->curve_edit_threshold);
- if (gps->editcurve != NULL) {
- gps->editcurve->resolution = gpd->editcurve_resolution;
- gps->editcurve->flag |= GP_STROKE_NEEDS_CURVE_UPDATE;
- }
+ gps->editcurve->resolution = gpd->editcurve_resolution;
+ /* Update the selection from the stroke to the curve. */
+ BKE_gpencil_editcurve_stroke_sync_selection(gps, gps->editcurve);
+ gps->flag |= GP_STROKE_NEEDS_CURVE_UPDATE;
BKE_gpencil_stroke_geometry_update(gpd, gps);
}
}
@@ -101,6 +101,8 @@ static int gpencil_stroke_enter_editcurve_mode(bContext *C, wmOperator *op)
}
}
+ gpd->flag |= GP_DATA_CURVE_EDIT_MODE;
+
/* notifiers */
DEG_id_tag_update(&gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);
WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
@@ -118,7 +120,7 @@ void GPENCIL_OT_stroke_enter_editcurve_mode(wmOperatorType *ot)
ot->description = "Called to transform a stroke into a curve";
/* api callbacks */
- ot->exec = gpencil_stroke_enter_editcurve_mode;
+ ot->exec = gpencil_stroke_enter_editcurve_mode_exec;
ot->poll = gpencil_active_layer_poll;
/* flags */
diff --git a/source/blender/editors/gpencil/gpencil_select.c b/source/blender/editors/gpencil/gpencil_select.c
index d348b849f5b..70e8649dd94 100644
--- a/source/blender/editors/gpencil/gpencil_select.c
+++ b/source/blender/editors/gpencil/gpencil_select.c
@@ -128,6 +128,61 @@ static bool gpencil_select_poll(bContext *C)
return false;
}
+static bool gpencil_3d_point_to_screen_space(ARegion *region,
+ const float diff_mat[4][4],
+ const float co[3],
+ int r_co[2])
+{
+ float parent_co[3];
+ mul_v3_m4v3(parent_co, diff_mat, co);
+ int screen_co[2];
+ if (ED_view3d_project_int_global(
+ region, parent_co, screen_co, V3D_PROJ_RET_CLIP_BB | V3D_PROJ_RET_CLIP_WIN) ==
+ V3D_PROJ_RET_OK) {
+ if (!ELEM(V2D_IS_CLIPPED, screen_co[0], screen_co[1])) {
+ copy_v2_v2_int(r_co, screen_co);
+ return true;
+ }
+ }
+ r_co[0] = V2D_IS_CLIPPED;
+ r_co[1] = V2D_IS_CLIPPED;
+ return false;
+}
+
+/* helper to deselect all selected strokes/points */
+static void deselect_all_selected(bContext *C)
+{
+ CTX_DATA_BEGIN (C, bGPDstroke *, gps, editable_gpencil_strokes) {
+ /* deselect stroke and its points if selected */
+ if (gps->flag & GP_STROKE_SELECT) {
+ bGPDspoint *pt;
+ int i;
+
+ /* deselect points */
+ for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
+ pt->flag &= ~GP_SPOINT_SELECT;
+ }
+
+ /* deselect curve and curve points */
+ if (gps->editcurve != NULL) {
+ bGPDcurve *gpc = gps->editcurve;
+ for (int j = 0; j < gpc->tot_curve_points; j++) {
+ bGPDcurve_point *gpc_pt = &gpc->curve_points[j];
+ BezTriple *bezt = &gpc_pt->bezt;
+ gpc_pt->flag &= ~GP_CURVE_POINT_SELECT;
+ BEZT_DESEL_ALL(bezt);
+ }
+
+ gpc->flag &= ~GP_CURVE_SELECT;
+ }
+
+ /* deselect stroke itself too */
+ gps->flag &= ~GP_STROKE_SELECT;
+ }
+ }
+ CTX_DATA_END;
+}
+
/** \} */
/* -------------------------------------------------------------------- */
@@ -306,7 +361,43 @@ static int gpencil_select_alternate_exec(bContext *C, wmOperator *op)
bool changed = false;
if (is_curve_edit) {
- /* TODO: do curve select */
+ GP_EDITABLE_CURVES_BEGIN(gps_iter, C, gpl, gps, gpc)
+ {
+ if ((gps->flag & GP_STROKE_SELECT) && (gps->totpoints > 1)) {
+ int idx = 0;
+ int start = 0;
+ if (unselect_ends) {
+ start = 1;
+ }
+
+ for (int i = start; i < gpc->tot_curve_points; i++) {
+ bGPDcurve_point *gpc_pt = &gpc->curve_points[i];
+ if ((idx % 2) == 0) {
+ gpc_pt->flag |= GP_SPOINT_SELECT;
+ BEZT_SEL_ALL(&gpc_pt->bezt);
+ }
+ else {
+ gpc_pt->flag &= ~GP_SPOINT_SELECT;
+ BEZT_DESEL_ALL(&gpc_pt->bezt);
+ }
+ idx++;
+ }
+
+ if (unselect_ends) {
+ bGPDcurve_point *gpc_pt = &gpc->curve_points[0];
+ gpc_pt->flag &= ~GP_SPOINT_SELECT;
+ BEZT_DESEL_ALL(&gpc_pt->bezt);
+
+ gpc_pt = &gpc->curve_points[gpc->tot_curve_points - 1];
+ gpc_pt->flag &= ~GP_SPOINT_SELECT;
+ BEZT_DESEL_ALL(&gpc_pt->bezt);
+ }
+
+ BKE_gpencil_curve_sync_selection(gps);
+ changed = true;
+ }
+ }
+ GP_EDITABLE_CURVES_END(gps_iter);
}
else {
/* select all points in selected strokes */
@@ -409,31 +500,44 @@ static bool gpencil_select_same_layer(bContext *C)
const bool is_curve_edit = (bool)GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd);
bool changed = false;
- if (is_curve_edit) {
- /* TODO: do curve select */
- }
- else {
- CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) {
- bGPDframe *gpf = BKE_gpencil_layer_frame_get(gpl, CFRA, GP_GETFRAME_USE_PREV);
- bGPDstroke *gps;
- bool found = false;
+ CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) {
+ bGPDframe *gpf = BKE_gpencil_layer_frame_get(gpl, CFRA, GP_GETFRAME_USE_PREV);
+ bGPDstroke *gps;
+ bool found = false;
- if (gpf == NULL) {
- continue;
+ if (gpf == NULL) {
+ continue;
+ }
+
+ /* Search for a selected stroke */
+ for (gps = gpf->strokes.first; gps; gps = gps->next) {
+ if (ED_gpencil_stroke_can_use(C, gps)) {
+ if (gps->flag & GP_STROKE_SELECT) {
+ found = true;
+ break;
+ }
}
+ }
+
+ /* Select all if found */
+ if (found) {
+ if (is_curve_edit) {
+ for (gps = gpf->strokes.first; gps; gps = gps->next) {
+ if (gps->editcurve != NULL && ED_gpencil_stroke_can_use(C, gps)) {
+ bGPDcurve *gpc = gps->editcurve;
+ for (int i = 0; i < gpc->tot_curve_points; i++) {
+ bGPDcurve_point *gpc_pt = &gpc->curve_points[i];
+ gpc_pt->flag |= GP_CURVE_POINT_SELECT;
+ BEZT_SEL_ALL(&gpc_pt->bezt);
+ }
+ gpc->flag |= GP_CURVE_SELECT;
+ gps->flag |= GP_STROKE_SELECT;
- /* Search for a selected stroke */
- for (gps = gpf->strokes.first; gps; gps = gps->next) {
- if (ED_gpencil_stroke_can_use(C, gps)) {
- if (gps->flag & GP_STROKE_SELECT) {
- found = true;
- break;
+ changed = true;
}
}
}
-
- /* Select all if found */
- if (found) {
+ else {
for (gps = gpf->strokes.first; gps; gps = gps->next) {
if (ED_gpencil_stroke_can_use(C, gps)) {
bGPDspoint *pt;
@@ -450,8 +554,8 @@ static bool gpencil_select_same_layer(bContext *C)
}
}
}
- CTX_DATA_END;
}
+ CTX_DATA_END;
return changed;
}
@@ -465,21 +569,36 @@ static bool gpencil_select_same_material(bContext *C)
GSet *selected_colors = BLI_gset_str_new("GP Selected Colors");
bool changed = false;
- if (is_curve_edit) {
- /* TODO: do curve select */
+
+ CTX_DATA_BEGIN (C, bGPDstroke *, gps, editable_gpencil_strokes) {
+ if (gps->flag & GP_STROKE_SELECT) {
+ /* add instead of insert here, otherwise the uniqueness check gets skipped,
+ * and we get many duplicate entries...
+ */
+ BLI_gset_add(selected_colors, &gps->mat_nr);
+ }
}
- else {
+ CTX_DATA_END;
+
+ /* Second, select any visible stroke that uses these colors */
+ if (is_curve_edit) {
CTX_DATA_BEGIN (C, bGPDstroke *, gps, editable_gpencil_strokes) {
- if (gps->flag & GP_STROKE_SELECT) {
- /* add instead of insert here, otherwise the uniqueness check gets skipped,
- * and we get many duplicate entries...
- */
- BLI_gset_add(selected_colors, &gps->mat_nr);
+ if (gps->editcurve != NULL && BLI_gset_haskey(selected_colors, &gps->mat_nr)) {
+ bGPDcurve *gpc = gps->editcurve;
+ for (int i = 0; i < gpc->tot_curve_points; i++) {
+ bGPDcurve_point *gpc_pt = &gpc->curve_points[i];
+ gpc_pt->flag |= GP_CURVE_POINT_SELECT;
+ BEZT_SEL_ALL(&gpc_pt->bezt);
+ }
+ gpc->flag |= GP_CURVE_SELECT;
+ gps->flag |= GP_STROKE_SELECT;
+
+ changed = true;
}
}
CTX_DATA_END;
-
- /* Second, select any visible stroke that uses these colors */
+ }
+ else {
CTX_DATA_BEGIN (C, bGPDstroke *, gps, editable_gpencil_strokes) {
if (BLI_gset_haskey(selected_colors, &gps->mat_nr)) {
/* select this stroke */
@@ -591,19 +710,33 @@ static int gpencil_select_first_exec(bContext *C, wmOperator *op)
const bool extend = RNA_boolean_get(op->ptr, "extend");
bool changed = false;
- if (is_curve_edit) {
- /* TODO: do curve select */
- }
- else {
- CTX_DATA_BEGIN (C, bGPDstroke *, gps, editable_gpencil_strokes) {
- /* skip stroke if we're only manipulating selected strokes */
- if (only_selected && !(gps->flag & GP_STROKE_SELECT)) {
- continue;
- }
+ CTX_DATA_BEGIN (C, bGPDstroke *, gps, editable_gpenc
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list