Patch by Martin Poirier: display normalized coordinates in image window, with
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Sun, 26 Jun 2005 15:37:36 +0000 (15:37 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Sun, 26 Jun 2005 15:37:36 +0000 (15:37 +0000)
a few small modifications:
- also display normalized coords while transforming
- adapt step size & precision for button
- moved option to 'View' menu

Also made sure pixel snapping when transforming uv's is off by default.

source/blender/makesdna/DNA_space_types.h
source/blender/src/drawimage.c
source/blender/src/editsima.c
source/blender/src/header_image.c

index cd9bf98776a1c26fb536ab6402232406eb00d19e..12f006a191ef76d238efcf155580a0ba16b263b1 100644 (file)
@@ -455,8 +455,10 @@ typedef struct SpaceImaSel {
 #define SI_STICKYUVS    16
 #define SI_DRAWSHADOW   32
 #define SI_SELACTFACE   64
-#define SI_NOPIXELSNAP  128
+#define SI_DEPRECATED  128
 #define SI_LOCALSTICKY  256
+#define SI_COORDFLOATS  512
+#define SI_PIXELSNAP   1024
 
 /* SpaceText flags (moved from DNA_text_types.h) */
 
index f1991f52a6f939f7742320dc4d9f1372780a8e12..efc2892c10690fbdded730cb7578028522f02ab9 100644 (file)
@@ -571,7 +571,7 @@ static void image_editvertex_buts(uiBlock *block)
        static float ocent[2];
        float cent[2]= {0.0, 0.0};
        int imx, imy;
-       int i, nactive= 0;
+       int i, nactive= 0, step, digits;
        Mesh *me;
        
        if( is_uv_tface_editing_allowed_silent()==0 ) return;
@@ -614,32 +614,46 @@ static void image_editvertex_buts(uiBlock *block)
                
        if(block) {     // do the buttons
                if (nactive) {
-                       ocent[0]= (cent[0]*imx)/nactive;
-                       ocent[1]= (cent[1]*imy)/nactive;
+                       ocent[0]= cent[0]/nactive;
+                       ocent[1]= cent[1]/nactive;
+                       if (G.sima->flag & SI_COORDFLOATS) {
+                               step= 1;
+                               digits= 3;
+                       }
+                       else {
+                               ocent[0] *= imx;
+                               ocent[1] *= imy;
+                               step= 100;
+                               digits= 2;
+                       }
                        
                        uiDefBut(block, LABEL, 0, "UV Vertex:",10,55,302,19,0,0,0,0,0,"");
+                       uiBlockBeginAlign(block);
                        if(nactive==1) {
-                               uiBlockBeginAlign(block);
-                               uiDefButF(block, NUM, B_TRANS_IMAGE, "Vertex X:",       10, 35, 290, 19, &ocent[0], -10*imx, 10.0*imx, 100, 0, "");
-                               uiDefButF(block, NUM, B_TRANS_IMAGE, "Vertex Y:",       10, 15, 290, 19, &ocent[1], -10*imy, 10.0*imy, 100, 0, "");
-                               uiBlockEndAlign(block);
+                               uiDefButF(block, NUM, B_TRANS_IMAGE, "Vertex X:",       10, 35, 290, 19, &ocent[0], -10*imx, 10.0*imx, step, digits, "");
+                               uiDefButF(block, NUM, B_TRANS_IMAGE, "Vertex Y:",       10, 15, 290, 19, &ocent[1], -10*imy, 10.0*imy, step, digits, "");
                        }
                        else {
-                               uiBlockBeginAlign(block);
-                               uiDefButF(block, NUM, B_TRANS_IMAGE, "Median X:",       10, 35, 290, 19, &ocent[0], -10*imx, 10.0*imx, 100, 0, "");
-                               uiDefButF(block, NUM, B_TRANS_IMAGE, "Median Y:",       10, 15, 290, 19, &ocent[1], -10*imy, 10.0*imy, 100, 0, "");
-                               uiBlockEndAlign(block);
+                               uiDefButF(block, NUM, B_TRANS_IMAGE, "Median X:",       10, 35, 290, 19, &ocent[0], -10*imx, 10.0*imx, step, digits, "");
+                               uiDefButF(block, NUM, B_TRANS_IMAGE, "Median Y:",       10, 15, 290, 19, &ocent[1], -10*imy, 10.0*imy, step, digits, "");
                        }
+                       uiBlockEndAlign(block);
                }
        }
        else {  // apply event
                float delta[2];
                
-               cent[0]= (cent[0]*imx)/nactive;
-               cent[1]= (cent[1]*imy)/nactive;
+               cent[0]= cent[0]/nactive;
+               cent[1]= cent[1]/nactive;
                        
-               delta[0]= (ocent[0]-cent[0])/imx;
-               delta[1]= (ocent[1]-cent[1])/imy;
+               if (G.sima->flag & SI_COORDFLOATS) {
+                       delta[0]= ocent[0]-cent[0];
+                       delta[1]= ocent[1]-cent[1];
+               }
+               else {
+                       delta[0]= ocent[0]/imx - cent[0];
+                       delta[1]= ocent[1]/imy - cent[1];
+               }
 
                for (i=0; i<me->totface; i++) {
                        MFace *mf= &((MFace*) me->mface)[i];
index fc6506579ab4d59d9f9cfeb5febb5e98445f3648..8cb75c590500c4153a62b9093b0e0b404c77c8e6 100644 (file)
@@ -229,12 +229,8 @@ static void sima_pixelgrid(float *loc, float sx, float sy)
 {
        float y;
        float x;
-       
-       if(G.sima->flag & SI_NOPIXELSNAP) {
-               loc[0]= sx;
-               loc[1]= sy;
-       }
-       else {
+
+       if(G.sima->flag & SI_PIXELSNAP) {
                if(G.sima->image && G.sima->image->ibuf) {
                        x= G.sima->image->ibuf->x;
                        y= G.sima->image->ibuf->y;
@@ -256,6 +252,10 @@ static void sima_pixelgrid(float *loc, float sx, float sy)
                        loc[1]= sy;
                }
        }
+       else {
+               loc[0]= sx;
+               loc[1]= sy;
+       }
 }
 
 
@@ -539,11 +539,17 @@ void transform_tface_uv(int mode, int context)    // 2 args, for callback
                                        }
                                }
                                        
-                               ivec[0]= (vec[0]*xim);
-                               ivec[1]= (vec[1]*yim);
-
                                if(G.sima->flag & SI_BE_SQUARE) be_square_tface_uv(me);
-                       
+       
+                               if (G.sima->flag & SI_COORDFLOATS) {
+                                       ivec[0]= vec[0];
+                                       ivec[1]= vec[1];
+                               }
+                               else {
+                                       ivec[0]= (vec[0]*xim);
+                                       ivec[1]= (vec[1]*yim);
+                               }
+               
                                sprintf(str, "X: %.4f   Y: %.4f  ", ivec[0], ivec[1]);
                                headerprint(str);
                        }
index 683c8407e0d19e70cb6f211d3cf7c62ab4c192b4..9a1668c89b593a2326439fbb7be3ea9a3960c7d2 100644 (file)
@@ -444,6 +444,10 @@ static void do_image_viewmenu(void *arg, int event)
                break;
        case 9:
                image_viewcentre();
+       case 10: /* Display Normalized Coordinates */
+               G.sima->flag ^= SI_COORDFLOATS;
+               allqueue(REDRAWIMAGE, 0);
+               break;
        }
        allqueue(REDRAWVIEW3D, 0);
 }
@@ -460,12 +464,13 @@ static uiBlock *image_viewmenu(void *arg_unused)
        uiDefIconTextBut(block, BUTM, 1, ICON_MENU_PANEL, "View Properties...", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 7, "");
        uiDefIconTextBut(block, BUTM, 1, ICON_MENU_PANEL, "View Paint Tool...", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 8, "");
 
-       
+       if(G.sima->flag & SI_COORDFLOATS) uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Display Normalized Coordinates|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 10, "");
+       else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Display Normalized Coordinates|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 10, "");
        if(G.f & G_DRAWFACES) uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Draw Faces", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 6, "");
        else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Draw Faces|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 6, "");
        if(G.sima->flag & SI_DRAWSHADOW) uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Draw Shadow Mesh", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 5, "");
        else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Draw Shadow Mesh|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 5, "");
-       
+
        uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
        uiDefIconTextBlockBut(block, image_view_viewnavmenu, NULL, ICON_RIGHTARROW_THIN, "View Navigation", 0, yco-=20, 120, 19, "");
 
@@ -956,8 +961,7 @@ static void do_image_uvsmenu(void *arg, int event)
                        G.scene->proportional= 1;
                break;
        case 7: /* UVs Snap to Pixel */
-               if(G.sima->flag & SI_NOPIXELSNAP) G.sima->flag &= ~SI_NOPIXELSNAP;
-               else G.sima->flag |= SI_NOPIXELSNAP;
+               G.sima->flag ^= SI_PIXELSNAP;
                break;
     case 8:
                pin_tface_uv(1);
@@ -983,8 +987,8 @@ static uiBlock *image_uvsmenu(void *arg_unused)
 
        // uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Transform Properties...|N", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 0, "");
        // uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
-       if(G.sima->flag & SI_NOPIXELSNAP) uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Snap to Pixels|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 7, "");
-       else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Snap to Pixels|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 7, "");
+       if(G.sima->flag & SI_PIXELSNAP) uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Snap to Pixels|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 7, "");
+       else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Snap to Pixels|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 7, "");
 
        if(G.sima->flag & SI_BE_SQUARE) uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Quads Constrained Rectangular|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 1, "");
        else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Quads Constrained Rectangular|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 1, "");