make selection operator follow mesh selection options from trunk.

This commit is contained in:
Campbell Barton
2012-05-28 05:37:16 +00:00
parent daa8fe9145
commit 8fb7b4073e
6 changed files with 97 additions and 44 deletions

View File

@@ -73,6 +73,9 @@ float BKE_mask_point_weight(struct MaskSpline *spline, struct MaskSplinePoint *p
struct MaskSplinePointUW *BKE_mask_point_sort_uw(struct MaskSplinePoint *point, struct MaskSplinePointUW *uw);
void BKE_mask_point_add_uw(struct MaskSplinePoint *point, float u, float w);
void BKE_mask_point_select_set(struct MaskSplinePoint *point, int select);
void BKE_mask_point_select_set_handle(struct MaskSplinePoint *point, int select);
/* general */
struct Mask *BKE_mask_new(const char *name);
@@ -134,5 +137,6 @@ void BKE_mask_rasterize(struct Mask *mask, int width, int height, float *buffer)
#define MASKPOINT_HANDLE_ONLY_ISSEL(p) ( (((p)->bezt.f1 | (p)->bezt.f2) & SELECT) && (((p)->bezt.f2 & SELECT) == 0) )
#define MASKPOINT_HANDLE_ISSEL(p) ( (((p)->bezt.f1 | (p)->bezt.f2) & SELECT) )
#define MASKPOINT_HANDLE_SEL(p) { (p)->bezt.f1 |= SELECT; (p)->bezt.f3 |= SELECT; } (void)0
#define MASKPOINT_HANDLE_DESEL(p) { (p)->bezt.f1 &= ~SELECT; (p)->bezt.f3 &= ~SELECT; } (void)0
#endif

View File

@@ -41,6 +41,7 @@
#include "DNA_mask_types.h"
#include "DNA_scene_types.h"
#include "DNA_object_types.h"
#include "DNA_screen_types.h"
#include "DNA_space_types.h"
#include "DNA_movieclip_types.h"
@@ -618,6 +619,37 @@ void BKE_mask_point_add_uw(MaskSplinePoint *point, float u, float w)
BKE_mask_point_sort_uw(point, &point->uw[point->tot_uw - 1]);
}
void BKE_mask_point_select_set(MaskSplinePoint *point, int select)
{
int i;
if (select) {
MASKPOINT_SEL(point);
}
else {
MASKPOINT_DESEL(point);
}
for (i = 0; i < point->tot_uw; i++) {
if (select) {
point->uw[i].flag |= SELECT;
}
else {
point->uw[i].flag &= ~SELECT;
}
}
}
void BKE_mask_point_select_set_handle(MaskSplinePoint *point, int select)
{
if (select) {
MASKPOINT_HANDLE_SEL(point);
}
else {
MASKPOINT_HANDLE_DESEL(point);
}
}
/* only mask block itself */
static Mask *mask_alloc(const char *name)
{

View File

@@ -189,10 +189,15 @@ void ED_keymap_mask(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "MASK_OT_delete", XKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "MASK_OT_delete", DELKEY, KM_PRESS, 0, 0);
/* select */
WM_keymap_add_item(keymap, "MASK_OT_select", SELECTMOUSE, KM_PRESS, 0, 0);
/* selection */
kmi = WM_keymap_add_item(keymap, "MASK_OT_select", SELECTMOUSE, KM_PRESS, 0, 0);
RNA_boolean_set(kmi->ptr, "extend", FALSE);
RNA_boolean_set(kmi->ptr, "deselect", FALSE);
RNA_boolean_set(kmi->ptr, "toggle", FALSE);
kmi = WM_keymap_add_item(keymap, "MASK_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0);
RNA_boolean_set(kmi->ptr, "extend", TRUE);
RNA_boolean_set(kmi->ptr, "extend", FALSE);
RNA_boolean_set(kmi->ptr, "deselect", FALSE);
RNA_boolean_set(kmi->ptr, "toggle", TRUE);
kmi = WM_keymap_add_item(keymap, "MASK_OT_select_all", AKEY, KM_PRESS, 0, 0);
RNA_enum_set(kmi->ptr, "action", SEL_TOGGLE);

View File

@@ -73,7 +73,8 @@ void MASK_OT_select_all(struct wmOperatorType *ot);
int ED_mask_spline_select_check(struct MaskSplinePoint *points, int tot_point);
int ED_mask_select_check(struct Mask *mask);
void ED_mask_point_select(struct MaskSplinePoint *point, int action);
void ED_mask_point_select_set(struct MaskSplinePoint *point, int action);
void ED_mask_point_select_set_handle(struct MaskSplinePoint *point, int select);
void ED_mask_select_toggle_all(struct Mask *mask, int action);
void ED_mask_select_flush_all(struct Mask *mask);

View File

@@ -646,7 +646,7 @@ static int slide_point_invoke(bContext *C, wmOperator *op, wmEvent *event)
else if (!MASKPOINT_ISSEL(slidedata->point)) {
ED_mask_select_toggle_all(mask, SEL_DESELECT);
ED_mask_point_select(slidedata->point, SEL_SELECT);
BKE_mask_point_select_set(slidedata->point, TRUE);
ED_mask_select_flush_all(mask);
}

View File

@@ -86,38 +86,6 @@ int ED_mask_select_check(Mask *mask)
return FALSE;
}
void ED_mask_point_select(MaskSplinePoint *point, int action)
{
int i;
switch (action) {
case SEL_SELECT:
MASKPOINT_SEL(point);
break;
case SEL_DESELECT:
MASKPOINT_DESEL(point);
break;
case SEL_INVERT:
MASKPOINT_INVSEL(point);
break;
}
for (i = 0; i < point->tot_uw; i++) {
switch (action) {
case SEL_SELECT:
point->uw[i].flag |= SELECT;
break;
case SEL_DESELECT:
point->uw[i].flag &= ~SELECT;
break;
case SEL_INVERT:
point->uw[i].flag ^= SELECT;
break;
}
}
}
void ED_mask_select_toggle_all(Mask *mask, int action)
{
MaskObject *maskobj;
@@ -138,7 +106,7 @@ void ED_mask_select_toggle_all(Mask *mask, int action)
for (i = 0; i < spline->tot_point; i++) {
MaskSplinePoint *point = &spline->points[i];
ED_mask_point_select(point, action);
BKE_mask_point_select_set(point, (action == SEL_SELECT) ? TRUE : FALSE);
}
}
}
@@ -219,7 +187,10 @@ static int select_exec(bContext *C, wmOperator *op)
MaskSpline *spline;
MaskSplinePoint *point = NULL;
float co[2];
int extend = RNA_boolean_get(op->ptr, "extend");
short extend = RNA_boolean_get(op->ptr, "extend");
short deselect = RNA_boolean_get(op->ptr, "deselect");
short toggle = RNA_boolean_get(op->ptr, "toggle");
int is_handle = 0;
const float threshold = 19;
@@ -228,14 +199,52 @@ static int select_exec(bContext *C, wmOperator *op)
point = ED_mask_point_find_nearest(C, mask, co, threshold, &maskobj, &spline, &is_handle, NULL);
if (point) {
if (!extend)
if (extend == 0 && deselect == 0 && toggle == 0)
ED_mask_select_toggle_all(mask, SEL_DESELECT);
if (is_handle) {
MASKPOINT_HANDLE_SEL(point);
if (extend) {
maskobj->act_spline = spline;
maskobj->act_point = point;
BKE_mask_point_select_set_handle(point, TRUE);
}
else if (deselect) {
BKE_mask_point_select_set_handle(point, FALSE);
}
else {
maskobj->act_spline = spline;
maskobj->act_point = point;
if (!MASKPOINT_HANDLE_ISSEL(point)) {
BKE_mask_point_select_set_handle(point, TRUE);
}
else if (toggle) {
BKE_mask_point_select_set_handle(point, FALSE);
}
}
}
else {
ED_mask_point_select(point, SEL_SELECT);
if (extend) {
maskobj->act_spline = spline;
maskobj->act_point = point;
BKE_mask_point_select_set(point, TRUE);
}
else if (deselect) {
BKE_mask_point_select_set(point, FALSE);
}
else {
maskobj->act_spline = spline;
maskobj->act_point = point;
if (!MASKPOINT_ISSEL(point)) {
BKE_mask_point_select_set(point, TRUE);
}
else if (toggle) {
BKE_mask_point_select_set(point, FALSE);
}
}
}
maskobj->act_spline = spline;
@@ -298,8 +307,10 @@ void MASK_OT_select(wmOperatorType *ot)
ot->flag = OPTYPE_UNDO;
/* properties */
RNA_def_boolean(ot->srna, "extend", 0,
"Extend", "Extend selection rather than clearing the existing selection");
RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend selection instead of deselecting everything first");
RNA_def_boolean(ot->srna, "deselect", 0, "Deselect", "Remove from selection");
RNA_def_boolean(ot->srna, "toggle", 0, "Toggle Selection", "Toggles selection");
RNA_def_float_vector(ot->srna, "location", 2, NULL, -FLT_MIN, FLT_MAX,
"Location", "Location of vertex in normalized space", -1.0f, 1.0f);
}