Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonio Vazquez <blendergit@gmail.com>2022-01-19 18:58:29 +0300
committerAntonio Vazquez <blendergit@gmail.com>2022-01-19 18:58:29 +0300
commit531d0fa8e3697ca1e10dd7c4447de2e3bd038ae1 (patch)
treed107933f7be9a7ebfa149e3f7f6c662ba5dcd656 /source/blender/editors/gpencil/gpencil_asset.c
parent52798653bc1397885ce7e530de9483ade6c0ff7e (diff)
Cleanup code and avoid duplications
Also be sure the selection index is set as expected (this index is used in interpolation tools)
Diffstat (limited to 'source/blender/editors/gpencil/gpencil_asset.c')
-rw-r--r--source/blender/editors/gpencil/gpencil_asset.c45
1 files changed, 31 insertions, 14 deletions
diff --git a/source/blender/editors/gpencil/gpencil_asset.c b/source/blender/editors/gpencil/gpencil_asset.c
index 40998f57b8f..ad44d1c89c6 100644
--- a/source/blender/editors/gpencil/gpencil_asset.c
+++ b/source/blender/editors/gpencil/gpencil_asset.c
@@ -333,8 +333,10 @@ static bool gpencil_asset_create(const bContext *C,
}
}
/* Unselect all strokes and points. */
+ gpd->select_last_index = 0;
LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
gps->flag &= ~GP_STROKE_SELECT;
+ BKE_gpencil_stroke_select_index_reset(gps);
bGPDspoint *pt;
int i;
for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
@@ -956,6 +958,16 @@ static void gpencil_asset_set_selection(tGPDasset *tgpa, const bool enable)
pt->flag &= ~GP_SPOINT_SELECT;
}
}
+
+ /* Set selection index. */
+ if (enable) {
+ gps->flag |= GP_STROKE_SELECT;
+ BKE_gpencil_stroke_select_index_set(tgpa->gpd, gps);
+ }
+ else {
+ gps->flag &= ~GP_STROKE_SELECT;
+ BKE_gpencil_stroke_select_index_reset(gps);
+ }
}
}
@@ -1351,6 +1363,19 @@ static int gpencil_asset_import_invoke(bContext *C, wmOperator *op, const wmEven
return OPERATOR_RUNNING_MODAL;
}
+static void gpencil_confirm_asset_import(bContext *C,
+ wmOperator *op,
+ wmWindow *win,
+ tGPDasset *tgpa)
+{
+ /* Return to normal cursor and header status. */
+ ED_area_status_text(tgpa->area, NULL);
+ ED_workspace_status_text(C, NULL);
+ WM_cursor_modal_restore(win);
+ /* Select imported strokes. */
+ gpencil_asset_set_selection(tgpa, true);
+}
+
/* Modal handler: Events handling during interactive part. */
static int gpencil_asset_import_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
@@ -1369,16 +1394,15 @@ static int gpencil_asset_import_modal(bContext *C, wmOperator *op, const wmEvent
if (tgpa->flag & GP_ASSET_FLAG_IDLE) {
+ /* If click outside cage, confirm the current asset import. */
if (!BLI_rctf_isect_pt(&rect_big, (float)event->mval[0], (float)event->mval[1])) {
- ED_area_status_text(tgpa->area, NULL);
- ED_workspace_status_text(C, NULL);
- WM_cursor_modal_restore(win);
- /* Select always the strokes. */
- gpencil_asset_set_selection(tgpa, true);
-
+ gpencil_confirm_asset_import(C, op, win, tgpa);
+ /* Clean up temp data. */
gpencil_asset_import_exit(C, op);
+ /* Done! */
return OPERATOR_FINISHED;
}
+
copy_v2_v2_int(tgpa->mouse, event->mval);
/* Distance to asset center. */
@@ -1410,16 +1434,9 @@ static int gpencil_asset_import_modal(bContext *C, wmOperator *op, const wmEvent
/* Confirm. */
case EVT_PADENTER:
case EVT_RETKEY: {
- /* Return to normal cursor and header status. */
- ED_area_status_text(tgpa->area, NULL);
- ED_workspace_status_text(C, NULL);
- WM_cursor_modal_restore(win);
- /* Apply selection depending of mode. */
- gpencil_asset_set_selection(tgpa, GPENCIL_EDIT_MODE(tgpa->gpd));
-
+ gpencil_confirm_asset_import(C, op, win, tgpa);
/* Clean up temp data. */
gpencil_asset_import_exit(C, op);
-
/* Done! */
return OPERATOR_FINISHED;
}