diff --git a/source/blender/editors/space_clip/clip_draw.c b/source/blender/editors/space_clip/clip_draw.c index 44623f97530..b6ba399d10a 100644 --- a/source/blender/editors/space_clip/clip_draw.c +++ b/source/blender/editors/space_clip/clip_draw.c @@ -73,9 +73,11 @@ static void draw_movieclip_cache(SpaceClip *sc, ARegion *ar, MovieClip *clip, Sc { float x; int *points, totseg, sel_type, i, a; - float sfra= SFRA, efra= EFRA; + float sfra= SFRA, efra= EFRA, framelen= ar->winx/(efra-sfra+1), fontsize, fontwidth; void *sel; - float framelen= ar->winx/(efra-sfra+1); + uiStyle *style= U.uistyles.first; + int fontid= style->widget.uifont_id; + char str[32]; BKE_movieclip_last_selection(clip, &sel_type, &sel); @@ -166,6 +168,26 @@ static void draw_movieclip_cache(SpaceClip *sc, ARegion *ar, MovieClip *clip, Sc UI_ThemeColor(TH_CFRAME); glRecti(x, 0, x+framelen, 8); + + /* frame number */ + BLF_size(fontid, 11.f, U.dpi); + BLI_snprintf(str, sizeof(str), "%d", sc->user.framenr); + fontsize= BLF_height(fontid, str); + fontwidth= BLF_width(fontid, str); + + if(x+fontwidth+6.f<=ar->winx) { + glRecti(x, 8.f, x+fontwidth+6.f, 12.f+fontsize); + + glColor3f(0.f, 0.f, 0.f); + BLF_position(fontid, x+2.f, 10.f, 0.f); + BLF_draw(fontid, str, strlen(str)); + } else { + glRecti(x+framelen, 8.f, x+framelen-fontwidth-6.f, 12.f+fontsize); + + glColor3f(0.f, 0.f, 0.f); + BLF_position(fontid, x-2.f-fontwidth+framelen, 10.f, 0.f); + BLF_draw(fontid, str, strlen(str)); + } } static void draw_movieclip_buffer(SpaceClip *sc, ARegion *ar, ImBuf *ibuf, float zoomx, float zoomy) diff --git a/source/blender/editors/space_clip/clip_intern.h b/source/blender/editors/space_clip/clip_intern.h index 291850eff4b..41dcd637bfa 100644 --- a/source/blender/editors/space_clip/clip_intern.h +++ b/source/blender/editors/space_clip/clip_intern.h @@ -54,6 +54,7 @@ void CLIP_OT_view_zoom_out(struct wmOperatorType *ot); void CLIP_OT_view_zoom_ratio(struct wmOperatorType *ot); void CLIP_OT_view_all(struct wmOperatorType *ot); void CLIP_OT_view_selected(struct wmOperatorType *ot); +void CLIP_OT_change_frame(wmOperatorType *ot); /* tracking_ops.c */ void CLIP_OT_select(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_clip/clip_ops.c b/source/blender/editors/space_clip/clip_ops.c index d9f90432ca4..bd931020794 100644 --- a/source/blender/editors/space_clip/clip_ops.c +++ b/source/blender/editors/space_clip/clip_ops.c @@ -32,15 +32,18 @@ #include "MEM_guardedalloc.h" #include "DNA_userdef_types.h" +#include "DNA_scene_types.h" /* min/max frames */ #include "BLI_utildefines.h" #include "BLI_math.h" #include "BKE_context.h" +#include "BKE_global.h" #include "BKE_report.h" #include "BKE_main.h" #include "BKE_library.h" #include "BKE_movieclip.h" +#include "BKE_sound.h" #include "WM_api.h" #include "WM_types.h" @@ -730,6 +733,104 @@ void CLIP_OT_view_selected(wmOperatorType *ot) ot->poll= ED_space_clip_poll; } +/********************** change frame operator *********************/ + +static int change_frame_poll(bContext *C) +{ + /* prevent changes during render */ + if(G.rendering) + return 0; + + return ED_space_clip_poll(C); +} + +static void change_frame_apply(bContext *C, wmOperator *op) +{ + Scene *scene= CTX_data_scene(C); + + /* set the new frame number */ + CFRA= RNA_int_get(op->ptr, "frame"); + FRAMENUMBER_MIN_CLAMP(CFRA); + SUBFRA = 0.f; + + /* do updates */ + sound_seek_scene(C); + WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene); +} + +static int change_frame_exec(bContext *C, wmOperator *op) +{ + change_frame_apply(C, op); + + return OPERATOR_FINISHED; +} + +static int frame_from_event(bContext *C, wmEvent *event) +{ + ARegion *ar= CTX_wm_region(C); + Scene *scene= CTX_data_scene(C); + + float sfra= SFRA, efra= EFRA, framelen= ar->winx/(efra-sfra+1); + + return sfra+event->mval[0]/framelen; +} + +static int change_frame_invoke(bContext *C, wmOperator *op, wmEvent *event) +{ + if(event->mval[1]>16) + return OPERATOR_PASS_THROUGH; + + RNA_int_set(op->ptr, "frame", frame_from_event(C, event)); + + change_frame_apply(C, op); + + /* add temp handler */ + WM_event_add_modal_handler(C, op); + + return OPERATOR_RUNNING_MODAL; +} + +static int change_frame_modal(bContext *C, wmOperator *op, wmEvent *event) +{ + switch (event->type) { + case ESCKEY: + return OPERATOR_FINISHED; + + case MOUSEMOVE: + RNA_int_set(op->ptr, "frame", frame_from_event(C, event)); + change_frame_apply(C, op); + break; + + case LEFTMOUSE: + case RIGHTMOUSE: + if (event->val==KM_RELEASE) + return OPERATOR_FINISHED; + break; + } + + return OPERATOR_RUNNING_MODAL; +} + +void CLIP_OT_change_frame(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Change frame"; + ot->idname= "CLIP_OT_change_frame"; + ot->description= "Interactively change the current frame number"; + + /* api callbacks */ + ot->exec= change_frame_exec; + ot->invoke= change_frame_invoke; + ot->modal= change_frame_modal; + ot->poll= change_frame_poll; + + /* flags */ + ot->flag= OPTYPE_BLOCKING|OPTYPE_UNDO; + + /* rna */ + RNA_def_int(ot->srna, "frame", 0, MINAFRAME, MAXFRAME, "Frame", "", MINAFRAME, MAXFRAME); +} + /********************** macroses *********************/ void ED_operatormacros_clip(void) diff --git a/source/blender/editors/space_clip/space_clip.c b/source/blender/editors/space_clip/space_clip.c index 412155443f4..97047bc4a0f 100644 --- a/source/blender/editors/space_clip/space_clip.c +++ b/source/blender/editors/space_clip/space_clip.c @@ -249,6 +249,7 @@ static void clip_operatortypes(void) WM_operatortype_append(CLIP_OT_view_zoom_ratio); WM_operatortype_append(CLIP_OT_view_all); WM_operatortype_append(CLIP_OT_view_selected); + WM_operatortype_append(CLIP_OT_change_frame); WM_operatortype_append(CLIP_OT_select); WM_operatortype_append(CLIP_OT_select_all); @@ -406,6 +407,8 @@ static void clip_keymap(struct wmKeyConfig *keyconf) kmi= WM_keymap_add_item(keymap, "WM_OT_context_toggle", MKEY, KM_PRESS, 0, 0); RNA_string_set(kmi->ptr, "data_path", "space_data.use_mute_footage"); + WM_keymap_add_item(keymap, "CLIP_OT_change_frame", LEFTMOUSE, KM_PRESS, 0, 0); + transform_keymap_for_space(keyconf, keymap, SPACE_CLIP); } diff --git a/source/blender/editors/space_clip/tracking_ops.c b/source/blender/editors/space_clip/tracking_ops.c index 06ac92706cf..a185e0776c5 100644 --- a/source/blender/editors/space_clip/tracking_ops.c +++ b/source/blender/editors/space_clip/tracking_ops.c @@ -485,7 +485,7 @@ static int slide_marker_invoke(bContext *C, wmOperator *op, wmEvent *event) return OPERATOR_RUNNING_MODAL; } - return OPERATOR_CANCELLED; + return OPERATOR_PASS_THROUGH; } static void cancel_mouse_slide(SlideMarkerData *data)