Transform: Move some hardcoded keyitems to keymap_data in python

Keymaps must be customized by the user.

But this is not the case for hardcoded keymaps.

Also the repetition of hardcoded and user-defined keyitems may induce
the user to think they have made a mistake or it is a bug.

Differential Revision: https://developer.blender.org/D6454
This commit is contained in:
Germano Cavalcante 2020-09-01 09:37:43 -03:00 committed by Germano Cavalcante
parent 17cf500101
commit 526fbdec3b
Notes: blender-bot 2023-02-14 11:25:11 +01:00
Referenced by issue #80429, Most Tools cannot be cancelled
5 changed files with 80 additions and 212 deletions

View File

@ -4952,6 +4952,7 @@ def km_transform_modal_map(_params):
("CONFIRM", {"type": 'LEFTMOUSE', "value": 'PRESS', "any": True}, None),
("CONFIRM", {"type": 'RET', "value": 'PRESS', "any": True}, None),
("CONFIRM", {"type": 'NUMPAD_ENTER', "value": 'PRESS', "any": True}, None),
("CONFIRM", {"type": 'SPACE', "value": 'PRESS', "any": True}, None),
("CANCEL", {"type": 'RIGHTMOUSE', "value": 'PRESS', "any": True}, None),
("CANCEL", {"type": 'ESC', "value": 'PRESS', "any": True}, None),
("AXIS_X", {"type": 'X', "value": 'PRESS', "repeat": False}, None),
@ -4982,11 +4983,18 @@ def km_transform_modal_map(_params):
("PROPORTIONAL_SIZE", {"type": 'TRACKPADPAN', "value": 'ANY'}, None),
("EDGESLIDE_EDGE_NEXT", {"type": 'WHEELDOWNMOUSE', "value": 'PRESS', "alt": True}, None),
("EDGESLIDE_PREV_NEXT", {"type": 'WHEELUPMOUSE', "value": 'PRESS', "alt": True}, None),
("AUTOIK_CHAIN_LEN_UP", {"type": 'PAGE_UP', "value": 'PRESS'}, None),
("AUTOIK_CHAIN_LEN_DOWN", {"type": 'PAGE_DOWN', "value": 'PRESS'}, None),
("AUTOIK_CHAIN_LEN_UP", {"type": 'PAGE_UP', "value": 'PRESS', "shift": True}, None),
("AUTOIK_CHAIN_LEN_DOWN", {"type": 'PAGE_DOWN', "value": 'PRESS', "shift": True}, None),
("AUTOIK_CHAIN_LEN_UP", {"type": 'WHEELDOWNMOUSE', "value": 'PRESS'}, None),
("AUTOIK_CHAIN_LEN_DOWN", {"type": 'WHEELUPMOUSE', "value": 'PRESS'}, None),
("AUTOIK_CHAIN_LEN_UP", {"type": 'WHEELDOWNMOUSE', "value": 'PRESS', "shift": True}, None),
("AUTOIK_CHAIN_LEN_DOWN", {"type": 'WHEELUPMOUSE', "value": 'PRESS', "shift": True}, None),
("INSERTOFS_TOGGLE_DIR", {"type": 'T', "value": 'PRESS', "repeat": False}, None),
("AUTOCONSTRAIN", {"type": 'MIDDLEMOUSE', "value": 'PRESS', "repeat": False}, None),
("CONSTRAINPLANE", {"type": 'LEFT_SHIFT', "value": 'PRESS', "repeat": False}, None),
("CONSTRAINPLANE", {"type": 'RIGHT_SHIFT', "value": 'PRESS', "repeat": False}, None),
])
return keymap

View File

@ -3894,6 +3894,7 @@ def km_transform_modal_map(_params):
("CONFIRM", {"type": 'LEFTMOUSE', "value": 'PRESS', "any": True}, None),
("CONFIRM", {"type": 'RET', "value": 'PRESS', "any": True}, None),
("CONFIRM", {"type": 'NUMPAD_ENTER', "value": 'PRESS', "any": True}, None),
("CONFIRM", {"type": 'SPACE', "value": 'PRESS', "any": True}, None),
("CANCEL", {"type": 'RIGHTMOUSE', "value": 'PRESS', "any": True}, None),
("CANCEL", {"type": 'ESC', "value": 'PRESS', "any": True}, None),
("AXIS_X", {"type": 'X', "value": 'PRESS'}, None),
@ -3924,11 +3925,18 @@ def km_transform_modal_map(_params):
("PROPORTIONAL_SIZE", {"type": 'TRACKPADPAN', "value": 'ANY'}, None),
("EDGESLIDE_EDGE_NEXT", {"type": 'WHEELDOWNMOUSE', "value": 'PRESS', "alt": True}, None),
("EDGESLIDE_PREV_NEXT", {"type": 'WHEELUPMOUSE', "value": 'PRESS', "alt": True}, None),
("AUTOIK_CHAIN_LEN_UP", {"type": 'PAGE_UP', "value": 'PRESS'}, None),
("AUTOIK_CHAIN_LEN_DOWN", {"type": 'PAGE_DOWN', "value": 'PRESS'}, None),
("AUTOIK_CHAIN_LEN_UP", {"type": 'PAGE_UP', "value": 'PRESS', "shift": True}, None),
("AUTOIK_CHAIN_LEN_DOWN", {"type": 'PAGE_DOWN', "value": 'PRESS', "shift": True}, None),
("AUTOIK_CHAIN_LEN_UP", {"type": 'WHEELDOWNMOUSE', "value": 'PRESS'}, None),
("AUTOIK_CHAIN_LEN_DOWN", {"type": 'WHEELUPMOUSE', "value": 'PRESS'}, None),
("AUTOIK_CHAIN_LEN_UP", {"type": 'WHEELDOWNMOUSE', "value": 'PRESS', "shift": True}, None),
("AUTOIK_CHAIN_LEN_DOWN", {"type": 'WHEELUPMOUSE', "value": 'PRESS', "shift": True}, None),
("INSERTOFS_TOGGLE_DIR", {"type": 'T', "value": 'PRESS'}, None),
("AUTOCONSTRAIN", {"type": 'MIDDLEMOUSE', "value": 'PRESS'}, None),
("CONSTRAINPLANE", {"type": 'LEFT_SHIFT', "value": 'PRESS', "repeat": False}, None),
("CONSTRAINPLANE", {"type": 'RIGHT_SHIFT', "value": 'PRESS', "repeat": False}, None),
])
return keymap

View File

@ -560,94 +560,6 @@ static void viewRedrawPost(bContext *C, TransInfo *t)
#endif
}
/* ************************** TRANSFORMATIONS **************************** */
static void view_editmove(ushort UNUSED(event))
{
#if 0 // TRANSFORM_FIX_ME
int refresh = 0;
/* Regular: Zoom in */
/* Shift: Scroll up */
/* Ctrl: Scroll right */
/* Alt-Shift: Rotate up */
/* Alt-Ctrl: Rotate right */
/* only work in 3D window for now
* In the end, will have to send to event to a 2D window handler instead
*/
if (Trans.flag & T_2D_EDIT) {
return;
}
switch (event) {
case WHEELUPMOUSE:
if (G.qual & LR_SHIFTKEY) {
if (G.qual & LR_ALTKEY) {
G.qual &= ~LR_SHIFTKEY;
persptoetsen(PAD2);
G.qual |= LR_SHIFTKEY;
}
else {
persptoetsen(PAD2);
}
}
else if (G.qual & LR_CTRLKEY) {
if (G.qual & LR_ALTKEY) {
G.qual &= ~LR_CTRLKEY;
persptoetsen(PAD4);
G.qual |= LR_CTRLKEY;
}
else {
persptoetsen(PAD4);
}
}
else if (U.uiflag & USER_WHEELZOOMDIR) {
persptoetsen(PADMINUS);
}
else {
persptoetsen(PADPLUSKEY);
}
refresh = 1;
break;
case WHEELDOWNMOUSE:
if (G.qual & LR_SHIFTKEY) {
if (G.qual & LR_ALTKEY) {
G.qual &= ~LR_SHIFTKEY;
persptoetsen(PAD8);
G.qual |= LR_SHIFTKEY;
}
else {
persptoetsen(PAD8);
}
}
else if (G.qual & LR_CTRLKEY) {
if (G.qual & LR_ALTKEY) {
G.qual &= ~LR_CTRLKEY;
persptoetsen(PAD6);
G.qual |= LR_CTRLKEY;
}
else {
persptoetsen(PAD6);
}
}
else if (U.uiflag & USER_WHEELZOOMDIR) {
persptoetsen(PADPLUSKEY);
}
else {
persptoetsen(PADMINUS);
}
refresh = 1;
break;
}
if (refresh) {
setTransformViewMatrices(&Trans);
}
#endif
}
/* ************************************************* */
static bool transform_modal_item_poll(const wmOperator *op, int value)
@ -770,6 +682,17 @@ wmKeyMap *transform_modal_keymap(wmKeyConfig *keyconf)
{TFM_MODAL_TRANSLATE, "TRANSLATE", 0, "Move", ""},
{TFM_MODAL_ROTATE, "ROTATE", 0, "Rotate", ""},
{TFM_MODAL_RESIZE, "RESIZE", 0, "Resize", ""},
{TFM_MODAL_AUTOCONSTRAINT,
"AUTOCONSTRAIN",
0,
"Automatically detects one direction for constraint",
""},
{TFM_MODAL_CONSTRAINTPLANE,
"CONSTRAINPLANE",
0,
"modifier that enables the plane type constraint",
""},
{0, NULL, 0, NULL, NULL},
};
@ -778,6 +701,25 @@ wmKeyMap *transform_modal_keymap(wmKeyConfig *keyconf)
keymap = WM_modalkeymap_ensure(keyconf, "Transform Modal Map", modal_items);
keymap->poll_modal_item = transform_modal_item_poll;
/* Default modal map values:
*
* \code{.c}
* WM_modalkeymap_add_item(keymap, EVT_RETKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_CONFIRM);
* WM_modalkeymap_add_item(keymap, EVT_ESCKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_CANCEL);
* WM_modalkeymap_add_item(keymap, EVT_PAGEUPKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_AUTOIK_LEN_INC);
* WM_modalkeymap_add_item(
* keymap, EVT_PAGEDOWNKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_AUTOIK_LEN_DEC);
* WM_modalkeymap_add_item(keymap, EVT_GKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_TRANSLATE);
* WM_modalkeymap_add_item(keymap, EVT_RKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_ROTATE);
* WM_modalkeymap_add_item(keymap, EVT_SKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_RESIZE);
* WM_modalkeymap_add_item(keymap, MIDDLEMOUSE, KM_PRESS, KM_ANY, 0, TFM_MODAL_AUTOCONSTRAINT);
* WM_modalkeymap_add_item(
* keymap, EVT_LEFTSHIFTKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_CONSTRAINTPLANE);
* WM_modalkeymap_add_item(
* keymap, EVT_RIGHTSHIFTKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_CONSTRAINTPLANE);
* \endcode
*/
return keymap;
}
@ -887,6 +829,7 @@ int transformEvent(TransInfo *t, const wmEvent *event)
handled = true;
}
/* handle modal keymap first */
/* enforce redraw of transform when modifiers are used */
else if (event->type == EVT_MODAL_MAP) {
switch (event->val) {
case TFM_MODAL_CANCEL:
@ -1147,40 +1090,7 @@ int transformEvent(TransInfo *t, const wmEvent *event)
t->redraw |= TREDRAW_SOFT;
}
break;
/* Those two are only handled in transform's own handler, see T44634! */
case TFM_MODAL_EDGESLIDE_UP:
case TFM_MODAL_EDGESLIDE_DOWN:
default:
break;
}
}
/* else do non-mapped events */
else if (event->val == KM_PRESS) {
switch (event->type) {
case EVT_ESCKEY:
case RIGHTMOUSE:
t->state = TRANS_CANCEL;
handled = true;
break;
case EVT_SPACEKEY:
case EVT_PADENTER:
case EVT_RETKEY:
if (event->is_repeat) {
break;
}
t->state = TRANS_CONFIRM;
handled = true;
break;
/* enforce redraw of transform when modifiers are used */
case EVT_LEFTSHIFTKEY:
case EVT_RIGHTSHIFTKEY:
t->modifiers |= MOD_CONSTRAINT_PLANE;
t->redraw |= TREDRAW_HARD;
handled = true;
break;
case MIDDLEMOUSE:
case TFM_MODAL_AUTOCONSTRAINT:
if ((t->flag & T_NO_CONSTRAINT) == 0) {
/* exception for switching to dolly, or trackball, in camera view */
if (t->flag & T_CAMERA) {
@ -1206,59 +1116,21 @@ int transformEvent(TransInfo *t, const wmEvent *event)
handled = true;
}
break;
case EVT_GKEY:
if (event->is_repeat) {
break;
}
/* only switch when... */
if (t->mode != TFM_TRANSLATION && transform_mode_is_changeable(t->mode)) {
restoreTransObjects(t);
resetTransModal(t);
resetTransRestrictions(t);
transform_mode_init(t, NULL, TFM_TRANSLATION);
initSnapping(t, NULL); // need to reinit after mode change
t->redraw |= TREDRAW_HARD;
handled = true;
}
case TFM_MODAL_CONSTRAINTPLANE:
t->modifiers |= MOD_CONSTRAINT_PLANE;
t->redraw |= TREDRAW_HARD;
handled = true;
break;
case EVT_SKEY:
if (event->is_repeat) {
break;
}
/* only switch when... */
if (t->mode != TFM_RESIZE && transform_mode_is_changeable(t->mode)) {
restoreTransObjects(t);
resetTransModal(t);
resetTransRestrictions(t);
transform_mode_init(t, NULL, TFM_RESIZE);
initSnapping(t, NULL); // need to reinit after mode change
t->redraw |= TREDRAW_HARD;
handled = true;
}
break;
case EVT_RKEY:
if (event->is_repeat) {
break;
}
/* only switch when... */
if (!(t->options & CTX_TEXTURE)) {
if (transform_mode_is_changeable(t->mode)) {
restoreTransObjects(t);
resetTransModal(t);
resetTransRestrictions(t);
if (t->mode == TFM_ROTATION) {
transform_mode_init(t, NULL, TFM_TRACKBALL);
}
else {
transform_mode_init(t, NULL, TFM_ROTATION);
}
initSnapping(t, NULL); // need to reinit after mode change
t->redraw |= TREDRAW_HARD;
handled = true;
}
}
/* Those two are only handled in transform's own handler, see T44634! */
case TFM_MODAL_EDGESLIDE_UP:
case TFM_MODAL_EDGESLIDE_DOWN:
default:
break;
}
}
/* Else do non-mapped events. */
else if (event->val == KM_PRESS) {
switch (event->type) {
case EVT_CKEY:
if (event->is_repeat) {
break;
@ -1295,17 +1167,6 @@ int transformEvent(TransInfo *t, const wmEvent *event)
handled = true;
}
break;
case EVT_PAGEUPKEY:
case WHEELDOWNMOUSE:
if (t->flag & T_AUTOIK) {
transform_autoik_update(t, 1);
}
else {
view_editmove(event->type);
}
t->redraw = TREDRAW_HARD;
handled = true;
break;
case EVT_PADMINUS:
if (event->alt && t->flag & T_PROP_EDIT) {
t->prop_size /= (t->modifiers & MOD_PRECISION) ? 1.01f : 1.1f;
@ -1314,17 +1175,6 @@ int transformEvent(TransInfo *t, const wmEvent *event)
handled = true;
}
break;
case EVT_PAGEDOWNKEY:
case WHEELUPMOUSE:
if (t->flag & T_AUTOIK) {
transform_autoik_update(t, -1);
}
else {
view_editmove(event->type);
}
t->redraw = TREDRAW_HARD;
handled = true;
break;
case EVT_LEFTALTKEY:
case EVT_RIGHTALTKEY:
if (ELEM(t->spacetype, SPACE_SEQ, SPACE_VIEW3D)) {
@ -1357,31 +1207,30 @@ int transformEvent(TransInfo *t, const wmEvent *event)
}
else if (event->val == KM_RELEASE) {
switch (event->type) {
case EVT_LEFTSHIFTKEY:
case EVT_RIGHTSHIFTKEY:
t->modifiers &= ~MOD_CONSTRAINT_PLANE;
t->redraw |= TREDRAW_HARD;
handled = true;
break;
case MIDDLEMOUSE:
if ((t->flag & T_NO_CONSTRAINT) == 0) {
t->modifiers &= ~MOD_CONSTRAINT_SELECT;
postSelectConstraint(t);
t->redraw |= TREDRAW_HARD;
handled = true;
}
break;
case EVT_LEFTALTKEY:
case EVT_RIGHTALTKEY:
/* TODO: Modal Map */
if (ELEM(t->spacetype, SPACE_SEQ, SPACE_VIEW3D)) {
t->flag &= ~T_ALT_TRANSFORM;
t->redraw |= TREDRAW_HARD;
handled = true;
}
break;
default:
default: {
/* Disable modifiers. */
int modifiers = t->modifiers;
modifiers &= ~MOD_CONSTRAINT_SELECT;
modifiers &= ~MOD_CONSTRAINT_PLANE;
if (modifiers != t->modifiers) {
if (t->modifiers & MOD_CONSTRAINT_SELECT) {
postSelectConstraint(t);
}
t->modifiers = modifiers;
t->redraw |= TREDRAW_HARD;
handled = true;
}
break;
}
}
/* confirm transform if launch key is released after mouse move */

View File

@ -575,6 +575,9 @@ enum {
TFM_MODAL_PROPSIZE = 26,
/* node editor insert offset (aka auto-offset) direction toggle */
TFM_MODAL_INSERTOFS_TOGGLE_DIR = 27,
TFM_MODAL_AUTOCONSTRAINT = 28,
TFM_MODAL_CONSTRAINTPLANE = 29,
};
bool initTransform(struct bContext *C,

@ -1 +1 @@
Subproject commit f4aa2de034d359bf85c6a0f90c0d045c5858eb8d
Subproject commit 2afbb8ec472cac5102eb239f57b006f8c9387685