Blender  V2.93
sequencer_view.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2012 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include "BLI_blenlib.h"
25 #include "BLI_math.h"
26 #include "BLI_utildefines.h"
27 
28 #include "DNA_scene_types.h"
29 
30 #include "BKE_context.h"
31 
32 #include "WM_api.h"
33 #include "WM_types.h"
34 
35 #include "RNA_define.h"
36 
37 #include "UI_view2d.h"
38 
39 #include "RNA_define.h"
40 
41 #include "SEQ_select.h"
42 #include "SEQ_sequencer.h"
43 #include "SEQ_time.h"
44 
45 /* For menu, popup, icons, etc. */
46 #include "ED_anim_api.h"
47 #include "ED_screen.h"
48 #include "ED_util_imbuf.h"
49 
50 /* Own include. */
51 #include "sequencer_intern.h"
52 
53 /* -------------------------------------------------------------------- */
58 {
59  /* Identifiers. */
60  ot->name = "Sample Color";
61  ot->idname = "SEQUENCER_OT_sample";
62  ot->description = "Use mouse to sample color in current frame";
63 
64  /* Api callbacks. */
69 
70  /* Flags. */
72 
73  /* Not implemented. */
74  PropertyRNA *prop;
75  prop = RNA_def_int(ot->srna, "size", 1, 1, 128, "Sample Size", "", 1, 64);
78 }
79 
82 /* -------------------------------------------------------------------- */
87 {
88  ARegion *region = CTX_wm_region(C);
89  rctf box;
90 
91  const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
93  const Editing *ed = SEQ_editing_get(scene, false);
94 
96  UI_view2d_smooth_view(C, region, &box, smooth_viewtx);
97  return OPERATOR_FINISHED;
98 }
99 
101 {
102  /* Identifiers. */
103  ot->name = "Frame All";
104  ot->idname = "SEQUENCER_OT_view_all";
105  ot->description = "View all the strips in the sequencer";
106 
107  /* Api callbacks. */
110 
111  /* Flags. */
113 }
114 
117 /* -------------------------------------------------------------------- */
122 {
123  const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
124  ANIM_center_frame(C, smooth_viewtx);
125 
126  return OPERATOR_FINISHED;
127 }
128 
130 {
131  /* Identifiers. */
132  ot->name = "Go to Current Frame";
133  ot->idname = "SEQUENCER_OT_view_frame";
134  ot->description = "Move the view to the current frame";
135 
136  /* Api callbacks. */
139 
140  /* Flags. */
141  ot->flag = 0;
142 }
143 
146 /* -------------------------------------------------------------------- */
151 {
152  SpaceSeq *sseq = CTX_wm_space_seq(C);
153  bScreen *screen = CTX_wm_screen(C);
155 #if 0
156  ARegion *region = CTX_wm_region(C);
158 #endif
160 
161  v2d->cur = v2d->tot;
163  UI_view2d_sync(screen, area, v2d, V2D_LOCK_COPY);
164 
165 #if 0
166  /* Like zooming on an image view. */
167  float zoomX, zoomY;
168  int width, height, imgwidth, imgheight;
169 
170  width = region->winx;
171  height = region->winy;
172 
173  seq_reset_imageofs(sseq);
174 
175  imgwidth = (scene->r.size * scene->r.xsch) / 100;
176  imgheight = (scene->r.size * scene->r.ysch) / 100;
177 
178  /* Apply aspect, doesn't need to be that accurate. */
179  imgwidth = (int)(imgwidth * (scene->r.xasp / scene->r.yasp));
180 
181  if (((imgwidth >= width) || (imgheight >= height)) && ((width > 0) && (height > 0))) {
182  /* Find the zoom value that will fit the image in the image space. */
183  zoomX = ((float)width) / ((float)imgwidth);
184  zoomY = ((float)height) / ((float)imgheight);
185  sseq->zoom = (zoomX < zoomY) ? zoomX : zoomY;
186 
187  sseq->zoom = 1.0f / power_of_2(1 / min_ff(zoomX, zoomY));
188  }
189  else {
190  sseq->zoom = 1.0f;
191  }
192 #endif
193 
194  sseq->flag |= SEQ_ZOOM_TO_FIT;
195 
197  return OPERATOR_FINISHED;
198 }
199 
201 {
202  /* Identifiers. */
203  ot->name = "Frame All";
204  ot->idname = "SEQUENCER_OT_view_all_preview";
205  ot->description = "Zoom preview to fit in the area";
206 
207  /* Api callbacks. */
210 
211  /* Flags. */
213 }
214 
217 /* -------------------------------------------------------------------- */
222 {
223  RenderData *rd = &CTX_data_scene(C)->r;
225 
226  float ratio = RNA_float_get(op->ptr, "ratio");
227 
228  float winx = (int)(rd->size * rd->xsch) / 100;
229  float winy = (int)(rd->size * rd->ysch) / 100;
230 
231  float facx = BLI_rcti_size_x(&v2d->mask) / winx;
232  float facy = BLI_rcti_size_y(&v2d->mask) / winy;
233 
234  BLI_rctf_resize(&v2d->cur, ceilf(winx * facx / ratio + 0.5f), ceilf(winy * facy / ratio + 0.5f));
235 
237 
239 
240  return OPERATOR_FINISHED;
241 }
242 
244 {
245  /* Identifiers. */
246  ot->name = "Sequencer View Zoom Ratio";
247  ot->idname = "SEQUENCER_OT_view_zoom_ratio";
248  ot->description = "Change zoom ratio of sequencer preview";
249 
250  /* Api callbacks. */
253 
254  /* Properties. */
256  "ratio",
257  1.0f,
258  -FLT_MAX,
259  FLT_MAX,
260  "Ratio",
261  "Zoom ratio, 1.0 is 1:1, higher is zoomed in, lower is zoomed out",
262  -FLT_MAX,
263  FLT_MAX);
264 }
265 
268 /* -------------------------------------------------------------------- */
273 {
276  ARegion *region = CTX_wm_region(C);
277  Editing *ed = SEQ_editing_get(scene, false);
278  Sequence *last_seq = SEQ_select_active_get(scene);
279  Sequence *seq;
280  rctf cur_new = v2d->cur;
281 
282  int xmin = MAXFRAME * 2;
283  int xmax = -MAXFRAME * 2;
284  int ymin = MAXSEQ + 1;
285  int ymax = 0;
286  int orig_height;
287  int ymid;
288  int ymargin = 1;
289  int xmargin = FPS;
290 
291  if (ed == NULL) {
292  return OPERATOR_CANCELLED;
293  }
294 
295  for (seq = ed->seqbasep->first; seq; seq = seq->next) {
296  if ((seq->flag & SELECT) || (seq == last_seq)) {
297  xmin = min_ii(xmin, seq->startdisp);
298  xmax = max_ii(xmax, seq->enddisp);
299 
300  ymin = min_ii(ymin, seq->machine);
301  ymax = max_ii(ymax, seq->machine);
302  }
303  }
304 
305  if (ymax != 0) {
306  const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
307 
308  xmax += xmargin;
309  xmin -= xmargin;
310  ymax += ymargin;
311  ymin -= ymargin;
312 
313  orig_height = BLI_rctf_size_y(&cur_new);
314 
315  cur_new.xmin = xmin;
316  cur_new.xmax = xmax;
317 
318  cur_new.ymin = ymin;
319  cur_new.ymax = ymax;
320 
321  /* Only zoom out vertically. */
322  if (orig_height > BLI_rctf_size_y(&cur_new)) {
323  ymid = BLI_rctf_cent_y(&cur_new);
324 
325  cur_new.ymin = ymid - (orig_height / 2);
326  cur_new.ymax = ymid + (orig_height / 2);
327  }
328 
329  UI_view2d_smooth_view(C, region, &cur_new, smooth_viewtx);
330 
331  return OPERATOR_FINISHED;
332  }
333  return OPERATOR_CANCELLED;
334 }
335 
337 {
338  /* Identifiers. */
339  ot->name = "Frame Selected";
340  ot->idname = "SEQUENCER_OT_view_selected";
341  ot->description = "Zoom the sequencer on the selected strips";
342 
343  /* Api callbacks. */
346 
347  /* Flags. */
349 }
350 
353 /* -------------------------------------------------------------------- */
358 {
361 
362  rctf rect;
363 
364  /* Convert coordinates of rect to 'tot' rect coordinates. */
366  UI_view2d_region_to_view_rctf(v2d, &rect, &rect);
367 
368  rect.xmin /= fabsf(BLI_rctf_size_x(&v2d->tot));
369  rect.ymin /= fabsf(BLI_rctf_size_y(&v2d->tot));
370 
371  rect.xmax /= fabsf(BLI_rctf_size_x(&v2d->tot));
372  rect.ymax /= fabsf(BLI_rctf_size_y(&v2d->tot));
373 
374  rect.xmin += 0.5f;
375  rect.xmax += 0.5f;
376  rect.ymin += 0.5f;
377  rect.ymax += 0.5f;
378 
379  CLAMP(rect.xmin, 0.0f, 1.0f);
380  CLAMP(rect.ymin, 0.0f, 1.0f);
381  CLAMP(rect.xmax, 0.0f, 1.0f);
382  CLAMP(rect.ymax, 0.0f, 1.0f);
383 
384  scene->ed->over_border = rect;
385 
387 
388  return OPERATOR_FINISHED;
389 }
390 
392 {
393  /* Identifiers. */
394  ot->name = "Border Offset View";
395  ot->idname = "SEQUENCER_OT_view_ghost_border";
396  ot->description = "Set the boundaries of the border used for offset view";
397 
398  /* Api callbacks. */
404 
405  /* Flags. */
406  ot->flag = 0;
407 
408  /* Properties. */
410 }
411 
typedef float(TangentPoint)[2]
struct ScrArea * CTX_wm_area(const bContext *C)
Definition: context.c:714
struct Scene * CTX_data_scene(const bContext *C)
Definition: context.c:1034
struct SpaceSeq * CTX_wm_space_seq(const bContext *C)
Definition: context.c:827
struct bScreen * CTX_wm_screen(const bContext *C)
Definition: context.c:709
struct ARegion * CTX_wm_region(const bContext *C)
Definition: context.c:725
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:157
BLI_INLINE float BLI_rctf_cent_y(const struct rctf *rct)
Definition: BLI_rect.h:148
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
Definition: BLI_rect.h:153
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
Definition: BLI_rect.h:161
void BLI_rctf_resize(struct rctf *rect, float x, float y)
Definition: rct.c:674
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
Definition: BLI_rect.h:165
#define UNUSED(x)
#define FPS
#define MAXFRAME
#define MAXSEQ
@ SEQ_ZOOM_TO_FIT
@ OPERATOR_CANCELLED
@ OPERATOR_FINISHED
void ED_area_tag_redraw(ScrArea *area)
Definition: area.c:745
bool ED_operator_sequencer_active(struct bContext *C)
Definition: screen_ops.c:319
void ED_region_tag_redraw(struct ARegion *region)
Definition: area.c:667
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 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
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
Group RGB to Bright Vector Camera CLAMP
@ PROP_SKIP_SAVE
Definition: RNA_types.h:204
@ PROP_HIDDEN
Definition: RNA_types.h:202
@ PROP_PIXEL
Definition: RNA_types.h:128
#define C
Definition: RandGen.cpp:39
void UI_view2d_smooth_view(struct bContext *C, struct ARegion *region, const struct rctf *cur, const int smooth_viewtx)
#define V2D_LOCK_COPY
Definition: UI_view2d.h:84
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.c:876
void UI_view2d_curRect_changed(const struct bContext *C, struct View2D *v2d)
#define ND_SEQUENCER
Definition: WM_types.h:337
@ OPTYPE_BLOCKING
Definition: WM_types.h:157
@ OPTYPE_REGISTER
Definition: WM_types.h:153
#define NC_SCENE
Definition: WM_types.h:279
void ANIM_center_frame(struct bContext *C, int smooth_viewtx)
Definition: anim_draw.c:588
#define SELECT
Scene scene
#define ceilf(x)
#define fabsf(x)
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:6355
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:3825
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1512
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:3585
void RNA_def_property_subtype(PropertyRNA *prop, PropertySubType subtype)
Definition: rna_define.c:1563
ListBase * SEQ_active_seqbase_get(const Editing *ed)
Definition: sequencer.c:350
Editing * SEQ_editing_get(Scene *scene, bool alloc)
Definition: sequencer.c:232
bool sequencer_view_preview_poll(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)
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)
Sequence * SEQ_select_active_get(Scene *scene)
Definition: strip_select.c:35
void SEQ_timeline_boundbox(const Scene *scene, const ListBase *seqbase, rctf *rect)
Definition: strip_time.c:385
ListBase * seqbasep
void * first
Definition: DNA_listBase.h:47
struct Editing * ed
struct RenderData r
struct Sequence * next
float xmax
Definition: DNA_vec_types.h:85
float xmin
Definition: DNA_vec_types.h:85
float ymax
Definition: DNA_vec_types.h:86
float ymin
Definition: DNA_vec_types.h:86
int(* invoke)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:752
const char * name
Definition: WM_types.h:721
int(* modal)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:768
const char * idname
Definition: WM_types.h:723
bool(* poll)(struct bContext *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:776
void(* cancel)(struct bContext *, struct wmOperator *)
Definition: WM_types.h:760
struct StructRNA * srna
Definition: WM_types.h:802
const char * description
Definition: WM_types.h:726
int(* exec)(struct bContext *, struct wmOperator *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:736
struct PointerRNA * ptr
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
wmOperatorType * ot
Definition: wm_files.c:3156
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)
Definition: wm_operators.c:944