Added extend-select for edit mesh.

Note for operator design; you cannot give operators hardcoded 
properties like "SHIFT" or "ALT", that conflicts with the idea
of keymaps. Instead the properties have to be functional, like
setting 'extend' on or off.

I also think mouse select could get these operators:

- activate/select, option 'extend'
- activate/select on object center, option 'extend'
- activate/select, with menu, option 'extend'

and of course loop-select, group-select, and so on.

BTW: border-select could also get 'extend' option :)
This commit is contained in:
Ton Roosendaal 2008-12-31 17:50:00 +00:00
parent b54d8f3c57
commit 0371e6cb21
4 changed files with 29 additions and 61 deletions

@ -104,7 +104,7 @@ void EM_editselection_plane(float *plane, EditSelection *ese);
/* editmesh_mods.c */ /* editmesh_mods.c */
extern unsigned int em_vertoffs, em_solidoffs, em_wireoffs; extern unsigned int em_vertoffs, em_solidoffs, em_wireoffs;
void mouse_mesh(struct bContext *C, short mval[2]); void mouse_mesh(struct bContext *C, short mval[2], short extend);
int EM_check_backbuf(unsigned int index); int EM_check_backbuf(unsigned int index);
int EM_mask_init_backbuf_border(struct View3D *v3d, short mcords[][2], short tot, short xmin, short ymin, short xmax, short ymax); int EM_mask_init_backbuf_border(struct View3D *v3d, short mcords[][2], short tot, short xmin, short ymin, short xmax, short ymax);
void EM_free_backbuf(void); void EM_free_backbuf(void);

@ -2174,13 +2174,13 @@ static void mouse_mesh_loop(ViewContext *vc)
/* here actual select happens */ /* here actual select happens */
void mouse_mesh(bContext *C, short mval[2]) void mouse_mesh(bContext *C, short mval[2], short extend)
{ {
ViewContext vc; ViewContext vc;
EditVert *eve; EditVert *eve;
EditEdge *eed; EditEdge *eed;
EditFace *efa; EditFace *efa;
int shift= 0, alt= 0; // XXX int alt= 0; // XXX
/* setup view context for argument to callbacks */ /* setup view context for argument to callbacks */
em_setup_viewcontext(C, &vc); em_setup_viewcontext(C, &vc);
@ -2190,7 +2190,7 @@ void mouse_mesh(bContext *C, short mval[2])
if(alt) mouse_mesh_loop(&vc); if(alt) mouse_mesh_loop(&vc);
else if(unified_findnearest(&vc, &eve, &eed, &efa)) { else if(unified_findnearest(&vc, &eve, &eed, &efa)) {
if((shift)==0) EM_clear_flag_all(vc.em, SELECT); if(extend==0) EM_clear_flag_all(vc.em, SELECT);
if(efa) { if(efa) {
/* set the last selected face */ /* set the last selected face */
@ -2200,7 +2200,7 @@ void mouse_mesh(bContext *C, short mval[2])
EM_store_selection(vc.em, efa, EDITFACE); EM_store_selection(vc.em, efa, EDITFACE);
EM_select_face_fgon(vc.em, efa, 1); EM_select_face_fgon(vc.em, efa, 1);
} }
else if(shift) { else if(extend) {
EM_remove_selection(vc.em, efa, EDITFACE); EM_remove_selection(vc.em, efa, EDITFACE);
EM_select_face_fgon(vc.em, efa, 0); EM_select_face_fgon(vc.em, efa, 0);
} }
@ -2210,7 +2210,7 @@ void mouse_mesh(bContext *C, short mval[2])
EM_store_selection(vc.em, eed, EDITEDGE); EM_store_selection(vc.em, eed, EDITEDGE);
EM_select_edge(eed, 1); EM_select_edge(eed, 1);
} }
else if(shift) { else if(extend) {
EM_remove_selection(vc.em, eed, EDITEDGE); EM_remove_selection(vc.em, eed, EDITEDGE);
EM_select_edge(eed, 0); EM_select_edge(eed, 0);
} }
@ -2220,7 +2220,7 @@ void mouse_mesh(bContext *C, short mval[2])
eve->f |= SELECT; eve->f |= SELECT;
EM_store_selection(vc.em, eve, EDITVERT); EM_store_selection(vc.em, eve, EDITVERT);
} }
else if(shift){ else if(extend){
EM_remove_selection(vc.em, eve, EDITVERT); EM_remove_selection(vc.em, eve, EDITVERT);
eve->f &= ~SELECT; eve->f &= ~SELECT;
} }

@ -70,7 +70,6 @@ void view3d_operatortypes(void)
WM_operatortype_append(VIEW3D_OT_viewnumpad); WM_operatortype_append(VIEW3D_OT_viewnumpad);
WM_operatortype_append(VIEW3D_OT_viewcenter); WM_operatortype_append(VIEW3D_OT_viewcenter);
WM_operatortype_append(VIEW3D_OT_select); WM_operatortype_append(VIEW3D_OT_select);
WM_operatortype_append(VIEW3D_OT_select_extend);
WM_operatortype_append(VIEW3D_OT_borderselect); WM_operatortype_append(VIEW3D_OT_borderselect);
WM_operatortype_append(VIEW3D_OT_clipping); WM_operatortype_append(VIEW3D_OT_clipping);
WM_operatortype_append(VIEW3D_OT_circle_select); WM_operatortype_append(VIEW3D_OT_circle_select);
@ -122,14 +121,10 @@ void view3d_keymap(wmWindowManager *wm)
/* selection*/ /* selection*/
WM_keymap_add_item(keymap, "VIEW3D_OT_select", SELECTMOUSE, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "VIEW3D_OT_select", SELECTMOUSE, KM_PRESS, 0, 0);
RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "type", 1);
WM_keymap_add_item(keymap, "VIEW3D_OT_borderselect", BKEY, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "VIEW3D_OT_borderselect", BKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "VIEW3D_OT_circle_select", CKEY, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "VIEW3D_OT_circle_select", CKEY, KM_PRESS, 0, 0);
/* select extend*/
RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_select_extend", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "modifier", KM_SHIFT);
RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_select_extend", SELECTMOUSE, KM_PRESS, KM_CTRL, 0)->ptr, "modifier", KM_CTRL);
RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_select_extend", SELECTMOUSE, KM_PRESS, KM_ALT, 0)->ptr, "modifier", KM_ALT);
WM_keymap_add_item(keymap, "VIEW3D_OT_clipping", BKEY, KM_PRESS, KM_ALT, 0); WM_keymap_add_item(keymap, "VIEW3D_OT_clipping", BKEY, KM_PRESS, KM_ALT, 0);
WM_keymap_add_item(keymap, "VIEW3D_OT_render_border", BKEY, KM_PRESS, KM_SHIFT, 0); WM_keymap_add_item(keymap, "VIEW3D_OT_render_border", BKEY, KM_PRESS, KM_SHIFT, 0);

@ -835,8 +835,9 @@ static short mixed_bones_object_selectbuffer(ViewContext *vc, unsigned int *buff
return 0; return 0;
} }
/* mval is region coords */ /* mval is region coords */
static void mouse_select(bContext *C, short *mval, short modifier) static void mouse_select(bContext *C, short *mval, short extend, short obcenter)
{ {
ViewContext vc; ViewContext vc;
ARegion *ar= CTX_wm_region(C); ARegion *ar= CTX_wm_region(C);
@ -859,10 +860,12 @@ static void mouse_select(bContext *C, short *mval, short modifier)
if(BASACT && BASACT->next) startbase= BASACT->next; if(BASACT && BASACT->next) startbase= BASACT->next;
/* This block uses the control key to make the object selected by its center point rather then its contents */ /* This block uses the control key to make the object selected by its center point rather then its contents */
if(G.obedit==0 && modifier == KM_CTRL) { /* XXX later on, in editmode do not activate */
if(G.obedit==NULL && obcenter) {
/* note; shift+alt goes to group-flush-selecting */ /* note; shift+alt goes to group-flush-selecting */
if(modifier == KM_ALT && modifier == KM_CTRL) /* XXX solve */
if(0)
basact= mouse_select_menu(&vc, NULL, 0, mval); basact= mouse_select_menu(&vc, NULL, 0, mval);
else { else {
base= startbase; base= startbase;
@ -896,7 +899,7 @@ static void mouse_select(bContext *C, short *mval, short modifier)
for(a=0; a<hits; a++) if(buffer[4*a+3] & 0xFFFF0000) has_bones= 1; for(a=0; a<hits; a++) if(buffer[4*a+3] & 0xFFFF0000) has_bones= 1;
/* note; shift+alt goes to group-flush-selecting */ /* note; shift+alt goes to group-flush-selecting */
if(has_bones==0 && (modifier == KM_ALT)) if(has_bones==0 && 0)
basact= mouse_select_menu(&vc, buffer, hits, mval); basact= mouse_select_menu(&vc, buffer, hits, mval);
else { else {
static short lastmval[2]={-100, -100}; static short lastmval[2]={-100, -100};
@ -1023,11 +1026,11 @@ static void mouse_select(bContext *C, short *mval, short modifier)
oldbasact= BASACT; oldbasact= BASACT;
BASACT= basact; BASACT= basact;
if(modifier != KM_SHIFT) { if(!extend) {
deselectall_except(scene, basact); deselectall_except(scene, basact);
ED_base_object_select(basact, BA_SELECT); ED_base_object_select(basact, BA_SELECT);
} }
else if(modifier == KM_CTRL && modifier == KM_ALT) { else if(0) {
// XXX select_all_from_groups(basact); // XXX select_all_from_groups(basact);
} }
else { else {
@ -1442,10 +1445,17 @@ void VIEW3D_OT_borderselect(wmOperatorType *ot)
/* ****** Mouse Select ****** */ /* ****** Mouse Select ****** */
static EnumPropertyItem prop_select_types[] = {
{0, "EXCLUSIVE", "Exclusive", ""},
{1, "EXTEND", "Extend", ""},
{0, NULL, NULL, NULL}
};
static int view3d_select_invoke(bContext *C, wmOperator *op, wmEvent *event) static int view3d_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
{ {
ARegion *ar= CTX_wm_region(C); ARegion *ar= CTX_wm_region(C);
Object *obedit= CTX_data_edit_object(C); Object *obedit= CTX_data_edit_object(C);
short extend= RNA_enum_is_equal(op->ptr, "type", "EXTEND");
short mval[2]; short mval[2];
mval[0]= event->x - ar->winrct.xmin; mval[0]= event->x - ar->winrct.xmin;
@ -1455,16 +1465,17 @@ static int view3d_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
if(obedit) { if(obedit) {
if(obedit->type==OB_MESH) if(obedit->type==OB_MESH)
mouse_mesh(C, mval); mouse_mesh(C, mval, extend);
} }
else else
mouse_select(C, mval, 0); mouse_select(C, mval, extend, 0);
return OPERATOR_FINISHED; return OPERATOR_FINISHED;
} }
void VIEW3D_OT_select(wmOperatorType *ot) void VIEW3D_OT_select(wmOperatorType *ot)
{ {
PropertyRNA *prop;
/* identifiers */ /* identifiers */
ot->name= "Activate/Select"; ot->name= "Activate/Select";
@ -1474,46 +1485,8 @@ void VIEW3D_OT_select(wmOperatorType *ot)
ot->invoke= view3d_select_invoke; ot->invoke= view3d_select_invoke;
ot->poll= ED_operator_view3d_active; ot->poll= ED_operator_view3d_active;
} prop = RNA_def_property(ot->srna, "type", PROP_ENUM, PROP_NONE);
static EnumPropertyItem prop_select_extend_types[] = { RNA_def_property_enum_items(prop, prop_select_types);
{KM_SHIFT, "SHIFT", "Shift", ""},
{KM_CTRL, "CTRL", "Ctrl", ""},
{KM_ALT, "ALT", "Alt", ""},
{0, NULL, NULL, NULL}
};
static int view3d_select_extend_invoke(bContext *C, wmOperator *op, wmEvent *event)
{
ARegion *ar= CTX_wm_region(C);
short mval[2], modifier;
mval[0]= event->x - ar->winrct.xmin;
mval[1]= event->y - ar->winrct.ymin;
modifier = RNA_enum_get(op->ptr, "modifier");
view3d_operator_needs_opengl(C);
mouse_select(C, mval, modifier);
return OPERATOR_FINISHED;
}
void VIEW3D_OT_select_extend(wmOperatorType *ot)
{
PropertyRNA *prop;
/* identifiers */
ot->name= "Activate/Select Extend";
ot->idname= "VIEW3D_OT_select_extend";
/* api callbacks */
ot->invoke= view3d_select_extend_invoke;
ot->poll= ED_operator_view3d_active;
prop = RNA_def_property(ot->srna, "modifier", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_items(prop, prop_select_extend_types);
} }