From dc82c2cd4817c6c84a4dd7e313eb2659a8830d59 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 10 May 2016 04:37:00 +1000 Subject: [PATCH] View selected support for grease-pencil --- .../blender/editors/gpencil/gpencil_utils.c | 18 +++++++++++++++ source/blender/editors/include/ED_gpencil.h | 4 ++++ .../editors/space_view3d/view3d_edit.c | 22 ++++++++++++++++++- 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c index f54da91af71..b2c6107ab61 100644 --- a/source/blender/editors/gpencil/gpencil_utils.c +++ b/source/blender/editors/gpencil/gpencil_utils.c @@ -641,3 +641,21 @@ void gp_subdivide_stroke(bGPDstroke *gps, const int new_totpoints) } /* ******************************************************** */ + + +bool ED_gpencil_stroke_minmax( + const bGPDstroke *gps, const bool use_select, + float r_min[3], float r_max[3]) +{ + const bGPDspoint *pt; + int i; + bool changed = false; + + for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { + if ((use_select == false) || (pt->flag & GP_SPOINT_SELECT)) {; + minmax_v3v3_v3(r_min, r_max, &pt->x); + changed = true; + } + } + return changed; +} diff --git a/source/blender/editors/include/ED_gpencil.h b/source/blender/editors/include/ED_gpencil.h index 0f638c449ad..255827db373 100644 --- a/source/blender/editors/include/ED_gpencil.h +++ b/source/blender/editors/include/ED_gpencil.h @@ -86,6 +86,10 @@ bool ED_gpencil_has_keyframe_v3d(struct Scene *scene, struct Object *ob, int cfr bool ED_gpencil_stroke_can_use_direct(const struct ScrArea *sa, const struct bGPDstroke *gps); bool ED_gpencil_stroke_can_use(const struct bContext *C, const struct bGPDstroke *gps); +bool ED_gpencil_stroke_minmax( + const struct bGPDstroke *gps, const bool use_select, + float r_min[3], float r_max[3]); + /* ----------- Grease Pencil Operators ----------------- */ void ED_keymap_gpencil(struct wmKeyConfig *keyconf); diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 9ee00d2413c..c7a10d65071 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -37,6 +37,7 @@ #include "DNA_curve_types.h" #include "DNA_object_types.h" #include "DNA_scene_types.h" +#include "DNA_gpencil_types.h" #include "MEM_guardedalloc.h" @@ -74,6 +75,7 @@ #include "ED_screen.h" #include "ED_transform.h" #include "ED_mesh.h" +#include "ED_gpencil.h" #include "ED_view3d.h" #include "UI_resources.h" @@ -3019,6 +3021,8 @@ static int viewselected_exec(bContext *C, wmOperator *op) ARegion *ar = CTX_wm_region(C); View3D *v3d = CTX_wm_view3d(C); Scene *scene = CTX_data_scene(C); + bGPdata *gpd = CTX_data_gpencil_data(C); + const bool is_gp_edit = ((gpd) && (gpd->flag & GP_DATA_STROKE_EDITMODE)); Object *ob = OBACT; Object *obedit = CTX_data_edit_object(C); float min[3], max[3]; @@ -3031,6 +3035,10 @@ static int viewselected_exec(bContext *C, wmOperator *op) INIT_MINMAX(min, max); + if (is_gp_edit) { + ob = NULL; + } + if (ob && (ob->mode & OB_MODE_WEIGHT_PAINT)) { /* hard-coded exception, we look for the one selected armature */ /* this is weak code this way, we should make a generic active/selection callback interface once... */ @@ -3047,7 +3055,19 @@ static int viewselected_exec(bContext *C, wmOperator *op) } - if (obedit) { + if (is_gp_edit) { + CTX_DATA_BEGIN(C, bGPDstroke *, gps, editable_gpencil_strokes) + { + /* we're only interested in selected points here... */ + if ((gps->flag & GP_STROKE_SELECT) && (gps->flag & GP_STROKE_3DSPACE)) { + if (ED_gpencil_stroke_minmax(gps, true, min, max)) { + ok = true; + } + } + } + CTX_DATA_END; + } + else if (obedit) { ok = ED_view3d_minmax_verts(obedit, min, max); /* only selected */ } else if (ob && (ob->mode & OB_MODE_POSE)) {