generalize mask poll functions and sequencer mask code.
authorCampbell Barton <ideasman42@gmail.com>
Tue, 24 Jul 2012 09:53:29 +0000 (09:53 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 24 Jul 2012 09:53:29 +0000 (09:53 +0000)
source/blender/blenkernel/BKE_sequencer.h
source/blender/blenkernel/intern/sequencer.c
source/blender/editors/include/ED_sequencer.h
source/blender/editors/mask/mask_draw.c
source/blender/editors/mask/mask_edit.c
source/blender/editors/space_clip/space_clip.c
source/blender/editors/space_sequencer/sequencer_draw.c
source/blender/editors/space_sequencer/sequencer_edit.c
source/blender/editors/space_sequencer/space_sequencer.c

index d6c1a26fdbab316df03d8cbb5a11730720adeed3..a8890d5a37e520d4a8234b6b3f8de8812c46fd61 100644 (file)
@@ -182,7 +182,7 @@ struct Sequence *BKE_sequencer_active_get(struct Scene *scene);
 int              BKE_sequencer_active_get_pair(struct Scene *scene,
                                                struct Sequence **seq_act, struct Sequence **seq_other);
 void             BKE_sequencer_active_set(struct Scene *scene, struct Sequence *seq);
-
+struct Mask      *BKE_sequencer_mask_get(struct Scene *scene);
 
 /* apply functions recursively */
 int seqbase_recursive_apply(struct ListBase *seqbase, int (*apply_func)(struct Sequence *seq, void *), void *arg);
index b7f72ff86e227efe19cb13b4bd6d166abd37e984..f0907d20ce20d4e26679f35c4a9a8c1af2d68139 100644 (file)
@@ -3810,6 +3810,18 @@ int BKE_sequencer_active_get_pair(Scene *scene, Sequence **seq_act, Sequence **s
        }
 }
 
+Mask *BKE_sequencer_mask_get(Scene *scene)
+{
+       Sequence *seq_act = BKE_sequencer_active_get(scene);
+
+       if (seq_act && seq_act->type == SEQ_TYPE_MASK) {
+               return seq_act->mask;
+       }
+       else {
+               return NULL;
+       }
+}
+
 /* api like funcs for adding */
 
 void seq_load_apply(Scene *scene, Sequence *seq, SeqLoadInfo *seq_load)
index 7ba26f30c39e5bb011bf12b63612baba7a8ea167..7807f06594e20aa786f5fac4b20fc27079853723 100644 (file)
 
 struct Scene;
 struct Sequence;
+struct SpaceSeq;
 
 void ED_sequencer_select_sequence_single(struct Scene *scene, struct Sequence *seq, int deselect_all);
 void ED_sequencer_deselect_all(struct Scene *scene);
 
+int ED_space_sequencer_maskedit_mask_poll(struct bContext *C);
+int ED_space_sequencer_check_show_maskedit(struct SpaceSeq *sseq, struct Scene *scene);
+int ED_space_sequencer_maskedit_poll(bContext *C);
+
 void ED_operatormacros_sequencer(void);
 
 #endif /*  __ED_SEQUENCER_H__ */
index f378d5452a446a337140c2a2086f299e5a9197bd..8503c538a8db937ce3fbf8c546e97956cb204860 100644 (file)
@@ -129,7 +129,8 @@ static void draw_spline_points(MaskLayer *masklay, MaskSpline *spline,
        if (!spline->tot_point)
                return;
 
-       hsize = UI_GetThemeValuef(TH_HANDLE_VERTEX_SIZE);
+       /* TODO, add this to sequence editor */
+       hsize = 4; /* UI_GetThemeValuef(TH_HANDLE_VERTEX_SIZE); */
 
        glPointSize(hsize);
 
index b9522540e676acf533864d1f5a828e77f852bb5d..3ba198b60be3a8565ec0e2b6a403c38f66898d4c 100644 (file)
@@ -44,6 +44,7 @@
 #include "ED_mask.h"  /* own include */
 #include "ED_object.h" /* ED_keymap_proportional_maskmode only */
 #include "ED_clip.h"
+#include "ED_sequencer.h"
 #include "ED_transform.h"
 
 #include "RNA_access.h"
 
 int ED_maskedit_poll(bContext *C)
 {
-       SpaceClip *sc = CTX_wm_space_clip(C);
-
-       if (sc) {
-               return ED_space_clip_maskedit_poll(C);
+       ScrArea *sa = CTX_wm_area(C);
+       if (sa) {
+               switch (sa->spacetype) {
+                       case SPACE_CLIP:
+                               return ED_space_clip_maskedit_poll(C);
+                       case SPACE_SEQ:
+                               return ED_space_sequencer_maskedit_poll(C);
+               }
        }
-
        return FALSE;
 }
 
 int ED_maskedit_mask_poll(bContext *C)
 {
-       SpaceClip *sc = CTX_wm_space_clip(C);
-
-       if (sc) {
-               return ED_space_clip_maskedit_mask_poll(C);
+       ScrArea *sa = CTX_wm_area(C);
+       if (sa) {
+               switch (sa->spacetype) {
+                       case SPACE_CLIP:
+                               return ED_space_clip_maskedit_mask_poll(C);
+                       case SPACE_SEQ:
+                               return ED_space_sequencer_maskedit_mask_poll(C);
+               }
        }
-
        return FALSE;
 }
 
index 3623cd1d58b09c939cfe0946bb44721bcbe17222..af96644a25493e77488d4b865be2392462db792e 100644 (file)
@@ -1066,10 +1066,10 @@ static void clip_main_area_init(wmWindowManager *wm, ARegion *ar)
 
        UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_STANDARD, ar->winx, ar->winy);
 
-       /* own keymap */
        keymap = WM_keymap_find(wm->defaultconf, "Mask Editing", 0, 0);
        WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
 
+       /* own keymap */
        keymap = WM_keymap_find(wm->defaultconf, "Clip", SPACE_CLIP, 0);
        WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
 
index 38f29e8816ec6ab74869e6f8519a598751193d98..09bfa384db0690979ec2177141147a683805725a 100644 (file)
@@ -798,6 +798,61 @@ static void UNUSED_FUNCTION(set_special_seq_update) (int val)
        else special_seq_update = NULL;
 }
 
+static void sequencer_main_area_draw_mask(const bContext *C, Scene *scene, ARegion *ar)
+{
+       Mask *mask = BKE_sequencer_mask_get(scene);
+
+       if (mask) {
+               struct View2D *v2d = &ar->v2d;
+
+               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();
+       }
+}
+
+
 void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq, int cfra, int frame_ofs)
 {
        struct Main *bmain = CTX_data_main(C);
@@ -992,54 +1047,7 @@ void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq
 
        //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();
-               }
+               sequencer_main_area_draw_mask(C, scene, ar);
        }
 
 }
index 82e2730c59e5f6e22714f482123c660c517ce1a2..92c0f785ccb28185de50d943d307149b76453581 100644 (file)
@@ -466,6 +466,33 @@ void recurs_sel_seq(Sequence *seqm)
        }
 }
 
+int ED_space_sequencer_maskedit_mask_poll(bContext *C)
+{
+       /* in this case both funcs are the same, for clip editor not */
+       return ED_space_sequencer_maskedit_poll(C);
+}
+
+int ED_space_sequencer_check_show_maskedit(SpaceSeq *sseq, Scene *scene)
+{
+       if (sseq && sseq->mainb == SEQ_DRAW_IMG_IMBUF) {
+               return (BKE_sequencer_mask_get(scene) != NULL);
+       }
+
+       return FALSE;
+}
+
+int ED_space_sequencer_maskedit_poll(bContext *C)
+{
+       SpaceSeq *sseq = CTX_wm_space_seq(C);
+
+       if (sseq) {
+               Scene *scene = CTX_data_scene(C);
+               return ED_space_sequencer_check_show_maskedit(sseq, scene);
+       }
+
+       return FALSE;
+}
+
 int seq_effect_find_selected(Scene *scene, Sequence *activeseq, int type, Sequence **selseq1, Sequence **selseq2, Sequence **selseq3, const char **error_str)
 {
        Editing *ed = BKE_sequencer_editing_get(scene, FALSE);
index cabc761161e74a1097ad80bcb1ad1dc26a8c46e6..34ca26a317632c3bb3f55606df0964e1058b21a5 100644 (file)
@@ -300,7 +300,10 @@ static void sequencer_main_area_init(wmWindowManager *wm, ARegion *ar)
        ListBase *lb;
        
        UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
-       
+
+//     keymap = WM_keymap_find(wm->defaultconf, "Mask Editing", 0, 0);
+//     WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+
        keymap = WM_keymap_find(wm->defaultconf, "SequencerCommon", SPACE_SEQ, 0);
        WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
        
@@ -409,9 +412,9 @@ static int sequencer_context(const bContext *C, const char *member, bContextData
                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);
+               Mask *mask = BKE_sequencer_mask_get(scene);
+               if (mask) {
+                       CTX_data_id_pointer_set(result, &mask->id);
                }
                return TRUE;
        }
@@ -468,6 +471,9 @@ static void sequencer_preview_area_init(wmWindowManager *wm, ARegion *ar)
 
        UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
        
+//     keymap = WM_keymap_find(wm->defaultconf, "Mask Editing", 0, 0);
+//     WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+
        keymap = WM_keymap_find(wm->defaultconf, "SequencerCommon", SPACE_SEQ, 0);
        WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);