Two in one:
[blender.git] / source / blender / src / transform_numinput.c
index c83955f46f777d09ebb549e435c7a859acf45e16..730d25545bdf78602c0a5d109cc8f48bc70b4285 100755 (executable)
  * ***** END GPL/BL DUAL LICENSE BLOCK *****
  */
 
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
+#include <math.h>                      /* fabs */
+#include <stdio.h>                     /* for sprintf          */
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "BKE_global.h"                /* for G                        */
+#include "BKE_utildefines.h"   /* ABS */
 
-#ifndef WIN32
-#include <unistd.h>
-#else
-#include <io.h>
-#include "BLI_winstuff.h"
-#endif
+#include "mydevice.h"          /* for KEY defines      */
 
-#include "MEM_guardedalloc.h"
-
-#include "blendef.h"
-
-#include "mydevice.h"
-
-#include "BLI_arithb.h"
-
-#include "transform_numinput.h"
 #include "transform.h"
 
 /* ************************** Functions *************************** */
@@ -67,7 +51,7 @@ void outputNumInput(NumInput *n, char *str)
 
        for (j=0; j<=n->idx_max; j++) {
                /* if AFFECTALL and no number typed and cursor not on number, use first number */
-               if (n->flags & AFFECTALL && n->idx != j && n->ctrl[j] == 0)
+               if (n->flag & NUM_AFFECT_ALL && n->idx != j && n->ctrl[j] == 0)
                        i = 0;
                else
                        i = j;
@@ -77,32 +61,36 @@ void outputNumInput(NumInput *n, char *str)
                else
                        cur = '|';
 
-               switch (n->ctrl[i]) {
-               case 0:
-                       sprintf(&str[j*20], "NONE%c", cur);
-                       break;
-               case 1:
-               case -1:
-                       sprintf(&str[j*20], "%.0f%c", n->val[i], cur);
-                       break;
-               case 10:
-               case -10:
-                       sprintf(&str[j*20], "%.f.%c", n->val[i], cur);
-                       break;
-               case 100:
-               case -100:
-                       sprintf(&str[j*20], "%.1f%c", n->val[i], cur);
-                       break;
-               case 1000:
-               case -1000:
-                       sprintf(&str[j*20], "%.2f%c", n->val[i], cur);
-               case 10000:
-               case -10000:
-                       sprintf(&str[j*20], "%.3f%c", n->val[i], cur);
-                       break;
-               default:
-                       sprintf(&str[j*20], "%.4f%c", n->val[i], cur);
-               }
+               if( n->val[i] > 1e10 || n->val[i] < -1e10 )
+                       sprintf(&str[j*20], "%.4e%c", n->val[i], cur);
+               else
+                       switch (n->ctrl[i]) {
+                       case 0:
+                               sprintf(&str[j*20], "NONE%c", cur);
+                               break;
+                       case 1:
+                       case -1:
+                               sprintf(&str[j*20], "%.0f%c", n->val[i], cur);
+                               break;
+                       case 10:
+                       case -10:
+                               sprintf(&str[j*20], "%.f.%c", n->val[i], cur);
+                               break;
+                       case 100:
+                       case -100:
+                               sprintf(&str[j*20], "%.1f%c", n->val[i], cur);
+                               break;
+                       case 1000:
+                       case -1000:
+                               sprintf(&str[j*20], "%.2f%c", n->val[i], cur);
+                               break;
+                       case 10000:
+                       case -10000:
+                               sprintf(&str[j*20], "%.3f%c", n->val[i], cur);
+                               break;
+                       default:
+                               sprintf(&str[j*20], "%.4e%c", n->val[i], cur);
+                       }
        }
 }
 
@@ -121,23 +109,26 @@ short hasNumInput(NumInput *n)
 void applyNumInput(NumInput *n, float *vec)
 {
        short i, j;
+       float val[3];
 
        if (hasNumInput(n)) {
+               convertDisplayNumToVec(n->val, val);
+
                for (j=0; j<=n->idx_max; j++) {
                        /* if AFFECTALL and no number typed and cursor not on number, use first number */
-                       if (n->flags & AFFECTALL && n->idx != j && n->ctrl[j] == 0)
+                       if (n->flag & NUM_AFFECT_ALL && n->idx != j && n->ctrl[j] == 0)
                                i = 0;
                        else
                                i = j;
 
-                       if (n->ctrl[i] == 0 && n->flags & NULLONE) {
+                       if (n->ctrl[i] == 0 && n->flag & NUM_NULL_ONE) {
                                vec[j] = 1.0f;
                        }
-                       else if (n->val[i] == 0.0f && n->flags & NOZERO) {
+                       else if (val[i] == 0.0f && n->flag & NUM_NO_ZERO) {
                                vec[j] = 0.0001f;
                        }
                        else {
-                               vec[j] = n->val[i];
+                               vec[j] = val[i];
                        }
                }
        }
@@ -165,7 +156,7 @@ char handleNumInput(NumInput *n, unsigned short event)
                break;
        case PERIODKEY:
        case PADPERIOD:
-               if (n->flags & NOFRACTION)
+               if (n->flag & NUM_NO_FRACTION)
                        break;
 
                switch (n->ctrl[idx])
@@ -178,8 +169,11 @@ char handleNumInput(NumInput *n, unsigned short event)
                        n->ctrl[idx] = -10;
                }
                break;
+       case PADMINUS:
+               if(G.qual & LR_ALTKEY)
+                       break;
        case MINUSKEY:
-               if (n->flags & NONEGATIVE)
+               if (n->flag & NUM_NO_NEGATIVE)
                        break;
 
                if (n->ctrl[idx]) {
@@ -227,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;
                }
@@ -236,13 +231,17 @@ 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;
        }
+       
        /* REDRAW SINCE NUMBERS HAVE CHANGED */
        return 1;
 }