2.5
authorMartin Poirier <theeth@yahoo.com>
Sat, 10 Jan 2009 18:33:16 +0000 (18:33 +0000)
committerMartin Poirier <theeth@yahoo.com>
Sat, 10 Jan 2009 18:33:16 +0000 (18:33 +0000)
Transform draw callback: constraints, snapping, prop circle

source/blender/editors/include/BIF_transform.h
source/blender/editors/include/ED_view3d.h
source/blender/editors/space_view3d/view3d_intern.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_snap.c

index 284e2ab60a8993436277680bc1ee36370866da88..652df0948217c3f03faec313e67eab20b476356c 100644 (file)
@@ -116,11 +116,6 @@ void BIF_selectTransformOrientationFromIndex(int index);
 char * BIF_menustringTransformOrientation(char *title); /* the returned value was allocated and needs to be freed after use */
 int BIF_countTransformOrientation();
 
-/* Drawing callbacks */
-void BIF_drawConstraint(void);
-void BIF_drawPropCircle(void);
-void BIF_drawSnap(void);
-
 void BIF_getPropCenter(float *center);
 
 void BIF_TransformSetUndo(char *str);
index 4f4afd2abb4f1526f1ab88d1c3caea5994982aaa..9de1095ef25a4006c635bfe918fac50d6e826581 100644 (file)
@@ -83,6 +83,8 @@ void lattice_foreachScreenVert(struct ViewContext *vc, void (*func)(void *userDa
 int view3d_test_clipping(struct View3D *v3d, float *vec);
 void view3d_align_axis_to_vector(struct Scene *scene, struct View3D *v3d, int axisidx, float vec[3]);
 
+void drawcircball(int mode, float *cent, float rad, float tmat[][4]);
+
 /* backbuffer select and draw support */
 struct ImBuf *view3d_read_backbuf(struct ViewContext *vc, short xmin, short ymin, short xmax, short ymax);
 unsigned int view3d_sample_backbuf_rect(struct ViewContext *vc, short mval[2], int size, unsigned int min, unsigned int max, int *dist, short strict, unsigned int (*indextest)(unsigned int index));
index baf5a849bd436bb4ad21b09a885fb10687768bbc..f304418ba8a3565228407a5ceef3f57c94918932 100644 (file)
@@ -86,7 +86,6 @@ void VIEW3D_OT_drawtype(struct wmOperatorType *ot);
 /* drawobject.c */
 void draw_object(Scene *scene, struct ARegion *ar, View3D *v3d, Base *base, int flag);
 int draw_glsl_material(Scene *scene, Object *ob, View3D *v3d, int dt);
-void drawcircball(int mode, float *cent, float rad, float tmat[][4]);
 void draw_object_instance(Scene *scene, View3D *v3d, Object *ob, int dt, int outline);
 void draw_object_backbufsel(Scene *scene, View3D *v3d, Object *ob);
 void drawaxes(float size, int flag, char drawtype);
index c0ef862a9c39fa64bbf3375dcbd8526d7c34dfe4..164d101ebb6521af376f6d8891c42e558fcfc64f 100644 (file)
@@ -99,6 +99,8 @@
 #include "ED_view3d.h"
 #include "ED_screen.h"
 #include "ED_util.h"
+#include "ED_space_api.h"
+
 #include "UI_view2d.h"
 #include "WM_types.h"
 #include "WM_api.h"
 
 #include "transform.h"
 
-/******************************** Helper functions ************************************/
-
-/* GLOBAL Wrapper Fonctions */
-
-//void BIF_drawSnap()
-//{
-//     drawSnapping(&Trans);
-//}
-
 /* ************************** Dashed help line **************************** */
 
 
@@ -959,6 +952,15 @@ int calculateTransformCenter(bContext *C, wmEvent *event, int centerMode, float
        return success;
 }
 
+void drawTransform(const struct bContext *C, struct ARegion *ar, void *arg)
+{
+       TransInfo *t = arg;
+       
+       drawConstraint(t);
+       drawPropCircle(t);
+       drawSnapping(t);
+}
+
 void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
 {
        RNA_int_set(op->ptr, "mode", t->mode);
@@ -988,6 +990,8 @@ void initTransform(bContext *C, TransInfo *t, wmOperator *op, wmEvent *event)
                //calc_manipulator_stats(curarea);
                Mat3CpyMat4(t->spacemtx, v3d->twmat);
                Mat3Ortho(t->spacemtx);
+               
+               t->draw_handle = ED_region_draw_cb_activate(t->ar->type, drawTransform, t, REGION_DRAW_POST);
        }
        else
                Mat3One(t->spacemtx);
index 75edfb78aba578a292427a06990b2edc5f600ab1..fb1a82d232c93b7ad8eedb056930ede5e7f62bd4 100644 (file)
@@ -241,6 +241,7 @@ typedef struct TransInfo {
        struct Scene    *scene;
     short       mval[2];        /* current mouse position               */
     struct Object   *obedit;
+    void               *draw_handle;
 } TransInfo;
 
 
@@ -427,6 +428,9 @@ int Mirror(TransInfo *t, short mval[2]);
 void initAlign(TransInfo *t);
 int Align(TransInfo *t, short mval[2]);
 
+
+void drawPropCircle(TransInfo *t);
+
 /*********************** transform_conversions.c ********** */
 struct ListBase;
 void flushTransGPactionData(TransInfo *t);
@@ -456,6 +460,8 @@ void autokeyframe_pose_cb_func(struct Object *ob, int tmode, short targetless_ik
 
 /*********************** Constraints *****************************/
 
+void drawConstraint(TransInfo *t);
+
 void getConstraintMatrix(TransInfo *t);
 void setConstraint(TransInfo *t, float space[3][3], int mode, const char text[]);
 void setLocalConstraint(TransInfo *t, int mode, const char text[]);
@@ -522,7 +528,7 @@ void initTransInfo(struct bContext *C, TransInfo *t, struct wmEvent *event);
 void postTrans (TransInfo *t);
 void resetTransRestrictions(TransInfo *t);
 
-void drawLine(float *center, float *dir, char axis, short options);
+void drawLine(TransInfo *t, float *center, float *dir, char axis, short options);
 
 TransDataCurveHandleFlags *initTransDataCurveHandes(TransData *td, struct BezTriple *bezt);
 
index c2a53b8a3d9982ca22c9601e0cb8e2e779f9f19e..0270cf0695608c71e3a262dc59b616fb9a98beb8 100644 (file)
 
 #include "BLI_arithb.h"
 
-//#include "BDR_drawobject.h"  /* drawcircball */
-//
 //#include "blendef.h"
 //
 //#include "mydevice.h"
 
 #include "WM_types.h"
+#include "UI_resources.h"
+
 
 #include "transform.h"
 
@@ -676,9 +676,8 @@ void BIF_setDualAxisConstraint(float vec1[3], float vec2[3], char *text) {
 
 /*----------------- DRAWING CONSTRAINTS -------------------*/
 
-void BIF_drawConstraint(void)
+void drawConstraint(TransInfo *t)
 {
-       TransInfo *t = BIF_GetTransInfo();
        TransCon *tc = &(t->con);
 
        if (t->spacetype!=SPACE_VIEW3D)
@@ -705,9 +704,9 @@ void BIF_drawConstraint(void)
                        convertViewVec(t, vec, (short)(t->mval[0] - t->con.imval[0]), (short)(t->mval[1] - t->con.imval[1]));
                        VecAddf(vec, vec, tc->center);
 
-                       drawLine(tc->center, tc->mtx[0], 'x', 0);
-                       drawLine(tc->center, tc->mtx[1], 'y', 0);
-                       drawLine(tc->center, tc->mtx[2], 'z', 0);
+                       drawLine(t, tc->center, tc->mtx[0], 'x', 0);
+                       drawLine(t, tc->center, tc->mtx[1], 'y', 0);
+                       drawLine(t, tc->center, tc->mtx[2], 'z', 0);
 
                        glColor3ubv((GLubyte *)col2);
                        
@@ -724,44 +723,53 @@ void BIF_drawConstraint(void)
                }
 
                if (tc->mode & CON_AXIS0) {
-                       drawLine(tc->center, tc->mtx[0], 'x', DRAWLIGHT);
+                       drawLine(t, tc->center, tc->mtx[0], 'x', DRAWLIGHT);
                }
                if (tc->mode & CON_AXIS1) {
-                       drawLine(tc->center, tc->mtx[1], 'y', DRAWLIGHT);
+                       drawLine(t, tc->center, tc->mtx[1], 'y', DRAWLIGHT);
                }
                if (tc->mode & CON_AXIS2) {
-                       drawLine(tc->center, tc->mtx[2], 'z', DRAWLIGHT);
+                       drawLine(t, tc->center, tc->mtx[2], 'z', DRAWLIGHT);
                }
        }
 }
 
 /* called from drawview.c, as an extra per-window draw option */
-void BIF_drawPropCircle()
+void drawPropCircle(TransInfo *t)
 {
-       TransInfo *t = BIF_GetTransInfo();
-
        if (t->flag & T_PROP_EDIT) {
-               // TRANSFORM_FIX_ME
-#if 0
                float tmat[4][4], imat[4][4];
 
-               BIF_ThemeColor(TH_GRID);
+               UI_ThemeColor(TH_GRID);
                
-               /* if editmode we need to go into object space */
-               if(t->scene->obedit && t->spacetype == SPACE_VIEW3D)
-                       mymultmatrix(t->scene->obedit->obmat);
+               if (t->spacetype == SPACE_VIEW3D)
+               {
+                       View3D *v3d = t->view;
+                       
+                       Mat4CpyMat4(tmat, v3d->viewmat);
+                       Mat4Invert(imat, tmat);
+               }
+               else
+               {
+                       Mat4One(tmat);
+                       Mat4One(imat);
+               }
+
                
-               mygetmatrix(tmat);
-               Mat4Invert(imat, tmat);
+               if(t->obedit)
+               {
+                       glPushMatrix();
+                       glMultMatrixf(t->obedit->obmat); /* because t->center is in local space */
+               }
 
                set_inverted_drawing(1);
                drawcircball(GL_LINE_LOOP, t->center, t->propsize, imat);
                set_inverted_drawing(0);
                
-               /* if editmode we restore */
-               if(t->scene->obedit && t->spacetype == SPACE_VIEW3D)
-                       myloadmatrix(G.vd->viewmat);
-#endif
+               if(t->obedit)
+               {
+                       glPopMatrix();
+               }
        }
 }
 
@@ -775,6 +783,7 @@ void BIF_getPropCenter(float *center)
        else
                center[0] = center[1] = center[2] = 0.0f;
 }
+
 static void drawObjectConstraint(TransInfo *t) {
        int i;
        TransData * td = t->data;
@@ -786,26 +795,26 @@ static void drawObjectConstraint(TransInfo *t) {
           Without drawing the first light, users have little clue what they are doing.
         */
        if (t->con.mode & CON_AXIS0) {
-               drawLine(td->ob->obmat[3], td->axismtx[0], 'x', DRAWLIGHT);
+               drawLine(t, td->ob->obmat[3], td->axismtx[0], 'x', DRAWLIGHT);
        }
        if (t->con.mode & CON_AXIS1) {
-               drawLine(td->ob->obmat[3], td->axismtx[1], 'y', DRAWLIGHT);
+               drawLine(t, td->ob->obmat[3], td->axismtx[1], 'y', DRAWLIGHT);
        }
        if (t->con.mode & CON_AXIS2) {
-               drawLine(td->ob->obmat[3], td->axismtx[2], 'z', DRAWLIGHT);
+               drawLine(t, td->ob->obmat[3], td->axismtx[2], 'z', DRAWLIGHT);
        }
        
        td++;
 
        for(i=1;i<t->total;i++,td++) {
                if (t->con.mode & CON_AXIS0) {
-                       drawLine(td->ob->obmat[3], td->axismtx[0], 'x', 0);
+                       drawLine(t, td->ob->obmat[3], td->axismtx[0], 'x', 0);
                }
                if (t->con.mode & CON_AXIS1) {
-                       drawLine(td->ob->obmat[3], td->axismtx[1], 'y', 0);
+                       drawLine(t, td->ob->obmat[3], td->axismtx[1], 'y', 0);
                }
                if (t->con.mode & CON_AXIS2) {
-                       drawLine(td->ob->obmat[3], td->axismtx[2], 'z', 0);
+                       drawLine(t, td->ob->obmat[3], td->axismtx[2], 'z', 0);
                }
        }
 }
index 69d2e1c119e4b7dc01d04e7264439eeb88fdb3e6..6fd7de6d92c4ab7e26040e71a689d64907e7c6af 100644 (file)
@@ -53,7 +53,6 @@
 #include "DNA_view3d_types.h"
 
 //#include "BIF_screen.h"
-//#include "BIF_resources.h"
 //#include "BIF_mywindow.h"
 #include "BIF_gl.h"
 //#include "BIF_editaction.h"
@@ -89,6 +88,7 @@
 #include "ED_armature.h"
 #include "ED_view3d.h"
 #include "ED_mesh.h"
+#include "ED_space_api.h"
 
 //#include "BSE_editaction_types.h"
 //#include "BDR_unwrapper.h"
 
 #include "WM_types.h"
 
+#include "UI_resources.h"
+
 //#include "blendef.h"
 //
 //#include "mydevice.h"
@@ -611,38 +613,44 @@ void recalcData(TransInfo *t)
                reshadeall_displist(t->scene);
 }
 
-void drawLine(float *center, float *dir, char axis, short options)
+void drawLine(TransInfo *t, float *center, float *dir, char axis, short options)
 {
-#if 0 // TRANSFORM_FIX_ME
-       extern void make_axis_color(char *col, char *col2, char axis);  // drawview.c
+       extern void make_axis_color(char *col, char *col2, char axis);  // view3d_draw.c
        float v1[3], v2[3], v3[3];
        char col[3], col2[3];
        
-       //if(t->obedit) mymultmatrix(t->obedit->obmat); // sets opengl viewing
-
-       VecCopyf(v3, dir);
-       VecMulf(v3, G.vd->far);
+       if (t->spacetype == SPACE_VIEW3D)
+       {
+               View3D *v3d = t->view;
+               
+               glPushMatrix();
+               
+               //if(t->obedit) glLoadMatrixf(t->obedit->obmat);        // sets opengl viewing
+               
        
-       VecSubf(v2, center, v3);
-       VecAddf(v1, center, v3);
-
-       if (options & DRAWLIGHT) {
-               col[0] = col[1] = col[2] = 220;
-       }
-       else {
-               BIF_GetThemeColor3ubv(TH_GRID, col);
-       }
-       make_axis_color(col, col2, axis);
-       glColor3ubv((GLubyte *)col2);
-
-       setlinestyle(0);
-       glBegin(GL_LINE_STRIP); 
-               glVertex3fv(v1); 
-               glVertex3fv(v2); 
-       glEnd();
+               VecCopyf(v3, dir);
+               VecMulf(v3, v3d->far);
+               
+               VecSubf(v2, center, v3);
+               VecAddf(v1, center, v3);
        
-       myloadmatrix(G.vd->viewmat);
-#endif
+               if (options & DRAWLIGHT) {
+                       col[0] = col[1] = col[2] = 220;
+               }
+               else {
+                       UI_GetThemeColor3ubv(TH_GRID, col);
+               }
+               make_axis_color(col, col2, axis);
+               glColor3ubv((GLubyte *)col2);
+       
+               setlinestyle(0);
+               glBegin(GL_LINE_STRIP); 
+                       glVertex3fv(v1); 
+                       glVertex3fv(v2); 
+               glEnd();
+               
+               glPopMatrix();
+       }
 }
 
 void resetTransRestrictions(TransInfo *t)
@@ -755,10 +763,13 @@ void postTrans (TransInfo *t)
 {
        TransData *td;
 
-       G.moving = 0; // Set moving flag off (display as usual)
-
        stopConstraint(t);
        
+       if (t->draw_handle)
+       {
+               ED_region_draw_cb_exit(t->ar->type, t->draw_handle);
+       }
+       
        /* postTrans can be called when nothing is selected, so data is NULL already */
        if (t->data) {
                int a;
index d1f641e874b1a6075a9d67dcd2e89652c85e4d35..f139651c6081111f0a3c041b8217c2b1086afeef 100644 (file)
@@ -52,7 +52,6 @@
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
 //#include "BIF_mywindow.h"
-//#include "BIF_resources.h"
 //#include "BIF_screen.h"
 //#include "BIF_editsima.h"
 //#include "BIF_drawimage.h"
 
 #include "ED_view3d.h"
 
+#include "WM_types.h"
+
+#include "UI_resources.h"
+
 #include "MEM_guardedalloc.h"
 
 #include "transform.h"
-#include "WM_types.h"
+
 //#include "blendef.h" /* for selection modes */
 
 static EditVert *EM_get_vert_for_index(int x) {return 0;}      // XXX
@@ -127,42 +130,36 @@ void drawSnapping(TransInfo *t)
                {
                
                char col[4] = {1, 0, 1};
-               //BIF_GetThemeColor3ubv(TH_TRANSFORM, col);
+               UI_GetThemeColor3ubv(TH_TRANSFORM, col);
                glColor4ub(col[0], col[1], col[2], 128);
                
                if (t->spacetype == SPACE_VIEW3D) {
                        View3D *v3d = t->view;
-                       float unitmat[4][4];
+                       float tmat[4][4], imat[4][4];
                        float size;
                        
                        glDisable(GL_DEPTH_TEST);
        
                        size = get_drawsize(v3d, t->sa, t->tsnap.snapPoint);
                        
-                       //size *= 0.5f * BIF_GetThemeValuef(TH_VERTEX_SIZE);
-                       
-                       glPushMatrix();
+                       size *= 0.5f * UI_GetThemeValuef(TH_VERTEX_SIZE);
                        
-                       glTranslatef(t->tsnap.snapPoint[0], t->tsnap.snapPoint[1], t->tsnap.snapPoint[2]);
+                       Mat4CpyMat4(tmat, v3d->viewmat);
+                       Mat4Invert(imat, tmat);
+
+                       drawcircball(GL_LINE_LOOP, t->tsnap.snapPoint, size, imat);
                        
                        /* draw normal if needed */
                        if (usingSnappingNormal(t) && validSnappingNormal(t))
                        {
                                glBegin(GL_LINES);
-                                       glVertex3f(0, 0, 0);
-                                       glVertex3f(t->tsnap.snapNormal[0], t->tsnap.snapNormal[1], t->tsnap.snapNormal[2]);
+                                       glVertex3f(t->tsnap.snapPoint[0], t->tsnap.snapPoint[1], t->tsnap.snapPoint[2]);
+                                       glVertex3f(     t->tsnap.snapPoint[0] + t->tsnap.snapNormal[0],
+                                                               t->tsnap.snapPoint[1] + t->tsnap.snapNormal[1],
+                                                               t->tsnap.snapPoint[2] + t->tsnap.snapNormal[2]);
                                glEnd();
                        }
                        
-                       /* sets view screen aligned */
-                       glRotatef( -360.0f*saacos(v3d->viewquat[0])/(float)M_PI, v3d->viewquat[1], v3d->viewquat[2], v3d->viewquat[3]);
-                       
-                       Mat4One(unitmat);
-                       // TRANSFORM_FIX_ME
-                       //drawcircball(GL_LINE_LOOP, unitmat[3], size, unitmat);
-                       
-                       glPopMatrix();
-                       
                        if(v3d->zbuf)
                                glEnable(GL_DEPTH_TEST);
                }