Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_sequencer/sequencer_view.c
| /* SPDX-License-Identifier: GPL-2.0-or-later | /* SPDX-License-Identifier: GPL-2.0-or-later | ||||
| * Copyright 2012 Blender Foundation. All rights reserved. */ | * Copyright 2012 Blender Foundation. All rights reserved. */ | ||||
| /** \file | /** \file | ||||
| * \ingroup spseq | * \ingroup spseq | ||||
| */ | */ | ||||
| #include "BLI_blenlib.h" | #include "BLI_blenlib.h" | ||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "DNA_scene_types.h" | #include "DNA_scene_types.h" | ||||
| #include "DNA_video_edit_types.h" | |||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_scene.h" | #include "BKE_scene.h" | ||||
| #include "WM_api.h" | #include "WM_api.h" | ||||
| #include "WM_types.h" | #include "WM_types.h" | ||||
| #include "RNA_define.h" | #include "RNA_define.h" | ||||
| ▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | |||||
| * \{ */ | * \{ */ | ||||
| static int sequencer_view_all_exec(bContext *C, wmOperator *op) | static int sequencer_view_all_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| ARegion *region = CTX_wm_region(C); | ARegion *region = CTX_wm_region(C); | ||||
| rctf box; | rctf box; | ||||
| const int smooth_viewtx = WM_operator_smooth_viewtx_get(op); | const int smooth_viewtx = WM_operator_smooth_viewtx_get(op); | ||||
| Scene *scene = CTX_data_scene(C); | VideoEdit *video_edit = CTX_data_video_edit(C); | ||||
| const Editing *ed = SEQ_editing_get(scene); | |||||
| SEQ_timeline_init_boundbox(scene, &box); | SEQ_timeline_init_boundbox(video_edit, &box); | ||||
| MetaStack *ms = SEQ_meta_stack_active_get(ed); | MetaStack *ms = SEQ_meta_stack_active_get(video_edit); | ||||
| /* Use meta strip range instead of scene. */ | /* Use meta strip range instead of video_edit. */ | ||||
| if (ms != NULL) { | if (ms != NULL) { | ||||
| box.xmin = ms->disp_range[0] - 1; | box.xmin = ms->disp_range[0] - 1; | ||||
| box.xmax = ms->disp_range[1] + 1; | box.xmax = ms->disp_range[1] + 1; | ||||
| } | } | ||||
| SEQ_timeline_expand_boundbox(scene, SEQ_active_seqbase_get(ed), &box); | SEQ_timeline_expand_boundbox(video_edit, SEQ_active_seqbase_get(video_edit), &box); | ||||
| View2D *v2d = ®ion->v2d; | View2D *v2d = ®ion->v2d; | ||||
| rcti scrub_rect; | rcti scrub_rect; | ||||
| ED_time_scrub_region_rect_get(region, &scrub_rect); | ED_time_scrub_region_rect_get(region, &scrub_rect); | ||||
| const float pixel_view_size_y = BLI_rctf_size_y(&v2d->cur) / BLI_rcti_size_y(&v2d->mask); | const float pixel_view_size_y = BLI_rctf_size_y(&v2d->cur) / BLI_rcti_size_y(&v2d->mask); | ||||
| const float scrub_bar_height = BLI_rcti_size_y(&scrub_rect) * pixel_view_size_y; | const float scrub_bar_height = BLI_rcti_size_y(&scrub_rect) * pixel_view_size_y; | ||||
| /* Channel n has range of <n, n+1>. */ | /* Channel n has range of <n, n+1>. */ | ||||
| Show All 22 Lines | |||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Go to Current Frame Operator | /** \name Go to Current Frame Operator | ||||
| * \{ */ | * \{ */ | ||||
| static int sequencer_view_frame_exec(bContext *C, wmOperator *op) | static int sequencer_view_frame_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| const int smooth_viewtx = WM_operator_smooth_viewtx_get(op); | const int smooth_viewtx = WM_operator_smooth_viewtx_get(op); | ||||
| ANIM_center_frame(C, smooth_viewtx); | VideoEdit *video_edit = CTX_data_video_edit(C); | ||||
| double fps = (((double)video_edit->r.frs_sec) / (double)video_edit->r.frs_sec_base); | |||||
| ANIM_center_frame(C, fps, video_edit->r.cfra, smooth_viewtx); | |||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| void SEQUENCER_OT_view_frame(wmOperatorType *ot) | void SEQUENCER_OT_view_frame(wmOperatorType *ot) | ||||
| { | { | ||||
| /* Identifiers. */ | /* Identifiers. */ | ||||
| ot->name = "Go to Current Frame"; | ot->name = "Go to Current Frame"; | ||||
| ▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | |||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Sequencer View Zoom Ratio Operator | /** \name Sequencer View Zoom Ratio Operator | ||||
| * \{ */ | * \{ */ | ||||
| static int sequencer_view_zoom_ratio_exec(bContext *C, wmOperator *op) | static int sequencer_view_zoom_ratio_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| RenderData *rd = &CTX_data_scene(C)->r; | RenderData *rd = &CTX_data_video_edit(C)->r; | ||||
| View2D *v2d = UI_view2d_fromcontext(C); | View2D *v2d = UI_view2d_fromcontext(C); | ||||
| float ratio = RNA_float_get(op->ptr, "ratio"); | float ratio = RNA_float_get(op->ptr, "ratio"); | ||||
| int winx, winy; | int winx, winy; | ||||
| BKE_render_resolution(rd, false, &winx, &winy); | BKE_render_resolution(rd, false, &winx, &winy); | ||||
| float facx = BLI_rcti_size_x(&v2d->mask) / (float)winx; | float facx = BLI_rcti_size_x(&v2d->mask) / (float)winx; | ||||
| Show All 32 Lines | |||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Frame Selected Operator | /** \name Frame Selected Operator | ||||
| * \{ */ | * \{ */ | ||||
| static void seq_view_collection_rect_preview(Scene *scene, SeqCollection *strips, rctf *rect) | static void seq_view_collection_rect_preview(VideoEdit *video_edit, SeqCollection *strips, rctf *rect) | ||||
| { | { | ||||
| float min[2], max[2]; | float min[2], max[2]; | ||||
| SEQ_image_transform_bounding_box_from_collection(scene, strips, true, min, max); | SEQ_image_transform_bounding_box_from_collection(video_edit, strips, true, min, max); | ||||
| rect->xmin = min[0]; | rect->xmin = min[0]; | ||||
| rect->xmax = max[0]; | rect->xmax = max[0]; | ||||
| rect->ymin = min[1]; | rect->ymin = min[1]; | ||||
| rect->ymax = max[1]; | rect->ymax = max[1]; | ||||
| float minsize = min_ff(BLI_rctf_size_x(rect), BLI_rctf_size_y(rect)); | float minsize = min_ff(BLI_rctf_size_x(rect), BLI_rctf_size_y(rect)); | ||||
| /* If the size of the strip is smaller than a pixel, add padding to prevent division by zero. */ | /* If the size of the strip is smaller than a pixel, add padding to prevent division by zero. */ | ||||
| if (minsize < 1.0f) { | if (minsize < 1.0f) { | ||||
| BLI_rctf_pad(rect, 20.0f, 20.0f); | BLI_rctf_pad(rect, 20.0f, 20.0f); | ||||
| } | } | ||||
| /* Add padding. */ | /* Add padding. */ | ||||
| BLI_rctf_scale(rect, 1.1f); | BLI_rctf_scale(rect, 1.1f); | ||||
| } | } | ||||
| static void seq_view_collection_rect_timeline(Scene *scene, SeqCollection *strips, rctf *rect) | static void seq_view_collection_rect_timeline(VideoEdit *video_edit, SeqCollection *strips, rctf *rect) | ||||
| { | { | ||||
| Sequence *seq; | Sequence *seq; | ||||
| double fps = (((double)video_edit->r.frs_sec) / (double)video_edit->r.frs_sec_base); | |||||
| int xmin = MAXFRAME * 2; | int xmin = MAXFRAME * 2; | ||||
| int xmax = -MAXFRAME * 2; | int xmax = -MAXFRAME * 2; | ||||
| int ymin = MAXSEQ + 1; | int ymin = MAXSEQ + 1; | ||||
| int ymax = 0; | int ymax = 0; | ||||
| int orig_height; | int orig_height; | ||||
| int ymid; | int ymid; | ||||
| int ymargin = 1; | int ymargin = 1; | ||||
| int xmargin = FPS; | int xmargin = fps; | ||||
| SEQ_ITERATOR_FOREACH (seq, strips) { | SEQ_ITERATOR_FOREACH (seq, strips) { | ||||
| xmin = min_ii(xmin, SEQ_time_left_handle_frame_get(scene, seq)); | xmin = min_ii(xmin, SEQ_time_left_handle_frame_get(video_edit, seq)); | ||||
| xmax = max_ii(xmax, SEQ_time_right_handle_frame_get(scene, seq)); | xmax = max_ii(xmax, SEQ_time_right_handle_frame_get(video_edit, seq)); | ||||
| ymin = min_ii(ymin, seq->machine); | ymin = min_ii(ymin, seq->machine); | ||||
| ymax = max_ii(ymax, seq->machine); | ymax = max_ii(ymax, seq->machine); | ||||
| } | } | ||||
| xmax += xmargin; | xmax += xmargin; | ||||
| xmin -= xmargin; | xmin -= xmargin; | ||||
| ymax += ymargin; | ymax += ymargin; | ||||
| Show All 13 Lines | if (orig_height > BLI_rctf_size_y(rect)) { | ||||
| rect->ymin = ymid - (orig_height / 2); | rect->ymin = ymid - (orig_height / 2); | ||||
| rect->ymax = ymid + (orig_height / 2); | rect->ymax = ymid + (orig_height / 2); | ||||
| } | } | ||||
| } | } | ||||
| static int sequencer_view_selected_exec(bContext *C, wmOperator *op) | static int sequencer_view_selected_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Scene *scene = CTX_data_scene(C); | VideoEdit *video_edit = CTX_data_video_edit(C); | ||||
| ARegion *region = CTX_wm_region(C); | ARegion *region = CTX_wm_region(C); | ||||
| SeqCollection *strips = selected_strips_from_context(C); | SeqCollection *strips = selected_strips_from_context(C); | ||||
| View2D *v2d = UI_view2d_fromcontext(C); | View2D *v2d = UI_view2d_fromcontext(C); | ||||
| rctf cur_new = v2d->cur; | rctf cur_new = v2d->cur; | ||||
| if (SEQ_collection_len(strips) == 0) { | if (SEQ_collection_len(strips) == 0) { | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| if (sequencer_view_has_preview_poll(C) && !sequencer_view_preview_only_poll(C)) { | if (sequencer_view_has_preview_poll(C) && !sequencer_view_preview_only_poll(C)) { | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| if (region && region->regiontype == RGN_TYPE_PREVIEW) { | if (region && region->regiontype == RGN_TYPE_PREVIEW) { | ||||
| seq_view_collection_rect_preview(scene, strips, &cur_new); | seq_view_collection_rect_preview(video_edit, strips, &cur_new); | ||||
| } | } | ||||
| else { | else { | ||||
| seq_view_collection_rect_timeline(scene, strips, &cur_new); | seq_view_collection_rect_timeline(video_edit, strips, &cur_new); | ||||
| } | } | ||||
| const int smooth_viewtx = WM_operator_smooth_viewtx_get(op); | const int smooth_viewtx = WM_operator_smooth_viewtx_get(op); | ||||
| UI_view2d_smooth_view(C, region, &cur_new, smooth_viewtx); | UI_view2d_smooth_view(C, region, &cur_new, smooth_viewtx); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| Show All 15 Lines | |||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Border Offset View Operator | /** \name Border Offset View Operator | ||||
| * \{ */ | * \{ */ | ||||
| static int view_ghost_border_exec(bContext *C, wmOperator *op) | static int view_ghost_border_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Scene *scene = CTX_data_scene(C); | VideoEdit *video_edit = CTX_data_video_edit(C); | ||||
| View2D *v2d = UI_view2d_fromcontext(C); | View2D *v2d = UI_view2d_fromcontext(C); | ||||
| rctf rect; | rctf rect; | ||||
| /* Convert coordinates of rect to 'tot' rect coordinates. */ | /* Convert coordinates of rect to 'tot' rect coordinates. */ | ||||
| WM_operator_properties_border_to_rctf(op, &rect); | WM_operator_properties_border_to_rctf(op, &rect); | ||||
| UI_view2d_region_to_view_rctf(v2d, &rect, &rect); | UI_view2d_region_to_view_rctf(v2d, &rect, &rect); | ||||
| rect.xmin /= fabsf(BLI_rctf_size_x(&v2d->tot)); | rect.xmin /= fabsf(BLI_rctf_size_x(&v2d->tot)); | ||||
| rect.ymin /= fabsf(BLI_rctf_size_y(&v2d->tot)); | rect.ymin /= fabsf(BLI_rctf_size_y(&v2d->tot)); | ||||
| rect.xmax /= fabsf(BLI_rctf_size_x(&v2d->tot)); | rect.xmax /= fabsf(BLI_rctf_size_x(&v2d->tot)); | ||||
| rect.ymax /= fabsf(BLI_rctf_size_y(&v2d->tot)); | rect.ymax /= fabsf(BLI_rctf_size_y(&v2d->tot)); | ||||
| rect.xmin += 0.5f; | rect.xmin += 0.5f; | ||||
| rect.xmax += 0.5f; | rect.xmax += 0.5f; | ||||
| rect.ymin += 0.5f; | rect.ymin += 0.5f; | ||||
| rect.ymax += 0.5f; | rect.ymax += 0.5f; | ||||
| CLAMP(rect.xmin, 0.0f, 1.0f); | CLAMP(rect.xmin, 0.0f, 1.0f); | ||||
| CLAMP(rect.ymin, 0.0f, 1.0f); | CLAMP(rect.ymin, 0.0f, 1.0f); | ||||
| CLAMP(rect.xmax, 0.0f, 1.0f); | CLAMP(rect.xmax, 0.0f, 1.0f); | ||||
| CLAMP(rect.ymax, 0.0f, 1.0f); | CLAMP(rect.ymax, 0.0f, 1.0f); | ||||
| scene->ed->overlay_frame_rect = rect; | video_edit->overlay_frame_rect = rect; | ||||
| WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene); | WM_event_add_notifier(C, NC_VIDEO_EDIT | ND_SEQUENCER, video_edit); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| void SEQUENCER_OT_view_ghost_border(wmOperatorType *ot) | void SEQUENCER_OT_view_ghost_border(wmOperatorType *ot) | ||||
| { | { | ||||
| /* Identifiers. */ | /* Identifiers. */ | ||||
| ot->name = "Border Offset View"; | ot->name = "Border Offset View"; | ||||
| Show All 18 Lines | |||||