use UI_view2d_getscale() to get the scale for image cursor drawing and ED_mask_pixels...
authorCampbell Barton <ideasman42@gmail.com>
Fri, 14 Dec 2012 16:51:02 +0000 (16:51 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 14 Dec 2012 16:51:02 +0000 (16:51 +0000)
source/blender/editors/include/UI_view2d.h
source/blender/editors/interface/view2d.c
source/blender/editors/mask/mask_edit.c
source/blender/editors/uvedit/uvedit_draw.c

index d050df5839a8182d504a2619bc342aa118f4c492..3ae1e93dc3dcb1d823497eb834b71355fb151e98 100644 (file)
@@ -199,6 +199,7 @@ struct View2D *UI_view2d_fromcontext(const struct bContext *C);
 struct View2D *UI_view2d_fromcontext_rwin(const struct bContext *C);
 
 void UI_view2d_getscale(struct View2D *v2d, float *x, float *y);
+void UI_view2d_getscale_inverse(struct View2D *v2d, float *x, float *y);
 
 short UI_view2d_mouse_in_scrollers(const struct bContext *C, struct View2D *v2d, int x, int y);
 
index e2a20e5296a15d2a35ee410dca4d6741fa7751f6..a5f9995df889cad8bfc9750087e1c5be98fdcf32 100644 (file)
@@ -2059,6 +2059,12 @@ void UI_view2d_getscale(View2D *v2d, float *x, float *y)
        if (x) *x = BLI_rcti_size_x(&v2d->mask) / BLI_rctf_size_x(&v2d->cur);
        if (y) *y = BLI_rcti_size_y(&v2d->mask) / BLI_rctf_size_y(&v2d->cur);
 }
+/* Same as UI_view2d_getscale() - 1.0f / x, y */
+void UI_view2d_getscale_inverse(View2D *v2d, float *x, float *y)
+{
+       if (x) *x = BLI_rctf_size_x(&v2d->cur) / BLI_rcti_size_x(&v2d->mask);
+       if (y) *y = BLI_rctf_size_y(&v2d->cur) / BLI_rcti_size_y(&v2d->mask);
+}
 
 /* Check if mouse is within scrollers
  *     - Returns appropriate code for match
index 18384ad9de4a1633dc6f8fd3db9f5277ef4ff028..cd2995be4399ed97a6c9d414544388bd900f41ae 100644 (file)
@@ -324,15 +324,13 @@ void ED_mask_pixelspace_factor(ScrArea *sa, ARegion *ar, float *scalex, float *s
                        case SPACE_CLIP:
                        {
                                SpaceClip *sc = sa->spacedata.first;
-                               int width, height;
-                               float zoomx, zoomy, aspx, aspy;
+                               float aspx, aspy;
 
-                               ED_space_clip_get_size(sc, &width, &height);
-                               ED_space_clip_get_zoom(sc, ar, &zoomx, &zoomy);
+                               UI_view2d_getscale(&ar->v2d, scalex, scaley);
                                ED_space_clip_get_aspect(sc, &aspx, &aspy);
 
-                               *scalex = ((float)width * aspx) * zoomx;
-                               *scaley = ((float)height * aspy) * zoomy;
+                               *scalex *= aspx;
+                               *scaley *= aspy;
                                break;
                        }
                        case SPACE_SEQ:
@@ -343,15 +341,13 @@ void ED_mask_pixelspace_factor(ScrArea *sa, ARegion *ar, float *scalex, float *s
                        case SPACE_IMAGE:
                        {
                                SpaceImage *sima = sa->spacedata.first;
-                               int width, height;
-                               float zoomx, zoomy, aspx, aspy;
+                               float aspx, aspy;
 
-                               ED_space_image_get_size(sima, &width, &height);
-                               ED_space_image_get_zoom(sima, ar, &zoomx, &zoomy);
+                               UI_view2d_getscale(&ar->v2d, scalex, scaley);
                                ED_space_image_get_aspect(sima, &aspx, &aspy);
 
-                               *scalex = ((float)width * aspx) * zoomx;
-                               *scaley = ((float)height * aspy) * zoomy;
+                               *scalex *= aspx;
+                               *scaley *= aspy;
                                break;
                        }
                        default:
index c6b251b04ae3d9ab7d3d81733c3dceb47ad86634..607640090aa4e2ac3f8cad58d2ee1cb5a857371c 100644 (file)
 
 #include "UI_resources.h"
 #include "UI_interface.h"
+#include "UI_view2d.h"
 
 #include "uvedit_intern.h"
 
 void draw_image_cursor(SpaceImage *sima, ARegion *ar)
 {
-       float zoomx, zoomy, x_fac, y_fac;
-       int width, height;
+       float zoom[2], x_fac, y_fac;
 
-       ED_space_image_get_size(sima, &width, &height);
-       ED_space_image_get_zoom(sima, ar, &zoomx, &zoomy);
+       UI_view2d_getscale_inverse(&ar->v2d, &zoom[0], &zoom[1]);
 
-       x_fac = (1.0f / (zoomx * width  / 256.0f)) * UI_DPI_FAC;
-       y_fac = (1.0f / (zoomy * height / 256.0f)) * UI_DPI_FAC;
+       mul_v2_fl(zoom, 256.0f * UI_DPI_FAC);
+       x_fac = zoom[0];
+       y_fac = zoom[1];
        
        cpack(0xFFFFFF);
        glTranslatef(sima->cursor[0], sima->cursor[1], 0.0);