[Bf-blender-cvs] [9d69d642ff1] soc-2020-greasepencil-curve: GPencil: Recalculate curve when entering editmode
Falk David
noreply at git.blender.org
Fri Jul 17 14:18:09 CEST 2020
Commit: 9d69d642ff17fad683840d055a9b4b8393de92da
Author: Falk David
Date: Fri Jul 17 13:36:14 2020 +0200
Branches: soc-2020-greasepencil-curve
https://developer.blender.org/rB9d69d642ff17fad683840d055a9b4b8393de92da
GPencil: Recalculate curve when entering editmode
===================================================================
M source/blender/blenkernel/BKE_gpencil_curve.h
M source/blender/blenkernel/intern/gpencil_curve.c
M source/blender/editors/gpencil/gpencil_edit.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 3527d678355..b066e901211 100644
--- a/source/blender/blenkernel/BKE_gpencil_curve.h
+++ b/source/blender/blenkernel/BKE_gpencil_curve.h
@@ -48,7 +48,8 @@ struct bGPDcurve *BKE_gpencil_stroke_editcurve_generate(struct bGPDstroke *gps,
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_strokes_selected_update_editcurve(struct bGPdata *gpd);
+void BKE_gpencil_strokes_selected_sync_selection_editcurve(struct bGPdata *gpd);
void BKE_gpencil_stroke_update_geometry_from_editcurve(struct bGPDstroke *gps);
void BKE_gpencil_editcurve_recalculate_handles(struct bGPDstroke *gps);
void BKE_gpencil_editcurve_subdivide(struct bGPDstroke *gps, const int cuts);
diff --git a/source/blender/blenkernel/intern/gpencil_curve.c b/source/blender/blenkernel/intern/gpencil_curve.c
index 3bd60746028..f04e1a4bd5f 100644
--- a/source/blender/blenkernel/intern/gpencil_curve.c
+++ b/source/blender/blenkernel/intern/gpencil_curve.c
@@ -991,4 +991,67 @@ void BKE_gpencil_editcurve_subdivide(bGPDstroke *gps, const int cuts)
}
}
+void BKE_gpencil_strokes_selected_update_editcurve(bGPdata *gpd)
+{
+ const bool is_multiedit = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd);
+ /* For all selected strokes, update edit curve. */
+ LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
+ if (!BKE_gpencil_layer_is_editable(gpl)) {
+ continue;
+ }
+ 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) {
+ /* skip deselected stroke */
+ if (!(gps->flag & GP_STROKE_SELECT)) {
+ continue;
+ }
+
+ /* Generate the curve if there is none or the stroke was changed */
+ if (gps->editcurve == NULL) {
+ BKE_gpencil_stroke_editcurve_update(gps, gpd->curve_edit_threshold);
+ /* Continue if curve could not be generated. */
+ if (gps->editcurve == NULL) {
+ continue;
+ }
+ }
+ else if (gps->editcurve->flag & GP_CURVE_NEEDS_STROKE_UPDATE) {
+ BKE_gpencil_stroke_editcurve_update(gps, gpd->curve_edit_threshold);
+ }
+ /* Update the selection from the stroke to the curve. */
+ BKE_gpencil_editcurve_stroke_sync_selection(gps, gps->editcurve);
+
+ gps->editcurve->resolution = gpd->editcurve_resolution;
+ gps->flag |= GP_STROKE_NEEDS_CURVE_UPDATE;
+ BKE_gpencil_stroke_geometry_update(gpd, gps);
+ }
+ }
+ }
+ }
+}
+
+void BKE_gpencil_strokes_selected_sync_selection_editcurve(bGPdata *gpd)
+{
+ const bool is_multiedit = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd);
+ /* Sync selection for all strokes with editcurve. */
+ LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
+ if (!BKE_gpencil_layer_is_editable(gpl)) {
+ continue;
+ }
+ 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) {
+ bGPDcurve *gpc = gps->editcurve;
+ if (gpc != NULL) {
+ /* Update the selection of every stroke that has an editcurve */
+ BKE_gpencil_stroke_editcurve_sync_selection(gps, gpc);
+ }
+ }
+ }
+ }
+ }
+}
+
/** \} */
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index 51cb9dea743..10857aed866 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -202,6 +202,10 @@ static int gpencil_editmode_toggle_exec(bContext *C, wmOperator *op)
ob->mode = mode;
}
+ if (GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd)) {
+ BKE_gpencil_strokes_selected_update_editcurve(gpd);
+ }
+
/* setup other modes */
ED_gpencil_setup_modes(C, gpd, mode);
/* set cache as dirty */
diff --git a/source/blender/makesrna/intern/rna_gpencil.c b/source/blender/makesrna/intern/rna_gpencil.c
index b32b31f3dd3..2bd2aea94f8 100644
--- a/source/blender/makesrna/intern/rna_gpencil.c
+++ b/source/blender/makesrna/intern/rna_gpencil.c
@@ -186,7 +186,6 @@ static void rna_GPencil_curve_edit_mode_toggle(Main *bmain, Scene *scene, Pointe
{
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)) {
@@ -196,62 +195,11 @@ static void rna_GPencil_curve_edit_mode_toggle(Main *bmain, Scene *scene, Pointe
ts->gpencil_selectmode_edit = GP_SELECTMODE_POINT;
}
- /* For all selected strokes, update edit curve. */
- LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
- if (!BKE_gpencil_layer_is_editable(gpl)) {
- continue;
- }
- 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) {
- /* skip deselected stroke */
- if (!(gps->flag & GP_STROKE_SELECT)) {
- continue;
- }
-
- /* Generate the curve if there is none or the stroke was changed */
- if (gps->editcurve == NULL) {
- BKE_gpencil_stroke_editcurve_update(gps, gpd->curve_edit_threshold);
- /* Continue if curve could not be generated. */
- if (gps->editcurve == NULL) {
- continue;
- }
- }
- else if (gps->editcurve->flag & GP_CURVE_NEEDS_STROKE_UPDATE) {
- BKE_gpencil_stroke_editcurve_update(gps, gpd->curve_edit_threshold);
- }
- /* Update the selection from the stroke to the curve. */
- BKE_gpencil_editcurve_stroke_sync_selection(gps, gps->editcurve);
-
- gps->editcurve->resolution = gpd->editcurve_resolution;
- gps->flag |= GP_STROKE_NEEDS_CURVE_UPDATE;
- BKE_gpencil_stroke_geometry_update(gpd, gps);
- }
- }
- }
- }
+ BKE_gpencil_strokes_selected_update_editcurve(gpd);
}
/* Curve edit mode is turned off. */
else {
- /* Sync selection for all strokes with editcurve. */
- LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
- if (!BKE_gpencil_layer_is_editable(gpl)) {
- continue;
- }
- 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) {
- bGPDcurve *gpc = gps->editcurve;
- if (gpc != NULL) {
- /* Update the selection of every stroke that has an editcurve */
- BKE_gpencil_stroke_editcurve_sync_selection(gps, gpc);
- }
- }
- }
- }
- }
+ BKE_gpencil_strokes_selected_sync_selection_editcurve(gpd);
}
/* Standard update. */
More information about the Bf-blender-cvs
mailing list