Blender  V2.93
clip_dopesheet_draw.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 "DNA_movieclip_types.h"
25 #include "DNA_scene_types.h"
26 
27 #include "BLI_math.h"
28 #include "BLI_rect.h"
29 #include "BLI_utildefines.h"
30 
31 #include "BKE_context.h"
32 #include "BKE_movieclip.h"
33 
34 #include "ED_clip.h"
35 #include "ED_screen.h"
36 
37 #include "WM_types.h"
38 
39 #include "UI_interface.h"
40 #include "UI_resources.h"
41 #include "UI_view2d.h"
42 
43 #include "BLF_api.h"
44 
45 #include "RNA_access.h"
46 
47 #include "GPU_immediate.h"
48 #include "GPU_state.h"
49 
50 #include "clip_intern.h" /* own include */
51 
53  const float default_color[3],
54  float color[3])
55 {
56  if (track->flag & TRACK_CUSTOMCOLOR) {
57  float bg[3];
59 
60  interp_v3_v3v3(color, track->color, bg, 0.5);
61  }
62  else {
63  if (default_color) {
64  copy_v3_v3(color, default_color);
65  }
66  else {
68  }
69  }
70 }
71 
72 static void draw_keyframe_shape(
73  float x, float y, bool sel, float alpha, uint pos_id, uint color_id)
74 {
75  float color[4] = {0.91f, 0.91f, 0.91f, alpha};
76  if (sel) {
77  UI_GetThemeColorShadeAlpha4fv(TH_STRIP_SELECT, 50, -255 * (1.0f - alpha), color);
78  }
79 
80  immAttr4fv(color_id, color);
81  immVertex2f(pos_id, x, y);
82 }
83 
84 static void clip_draw_dopesheet_background(ARegion *region, MovieClip *clip, uint pos_id)
85 {
86  View2D *v2d = &region->v2d;
87  MovieTracking *tracking = &clip->tracking;
88  MovieTrackingDopesheet *dopesheet = &tracking->dopesheet;
89  MovieTrackingDopesheetCoverageSegment *coverage_segment;
90 
91  for (coverage_segment = dopesheet->coverage_segments.first; coverage_segment;
92  coverage_segment = coverage_segment->next) {
93  if (coverage_segment->coverage < TRACKING_COVERAGE_OK) {
94  int start_frame = BKE_movieclip_remap_clip_to_scene_frame(clip,
95  coverage_segment->start_frame);
96  int end_frame = BKE_movieclip_remap_clip_to_scene_frame(clip, coverage_segment->end_frame);
97 
98  if (coverage_segment->coverage == TRACKING_COVERAGE_BAD) {
99  immUniformColor4f(1.0f, 0.0f, 0.0f, 0.07f);
100  }
101  else {
102  immUniformColor4f(1.0f, 1.0f, 0.0f, 0.07f);
103  }
104 
105  immRectf(pos_id, start_frame, v2d->cur.ymin, end_frame, v2d->cur.ymax);
106  }
107  }
108 }
109 
111 {
112  MovieClip *clip = ED_space_clip_get_clip(sc);
113  View2D *v2d = &region->v2d;
114 
115  /* frame range */
117 
118  if (clip) {
119  MovieTracking *tracking = &clip->tracking;
120  MovieTrackingDopesheet *dopesheet = &tracking->dopesheet;
122  float strip[4], selected_strip[4];
123  float height = (dopesheet->tot_channel * CHANNEL_STEP) + CHANNEL_HEIGHT;
124 
125  uint keyframe_len = 0;
126 
130 
131  /* don't use totrect set, as the width stays the same
132  * (NOTE: this is ok here, the configuration is pretty straightforward)
133  */
134  v2d->tot.ymin = (float)(-height);
135 
136  float y = (float)CHANNEL_FIRST;
137 
138  /* setup colors for regular and selected strips */
140  UI_GetThemeColor3fv(TH_STRIP_SELECT, selected_strip);
141 
142  strip[3] = 0.5f;
143  selected_strip[3] = 1.0f;
144 
146 
147  clip_draw_dopesheet_background(region, clip, pos_id);
148 
149  for (channel = dopesheet->channels.first; channel; channel = channel->next) {
150  float yminc = (float)(y - CHANNEL_HEIGHT_HALF);
151  float ymaxc = (float)(y + CHANNEL_HEIGHT_HALF);
152 
153  /* check if visible */
154  if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
155  IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax)) {
156  MovieTrackingTrack *track = channel->track;
157  int i;
158  bool sel = (track->flag & TRACK_DOPE_SEL) != 0;
159 
160  /* selection background */
161  if (sel) {
162  float color[4] = {0.0f, 0.0f, 0.0f, 0.3f};
163  float default_color[4] = {0.8f, 0.93f, 0.8f, 0.3f};
164 
165  track_channel_color(track, default_color, color);
166  immUniformColor4fv(color);
167 
168  immRectf(pos_id,
169  v2d->cur.xmin,
170  (float)y - CHANNEL_HEIGHT_HALF,
171  v2d->cur.xmax + EXTRA_SCROLL_PAD,
172  (float)y + CHANNEL_HEIGHT_HALF);
173  }
174 
175  /* tracked segments */
176  for (i = 0; i < channel->tot_segment; i++) {
177  int start_frame = BKE_movieclip_remap_clip_to_scene_frame(clip,
178  channel->segments[2 * i]);
179  int end_frame = BKE_movieclip_remap_clip_to_scene_frame(clip,
180  channel->segments[2 * i + 1]);
181 
182  immUniformColor4fv(sel ? selected_strip : strip);
183 
184  if (start_frame != end_frame) {
185  immRectf(pos_id,
186  start_frame,
187  (float)y - STRIP_HEIGHT_HALF,
188  end_frame,
189  (float)y + STRIP_HEIGHT_HALF);
190  keyframe_len += 2;
191  }
192  else {
193  keyframe_len++;
194  }
195  }
196 
197  /* keyframes */
198  i = 0;
199  while (i < track->markersnr) {
200  MovieTrackingMarker *marker = &track->markers[i];
201 
202  if ((marker->flag & (MARKER_DISABLED | MARKER_TRACKED)) == 0) {
203  keyframe_len++;
204  }
205 
206  i++;
207  }
208  }
209 
210  /* adjust y-position for next one */
211  y -= CHANNEL_STEP;
212  }
213 
215 
216  if (keyframe_len > 0) {
217  /* draw keyframe markers */
222  uint outline_color_id = GPU_vertformat_attr_add(
223  format, "outlineColor", GPU_COMP_U8, 4, GPU_FETCH_INT_TO_FLOAT_UNIT);
225 
228  immUniform1f("outline_scale", 1.0f);
229  immUniform2f(
230  "ViewportSize", BLI_rcti_size_x(&v2d->mask) + 1, BLI_rcti_size_y(&v2d->mask) + 1);
231  immBegin(GPU_PRIM_POINTS, keyframe_len);
232 
233  /* all same size with black outline */
234  immAttr1f(size_id, 2.0f * STRIP_HEIGHT_HALF);
235  immAttr4ub(outline_color_id, 0, 0, 0, 255);
236  immAttr1u(flags_id, 0);
237 
238  y = (float)CHANNEL_FIRST; /* start again at the top */
239  for (channel = dopesheet->channels.first; channel; channel = channel->next) {
240  float yminc = (float)(y - CHANNEL_HEIGHT_HALF);
241  float ymaxc = (float)(y + CHANNEL_HEIGHT_HALF);
242 
243  /* check if visible */
244  if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
245  IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax)) {
246  MovieTrackingTrack *track = channel->track;
247  int i;
248  bool sel = (track->flag & TRACK_DOPE_SEL) != 0;
249  float alpha = (track->flag & TRACK_LOCKED) ? 0.5f : 1.0f;
250 
251  /* tracked segments */
252  for (i = 0; i < channel->tot_segment; i++) {
253  int start_frame = BKE_movieclip_remap_clip_to_scene_frame(clip,
254  channel->segments[2 * i]);
255  int end_frame = BKE_movieclip_remap_clip_to_scene_frame(clip,
256  channel->segments[2 * i + 1]);
257 
258  if (start_frame != end_frame) {
259  draw_keyframe_shape(start_frame, y, sel, alpha, pos_id, color_id);
260  draw_keyframe_shape(end_frame, y, sel, alpha, pos_id, color_id);
261  }
262  else {
263  draw_keyframe_shape(start_frame, y, sel, alpha, pos_id, color_id);
264  }
265  }
266 
267  /* keyframes */
268  i = 0;
269  while (i < track->markersnr) {
270  MovieTrackingMarker *marker = &track->markers[i];
271 
272  if ((marker->flag & (MARKER_DISABLED | MARKER_TRACKED)) == 0) {
273  int framenr = BKE_movieclip_remap_clip_to_scene_frame(clip, marker->framenr);
274 
275  draw_keyframe_shape(framenr, y, sel, alpha, pos_id, color_id);
276  }
277 
278  i++;
279  }
280  }
281 
282  /* adjust y-position for next one */
283  y -= CHANNEL_STEP;
284  }
285 
286  immEnd();
287  GPU_program_point_size(false);
289  }
290 
292  }
293 }
294 
296 {
299  View2D *v2d = &region->v2d;
300  MovieClip *clip = ED_space_clip_get_clip(sc);
301  const uiStyle *style = UI_style_get();
302  int fontid = style->widget.uifont_id;
303 
304  if (!clip) {
305  return;
306  }
307 
308  MovieTracking *tracking = &clip->tracking;
309  MovieTrackingDopesheet *dopesheet = &tracking->dopesheet;
310  int height = (dopesheet->tot_channel * CHANNEL_STEP) + CHANNEL_HEIGHT;
311 
312  if (height > BLI_rcti_size_y(&v2d->mask)) {
313  /* don't use totrect set, as the width stays the same
314  * (NOTE: this is ok here, the configuration is pretty straightforward)
315  */
316  v2d->tot.ymin = (float)(-height);
317  }
318 
319  /* need to do a view-sync here, so that the keys area doesn't jump around
320  * (it must copy this) */
322 
323  /* loop through channels, and set up drawing depending on their type
324  * first pass: just the standard GL-drawing for backdrop + text
325  */
326  float y = (float)CHANNEL_FIRST;
327 
330 
332 
334  for (channel = dopesheet->channels.first; channel; channel = channel->next) {
335  float yminc = (float)(y - CHANNEL_HEIGHT_HALF);
336  float ymaxc = (float)(y + CHANNEL_HEIGHT_HALF);
337 
338  /* check if visible */
339  if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
340  IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax)) {
341  MovieTrackingTrack *track = channel->track;
342  float color[3];
343  track_channel_color(track, NULL, color);
344  immUniformColor3fv(color);
345 
346  immRectf(pos,
347  v2d->cur.xmin,
348  (float)y - CHANNEL_HEIGHT_HALF,
349  v2d->cur.xmax + EXTRA_SCROLL_PAD,
350  (float)y + CHANNEL_HEIGHT_HALF);
351  }
352 
353  /* adjust y-position for next one */
354  y -= CHANNEL_STEP;
355  }
357 
358  /* second pass: text */
359  y = (float)CHANNEL_FIRST;
360 
361  BLF_size(fontid, 11.0f * U.pixelsize, U.dpi);
362 
363  for (channel = dopesheet->channels.first; channel; channel = channel->next) {
364  float yminc = (float)(y - CHANNEL_HEIGHT_HALF);
365  float ymaxc = (float)(y + CHANNEL_HEIGHT_HALF);
366 
367  /* check if visible */
368  if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
369  IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax)) {
370  MovieTrackingTrack *track = channel->track;
371  bool sel = (track->flag & TRACK_DOPE_SEL) != 0;
372 
373  UI_FontThemeColor(fontid, sel ? TH_TEXT_HI : TH_TEXT);
374 
375  float font_height = BLF_height(fontid, channel->name, sizeof(channel->name));
376  BLF_position(fontid, v2d->cur.xmin + CHANNEL_PAD, y - font_height / 2.0f, 0.0f);
377  BLF_draw(fontid, channel->name, strlen(channel->name));
378  }
379 
380  /* adjust y-position for next one */
381  y -= CHANNEL_STEP;
382  }
383 
384  /* third pass: widgets */
385  uiBlock *block = UI_block_begin(C, region, __func__, UI_EMBOSS);
386  y = (float)CHANNEL_FIRST;
387 
388  /* get RNA properties (once) */
390  BLI_assert(chan_prop_lock);
391 
393  for (channel = dopesheet->channels.first; channel; channel = channel->next) {
394  float yminc = (float)(y - CHANNEL_HEIGHT_HALF);
395  float ymaxc = (float)(y + CHANNEL_HEIGHT_HALF);
396 
397  /* check if visible */
398  if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
399  IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax)) {
400  MovieTrackingTrack *track = channel->track;
401  const int icon = (track->flag & TRACK_LOCKED) ? ICON_LOCKED : ICON_UNLOCKED;
402  PointerRNA ptr;
403 
404  RNA_pointer_create(&clip->id, &RNA_MovieTrackingTrack, track, &ptr);
405 
407  uiDefIconButR_prop(block,
409  1,
410  icon,
411  v2d->cur.xmax - UI_UNIT_X - CHANNEL_PAD,
412  y - UI_UNIT_Y / 2.0f,
413  UI_UNIT_X,
414  UI_UNIT_Y,
415  &ptr,
416  chan_prop_lock,
417  0,
418  0,
419  0,
420  0,
421  0,
422  NULL);
424  }
425 
426  /* adjust y-position for next one */
427  y -= CHANNEL_STEP;
428  }
430 
431  UI_block_end(C, block);
432  UI_block_draw(C, block);
433 }
typedef float(TangentPoint)[2]
struct ScrArea * CTX_wm_area(const bContext *C)
Definition: context.c:714
struct SpaceClip * CTX_wm_space_clip(const bContext *C)
Definition: context.c:899
float BKE_movieclip_remap_clip_to_scene_frame(const struct MovieClip *clip, float framenr)
void BLF_draw(int fontid, const char *str, size_t len) ATTR_NONNULL(2)
Definition: blf.c:542
float BLF_height(int fontid, const char *str, size_t len) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: blf.c:752
void BLF_size(int fontid, int size, int dpi)
Definition: blf.c:367
void BLF_position(int fontid, float x, float y, float z)
Definition: blf.c:312
#define BLI_assert(a)
Definition: BLI_assert.h:58
void interp_v3_v3v3(float r[3], const float a[3], const float b[3], const float t)
Definition: math_vector.c:49
MINLINE void copy_v3_v3(float r[3], const float a[3])
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
Definition: BLI_rect.h:157
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
Definition: BLI_rect.h:153
unsigned int uint
Definition: BLI_sys_types.h:83
#define IN_RANGE(a, b, c)
@ TRACK_CUSTOMCOLOR
@ TRACK_LOCKED
@ TRACK_DOPE_SEL
@ MARKER_TRACKED
@ MARKER_DISABLED
@ TRACKING_COVERAGE_BAD
@ TRACKING_COVERAGE_OK
struct MovieClip * ED_space_clip_get_clip(struct SpaceClip *sc)
Definition: clip_editor.c:572
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:35
@ GPU_SHADER_2D_UNIFORM_COLOR
Definition: GPU_shader.h:171
@ GPU_SHADER_KEYFRAME_DIAMOND
Definition: GPU_shader.h:162
void GPU_program_point_size(bool enable)
Definition: gpu_state.cc:191
@ GPU_BLEND_NONE
Definition: GPU_state.h:55
@ GPU_BLEND_ALPHA
Definition: GPU_state.h:57
void GPU_blend(eGPUBlend blend)
Definition: gpu_state.cc:55
@ 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
StructRNA RNA_MovieTrackingTrack
#define C
Definition: RandGen.cpp:39
#define UI_UNIT_Y
@ UI_EMBOSS_NONE
Definition: UI_interface.h:108
@ UI_EMBOSS
Definition: UI_interface.h:107
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.c:5549
void UI_block_end(const struct bContext *C, uiBlock *block)
void UI_block_emboss_set(uiBlock *block, eUIEmbossType emboss)
Definition: interface.c:3542
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:346
void UI_GetThemeColor3fv(int colorid, float col[3])
Definition: resources.c:1191
@ TH_HEADER
Definition: UI_resources.h:66
@ TH_STRIP
Definition: UI_resources.h:154
@ TH_TEXT
Definition: UI_resources.h:58
@ TH_STRIP_SELECT
Definition: UI_resources.h:155
@ TH_TEXT_HI
Definition: UI_resources.h:59
void UI_GetThemeColorShadeAlpha4fv(int colorid, int coloffset, int alphaoffset, float col[4])
Definition: resources.c:1286
void UI_FontThemeColor(int fontid, int colorid)
Definition: resources.c:1156
#define V2D_LOCK_COPY
Definition: UI_view2d.h:84
void UI_view2d_sync(struct bScreen *screen, struct ScrArea *area, struct View2D *v2dcur, int flag)
Definition: view2d.c:876
#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:41
#define STRIP_HEIGHT_HALF
Definition: clip_intern.h:48
#define CHANNEL_PAD
Definition: clip_intern.h:43
#define CHANNEL_HEIGHT
Definition: clip_intern.h:38
#define CHANNEL_FIRST
Definition: clip_intern.h:37
#define CHANNEL_HEIGHT_HALF
Definition: clip_intern.h:39
void clip_draw_sfra_efra(struct View2D *v2d, struct Scene *scene)
Definition: clip_utils.c:628
Scene scene
static CCL_NAMESPACE_BEGIN const double alpha
uint pos
format
Definition: logImageCore.h:47
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:146
PropertyRNA * RNA_struct_type_find_property(StructRNA *srna, const char *identifier)
Definition: rna_access.c:953
void * first
Definition: DNA_listBase.h:47
struct MovieTracking tracking
struct MovieTrackingDopesheetChannel * next
struct MovieTrackingDopesheetCoverageSegment * next
MovieTrackingMarker * markers
MovieTrackingDopesheet dopesheet
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
uiFontStyle widget
PointerRNA * ptr
Definition: wm_files.c:3157