Blender  V3.3
sequencer_view.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2012 Blender Foundation. All rights reserved. */
3 
8 #include "BLI_blenlib.h"
9 #include "BLI_math.h"
10 #include "BLI_utildefines.h"
11 
12 #include "DNA_scene_types.h"
13 
14 #include "BKE_context.h"
15 #include "BKE_scene.h"
16 
17 #include "WM_api.h"
18 #include "WM_types.h"
19 
20 #include "RNA_define.h"
21 
22 #include "UI_view2d.h"
23 
24 #include "SEQ_iterator.h"
25 #include "SEQ_select.h"
26 #include "SEQ_sequencer.h"
27 #include "SEQ_time.h"
28 #include "SEQ_transform.h"
29 
30 /* For menu, popup, icons, etc. */
31 #include "ED_anim_api.h"
32 #include "ED_screen.h"
33 #include "ED_time_scrub_ui.h"
34 #include "ED_util_imbuf.h"
35 
36 /* Own include. */
37 #include "sequencer_intern.h"
38 
39 /* -------------------------------------------------------------------- */
44 {
45  /* Identifiers. */
46  ot->name = "Sample Color";
47  ot->idname = "SEQUENCER_OT_sample";
48  ot->description = "Use mouse to sample color in current frame";
49 
50  /* Api callbacks. */
55 
56  /* Flags. */
58 
59  /* Not implemented. */
60  PropertyRNA *prop;
61  prop = RNA_def_int(ot->srna, "size", 1, 1, 128, "Sample Size", "", 1, 64);
64 }
65 
68 /* -------------------------------------------------------------------- */
73 {
74  ARegion *region = CTX_wm_region(C);
75  rctf box;
76 
77  const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
79  const Editing *ed = SEQ_editing_get(scene);
80 
83  /* Use meta strip range instead of scene. */
84  if (ms != NULL) {
85  box.xmin = ms->disp_range[0] - 1;
86  box.xmax = ms->disp_range[1] + 1;
87  }
89 
90  View2D *v2d = &region->v2d;
91  rcti scrub_rect;
92  ED_time_scrub_region_rect_get(region, &scrub_rect);
93  const float pixel_view_size_y = BLI_rctf_size_y(&v2d->cur) / BLI_rcti_size_y(&v2d->mask);
94  const float scrub_bar_height = BLI_rcti_size_y(&scrub_rect) * pixel_view_size_y;
95 
96  /* Channel n has range of <n, n+1>. */
97  box.ymax += 1.0f + scrub_bar_height;
98 
99  UI_view2d_smooth_view(C, region, &box, smooth_viewtx);
100  return OPERATOR_FINISHED;
101 }
102 
104 {
105  /* Identifiers. */
106  ot->name = "Frame All";
107  ot->idname = "SEQUENCER_OT_view_all";
108  ot->description = "View all the strips in the sequencer";
109 
110  /* Api callbacks. */
113 
114  /* Flags. */
116 }
117 
120 /* -------------------------------------------------------------------- */
125 {
126  const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
127  ANIM_center_frame(C, smooth_viewtx);
128 
129  return OPERATOR_FINISHED;
130 }
131 
133 {
134  /* Identifiers. */
135  ot->name = "Go to Current Frame";
136  ot->idname = "SEQUENCER_OT_view_frame";
137  ot->description = "Move the view to the current frame";
138 
139  /* Api callbacks. */
142 
143  /* Flags. */
144  ot->flag = 0;
145 }
146 
149 /* -------------------------------------------------------------------- */
154 {
155  SpaceSeq *sseq = CTX_wm_space_seq(C);
156  bScreen *screen = CTX_wm_screen(C);
158 #if 0
159  ARegion *region = CTX_wm_region(C);
161 #endif
163 
164  v2d->cur = v2d->tot;
166  UI_view2d_sync(screen, area, v2d, V2D_LOCK_COPY);
167 
168 #if 0
169  /* Like zooming on an image view. */
170  float zoomX, zoomY;
171  int width, height, imgwidth, imgheight;
172 
173  width = region->winx;
174  height = region->winy;
175 
176  seq_reset_imageofs(sseq);
177 
178  BKE_render_resolution(&scene->r, false, &imgwidth, &imgheight);
179 
180  /* Apply aspect, doesn't need to be that accurate. */
181  imgwidth = (int)(imgwidth * (scene->r.xasp / scene->r.yasp));
182 
183  if (((imgwidth >= width) || (imgheight >= height)) && ((width > 0) && (height > 0))) {
184  /* Find the zoom value that will fit the image in the image space. */
185  zoomX = ((float)width) / ((float)imgwidth);
186  zoomY = ((float)height) / ((float)imgheight);
187  sseq->zoom = (zoomX < zoomY) ? zoomX : zoomY;
188 
189  sseq->zoom = 1.0f / power_of_2(1 / min_ff(zoomX, zoomY));
190  }
191  else {
192  sseq->zoom = 1.0f;
193  }
194 #endif
195 
196  sseq->flag |= SEQ_ZOOM_TO_FIT;
197 
199  return OPERATOR_FINISHED;
200 }
201 
203 {
204  /* Identifiers. */
205  ot->name = "Frame All";
206  ot->idname = "SEQUENCER_OT_view_all_preview";
207  ot->description = "Zoom preview to fit in the area";
208 
209  /* Api callbacks. */
212 
213  /* Flags. */
215 }
216 
219 /* -------------------------------------------------------------------- */
224 {
225  RenderData *rd = &CTX_data_scene(C)->r;
227 
228  float ratio = RNA_float_get(op->ptr, "ratio");
229 
230  int winx, winy;
231  BKE_render_resolution(rd, false, &winx, &winy);
232 
233  float facx = BLI_rcti_size_x(&v2d->mask) / (float)winx;
234  float facy = BLI_rcti_size_y(&v2d->mask) / (float)winy;
235 
236  BLI_rctf_resize(&v2d->cur, ceilf(winx * facx / ratio + 0.5f), ceilf(winy * facy / ratio + 0.5f));
237 
239 
241 
242  return OPERATOR_FINISHED;
243 }
244 
246 {
247  /* Identifiers. */
248  ot->name = "Sequencer View Zoom Ratio";
249  ot->idname = "SEQUENCER_OT_view_zoom_ratio";
250  ot->description = "Change zoom ratio of sequencer preview";
251 
252  /* Api callbacks. */
255 
256  /* Properties. */
258  "ratio",
259  1.0f,
260  -FLT_MAX,
261  FLT_MAX,
262  "Ratio",
263  "Zoom ratio, 1.0 is 1:1, higher is zoomed in, lower is zoomed out",
264  -FLT_MAX,
265  FLT_MAX);
266 }
267 
270 /* -------------------------------------------------------------------- */
275 {
276  float min[2], max[2];
278 
279  rect->xmin = min[0];
280  rect->xmax = max[0];
281  rect->ymin = min[1];
282  rect->ymax = max[1];
283 
284  float minsize = min_ff(BLI_rctf_size_x(rect), BLI_rctf_size_y(rect));
285 
286  /* If the size of the strip is smaller than a pixel, add padding to prevent division by zero. */
287  if (minsize < 1.0f) {
288  BLI_rctf_pad(rect, 20.0f, 20.0f);
289  }
290 
291  /* Add padding. */
292  BLI_rctf_scale(rect, 1.1f);
293 }
294 
296 {
297  Sequence *seq;
298 
299  int xmin = MAXFRAME * 2;
300  int xmax = -MAXFRAME * 2;
301  int ymin = MAXSEQ + 1;
302  int ymax = 0;
303  int orig_height;
304  int ymid;
305  int ymargin = 1;
306  int xmargin = FPS;
307 
308  SEQ_ITERATOR_FOREACH (seq, strips) {
309  xmin = min_ii(xmin, SEQ_time_left_handle_frame_get(scene, seq));
310  xmax = max_ii(xmax, SEQ_time_right_handle_frame_get(scene, seq));
311 
312  ymin = min_ii(ymin, seq->machine);
313  ymax = max_ii(ymax, seq->machine);
314  }
315 
316  xmax += xmargin;
317  xmin -= xmargin;
318  ymax += ymargin;
319  ymin -= ymargin;
320 
321  orig_height = BLI_rctf_size_y(rect);
322 
323  rect->xmin = xmin;
324  rect->xmax = xmax;
325 
326  rect->ymin = ymin;
327  rect->ymax = ymax;
328 
329  /* Only zoom out vertically. */
330  if (orig_height > BLI_rctf_size_y(rect)) {
331  ymid = BLI_rctf_cent_y(rect);
332 
333  rect->ymin = ymid - (orig_height / 2);
334  rect->ymax = ymid + (orig_height / 2);
335  }
336 }
337 
339 {
341  ARegion *region = CTX_wm_region(C);
344  rctf cur_new = v2d->cur;
345 
346  if (SEQ_collection_len(strips) == 0) {
347  return OPERATOR_CANCELLED;
348  }
349 
351  return OPERATOR_CANCELLED;
352  }
353 
354  if (region && region->regiontype == RGN_TYPE_PREVIEW) {
355  seq_view_collection_rect_preview(scene, strips, &cur_new);
356  }
357  else {
358  seq_view_collection_rect_timeline(scene, strips, &cur_new);
359  }
360 
361  const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
362  UI_view2d_smooth_view(C, region, &cur_new, smooth_viewtx);
363 
364  return OPERATOR_FINISHED;
365 }
366 
368 {
369  /* Identifiers. */
370  ot->name = "Frame Selected";
371  ot->idname = "SEQUENCER_OT_view_selected";
372  ot->description = "Zoom the sequencer on the selected strips";
373 
374  /* Api callbacks. */
377 
378  /* Flags. */
380 }
381 
384 /* -------------------------------------------------------------------- */
389 {
392 
393  rctf rect;
394 
395  /* Convert coordinates of rect to 'tot' rect coordinates. */
397  UI_view2d_region_to_view_rctf(v2d, &rect, &rect);
398 
399  rect.xmin /= fabsf(BLI_rctf_size_x(&v2d->tot));
400  rect.ymin /= fabsf(BLI_rctf_size_y(&v2d->tot));
401 
402  rect.xmax /= fabsf(BLI_rctf_size_x(&v2d->tot));
403  rect.ymax /= fabsf(BLI_rctf_size_y(&v2d->tot));
404 
405  rect.xmin += 0.5f;
406  rect.xmax += 0.5f;
407  rect.ymin += 0.5f;
408  rect.ymax += 0.5f;
409 
410  CLAMP(rect.xmin, 0.0f, 1.0f);
411  CLAMP(rect.ymin, 0.0f, 1.0f);
412  CLAMP(rect.xmax, 0.0f, 1.0f);
413  CLAMP(rect.ymax, 0.0f, 1.0f);
414 
415  scene->ed->overlay_frame_rect = rect;
416 
418 
419  return OPERATOR_FINISHED;
420 }
421 
423 {
424  /* Identifiers. */
425  ot->name = "Border Offset View";
426  ot->idname = "SEQUENCER_OT_view_ghost_border";
427  ot->description = "Set the boundaries of the border used for offset view";
428 
429  /* Api callbacks. */
435 
436  /* Flags. */
437  ot->flag = 0;
438 
439  /* Properties. */
441 }
442 
typedef float(TangentPoint)[2]
struct ScrArea * CTX_wm_area(const bContext *C)
Definition: context.c:738
struct Scene * CTX_data_scene(const bContext *C)
Definition: context.c:1090
struct SpaceSeq * CTX_wm_space_seq(const bContext *C)
Definition: context.c:851
struct bScreen * CTX_wm_screen(const bContext *C)
Definition: context.c:733
struct ARegion * CTX_wm_region(const bContext *C)
Definition: context.c:749
void BKE_render_resolution(const struct RenderData *r, const bool use_crop, int *r_width, int *r_height)
Definition: scene.cc:2960
MINLINE int min_ii(int a, int b)
MINLINE float min_ff(float a, float b)
MINLINE int max_ii(int a, int b)
MINLINE float power_of_2(float f)
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
Definition: BLI_rect.h:190
BLI_INLINE float BLI_rctf_cent_y(const struct rctf *rct)
Definition: BLI_rect.h:181
void BLI_rctf_scale(rctf *rect, float scale)
Definition: rct.c:655
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
Definition: BLI_rect.h:186
void BLI_rctf_pad(struct rctf *rect, float pad_x, float pad_y)
Definition: rct.c:615
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
Definition: BLI_rect.h:194
void BLI_rctf_resize(struct rctf *rect, float x, float y)
Definition: rct.c:635
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
Definition: BLI_rect.h:198
#define UNUSED(x)
#define FPS
#define MAXFRAME
@ RGN_TYPE_PREVIEW
#define MAXSEQ
@ SEQ_ZOOM_TO_FIT
@ OPERATOR_CANCELLED
@ OPERATOR_FINISHED
void ED_area_tag_redraw(ScrArea *area)
Definition: area.c:729
bool ED_operator_sequencer_active(struct bContext *C)
Definition: screen_ops.c:334
void ED_region_tag_redraw(struct ARegion *region)
Definition: area.c:655
int ED_imbuf_sample_invoke(struct bContext *C, struct wmOperator *op, const struct wmEvent *event)
bool ED_imbuf_sample_poll(struct bContext *C)
void ED_imbuf_sample_cancel(struct bContext *C, struct wmOperator *op)
int ED_imbuf_sample_modal(struct bContext *C, struct wmOperator *op, const struct wmEvent *event)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei width
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position CLAMP
@ PROP_SKIP_SAVE
Definition: RNA_types.h:218
@ PROP_HIDDEN
Definition: RNA_types.h:216
@ PROP_PIXEL
Definition: RNA_types.h:141
#define C
Definition: RandGen.cpp:25
#define SEQ_ITERATOR_FOREACH(var, collection)
Definition: SEQ_iterator.h:35
#define V2D_LOCK_COPY
Definition: UI_view2d.h:82
void UI_view2d_smooth_view(const struct bContext *C, struct ARegion *region, const struct rctf *cur, int smooth_viewtx)
struct View2D * UI_view2d_fromcontext(const struct bContext *C)
void UI_view2d_region_to_view_rctf(const struct View2D *v2d, const struct rctf *rect_src, struct rctf *rect_dst) ATTR_NONNULL()
void UI_view2d_sync(struct bScreen *screen, struct ScrArea *area, struct View2D *v2dcur, int flag)
Definition: view2d.cc:851
void UI_view2d_curRect_changed(const struct bContext *C, struct View2D *v2d)
#define ND_SEQUENCER
Definition: WM_types.h:385
@ OPTYPE_BLOCKING
Definition: WM_types.h:150
@ OPTYPE_REGISTER
Definition: WM_types.h:146
#define NC_SCENE
Definition: WM_types.h:328
void ANIM_center_frame(struct bContext *C, int smooth_viewtx)
Definition: anim_draw.c:619
Scene scene
uint SEQ_collection_len(const SeqCollection *collection)
Definition: iterator.c:95
#define ceilf(x)
Definition: metal/compat.h:225
#define fabsf(x)
Definition: metal/compat.h:219
static void area(int d1, int d2, int e1, int e2, float weights[2])
float RNA_float_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:4957
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, float default_value, float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
Definition: rna_define.c:3836
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1490
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, int default_value, int hardmin, int hardmax, const char *ui_name, const char *ui_description, int softmin, int softmax)
Definition: rna_define.c:3597
void RNA_def_property_subtype(PropertyRNA *prop, PropertySubType subtype)
Definition: rna_define.c:1534
ListBase * SEQ_active_seqbase_get(const Editing *ed)
Definition: sequencer.c:388
MetaStack * SEQ_meta_stack_active_get(const Editing *ed)
Definition: sequencer.c:420
Editing * SEQ_editing_get(const Scene *scene)
Definition: sequencer.c:241
bool sequencer_view_preview_only_poll(const bContext *C)
bool sequencer_view_has_preview_poll(bContext *C)
bool sequencer_editing_initialized_and_active(bContext *C)
struct SeqCollection * selected_strips_from_context(struct bContext *C)
static int sequencer_view_frame_exec(bContext *C, wmOperator *op)
static int sequencer_view_all_exec(bContext *C, wmOperator *op)
static int sequencer_view_zoom_ratio_exec(bContext *C, wmOperator *op)
void SEQUENCER_OT_sample(wmOperatorType *ot)
static void seq_view_collection_rect_timeline(Scene *scene, SeqCollection *strips, rctf *rect)
static void seq_view_collection_rect_preview(Scene *scene, SeqCollection *strips, rctf *rect)
void SEQUENCER_OT_view_all_preview(wmOperatorType *ot)
void SEQUENCER_OT_view_zoom_ratio(wmOperatorType *ot)
void SEQUENCER_OT_view_ghost_border(wmOperatorType *ot)
static int sequencer_view_selected_exec(bContext *C, wmOperator *op)
void SEQUENCER_OT_view_frame(wmOperatorType *ot)
void SEQUENCER_OT_view_selected(wmOperatorType *ot)
void SEQUENCER_OT_view_all(wmOperatorType *ot)
static int sequencer_view_all_preview_exec(bContext *C, wmOperator *UNUSED(op))
static int view_ghost_border_exec(bContext *C, wmOperator *op)
#define min(a, b)
Definition: sort.c:35
void SEQ_timeline_init_boundbox(const Scene *scene, rctf *rect)
Definition: strip_time.c:346
void SEQ_timeline_expand_boundbox(const Scene *scene, const ListBase *seqbase, rctf *rect)
Definition: strip_time.c:354
int SEQ_time_left_handle_frame_get(const Scene *UNUSED(scene), const Sequence *seq)
Definition: strip_time.c:506
int SEQ_time_right_handle_frame_get(const Scene *scene, const Sequence *seq)
Definition: strip_time.c:515
void SEQ_image_transform_bounding_box_from_collection(Scene *scene, SeqCollection *strips, bool apply_rotation, float r_min[2], float r_max[2])
short regiontype
rctf overlay_frame_rect
struct Editing * ed
struct RenderData r
float xmax
Definition: DNA_vec_types.h:69
float xmin
Definition: DNA_vec_types.h:69
float ymax
Definition: DNA_vec_types.h:70
float ymin
Definition: DNA_vec_types.h:70
int(* invoke)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:919
const char * name
Definition: WM_types.h:888
int(* modal)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:935
const char * idname
Definition: WM_types.h:890
bool(* poll)(struct bContext *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:943
void(* cancel)(struct bContext *, struct wmOperator *)
Definition: WM_types.h:927
struct StructRNA * srna
Definition: WM_types.h:969
const char * description
Definition: WM_types.h:893
int(* exec)(struct bContext *, struct wmOperator *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:903
struct PointerRNA * ptr
void ED_time_scrub_region_rect_get(const ARegion *region, rcti *rect)
Definition: time_scrub_ui.c:35
float max
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
wmOperatorType * ot
Definition: wm_files.c:3479
void WM_gesture_box_cancel(bContext *C, wmOperator *op)
int WM_gesture_box_invoke(bContext *C, wmOperator *op, const wmEvent *event)
int WM_gesture_box_modal(bContext *C, wmOperator *op, const wmEvent *event)
void WM_operator_properties_gesture_box(wmOperatorType *ot)
void WM_operator_properties_border_to_rctf(struct wmOperator *op, rctf *rect)
int WM_operator_smooth_viewtx_get(const wmOperator *op)