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 8ae2b76cd4ee62edc582c1675814245c92e25a87..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"
 
@@ -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));