Revision: 18303
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=18303
Author:   jesterking
Date:     2009-01-04 02:08:01 +0100 (Sun, 04 Jan 2009)

Log Message:
-----------
2.5 / Nodes / Transformations
- 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.

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/editors/include/BIF_transform.h
    branches/blender2.5/blender/source/blender/editors/transform/transform.c
    branches/blender2.5/blender/source/blender/editors/transform/transform.h
    
branches/blender2.5/blender/source/blender/editors/transform/transform_conversions.c
    
branches/blender2.5/blender/source/blender/editors/transform/transform_generics.c
    branches/blender2.5/blender/source/blender/editors/transform/transform_ops.c

Modified: 
branches/blender2.5/blender/source/blender/editors/include/BIF_transform.h
===================================================================
--- branches/blender2.5/blender/source/blender/editors/include/BIF_transform.h  
2009-01-04 00:05:40 UTC (rev 18302)
+++ branches/blender2.5/blender/source/blender/editors/include/BIF_transform.h  
2009-01-04 01:08:01 UTC (rev 18303)
@@ -71,8 +71,7 @@
        TFM_BAKE_TIME,
        TFM_BEVEL,
        TFM_BWEIGHT,
-       TFM_ALIGN,
-       TFM_NODE_TRANSLATE
+       TFM_ALIGN
 } TfmModesInputFlags;
 
 /* TRANSFORM CONTEXTS */

Modified: 
branches/blender2.5/blender/source/blender/editors/transform/transform.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/transform/transform.c    
2009-01-04 00:05:40 UTC (rev 18302)
+++ branches/blender2.5/blender/source/blender/editors/transform/transform.c    
2009-01-04 01:08:01 UTC (rev 18303)
@@ -220,6 +220,17 @@
                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 @@
                        return "Key Time";
                case TFM_MIRROR:
                        return "Mirror";
-               case TFM_NODE_TRANSLATE:
-                       return "Node Translate";
        }
        return "Transform";
 }
@@ -1080,13 +1089,8 @@
        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 @@
                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 @@
        
        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 @@
        }
 #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;
-}

Modified: 
branches/blender2.5/blender/source/blender/editors/transform/transform.h
===================================================================
--- branches/blender2.5/blender/source/blender/editors/transform/transform.h    
2009-01-04 00:05:40 UTC (rev 18302)
+++ branches/blender2.5/blender/source/blender/editors/transform/transform.h    
2009-01-04 01:08:01 UTC (rev 18303)
@@ -433,9 +433,6 @@
 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 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]);

Modified: 
branches/blender2.5/blender/source/blender/editors/transform/transform_conversions.c
===================================================================
--- 
branches/blender2.5/blender/source/blender/editors/transform/transform_conversions.c
        2009-01-04 00:05:40 UTC (rev 18302)
+++ 
branches/blender2.5/blender/source/blender/editors/transform/transform_conversions.c
        2009-01-04 01:08:01 UTC (rev 18303)
@@ -2279,6 +2279,19 @@
                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 @@
 }
 
 /* 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
 }
 

Modified: 
branches/blender2.5/blender/source/blender/editors/transform/transform_generics.c
===================================================================
--- 
branches/blender2.5/blender/source/blender/editors/transform/transform_generics.c
   2009-01-04 00:05:40 UTC (rev 18302)
+++ 
branches/blender2.5/blender/source/blender/editors/transform/transform_generics.c
   2009-01-04 01:08:01 UTC (rev 18303)
@@ -575,7 +575,10 @@
                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 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 @@
        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++) {

Modified: 
branches/blender2.5/blender/source/blender/editors/transform/transform_ops.c
===================================================================
--- 
branches/blender2.5/blender/source/blender/editors/transform/transform_ops.c    
    2009-01-04 00:05:40 UTC (rev 18302)
+++ 
branches/blender2.5/blender/source/blender/editors/transform/transform_ops.c    
    2009-01-04 01:08:01 UTC (rev 18303)
@@ -201,9 +201,18 @@
                        
                        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;
        }


_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to