void ED_space_clip_get_aspect_dimension_aware(SpaceClip *sc, float *aspx, float *aspy) { int w, h; /* most of tools does not require aspect to be returned with dimensions correction * due to they're invariant to this stuff, but some transformation tools like rotation * should be aware of aspect correction caused by different resolution in different * directions. * mainly this is sued for transformation stuff */ if (!sc->clip) { *aspx = 1.0f; *aspy = 1.0f; return; } ED_space_clip_get_aspect(sc, aspx, aspy); BKE_movieclip_get_size(sc->clip, &sc->user, &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_aspect(ScrArea *sa, ARegion *UNUSED(ar), float *aspx, float *aspy) { if (sa && sa->spacedata.first) { switch (sa->spacetype) { case SPACE_CLIP: { SpaceClip *sc = sa->spacedata.first; ED_space_clip_get_aspect(sc, aspx, aspy); break; } case SPACE_SEQ: { *aspx = *aspy = 1.0f; /* MASKTODO - render aspect? */ break; } case SPACE_IMAGE: { SpaceImage *sima = sa->spacedata.first; ED_space_image_get_aspect(sima, aspx, aspy); break; } default: /* possible other spaces from which mask editing is available */ BLI_assert(0); *aspx = *aspy = 1.0f; break; } } else { BLI_assert(0); *aspx = *aspy = 1.0f; } }
void clip_view_center_to_point(SpaceClip *sc, float x, float y) { int width, height; float aspx, aspy; ED_space_clip_get_size(sc, &width, &height); ED_space_clip_get_aspect(sc, &aspx, &aspy); sc->xof = (x - 0.5f) * width * aspx; sc->yof = (y - 0.5f) * height * aspy; }
static int view_all_exec(bContext *C, wmOperator *op) { SpaceClip *sc; ARegion *ar; int w, h, width, height; float aspx, aspy; int fit_view = RNA_boolean_get(op->ptr, "fit_view"); float zoomx, zoomy; /* retrieve state */ sc = CTX_wm_space_clip(C); ar = CTX_wm_region(C); ED_space_clip_get_size(sc, &w, &h); ED_space_clip_get_aspect(sc, &aspx, &aspy); w = w * aspx; h = h * aspy; /* check if the image will fit in the image with zoom == 1 */ width = BLI_rcti_size_x(&ar->winrct) + 1; height = BLI_rcti_size_y(&ar->winrct) + 1; if (fit_view) { const int margin = 5; /* margin from border */ zoomx = (float) width / (w + 2 * margin); zoomy = (float) height / (h + 2 * margin); sclip_zoom_set(C, min_ff(zoomx, zoomy), NULL); } else { if ((w >= width || h >= height) && (width > 0 && height > 0)) { zoomx = (float) width / w; zoomy = (float) height / h; /* find the zoom value that will fit the image in the image space */ sclip_zoom_set(C, 1.0f / power_of_2(1.0f / min_ff(zoomx, zoomy)), NULL); } else sclip_zoom_set(C, 1.0f, NULL); } sc->xof = sc->yof = 0.0f; ED_region_tag_redraw(CTX_wm_region(C)); return OPERATOR_FINISHED; }
static void sclip_zoom_set(const bContext *C, float zoom, float location[2]) { SpaceClip *sc = CTX_wm_space_clip(C); ARegion *ar = CTX_wm_region(C); float oldzoom = sc->zoom; int width, height; sc->zoom = zoom; if (sc->zoom < 0.1f || sc->zoom > 4.0f) { /* check zoom limits */ ED_space_clip_get_size(sc, &width, &height); width *= sc->zoom; height *= sc->zoom; if ((width < 4) && (height < 4) && sc->zoom < oldzoom) sc->zoom = oldzoom; else if (BLI_rcti_size_x(&ar->winrct) <= sc->zoom) sc->zoom = oldzoom; else if (BLI_rcti_size_y(&ar->winrct) <= sc->zoom) sc->zoom = oldzoom; } if ((U.uiflag & USER_ZOOM_TO_MOUSEPOS) && location) { float aspx, aspy, w, h, dx, dy; ED_space_clip_get_size(sc, &width, &height); ED_space_clip_get_aspect(sc, &aspx, &aspy); w = width * aspx; h = height * aspy; dx = ((location[0] - 0.5f) * w - sc->xof) * (sc->zoom - oldzoom) / sc->zoom; dy = ((location[1] - 0.5f) * h - sc->yof) * (sc->zoom - oldzoom) / sc->zoom; if (sc->flag & SC_LOCK_SELECTION) { sc->xlockof += dx; sc->ylockof += dy; } else { sc->xof += dx; sc->yof += dy; } } }
void ED_mask_pixelspace_factor(ScrArea *sa, ARegion *ar, float *scalex, float *scaley) { if (sa && sa->spacedata.first) { switch (sa->spacetype) { case SPACE_CLIP: { SpaceClip *sc = sa->spacedata.first; float aspx, aspy; UI_view2d_getscale(&ar->v2d, scalex, scaley); ED_space_clip_get_aspect(sc, &aspx, &aspy); *scalex *= aspx; *scaley *= aspy; break; } case SPACE_SEQ: { *scalex = *scaley = 1.0f; /* MASKTODO? */ break; } case SPACE_IMAGE: { SpaceImage *sima = sa->spacedata.first; float aspx, aspy; UI_view2d_getscale(&ar->v2d, scalex, scaley); ED_space_image_get_aspect(sima, &aspx, &aspy); *scalex *= aspx; *scaley *= aspy; break; } default: /* possible other spaces from which mask editing is available */ BLI_assert(0); *scalex = *scaley = 1.0f; break; } } else { BLI_assert(0); *scalex = *scaley = 1.0f; } }
bool ED_clip_view_selection(const bContext *C, ARegion *ar, bool fit) { SpaceClip *sc = CTX_wm_space_clip(C); int w, h, frame_width, frame_height; float min[2], max[2]; ED_space_clip_get_size(sc, &frame_width, &frame_height); if ((frame_width == 0) || (frame_height == 0) || (sc->clip == NULL)) return false; if (!selected_boundbox(sc, min, max)) return false; /* center view */ clip_view_center_to_point(sc, (max[0] + min[0]) / (2 * frame_width), (max[1] + min[1]) / (2 * frame_height)); w = max[0] - min[0]; h = max[1] - min[1]; /* set zoom to see all selection */ if (w > 0 && h > 0) { int width, height; float zoomx, zoomy, newzoom, aspx, aspy; ED_space_clip_get_aspect(sc, &aspx, &aspy); width = BLI_rcti_size_x(&ar->winrct) + 1; height = BLI_rcti_size_y(&ar->winrct) + 1; zoomx = (float)width / w / aspx; zoomy = (float)height / h / aspy; newzoom = 1.0f / power_of_2(1.0f / min_ff(zoomx, zoomy)); if (fit || sc->zoom > newzoom) sc->zoom = newzoom; } return true; }