From 36db2a2cff58d3bd3dd0f7e8e0d2fbec36e32412 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 7 Jun 2012 19:24:49 +0000 Subject: initial support for editing masks in the sequencer, currently only draw the mask. --- source/blender/editors/mask/mask_edit.c | 28 +++++++---- .../editors/space_sequencer/sequencer_draw.c | 55 ++++++++++++++++++++++ .../editors/space_sequencer/space_sequencer.c | 26 +++++++++- 3 files changed, 99 insertions(+), 10 deletions(-) (limited to 'source') diff --git a/source/blender/editors/mask/mask_edit.c b/source/blender/editors/mask/mask_edit.c index 9bfcd2a9886..6a59279934e 100644 --- a/source/blender/editors/mask/mask_edit.c +++ b/source/blender/editors/mask/mask_edit.c @@ -35,6 +35,8 @@ #include "BKE_context.h" #include "BKE_mask.h" +#include "DNA_scene_types.h" + #include "WM_api.h" #include "WM_types.h" @@ -132,16 +134,24 @@ void ED_mask_point_pos__reverse(bContext *C, float x, float y, float *xr, float void ED_mask_size(bContext *C, int *width, int *height) { - SpaceClip *sc = CTX_wm_space_clip(C); - - if (sc) { - ED_space_clip_mask_size(sc, width, height); - } - else { - /* possible other spaces from which mask editing is available */ - *width = 0; - *height = 0; + ScrArea *sa = CTX_wm_area(C); + if (sa && sa->spacedata.first) { + if (sa->spacetype == SPACE_CLIP) { + SpaceClip *sc = sa->spacedata.first; + ED_space_clip_mask_size(sc, 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; + } } + + /* possible other spaces from which mask editing is available */ + *width = 0; + *height = 0; } void ED_mask_aspect(bContext *C, float *aspx, float *aspy) diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c index eb943451b1f..b674943b2dc 100644 --- a/source/blender/editors/space_sequencer/sequencer_draw.c +++ b/source/blender/editors/space_sequencer/sequencer_draw.c @@ -59,7 +59,9 @@ #include "ED_anim_api.h" #include "ED_markers.h" +#include "ED_mask.h" #include "ED_types.h" +#include "ED_space_api.h" #include "UI_interface.h" #include "UI_resources.h" @@ -984,6 +986,59 @@ void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq /* ortho at pixel level */ UI_view2d_view_restore(C); + + //if (sc->mode == SC_MODE_MASKEDIT) { + if (sseq->mainb == SEQ_DRAW_IMG_IMBUF) { + Sequence *seq_act = BKE_sequencer_active_get(scene); + + if (seq_act && seq_act->type == SEQ_TYPE_MASK && seq_act->mask) { + int x, y; + int width, height; + 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); + + width = v2d->tot.xmax - v2d->tot.xmin; + height = 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)); + + x += v2d->tot.xmin * zoomx; + y += v2d->tot.ymin * zoomy; + + /* frame the image */ + maxdim = maxf(width, height); + if (width == height) { + xofs = yofs = 0; + } + else if (width < height) { + xofs = ((height - width) / -2.0f) * zoomx; + yofs = 0.0f; + } + else { /* (width > height) */ + xofs = 0.0f; + yofs = ((width - height) / -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); + + ED_mask_draw((bContext *)C, 0, 0); // sc->mask_draw_flag, sc->mask_draw_type + + ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW); + + glPopMatrix(); + } + } + } #if 0 diff --git a/source/blender/editors/space_sequencer/space_sequencer.c b/source/blender/editors/space_sequencer/space_sequencer.c index cc59a05b781..3643f92d334 100644 --- a/source/blender/editors/space_sequencer/space_sequencer.c +++ b/source/blender/editors/space_sequencer/space_sequencer.c @@ -33,6 +33,7 @@ #include #include "DNA_scene_types.h" +#include "DNA_mask_types.h" #include "MEM_guardedalloc.h" @@ -380,6 +381,29 @@ static void sequencer_dropboxes(void) /* ************* end drop *********** */ +const char *sequencer_context_dir[] = {"edit_mask", NULL}; + +static int sequencer_context(const bContext *C, const char *member, bContextDataResult *result) +{ + Scene *scene = CTX_data_scene(C); + + if (CTX_data_dir(member)) { + CTX_data_dir_set(result, sequencer_context_dir); + + return TRUE; + } + else if (CTX_data_equals(member, "edit_mask")) { + Sequence *seq_act = BKE_sequencer_active_get(scene); + if (seq_act && seq_act->type == SEQ_TYPE_MASK && seq_act->mask) { + CTX_data_id_pointer_set(result, &seq_act->mask->id); + } + return TRUE; + } + + return FALSE; +} + + /* add handlers, stuff you only do once or on area/region changes */ static void sequencer_header_area_init(wmWindowManager *UNUSED(wm), ARegion *ar) { @@ -545,6 +569,7 @@ void ED_spacetype_sequencer(void) st->duplicate = sequencer_duplicate; st->operatortypes = sequencer_operatortypes; st->keymap = sequencer_keymap; + st->context = sequencer_context; st->dropboxes = sequencer_dropboxes; st->refresh = sequencer_refresh; @@ -597,4 +622,3 @@ void ED_spacetype_sequencer(void) sequencer_view3d_cb = ED_view3d_draw_offscreen_imbuf_simple; } } - -- cgit v1.2.3