diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2014-08-26 14:04:24 +0400 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2014-08-26 14:31:08 +0400 |
commit | 0e3fa0b7618fa86e97c5f46ae7208c082fd26eb7 (patch) | |
tree | 447fcae65fe6bf4086a79e03a82abb7a4138897b /source/blender/editors/util | |
parent | 600248783b50ddef9b809b0d4c7abd9a9b20fda3 (diff) |
Fix T41590: When scene scale is not 1.0, and units are "None," Blender assumes translations are in meters.
Turned out there were several issues in handling of scale parameter by numinput.
Fixed that by factorizing more some code in common with 'usual' numbuttons eval code
(new `bUnit_getScaleUnit()` helper will return valid scaled value, depending on
given system and type).
Now, numinput behaves as expected - using default unit amended by scale in case no unit is given
(i.e. entering '20' with a scale of 0.01 will give you 20cm, and '20cm' as well!).
Diffstat (limited to 'source/blender/editors/util')
-rw-r--r-- | source/blender/editors/util/numinput.c | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/source/blender/editors/util/numinput.c b/source/blender/editors/util/numinput.c index aade6d7b7e8..4e8f6df66e1 100644 --- a/source/blender/editors/util/numinput.c +++ b/source/blender/editors/util/numinput.c @@ -87,7 +87,7 @@ void initNumInput(NumInput *n) } /* str must be NUM_STR_REP_LEN * (idx_max + 1) length. */ -void outputNumInput(NumInput *n, char *str, const float scale_length) +void outputNumInput(NumInput *n, char *str, UnitSettings *unit_settings) { short j; const int ln = NUM_STR_REP_LEN; @@ -98,7 +98,7 @@ void outputNumInput(NumInput *n, char *str, const float scale_length) const short i = (n->flag & NUM_AFFECT_ALL && n->idx != j && !(n->val_flag[j] & NUM_EDITED)) ? 0 : j; /* Use scale_length if needed! */ - const float fac = ELEM(n->unit_type[j], B_UNIT_LENGTH, B_UNIT_AREA, B_UNIT_VOLUME) ? scale_length : 1.0f; + const float fac = (float)bUnit_getScaleUnit(unit_settings, n->unit_type[j], 1.0); if (n->val_flag[i] & NUM_EDITED) { /* Get the best precision, allows us to draw '10.0001' as '10' instead! */ @@ -478,26 +478,24 @@ bool handleNumInput(bContext *C, NumInput *n, const wmEvent *event) #ifdef WITH_PYTHON Scene *sce = CTX_data_scene(C); double val; - float fac = 1.0f; char str_unit_convert[NUM_STR_REP_LEN * 6]; /* Should be more than enough! */ const char *default_unit = NULL; + /* Use scale_length if needed! */ + const float fac = (float)bUnit_getScaleUnit(&sce->unit, n->unit_type[idx], 1.0); + /* Make radian default unit when needed. */ if (n->unit_use_radians && n->unit_type[idx] == B_UNIT_ROTATION) default_unit = "r"; - /* Use scale_length if needed! */ - if (ELEM(n->unit_type[idx], B_UNIT_LENGTH, B_UNIT_AREA, B_UNIT_VOLUME)) - fac /= sce->unit.scale_length; - BLI_strncpy(str_unit_convert, n->str, sizeof(str_unit_convert)); - bUnit_ReplaceString(str_unit_convert, sizeof(str_unit_convert), default_unit, 1.0, + bUnit_ReplaceString(str_unit_convert, sizeof(str_unit_convert), default_unit, fac, n->unit_sys, n->unit_type[idx]); /* Note: with angles, we always get values as radians here... */ if (BPY_button_exec(C, str_unit_convert, &val, false) != -1) { - n->val[idx] = (float)val * fac; + n->val[idx] = (float)val; n->val_flag[idx] &= ~NUM_INVALID; } else { |