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-06-30 12:57:39 +0400
committerBastien Montagne <montagne29@wanadoo.fr>2014-06-30 12:57:39 +0400
commitcadf77d5ef97935885802d1841184d9a044d2249 (patch)
tree69c10f127a46b5358128ae48bd116e732f7e169c /source/blender/editors/util/numinput.c
parent61e1ea382b84c1c1d3cd4c03da37fa4c282ea1d4 (diff)
Fix T40862: numinput transform did not take into account scale_length.
Diffstat (limited to 'source/blender/editors/util/numinput.c')
-rw-r--r--source/blender/editors/util/numinput.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/source/blender/editors/util/numinput.c b/source/blender/editors/util/numinput.c
index 26b9d8b5d71..a618ab8419b 100644
--- a/source/blender/editors/util/numinput.c
+++ b/source/blender/editors/util/numinput.c
@@ -87,15 +87,18 @@ void initNumInput(NumInput *n)
}
/* str must be NUM_STR_REP_LEN * (idx_max + 1) length. */
-void outputNumInput(NumInput *n, char *str)
+void outputNumInput(NumInput *n, char *str, const float scale_length)
{
- short i, j;
+ short j;
const int ln = NUM_STR_REP_LEN;
int prec = 2; /* draw-only, and avoids too much issues with radian->degrees conversion. */
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;
+ 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 = ELEM3(n->unit_type[j], B_UNIT_LENGTH, B_UNIT_AREA, B_UNIT_VOLUME) ? scale_length : 1.0f;
if (n->val_flag[i] & NUM_EDITED) {
/* Get the best precision, allows us to draw '10.0001' as '10' instead! */
@@ -118,7 +121,7 @@ void outputNumInput(NumInput *n, char *str)
BLI_strncpy(val, "Invalid", sizeof(val));
}
else {
- bUnit_AsString(val, sizeof(val), (double)n->val[i], prec,
+ bUnit_AsString(val, sizeof(val), (double)(n->val[i] * fac), prec,
n->unit_sys, n->unit_type[i], true, false);
}
@@ -466,7 +469,9 @@ bool handleNumInput(bContext *C, NumInput *n, const wmEvent *event)
/* At this point, our value has changed, try to interpret it with python (if str is not empty!). */
if (n->str[0]) {
#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;
@@ -474,6 +479,10 @@ bool handleNumInput(bContext *C, NumInput *n, const wmEvent *event)
if (n->unit_use_radians && n->unit_type[idx] == B_UNIT_ROTATION)
default_unit = "r";
+ /* Use scale_length if needed! */
+ if (ELEM3(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,
@@ -481,7 +490,7 @@ bool handleNumInput(bContext *C, NumInput *n, const wmEvent *event)
/* 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;
+ n->val[idx] = (float)val * fac;
n->val_flag[idx] &= ~NUM_INVALID;
}
else {