Blender V5.3
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.hh"
13#include "BLI_math_vector_c.hh"
14#include "BLI_rect.hh"
15#include "BLI_utildefines.hh"
16
17#include "BKE_context.hh"
18#include "BKE_movieclip.hh"
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
40namespace blender {
41
42static void track_channel_color(MovieTrackingTrack *track, bool default_color, float color[3])
43{
44 if (track->flag & TRACK_CUSTOMCOLOR) {
45 float bg[3];
47
48 interp_v3_v3v3(color, track->color, bg, 0.5);
49 }
50 else {
51 if (default_color) {
53 }
54 else {
56 }
57 }
58}
59
61 float x, float y, bool sel, float alpha, uint pos_id, uint color_id)
62{
63 float color[4];
64 if (sel) {
66 }
67 else {
69 }
70 color[3] = alpha;
71
72 immAttr4fv(color_id, color);
73 immVertex2f(pos_id, x, y);
74}
75
76static void clip_draw_dopesheet_background(ARegion *region, MovieClip *clip, uint pos_id)
77{
78 View2D *v2d = &region->v2d;
79 MovieTracking *tracking = &clip->tracking;
80 MovieTrackingDopesheet *dopesheet = &tracking->dopesheet;
81
82 for (MovieTrackingDopesheetCoverageSegment &coverage_segment : dopesheet->coverage_segments) {
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
118 GPUVertFormat *format = immVertexFormat();
119 uint pos_id = GPU_vertformat_attr_add(format, "pos", 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 */
132
134
135 clip_draw_dopesheet_background(region, clip, pos_id);
136
137 for (MovieTrackingDopesheetChannel &channel : dopesheet->channels) {
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);
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, channel.segments[2 * i]);
166 int end_frame = BKE_movieclip_remap_clip_to_scene_frame(clip,
167 channel.segments[2 * i + 1]);
168
169 immUniformColor4fv(sel ? selected_strip : strip);
170
171 if (start_frame != end_frame) {
172 immRectf(pos_id, start_frame, y - STRIP_HEIGHT_HALF, end_frame, y + STRIP_HEIGHT_HALF);
173 keyframe_len += 2;
174 }
175 else {
176 keyframe_len++;
177 }
178 }
179
180 /* keyframes */
181 i = 0;
182 while (i < track->markersnr) {
183 MovieTrackingMarker *marker = &track->markers[i];
184
185 if ((marker->flag & (MARKER_DISABLED | MARKER_TRACKED)) == 0) {
186 keyframe_len++;
187 }
188
189 i++;
190 }
191 }
192
193 /* adjust y-position for next one */
194 y -= CHANNEL_STEP;
195 }
196
198
199 if (keyframe_len > 0) {
200 /* draw keyframe markers */
201 format = immVertexFormat();
202 pos_id = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
203 uint size_id = GPU_vertformat_attr_add(format, "size", gpu::VertAttrType::SFLOAT_32);
204 uint color_id = GPU_vertformat_attr_add(
205 format, "color", gpu::VertAttrType::SFLOAT_32_32_32_32);
206 uint outline_color_id = GPU_vertformat_attr_add(
207 format, "outlineColor", gpu::VertAttrType::UNORM_8_8_8_8);
208 uint flags_id = GPU_vertformat_attr_add(format, "flags", gpu::VertAttrType::UINT_32);
209
212 immUniform1f("outline_scale", 1.0f);
214 "ViewportSize", BLI_rcti_size_x(&v2d->mask) + 1, BLI_rcti_size_y(&v2d->mask) + 1);
215 immBegin(GPU_PRIM_POINTS, keyframe_len);
216
217 /* all same size with black outline */
218 immAttr1f(size_id, 2.0f * STRIP_HEIGHT_HALF);
219 immAttr4ub(outline_color_id, 0, 0, 0, 255);
220 immAttr1u(flags_id, 0);
221
222 y = (CHANNEL_FIRST); /* start again at the top */
223 for (MovieTrackingDopesheetChannel &channel : dopesheet->channels) {
224 float yminc = (y - CHANNEL_HEIGHT_HALF);
225 float ymaxc = (y + CHANNEL_HEIGHT_HALF);
226
227 /* check if visible */
228 if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
229 IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax))
230 {
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();
274 }
275
277 }
278}
279
281{
282 ScrArea *area = CTX_wm_area(C);
284 View2D *v2d = &region->v2d;
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) */
306 ui::view2d_sync(nullptr, area, v2d, V2D_LOCK_COPY);
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 = (CHANNEL_FIRST);
312
313 GPUVertFormat *format = immVertexFormat();
314 uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
315
317
318 for (MovieTrackingDopesheetChannel &channel : dopesheet->channels) {
319 float yminc = (y - CHANNEL_HEIGHT_HALF);
320 float ymaxc = (y + CHANNEL_HEIGHT_HALF);
321
322 /* check if visible */
323 if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
324 IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax))
325 {
326 MovieTrackingTrack *track = channel.track;
327 float color[3];
328 track_channel_color(track, false, color);
330
331 immRectf(pos,
332 v2d->cur.xmin,
336 }
337
338 /* adjust y-position for next one */
339 y -= CHANNEL_STEP;
340 }
342
343 /* second pass: text */
344 y = (CHANNEL_FIRST);
345
346 BLF_size(fontid, 11.0f * UI_SCALE_FAC);
347
348 for (MovieTrackingDopesheetChannel &channel : dopesheet->channels) {
349 float yminc = (y - CHANNEL_HEIGHT_HALF);
350 float ymaxc = (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 {
356 MovieTrackingTrack *track = channel.track;
357 bool sel = (track->flag & TRACK_DOPE_SEL) != 0;
358
360
361 float font_height = BLF_height(fontid, channel.name, sizeof(channel.name));
362 BLF_position(fontid, v2d->cur.xmin + CHANNEL_PAD, y - font_height / 2.0f, 0.0f);
363 BLF_draw(fontid, channel.name, strlen(channel.name));
364 }
365
366 /* adjust y-position for next one */
367 y -= CHANNEL_STEP;
368 }
369
370 /* third pass: widgets */
371 ui::Block *block = block_begin(C, region, __func__, ui::EmbossType::Emboss);
372 y = (CHANNEL_FIRST);
373
374 /* get RNA properties (once) */
375 PropertyRNA *chan_prop_lock = RNA_struct_type_find_property(RNA_MovieTrackingTrack, "lock");
376 BLI_assert(chan_prop_lock);
377
379 for (MovieTrackingDopesheetChannel &channel : dopesheet->channels) {
380 float yminc = (y - CHANNEL_HEIGHT_HALF);
381 float ymaxc = (y + CHANNEL_HEIGHT_HALF);
382
383 /* check if visible */
384 if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
385 IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax))
386 {
387 MovieTrackingTrack *track = channel.track;
388 const int icon = (track->flag & TRACK_LOCKED) ? ICON_LOCKED : ICON_UNLOCKED;
389 PointerRNA ptr = RNA_pointer_create_discrete(&clip->id, RNA_MovieTrackingTrack, track);
390
391 block_emboss_set(block, ui::EmbossType::None);
392 uiDefIconButR_prop(block,
394 icon,
395 v2d->cur.xmax - UI_UNIT_X - CHANNEL_PAD,
396 y - UI_UNIT_Y / 2.0f,
397 UI_UNIT_X,
398 UI_UNIT_Y,
399 &ptr,
400 chan_prop_lock,
401 0,
402 0,
403 0,
404 std::nullopt);
405 block_emboss_set(block, ui::EmbossType::Emboss);
406 }
407
408 /* adjust y-position for next one */
409 y -= CHANNEL_STEP;
410 }
412
413 block_end(C, block);
414 block_draw(C, block);
415}
416
417} // namespace blender
#define UI_SCALE_FAC
#define C
Definition RandGen.cpp:29
#define UI_UNIT_Y
#define UI_UNIT_X
#define V2D_LOCK_COPY
Definition UI_view2d.hh:110
#define EXTRA_SCROLL_PAD
#define IN_RANGE(a, b, c)
#define CHANNEL_STEP
#define STRIP_HEIGHT_HALF
#define CHANNEL_PAD
#define CHANNEL_HEIGHT
#define CHANNEL_FIRST
#define CHANNEL_HEIGHT_HALF
void font_theme_color_set(int fontid, int colorid)
void get_color_3fv(int colorid, float col[3])
void get_color_4fv(int colorid, float col[4])
void view2d_view_ortho(const View2D *v2d)
Definition view2d.cc:1080
const uiStyle * style_get()
void view2d_sync(bScreen *screen, ScrArea *area, View2D *v2dcur, int flag)
Definition view2d.cc:850
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void ANIM_draw_framerange(Scene *scene, View2D *v2d)
Definition anim_draw.cc:176
ScrArea * CTX_wm_area(const bContext *C)
void BLF_position(int fontid, float x, float y, float z)
Definition blf.cc:390
void immEnd()
unsigned int uint
Definition BKE_text.h:55
void draw_keyframe_shape(const float x, const float y, float size, const bool sel, const eBezTriple_KeyframeType key_type, const eKeyframeShapeDrawOpts mode, const float alpha, const KeyframeShaderBindings *sh_bindings, const short handle_type, const short extreme_type)
void immUniform2f(const char *name, float x, float y)
GPUVertFormat * immVertexFormat()
SpaceClip * CTX_wm_space_clip(const bContext *C)
void immBegin(GPUPrimType, uint vertex_len)
static void track_channel_color(MovieTrackingTrack *track, bool default_color, float color[3])
@ TH_LONGKEY_SELECT
@ TH_KEYTYPE_KEYFRAME_SELECT
@ TH_CHANNEL_SELECT
@ TH_KEYTYPE_KEYFRAME
void immUniformColor4fv(const float rgba[4])
void immUnbindProgram()
@ GPU_BLEND_NONE
Definition GPU_state.hh:88
@ GPU_BLEND_ALPHA
Definition GPU_state.hh:90
void immBindBuiltinProgram(GPUBuiltinShader shader_id)
void BLF_size(int fontid, float size)
Definition blf.cc:445
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
Definition BLI_rect.hh:207
void immUniform1f(const char *name, float x)
void immVertex2f(uint attr_id, float x, float y)
void immAttr4fv(uint attr_id, const float data[4])
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:870
void immUniformColor4f(float r, float g, float b, float a)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
void GPU_program_point_size(bool enable)
Definition gpu_state.cc:165
PropertyRNA * RNA_struct_type_find_property(StructRNA *srna, const char *identifier)
void interp_v3_v3v3(float r[3], const float a[3], const float b[3], float t)
void ANIM_draw_previewrange(const Scene *scene, View2D *v2d, int end_frame_width)
Definition anim_draw.cc:88
void BLF_draw(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_NONNULL(2)
Definition blf.cc:587
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
Definition BLI_rect.hh:203
void immAttr4ub(uint attr_id, unsigned char r, unsigned char g, unsigned char b, unsigned char a)
void immAttr1f(uint attr_id, float x)
MovieClip * ED_space_clip_get_clip(const SpaceClip *sc)
float BKE_movieclip_remap_clip_to_scene_frame(const MovieClip *clip, float framenr)
void immAttr1u(uint attr_id, uint x)
void immUniformColor3fv(const float rgb[3])
void GPU_blend(GPUBlend blend)
Definition gpu_state.cc:44
void clip_draw_dopesheet_channels(const bContext *C, ARegion *region)
void immRectf(uint pos, float x1, float y1, float x2, float y2)
static void clip_draw_dopesheet_background(ARegion *region, MovieClip *clip, uint pos_id)
void clip_draw_dopesheet_main(SpaceClip *sc, ARegion *region, Scene *scene)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
struct MovieTracking tracking
ListBaseT< MovieTrackingDopesheetCoverageSegment > coverage_segments
ListBaseT< MovieTrackingDopesheetChannel > channels
MovieTrackingMarker * markers
MovieTrackingDopesheet dopesheet
uiFontStyle widget