From 8a34cbe41ff8248aa9d65d0032f1ebcee87b1dff Mon Sep 17 00:00:00 2001 From: Ton Roosendaal Date: Sat, 8 Jul 2006 11:56:42 +0000 Subject: [PATCH] Bug fix #4627 The transform number input code allowed to keep typing forever. That's nice but the code uses floats to store values, so there's a limit of 7 digits resolution to take care of. I've added this limit now, it will stop when the 8th digit was typed, giving a range of 100 million, quite OK for Blender measures. There was also a short in use for values between 0 and 1, causing an error when you try to type like 0.99999. Here I've added a limit of 7 digits. --- source/blender/src/transform_numinput.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/source/blender/src/transform_numinput.c b/source/blender/src/transform_numinput.c index 28a45bf94ca..c59fc8d6104 100755 --- a/source/blender/src/transform_numinput.c +++ b/source/blender/src/transform_numinput.c @@ -30,11 +30,13 @@ * ***** END GPL/BL DUAL LICENSE BLOCK ***** */ -#include /* for sprintf */ +#include /* fabs */ +#include /* for sprintf */ -#include "BKE_global.h" /* for G */ +#include "BKE_global.h" /* for G */ +#include "BKE_utildefines.h" /* ABS */ -#include "mydevice.h" /* for KEY defines */ +#include "mydevice.h" /* for KEY defines */ #include "transform.h" @@ -219,7 +221,8 @@ char handleNumInput(NumInput *n, unsigned short event) if (!n->ctrl[idx]) n->ctrl[idx] = 1; - if (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; } @@ -228,13 +231,19 @@ char handleNumInput(NumInput *n, unsigned short event) n->val[idx] -= Val; } else { - n->val[idx] += Val / (float)n->ctrl[idx]; - n->ctrl[idx] *= 10; + /* 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; } + + printf("value %f cntrl %d\n", n->val[idx], n->ctrl[idx]); + /* REDRAW SINCE NUMBERS HAVE CHANGED */ return 1; }