diff options
author | Germano Cavalcante <germano.costa@ig.com.br> | 2020-12-04 18:22:50 +0300 |
---|---|---|
committer | Germano Cavalcante <germano.costa@ig.com.br> | 2020-12-04 18:31:30 +0300 |
commit | b9195116075420b09969eacd4ba91c4cce7b7b5c (patch) | |
tree | 2a9a67fdbf1262e436bb339c63dc48be51095eee /source/blender/editors/transform | |
parent | fe1f05de1b77798650b91c4e5f8c2b02c3276b18 (diff) |
Cleanup: Deduplicate constraint event code
Diffstat (limited to 'source/blender/editors/transform')
-rw-r--r-- | source/blender/editors/transform/transform.c | 119 | ||||
-rw-r--r-- | source/blender/editors/transform/transform_constraints.c | 10 |
2 files changed, 48 insertions, 81 deletions
diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index 3b8f7f90edc..2004e3b052d 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -713,55 +713,67 @@ wmKeyMap *transform_modal_keymap(wmKeyConfig *keyconf) return keymap; } -static void transform_event_xyz_constraint(TransInfo *t, short key_type, bool is_plane) +static bool transform_event_modal_constraint(TransInfo *t, short modal_type) { if (!(t->flag & T_NO_CONSTRAINT)) { - char cmode = constraintModeToChar(t); - int constraint_axis, constraint_plane; - const bool edit_2d = (t->flag & T_2D_EDIT) != 0; - const char *msg1 = "", *msg2 = "", *msg3 = ""; - char axis; + if (t->flag & T_2D_EDIT && ELEM(modal_type, TFM_MODAL_AXIS_Z, TFM_MODAL_PLANE_Z)) { + return false; + } + int constraint_curr = (t->con.mode & CON_APPLY) ? + t->con.mode & (CON_AXIS0 | CON_AXIS1 | CON_AXIS2) : + -1; + int constraint_new; + const char *msg_2d = "", *msg_3d = ""; /* Initialize */ - switch (key_type) { - case EVT_XKEY: - msg1 = TIP_("along X"); - msg2 = TIP_("along %s X"); - msg3 = TIP_("locking %s X"); - axis = 'X'; - constraint_axis = CON_AXIS0; + switch (modal_type) { + case TFM_MODAL_AXIS_X: + msg_2d = TIP_("along X"); + msg_3d = TIP_("along %s X"); + constraint_new = CON_AXIS0; + break; + case TFM_MODAL_AXIS_Y: + msg_2d = TIP_("along Y"); + msg_3d = TIP_("along %s Y"); + constraint_new = CON_AXIS1; break; - case EVT_YKEY: - msg1 = TIP_("along Y"); - msg2 = TIP_("along %s Y"); - msg3 = TIP_("locking %s Y"); - axis = 'Y'; - constraint_axis = CON_AXIS1; + case TFM_MODAL_AXIS_Z: + msg_2d = TIP_("along Z"); + msg_3d = TIP_("along %s Z"); + constraint_new = CON_AXIS2; break; - case EVT_ZKEY: - msg1 = TIP_("along Z"); - msg2 = TIP_("along %s Z"); - msg3 = TIP_("locking %s Z"); - axis = 'Z'; - constraint_axis = CON_AXIS2; + case TFM_MODAL_PLANE_X: + msg_3d = TIP_("locking %s X"); + constraint_new = CON_AXIS1 | CON_AXIS2; + break; + case TFM_MODAL_PLANE_Y: + msg_3d = TIP_("locking %s Y"); + constraint_new = CON_AXIS0 | CON_AXIS2; + break; + case TFM_MODAL_PLANE_Z: + msg_3d = TIP_("locking %s Z"); + constraint_new = CON_AXIS0 | CON_AXIS1; break; default: /* Invalid key */ - return; + return false; } - constraint_plane = ((CON_AXIS0 | CON_AXIS1 | CON_AXIS2) & (~constraint_axis)); - if (edit_2d && (key_type != EVT_ZKEY)) { - if (cmode == axis) { + if (t->flag & T_2D_EDIT) { + BLI_assert(modal_type < TFM_MODAL_PLANE_X); + if (constraint_new == CON_AXIS2) { + return false; + } + if (constraint_curr == constraint_new) { stopConstraint(t); } else { - setUserConstraint(t, constraint_axis, msg1); + setUserConstraint(t, constraint_new, msg_2d); } } - else if (!edit_2d) { + else { short orient_index = 1; - if (t->orient_curr == 0 || ELEM(cmode, '\0', axis)) { + if (t->orient_curr == 0 || ELEM(constraint_curr, -1, constraint_new)) { /* Successive presses on existing axis, cycle orientation modes. */ orient_index = (short)((t->orient_curr + 1) % (int)ARRAY_SIZE(t->orient)); } @@ -771,16 +783,13 @@ static void transform_event_xyz_constraint(TransInfo *t, short key_type, bool is stopConstraint(t); } else { - if (is_plane == false) { - setUserConstraint(t, constraint_axis, msg2); - } - else { - setUserConstraint(t, constraint_plane, msg3); - } + setUserConstraint(t, constraint_new, msg_3d); } } t->redraw |= TREDRAW_HARD; + return true; } + return false; } int transformEvent(TransInfo *t, const wmEvent *event) @@ -949,44 +958,12 @@ int transformEvent(TransInfo *t, const wmEvent *event) handled = true; break; case TFM_MODAL_AXIS_X: - if (!(t->flag & T_NO_CONSTRAINT)) { - transform_event_xyz_constraint(t, EVT_XKEY, false); - t->redraw |= TREDRAW_HARD; - handled = true; - } - break; case TFM_MODAL_AXIS_Y: - if ((t->flag & T_NO_CONSTRAINT) == 0) { - transform_event_xyz_constraint(t, EVT_YKEY, false); - t->redraw |= TREDRAW_HARD; - handled = true; - } - break; case TFM_MODAL_AXIS_Z: - if ((t->flag & (T_NO_CONSTRAINT)) == 0) { - transform_event_xyz_constraint(t, EVT_ZKEY, false); - t->redraw |= TREDRAW_HARD; - handled = true; - } - break; case TFM_MODAL_PLANE_X: - if ((t->flag & (T_NO_CONSTRAINT | T_2D_EDIT)) == 0) { - transform_event_xyz_constraint(t, EVT_XKEY, true); - t->redraw |= TREDRAW_HARD; - handled = true; - } - break; case TFM_MODAL_PLANE_Y: - if ((t->flag & (T_NO_CONSTRAINT | T_2D_EDIT)) == 0) { - transform_event_xyz_constraint(t, EVT_YKEY, true); - t->redraw |= TREDRAW_HARD; - handled = true; - } - break; case TFM_MODAL_PLANE_Z: - if ((t->flag & (T_NO_CONSTRAINT | T_2D_EDIT)) == 0) { - transform_event_xyz_constraint(t, EVT_ZKEY, true); - t->redraw |= TREDRAW_HARD; + if (transform_event_modal_constraint(t, event->val)) { handled = true; } break; diff --git a/source/blender/editors/transform/transform_constraints.c b/source/blender/editors/transform/transform_constraints.c index 5e2a8be8db0..54533bf43e5 100644 --- a/source/blender/editors/transform/transform_constraints.c +++ b/source/blender/editors/transform/transform_constraints.c @@ -1127,16 +1127,6 @@ int constraintModeToIndex(const TransInfo *t) } } -char constraintModeToChar(const TransInfo *t) -{ - int index = constraintModeToIndex(t); - if (index == -1) { - return '\0'; - } - BLI_assert((uint)index < 3); - return 'X' + index; -} - bool isLockConstraint(TransInfo *t) { int mode = t->con.mode; |