Blender V5.0
clip_dopesheet_draw.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2012 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
10#include "DNA_scene_types.h"
11
12#include "BLI_listbase.h"
13#include "BLI_math_vector.h"
14#include "BLI_rect.h"
15#include "BLI_utildefines.h"
16
17#include "BKE_context.hh"
18#include "BKE_movieclip.h"
19
20#include "ED_anim_api.hh"
21#include "ED_clip.hh"
22#include "ED_screen.hh"
23
24#include "WM_types.hh"
25
26#include "UI_interface.hh"
27#include "UI_resources.hh"
28#include "UI_view2d.hh"
29
30#include "BLF_api.hh"
31
32#include "RNA_access.hh"
33#include "RNA_prototypes.hh"
34
35#include "GPU_immediate.hh"
36#include "GPU_state.hh"
37
38#include "clip_intern.hh" /* own include */
39
40static void track_channel_color(MovieTrackingTrack *track, bool default_color, float color[3])
41{
42 if (track->flag & TRACK_CUSTOMCOLOR) {
43 float bg[3];
45
46 interp_v3_v3v3(color, track->color, bg, 0.5);
47 }
48 else {
49 if (default_color) {
51 }
52 else {
54 }
55 }
56}
57
59 float x, float y, bool sel, float alpha, uint pos_id, uint color_id)
60{
61 float color[4];
62 if (sel) {
64 }
65 else {
67 }
68 color[3] = alpha;
69
70 immAttr4fv(color_id, color);
71 immVertex2f(pos_id, x, y);
72}
73
74static void clip_draw_dopesheet_background(ARegion *region, MovieClip *clip, uint pos_id)
75{
76 View2D *v2d = &region->v2d;
77 MovieTracking *tracking = &clip->tracking;
78 MovieTrackingDopesheet *dopesheet = &tracking->dopesheet;
79
81 MovieTrackingDopesheetCoverageSegment *, coverage_segment, &dopesheet->coverage_segments)
82 {
83 if (coverage_segment->coverage < TRACKING_COVERAGE_OK) {
84 int start_frame = BKE_movieclip_remap_clip_to_scene_frame(clip,
85 coverage_segment->start_frame);
86 int end_frame = BKE_movieclip_remap_clip_to_scene_frame(clip, coverage_segment->end_frame);
87
88 if (coverage_segment->coverage == TRACKING_COVERAGE_BAD) {
89 immUniformColor4f(1.0f, 0.0f, 0.0f, 0.07f);
90 }
91 else {
92 immUniformColor4f(1.0f, 1.0f, 0.0f, 0.07f);
93 }
94
95 immRectf(pos_id, start_frame, v2d->cur.ymin, end_frame, v2d->cur.ymax);
96 }
97 }
98}
99
101{
103 View2D *v2d = &region->v2d;
104
105 /* Frame and preview range. */
107 ANIM_draw_framerange(scene, v2d);
108 ANIM_draw_previewrange(scene, v2d, 0);
109
110 if (clip) {
111 MovieTracking *tracking = &clip->tracking;
112 MovieTrackingDopesheet *dopesheet = &tracking->dopesheet;
113 float strip[4], selected_strip[4];
114 float height = (dopesheet->tot_channel * CHANNEL_STEP) + CHANNEL_HEIGHT;
115
116 uint keyframe_len = 0;
117
119 uint pos_id = GPU_vertformat_attr_add(format, "pos", blender::gpu::VertAttrType::SFLOAT_32_32);
121
122 /* don't use totrect set, as the width stays the same
123 * (NOTE: this is ok here, the configuration is pretty straightforward)
124 */
125 v2d->tot.ymin = (-height);
126
127 float y = (CHANNEL_FIRST);
128
129 /* setup colors for regular and selected strips */
131 UI_GetThemeColor4fv(TH_LONGKEY_SELECT, selected_strip);
132
134
135 clip_draw_dopesheet_background(region, clip, pos_id);
136
138 float yminc = (y - CHANNEL_HEIGHT_HALF);
139 float ymaxc = (y + CHANNEL_HEIGHT_HALF);
140
141 /* check if visible */
142 if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
143 IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax))
144 {
145 MovieTrackingTrack *track = channel->track;
146 int i;
147 bool sel = (track->flag & TRACK_DOPE_SEL) != 0;
148
149 /* selection background */
150 if (sel) {
151 float color[4] = {0.0f, 0.0f, 0.0f, 0.3f};
152
153 track_channel_color(track, true, color);
154 immUniformColor4fv(color);
155
156 immRectf(pos_id,
157 v2d->cur.xmin,
161 }
162
163 /* tracked segments */
164 for (i = 0; i < channel->tot_segment; i++) {
165 int start_frame = BKE_movieclip_remap_clip_to_scene_frame(clip,
166 channel->segments[2 * i]);
167 int end_frame = BKE_movieclip_remap_clip_to_scene_frame(clip,
168 channel->segments[2 * i + 1]);
169
170 immUniformColor4fv(sel ? selected_strip : strip);
171
172 if (start_frame != end_frame) {
173 immRectf(pos_id, start_frame, y - STRIP_HEIGHT_HALF, end_frame, y + STRIP_HEIGHT_HALF);
174 keyframe_len += 2;
175 }
176 else {
177 keyframe_len++;
178 }
179 }
180
181 /* keyframes */
182 i = 0;
183 while (i < track->markersnr) {
184 MovieTrackingMarker *marker = &track->markers[i];
185
186 if ((marker->flag & (MARKER_DISABLED | MARKER_TRACKED)) == 0) {
187 keyframe_len++;
188 }
189
190 i++;
191 }
192 }
193
194 /* adjust y-position for next one */
195 y -= CHANNEL_STEP;
196 }
197
199
200 if (keyframe_len > 0) {
201 /* draw keyframe markers */
203 pos_id = GPU_vertformat_attr_add(format, "pos", blender::gpu::VertAttrType::SFLOAT_32_32);
205 format, "size", blender::gpu::VertAttrType::SFLOAT_32);
206 uint color_id = GPU_vertformat_attr_add(
207 format, "color", blender::gpu::VertAttrType::SFLOAT_32_32_32_32);
208 uint outline_color_id = GPU_vertformat_attr_add(
209 format, "outlineColor", blender::gpu::VertAttrType::UNORM_8_8_8_8);
210 uint flags_id = GPU_vertformat_attr_add(
211 format, "flags", blender::gpu::VertAttrType::UINT_32);
212
215 immUniform1f("outline_scale", 1.0f);
217 "ViewportSize", BLI_rcti_size_x(&v2d->mask) + 1, BLI_rcti_size_y(&v2d->mask) + 1);
218 immBegin(GPU_PRIM_POINTS, keyframe_len);
219
220 /* all same size with black outline */
221 immAttr1f(size_id, 2.0f * STRIP_HEIGHT_HALF);
222 immAttr4ub(outline_color_id, 0, 0, 0, 255);
223 immAttr1u(flags_id, 0);
224
225 y = (CHANNEL_FIRST); /* start again at the top */
227 float yminc = (y - CHANNEL_HEIGHT_HALF);
228 float ymaxc = (y + CHANNEL_HEIGHT_HALF);
229
230 /* check if visible */
231 if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
232 IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax))
233 {
234 MovieTrackingTrack *track = channel->track;
235 int i;
236 bool sel = (track->flag & TRACK_DOPE_SEL) != 0;
237 float alpha = (track->flag & TRACK_LOCKED) ? 0.5f : 1.0f;
238
239 /* tracked segments */
240 for (i = 0; i < channel->tot_segment; i++) {
241 int start_frame = BKE_movieclip_remap_clip_to_scene_frame(clip,
242 channel->segments[2 * i]);
243 int end_frame = BKE_movieclip_remap_clip_to_scene_frame(clip,
244 channel->segments[2 * i + 1]);
245
246 if (start_frame != end_frame) {
247 draw_keyframe_shape(start_frame, y, sel, alpha, pos_id, color_id);
248 draw_keyframe_shape(end_frame, y, sel, alpha, pos_id, color_id);
249 }
250 else {
251 draw_keyframe_shape(start_frame, y, sel, alpha, pos_id, color_id);
252 }
253 }
254
255 /* keyframes */
256 i = 0;
257 while (i < track->markersnr) {
258 MovieTrackingMarker *marker = &track->markers[i];
259
260 if ((marker->flag & (MARKER_DISABLED | MARKER_TRACKED)) == 0) {
261 int framenr = BKE_movieclip_remap_clip_to_scene_frame(clip, marker->framenr);
262
263 draw_keyframe_shape(framenr, y, sel, alpha, pos_id, color_id);
264 }
265
266 i++;
267 }
268 }
269
270 /* adjust y-position for next one */
271 y -= CHANNEL_STEP;
272 }
273
274 immEnd();
277 }
278
280 }
281}
282
284{
285 ScrArea *area = CTX_wm_area(C);
287 View2D *v2d = &region->v2d;
289 const uiStyle *style = UI_style_get();
290 int fontid = style->widget.uifont_id;
291
292 if (!clip) {
293 return;
294 }
295
296 MovieTracking *tracking = &clip->tracking;
297 MovieTrackingDopesheet *dopesheet = &tracking->dopesheet;
298 int height = (dopesheet->tot_channel * CHANNEL_STEP) + CHANNEL_HEIGHT;
299
300 if (height > BLI_rcti_size_y(&v2d->mask)) {
301 /* don't use totrect set, as the width stays the same
302 * (NOTE: this is ok here, the configuration is pretty straightforward)
303 */
304 v2d->tot.ymin = float(-height);
305 }
306
307 /* need to do a view-sync here, so that the keys area doesn't jump around
308 * (it must copy this) */
309 UI_view2d_sync(nullptr, area, v2d, V2D_LOCK_COPY);
310
311 /* loop through channels, and set up drawing depending on their type
312 * first pass: just the standard GL-drawing for backdrop + text
313 */
314 float y = (CHANNEL_FIRST);
315
317 uint pos = GPU_vertformat_attr_add(format, "pos", blender::gpu::VertAttrType::SFLOAT_32_32);
318
320
322 float yminc = (y - CHANNEL_HEIGHT_HALF);
323 float ymaxc = (y + CHANNEL_HEIGHT_HALF);
324
325 /* check if visible */
326 if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
327 IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax))
328 {
329 MovieTrackingTrack *track = channel->track;
330 float color[3];
331 track_channel_color(track, false, color);
332 immUniformColor3fv(color);
333
335 v2d->cur.xmin,
339 }
340
341 /* adjust y-position for next one */
342 y -= CHANNEL_STEP;
343 }
345
346 /* second pass: text */
347 y = (CHANNEL_FIRST);
348
349 BLF_size(fontid, 11.0f * UI_SCALE_FAC);
350
352 float yminc = (y - CHANNEL_HEIGHT_HALF);
353 float ymaxc = (y + CHANNEL_HEIGHT_HALF);
354
355 /* check if visible */
356 if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
357 IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax))
358 {
359 MovieTrackingTrack *track = channel->track;
360 bool sel = (track->flag & TRACK_DOPE_SEL) != 0;
361
362 UI_FontThemeColor(fontid, sel ? TH_TEXT_HI : TH_TEXT);
363
364 float font_height = BLF_height(fontid, channel->name, sizeof(channel->name));
365 BLF_position(fontid, v2d->cur.xmin + CHANNEL_PAD, y - font_height / 2.0f, 0.0f);
366 BLF_draw(fontid, channel->name, strlen(channel->name));
367 }
368
369 /* adjust y-position for next one */
370 y -= CHANNEL_STEP;
371 }
372
373 /* third pass: widgets */
374 uiBlock *block = UI_block_begin(C, region, __func__, blender::ui::EmbossType::Emboss);
375 y = (CHANNEL_FIRST);
376
377 /* get RNA properties (once) */
378 PropertyRNA *chan_prop_lock = RNA_struct_type_find_property(&RNA_MovieTrackingTrack, "lock");
379 BLI_assert(chan_prop_lock);
380
383 float yminc = (y - CHANNEL_HEIGHT_HALF);
384 float ymaxc = (y + CHANNEL_HEIGHT_HALF);
385
386 /* check if visible */
387 if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
388 IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax))
389 {
390 MovieTrackingTrack *track = channel->track;
391 const int icon = (track->flag & TRACK_LOCKED) ? ICON_LOCKED : ICON_UNLOCKED;
392 PointerRNA ptr = RNA_pointer_create_discrete(&clip->id, &RNA_MovieTrackingTrack, track);
393
395 uiDefIconButR_prop(block,
397 1,
398 icon,
399 v2d->cur.xmax - UI_UNIT_X - CHANNEL_PAD,
400 y - UI_UNIT_Y / 2.0f,
401 UI_UNIT_X,
402 UI_UNIT_Y,
403 &ptr,
404 chan_prop_lock,
405 0,
406 0,
407 0,
408 std::nullopt);
410 }
411
412 /* adjust y-position for next one */
413 y -= CHANNEL_STEP;
414 }
416
417 UI_block_end(C, block);
418 UI_block_draw(C, block);
419}
ScrArea * CTX_wm_area(const bContext *C)
SpaceClip * CTX_wm_space_clip(const bContext *C)
float BKE_movieclip_remap_clip_to_scene_frame(const struct MovieClip *clip, float framenr)
void BLF_size(int fontid, float size)
Definition blf.cc:443
float BLF_height(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2)
Definition blf.cc:837
void BLF_draw(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_NONNULL(2)
Definition blf.cc:585
void BLF_position(int fontid, float x, float y, float z)
Definition blf.cc:388
#define BLI_assert(a)
Definition BLI_assert.h:46
#define LISTBASE_FOREACH(type, var, list)
void interp_v3_v3v3(float r[3], const float a[3], const float b[3], float t)
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
Definition BLI_rect.h:198
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
Definition BLI_rect.h:194
unsigned int uint
#define IN_RANGE(a, b, c)
#define UI_SCALE_FAC
@ TRACK_CUSTOMCOLOR
@ TRACK_LOCKED
@ TRACK_DOPE_SEL
@ MARKER_TRACKED
@ MARKER_DISABLED
@ TRACKING_COVERAGE_BAD
@ TRACKING_COVERAGE_OK
MovieClip * ED_space_clip_get_clip(const SpaceClip *sc)
void immEnd()
void immUnbindProgram()
void immAttr4fv(uint attr_id, const float data[4])
void immBindBuiltinProgram(GPUBuiltinShader shader_id)
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 immVertex2f(uint attr_id, float x, float y)
void immAttr1f(uint attr_id, float x)
void immAttr1u(uint attr_id, uint x)
void immUniform1f(const char *name, float x)
GPUVertFormat * immVertexFormat()
void immUniformColor4fv(const float rgba[4])
void immBegin(GPUPrimType, uint vertex_len)
void immUniformColor3fv(const float rgb[3])
void immRectf(uint pos, float x1, float y1, float x2, float y2)
@ GPU_PRIM_POINTS
@ GPU_SHADER_KEYFRAME_SHAPE
@ GPU_SHADER_3D_UNIFORM_COLOR
void GPU_program_point_size(bool enable)
Definition gpu_state.cc:180
@ GPU_BLEND_NONE
Definition GPU_state.hh:85
@ GPU_BLEND_ALPHA
Definition GPU_state.hh:87
void GPU_blend(GPUBlend blend)
Definition gpu_state.cc:42
uint GPU_vertformat_attr_add(GPUVertFormat *format, blender::StringRef name, blender::gpu::VertAttrType type)
#define C
Definition RandGen.cpp:29
#define UI_UNIT_Y
void UI_block_emboss_set(uiBlock *block, blender::ui::EmbossType emboss)
uiBlock * UI_block_begin(const bContext *C, ARegion *region, std::string name, blender::ui::EmbossType emboss)
const uiStyle * UI_style_get()
uiBut * uiDefIconButR_prop(uiBlock *block, ButType type, int retval, int icon, int x, int y, short width, short height, PointerRNA *ptr, PropertyRNA *prop, int index, float min, float max, std::optional< blender::StringRef > tip)
void UI_block_draw(const bContext *C, uiBlock *block)
#define UI_UNIT_X
void UI_block_end(const bContext *C, uiBlock *block)
void UI_GetThemeColor3fv(int colorid, float col[3])
@ TH_KEYTYPE_KEYFRAME
@ TH_HEADER
@ TH_KEYTYPE_KEYFRAME_SELECT
@ TH_CHANNEL
@ TH_CHANNEL_SELECT
@ TH_LONGKEY_SELECT
@ TH_TEXT
@ TH_LONGKEY
@ TH_TEXT_HI
void UI_GetThemeColor4fv(int colorid, float col[4])
void UI_FontThemeColor(int fontid, int colorid)
void UI_view2d_sync(bScreen *screen, ScrArea *area, View2D *v2dcur, int flag)
Definition view2d.cc:865
#define V2D_LOCK_COPY
Definition UI_view2d.hh:85
void UI_view2d_view_ortho(const View2D *v2d)
Definition view2d.cc:1095
#define EXTRA_SCROLL_PAD
void ANIM_draw_previewrange(const Scene *scene, View2D *v2d, int end_frame_width)
Definition anim_draw.cc:82
void ANIM_draw_framerange(Scene *scene, View2D *v2d)
Definition anim_draw.cc:171
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, bool default_color, float color[3])
#define CHANNEL_STEP
#define STRIP_HEIGHT_HALF
#define CHANNEL_PAD
#define CHANNEL_HEIGHT
#define CHANNEL_FIRST
#define CHANNEL_HEIGHT_HALF
nullptr float
uint pos
format
PropertyRNA * RNA_struct_type_find_property(StructRNA *srna, const char *identifier)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
struct MovieTracking tracking
MovieTrackingMarker * markers
MovieTrackingDopesheet dopesheet
float xmax
float xmin
float ymax
float ymin
uiFontStyle widget
i
Definition text_draw.cc:230
PointerRNA * ptr
Definition wm_files.cc:4238