Bug fix #4627
authorTon Roosendaal <ton@blender.org>
Sat, 8 Jul 2006 11:56:42 +0000 (11:56 +0000)
committerTon Roosendaal <ton@blender.org>
Sat, 8 Jul 2006 11:56:42 +0000 (11:56 +0000)
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

index 28a45bf94caeeaae198903f8256b24c447b97a20..c59fc8d61044fc01bcd1623799ec28eb00db4024 100755 (executable)
  * ***** END GPL/BL DUAL LICENSE BLOCK *****
  */
 
-#include <stdio.h>             /* for sprintf          */
+#include <math.h>                      /* fabs */
+#include <stdio.h>                     /* 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;
 }