From 1cb7dc55b40ab5270502ac76ed81887bc227ae02 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 17 Jun 2010 14:22:54 +0000 Subject: sequencer numpad keys for zoom levels --- source/blender/blenlib/BLI_rect.h | 2 ++ source/blender/blenlib/intern/path_util.c | 2 +- source/blender/blenlib/intern/rct.c | 21 ++++++++++++ .../editors/space_sequencer/sequencer_edit.c | 37 ++++++++++++++++++++++ .../editors/space_sequencer/sequencer_intern.h | 1 + .../editors/space_sequencer/sequencer_ops.c | 13 ++++++++ 6 files changed, 75 insertions(+), 1 deletion(-) diff --git a/source/blender/blenlib/BLI_rect.h b/source/blender/blenlib/BLI_rect.h index 52f645705cc..0b886c17309 100644 --- a/source/blender/blenlib/BLI_rect.h +++ b/source/blender/blenlib/BLI_rect.h @@ -52,6 +52,8 @@ void BLI_init_rctf(struct rctf *rect, float xmin, float xmax, float ymin, float void BLI_init_rcti(struct rcti *rect, int xmin, int xmax, int ymin, int ymax); void BLI_translate_rctf(struct rctf *rect, float x, float y); void BLI_translate_rcti(struct rcti *rect, int x, int y); +void BLI_resize_rcti(struct rcti *rect, int x, int y); +void BLI_resize_rctf(struct rctf *rect, float x, float y); int BLI_in_rcti(struct rcti *rect, int x, int y); int BLI_in_rctf(struct rctf *rect, float x, float y); int BLI_isect_rctf(struct rctf *src1, struct rctf *src2, struct rctf *dest); diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index f9acf7ba148..045ac5a013f 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -703,7 +703,7 @@ int BLI_path_cwd(char *path) } -/* copy di to fi, filename only */ +/* 'di's filename component is moved into 'fi', di is made a dir path */ void BLI_splitdirstring(char *di, char *fi) { char *lslash= BLI_last_slash(di); diff --git a/source/blender/blenlib/intern/rct.c b/source/blender/blenlib/intern/rct.c index 7fce9ac7e8d..5466acdba9f 100644 --- a/source/blender/blenlib/intern/rct.c +++ b/source/blender/blenlib/intern/rct.c @@ -142,6 +142,27 @@ void BLI_translate_rctf(rctf *rect, float x, float y) rect->ymax += y; } +/* change width & height around the central location */ +void BLI_resize_rcti(rcti *rect, int x, int y) +{ + rect->xmin= rect->xmax= (rect->xmax + rect->xmin) / 2; + rect->ymin= rect->ymax= (rect->ymax + rect->ymin) / 2; + rect->xmin -= x / 2; + rect->ymin -= y / 2; + rect->xmax= rect->xmin + x; + rect->ymax= rect->ymin + y; +} + +void BLI_resize_rctf(rctf *rect, float x, float y) +{ + rect->xmin= rect->xmax= (rect->xmax + rect->xmin) * 0.5f; + rect->ymin= rect->ymax= (rect->ymax + rect->ymin) * 0.5f; + rect->xmin -= x * 0.5f; + rect->ymin -= y * 0.5f; + rect->xmax= rect->xmin + x; + rect->ymax= rect->ymin + y; +} + int BLI_isect_rctf(rctf *src1, rctf *src2, rctf *dest) { float xmin, xmax; diff --git a/source/blender/editors/space_sequencer/sequencer_edit.c b/source/blender/editors/space_sequencer/sequencer_edit.c index 9deb0ba4a0a..dedde7e10c3 100644 --- a/source/blender/editors/space_sequencer/sequencer_edit.c +++ b/source/blender/editors/space_sequencer/sequencer_edit.c @@ -2218,6 +2218,43 @@ void SEQUENCER_OT_view_all_preview(wmOperatorType *ot) ot->flag= OPTYPE_REGISTER; } + +static int sequencer_view_zoom_ratio_exec(bContext *C, wmOperator *op) +{ + RenderData *r= &CTX_data_scene(C)->r; + View2D *v2d= UI_view2d_fromcontext(C); + + float ratio= RNA_float_get(op->ptr, "ratio"); + + float winx= (int)(r->size * r->xsch)/100; + float winy= (int)(r->size * r->ysch)/100; + + float facx= (v2d->mask.xmax - v2d->mask.xmin) / winx; + float facy= (v2d->mask.ymax - v2d->mask.ymin) / winy; + + BLI_resize_rctf(&v2d->cur, winx*facx*ratio, winy*facy*ratio); + + ED_region_tag_redraw(CTX_wm_region(C)); + + return OPERATOR_FINISHED; +} + +void SEQUENCER_OT_view_zoom_ratio(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Sequencer View Zoom Ratio"; + ot->idname= "SEQUENCER_OT_view_zoom_ratio"; + + /* api callbacks */ + ot->exec= sequencer_view_zoom_ratio_exec; + ot->poll= ED_operator_sequencer_active; + + /* properties */ + RNA_def_float(ot->srna, "ratio", 1.0f, 0.0f, FLT_MAX, + "Ratio", "Zoom ratio, 1.0 is 1:1, higher is zoomed in, lower is zoomed out.", -FLT_MAX, FLT_MAX); +} + + #if 0 static EnumPropertyItem view_type_items[] = { {SEQ_VIEW_SEQUENCE, "SEQUENCER", ICON_SEQ_SEQUENCER, "Sequencer", ""}, diff --git a/source/blender/editors/space_sequencer/sequencer_intern.h b/source/blender/editors/space_sequencer/sequencer_intern.h index dc2d89293ee..fd4ee70e258 100644 --- a/source/blender/editors/space_sequencer/sequencer_intern.h +++ b/source/blender/editors/space_sequencer/sequencer_intern.h @@ -100,6 +100,7 @@ void SEQUENCER_OT_rendersize(struct wmOperatorType *ot); void SEQUENCER_OT_view_toggle(struct wmOperatorType *ot); void SEQUENCER_OT_view_all(struct wmOperatorType *ot); void SEQUENCER_OT_view_selected(struct wmOperatorType *ot); +void SEQUENCER_OT_view_zoom_ratio(struct wmOperatorType *ot); void SEQUENCER_OT_copy(struct wmOperatorType *ot); void SEQUENCER_OT_paste(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_sequencer/sequencer_ops.c b/source/blender/editors/space_sequencer/sequencer_ops.c index f1ca2490095..559a090a2ee 100644 --- a/source/blender/editors/space_sequencer/sequencer_ops.c +++ b/source/blender/editors/space_sequencer/sequencer_ops.c @@ -79,6 +79,7 @@ void sequencer_operatortypes(void) WM_operatortype_append(SEQUENCER_OT_view_selected); WM_operatortype_append(SEQUENCER_OT_view_all_preview); WM_operatortype_append(SEQUENCER_OT_view_toggle); + WM_operatortype_append(SEQUENCER_OT_view_zoom_ratio); /* sequencer_select.c */ WM_operatortype_append(SEQUENCER_OT_select_all_toggle); @@ -224,5 +225,17 @@ void sequencer_keymap(wmKeyConfig *keyconf) keymap= WM_keymap_find(keyconf, "SequencerPreview", SPACE_SEQ, 0); WM_keymap_add_item(keymap, "SEQUENCER_OT_view_all_preview", HOMEKEY, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "SEQUENCER_OT_properties", NKEY, KM_PRESS, 0, 0); + + + keymap= WM_keymap_find(keyconf, "SequencerPreview", SPACE_SEQ, 0); + + /* would prefer to use numpad keys for job */ + RNA_float_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_view_zoom_ratio", PAD8, KM_PRESS, KM_SHIFT, 0)->ptr, "ratio", 8.0f); + RNA_float_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_view_zoom_ratio", PAD4, KM_PRESS, KM_SHIFT, 0)->ptr, "ratio", 4.0f); + RNA_float_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_view_zoom_ratio", PAD2, KM_PRESS, KM_SHIFT, 0)->ptr, "ratio", 2.0f); + RNA_float_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_view_zoom_ratio", PAD1, KM_PRESS, 0, 0)->ptr, "ratio", 1.0f); + RNA_float_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_view_zoom_ratio", PAD2, KM_PRESS, 0, 0)->ptr, "ratio", 0.5f); + RNA_float_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_view_zoom_ratio", PAD4, KM_PRESS, 0, 0)->ptr, "ratio", 0.25f); + RNA_float_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_view_zoom_ratio", PAD8, KM_PRESS, 0, 0)->ptr, "ratio", 0.125f); } -- cgit v1.2.3