Bretch's patch for 2D transform. Thanks
[blender.git] / source / blender / src / drawimage.c
index 11081fc43b8f7d31656604ab084d8a51355e62d3..7897f95a197b6b74b6e3fb07a04414b8f24f6260 100644 (file)
@@ -65,6 +65,7 @@
 #include "BKE_image.h"
 #include "BKE_DerivedMesh.h"
 #include "BKE_displist.h"
+#include "BKE_object.h"
 
 #include "BDR_editface.h"
 #include "BDR_drawobject.h"
 #include "BIF_glutil.h"
 #include "BIF_space.h"
 #include "BIF_screen.h"
+#include "BIF_transform.h"
 
 #include "BSE_trans_types.h"
+#include "BSE_view.h"
 
 /* Modules used */
 #include "mydevice.h"
 #include "blendef.h"
 #include "butspace.h"  // event codes
 
-float prop_cent[3]= {0.0, 0.0, 0.0}, prop_size= 0.1;
-
 /**
  * Sets up the fields of the View2D member of the SpaceImage struct
  * This routine can be called in two modes:
@@ -224,7 +225,7 @@ void uvco_to_areaco(float *vec, short *mval)
 {
        float x, y;
 
-       mval[0]= 3200;
+       mval[0]= IS_CLIPPED;
        
        x= (vec[0] - G.v2d->cur.xmin)/(G.v2d->cur.xmax-G.v2d->cur.xmin);
        y= (vec[1] - G.v2d->cur.ymin)/(G.v2d->cur.ymax-G.v2d->cur.ymin);
@@ -237,11 +238,11 @@ void uvco_to_areaco(float *vec, short *mval)
        }
 }
 
-void uvco_to_areaco_noclip(float *vec, short *mval)
+void uvco_to_areaco_noclip(float *vec, int *mval)
 {
        float x, y;
 
-       mval[0]= 3200;
+       mval[0]= IS_CLIPPED;
        
        x= (vec[0] - G.v2d->cur.xmin)/(G.v2d->cur.xmax-G.v2d->cur.xmin);
        y= (vec[1] - G.v2d->cur.ymin)/(G.v2d->cur.ymax-G.v2d->cur.ymin);
@@ -284,8 +285,7 @@ void draw_tfaces(void)
                                mface= me->mface;
                                a= me->totface;                 
                                while(a--) {
-                                       if(tface->flag & TF_HIDE);
-                                       else if(mface->v3) {
+                                       if(!(tface->flag & TF_HIDE)) {
                                                glColor3ub(112, 112, 112);
                                                glBegin(GL_LINE_LOOP);
                                                glVertex2fv(tface->uv[0]);
@@ -309,7 +309,7 @@ void draw_tfaces(void)
                                mface= me->mface;
                                a= me->totface;                 
                                while(a--) {
-                                       if(mface->v3 && (tface->flag & TF_SELECT)) {
+                                       if(tface->flag & TF_SELECT) {
                                                if(!(~tface->flag & (TF_SEL1|TF_SEL2|TF_SEL3)) &&
                                                   (!mface->v4 || tface->flag & TF_SEL4))
                                                        glColor4ubv(col2);
@@ -334,7 +334,7 @@ void draw_tfaces(void)
                        mface= me->mface;
                        a= me->totface;
                        while(a--) {
-                               if(mface->v3 && (tface->flag & TF_SELECT) ) {
+                               if(tface->flag & TF_SELECT) {
                                        if(tface->flag & TF_ACTIVE){
                                                activetface= tface; 
                                                activemface= mface; 
@@ -421,7 +421,7 @@ void draw_tfaces(void)
                        mface= me->mface;
                        a= me->totface;
                        while(a--) {
-                               if(mface->v3  && (tface->flag & TF_SELECT) ) {
+                               if(tface->flag & TF_SELECT) {
                                        
                                        if(tface->flag & TF_SEL1); else bglVertex2fv(tface->uv[0]);
                                        if(tface->flag & TF_SEL2); else bglVertex2fv(tface->uv[1]);
@@ -445,7 +445,7 @@ void draw_tfaces(void)
                        mface= me->mface;
                        a= me->totface;
                        while(a--) {
-                               if(mface->v3  && (tface->flag & TF_SELECT) ) {
+                               if(tface->flag & TF_SELECT) {
                                        
                                        if(tface->unwrap & TF_PIN1) bglVertex2fv(tface->uv[0]);
                                        if(tface->unwrap & TF_PIN2) bglVertex2fv(tface->uv[1]);
@@ -468,7 +468,7 @@ void draw_tfaces(void)
                        mface= me->mface;
                        a= me->totface;
                        while(a--) {
-                               if(mface->v3  && (tface->flag & TF_SELECT) ) {
+                               if(tface->flag & TF_SELECT) {
                                        
                                        if(tface->flag & TF_SEL1) bglVertex2fv(tface->uv[0]);
                                        if(tface->flag & TF_SEL2) bglVertex2fv(tface->uv[1]);
@@ -508,28 +508,12 @@ static unsigned int *get_part_from_ibuf(ImBuf *ibuf, short startx, short starty,
        return rectmain;
 }
 
-/* now only in use by drawimage.c */
-static void draw_prop_circle()
+static void draw_image_transform(ImBuf *ibuf)
 {
-       if (G.scene->proportional) {
-               float tmat[4][4], imat[4][4];
-               
-               if(G.moving) {
-                       BIF_ThemeColor(TH_GRID);
-                       
-                       mygetmatrix(tmat);
-                       Mat4Invert(imat, tmat);
-                       
-                       drawcircball(GL_LINE_LOOP, prop_cent, prop_size, imat);
-               }
-       }
-}
+       if(G.moving) {
+               float aspx, aspy, center[3];
 
-static void draw_image_prop_circle(ImBuf *ibuf)
-{
-       float aspx, aspy;
-
-       if(G.moving && G.scene->proportional) {
+        BIF_drawConstraint();
 
                if(ibuf==0 || ibuf->rect==0 || ibuf->x==0 || ibuf->y==0) {
                        aspx= aspy= 1.0;
@@ -539,12 +523,16 @@ static void draw_image_prop_circle(ImBuf *ibuf)
                        aspy= 256.0/ibuf->y;
                }
 
+               BIF_getPropCenter(center);
+
                /* scale and translate the circle into place and draw it */
                glPushMatrix();
                glScalef(aspx, aspy, 1.0);
-               glTranslatef((1/aspx)*prop_cent[0] - prop_cent[0],
-                            (1/aspy)*prop_cent[1] - prop_cent[1], 0.0);
-               draw_prop_circle();
+               glTranslatef((1/aspx)*center[0] - center[0],
+                            (1/aspy)*center[1] - center[1], 0.0);
+
+               BIF_drawPropCircle();
+
                glPopMatrix();
        }
 }
@@ -600,7 +588,7 @@ static void image_editvertex_buts(uiBlock *block)
                MFace *mf= &((MFace*) me->mface)[i];
                TFace *tf= &((TFace*) me->tface)[i];
                
-               if (!mf->v3 || !(tf->flag & TF_SELECT))
+               if (!(tf->flag & TF_SELECT))
                        continue;
                
                if (tf->flag & TF_SEL1) {
@@ -672,7 +660,7 @@ static void image_editvertex_buts(uiBlock *block)
                        MFace *mf= &((MFace*) me->mface)[i];
                        TFace *tf= &((TFace*) me->tface)[i];
                
-                       if (!mf->v3 || !(tf->flag & TF_SELECT))
+                       if (!(tf->flag & TF_SELECT))
                                continue;
                
                        if (tf->flag & TF_SEL1) {
@@ -828,6 +816,15 @@ void drawimagespace(ScrArea *sa, void *spacedata)
        int x1, y1;
        short sx, sy, dx, dy;
        
+               /* If derived data is used then make sure that object
+                * is up-to-date... might not be the case because updates
+                * are normally done in drawview and could get here before
+                * drawing a View3D.
+                */
+       if (!G.obedit && OBACT && (G.sima->flag&SI_DRAWSHADOW)) {
+               object_handle_update(OBACT);
+       }
+
        BIF_GetThemeColor3fv(TH_BACK, col);
        glClearColor(col[0], col[1], col[2], 0.0);
        glClear(GL_COLOR_BUFFER_BIT);
@@ -927,7 +924,7 @@ void drawimagespace(ScrArea *sa, void *spacedata)
                calc_image_view(G.sima, 'f');   /* float */
        }
 
-       draw_image_prop_circle(ibuf);
+       draw_image_transform(ibuf);
 
        myortho2(-0.375, sa->winx-0.375, -0.375, sa->winy-0.375);
        draw_image_view_icon();
@@ -1101,7 +1098,7 @@ void image_viewcentre(void)
        
        if(size<=0.01) size= 0.01;
 
-       G.sima->zoom= 1.0/size;
+       G.sima->zoom= 0.7/size;
 
        calc_image_view(G.sima, 'p');