Found some time do sanitize the big Transform call:
authorMartin Poirier <theeth@yahoo.com>
Tue, 10 May 2005 04:21:11 +0000 (04:21 +0000)
committerMartin Poirier <theeth@yahoo.com>
Tue, 10 May 2005 04:21:11 +0000 (04:21 +0000)
- Splited off the event treatment into a fonction of its own
- Splited off the initialisation phase into a function of its own (will have to do it for the manipulator function too)
Calling transform now works like this:
initTransform(mode, context)
- possible post init calls, constraints mostly
Transform()
- eventually, the postTransform function, so that Transform is just a simple big loop which could in the end just be tied in the blender event system instead.
- Added a state variable in TransInfo to replace the ret_val local variable. Possible values are: TRANS_RUNNING, TRANS_CANCEL, TRANS_CONFIRM
- Tied MMB and the hotkey select for constraint together, so selecting an axis with MMB and pressing the axis key after that goes to local mode on that axis. Much less confusing.

14 files changed:
source/blender/include/BIF_transform.h
source/blender/include/transform.h
source/blender/src/editarmature.c
source/blender/src/editcurve.c
source/blender/src/editmball.c
source/blender/src/editmesh_add.c
source/blender/src/editmesh_tools.c
source/blender/src/editobject.c
source/blender/src/editview.c
source/blender/src/header_view3d.c
source/blender/src/space.c
source/blender/src/toolbox.c
source/blender/src/transform.c
source/blender/src/transform_constraints.c

index aea415725c01db584c7d86dcb19e1a0cd8c02be1..e0b464d147cf417058bee094e04da7424cdfab13 100755 (executable)
 #define CTX_EDGE                       2
 #define CTX_NO_PET                     4
 #define CTX_NO_NOR_RECALC      8
-#define CTX_SETLOCALCONST      16
 
-
-void Transform(int mode, int context);
+void initTransform(int mode, int context);
+void Transform(void);
 void Mirror(short mode);
 
 struct TransInfo;
index 115e5a57e594c29f89410a8f740b5cdcd38b8253..74857c1e527b4a70deafea3b125f4ff66959630d 100755 (executable)
@@ -125,11 +125,12 @@ typedef struct TransData {
 
 typedef struct TransInfo {
     int         mode;           /* current mode                         */
+       short           state;                  /* current state (running, canceled,...)*/
     int         context;        /* current context                      */
     int       (*transform)(struct TransInfo *, short *);
                                 /* transform function pointer           */
     char        redraw;         /* redraw flag                          */
-    int                flag;          /* generic flags for special behaviors  */
+    int                flag;           /* generic flags for special behaviors  */
     int         total;          /* total number of transformed data     */
        float           propsize;               /* proportional circle radius           */
        char            proptext[20];   /* proportional falloff text                    */
@@ -166,6 +167,11 @@ typedef struct TransInfo {
 #define NUM_NO_FRACTION                16
 #define        NUM_AFFECT_ALL          32
 
+/* transinfo->state */
+#define TRANS_RUNNING  0
+#define TRANS_CONFIRM  1
+#define TRANS_CANCEL   2
+
 /* transinfo->flag */
 #define T_OBJECT               1
 #define T_EDIT                 2
@@ -186,6 +192,8 @@ typedef struct TransInfo {
 #define T_PROP_EDIT             2048
 #define T_PROP_CONNECTED 4096
 
+/* if MMB is pressed or not */
+#define        T_MMB_PRESSED   8192
 
 /* transinfo->con->mode */
 #define CON_APPLY              1
@@ -279,6 +287,7 @@ int getConstraintSpaceDimension(TransInfo *t);
 
 void setNearestAxis(TransInfo *t);
 
+char constraintModeToChar(TransInfo *t);
 
 /*********************** Generics ********************************/
 void recalcData(TransInfo *t);
index ec0c46801e9b909b1955507928791f045dbab367..74b8350b6a9d0ec3ad7061c6bd6ed34d81928f86 100644 (file)
@@ -1997,7 +1997,8 @@ void extrude_armature(void)
        /* Transform the endpoints */
        countall();
        BIF_TransformSetUndo("Extrude");
-       Transform(TFM_TRANSLATION, CTX_NO_PET);
+       initTransform(TFM_TRANSLATION, CTX_NO_PET);
+       Transform();
        allqueue(REDRAWBUTSEDIT, 0);
        allqueue(REDRAWBUTSOBJECT, 0);
        allqueue(REDRAWOOPS, 0);
@@ -2161,7 +2162,8 @@ void adduplicate_armature(void)
        }
 
        BIF_TransformSetUndo("Add Duplicate");
-       Transform(TFM_TRANSLATION, CTX_NO_PET);
+       initTransform(TFM_TRANSLATION, CTX_NO_PET);
+       Transform();
        allqueue(REDRAWBUTSEDIT, 0);
        allqueue(REDRAWBUTSOBJECT, 0);
        allqueue(REDRAWOOPS, 0);
index e4610015e25c327ab2e6ba52099996e0a36d4529..dd4af70c3f784a4fadfad3358460dbe72ea2dce1 100644 (file)
@@ -2795,7 +2795,8 @@ void addvert_Nurb(int mode)
 
        if(mode=='e') {
                BIF_TransformSetUndo("Extrude");
-               Transform(TFM_TRANSLATION, CTX_NO_PET);
+               initTransform(TFM_TRANSLATION, CTX_NO_PET);
+               Transform();
        }
        else while(get_mbut()&R_MOUSE) BIF_wait_for_statechange();
 
@@ -2833,7 +2834,8 @@ void extrude_nurb()
                                makeDispList(G.obedit);
                                countall();
                                BIF_TransformSetUndo("Extrude");
-                               Transform(TFM_TRANSLATION, CTX_NO_PET);
+                               initTransform(TFM_TRANSLATION, CTX_NO_PET);
+                               Transform();
                        }
                }
        }
@@ -3062,7 +3064,8 @@ void adduplicate_nurb()
 
        countall();
        BIF_TransformSetUndo("Add Duplicate");
-       Transform(TFM_TRANSLATION, CTX_NO_PET);
+       initTransform(TFM_TRANSLATION, CTX_NO_PET);
+       Transform();
 }
 
 void delNurb()
index 1ba62b0720624cc25ac94204a54b224768cc11e3..62f4a85358b0a009e6ec71d168932d90d7236b46 100644 (file)
@@ -313,7 +313,8 @@ void adduplicate_mball()
        }
        
        BIF_TransformSetUndo("Add Duplicate");
-       Transform(TFM_TRANSLATION, CTX_NO_PET);
+       initTransform(TFM_TRANSLATION, CTX_NO_PET);
+       Transform();
        allqueue(REDRAWBUTSEDIT, 0);
 }
 
index f57fe17836041ae0f2c996099c7230f268907085..3e9b3b58cf3431d833748eafac85968994dae9ff 100644 (file)
@@ -438,7 +438,8 @@ void adduplicate_mesh(void)
        waitcursor(0);
        countall(); 
        BIF_TransformSetUndo("Add Duplicate");
-       Transform(TFM_TRANSLATION, CTX_NO_PET);
+       initTransform(TFM_TRANSLATION, CTX_NO_PET);
+       Transform();
 }
 
 
index 753839698fa8badbaa181efceb843ff61cf89050..4d454930b73e5e9cfc7bc0eab94559720d1531ec 100644 (file)
@@ -582,15 +582,17 @@ void extrude_mesh(void)
                /* individual faces? */
                BIF_TransformSetUndo("Extrude");
                if(nr==2) {
-                       Transform(TFM_SHRINKFATTEN, CTX_NO_PET|CTX_NO_NOR_RECALC);
+                       initTransform(TFM_SHRINKFATTEN, CTX_NO_PET|CTX_NO_NOR_RECALC);
+                       Transform();
                }
                else {
+                       initTransform(TFM_TRANSLATION, CTX_NO_PET);
                        if(transmode=='n') {
                                Mat4MulVecfl(G.obedit->obmat, nor);
                                VecSubf(nor, nor, G.obedit->obmat[3]);
                                BIF_setSingleAxisConstraint(nor, NULL);
                        }
-                       Transform(TFM_TRANSLATION, CTX_NO_PET);
+                       Transform();
                }
        }
 
index 749dcc0ffae3ba9c12190b7167926bc5848b1884..71c42e10dd16f6c5cc2a8b10c9045fb0c4c59b60 100644 (file)
@@ -3265,8 +3265,10 @@ void std_rmouse_transform(void (*xf_func)(int, int))
        while(get_mbut() & mousebut) {
                getmouseco_areawin(mval);
                if(abs(mval[0]-xo)+abs(mval[1]-yo) > 10) {
-                       if(curarea->spacetype==SPACE_VIEW3D)
-                               Transform(TFM_TRANSLATION, CTX_NONE);
+                       if(curarea->spacetype==SPACE_VIEW3D) {
+                               initTransform(TFM_TRANSLATION, CTX_NONE);
+                               Transform();
+                       }
                        else
                                xf_func('g', 0);
 
@@ -4134,7 +4136,8 @@ void adduplicate(float *dtrans)
        countall();
        if(dtrans==0) {
                BIF_TransformSetUndo("Add Duplicate");
-               Transform(TFM_TRANSLATION, CTX_NONE);
+               initTransform(TFM_TRANSLATION, CTX_NONE);
+               Transform();
        }
        set_active_base(BASACT);
        
@@ -4480,9 +4483,18 @@ void texspace_edit(void)
        }
        
 
-       if(nr==1) Transform(TFM_TRANSLATION, CTX_TEXTURE);
-       else if(nr==2) Transform(TFM_RESIZE, CTX_TEXTURE);
-       else if(nr==3) Transform(TFM_ROTATION, CTX_TEXTURE);
+       if(nr==1) {
+               initTransform(TFM_TRANSLATION, CTX_TEXTURE);
+               Transform();
+       }
+       else if(nr==2) {
+               initTransform(TFM_RESIZE, CTX_TEXTURE);
+               Transform();
+       }
+       else if(nr==3) {
+               initTransform(TFM_ROTATION, CTX_TEXTURE);
+               Transform();
+       }
 }
 
 void first_base(void)
index 18e05ed13f8a708435636116f8515682a2d5de19..22d738fbafd325f6e270dbdea544fe85de53891a 100644 (file)
@@ -710,9 +710,18 @@ int gesture(void)
                                else if(curarea->spacetype==SPACE_IMAGE) transform_tface_uv(i, 0);
                                else if(curarea->spacetype==SPACE_OOPS) transform_oops('g', 0);
                                else {
-                                       if(i=='g') Transform(TFM_TRANSLATION, CTX_NONE);
-                                       else if(i=='r') Transform(TFM_ROTATION, CTX_NONE);
-                                       else Transform(TFM_RESIZE, CTX_NONE);
+                                       if(i=='g') {
+                                               initTransform(TFM_TRANSLATION, CTX_NONE);
+                                               Transform();
+                                       }
+                                       else if(i=='r') {
+                                               initTransform(TFM_ROTATION, CTX_NONE);
+                                               Transform();
+                                       }
+                                       else {
+                                               initTransform(TFM_RESIZE, CTX_NONE);
+                                               Transform();
+                                       }
                                }
                        }
                }
index 39a5f09eaffef3632e37acec8235639fdab8c145..72bdd51fb589f1cead5b05bb305f9ed39d02687d 100644 (file)
@@ -1234,28 +1234,34 @@ void do_view3d_transform_moveaxismenu(void *arg, int event)
        switch(event)
        {
            case 0: /* X Global */
+                       initTransform(TFM_TRANSLATION, CTX_NONE);
                        BIF_setSingleAxisConstraint(mat[0], " X");
-                       Transform(TFM_TRANSLATION, CTX_NONE);
+                       Transform();
                        break;
                case 1: /* Y Global */
-                       BIF_setSingleAxisConstraint(mat[0], " Y");
-                       Transform(TFM_TRANSLATION, CTX_NONE);
+                       initTransform(TFM_TRANSLATION, CTX_NONE);
+                       BIF_setSingleAxisConstraint(mat[1], " Y");
+                       Transform();
                        break;
                case 2: /* Z Global */
-                       BIF_setSingleAxisConstraint(mat[0], " Z");
-                       Transform(TFM_TRANSLATION, CTX_NONE);
+                       initTransform(TFM_TRANSLATION, CTX_NONE);
+                       BIF_setSingleAxisConstraint(mat[2], " Z");
+                       Transform();
                        break;
                case 3: /* X Local */
+                       initTransform(TFM_TRANSLATION, CTX_NONE);
                        BIF_setLocalAxisConstraint('X', " X");
-                       Transform(TFM_TRANSLATION, CTX_SETLOCALCONST);
+                       Transform();
                        break;
                case 4: /* Y Local */
+                       initTransform(TFM_TRANSLATION, CTX_NONE);
                        BIF_setLocalAxisConstraint('Y', " Y");
-                       Transform(TFM_TRANSLATION, CTX_SETLOCALCONST);
+                       Transform();
                        break;
                case 5: /* Z Local */
+                       initTransform(TFM_TRANSLATION, CTX_NONE);
                        BIF_setLocalAxisConstraint('Z', " Z");
-                       Transform(TFM_TRANSLATION, CTX_SETLOCALCONST);
+                       Transform();
                        break;
        }
        allqueue(REDRAWVIEW3D, 0);
@@ -1294,28 +1300,34 @@ void do_view3d_transform_rotateaxismenu(void *arg, int event)
        switch(event)
        {
            case 0: /* X Global */
+                       initTransform(TFM_ROTATION, CTX_NONE);
                        BIF_setSingleAxisConstraint(mat[0], " X");
-                       Transform(TFM_ROTATION, CTX_NONE);
+                       Transform();
                        break;
                case 1: /* Y Global */
+                       initTransform(TFM_ROTATION, CTX_NONE);
                        BIF_setSingleAxisConstraint(mat[1], " Y");
-                       Transform(TFM_ROTATION, CTX_NONE);
+                       Transform();
                        break;
                case 2: /* Z Global */
+                       initTransform(TFM_ROTATION, CTX_NONE);
                        BIF_setSingleAxisConstraint(mat[2], " Z");
-                       Transform(TFM_ROTATION, CTX_NONE);
-                       break;
+                       Transform();
+                       break;
                case 3: /* X Local */
+                       initTransform(TFM_ROTATION, CTX_NONE);
                        BIF_setLocalAxisConstraint('X', " X");
-                       Transform(TFM_ROTATION, CTX_SETLOCALCONST);
+                       Transform();
                        break;
                case 4: /* Y Local */
+                       initTransform(TFM_ROTATION, CTX_NONE);
                        BIF_setLocalAxisConstraint('Y', " Y");
-                       Transform(TFM_ROTATION, CTX_SETLOCALCONST);
+                       Transform();
                        break;
                case 5: /* Z Local */
+                       initTransform(TFM_ROTATION, CTX_NONE);
                        BIF_setLocalAxisConstraint('Z', " Z");
-                       Transform(TFM_ROTATION, CTX_SETLOCALCONST);
+                       Transform();
                        break;
        }
        allqueue(REDRAWVIEW3D, 0);
@@ -1354,28 +1366,34 @@ void do_view3d_transform_scaleaxismenu(void *arg, int event)
        switch(event)
        {
            case 0: /* X Global */
+                       initTransform(TFM_RESIZE, CTX_NONE);
                        BIF_setSingleAxisConstraint(mat[0], " X");
-                       Transform(TFM_RESIZE, CTX_NONE);
+                       Transform();
                        break;
                case 1: /* Y Global */
+                       initTransform(TFM_RESIZE, CTX_NONE);
                        BIF_setSingleAxisConstraint(mat[1], " Y");
-                       Transform(TFM_RESIZE, CTX_NONE);
+                       Transform();
                        break;
                case 2: /* Z Global */
+                       initTransform(TFM_RESIZE, CTX_NONE);
                        BIF_setSingleAxisConstraint(mat[2], " Z");
-                       Transform(TFM_RESIZE, CTX_NONE);
+                       Transform();
                        break;
                case 3: /* X Local */
+                       initTransform(TFM_RESIZE, CTX_NONE);
                        BIF_setLocalAxisConstraint('X', " X");
-                       Transform(TFM_RESIZE, CTX_SETLOCALCONST);
+                       Transform();
                        break;
                case 4: /* Y Local */
+                       initTransform(TFM_RESIZE, CTX_NONE);
                        BIF_setLocalAxisConstraint('X', " X");
-                       Transform(TFM_RESIZE, CTX_SETLOCALCONST);
+                       Transform();
                        break;
                case 5: /* Z Local */
+                       initTransform(TFM_RESIZE, CTX_NONE);
                        BIF_setLocalAxisConstraint('X', " X");
-                       Transform(TFM_RESIZE, CTX_SETLOCALCONST);
+                       Transform();
                        break;
        }
        allqueue(REDRAWVIEW3D, 0);
@@ -1409,13 +1427,16 @@ static void do_view3d_transformmenu(void *arg, int event)
 {
        switch(event) {
        case 1:
-               Transform(TFM_TRANSLATION, CTX_NONE);
+               initTransform(TFM_TRANSLATION, CTX_NONE);
+               Transform();
                break;
        case 2:
-               Transform(TFM_ROTATION, CTX_NONE);
+               initTransform(TFM_ROTATION, CTX_NONE);
+               Transform();
                break;
        case 3:
-               Transform(TFM_RESIZE, CTX_NONE);
+               initTransform(TFM_RESIZE, CTX_NONE);
+               Transform();
                break;
        }
        allqueue(REDRAWVIEW3D, 0);
@@ -2056,7 +2077,8 @@ void do_view3d_edit_mesh_edgesmenu(void *arg, int event)
                editmesh_mark_seam(1);
                break;
        case 9: /* Cease SubSurf */
-               Transform(TFM_CREASE, CTX_EDGE);
+               initTransform(TFM_CREASE, CTX_EDGE);
+               Transform();
                break;
        case 10: /* Rotate Edge */
                edge_rotate_selected(2);
@@ -2336,13 +2358,16 @@ static void do_view3d_edit_meshmenu(void *arg, int event)
                delete_context_selected();
                break;
        case 9: /* Shrink/Fatten Along Normals */
-               Transform(TFM_SHRINKFATTEN, CTX_NONE);
+               initTransform(TFM_SHRINKFATTEN, CTX_NONE);
+               Transform();
                break;
        case 10: /* Shear */
-               Transform(TFM_SHEAR, CTX_NONE);
+               initTransform(TFM_SHEAR, CTX_NONE);
+               Transform();
                break;
        case 11: /* Warp */
-               Transform(TFM_WARP, CTX_NONE);
+               initTransform(TFM_WARP, CTX_NONE);
+               Transform();
                break;
        case 12: /* proportional edit (toggle) */
                if(G.scene->proportional) G.scene->proportional= 1;
@@ -2433,7 +2458,8 @@ static void do_view3d_edit_curve_controlpointsmenu(void *arg, int event)
 {
        switch(event) {
        case 0: /* tilt */
-               Transform(TFM_TILT, CTX_NONE);
+               initTransform(TFM_TILT, CTX_NONE);
+               Transform();
                break;
        case 1: /* clear tilt */
                clear_tilt();
@@ -2592,10 +2618,12 @@ static void do_view3d_edit_curvemenu(void *arg, int event)
                else G.scene->proportional= 1;
                break;
        case 13: /* Shear */
-               Transform(TFM_SHEAR, CTX_NONE);
+               initTransform(TFM_SHEAR, CTX_NONE);
+               Transform();
                break;
        case 14: /* Warp */
-               Transform(TFM_WARP, CTX_NONE);
+               initTransform(TFM_WARP, CTX_NONE);
+               Transform();
                break;
        }
        allqueue(REDRAWVIEW3D, 0);
@@ -2713,10 +2741,12 @@ static void do_view3d_edit_metaballmenu(void *arg, int event)
                delete_context_selected();
                break;
        case 5: /* Shear */
-               Transform(TFM_SHEAR, CTX_NONE);
+               initTransform(TFM_SHEAR, CTX_NONE);
+               Transform();
                break;
        case 6: /* Warp */
-               Transform(TFM_WARP, CTX_NONE);
+               initTransform(TFM_WARP, CTX_NONE);
+               Transform();
                break;
        case 7: /* Transform Properties */
                add_blockhandler(curarea, VIEW3D_HANDLER_OBJECT, 0);
@@ -2920,10 +2950,12 @@ static void do_view3d_edit_latticemenu(void *arg, int event)
                common_insertkey();
                break;
        case 3: /* Shear */
-               Transform(TFM_SHEAR, CTX_NONE);
+               initTransform(TFM_SHEAR, CTX_NONE);
+               Transform();
                break;
        case 4: /* Warp */
-               Transform(TFM_WARP, CTX_NONE);
+               initTransform(TFM_WARP, CTX_NONE);
+               Transform();
                break;
        case 5: /* proportional edit (toggle) */
                if(G.scene->proportional) G.scene->proportional= 0;
@@ -2998,10 +3030,12 @@ static void do_view3d_edit_armaturemenu(void *arg, int event)
                delete_context_selected();
                break;
        case 6: /* Shear */
-               Transform(TFM_SHEAR, CTX_NONE);
+               initTransform(TFM_SHEAR, CTX_NONE);
+               Transform();
                break;
        case 7: /* Warp */
-               Transform(TFM_WARP, CTX_NONE);
+               initTransform(TFM_WARP, CTX_NONE);
+               Transform();
                break;
        }
        allqueue(REDRAWVIEW3D, 0);
index f613cb6a055839263d5e366b0dbea2b3fffcf154..bec4fd46264b239c8bb1c4b935d714d86184ed98 100644 (file)
@@ -1215,7 +1215,8 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                }
                                else if (G.qual==LR_SHIFTKEY) {
                                        if (G.obedit && G.obedit->type==OB_MESH) {
-                                               Transform(TFM_CREASE, CTX_EDGE);
+                                               initTransform(TFM_CREASE, CTX_EDGE);
+                                               Transform();
                                        }
                                }
                                break;
@@ -1257,7 +1258,8 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        doredraw= 1;
                                }
                                else if((G.qual==0)) {
-                                       Transform(TFM_TRANSLATION, CTX_NONE);
+                                       initTransform(TFM_TRANSLATION, CTX_NONE);
+                                       Transform();
                                }
                                break;
                        case HKEY:
@@ -1500,13 +1502,17 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                                separatemenu();
                                        else if ((G.qual==0) && ELEM(G.obedit->type, OB_CURVE, OB_SURF))
                                                separate_nurb();
-                                       else if (G.qual==LR_SHIFTKEY)
-                                               Transform(TFM_PUSHPULL, CTX_NONE);
+                                       else if (G.qual==LR_SHIFTKEY) {
+                                               initTransform(TFM_PUSHPULL, CTX_NONE);
+                                               Transform();
+                                       }
                                }
                                else if(G.qual==LR_CTRLKEY || G.qual==(LR_SHIFTKEY|LR_CTRLKEY))
                                        make_parent();
-                               else if(G.qual==LR_SHIFTKEY)
-                                       Transform(TFM_PUSHPULL, CTX_NONE);
+                               else if(G.qual==LR_SHIFTKEY) {
+                                       initTransform(TFM_PUSHPULL, CTX_NONE);
+                                       Transform();
+                               }
                                else if(G.qual==LR_ALTKEY)
                                        clear_parent();
                                else if((G.qual==0)) {
@@ -1537,11 +1543,13 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                                        loopoperations(LOOP_CUT);
                                        }
                                        else if((G.qual==0)) {
-                                               Transform(TFM_ROTATION, CTX_NONE);
+                                               initTransform(TFM_ROTATION, CTX_NONE);
+                                               Transform();
                                        }
                                }
                                else if((G.qual==0)) {
-                                       Transform(TFM_ROTATION, CTX_NONE);
+                                       initTransform(TFM_ROTATION, CTX_NONE);
+                                       Transform();
                                }
                                break;
                        case SKEY:
@@ -1550,19 +1558,27 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        doredraw= 1;
                                }
                                else if(G.obedit) {
-                                       if(G.qual==LR_ALTKEY)
-                                               Transform(TFM_SHRINKFATTEN, CTX_NONE);
-                                       else if(G.qual==LR_CTRLKEY)
-                                               Transform(TFM_SHEAR, CTX_NONE);
-                                       else if(G.qual==(LR_CTRLKEY|LR_ALTKEY))
-                                               Transform(TFM_SHEAR, CTX_NONE);
+                                       if(G.qual==LR_ALTKEY) {
+                                               initTransform(TFM_SHRINKFATTEN, CTX_NONE);
+                                               Transform();
+                                       }
+                                       else if(G.qual==LR_CTRLKEY) {
+                                               initTransform(TFM_SHEAR, CTX_NONE);
+                                               Transform();
+                                       }
+                                       else if(G.qual==(LR_CTRLKEY|LR_ALTKEY)) {
+                                               initTransform(TFM_SHEAR, CTX_NONE);
+                                               Transform();
+                                       }
                                        else if(G.qual==LR_SHIFTKEY)
                                                snapmenu();
                                        else if(G.qual==0) {
-                                               Transform(TFM_RESIZE, CTX_NONE);
+                                               initTransform(TFM_RESIZE, CTX_NONE);
+                                               Transform();
                                        }
                                        else if(G.qual==(LR_SHIFTKEY|LR_CTRLKEY)){
-                                               Transform(TFM_TOSPHERE, CTX_NONE);
+                                               initTransform(TFM_TOSPHERE, CTX_NONE);
+                                               Transform();
                                        }
                                        
                                }
@@ -1575,12 +1591,17 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        snapmenu();
                                }
                                else if((G.qual==0)) {
-                                       Transform(TFM_RESIZE, CTX_NONE);
+                                       initTransform(TFM_RESIZE, CTX_NONE);
+                                       Transform();
+                               }
+                               else if(G.qual==(LR_SHIFTKEY|LR_CTRLKEY)) {
+                                       initTransform(TFM_TOSPHERE, CTX_NONE);
+                                       Transform();
+                               }
+                               else if(G.qual==(LR_CTRLKEY|LR_ALTKEY)) {
+                                       initTransform(TFM_SHEAR, CTX_NONE);
+                                       Transform();
                                }
-                               else if(G.qual==(LR_SHIFTKEY|LR_CTRLKEY))
-                                       Transform(TFM_TOSPHERE, CTX_NONE);
-                               else if(G.qual==(LR_CTRLKEY|LR_ALTKEY))
-                                       Transform(TFM_SHEAR, CTX_NONE);
                                break;
                        case TKEY:
                                if(G.obedit){
@@ -1595,7 +1616,8 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                                        clear_tilt();
                                                }
                                                else if (G.qual==0) {
-                                                       Transform(TFM_TILT, CTX_NONE);
+                                                       initTransform(TFM_TILT, CTX_NONE);
+                                                       Transform();
                                                }
                                        }
                                }
@@ -1661,7 +1683,8 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                break;
                        case WKEY:
                                if((G.qual==LR_SHIFTKEY)) {
-                                       Transform(TFM_WARP, CTX_NONE);
+                                       initTransform(TFM_WARP, CTX_NONE);
+                                       Transform();
                                }
                                else if(G.qual==LR_ALTKEY) {
                                        /* if(G.obedit && G.obedit->type==OB_MESH) write_videoscape(); */
index e1a23e17bb51329b1657b2c44ae480d76612e3dd..16448c7483838409c4c7139bb1ffae6e7e87037f 100644 (file)
@@ -1991,13 +1991,16 @@ static void tb_do_transform(void *arg, int event)
        switch(event)
        {
                case 0: /* Grab/move */
-                       Transform(TFM_TRANSLATION, CTX_NONE);
+                       initTransform(TFM_TRANSLATION, CTX_NONE);
+                       Transform();
                        break;
                case 1: /* Rotate */
-                       Transform(TFM_ROTATION, CTX_NONE);
+                       initTransform(TFM_ROTATION, CTX_NONE);
+                       Transform();
                        break;
                case 2: /* Scale */
-                       Transform(TFM_RESIZE,CTX_NONE);
+                       initTransform(TFM_RESIZE,CTX_NONE);
+                       Transform();
                        break;
                case 3: /* transform properties */
                        add_blockhandler(curarea, VIEW3D_HANDLER_OBJECT, UI_PNL_UNSTOW);
@@ -2006,13 +2009,16 @@ static void tb_do_transform(void *arg, int event)
                        snapmenu();
                        break;
                case 5: /* Shrink/Fatten Along Normals */
-                       Transform(TFM_SHRINKFATTEN, CTX_NONE);
+                       initTransform(TFM_SHRINKFATTEN, CTX_NONE);
+                       Transform();
                        break;
                case 6: /* Shear */
-                       Transform(TFM_SHEAR, CTX_NONE);
+                       initTransform(TFM_SHEAR, CTX_NONE);
+                       Transform();
                        break;
                case 7: /* Warp */
-                       Transform(TFM_WARP, CTX_NONE);
+                       initTransform(TFM_WARP, CTX_NONE);
+                       Transform();
                        break;
                case 8: /* proportional edit (toggle) */
                        if(G.scene->proportional) G.scene->proportional= 0;
index 5288fc1110b27c421950a02dc6b35a8d7ba4dfdc..0219ae81a95fc1d20e634b26fd00e089ff75fb4c 100755 (executable)
@@ -124,9 +124,6 @@ extern void helpline(float *vec);
 TransInfo Trans = {TFM_INIT, 0};       // enforce init on first usage
 int    LastMode = TFM_TRANSLATION;
 
-#define TRANS_CANCEL   2
-#define TRANS_CONFIRM  1
-
 /* ************************** TRANSFORMATIONS **************************** */
 
 static void view_editmove(unsigned short event)
@@ -219,20 +216,224 @@ static char *transform_to_undostr(TransInfo *t)
 
 /* ************************************************* */
 
-void Transform(int mode, int context) 
-{
-       int ret_val = 0;
-       short pmval[2] = {0, 0}, mval[2], val;
+void transformEvent(unsigned short event, short val) {
        float mati[3][3];
-       unsigned short event;
-       /* constraint mode THIS IS A HACK will have to use con.mode eventually */
-       char cmode = '\0';
-       /* If MMB is pressed or not */
-       char mmb_press = 0;
+       char cmode = constraintModeToChar(&Trans);
+       Mat3One(mati);
+       
 
+       if (val) {
+               switch (event){
+               /* enforce redraw of transform when modifiers are used */
+               case LEFTCTRLKEY:
+               case RIGHTCTRLKEY:
+                       Trans.redraw = 1;
+                       break;
+               case LEFTSHIFTKEY:
+               case RIGHTSHIFTKEY:
+                       /* shift is modifier for higher resolution transform, works nice to store this mouse position */
+                       getmouseco_areawin(Trans.shiftmval);
+                       Trans.flag |= T_SHIFT_MOD;
+                       Trans.redraw = 1;
+                       break;
+                       
+               case MIDDLEMOUSE:
+                       if ((Trans.flag & T_NO_CONSTRAINT)==0) {
+                               /* exception for switching to dolly, or trackball, in camera view */
+                               if (Trans.flag & T_CAMERA) {
+                                       if (Trans.mode==TFM_TRANSLATION)
+                                               setLocalConstraint(&Trans, (CON_AXIS2), "along local Z");
+                                       else if (Trans.mode==TFM_ROTATION) {
+                                               restoreTransObjects(&Trans);
+                                               initTransModeFlags(&Trans, TFM_TRACKBALL);
+                                               initTrackball(&Trans);
+                                       }
+                               }
+                               else {
+                                       Trans.flag |= T_MMB_PRESSED;
+                                       if (Trans.con.mode & CON_APPLY) {
+                                               stopConstraint(&Trans);
+                                       }
+                                       else {
+                                               initSelectConstraint(&Trans, mati);
+                                               postSelectConstraint(&Trans);
+                                       }
+                               }
+                               Trans.redraw = 1;
+                       }
+                       break;
+               case ESCKEY:
+               case RIGHTMOUSE:
+                       Trans.state = TRANS_CANCEL;
+                       break;
+               case LEFTMOUSE:
+               case SPACEKEY:
+               case PADENTER:
+               case RETKEY:
+                       Trans.state = TRANS_CONFIRM;
+                       break;
+               case GKEY:
+                       restoreTransObjects(&Trans);
+                       initTransModeFlags(&Trans, TFM_TRANSLATION);
+                       initTranslation(&Trans);
+                       Trans.redraw = 1;
+                       break;
+               case SKEY:
+                       restoreTransObjects(&Trans);
+                       initTransModeFlags(&Trans, TFM_RESIZE);
+                       initResize(&Trans);
+                       Trans.redraw = 1;
+                       break;
+               case RKEY:
+                       if (Trans.mode == TFM_ROTATION) {
+                               restoreTransObjects(&Trans);
+                               initTransModeFlags(&Trans, TFM_TRACKBALL);
+                               initTrackball(&Trans);
+                       }
+                       else {
+                               restoreTransObjects(&Trans);
+                               initTransModeFlags(&Trans, TFM_ROTATION);
+                               initRotation(&Trans);
+                       }
+                       Trans.redraw = 1;
+                       break;
+               case CKEY:
+                       if (G.qual & LR_ALTKEY) {
+                               Trans.flag ^= T_PROP_CONNECTED;
+                               sort_trans_data_dist(&Trans);
+                               calculatePropRatio(&Trans);
+                               Trans.redraw= 1;
+                       }
+                       else {
+                               stopConstraint(&Trans);
+                               Trans.redraw = 1;
+                       }
+                       break;
+               case XKEY:
+                       if ((Trans.flag & T_NO_CONSTRAINT)==0) {
+                               if (cmode == 'X') {
+                                       if (Trans.con.mode & CON_LOCAL) {
+                                               stopConstraint(&Trans);
+                                       }
+                                       else {
+                                               if (G.qual == 0)
+                                                       setLocalConstraint(&Trans, (CON_AXIS0), "along local X");
+                                               else if (G.qual == LR_SHIFTKEY)
+                                                       setLocalConstraint(&Trans, (CON_AXIS1|CON_AXIS2), "locking local X");
+                                       }
+                               }
+                               else {
+                                       if (G.qual == 0)
+                                               setConstraint(&Trans, mati, (CON_AXIS0), "along global X");
+                                       else if (G.qual == LR_SHIFTKEY)
+                                               setConstraint(&Trans, mati, (CON_AXIS1|CON_AXIS2), "locking global X");
+                               }
+                               Trans.redraw = 1;
+                       }
+                       break;
+               case YKEY:
+                       if ((Trans.flag & T_NO_CONSTRAINT)==0) {
+                               if (cmode == 'Y') {
+                                       if (Trans.con.mode & CON_LOCAL) {
+                                               stopConstraint(&Trans);
+                                       }
+                                       else {
+                                               if (G.qual == 0)
+                                                       setLocalConstraint(&Trans, (CON_AXIS1), "along local Y");
+                                               else if (G.qual == LR_SHIFTKEY)
+                                                       setLocalConstraint(&Trans, (CON_AXIS0|CON_AXIS2), "locking local Y");
+                                       }
+                               }
+                               else {
+                                       if (G.qual == 0)
+                                               setConstraint(&Trans, mati, (CON_AXIS1), "along global Y");
+                                       else if (G.qual == LR_SHIFTKEY)
+                                               setConstraint(&Trans, mati, (CON_AXIS0|CON_AXIS2), "locking global Y");
+                               }
+                               Trans.redraw = 1;
+                       }
+                       break;
+               case ZKEY:
+                       if ((Trans.flag & T_NO_CONSTRAINT)==0) {
+                               if (cmode == 'Z') {
+                                       if (Trans.con.mode & CON_LOCAL) {
+                                               stopConstraint(&Trans);
+                                       }
+                                       else {
+                                               if (G.qual == 0)
+                                                       setLocalConstraint(&Trans, (CON_AXIS2), "along local Z");
+                                               else if (G.qual == LR_SHIFTKEY)
+                                                       setLocalConstraint(&Trans, (CON_AXIS0|CON_AXIS1), "locking local Z");
+                                       }
+                               }
+                               else {
+                                       if (G.qual == 0)
+                                               setConstraint(&Trans, mati, (CON_AXIS2), "along global Z");
+                                       else if (G.qual == LR_SHIFTKEY)
+                                               setConstraint(&Trans, mati, (CON_AXIS0|CON_AXIS1), "locking global Z");
+                               }
+                               Trans.redraw = 1;
+                       }
+                       break;
+               case OKEY:
+                       if (Trans.flag & T_PROP_EDIT && G.qual==LR_SHIFTKEY) {
+                               G.scene->prop_mode = (G.scene->prop_mode+1)%6;
+                               calculatePropRatio(&Trans);
+                               Trans.redraw= 1;
+                       }
+                       break;
+               case WHEELDOWNMOUSE:
+               case PADPLUSKEY:
+                       if(Trans.flag & T_PROP_EDIT) {
+                               Trans.propsize*= 1.1f;
+                               calculatePropRatio(&Trans);
+                       }
+                       else view_editmove(event);
+                       Trans.redraw= 1;
+                       break;
+               case WHEELUPMOUSE:
+               case PADMINUS:
+                       if(Trans.flag & T_PROP_EDIT) {
+                               Trans.propsize*= 0.90909090f;
+                               calculatePropRatio(&Trans);
+                       }
+                       else view_editmove(event);
+                       Trans.redraw= 1;
+                       break;
+               }
+               Trans.redraw |= handleNumInput(&(Trans.num), event);
+               arrows_move_cursor(event);
+       }
+       else {
+               switch (event){
+               /* no redraw on release modifier keys! this makes sure you can assign the 'grid' still 
+                  after releasing modifer key */
+               case MIDDLEMOUSE:
+                       if ((Trans.flag & T_NO_CONSTRAINT)==0) {
+                               Trans.flag &= ~T_MMB_PRESSED;
+                               postSelectConstraint(&Trans);
+                               Trans.redraw = 1;
+                       }
+                       break;
+               case LEFTMOUSE:
+               case RIGHTMOUSE:
+                       /* commented out, doesn't work for actions started with menu */
+                       // Trans.state = TRANS_CONFIRM;
+                       break;
+               case LEFTSHIFTKEY:
+               case RIGHTSHIFTKEY:
+                       /* shift is modifier for higher resolution transform */
+                       Trans.flag &= ~T_SHIFT_MOD;
+                       break;
+               }
+       }
+}
+
+void initTransform(int mode, int context) {
        /* added initialize, for external calls to set stuff in TransInfo, like undo string */
        if(Trans.mode==TFM_INIT) memset(&Trans, 0, sizeof(TransInfo));
-       Mat3One(mati);
+
+       Trans.state = TRANS_RUNNING;
 
        /* stupid PET initialisation code */
        /* START */
@@ -261,16 +462,6 @@ void Transform(int mode, int context)
                return;
        }
 
-       /* CHECKING FOR CTX_SETLOCALCONST CONTEXT FLAG */
-       /* EVIL, best would be to split off init, this way all the external constraint call could work like that:
-               initTransform(mode)
-               initconstraint(setup)
-               Transform()
-       */
-       if (Trans.context & CTX_SETLOCALCONST) {
-               setLocalConstraint(&Trans, Trans.con.mode, Trans.con.text);
-       }
-
        /* EVIL! posemode code can switch translation to rotate when 1 bone is selected. will be removed (ton) */
        /* EVIL2: we gave as argument also texture space context bit... was cleared */
        mode= Trans.mode;
@@ -315,6 +506,15 @@ void Transform(int mode, int context)
        }
 
        initConstraint(&Trans);
+}
+
+void Transform() 
+{
+       float mati[3][3];
+       short pmval[2] = {0, 0}, mval[2], val;
+       unsigned short event;
+
+       Mat3One(mati);
 
        // Emptying event queue
        while( qtest() ) {
@@ -323,12 +523,12 @@ void Transform(int mode, int context)
 
        Trans.redraw = 1;
 
-       while (ret_val == 0) {
+       while (Trans.state == TRANS_RUNNING) {
 
                getmouseco_areawin(mval);
                
                if (mval[0] != pmval[0] || mval[1] != pmval[1]) {
-                       if (mmb_press) {
+                       if (Trans.flag & T_MMB_PRESSED) {
                                initSelectConstraint(&Trans, mati);
                        }
                        Trans.redraw = 1;
@@ -349,228 +549,13 @@ void Transform(int mode, int context)
 
                while( qtest() ) {
                        event= extern_qread(&val);
-
-                       if (val) {
-                               switch (event){
-                               /* enforce redraw of transform when modifiers are used */
-                               case LEFTCTRLKEY:
-                               case RIGHTCTRLKEY:
-                                       Trans.redraw = 1;
-                                       break;
-                               case LEFTSHIFTKEY:
-                               case RIGHTSHIFTKEY:
-                                       /* shift is modifier for higher resolution transform, works nice to store this mouse position */
-                                       getmouseco_areawin(Trans.shiftmval);
-                                       Trans.flag |= T_SHIFT_MOD;
-                                       Trans.redraw = 1;
-                                       break;
-                                       
-                               case MIDDLEMOUSE:
-                                       if ((Trans.flag & T_NO_CONSTRAINT)==0) {
-                                               /* exception for switching to dolly, or trackball, in camera view */
-                                               if (Trans.flag & T_CAMERA) {
-                                                       if (Trans.mode==TFM_TRANSLATION)
-                                                               setLocalConstraint(&Trans, (CON_AXIS2), "along local Z");
-                                                       else if (Trans.mode==TFM_ROTATION) {
-                                                               restoreTransObjects(&Trans);
-                                                               initTransModeFlags(&Trans, TFM_TRACKBALL);
-                                                               initTrackball(&Trans);
-                                                       }
-                                               }
-                                               else {
-                                                       mmb_press = 1;
-                                                       if (Trans.con.mode & CON_APPLY) {
-                                                               stopConstraint(&Trans);
-                                                       }
-                                                       else {
-                                                               initSelectConstraint(&Trans, mati);
-                                                               postSelectConstraint(&Trans);
-                                                       }
-                                               }
-                                               Trans.redraw = 1;
-                                       }
-                                       break;
-                               case ESCKEY:
-                               case RIGHTMOUSE:
-                                       ret_val = TRANS_CANCEL;
-                                       break;
-                               case LEFTMOUSE:
-                               case SPACEKEY:
-                               case PADENTER:
-                               case RETKEY:
-                                       ret_val = TRANS_CONFIRM;
-                                       break;
-                               case GKEY:
-                                       restoreTransObjects(&Trans);
-                                       initTransModeFlags(&Trans, TFM_TRANSLATION);
-                                       initTranslation(&Trans);
-                                       Trans.redraw = 1;
-                                       break;
-                               case SKEY:
-                                       restoreTransObjects(&Trans);
-                                       initTransModeFlags(&Trans, TFM_RESIZE);
-                                       initResize(&Trans);
-                                       Trans.redraw = 1;
-                                       break;
-                               case RKEY:
-                                       if (Trans.mode == TFM_ROTATION) {
-                                               restoreTransObjects(&Trans);
-                                               initTransModeFlags(&Trans, TFM_TRACKBALL);
-                                               initTrackball(&Trans);
-                                       }
-                                       else {
-                                               restoreTransObjects(&Trans);
-                                               initTransModeFlags(&Trans, TFM_ROTATION);
-                                               initRotation(&Trans);
-                                       }
-                                       Trans.redraw = 1;
-                                       break;
-                               case CKEY:
-                                       if (G.qual & LR_ALTKEY) {
-                                               Trans.flag ^= T_PROP_CONNECTED;
-                                               sort_trans_data_dist(&Trans);
-                                               calculatePropRatio(&Trans);
-                                               Trans.redraw= 1;
-                                       }
-                                       else {
-                                               cmode = '\0';
-                                               stopConstraint(&Trans);
-                                               Trans.redraw = 1;
-                                       }
-                                       break;
-                               case XKEY:
-                                       if ((Trans.flag & T_NO_CONSTRAINT)==0) {
-                                               if (cmode == 'X') {
-                                                       stopConstraint(&Trans);
-                                                       cmode = '\0';
-                                               }
-                                               else if(cmode == 'x') {
-                                                       if (G.qual == 0)
-                                                               setLocalConstraint(&Trans, (CON_AXIS0), "along local X");
-                                                       else if (G.qual == LR_SHIFTKEY)
-                                                               setLocalConstraint(&Trans, (CON_AXIS1|CON_AXIS2), "locking local X");
-
-                                                       cmode = 'X';
-                                               }
-                                               else {
-                                                       if (G.qual == 0)
-                                                               setConstraint(&Trans, mati, (CON_AXIS0), "along global X");
-                                                       else if (G.qual == LR_SHIFTKEY)
-                                                               setConstraint(&Trans, mati, (CON_AXIS1|CON_AXIS2), "locking global X");
-
-                                                       cmode = 'x';
-                                               }
-                                               Trans.redraw = 1;
-                                       }
-                                       break;
-                               case YKEY:
-                                       if ((Trans.flag & T_NO_CONSTRAINT)==0) {
-                                               if (cmode == 'Y') {
-                                                       stopConstraint(&Trans);
-                                                       cmode = '\0';
-                                               }
-                                               else if(cmode == 'y') {
-                                                       if (G.qual == 0)
-                                                               setLocalConstraint(&Trans, (CON_AXIS1), "along local Y");
-                                                       else if (G.qual == LR_SHIFTKEY)
-                                                               setLocalConstraint(&Trans, (CON_AXIS0|CON_AXIS2), "locking local Y");
-
-                                                       cmode = 'Y';
-                                               }
-                                               else {
-                                                       if (G.qual == 0)
-                                                               setConstraint(&Trans, mati, (CON_AXIS1), "along global Y");
-                                                       else if (G.qual == LR_SHIFTKEY)
-                                                               setConstraint(&Trans, mati, (CON_AXIS0|CON_AXIS2), "locking global Y");
-
-                                                       cmode = 'y';
-                                               }
-                                               Trans.redraw = 1;
-                                       }
-                                       break;
-                               case ZKEY:
-                                       if ((Trans.flag & T_NO_CONSTRAINT)==0) {
-                                               if (cmode == 'Z') {
-                                                       stopConstraint(&Trans);
-                                                       cmode = '\0';
-                                               }
-                                               else if(cmode == 'z') {
-                                                       if (G.qual == 0)
-                                                               setLocalConstraint(&Trans, (CON_AXIS2), "along local Z");
-                                                       else if (G.qual == LR_SHIFTKEY)
-                                                               setLocalConstraint(&Trans, (CON_AXIS0|CON_AXIS1), "locking local Z");
-
-                                                       cmode = 'Z';
-                                               }
-                                               else {
-                                                       if (G.qual == 0)
-                                                               setConstraint(&Trans, mati, (CON_AXIS2), "along global Z");
-                                                       else if (G.qual == LR_SHIFTKEY)
-                                                               setConstraint(&Trans, mati, (CON_AXIS0|CON_AXIS1), "locking global Z");
-
-                                                       cmode = 'z';
-                                               }
-                                               Trans.redraw = 1;
-                                       }
-                                       break;
-                               case OKEY:
-                                       if (Trans.flag & T_PROP_EDIT && G.qual==LR_SHIFTKEY) {
-                                               G.scene->prop_mode = (G.scene->prop_mode+1)%6;
-                                               calculatePropRatio(&Trans);
-                                               Trans.redraw= 1;
-                                       }
-                                       break;
-                               case WHEELDOWNMOUSE:
-                               case PADPLUSKEY:
-                                       if(Trans.flag & T_PROP_EDIT) {
-                                               Trans.propsize*= 1.1f;
-                                               calculatePropRatio(&Trans);
-                                       }
-                                       else view_editmove(event);
-                                       Trans.redraw= 1;
-                                       break;
-                               case WHEELUPMOUSE:
-                               case PADMINUS:
-                                       if(Trans.flag & T_PROP_EDIT) {
-                                               Trans.propsize*= 0.90909090f;
-                                               calculatePropRatio(&Trans);
-                                       }
-                                       else view_editmove(event);
-                                       Trans.redraw= 1;
-                                       break;
-                               }
-                               Trans.redraw |= handleNumInput(&(Trans.num), event);
-                               arrows_move_cursor(event);
-                       }
-                       else {
-                               switch (event){
-                               /* no redraw on release modifier keys! this makes sure you can assign the 'grid' still 
-                                  after releasing modifer key */
-                               case MIDDLEMOUSE:
-                                       if ((Trans.flag & T_NO_CONSTRAINT)==0) {
-                                               mmb_press = 0;
-                                               postSelectConstraint(&Trans);
-                                               Trans.redraw = 1;
-                                       }
-                                       break;
-                               case LEFTMOUSE:
-                               case RIGHTMOUSE:
-                                       /* commented out, doesn't work for actions started with menu */
-                                       // ret_val = TRANS_CONFIRM;
-                                       break;
-                               case LEFTSHIFTKEY:
-                               case RIGHTSHIFTKEY:
-                                       /* shift is modifier for higher resolution transform */
-                                       Trans.flag &= ~T_SHIFT_MOD;
-                                       break;
-                               }
-                       }
+                       transformEvent(event, val);
                }
        }
        
        
        /* handle restoring objects and Undo */
-       if(ret_val == TRANS_CANCEL) {
+       if(Trans.state == TRANS_CANCEL) {
                restoreTransObjects(&Trans);
                if(Trans.undostr) BIF_undo_push(Trans.undostr);
        }
@@ -587,11 +572,11 @@ void Transform(int mode, int context)
        {
                char cmode='g';
                
-               if(mode==TFM_RESIZE) cmode= 's';
-               else if(mode==TFM_ROTATION) cmode= 'r';
+               if(Trans.mode==TFM_RESIZE) cmode= 's';
+               else if(Trans.mode==TFM_ROTATION) cmode= 'r';
                /* aftertrans does displists, ipos and action channels */
                /* 7 = keyflags, meaning do loc/rot/scale ipos. Not sure if I like the old method to detect what changed (ton) */
-               special_aftertrans_update(cmode, 0, (short)(ret_val == TRANS_CANCEL), 7);
+               special_aftertrans_update(cmode, 0, (short)(Trans.state == TRANS_CANCEL), 7);
                
                if(G.obedit==NULL && G.obpose==NULL)
                        clear_trans_object_base_flags();
@@ -605,13 +590,15 @@ void Transform(int mode, int context)
 
 void ManipulatorTransform(int mode) 
 {
-       int ret_val = 0, mouse_moved = 0;
+       int mouse_moved = 0;
        short pmval[2] = {0, 0}, mval[2], val;
        unsigned short event;
 
        /* added initialize, for external calls to set stuff in TransInfo, like undo string */
        if(Trans.mode==TFM_INIT) memset(&Trans, 0, sizeof(TransInfo));
-       
+
+       Trans.state = TRANS_RUNNING;
+
        /* stupid PET initialisation code */
        /* START */
        if (Trans.propsize == 0.0f) {
@@ -658,7 +645,7 @@ void ManipulatorTransform(int mode)
        Trans.flag |= T_USES_MANIPULATOR;
        Trans.redraw = 1;
 
-       while (ret_val == 0) {
+       while (Trans.state == TRANS_RUNNING) {
                
                getmouseco_areawin(mval);
                
@@ -705,7 +692,7 @@ void ManipulatorTransform(int mode)
                                
                        case ESCKEY:
                        case RIGHTMOUSE:
-                               ret_val = TRANS_CANCEL;
+                               Trans.state = TRANS_CANCEL;
                                break;
                        case LEFTMOUSE:
                                if(mouse_moved==0 && val==0) break;
@@ -713,7 +700,7 @@ void ManipulatorTransform(int mode)
                        case SPACEKEY:
                        case PADENTER:
                        case RETKEY:
-                               ret_val = TRANS_CONFIRM;
+                               Trans.state = TRANS_CONFIRM;
                                break;
                        }
                        if(val) {
@@ -739,7 +726,7 @@ void ManipulatorTransform(int mode)
                }
        }
        
-       if(ret_val == TRANS_CANCEL) {
+       if(Trans.state == TRANS_CANCEL) {
                restoreTransObjects(&Trans);
        }
        else {
@@ -757,7 +744,7 @@ void ManipulatorTransform(int mode)
                else if(mode==TFM_ROTATION) cmode= 'r';
                /* aftertrans does displists, ipos and action channels */
                /* 7 = keyflags, meaning do loc/rot/scale ipos. Not sure if I like the old method to detect what changed (ton) */
-               special_aftertrans_update(cmode, 0, (short)(ret_val == TRANS_CANCEL), 7);
+               special_aftertrans_update(cmode, 0, (short)(Trans.state == TRANS_CANCEL), 7);
                
                if(G.obedit==NULL && G.obpose==NULL)
                        clear_trans_object_base_flags();
index fbcff3e7ef8f832dbdc32acb39dc2c3ff9958c3d..9ffce8f3544c1c67bc5a6c6a8d79c67a638d5aa2 100755 (executable)
@@ -552,17 +552,15 @@ void setConstraint(TransInfo *t, float space[3][3], int mode, const char text[])
 void BIF_setLocalAxisConstraint(char axis, char *text) {
        TransInfo *t = BIF_GetTransInfo();
 
-       strncpy(t->con.text, text, 48);
-
        switch (axis) {
        case 'X':
-               t->con.mode = (CON_AXIS0|CON_APPLY);
+               setLocalConstraint(t, CON_AXIS0, text);
                break;
        case 'Y':
-               t->con.mode = (CON_AXIS1|CON_APPLY);
+               setLocalConstraint(t, CON_AXIS1, text);
                break;
        case 'Z':
-               t->con.mode = (CON_AXIS2|CON_APPLY);
+               setLocalConstraint(t, CON_AXIS2, text);
                break;
        }
 }
@@ -570,17 +568,15 @@ void BIF_setLocalAxisConstraint(char axis, char *text) {
 void BIF_setLocalLockConstraint(char axis, char *text) {
        TransInfo *t = BIF_GetTransInfo();
 
-       strncpy(t->con.text, text, 48);
-
        switch (axis) {
        case 'x':
-               t->con.mode = (CON_AXIS1|CON_AXIS2|CON_APPLY);
+               setLocalConstraint(t, (CON_AXIS1|CON_AXIS2), text);
                break;
        case 'y':
-               t->con.mode = (CON_AXIS0|CON_AXIS2|CON_APPLY);
+               setLocalConstraint(t, (CON_AXIS0|CON_AXIS2), text);
                break;
        case 'z':
-               t->con.mode = (CON_AXIS0|CON_AXIS1|CON_APPLY);
+               setLocalConstraint(t, (CON_AXIS0|CON_AXIS1), text);
                break;
        }
 }
@@ -589,11 +585,11 @@ void setLocalConstraint(TransInfo *t, int mode, const char text[]) {
        if (t->flag & T_EDIT) {
                float obmat[3][3];
                Mat3CpyMat4(obmat, G.obedit->obmat);
-               setConstraint(t, obmat, mode, text);
+               setConstraint(t, obmat, mode|CON_LOCAL, text);
        }
        else {
                if (t->total == 1) {
-                       setConstraint(t, t->data->axismtx, mode, text);
+                       setConstraint(t, t->data->axismtx, mode|CON_LOCAL, text);
                }
                else {
                        strncpy(t->con.text + 1, text, 48);
@@ -627,8 +623,6 @@ void BIF_setSingleAxisConstraint(float vec[3], char *text) {
        Crossf(space[2], vec, space[1]);
        Mat3Ortho(space);
 
-       Mat3Ortho(space);
-
        Mat3CpyMat3(t->con.mtx, space);
        t->con.mode = (CON_AXIS0|CON_APPLY);
        getConstraintMatrix(t);
@@ -796,6 +790,7 @@ void initSelectConstraint(TransInfo *t, float mtx[3][3])
        Mat3CpyMat3(t->con.mtx, mtx);
        t->con.mode |= CON_APPLY;
        t->con.mode |= CON_SELECT;
+       t->con.mode &= ~CON_LOCAL;
 
        setNearestAxis(t);
        t->con.drawExtra = NULL;
@@ -893,3 +888,22 @@ void setNearestAxis(TransInfo *t)
        }
        getConstraintMatrix(t);
 }
+
+char constraintModeToChar(TransInfo *t) {
+       if ((t->con.mode & CON_APPLY)==0) {
+               return '\0';
+       }
+       switch (t->con.mode & (CON_AXIS0|CON_AXIS1|CON_AXIS2)) {
+       case (CON_AXIS0):
+       case (CON_AXIS1|CON_AXIS2):
+               return 'X';
+       case (CON_AXIS1):
+       case (CON_AXIS0|CON_AXIS2):
+               return 'Y';
+       case (CON_AXIS2):
+       case (CON_AXIS0|CON_AXIS1):
+               return 'Z';
+       default:
+               return '\0';
+       }
+}