initial support for editing masks in the sequencer, currently only draw the mask.
authorCampbell Barton <ideasman42@gmail.com>
Thu, 7 Jun 2012 19:24:49 +0000 (19:24 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 7 Jun 2012 19:24:49 +0000 (19:24 +0000)
source/blender/editors/mask/mask_edit.c
source/blender/editors/space_sequencer/sequencer_draw.c
source/blender/editors/space_sequencer/space_sequencer.c

index 9bfcd2a988679668ed95f1e08003ca0973f703ae..6a59279934e950bf80e7a03d22113c917c4e0de8 100644 (file)
@@ -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)
index eb943451b1fc4acf0c32bac2bd82fc67b3f21dcb..b674943b2dc67128bec1359ef11d1d309cf07733 100644 (file)
@@ -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
index cc59a05b781b64258bcc2291c49c9bcd3c8869e1..3643f92d33407e88b46a4b6ca0614d6142b2e298 100644 (file)
@@ -33,6 +33,7 @@
 #include <stdio.h>
 
 #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;
        }
 }
-