View All operator for motion tracking dopesheet.
authorSergey Sharybin <sergey.vfx@gmail.com>
Tue, 5 Mar 2013 12:41:17 +0000 (12:41 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Tue, 5 Mar 2013 12:41:17 +0000 (12:41 +0000)
source/blender/editors/space_clip/clip_dopesheet_ops.c
source/blender/editors/space_clip/clip_intern.h
source/blender/editors/space_clip/space_clip.c

index 09f6271..d914cd2 100644 (file)
 
 #include "clip_intern.h"       // own include
 
-#if 0
-static int ED_space_clip_dopesheet_poll(bContext *C)
+static int space_clip_dopesheet_poll(bContext *C)
 {
-       SpaceClip *sc = CTX_wm_space_clip(C);
+       if (ED_space_clip_tracking_poll(C)) {
+               SpaceClip *sc = CTX_wm_space_clip(C);
 
-       if (sc && sc->clip) {
                if (sc->view == SC_VIEW_DOPESHEET) {
                        ARegion *ar = CTX_wm_region(C);
 
@@ -74,7 +73,6 @@ static int ED_space_clip_dopesheet_poll(bContext *C)
 
        return FALSE;
 }
-#endif
 
 /********************** select channel operator *********************/
 
@@ -161,3 +159,54 @@ void CLIP_OT_dopesheet_select_channel(wmOperatorType *ot)
        RNA_def_boolean(ot->srna, "extend", 0,
                        "Extend", "Extend selection rather than clearing the existing selection");
 }
+
+/********************** View All operator *********************/
+
+static int dopesheet_view_all_exec(bContext *C, wmOperator *UNUSED(op))
+{
+       SpaceClip *sc = CTX_wm_space_clip(C);
+       ARegion *ar = CTX_wm_region(C);
+       View2D *v2d = &ar->v2d;
+       MovieClip *clip = ED_space_clip_get_clip(sc);
+       MovieTracking *tracking = &clip->tracking;
+       MovieTrackingDopesheet *dopesheet = &tracking->dopesheet;
+       MovieTrackingDopesheetChannel *channel;
+       int frame_min = INT_MAX, frame_max = INT_MIN;
+
+       for (channel = dopesheet->channels.first; channel; channel = channel->next) {
+               frame_min = min_ii(frame_min, channel->segments[0]);
+               frame_max = max_ii(frame_max, channel->segments[channel->tot_segment]);
+       }
+
+       if (frame_min < frame_max) {
+               float extra;
+
+               v2d->cur.xmin = frame_min;
+               v2d->cur.xmax = frame_max;
+
+               /* we need an extra "buffer" factor on either side so that the endpoints are visible */
+               extra = 0.01f * BLI_rctf_size_x(&v2d->cur);
+               v2d->cur.xmin -= extra;
+               v2d->cur.xmax += extra;
+
+               ED_region_tag_redraw(ar);
+       }
+
+
+       return OPERATOR_FINISHED;
+}
+
+void CLIP_OT_dopesheet_view_all(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name = "View All";
+       ot->description = "Reset viewable area to show full keyframe range";
+       ot->idname = "CLIP_OT_dopesheet_view_all";
+
+       /* api callbacks */
+       ot->exec = dopesheet_view_all_exec;
+       ot->poll = space_clip_dopesheet_poll;
+
+       /* flags */
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
index 432032e..9d5e2e9 100644 (file)
@@ -67,6 +67,7 @@ void clip_draw_dopesheet_channels(const struct bContext *C, struct ARegion *ar);
 
 /* clip_dopesheet_ops.c */
 void CLIP_OT_dopesheet_select_channel(struct wmOperatorType *ot);
+void CLIP_OT_dopesheet_view_all(struct wmOperatorType *ot);
 
 /* clip_draw.c */
 void clip_draw_main(const struct bContext *C, struct SpaceClip *sc, struct ARegion *ar);
index f0c0e7b..cec220a 100644 (file)
@@ -534,6 +534,7 @@ static void clip_operatortypes(void)
        /* ** clip_dopesheet_ops.c  ** */
 
        WM_operatortype_append(CLIP_OT_dopesheet_select_channel);
+       WM_operatortype_append(CLIP_OT_dopesheet_view_all);
 }
 
 static void clip_keymap(struct wmKeyConfig *keyconf)
@@ -768,6 +769,8 @@ static void clip_keymap(struct wmKeyConfig *keyconf)
 
        kmi = WM_keymap_add_item(keymap, "CLIP_OT_dopesheet_select_channel", ACTIONMOUSE, KM_PRESS, 0, 0);
        RNA_boolean_set(kmi->ptr, "extend", TRUE);  /* toggle */
+
+       WM_keymap_add_item(keymap, "CLIP_OT_dopesheet_view_all", HOMEKEY, KM_PRESS, 0, 0);
 }
 
 const char *clip_context_dir[] = {"edit_movieclip", "edit_mask", NULL};
@@ -1191,6 +1194,9 @@ static void clip_preview_area_init(wmWindowManager *wm, ARegion *ar)
 
        keymap = WM_keymap_find(wm->defaultconf, "Clip Graph Editor", SPACE_CLIP, 0);
        WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+
+       keymap = WM_keymap_find(wm->defaultconf, "Clip Dopesheet Editor", SPACE_CLIP, 0);
+       WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
 }
 
 static void graph_area_draw(const bContext *C, ARegion *ar)