void ED_space_image_get_size_fl(SpaceImage *sima, float size[2]) { int size_i[2]; ED_space_image_get_size(sima, &size_i[0], &size_i[1]); size[0] = size_i[0]; size[1] = size_i[1]; }
void ED_space_image_get_zoom(SpaceImage *sima, ARegion *ar, float *zoomx, float *zoomy) { int width, height; ED_space_image_get_size(sima, &width, &height); *zoomx = (float)(BLI_rcti_size_x(&ar->winrct) + 1) / (float)(BLI_rctf_size_x(&ar->v2d.cur) * width); *zoomy = (float)(BLI_rcti_size_y(&ar->winrct) + 1) / (float)(BLI_rctf_size_y(&ar->v2d.cur) * height); }
void ED_image_point_pos__reverse(SpaceImage *sima, ARegion *ar, const float co[2], float r_co[2]) { float zoomx, zoomy; int width, height; int sx, sy; UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &sx, &sy); ED_space_image_get_size(sima, &width, &height); ED_space_image_get_zoom(sima, ar, &zoomx, &zoomy); r_co[0] = (co[0] * width * zoomx) + (float)sx; r_co[1] = (co[1] * height * zoomy) + (float)sy; }
void ED_image_point_pos(SpaceImage *sima, ARegion *ar, float x, float y, float *xr, float *yr) { 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_view_to_region(&ar->v2d, 0.0f, 0.0f, &sx, &sy); *xr = ((x - sx) / zoomx) / width; *yr = ((y - sy) / zoomy) / height; }
/* takes event->mval */ void ED_image_mouse_pos(SpaceImage *sima, ARegion *ar, const int mval[2], 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_view_to_region(&ar->v2d, 0.0f, 0.0f, &sx, &sy); co[0] = ((mval[0] - sx) / zoomx) / width; co[1] = ((mval[1] - sy) / zoomy) / height; }
void ED_space_image_get_uv_aspect(SpaceImage *sima, float *aspx, float *aspy) { int w, h; ED_space_image_get_aspect(sima, aspx, aspy); ED_space_image_get_size(sima, &w, &h); *aspx *= (float)w; *aspy *= (float)h; if (*aspx < *aspy) { *aspy = *aspy / *aspx; *aspx = 1.0f; } else { *aspx = *aspx / *aspy; *aspy = 1.0f; } }
void ED_mask_get_size(ScrArea *sa, int *width, int *height) { if (sa && sa->spacedata.first) { switch (sa->spacetype) { case SPACE_CLIP: { SpaceClip *sc = sa->spacedata.first; ED_space_clip_get_size(sc, width, height); break; } case SPACE_SEQ: { // Scene *scene = CTX_data_scene(C); // *width = (scene->r.size * scene->r.xsch) / 100; // *height = (scene->r.size * scene->r.ysch) / 100; break; } case SPACE_IMAGE: { SpaceImage *sima = sa->spacedata.first; ED_space_image_get_size(sima, width, height); break; } default: /* possible other spaces from which mask editing is available */ BLI_assert(0); *width = 0; *height = 0; break; } } else { BLI_assert(0); *width = 0; *height = 0; } }