diff options
Diffstat (limited to 'source/blender/editors/mask')
-rw-r--r-- | source/blender/editors/mask/mask_draw.c | 74 | ||||
-rw-r--r-- | source/blender/editors/mask/mask_edit.c | 29 | ||||
-rw-r--r-- | source/blender/editors/mask/mask_intern.h | 3 |
3 files changed, 94 insertions, 12 deletions
diff --git a/source/blender/editors/mask/mask_draw.c b/source/blender/editors/mask/mask_draw.c index 8503c538a8d..c79920eeb01 100644 --- a/source/blender/editors/mask/mask_draw.c +++ b/source/blender/editors/mask/mask_draw.c @@ -32,17 +32,21 @@ #include "MEM_guardedalloc.h" #include "BLI_utildefines.h" +#include "BLI_math.h" #include "BKE_context.h" #include "BKE_mask.h" #include "DNA_mask_types.h" +#include "DNA_screen_types.h" #include "DNA_object_types.h" /* SELECT */ #include "ED_mask.h" /* own include */ +#include "ED_space_api.h" #include "BIF_gl.h" #include "UI_resources.h" +#include "UI_view2d.h" #include "mask_intern.h" /* own include */ @@ -462,3 +466,73 @@ void ED_mask_draw(const bContext *C, draw_masklays(mask, draw_flag, draw_type, width, height); } + +/* sets up the opengl context. + * width, height are to match the values from ED_mask_size() */ +void ED_mask_draw_region(Mask *mask, ARegion *ar, + const char draw_flag, const char draw_type, + int width, int height, + const short do_scale_applied, const short do_post_draw, + float stabmat[4][4], /* optional - only used by clip */ + const bContext *C /* optional - only used when do_post_draw is set */ + ) +{ + struct View2D *v2d = &ar->v2d; + + int x, y; + int w, h; + float zoomx, zoomy; + + /* frame image */ + float maxdim; + float xofs, yofs; + + /* find window pixel coordinates of origin */ + UI_view2d_to_region_no_clip(&ar->v2d, 0.0f, 0.0f, &x, &y); + + w = v2d->tot.xmax - v2d->tot.xmin; + h = v2d->tot.ymax - v2d->tot.ymin; + + zoomx = (float)(ar->winrct.xmax - ar->winrct.xmin + 1) / (float)((ar->v2d.cur.xmax - ar->v2d.cur.xmin)); + zoomy = (float)(ar->winrct.ymax - ar->winrct.ymin + 1) / (float)((ar->v2d.cur.ymax - ar->v2d.cur.ymin)); + + if (do_scale_applied) { + zoomx /= width; + zoomy /= height; + } + + x += v2d->tot.xmin * zoomx; + y += v2d->tot.ymin * zoomy; + + /* frame the image */ + maxdim = maxf(w, h); + if (w == h) { + xofs = yofs = 0; + } + else if (w < h) { + xofs = ((h - w) / -2.0f) * zoomx; + yofs = 0.0f; + } + else { /* (width > height) */ + xofs = 0.0f; + yofs = ((w - h) / -2.0f) * zoomy; + } + + /* apply transformation so mask editing tools will assume drawing from the origin in normalized space */ + glPushMatrix(); + glTranslatef(x + xofs, y + yofs, 0); + glScalef(maxdim * zoomx, maxdim * zoomy, 0); + + if (stabmat) { + glMultMatrixf(stabmat); + } + + /* draw! */ + draw_masklays(mask, draw_flag, draw_type, width, height); + + if (do_post_draw) { + ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW); + } + + glPopMatrix(); +} diff --git a/source/blender/editors/mask/mask_edit.c b/source/blender/editors/mask/mask_edit.c index 3ba198b60be..a739d88dbd4 100644 --- a/source/blender/editors/mask/mask_edit.c +++ b/source/blender/editors/mask/mask_edit.c @@ -42,6 +42,7 @@ #include "ED_screen.h" #include "ED_mask.h" /* own include */ +#include "ED_image.h" #include "ED_object.h" /* ED_keymap_proportional_maskmode only */ #include "ED_clip.h" #include "ED_sequencer.h" @@ -143,15 +144,25 @@ void ED_mask_size(const bContext *C, int *width, int *height) { ScrArea *sa = CTX_wm_area(C); if (sa && sa->spacedata.first) { - if (sa->spacetype == SPACE_CLIP) { - ED_space_clip_get_size(C, width, height); - return; - } - else if (sa->spacetype == SPACE_SEQ) { - Scene *scene = CTX_data_scene(C); - *width = (scene->r.size * scene->r.xsch) / 100; - *height = (scene->r.size * scene->r.ysch) / 100; - return; + switch (sa->spacetype) { + case SPACE_CLIP: + { + ED_space_clip_get_size(C, width, height); + return; + } + 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; + return; + } + case SPACE_IMAGE: + { + SpaceImage *sima = sa->spacedata.first; + ED_space_image_size(sima, width, height); + return; + } } } diff --git a/source/blender/editors/mask/mask_intern.h b/source/blender/editors/mask/mask_intern.h index bad0a9c28a8..70dafc963ec 100644 --- a/source/blender/editors/mask/mask_intern.h +++ b/source/blender/editors/mask/mask_intern.h @@ -99,9 +99,6 @@ void ED_mask_select_flush_all(struct Mask *mask); int ED_maskedit_poll(struct bContext *C); int ED_maskedit_mask_poll(struct bContext *C); -void ED_mask_size(const struct bContext *C, int *width, int *height); -void ED_mask_aspect(const struct bContext *C, float *aspx, float *aspy); - void ED_mask_pixelspace_factor(const struct bContext *C, float *scalex, float *scaley); void ED_mask_mouse_pos(const struct bContext *C, struct wmEvent *event, float co[2]); |