mask/image viewer now works with non 1:1 image aspect, editing masks in the image...
[blender.git] / source / blender / editors / space_image / image_edit.c
index 736b585864befad6dfee82c727700fa26d9834e1..f80210fe4d7cba1edf4e81858dfe416ef7420a76 100644 (file)
@@ -47,6 +47,8 @@
 #include "ED_screen.h"
 #include "ED_uvedit.h"
 
+#include "UI_view2d.h"
+
 #include "WM_api.h"
 #include "WM_types.h"
 
@@ -149,8 +151,8 @@ void ED_image_get_size(Image *ima, int *width, int *height)
                *height = ibuf->y;
        }
        else {
-               *width = 256;
-               *height = 256;
+               *width  = IMG_SIZE_FALLBACK;
+               *height = IMG_SIZE_FALLBACK;
        }
 
        if (ima)
@@ -183,8 +185,8 @@ void ED_space_image_get_size(SpaceImage *sima, int *width, int *height)
        /* I know a bit weak... but preview uses not actual image size */
        // XXX else if (image_preview_active(sima, width, height));
        else {
-               *width = 256;
-               *height = 256;
+               *width  = IMG_SIZE_FALLBACK;
+               *height = IMG_SIZE_FALLBACK;
        }
 
        ED_space_image_release_buffer(sima, lock);
@@ -250,6 +252,20 @@ void ED_image_get_uv_aspect(Image *ima, float *aspx, float *aspy)
        *aspy *= (float)h;
 }
 
+void ED_image_mouse_pos(SpaceImage *sima, ARegion *ar, wmEvent *event, float co[2])
+{
+       int sx, sy, width, height;
+       float zoomx, zoomy;
+
+       ED_space_image_get_zoom(sima, ar, &zoomx, &zoomy);
+       ED_space_image_get_size(sima, &width, &height);
+
+       UI_view2d_to_region_no_clip(&ar->v2d, 0.0f, 0.0f, &sx, &sy);
+
+       co[0] = ((event->mval[0] - sx) / zoomx) / width;
+       co[1] = ((event->mval[1] - sy) / zoomy) / height;
+}
+
 int ED_space_image_show_render(SpaceImage *sima)
 {
        return (sima->image && ELEM(sima->image->type, IMA_TYPE_R_RESULT, IMA_TYPE_COMPOSITE));