2.5 / Nodes / Transformations
authorNathan Letwory <nathan@letworyinteractive.com>
Sun, 4 Jan 2009 01:08:01 +0000 (01:08 +0000)
committerNathan Letwory <nathan@letworyinteractive.com>
Sun, 4 Jan 2009 01:08:01 +0000 (01:08 +0000)
- after talking with Martin P (theeth), I have now shuffled code around
  so that there is no more exception code for nodes in the wrong places.
  This means node editor now also use entirely common translation.
  As proof of concept, there is now also resize and rotate support. It already
  works, but there need to be a bit more thought in how those
  actions are initialised for node editor. Probably some way to tell
  what to use as pivot point, etc.

source/blender/editors/include/BIF_transform.h
source/blender/editors/transform/transform.c
source/blender/editors/transform/transform.h
source/blender/editors/transform/transform_conversions.c
source/blender/editors/transform/transform_generics.c
source/blender/editors/transform/transform_ops.c

index 02e931f4198e74378f3962bda84aef808a9fec9c..fbcec8eaadba7d4d120b9d53ad32be735b28c3b7 100644 (file)
@@ -71,8 +71,7 @@ enum {
        TFM_BAKE_TIME,
        TFM_BEVEL,
        TFM_BWEIGHT,
-       TFM_ALIGN,
-       TFM_NODE_TRANSLATE
+       TFM_ALIGN
 } TfmModesInputFlags;
 
 /* TRANSFORM CONTEXTS */
index e513a4fcbbc1bce9b3f596746bfa6d0984e285b8..5d10a07231bf7799ee14fb8e4c9a8307eac14cbe 100644 (file)
@@ -220,6 +220,17 @@ void convertViewVec(TransInfo *t, float *vec, short dx, short dy)
                vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy) / (divy);
                vec[2]= 0.0f;
        }
+       else if(t->spacetype==SPACE_NODE) {
+               View2D *v2d = &t->ar->v2d;
+               float divx, divy;
+               
+               divx= v2d->mask.xmax-v2d->mask.xmin;
+               divy= v2d->mask.ymax-v2d->mask.ymin;
+               
+               vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
+               vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
+               vec[2]= 0.0f;
+       }
 }
 
 void projectIntView(TransInfo *t, float *vec, int *adr)
@@ -550,8 +561,6 @@ static char *transform_to_undostr(TransInfo *t)
                        return "Key Time";
                case TFM_MIRROR:
                        return "Mirror";
-               case TFM_NODE_TRANSLATE:
-                       return "Node Translate";
        }
        return "Transform";
 }
@@ -1080,13 +1089,8 @@ void initTransform(bContext *C, TransInfo *t, wmOperator *op, wmEvent *event)
        case TFM_ALIGN:
                initAlign(t);
                break;
-       case TFM_NODE_TRANSLATE:
-               initNodeTranslate(t);
-               break;
        }
-
-
-
+       
        RNA_float_get_array(op->ptr, "values", values);
        
        /* overwrite initial values if operator supplied a non-null vector */
@@ -1135,12 +1139,7 @@ int transformEnd(bContext *C, TransInfo *t)
                if(t->state == TRANS_CANCEL)
                {
                        exit_code = OPERATOR_CANCELLED;
-                       
-                       /* TRANSFORM_FIX_ME fix jesty's node stuff, shouldn't be exceptional at this level */   
-                       if(t->spacetype == SPACE_NODE)
-                               restoreTransNodes(t);
-                       else
-                               restoreTransObjects(t); // calls recalcData()
+                       restoreTransObjects(t); // calls recalcData()
                }
                else
                {
@@ -2953,7 +2952,7 @@ int Translation(TransInfo *t, short mval[2])
        
        applyTranslation(t, t->values);
 
-       /* evil hack - redo translation if cliiping needeed */
+       /* evil hack - redo translation if clipping needed */
        if (t->flag & T_CLIP_UV && clipUVTransform(t, t->values, 0))
                applyTranslation(t, t->values);
 
@@ -4584,54 +4583,3 @@ void NDofTransform()
        }
 #endif
 }
-
-/* *** Node translation *** */
-
-void initNodeTranslate(TransInfo *t) 
-{
-       t->mode = TFM_NODE_TRANSLATE;
-       t->transform = NodeTranslate;
-       
-       initMouseInputMode(t, &t->mouse, INPUT_NONE);
-
-       /* num-input has max of (n-1) */
-       t->idx_max = 0;
-       t->num.flag = 0;
-       t->num.idx_max = t->idx_max;
-       
-       /* initialise snap like for everything else */
-       t->snap[0] = 0.0f; 
-       t->snap[1] = t->snap[2] = 1.0f;
-}
-
-static void applyNodeTranslate(TransInfo *t) 
-{
-       TransData2D *td = t->data2d;
-       int i;
-
-       for (i = 0 ; i < t->total; i++, td++) {
-               td->loc2d[0]= td->loc[0]+t->values[0];
-               td->loc2d[1]= td->loc[1]+t->values[1];
-       }
-}
-
-int NodeTranslate(TransInfo *t, short mval[2]) 
-{
-       View2D *v2d = &t->ar->v2d;
-       float cval[2], sval[2];
-       
-       /* calculate translation amount from mouse movement - in 'node-grid space' */
-       UI_view2d_region_to_view(v2d, mval[0], mval[1], &cval[0], &cval[1]);
-       UI_view2d_region_to_view(v2d, t->imval[0], t->imval[1], &sval[0], &sval[1]);
-
-       t->values[0] = cval[0] - sval[0];
-       t->values[1] = cval[1] - sval[1];
-       
-       applyNodeTranslate(t);
-
-       recalcData(t);
-       
-       viewRedrawForce(t);
-
-       return 1;
-}
index 078109a0a1f9f0c2ebcd511de14766416c91f906..806afa8e624978598ab362191fb2c990d57f5cb9 100644 (file)
@@ -433,9 +433,6 @@ int Mirror(TransInfo *t, short mval[2]);
 void initAlign(TransInfo *t);
 int Align(TransInfo *t, short mval[2]);
 
-void initNodeTranslate(TransInfo *t);
-int NodeTranslate(TransInfo *t, short mval[2]);
-
 /*********************** transform_conversions.c ********** */
 struct ListBase;
 void flushTransGPactionData(TransInfo *t);
@@ -443,6 +440,7 @@ void flushTransIpoData(TransInfo *t);
 void flushTransUVs(TransInfo *t);
 void flushTransParticles(TransInfo *t);
 int clipUVTransform(TransInfo *t, float *vec, int resize);
+void flushTransNodes(TransInfo *t);
 
 /*********************** exported from transform_manipulator.c ********** */
 void draw_manipulator_ext(struct ScrArea *sa, int type, char axis, int col, float vec[3], float mat[][3]);
index 8d73c808745f5403ef5ea03382ed83c14c011664..6b9c635779f1c3a38157ca0d2fd59e72e18eee81 100644 (file)
@@ -2279,6 +2279,19 @@ static void createTransEditVerts(bContext *C, TransInfo *t)
                MEM_freeN(defmats);
 }
 
+/* *** NODE EDITOR *** */
+void flushTransNodes(TransInfo *t)
+{
+       int a;
+       TransData2D *td;
+       
+       /* flush to 2d vector from internally used 3d vector */
+       for(a=0, td= t->data2d; a<t->total; a++, td++) {
+               td->loc2d[0]= td->loc[0];
+               td->loc2d[1]= td->loc[1];
+       }
+}
+
 /* ********************* UV ****************** */
 
 static void UVsToTransData(TransData *td, TransData2D *td2d, float *uv, int selected)
@@ -4108,28 +4121,43 @@ static void createTransObject(bContext *C, TransInfo *t)
 }
 
 /* transcribe given node into TransData2D for Transforming */
-static void NodeToTransData(bContext *C, TransInfo *t, TransData2D *td, bNode *node) 
+static void NodeToTransData(TransData *td, TransData2D *td2d, bNode *node)
+// static void NodeToTransData(bContext *C, TransInfo *t, TransData2D *td, bNode *node) 
 {
-       /* Note: since locx and locy come after each other in bNode struct, this works */
-       td->loc2d = &node->locx;
-       
-       /* initial location */
-       td->loc[0]= node->locx;
-       td->loc[1]= node->locy;
+       td2d->loc[0] = node->locx; /* hold original location */
+       td2d->loc[1] = node->locy;
+       td2d->loc[2] = 0.0f;
+       td2d->loc2d = &node->locx; /* current location */
+
+       td->flag = 0;
+       td->loc = td2d->loc;
+       VECCOPY(td->center, td->loc);
+       VECCOPY(td->iloc, td->loc);
+
+       memset(td->axismtx, 0, sizeof(td->axismtx));
+       td->axismtx[2][2] = 1.0f;
+
+       td->ext= NULL; td->tdi= NULL; td->val= NULL;
+
+       td->flag |= TD_SELECTED;
+       td->dist= 0.0;
+
+       Mat3One(td->mtx);
+       Mat3One(td->smtx);
 }
 
 void createTransNodeData(bContext *C, TransInfo *t)
 {
-       TransData2D *td;
-       int i= 0;
+       TransData *td;
+       TransData2D *td2d;
        
        CTX_DATA_COUNT(C, selected_nodes, t->total)
        
-       td = t->data2d = MEM_callocN(t->total*sizeof(TransData2D), "TransNode");
+       td = t->data = MEM_callocN(t->total*sizeof(TransData), "TransNode TransData");
+       td2d = t->data2d = MEM_callocN(t->total*sizeof(TransData2D), "TransNode TransData2D");
        
        CTX_DATA_BEGIN(C, bNode *, selnode, selected_nodes)
-               NodeToTransData(C, t, td, selnode);
-               td++;
+               NodeToTransData(td++, td2d++, selnode);
        CTX_DATA_END
 }
 
index e817b069034db35d7b1bd67e08c3e4920ae5b437..d1993a79bf6a6cef46cfb7b223eacdf2d47f9ffe 100644 (file)
@@ -575,7 +575,10 @@ void recalcData(TransInfo *t)
                flushTransParticles(t);
        }
 #endif
-       if (t->obedit) {
+       if (t->spacetype==SPACE_NODE) {
+               flushTransNodes(t);
+       }
+       else if (t->obedit) {
                if (t->obedit->type == OB_MESH) {
                        if(t->spacetype==SPACE_IMAGE) {
                                flushTransUVs(t);
@@ -918,20 +921,6 @@ static void restoreElement(TransData *td) {
        }
 }
 
-static void restoreNode(TransData2D *td)
-{
-       td->loc2d[0]= td->loc[0];
-       td->loc2d[1]= td->loc[1];
-}
-
-void restoreTransNodes(TransInfo *t)
-{
-       TransData2D *td;
-       for (td = t->data2d; td < t->data2d + t->total; td++) {
-               restoreNode(td);
-       }
-}
-
 void restoreTransObjects(TransInfo *t)
 {
        TransData *td;
@@ -1185,8 +1174,6 @@ void calculatePropRatio(TransInfo *t)
        int i;
        float dist;
        short connected = t->flag & T_PROP_CONNECTED;
-
-       if (t->spacetype == SPACE_NODE) return;
        
        if (t->flag & T_PROP_EDIT) {
                for(i = 0 ; i < t->total; i++, td++) {
index 35d1f45bf33cdcc399cb2aedab527d23836386b1..e15fd3780ea90266dda442c4bce85851e91e03e9 100644 (file)
@@ -201,9 +201,18 @@ void transform_keymap_for_space(struct wmWindowManager *wm, struct ListBase *key
                        
                        km= WM_keymap_add_item(keymap, "TFM_OT_transform", TKEY, KM_PRESS, 0, 0);
                        RNA_int_set(km->ptr, "mode", TFM_TIME_SLIDE);
+                       break;
+               
                case SPACE_NODE:
                        km= WM_keymap_add_item(keymap, "TFM_OT_transform", GKEY, KM_PRESS, 0, 0);
-                       RNA_int_set(km->ptr, "mode", TFM_NODE_TRANSLATE);
+                       RNA_int_set(km->ptr, "mode", TFM_TRANSLATION);
+                       
+                       km = WM_keymap_add_item(keymap, "TFM_OT_transform", RKEY, KM_PRESS, 0, 0);
+                       RNA_int_set(km->ptr, "mode", TFM_ROTATION);
+                       
+                       km = WM_keymap_add_item(keymap, "TFM_OT_transform", SKEY, KM_PRESS, 0, 0);
+                       RNA_int_set(km->ptr, "mode", TFM_RESIZE);
+                       break;
                default:
                        break;
        }