View selected support for grease-pencil

This commit is contained in:
Campbell Barton 2016-05-10 04:37:00 +10:00
parent 119230b565
commit dc82c2cd48
3 changed files with 43 additions and 1 deletions

View File

@ -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;
}

View File

@ -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);

View File

@ -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)) {