Blender  V3.3
clip_dopesheet_draw.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 "DNA_movieclip_types.h"
9 #include "DNA_scene_types.h"
10 
11 #include "BLI_math.h"
12 #include "BLI_rect.h"
13 #include "BLI_utildefines.h"
14 
15 #include "BKE_context.h"
16 #include "BKE_movieclip.h"
17 
18 #include "ED_clip.h"
19 #include "ED_screen.h"
20 
21 #include "WM_types.h"
22 
23 #include "UI_interface.h"
24 #include "UI_resources.h"
25 #include "UI_view2d.h"
26 
27 #include "BLF_api.h"
28 
29 #include "RNA_access.h"
30 #include "RNA_prototypes.h"
31 
32 #include "GPU_immediate.h"
33 #include "GPU_state.h"
34 
35 #include "clip_intern.h" /* own include */
36 
38  const float default_color[3],
39  float color[3])
40 {
41  if (track->flag & TRACK_CUSTOMCOLOR) {
42  float bg[3];
44 
45  interp_v3_v3v3(color, track->color, bg, 0.5);
46  }
47  else {
48  if (default_color) {
49  copy_v3_v3(color, default_color);
50  }
51  else {
53  }
54  }
55 }
56 
57 static void draw_keyframe_shape(
58  float x, float y, bool sel, float alpha, uint pos_id, uint color_id)
59 {
60  float color[4] = {0.91f, 0.91f, 0.91f, alpha};
61  if (sel) {
62  UI_GetThemeColorShadeAlpha4fv(TH_STRIP_SELECT, 50, -255 * (1.0f - alpha), color);
63  }
64 
65  immAttr4fv(color_id, color);
66  immVertex2f(pos_id, x, y);
67 }
68 
69 static void clip_draw_dopesheet_background(ARegion *region, MovieClip *clip, uint pos_id)
70 {
71  View2D *v2d = &region->v2d;
72  MovieTracking *tracking = &clip->tracking;
73  MovieTrackingDopesheet *dopesheet = &tracking->dopesheet;
74  MovieTrackingDopesheetCoverageSegment *coverage_segment;
75 
76  for (coverage_segment = dopesheet->coverage_segments.first; coverage_segment;
77  coverage_segment = coverage_segment->next) {
78  if (coverage_segment->coverage < TRACKING_COVERAGE_OK) {
79  int start_frame = BKE_movieclip_remap_clip_to_scene_frame(clip,
80  coverage_segment->start_frame);
81  int end_frame = BKE_movieclip_remap_clip_to_scene_frame(clip, coverage_segment->end_frame);
82 
83  if (coverage_segment->coverage == TRACKING_COVERAGE_BAD) {
84  immUniformColor4f(1.0f, 0.0f, 0.0f, 0.07f);
85  }
86  else {
87  immUniformColor4f(1.0f, 1.0f, 0.0f, 0.07f);
88  }
89 
90  immRectf(pos_id, start_frame, v2d->cur.ymin, end_frame, v2d->cur.ymax);
91  }
92  }
93 }
94 
96 {
98  View2D *v2d = &region->v2d;
99 
100  /* frame range */
102 
103  if (clip) {
104  MovieTracking *tracking = &clip->tracking;
105  MovieTrackingDopesheet *dopesheet = &tracking->dopesheet;
107  float strip[4], selected_strip[4];
108  float height = (dopesheet->tot_channel * CHANNEL_STEP) + CHANNEL_HEIGHT;
109 
110  uint keyframe_len = 0;
111 
115 
116  /* don't use totrect set, as the width stays the same
117  * (NOTE: this is ok here, the configuration is pretty straightforward)
118  */
119  v2d->tot.ymin = (float)(-height);
120 
121  float y = (float)CHANNEL_FIRST;
122 
123  /* setup colors for regular and selected strips */
125  UI_GetThemeColor3fv(TH_STRIP_SELECT, selected_strip);
126 
127  strip[3] = 0.5f;
128  selected_strip[3] = 1.0f;
129 
131 
132  clip_draw_dopesheet_background(region, clip, pos_id);
133 
134  for (channel = dopesheet->channels.first; channel; channel = channel->next) {
135  float yminc = (float)(y - CHANNEL_HEIGHT_HALF);
136  float ymaxc = (float)(y + CHANNEL_HEIGHT_HALF);
137 
138  /* check if visible */
139  if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
140  IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax)) {
141  MovieTrackingTrack *track = channel->track;
142  int i;
143  bool sel = (track->flag & TRACK_DOPE_SEL) != 0;
144 
145  /* selection background */
146  if (sel) {
147  float color[4] = {0.0f, 0.0f, 0.0f, 0.3f};
148  float default_color[4] = {0.8f, 0.93f, 0.8f, 0.3f};
149 
150  track_channel_color(track, default_color, color);
152 
153  immRectf(pos_id,
154  v2d->cur.xmin,
155  (float)y - CHANNEL_HEIGHT_HALF,
156  v2d->cur.xmax + EXTRA_SCROLL_PAD,
157  (float)y + CHANNEL_HEIGHT_HALF);
158  }
159 
160  /* tracked segments */
161  for (i = 0; i < channel->tot_segment; i++) {
162  int start_frame = BKE_movieclip_remap_clip_to_scene_frame(clip,
163  channel->segments[2 * i]);
164  int end_frame = BKE_movieclip_remap_clip_to_scene_frame(clip,
165  channel->segments[2 * i + 1]);
166 
167  immUniformColor4fv(sel ? selected_strip : strip);
168 
169  if (start_frame != end_frame) {
170  immRectf(pos_id,
171  start_frame,
172  (float)y - STRIP_HEIGHT_HALF,
173  end_frame,
174  (float)y + STRIP_HEIGHT_HALF);
175  keyframe_len += 2;
176  }
177  else {
178  keyframe_len++;
179  }
180  }
181 
182  /* keyframes */
183  i = 0;
184  while (i < track->markersnr) {
185  MovieTrackingMarker *marker = &track->markers[i];
186 
187  if ((marker->flag & (MARKER_DISABLED | MARKER_TRACKED)) == 0) {
188  keyframe_len++;
189  }
190 
191  i++;
192  }
193  }
194 
195  /* adjust y-position for next one */
196  y -= CHANNEL_STEP;
197  }
198 
200 
201  if (keyframe_len > 0) {
202  /* draw keyframe markers */
207  uint outline_color_id = GPU_vertformat_attr_add(
208  format, "outlineColor", GPU_COMP_U8, 4, GPU_FETCH_INT_TO_FLOAT_UNIT);
210 
213  immUniform1f("outline_scale", 1.0f);
214  immUniform2f(
215  "ViewportSize", BLI_rcti_size_x(&v2d->mask) + 1, BLI_rcti_size_y(&v2d->mask) + 1);
216  immBegin(GPU_PRIM_POINTS, keyframe_len);
217 
218  /* all same size with black outline */
219  immAttr1f(size_id, 2.0f * STRIP_HEIGHT_HALF);
220  immAttr4ub(outline_color_id, 0, 0, 0, 255);
221  immAttr1u(flags_id, 0);
222 
223  y = (float)CHANNEL_FIRST; /* start again at the top */
224  for (channel = dopesheet->channels.first; channel; channel = channel->next) {
225  float yminc = (float)(y - CHANNEL_HEIGHT_HALF);
226  float ymaxc = (float)(y + CHANNEL_HEIGHT_HALF);
227 
228  /* check if visible */
229  if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
230  IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax)) {
231  MovieTrackingTrack *track = channel->track;
232  int i;
233  bool sel = (track->flag & TRACK_DOPE_SEL) != 0;
234  float alpha = (track->flag & TRACK_LOCKED) ? 0.5f : 1.0f;
235 
236  /* tracked segments */
237  for (i = 0; i < channel->tot_segment; i++) {
238  int start_frame = BKE_movieclip_remap_clip_to_scene_frame(clip,
239  channel->segments[2 * i]);
240  int end_frame = BKE_movieclip_remap_clip_to_scene_frame(clip,
241  channel->segments[2 * i + 1]);
242 
243  if (start_frame != end_frame) {
244  draw_keyframe_shape(start_frame, y, sel, alpha, pos_id, color_id);
245  draw_keyframe_shape(end_frame, y, sel, alpha, pos_id, color_id);
246  }
247  else {
248  draw_keyframe_shape(start_frame, y, sel, alpha, pos_id, color_id);
249  }
250  }
251 
252  /* keyframes */
253  i = 0;
254  while (i < track->markersnr) {
255  MovieTrackingMarker *marker = &track->markers[i];
256 
257  if ((marker->flag & (MARKER_DISABLED | MARKER_TRACKED)) == 0) {
258  int framenr = BKE_movieclip_remap_clip_to_scene_frame(clip, marker->framenr);
259 
260  draw_keyframe_shape(framenr, y, sel, alpha, pos_id, color_id);
261  }
262 
263  i++;
264  }
265  }
266 
267  /* adjust y-position for next one */
268  y -= CHANNEL_STEP;
269  }
270 
271  immEnd();
272  GPU_program_point_size(false);
274  }
275 
277  }
278 }
279 
281 {
284  View2D *v2d = &region->v2d;
285  MovieClip *clip = ED_space_clip_get_clip(sc);
286  const uiStyle *style = UI_style_get();
287  int fontid = style->widget.uifont_id;
288 
289  if (!clip) {
290  return;
291  }
292 
293  MovieTracking *tracking = &clip->tracking;
294  MovieTrackingDopesheet *dopesheet = &tracking->dopesheet;
295  int height = (dopesheet->tot_channel * CHANNEL_STEP) + CHANNEL_HEIGHT;
296 
297  if (height > BLI_rcti_size_y(&v2d->mask)) {
298  /* don't use totrect set, as the width stays the same
299  * (NOTE: this is ok here, the configuration is pretty straightforward)
300  */
301  v2d->tot.ymin = (float)(-height);
302  }
303 
304  /* need to do a view-sync here, so that the keys area doesn't jump around
305  * (it must copy this) */
307 
308  /* loop through channels, and set up drawing depending on their type
309  * first pass: just the standard GL-drawing for backdrop + text
310  */
311  float y = (float)CHANNEL_FIRST;
312 
315 
317 
319  for (channel = dopesheet->channels.first; channel; channel = channel->next) {
320  float yminc = (float)(y - CHANNEL_HEIGHT_HALF);
321  float ymaxc = (float)(y + CHANNEL_HEIGHT_HALF);
322 
323  /* check if visible */
324  if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
325  IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax)) {
326  MovieTrackingTrack *track = channel->track;
327  float color[3];
328  track_channel_color(track, NULL, color);
330 
331  immRectf(pos,
332  v2d->cur.xmin,
333  (float)y - CHANNEL_HEIGHT_HALF,
334  v2d->cur.xmax + EXTRA_SCROLL_PAD,
335  (float)y + CHANNEL_HEIGHT_HALF);
336  }
337 
338  /* adjust y-position for next one */
339  y -= CHANNEL_STEP;
340  }
342 
343  /* second pass: text */
344  y = (float)CHANNEL_FIRST;
345 
346  BLF_size(fontid, 11.0f * U.pixelsize, U.dpi);
347 
348  for (channel = dopesheet->channels.first; channel; channel = channel->next) {
349  float yminc = (float)(y - CHANNEL_HEIGHT_HALF);
350  float ymaxc = (float)(y + CHANNEL_HEIGHT_HALF);
351 
352  /* check if visible */
353  if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
354  IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax)) {
355  MovieTrackingTrack *track = channel->track;
356  bool sel = (track->flag & TRACK_DOPE_SEL) != 0;
357 
358  UI_FontThemeColor(fontid, sel ? TH_TEXT_HI : TH_TEXT);
359 
360  float font_height = BLF_height(fontid, channel->name, sizeof(channel->name));
361  BLF_position(fontid, v2d->cur.xmin + CHANNEL_PAD, y - font_height / 2.0f, 0.0f);
362  BLF_draw(fontid, channel->name, strlen(channel->name));
363  }
364 
365  /* adjust y-position for next one */
366  y -= CHANNEL_STEP;
367  }
368 
369  /* third pass: widgets */
370  uiBlock *block = UI_block_begin(C, region, __func__, UI_EMBOSS);
371  y = (float)CHANNEL_FIRST;
372 
373  /* get RNA properties (once) */
374  PropertyRNA *chan_prop_lock = RNA_struct_type_find_property(&RNA_MovieTrackingTrack, "lock");
375  BLI_assert(chan_prop_lock);
376 
378  for (channel = dopesheet->channels.first; channel; channel = channel->next) {
379  float yminc = (float)(y - CHANNEL_HEIGHT_HALF);
380  float ymaxc = (float)(y + CHANNEL_HEIGHT_HALF);
381 
382  /* check if visible */
383  if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
384  IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax)) {
385  MovieTrackingTrack *track = channel->track;
386  const int icon = (track->flag & TRACK_LOCKED) ? ICON_LOCKED : ICON_UNLOCKED;
387  PointerRNA ptr;
388 
389  RNA_pointer_create(&clip->id, &RNA_MovieTrackingTrack, track, &ptr);
390 
392  uiDefIconButR_prop(block,
394  1,
395  icon,
396  v2d->cur.xmax - UI_UNIT_X - CHANNEL_PAD,
397  y - UI_UNIT_Y / 2.0f,
398  UI_UNIT_X,
399  UI_UNIT_Y,
400  &ptr,
401  chan_prop_lock,
402  0,
403  0,
404  0,
405  0,
406  0,
407  NULL);
409  }
410 
411  /* adjust y-position for next one */
412  y -= CHANNEL_STEP;
413  }
415 
416  UI_block_end(C, block);
417  UI_block_draw(C, block);
418 }
typedef float(TangentPoint)[2]
struct ScrArea * CTX_wm_area(const bContext *C)
Definition: context.c:738
struct SpaceClip * CTX_wm_space_clip(const bContext *C)
Definition: context.c:923
float BKE_movieclip_remap_clip_to_scene_frame(const struct MovieClip *clip, float framenr)
float BLF_height(int fontid, const char *str, size_t str_len) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: blf.c:717
void BLF_draw(int fontid, const char *str, size_t str_len) ATTR_NONNULL(2)
Definition: blf.c:538
void BLF_size(int fontid, float size, int dpi)
Definition: blf.c:363
void BLF_position(int fontid, float x, float y, float z)
Definition: blf.c:308
#define BLI_assert(a)
Definition: BLI_assert.h:46
MINLINE void copy_v3_v3(float r[3], const float a[3])
void interp_v3_v3v3(float r[3], const float a[3], const float b[3], float t)
Definition: math_vector.c:29
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
Definition: BLI_rect.h:190
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
Definition: BLI_rect.h:186
unsigned int uint
Definition: BLI_sys_types.h:67
#define IN_RANGE(a, b, c)
@ MARKER_TRACKED
@ MARKER_DISABLED
@ TRACK_CUSTOMCOLOR
@ TRACK_LOCKED
@ TRACK_DOPE_SEL
@ TRACKING_COVERAGE_BAD
@ TRACKING_COVERAGE_OK
struct MovieClip * ED_space_clip_get_clip(struct SpaceClip *sc)
Definition: clip_editor.c:570
void immAttr4fv(uint attr_id, const float data[4])
void immAttr4ub(uint attr_id, unsigned char r, unsigned char g, unsigned char b, unsigned char a)
void immUniform2f(const char *name, float x, float y)
void immUniformColor4f(float r, float g, float b, float a)
void immUnbindProgram(void)
void immVertex2f(uint attr_id, float x, float y)
void immAttr1f(uint attr_id, float x)
void immBindBuiltinProgram(eGPUBuiltinShader shader_id)
void immAttr1u(uint attr_id, uint x)
void immUniform1f(const char *name, float x)
void immUniformColor4fv(const float rgba[4])
GPUVertFormat * immVertexFormat(void)
void immBegin(GPUPrimType, uint vertex_len)
void immEnd(void)
void immUniformColor3fv(const float rgb[3])
void immRectf(uint pos, float x1, float y1, float x2, float y2)
_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 y
@ GPU_PRIM_POINTS
Definition: GPU_primitive.h:19
@ GPU_SHADER_KEYFRAME_SHAPE
Definition: GPU_shader.h:192
@ GPU_SHADER_2D_UNIFORM_COLOR
Definition: GPU_shader.h:201
void GPU_program_point_size(bool enable)
Definition: gpu_state.cc:172
@ GPU_BLEND_NONE
Definition: GPU_state.h:60
@ GPU_BLEND_ALPHA
Definition: GPU_state.h:62
void GPU_blend(eGPUBlend blend)
Definition: gpu_state.cc:39
@ GPU_FETCH_FLOAT
@ GPU_FETCH_INT_TO_FLOAT_UNIT
@ GPU_FETCH_INT
uint GPU_vertformat_attr_add(GPUVertFormat *, const char *name, GPUVertCompType, uint comp_len, GPUVertFetchMode)
@ GPU_COMP_F32
@ GPU_COMP_U32
@ GPU_COMP_U8
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 a value between a minimum and a maximum Vector Perform vector math operation Invert a color
#define C
Definition: RandGen.cpp:25
#define UI_UNIT_Y
@ UI_EMBOSS_NONE
Definition: UI_interface.h:109
@ UI_EMBOSS
Definition: UI_interface.h:108
const struct uiStyle * UI_style_get(void)
uiBut * uiDefIconButR_prop(uiBlock *block, int type, int retval, int icon, int x, int y, short width, short height, struct PointerRNA *ptr, struct PropertyRNA *prop, int index, float min, float max, float a1, float a2, const char *tip)
Definition: interface.cc:5570
void UI_block_end(const struct bContext *C, uiBlock *block)
void UI_block_emboss_set(uiBlock *block, eUIEmbossType emboss)
Definition: interface.cc:3629
void UI_block_draw(const struct bContext *C, struct uiBlock *block)
uiBlock * UI_block_begin(const struct bContext *C, struct ARegion *region, const char *name, eUIEmbossType emboss)
#define UI_UNIT_X
@ UI_BTYPE_ICON_TOGGLE
Definition: UI_interface.h:342
void UI_GetThemeColor3fv(int colorid, float col[3])
Definition: resources.c:1165
@ TH_HEADER
Definition: UI_resources.h:50
@ TH_STRIP
Definition: UI_resources.h:138
@ TH_TEXT
Definition: UI_resources.h:42
@ TH_STRIP_SELECT
Definition: UI_resources.h:139
@ TH_TEXT_HI
Definition: UI_resources.h:43
void UI_GetThemeColorShadeAlpha4fv(int colorid, int coloffset, int alphaoffset, float col[4])
Definition: resources.c:1259
void UI_FontThemeColor(int fontid, int colorid)
Definition: resources.c:1134
#define V2D_LOCK_COPY
Definition: UI_view2d.h:82
void UI_view2d_sync(struct bScreen *screen, struct ScrArea *area, struct View2D *v2dcur, int flag)
Definition: view2d.cc:851
#define EXTRA_SCROLL_PAD
unsigned int U
Definition: btGjkEpa3.h:78
static void clip_draw_dopesheet_background(ARegion *region, MovieClip *clip, uint pos_id)
void clip_draw_dopesheet_channels(const bContext *C, ARegion *region)
void clip_draw_dopesheet_main(SpaceClip *sc, ARegion *region, Scene *scene)
static void draw_keyframe_shape(float x, float y, bool sel, float alpha, uint pos_id, uint color_id)
static void track_channel_color(MovieTrackingTrack *track, const float default_color[3], float color[3])
#define CHANNEL_STEP
Definition: clip_intern.h:25
#define STRIP_HEIGHT_HALF
Definition: clip_intern.h:32
#define CHANNEL_PAD
Definition: clip_intern.h:27
#define CHANNEL_HEIGHT
Definition: clip_intern.h:22
#define CHANNEL_FIRST
Definition: clip_intern.h:21
#define CHANNEL_HEIGHT_HALF
Definition: clip_intern.h:23
void clip_draw_sfra_efra(struct View2D *v2d, struct Scene *scene)
Definition: clip_utils.c:609
Scene scene
uint pos
format
Definition: logImageCore.h:38
static void area(int d1, int d2, int e1, int e2, float weights[2])
void RNA_pointer_create(ID *id, StructRNA *type, void *data, PointerRNA *r_ptr)
Definition: rna_access.c:136
PropertyRNA * RNA_struct_type_find_property(StructRNA *srna, const char *identifier)
Definition: rna_access.c:806
void * first
Definition: DNA_listBase.h:31
struct MovieTracking tracking
struct MovieTrackingDopesheetChannel * next
struct MovieTrackingDopesheetCoverageSegment * next
MovieTrackingMarker * markers
MovieTrackingDopesheet dopesheet
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
uiFontStyle widget
PointerRNA * ptr
Definition: wm_files.c:3480