Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2014-03-23 02:20:14 +0400
committerBastien Montagne <montagne29@wanadoo.fr>2014-03-23 12:29:04 +0400
commit3bad243cb80f5f588f8464f41cedf6897dbb84d7 (patch)
tree053e36e5fff38c7862e58bb2f5e55209b0b21d43 /source/blender/editors/util/numinput.c
parentc359de2c3a8d49dab6b11107d5d80052fb5f5c53 (diff)
Further tweaking to numinput - enhance 'Reset' behavior.
Ways how it was resetting its values (backspace) was far from satisfaying. Now, e.g. when scaling, it will reset at 1 (or whatever mouse-value it was before entering numinput), instead of some ugly 0.0 value. Implementation details: * Values passed to applyNumInput() are stored as default ones (val_org), if it is not EDITED. * applyNumInput() returns a boolean saying whether it actually set values or not. * When backspace hits its ultimate step (where it clears all EDITED flags and reset all default values), it sets a temp FAKE_EDITED flag that will be used to apply one last time values of numinput (so that default values actually get applied!). There are important things to note here for code using numinput: * Values passed to applyNumInput() should be valid and are stored as default ones (val_org), if it is not EDITED. * bool returned by applyNumInput should be used to decide whether to apply numinput-specific post-process to data. * *Once applyNumInput has been called*, hasNumInput returns a valid value to decide whether to use numinput as drawstr source or not. Those two steps have to be separated (so do not use a common call to hasNumInput() to do both in the same time!).
Diffstat (limited to 'source/blender/editors/util/numinput.c')
-rw-r--r--source/blender/editors/util/numinput.c51
1 files changed, 36 insertions, 15 deletions
diff --git a/source/blender/editors/util/numinput.c b/source/blender/editors/util/numinput.c
index 4c097ca7da6..850f1d1c5cc 100644
--- a/source/blender/editors/util/numinput.c
+++ b/source/blender/editors/util/numinput.c
@@ -52,6 +52,7 @@
enum {
/* (1 << 8) and below are reserved for public flags! */
NUM_EDIT_FULL = (1 << 9), /* Enable full editing, with units and math operators support. */
+ NUM_FAKE_EDITED = (1 << 10), /* Fake edited state (temp, avoids issue with backspace). */
};
/* NumInput.val_flag[] */
@@ -148,6 +149,10 @@ bool hasNumInput(const NumInput *n)
{
short i;
+ if (n->flag & NUM_FAKE_EDITED) {
+ return true;
+ }
+
for (i = 0; i <= n->idx_max; i++) {
if (n->val_flag[i] & NUM_EDITED) {
return true;
@@ -160,31 +165,45 @@ bool hasNumInput(const NumInput *n)
/**
* \warning \a vec must be set beforehand otherwise we risk uninitialized vars.
*/
-void applyNumInput(NumInput *n, float *vec)
+bool applyNumInput(NumInput *n, float *vec)
{
short i, j;
float val;
if (hasNumInput(n)) {
for (j = 0; j <= n->idx_max; j++) {
- /* if AFFECTALL and no number typed and cursor not on number, use first number */
- i = (n->flag & NUM_AFFECT_ALL && n->idx != j && !(n->val_flag[j] & NUM_EDITED)) ? 0 : j;
- val = (!(n->val_flag[i] & NUM_EDITED) && n->val_flag[i] & NUM_NULL_ONE) ? 1.0f : n->val[i];
-
- if (n->val_flag[i] & NUM_NO_NEGATIVE && val < 0.0f) {
- val = 0.0f;
- }
- if (n->val_flag[i] & NUM_NO_ZERO && val == 0.0f) {
- val = 0.0001f;
+ if (n->flag & NUM_FAKE_EDITED) {
+ val = n->val[j];
}
- if (n->val_flag[i] & NUM_NO_FRACTION && val != floorf(val)) {
- val = floorf(val + 0.5f);
+ else {
+ /* if AFFECTALL and no number typed and cursor not on number, use first number */
+ i = (n->flag & NUM_AFFECT_ALL && n->idx != j && !(n->val_flag[j] & NUM_EDITED)) ? 0 : j;
+ val = (!(n->val_flag[i] & NUM_EDITED) && n->val_flag[i] & NUM_NULL_ONE) ? 1.0f : n->val[i];
+
+ if (n->val_flag[i] & NUM_NO_NEGATIVE && val < 0.0f) {
+ val = 0.0f;
+ }
if (n->val_flag[i] & NUM_NO_ZERO && val == 0.0f) {
- val = 1.0f;
+ val = 0.0001f;
+ }
+ if (n->val_flag[i] & NUM_NO_FRACTION && val != floorf(val)) {
+ val = floorf(val + 0.5f);
+ if (n->val_flag[i] & NUM_NO_ZERO && val == 0.0f) {
+ val = 1.0f;
+ }
}
}
vec[j] = val;
}
+ n->flag &= ~NUM_FAKE_EDITED;
+ return true;
+ }
+ else {
+ /* Else, we set the 'org' values for numinput! */
+ for (j = 0; j <= n->idx_max; j++) {
+ n->val[j] = n->val_org[j] = vec[j];
+ }
+ return false;
}
}
@@ -257,6 +276,7 @@ bool handleNumInput(bContext *C, NumInput *n, const wmEvent *event)
n->val_flag[0] &= ~NUM_EDITED;
n->val_flag[1] &= ~NUM_EDITED;
n->val_flag[2] &= ~NUM_EDITED;
+ n->flag |= NUM_FAKE_EDITED;
updated = true;
break;
}
@@ -286,6 +306,9 @@ bool handleNumInput(bContext *C, NumInput *n, const wmEvent *event)
memmove(&n->str[cur], &n->str[t_cur], strlen(&n->str[t_cur]) + 1); /* +1 for trailing '\0'. */
updated = true;
}
+ if (!n->str[0]) {
+ n->val[idx] = n->val_org[idx];
+ }
}
else {
return false;
@@ -318,12 +341,10 @@ bool handleNumInput(bContext *C, NumInput *n, const wmEvent *event)
}
return false;
case TABKEY:
- n->val_org[idx] = n->val[idx];
n->val_flag[idx] &= ~(NUM_NEGATE | NUM_INVERSE);
idx = (idx + idx_max + (event->ctrl ? 0 : 2)) % (idx_max + 1);
n->idx = idx;
- n->val[idx] = n->val_org[idx];
if (n->val_flag[idx] & NUM_EDITED) {
value_to_editstr(n, idx);
}