[Bf-blender-cvs] [78a38f1ec90] soc-2020-greasepencil-curve: GPencil: Selection syncing from/to curve edit mode
falk
noreply at git.blender.org
Tue Jun 23 16:24:54 CEST 2020
Commit: 78a38f1ec90982a0623bd92cce7e0b2513a4783a
Author: falk
Date: Tue Jun 23 16:00:51 2020 +0200
Branches: soc-2020-greasepencil-curve
https://developer.blender.org/rB78a38f1ec90982a0623bd92cce7e0b2513a4783a
GPencil: Selection syncing from/to curve edit mode
===================================================================
M source/blender/blenkernel/BKE_gpencil_curve.h
M source/blender/blenkernel/intern/gpencil_curve.c
M source/blender/makesrna/intern/rna_gpencil.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_gpencil_curve.h b/source/blender/blenkernel/BKE_gpencil_curve.h
index 2e8ba51e95d..eb9a02f7702 100644
--- a/source/blender/blenkernel/BKE_gpencil_curve.h
+++ b/source/blender/blenkernel/BKE_gpencil_curve.h
@@ -46,6 +46,8 @@ void BKE_gpencil_convert_curve(struct Main *bmain,
struct bGPDcurve *BKE_gpencil_stroke_editcurve_generate(struct bGPDstroke *gps,
float error_threshold);
void BKE_gpencil_stroke_editcurve_update(struct bGPDstroke *gps, float error_threshold);
+void BKE_gpencil_editcurve_stroke_sync_selection(struct bGPDstroke *gps, struct bGPDcurve *gpc);
+void BKE_gpencil_stroke_editcurve_sync_selection(struct bGPDstroke *gps, struct bGPDcurve *gpc);
void BKE_gpencil_selected_strokes_editcurve_update(struct bGPdata *gpd);
void BKE_gpencil_stroke_update_geometry_from_editcurve(struct bGPDstroke *gps);
diff --git a/source/blender/blenkernel/intern/gpencil_curve.c b/source/blender/blenkernel/intern/gpencil_curve.c
index 14e2a9836c4..15b0b052054 100644
--- a/source/blender/blenkernel/intern/gpencil_curve.c
+++ b/source/blender/blenkernel/intern/gpencil_curve.c
@@ -542,6 +542,58 @@ void BKE_gpencil_stroke_editcurve_update(bGPDstroke *gps, float error_threshold)
gps->editcurve = editcurve;
}
+void BKE_gpencil_editcurve_stroke_sync_selection(bGPDstroke *gps, bGPDcurve *gpc)
+{
+ if (gps->flag & GP_STROKE_SELECT) {
+ gpc->flag |= GP_CURVE_SELECT;
+ }
+ else {
+ gpc->flag &= ~GP_CURVE_SELECT;
+ }
+
+ for(int i = 0; i < gpc->tot_curve_points; i++) {
+ bGPDcurve_point *gpc_pt = &gpc->curve_points[i];
+ bGPDspoint *pt = &gps->points[gpc_pt->point_index];
+ if (pt->flag & GP_SPOINT_SELECT) {
+ gpc_pt->flag |= GP_CURVE_POINT_SELECT;
+ BEZT_SEL_ALL(&gpc_pt->bezt);
+ }
+ else {
+ gpc_pt->flag &= ~GP_CURVE_POINT_SELECT;
+ BEZT_DESEL_ALL(&gpc_pt->bezt);
+ }
+ }
+}
+
+void BKE_gpencil_stroke_editcurve_sync_selection(bGPDstroke *gps, bGPDcurve *gpc)
+{
+ if (gpc->flag & GP_CURVE_SELECT) {
+ gps->flag |= GP_STROKE_SELECT;
+ }
+ else {
+ gps->flag &= ~GP_STROKE_SELECT;
+ }
+
+ for(int i = 0; i < gpc->tot_curve_points; i++) {
+ bGPDcurve_point *gpc_pt = &gpc->curve_points[i];
+ bGPDspoint *pt = &gps->points[gpc_pt->point_index];
+
+ if (gpc_pt->flag & GP_CURVE_POINT_SELECT) {
+ pt->flag |= GP_SPOINT_SELECT;
+ if (i + 1 < gpc->tot_curve_points) {
+ bGPDcurve_point *gpc_pt_next = &gpc->curve_points[i+1];
+ if (gpc_pt_next->flag & GP_CURVE_POINT_SELECT) {
+ /* select all the points inbetween */
+ for (int j = gpc_pt->point_index + 1; j < gpc_pt_next->point_index; j++) {
+ bGPDspoint *pt_next = &gps->points[j];
+ pt_next->flag |= GP_SPOINT_SELECT;
+ }
+ }
+ }
+ }
+ }
+}
+
/**
* Update editcurve for all selected strokes.
*/
@@ -566,12 +618,15 @@ void BKE_gpencil_selected_strokes_editcurve_update(bGPdata *gpd)
continue;
}
- BKE_gpencil_stroke_editcurve_update(gps, gpd->curve_edit_threshold);
- if (gps->editcurve != NULL) {
- gps->editcurve->resolution = gpd->editcurve_resolution;
- gps->editcurve->flag |= GP_CURVE_RECALC_GEOMETRY;
+ if (gps->editcurve == NULL) {
+ BKE_gpencil_stroke_editcurve_update(gps, gpd->curve_edit_threshold);
+ if (gps->editcurve != NULL) {
+ gps->editcurve->resolution = gpd->editcurve_resolution;
+ gps->editcurve->flag |= GP_CURVE_RECALC_GEOMETRY;
+ }
+ BKE_gpencil_stroke_geometry_update(gps);
}
- BKE_gpencil_stroke_geometry_update(gps);
+ BKE_gpencil_editcurve_stroke_sync_selection(gps, gps->editcurve);
}
}
}
diff --git a/source/blender/makesrna/intern/rna_gpencil.c b/source/blender/makesrna/intern/rna_gpencil.c
index 92887ad54a1..94602659c09 100644
--- a/source/blender/makesrna/intern/rna_gpencil.c
+++ b/source/blender/makesrna/intern/rna_gpencil.c
@@ -186,6 +186,7 @@ static void rna_GPencil_curve_edit_update(Main *bmain, Scene *scene, PointerRNA
{
ToolSettings *ts = scene->toolsettings;
bGPdata *gpd = (bGPdata *)ptr->owner_id;
+ const bool is_multiedit = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd);
/* curve edit mode is turned on */
if (GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd)) {
@@ -201,15 +202,14 @@ static void rna_GPencil_curve_edit_update(Main *bmain, Scene *scene, PointerRNA
else {
/* deselect all strokes for now */
LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
- if (gpl->actframe != NULL) {
- bGPDframe *gpf = gpl->actframe;
- LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
- bGPDspoint *pt;
- int i;
- for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
- pt->flag &= ~GP_SPOINT_SELECT;
+ bGPDframe *init_gpf = (is_multiedit) ? gpl->frames.first : gpl->actframe;
+ for (bGPDframe *gpf = init_gpf; gpf; gpf = gpf->next) {
+ if ((gpf == gpl->actframe) || ((gpf->flag & GP_FRAME_SELECT) && is_multiedit)) {
+ LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
+ if (gps->editcurve != NULL) {
+ BKE_gpencil_stroke_editcurve_sync_selection(gps, gps->editcurve);
+ }
}
- gps->flag &= ~GP_STROKE_SELECT;
}
}
}
More information about the Bf-blender-cvs
mailing list