diff options
author | Martin Poirier <theeth@yahoo.com> | 2010-01-25 20:48:02 +0300 |
---|---|---|
committer | Martin Poirier <theeth@yahoo.com> | 2010-01-25 20:48:02 +0300 |
commit | c74440f198da9dbafcf563e0ecaa505d0d7834b5 (patch) | |
tree | 4647d9c293a8b28d401ec0c4a693526de86485fa /source/blender/editors/transform | |
parent | 52284155e1a9b0935c91a55009f16132622c964c (diff) |
Use modal keymap events for transform numinput increment and decrement
Diffstat (limited to 'source/blender/editors/transform')
-rw-r--r-- | source/blender/editors/transform/transform.c | 10 | ||||
-rw-r--r-- | source/blender/editors/transform/transform.h | 3 | ||||
-rw-r--r-- | source/blender/editors/transform/transform_numinput.c | 231 |
3 files changed, 134 insertions, 110 deletions
diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index 5ace57e36d8..143fc7632b4 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -470,6 +470,8 @@ static void view_editmove(unsigned short event) #define TFM_MODAL_CONS_OFF 15 #define TFM_MODAL_ADD_SNAP 16 #define TFM_MODAL_REMOVE_SNAP 17 +/* 18 and 19 used by numinput, defined in transform.h + * */ /* called in transform_ops.c, on each regeneration of keymaps */ wmKeyMap* transform_modal_keymap(wmKeyConfig *keyconf) @@ -492,6 +494,8 @@ wmKeyMap* transform_modal_keymap(wmKeyConfig *keyconf) {TFM_MODAL_CONS_OFF, "CONS_OFF", 0, "Remove Constraints", ""}, {TFM_MODAL_ADD_SNAP, "ADD_SNAP", 0, "Add Snap Point", ""}, {TFM_MODAL_REMOVE_SNAP, "REMOVE_SNAP", 0, "Remove Last Snap Point", ""}, + {TFM_MODAL_INCREMENT_UP, "INCREMENT_UP", 0, "Numinput Increment Up", ""}, + {TFM_MODAL_INCREMENT_DOWN, "INCREMENT_DOWN", 0, "Numinput Increment Down", ""}, {0, NULL, 0, NULL, NULL}}; wmKeyMap *keymap= WM_modalkeymap_get(keyconf, "Transform Modal Map"); @@ -519,6 +523,9 @@ wmKeyMap* transform_modal_keymap(wmKeyConfig *keyconf) WM_modalkeymap_add_item(keymap, AKEY, KM_PRESS, 0, 0, TFM_MODAL_ADD_SNAP); WM_modalkeymap_add_item(keymap, AKEY, KM_PRESS, KM_ALT, 0, TFM_MODAL_REMOVE_SNAP); + WM_modalkeymap_add_item(keymap, UPARROWKEY, KM_PRESS, 0, 0, TFM_MODAL_INCREMENT_UP); + WM_modalkeymap_add_item(keymap, DOWNARROWKEY, KM_PRESS, 0, 0, TFM_MODAL_INCREMENT_DOWN); + return keymap; } @@ -702,6 +709,9 @@ int transformEvent(TransInfo *t, wmEvent *event) handled = 0; break; } + + // Modal numinput events + t->redraw |= handleNumInput(&(t->num), event, t->snap[1]); } /* else do non-mapped events */ else if (event->val==KM_PRESS) { diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h index aae317fe5c1..231a01b86d7 100644 --- a/source/blender/editors/transform/transform.h +++ b/source/blender/editors/transform/transform.h @@ -679,6 +679,9 @@ short hasNumInput(NumInput *n); void applyNumInput(NumInput *n, float *vec); char handleNumInput(NumInput *n, struct wmEvent *event, float increment); +#define TFM_MODAL_INCREMENT_UP 18 +#define TFM_MODAL_INCREMENT_DOWN 19 + /*********************** NDofInput ********************************/ void initNDofInput(NDofInput *n); diff --git a/source/blender/editors/transform/transform_numinput.c b/source/blender/editors/transform/transform_numinput.c index cfcf43d69bc..9ea2e556bf7 100644 --- a/source/blender/editors/transform/transform_numinput.c +++ b/source/blender/editors/transform/transform_numinput.c @@ -164,127 +164,138 @@ char handleNumInput(NumInput *n, wmEvent *event, float increment) float Val = 0; short idx = n->idx, idx_max = n->idx_max; - switch (event->type) { - case DOWNARROWKEY: /* Increments down*/ - if (!n->ctrl[idx]) - n->ctrl[idx] = 1; + if (event->type == EVT_MODAL_MAP) { + switch (event->val) { + case TFM_MODAL_INCREMENT_UP: + if (!n->ctrl[idx]) + n->ctrl[idx] = 1; - n->val[idx] -= increment; - break; - case UPARROWKEY: /* Increments up*/ - if (!n->ctrl[idx]) - n->ctrl[idx] = 1; - - n->val[idx] += increment; - break; - case BACKSPACEKEY: - if (n->ctrl[idx] == 0) { - n->val[0] = - n->val[1] = - n->val[2] = 0.0f; - n->ctrl[0] = - n->ctrl[1] = - n->ctrl[2] = 0; - n->inv[0] = - n->inv[1] = - n->inv[2] = 0; - } - else { - n->val[idx] = 0.0f; - n->ctrl[idx] = 0; - n->inv[idx] = 0; - } - break; - case PERIODKEY: - case PADPERIOD: - if (n->flag & NUM_NO_FRACTION) + n->val[idx] += increment; break; + case TFM_MODAL_INCREMENT_DOWN: + if (!n->ctrl[idx]) + n->ctrl[idx] = 1; - switch (n->ctrl[idx]) - { - case 0: - case 1: - n->ctrl[idx] = 10; + n->val[idx] -= increment; break; - case -1: - n->ctrl[idx] = -10; } - break; - case PADMINUS: - if(event->alt) + } else { + switch (event->type) { + case UPARROWKEY: /* Increments up*/ + if (!n->ctrl[idx]) + n->ctrl[idx] = 1; + + n->val[idx] += increment; break; - case MINUSKEY: - if (n->flag & NUM_NO_NEGATIVE) + case BACKSPACEKEY: + if (n->ctrl[idx] == 0) { + n->val[0] = + n->val[1] = + n->val[2] = 0.0f; + n->ctrl[0] = + n->ctrl[1] = + n->ctrl[2] = 0; + n->inv[0] = + n->inv[1] = + n->inv[2] = 0; + } + else { + n->val[idx] = 0.0f; + n->ctrl[idx] = 0; + n->inv[idx] = 0; + } break; + case PERIODKEY: + case PADPERIOD: + if (n->flag & NUM_NO_FRACTION) + break; - if (n->ctrl[idx]) { - n->ctrl[idx] *= -1; - n->val[idx] *= -1; - } - else - n->ctrl[idx] = -1; - break; - case PADSLASHKEY: - case SLASHKEY: - n->inv[idx] = !n->inv[idx]; - break; - case TABKEY: - idx++; - if (idx > idx_max) - idx = 0; - n->idx = idx; - break; - case PAD9: - case NINEKEY: - Val += 1.0f; - case PAD8: - case EIGHTKEY: - Val += 1.0f; - case PAD7: - case SEVENKEY: - Val += 1.0f; - case PAD6: - case SIXKEY: - Val += 1.0f; - case PAD5: - case FIVEKEY: - Val += 1.0f; - case PAD4: - case FOURKEY: - Val += 1.0f; - case PAD3: - case THREEKEY: - Val += 1.0f; - case PAD2: - case TWOKEY: - Val += 1.0f; - case PAD1: - case ONEKEY: - Val += 1.0f; - case PAD0: - case ZEROKEY: - if (!n->ctrl[idx]) - n->ctrl[idx] = 1; + switch (n->ctrl[idx]) + { + case 0: + case 1: + n->ctrl[idx] = 10; + break; + case -1: + n->ctrl[idx] = -10; + } + break; + case PADMINUS: + if(event->alt) + break; + case MINUSKEY: + if (n->flag & NUM_NO_NEGATIVE) + break; - if (fabs(n->val[idx]) > 9999999.0f); - else if (n->ctrl[idx] == 1) { - n->val[idx] *= 10; - n->val[idx] += Val; - } - else if (n->ctrl[idx] == -1) { - n->val[idx] *= 10; - n->val[idx] -= Val; - } - else { - /* float resolution breaks when over six digits after comma */ - if( ABS(n->ctrl[idx]) < 10000000) { - n->val[idx] += Val / (float)n->ctrl[idx]; - n->ctrl[idx] *= 10; + if (n->ctrl[idx]) { + n->ctrl[idx] *= -1; + n->val[idx] *= -1; } + else + n->ctrl[idx] = -1; + break; + case PADSLASHKEY: + case SLASHKEY: + n->inv[idx] = !n->inv[idx]; + break; + case TABKEY: + idx++; + if (idx > idx_max) + idx = 0; + n->idx = idx; + break; + case PAD9: + case NINEKEY: + Val += 1.0f; + case PAD8: + case EIGHTKEY: + Val += 1.0f; + case PAD7: + case SEVENKEY: + Val += 1.0f; + case PAD6: + case SIXKEY: + Val += 1.0f; + case PAD5: + case FIVEKEY: + Val += 1.0f; + case PAD4: + case FOURKEY: + Val += 1.0f; + case PAD3: + case THREEKEY: + Val += 1.0f; + case PAD2: + case TWOKEY: + Val += 1.0f; + case PAD1: + case ONEKEY: + Val += 1.0f; + case PAD0: + case ZEROKEY: + if (!n->ctrl[idx]) + n->ctrl[idx] = 1; + + if (fabs(n->val[idx]) > 9999999.0f); + else if (n->ctrl[idx] == 1) { + n->val[idx] *= 10; + n->val[idx] += Val; + } + else if (n->ctrl[idx] == -1) { + n->val[idx] *= 10; + n->val[idx] -= Val; + } + else { + /* float resolution breaks when over six digits after comma */ + if( ABS(n->ctrl[idx]) < 10000000) { + n->val[idx] += Val / (float)n->ctrl[idx]; + n->ctrl[idx] *= 10; + } + } + break; + default: + return 0; } - break; - default: - return 0; } /* REDRAW SINCE NUMBERS HAVE CHANGED */ |