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:
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);
}