diff options
author | Campbell Barton <ideasman42@gmail.com> | 2020-03-25 11:06:17 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2020-03-25 11:06:17 +0300 |
commit | 4c57f07a0fde0ca067e5b0e6609ded6c0e170cc2 (patch) | |
tree | 652abc47c4f68fd7377c031d82ada29949bb4f28 /source/blender/editors/mask/mask_edit.c | |
parent | 2bc791437e3b8e42c1369daf15c72934474b1e73 (diff) |
Cleanup: move mask queries into own file
Similar functions to lookup nearest mask points were in mask_add.c
& mask_edit.c
Diffstat (limited to 'source/blender/editors/mask/mask_edit.c')
-rw-r--r-- | source/blender/editors/mask/mask_edit.c | 347 |
1 files changed, 9 insertions, 338 deletions
diff --git a/source/blender/editors/mask/mask_edit.c b/source/blender/editors/mask/mask_edit.c index 1606d079462..e18c4992671 100644 --- a/source/blender/editors/mask/mask_edit.c +++ b/source/blender/editors/mask/mask_edit.c @@ -47,7 +47,9 @@ #include "mask_intern.h" /* own include */ -/********************** generic poll functions *********************/ +/* -------------------------------------------------------------------- */ +/** \name Poll Functions + * \{ */ bool ED_maskedit_poll(bContext *C) { @@ -81,344 +83,11 @@ bool ED_maskedit_mask_poll(bContext *C) return false; } -/********************** registration *********************/ +/** \} */ -/* takes event->mval */ -void ED_mask_mouse_pos(ScrArea *sa, ARegion *region, const int mval[2], float co[2]) -{ - if (sa) { - switch (sa->spacetype) { - case SPACE_CLIP: { - SpaceClip *sc = sa->spacedata.first; - ED_clip_mouse_pos(sc, region, mval, co); - BKE_mask_coord_from_movieclip(sc->clip, &sc->user, co, co); - break; - } - case SPACE_SEQ: { - UI_view2d_region_to_view(®ion->v2d, mval[0], mval[1], &co[0], &co[1]); - break; - } - case SPACE_IMAGE: { - SpaceImage *sima = sa->spacedata.first; - ED_image_mouse_pos(sima, region, mval, co); - BKE_mask_coord_from_image(sima->image, &sima->iuser, co, co); - break; - } - default: - /* possible other spaces from which mask editing is available */ - BLI_assert(0); - zero_v2(co); - break; - } - } - else { - BLI_assert(0); - zero_v2(co); - } -} - -/* input: x/y - mval space - * output: xr/yr - mask point space */ -void ED_mask_point_pos(ScrArea *sa, ARegion *region, float x, float y, float *xr, float *yr) -{ - float co[2]; - - if (sa) { - switch (sa->spacetype) { - case SPACE_CLIP: { - SpaceClip *sc = sa->spacedata.first; - ED_clip_point_stable_pos(sc, region, x, y, &co[0], &co[1]); - BKE_mask_coord_from_movieclip(sc->clip, &sc->user, co, co); - break; - } - case SPACE_SEQ: - zero_v2(co); /* MASKTODO */ - break; - case SPACE_IMAGE: { - SpaceImage *sima = sa->spacedata.first; - ED_image_point_pos(sima, region, x, y, &co[0], &co[1]); - BKE_mask_coord_from_image(sima->image, &sima->iuser, co, co); - break; - } - default: - /* possible other spaces from which mask editing is available */ - BLI_assert(0); - zero_v2(co); - break; - } - } - else { - BLI_assert(0); - zero_v2(co); - } - - *xr = co[0]; - *yr = co[1]; -} - -void ED_mask_point_pos__reverse( - ScrArea *sa, ARegion *region, float x, float y, float *xr, float *yr) -{ - float co[2]; - - if (sa) { - switch (sa->spacetype) { - case SPACE_CLIP: { - SpaceClip *sc = sa->spacedata.first; - co[0] = x; - co[1] = y; - BKE_mask_coord_to_movieclip(sc->clip, &sc->user, co, co); - ED_clip_point_stable_pos__reverse(sc, region, co, co); - break; - } - case SPACE_SEQ: - zero_v2(co); /* MASKTODO */ - break; - case SPACE_IMAGE: { - SpaceImage *sima = sa->spacedata.first; - co[0] = x; - co[1] = y; - BKE_mask_coord_to_image(sima->image, &sima->iuser, co, co); - ED_image_point_pos__reverse(sima, region, co, co); - break; - } - default: - /* possible other spaces from which mask editing is available */ - BLI_assert(0); - zero_v2(co); - break; - } - } - else { - BLI_assert(0); - zero_v2(co); - } - - *xr = co[0]; - *yr = co[1]; -} - -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; - } -} - -void ED_mask_zoom(ScrArea *sa, ARegion *region, float *zoomx, float *zoomy) -{ - if (sa && sa->spacedata.first) { - switch (sa->spacetype) { - case SPACE_CLIP: { - SpaceClip *sc = sa->spacedata.first; - ED_space_clip_get_zoom(sc, region, zoomx, zoomy); - break; - } - case SPACE_SEQ: { - *zoomx = *zoomy = 1.0f; - break; - } - case SPACE_IMAGE: { - SpaceImage *sima = sa->spacedata.first; - ED_space_image_get_zoom(sima, region, zoomx, zoomy); - break; - } - default: - /* possible other spaces from which mask editing is available */ - BLI_assert(0); - *zoomx = *zoomy = 1.0f; - break; - } - } - else { - BLI_assert(0); - *zoomx = *zoomy = 1.0f; - } -} - -void ED_mask_get_aspect(ScrArea *sa, ARegion *UNUSED(region), 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 ED_mask_pixelspace_factor(ScrArea *sa, ARegion *region, 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_scale_get(®ion->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_scale_get(®ion->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; - } -} - -void ED_mask_cursor_location_get(ScrArea *sa, float cursor[2]) -{ - if (sa) { - switch (sa->spacetype) { - case SPACE_CLIP: { - SpaceClip *space_clip = sa->spacedata.first; - copy_v2_v2(cursor, space_clip->cursor); - break; - } - case SPACE_SEQ: { - zero_v2(cursor); - break; - } - case SPACE_IMAGE: { - SpaceImage *space_image = sa->spacedata.first; - copy_v2_v2(cursor, space_image->cursor); - break; - } - default: - /* possible other spaces from which mask editing is available */ - BLI_assert(0); - zero_v2(cursor); - break; - } - } - else { - BLI_assert(0); - zero_v2(cursor); - } -} - -bool ED_mask_selected_minmax(const bContext *C, float min[2], float max[2]) -{ - Mask *mask = CTX_data_edit_mask(C); - bool ok = false; - - if (mask == NULL) { - return ok; - } - - INIT_MINMAX2(min, max); - for (MaskLayer *mask_layer = mask->masklayers.first; mask_layer != NULL; - mask_layer = mask_layer->next) { - if (mask_layer->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) { - continue; - } - for (MaskSpline *spline = mask_layer->splines.first; spline != NULL; spline = spline->next) { - MaskSplinePoint *points_array = BKE_mask_spline_point_array(spline); - for (int i = 0; i < spline->tot_point; i++) { - MaskSplinePoint *point = &spline->points[i]; - MaskSplinePoint *deform_point = &points_array[i]; - BezTriple *bezt = &point->bezt; - float handle[2]; - if (!MASKPOINT_ISSEL_ANY(point)) { - continue; - } - if (bezt->f2 & SELECT) { - minmax_v2v2_v2(min, max, deform_point->bezt.vec[1]); - } - if (BKE_mask_point_handles_mode_get(point) == MASK_HANDLE_MODE_STICK) { - BKE_mask_point_handle(deform_point, MASK_WHICH_HANDLE_STICK, handle); - minmax_v2v2_v2(min, max, handle); - } - else { - if ((bezt->f1 & SELECT) && (bezt->h1 != HD_VECT)) { - BKE_mask_point_handle(deform_point, MASK_WHICH_HANDLE_LEFT, handle); - minmax_v2v2_v2(min, max, handle); - } - if ((bezt->f3 & SELECT) && (bezt->h2 != HD_VECT)) { - BKE_mask_point_handle(deform_point, MASK_WHICH_HANDLE_RIGHT, handle); - minmax_v2v2_v2(min, max, handle); - } - } - ok = true; - } - } - } - return ok; -} - -/********************** registration *********************/ +/* -------------------------------------------------------------------- */ +/** \name Registration + * \{ */ void ED_operatortypes_mask(void) { @@ -522,3 +191,5 @@ void ED_operatormacros_mask(void) RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false); RNA_boolean_set(otmacro->ptr, "mirror", false); } + +/** \} */ |