svn merge ^/trunk/blender -r46629:46632
[blender.git] / source / blender / editors / space_clip / space_clip.c
index a6fda200ff4e5de0b7f6be067f9c0021ab7dd1c1..75c60ed5b60f07970973ae9710a07cfe0e413a11 100644 (file)
@@ -33,6 +33,7 @@
 #include <stdio.h>
 
 #include "DNA_scene_types.h"
+#include "DNA_mask_types.h"
 #include "DNA_movieclip_types.h"
 
 #include "MEM_guardedalloc.h"
@@ -49,6 +50,7 @@
 
 #include "IMB_imbuf_types.h"
 
+#include "ED_mask.h"
 #include "ED_screen.h"
 #include "ED_clip.h"
 #include "ED_transform.h"
@@ -361,6 +363,23 @@ static void clip_listener(ScrArea *sa, wmNotifier *wmn)
                                        break;
                        }
                        break;
+               case NC_MASK:
+                       switch(wmn->data) {
+                               case ND_SELECT:
+                               case ND_DATA:
+                                       ED_area_tag_redraw(sa);
+                                       break;
+                       }
+                       switch(wmn->action) {
+                               case NA_SELECTED:
+                                       clip_scopes_tag_refresh(sa);
+                                       ED_area_tag_redraw(sa);
+                                       break;
+                               case NA_EDITED:
+                                       ED_area_tag_redraw(sa);
+                                       break;
+                       }
+                       break;
                case NC_GEOM:
                        switch (wmn->data) {
                                case ND_SELECT:
@@ -422,7 +441,8 @@ static void clip_operatortypes(void)
 
        /* markers */
        WM_operatortype_append(CLIP_OT_add_marker);
-       WM_operatortype_append(CLIP_OT_slide_marker);
+       /* XXX: need porting! */
+       //WM_operatortype_append(CLIP_OT_slide_marker);
        WM_operatortype_append(CLIP_OT_delete_track);
        WM_operatortype_append(CLIP_OT_delete_marker);
 
@@ -601,7 +621,8 @@ static void clip_keymap(struct wmKeyConfig *keyconf)
        WM_keymap_add_item(keymap, "CLIP_OT_delete_marker", DELKEY, KM_PRESS, KM_SHIFT, 0);
        WM_keymap_add_item(keymap, "CLIP_OT_delete_marker", XKEY, KM_PRESS, KM_SHIFT, 0);
 
-       WM_keymap_add_item(keymap, "CLIP_OT_slide_marker", LEFTMOUSE, KM_PRESS, 0, 0);
+       /* XXX: need porting */
+       //WM_keymap_add_item(keymap, "CLIP_OT_slide_marker", LEFTMOUSE, KM_PRESS, 0, 0);
 
        kmi = WM_keymap_add_item(keymap, "CLIP_OT_disable_markers", DKEY, KM_PRESS, KM_SHIFT, 0);
        RNA_enum_set(kmi->ptr, "action", 2);    /* toggle */
@@ -715,7 +736,7 @@ static void clip_keymap(struct wmKeyConfig *keyconf)
        RNA_boolean_set(kmi->ptr, "extend", TRUE);      /* toggle */
 }
 
-const char *clip_context_dir[] = {"edit_movieclip", NULL};
+const char *clip_context_dir[] = {"edit_movieclip", "edit_mask", NULL};
 
 static int clip_context(const bContext *C, const char *member, bContextDataResult *result)
 {
@@ -729,7 +750,11 @@ static int clip_context(const bContext *C, const char *member, bContextDataResul
        else if (CTX_data_equals(member, "edit_movieclip")) {
                if (sc->clip)
                        CTX_data_id_pointer_set(result, &sc->clip->id);
-
+               return TRUE;
+       }
+       else if (CTX_data_equals(member, "edit_mask")) {
+               if (sc->mask)
+                       CTX_data_id_pointer_set(result, &sc->mask->id);
                return TRUE;
        }
 
@@ -1025,6 +1050,9 @@ static void clip_main_area_init(wmWindowManager *wm, ARegion *ar)
 
        keymap = WM_keymap_find(wm->defaultconf, "Clip Editor", SPACE_CLIP, 0);
        WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+
+       keymap= WM_keymap_find(wm->defaultconf, "Mask Editor", 0, 0);
+       WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
 }
 
 static void clip_main_area_draw(const bContext *C, ARegion *ar)
@@ -1067,6 +1095,29 @@ static void clip_main_area_draw(const bContext *C, ARegion *ar)
        /* Grease Pencil */
        clip_draw_grease_pencil((bContext *)C, 1);
 
+       if(sc->mode == SC_MODE_MASKEDITING) {
+               int x, y;
+               int width, height;
+               float zoomx, zoomy, aspx, aspy;
+
+               /* find window pixel coordinates of origin */
+               UI_view2d_to_region_no_clip(&ar->v2d, 0.0f, 0.0f, &x, &y);
+
+               ED_space_clip_size(sc, &width, &height);
+               ED_space_clip_zoom(sc, ar, &zoomx, &zoomy);
+               ED_space_clip_aspect(sc, &aspx, &aspy);
+
+               /* apply transformation so mask editing tools will assume drawing from the origin in normalized space */
+               glPushMatrix();
+               glTranslatef(x, y, 0);
+               glScalef(width*zoomx, height*zoomy, 0);
+               glMultMatrixf(sc->stabmat);
+
+               ED_mask_draw((bContext *)C, width*aspx, height*aspy, zoomx, zoomy);
+
+               glPopMatrix();
+       }
+
        /* reset view matrix */
        UI_view2d_view_restore(C);