code cleanup: minor transform refactor
authorCampbell Barton <ideasman42@gmail.com>
Wed, 23 Oct 2013 06:48:36 +0000 (06:48 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 23 Oct 2013 06:48:36 +0000 (06:48 +0000)
redraw flag were mixing up types - int/char/bool, add enum type to use instead.

source/blender/editors/include/ED_numinput.h
source/blender/editors/transform/transform.c
source/blender/editors/transform/transform.h
source/blender/editors/transform/transform_constraints.c
source/blender/editors/transform/transform_generics.c
source/blender/editors/transform/transform_input.c
source/blender/editors/transform/transform_snap.c
source/blender/editors/util/numinput.c

index e7d80d96f89793a46fd443f9e3813c9d276095db..f46332c9a82bc32f9c15df4feb888e03ece90226 100644 (file)
@@ -27,7 +27,6 @@
 #ifndef __ED_NUMINPUT_H__
 #define __ED_NUMINPUT_H__
 
-
 /*
  *  The ctrl value has different meaning:
  *      0           : No value has been typed
@@ -59,11 +58,11 @@ typedef struct NumInput {
 void initNumInput(NumInput *n);
 #define NUM_STR_REP_LEN 20 /* str must be NUM_STR_LEN * (idx_max + 1) length. */
 void outputNumInput(NumInput *n, char *str);
-short hasNumInput(NumInput *n);
+bool hasNumInput(const NumInput *n);
 void applyNumInput(NumInput *n, float *vec);
-char handleNumInput(NumInput *n, const struct wmEvent *event);
+bool handleNumInput(NumInput *n, const struct wmEvent *event);
 
 #define NUM_MODAL_INCREMENT_UP   18
 #define NUM_MODAL_INCREMENT_DOWN 19
 
-#endif
+#endif  /* __ED_NUMINPUT_H__ */
index a0db93d53b8fe52d2065472f2a291f3f093905a4..c0fb959d6b517e0b46113038a7f68de41bed1699 100644 (file)
@@ -111,11 +111,11 @@ static void postInputRotation(TransInfo *t, float values[3]);
 
 /* Transform Callbacks */
 static void initWarp(TransInfo *t);
-static int handleEventWarp(TransInfo *t, const struct wmEvent *event);
+static eRedrawFlag handleEventWarp(TransInfo *t, const struct wmEvent *event);
 static void Warp(TransInfo *t, const int mval[2]);
 
 static void initShear(TransInfo *t);
-static int handleEventShear(TransInfo *t, const struct wmEvent *event);
+static eRedrawFlag handleEventShear(TransInfo *t, const struct wmEvent *event);
 static void applyShear(TransInfo *t, const int mval[2]);
 
 static void initResize(TransInfo *t);
@@ -167,11 +167,11 @@ static void initBoneRoll(TransInfo *t);
 static void applyBoneRoll(TransInfo *t, const int mval[2]);
 
 static void initEdgeSlide(TransInfo *t);
-static int handleEventEdgeSlide(TransInfo *t, const struct wmEvent *event);
+static eRedrawFlag handleEventEdgeSlide(TransInfo *t, const struct wmEvent *event);
 static void applyEdgeSlide(TransInfo *t, const int mval[2]);
 
 static void initVertSlide(TransInfo *t);
-static int handleEventVertSlide(TransInfo *t, const struct wmEvent *event);
+static eRedrawFlag handleEventVertSlide(TransInfo *t, const struct wmEvent *event);
 static void applyVertSlide(TransInfo *t, const int mval[2]);
 
 static void initTimeTranslate(TransInfo *t);
@@ -1220,8 +1220,10 @@ int transformEvent(TransInfo *t, const wmEvent *event)
                                break;
                }
 
-               // Modal numinput events
-               t->redraw |= handleNumInput(&(t->num), event);
+               /* Modal numinput events */
+               if (handleNumInput(&(t->num), event)) {
+                       t->redraw |= TREDRAW_HARD;
+               }
        }
        /* else do non-mapped events */
        else if (event->val == KM_PRESS) {
@@ -1325,7 +1327,7 @@ int transformEvent(TransInfo *t, const wmEvent *event)
                                        t->flag ^= T_PROP_CONNECTED;
                                        sort_trans_data_dist(t);
                                        calculatePropRatio(t);
-                                       t->redraw = 1;
+                                       t->redraw = TREDRAW_HARD;
                                }
                                else {
                                        stopConstraint(t);
@@ -1351,7 +1353,7 @@ int transformEvent(TransInfo *t, const wmEvent *event)
                                                t->prop_size = min_ff(t->prop_size, ((View3D *)t->view)->far);
                                        calculatePropRatio(t);
                                }
-                               t->redraw = 1;
+                               t->redraw = TREDRAW_HARD;
                                break;
                        case PAGEUPKEY:
                        case WHEELDOWNMOUSE:
@@ -1361,14 +1363,14 @@ int transformEvent(TransInfo *t, const wmEvent *event)
                                else {
                                        view_editmove(event->type);
                                }
-                               t->redraw = 1;
+                               t->redraw = TREDRAW_HARD;
                                break;
                        case PADMINUS:
                                if (event->alt && t->flag & T_PROP_EDIT) {
                                        t->prop_size *= 0.90909090f;
                                        calculatePropRatio(t);
                                }
-                               t->redraw = 1;
+                               t->redraw = TREDRAW_HARD;
                                break;
                        case PAGEDOWNKEY:
                        case WHEELUPMOUSE:
@@ -1378,7 +1380,7 @@ int transformEvent(TransInfo *t, const wmEvent *event)
                                else {
                                        view_editmove(event->type);
                                }
-                               t->redraw = 1;
+                               t->redraw = TREDRAW_HARD;
                                break;
                        case LEFTALTKEY:
                        case RIGHTALTKEY:
@@ -1393,10 +1395,12 @@ int transformEvent(TransInfo *t, const wmEvent *event)
                                break;
                }
 
-               // Numerical input events
-               t->redraw |= handleNumInput(&(t->num), event);
+               /* Numerical input events */
+               if (handleNumInput(&(t->num), event)) {
+                       t->redraw |= TREDRAW_HARD;
+               }
 
-               // Snapping key events
+               /* Snapping key events */
                t->redraw |= handleSnapping(t, event);
 
        }
@@ -2735,9 +2739,9 @@ static void initWarp(TransInfo *t)
        t->customData = data;
 }
 
-static int handleEventWarp(TransInfo *UNUSED(t), const wmEvent *event)
+static eRedrawFlag handleEventWarp(TransInfo *UNUSED(t), const wmEvent *event)
 {
-       int status = TREDRAW_NOTHING;
+       eRedrawFlag status = TREDRAW_NOTHING;
        
        if (event->type == MIDDLEMOUSE && event->val == KM_PRESS) {
                status = TREDRAW_HARD;
@@ -2898,9 +2902,9 @@ static void initShear(TransInfo *t)
        t->flag |= T_NO_CONSTRAINT;
 }
 
-static int handleEventShear(TransInfo *t, const wmEvent *event)
+static eRedrawFlag handleEventShear(TransInfo *t, const wmEvent *event)
 {
-       int status = TREDRAW_NOTHING;
+       eRedrawFlag status = TREDRAW_NOTHING;
        
        if (event->type == MIDDLEMOUSE && event->val == KM_PRESS) {
                // Use customData pointer to signal Shear direction
@@ -5867,7 +5871,7 @@ static void initEdgeSlide(TransInfo *t)
        t->flag |= T_NO_CONSTRAINT | T_NO_PROJECT;
 }
 
-static int handleEventEdgeSlide(struct TransInfo *t, const struct wmEvent *event)
+static eRedrawFlag handleEventEdgeSlide(struct TransInfo *t, const struct wmEvent *event)
 {
        if (t->mode == TFM_EDGE_SLIDE) {
                EdgeSlideData *sld = t->customData;
@@ -5877,7 +5881,7 @@ static int handleEventEdgeSlide(struct TransInfo *t, const struct wmEvent *event
                                case EKEY:
                                        if (event->val == KM_PRESS) {
                                                sld->is_proportional = !sld->is_proportional;
-                                               return 1;
+                                               return TREDRAW_HARD;
                                        }
                                        break;
                                case FKEY:
@@ -5886,7 +5890,7 @@ static int handleEventEdgeSlide(struct TransInfo *t, const struct wmEvent *event
                                                if (sld->is_proportional == FALSE) {
                                                        sld->flipped_vtx = !sld->flipped_vtx;
                                                }
-                                               return 1;
+                                               return TREDRAW_HARD;
                                        }
                                        break;
                                }
@@ -5911,7 +5915,7 @@ static int handleEventEdgeSlide(struct TransInfo *t, const struct wmEvent *event
                        }
                }
        }
-       return 0;
+       return TREDRAW_NOTHING;
 }
 
 static void drawEdgeSlide(const struct bContext *C, TransInfo *t)
@@ -6338,7 +6342,7 @@ void freeVertSlideVerts(TransInfo *t)
        recalcData(t);
 }
 
-void initVertSlide(TransInfo *t)
+static void initVertSlide(TransInfo *t)
 {
        VertSlideData *sld;
 
@@ -6373,7 +6377,7 @@ void initVertSlide(TransInfo *t)
        t->flag |= T_NO_CONSTRAINT | T_NO_PROJECT;
 }
 
-int handleEventVertSlide(struct TransInfo *t, const struct wmEvent *event)
+static eRedrawFlag handleEventVertSlide(struct TransInfo *t, const struct wmEvent *event)
 {
        if (t->mode == TFM_VERT_SLIDE) {
                VertSlideData *sld = t->customData;
@@ -6386,7 +6390,7 @@ int handleEventVertSlide(struct TransInfo *t, const struct wmEvent *event)
                                                if (sld->flipped_vtx) {
                                                        calcVertSlideCustomPoints(t);
                                                }
-                                               return 1;
+                                               return TREDRAW_HARD;
                                        }
                                        break;
                                case FKEY:
@@ -6394,7 +6398,7 @@ int handleEventVertSlide(struct TransInfo *t, const struct wmEvent *event)
                                        if (event->val == KM_PRESS) {
                                                sld->flipped_vtx = !sld->flipped_vtx;
                                                calcVertSlideCustomPoints(t);
-                                               return 1;
+                                               return TREDRAW_HARD;
                                        }
                                        break;
                                }
@@ -6404,7 +6408,7 @@ int handleEventVertSlide(struct TransInfo *t, const struct wmEvent *event)
                                        if (event->val == KM_PRESS) {
                                                t->flag ^= T_ALT_TRANSFORM;
                                                calcVertSlideCustomPoints(t);
-                                               return 1;
+                                               return TREDRAW_HARD;
                                        }
                                        break;
                                }
@@ -6440,7 +6444,7 @@ int handleEventVertSlide(struct TransInfo *t, const struct wmEvent *event)
                        }
                }
        }
-       return 0;
+       return TREDRAW_NOTHING;
 }
 
 static void drawVertSlide(const struct bContext *C, TransInfo *t)
@@ -6557,7 +6561,7 @@ static int doVertSlide(TransInfo *t, float perc)
        return 1;
 }
 
-void applyVertSlide(TransInfo *t, const int UNUSED(mval[2]))
+static void applyVertSlide(TransInfo *t, const int UNUSED(mval[2]))
 {
        char str[MAX_INFO_LEN];
        size_t ofs = 0;
index 7233d22756d7766c059218bb559e7453430e6d4e..376847937f3c05f4dce0151aba6ca138b3dace96 100644 (file)
@@ -62,6 +62,13 @@ struct wmTimer;
 struct ARegion;
 struct ReportList;
 
+/* transinfo->redraw */
+typedef enum {
+       TREDRAW_NOTHING   = 0,
+       TREDRAW_HARD      = 1,
+       TREDRAW_SOFT      = 2,
+} eRedrawFlag;
+
 typedef struct TransSnapPoint {
        struct TransSnapPoint *next, *prev;
        float co[3];
@@ -286,7 +293,7 @@ typedef struct TransInfo {
        float       fac;            /* factor for distance based transform  */
        void      (*transform)(struct TransInfo *, const int[2]);
                                                                /* transform function pointer           */
-       int       (*handleEvent)(struct TransInfo *, const struct wmEvent *);
+       eRedrawFlag (*handleEvent)(struct TransInfo *, const struct wmEvent *);
                                                                /* event handler function pointer  RETURN 1 if redraw is needed */
        int         total;          /* total number of transformed data     */
        TransData  *data;           /* transformed data (array)             */
@@ -296,7 +303,7 @@ typedef struct TransInfo {
        TransSnap       tsnap;
        NumInput    num;            /* numerical input                      */
        MouseInput      mouse;                  /* mouse input                          */
-       char        redraw;         /* redraw flag                          */
+       eRedrawFlag redraw;         /* redraw flag                          */
        float           prop_size;              /* proportional circle radius           */
        char            proptext[20];   /* proportional falloff text                    */
        float       center[3];      /* center of transformation             */
@@ -372,12 +379,6 @@ typedef struct TransInfo {
 #define TRANS_CONFIRM  2
 #define TRANS_CANCEL   3
 
-/* transinfo->redraw */
-#define TREDRAW_NOTHING        0
-#define TREDRAW_HARD           1
-#define TREDRAW_SOFT           2
-
-
 /* transinfo->flag */
 #define T_OBJECT               (1 << 0)
 #define T_EDIT                 (1 << 1)
@@ -575,14 +576,14 @@ void initSnapping(struct TransInfo *t, struct wmOperator *op);
 void applyProject(TransInfo *t);
 void applySnapping(TransInfo *t, float *vec);
 void resetSnapping(TransInfo *t);
-bool handleSnapping(TransInfo *t, const struct wmEvent *event);
+eRedrawFlag handleSnapping(TransInfo *t, const struct wmEvent *event);
 void drawSnapping(const struct bContext *C, TransInfo *t);
 bool usingSnappingNormal(TransInfo *t);
 bool validSnappingNormal(TransInfo *t);
 
 void getSnapPoint(TransInfo *t, float vec[3]);
 void addSnapPoint(TransInfo *t);
-bool updateSelectedSnapPoint(TransInfo *t);
+eRedrawFlag updateSelectedSnapPoint(TransInfo *t);
 void removeSnapPoint(TransInfo *t);
 
 /********************** Mouse Input ******************************/
@@ -605,7 +606,7 @@ typedef enum {
 
 void initMouseInput(TransInfo *t, MouseInput *mi, const float center[2], const int mval[2]);
 void initMouseInputMode(TransInfo *t, MouseInput *mi, MouseInputMode mode);
-int handleMouseInput(struct TransInfo *t, struct MouseInput *mi, const struct wmEvent *event);
+eRedrawFlag handleMouseInput(struct TransInfo *t, struct MouseInput *mi, const struct wmEvent *event);
 void applyMouseInput(struct TransInfo *t, struct MouseInput *mi, const int mval[2], float output[3]);
 
 void setCustomPoints(TransInfo *t, MouseInput *mi, const int start[2], const int end[2]);
index 4580bbefc96066aa84f7c30ea31ef4b3e971dc22..4497723185fe613ee9e510226485ac8f7b537152 100644 (file)
@@ -569,7 +569,7 @@ void setConstraint(TransInfo *t, float space[3][3], int mode, const char text[])
        t->con.applyVec = applyAxisConstraintVec;
        t->con.applySize = applyAxisConstraintSize;
        t->con.applyRot = applyAxisConstraintRot;
-       t->redraw = 1;
+       t->redraw = TREDRAW_HARD;
 }
 
 /* applies individual td->axismtx constraints */
@@ -590,7 +590,7 @@ void setAxisMatrixConstraint(TransInfo *t, int mode, const char text[])
                t->con.applyVec = applyObjectConstraintVec;
                t->con.applySize = applyObjectConstraintSize;
                t->con.applyRot = applyObjectConstraintRot;
-               t->redraw = 1;
+               t->redraw = TREDRAW_HARD;
        }
 }
 
@@ -911,7 +911,7 @@ void postSelectConstraint(TransInfo *t)
        setNearestAxis(t);
 
        startConstraint(t);
-       t->redraw = 1;
+       t->redraw = TREDRAW_HARD;
 }
 
 static void setNearestAxis2d(TransInfo *t)
index 94f481d8dfc09be15c5595ab37d75c2e47e88d2c..a8248cc73e104d96c117829213a355b5035c033c 100644 (file)
@@ -1066,7 +1066,7 @@ int initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *even
        
        t->flag = 0;
        
-       t->redraw = 1; /* redraw first time */
+       t->redraw = TREDRAW_HARD;  /* redraw first time */
        
        if (event) {
                copy_v2_v2_int(t->imval, event->mval);
index ee993129303b7c8921d0eac24be1f71dd57f9204..39c7b4b5c1c941e7c9b775fb22413b479ab12bca 100644 (file)
@@ -407,9 +407,9 @@ void applyMouseInput(TransInfo *t, MouseInput *mi, const int mval[2], float outp
        }
 }
 
-int handleMouseInput(TransInfo *t, MouseInput *mi, const wmEvent *event)
+eRedrawFlag handleMouseInput(TransInfo *t, MouseInput *mi, const wmEvent *event)
 {
-       int redraw = TREDRAW_NOTHING;
+       eRedrawFlag redraw = TREDRAW_NOTHING;
 
        switch (event->type) {
                case LEFTSHIFTKEY:
index 04bccac2a15f7f69aab939dca6ab9950451b06ef..dfb0217dfa84d68252691bfae5c8fa510fb9625f 100644 (file)
@@ -267,16 +267,16 @@ void drawSnapping(const struct bContext *C, TransInfo *t)
        }
 }
 
-bool handleSnapping(TransInfo *t, const wmEvent *event)
+eRedrawFlag handleSnapping(TransInfo *t, const wmEvent *event)
 {
-       bool status = false;
+       eRedrawFlag status = TREDRAW_NOTHING;
 
 #if 0 // XXX need a proper selector for all snap mode
        if (BIF_snappingSupported(t->obedit) && event->type == TABKEY && event->shift) {
                /* toggle snap and reinit */
                t->settings->snap_flag ^= SCE_SNAP;
                initSnapping(t, NULL);
-               status = 1;
+               status = TREDRAW_HARD;
        }
 #endif
        if (event->type == MOUSEMOVE) {
@@ -606,9 +606,10 @@ void addSnapPoint(TransInfo *t)
        }
 }
 
-bool updateSelectedSnapPoint(TransInfo *t)
+eRedrawFlag updateSelectedSnapPoint(TransInfo *t)
 {
-       bool status = false;
+       eRedrawFlag status = TREDRAW_NOTHING;
+
        if (t->tsnap.status & MULTI_POINTS) {
                TransSnapPoint *p, *closest_p = NULL;
                float closest_dist = TRANSFORM_SNAP_MAX_PX;
@@ -631,7 +632,10 @@ bool updateSelectedSnapPoint(TransInfo *t)
                }
 
                if (closest_p) {
-                       status = (t->tsnap.selectedPoint != closest_p);
+                       if (t->tsnap.selectedPoint != closest_p) {
+                               status = TREDRAW_HARD;
+                       }
+
                        t->tsnap.selectedPoint = closest_p;
                }
        }
index 3e5f879aa3c6cb382bd1fed19f037b54fe97917f..0feaf9361722ae9ebfb5358cf88428ac169dc81f 100644 (file)
@@ -114,16 +114,16 @@ void outputNumInput(NumInput *n, char *str)
        }
 }
 
-short hasNumInput(NumInput *n)
+bool hasNumInput(const NumInput *n)
 {
        short i;
 
        for (i = 0; i <= n->idx_max; i++) {
                if (n->ctrl[i])
-                       return 1;
+                       return true;
        }
 
-       return 0;
+       return false;
 }
 
 /**
@@ -159,7 +159,7 @@ void applyNumInput(NumInput *n, float *vec)
        }
 }
 
-char handleNumInput(NumInput *n, const wmEvent *event)
+bool handleNumInput(NumInput *n, const wmEvent *event)
 {
        float Val = 0;
        short idx = n->idx, idx_max = n->idx_max;