Blender V4.5
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
41 const float default_color[3],
42 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) {
52 copy_v3_v3(color, 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] = {0.91f, 0.91f, 0.91f, alpha};
64 if (sel) {
65 UI_GetThemeColorShadeAlpha4fv(TH_STRIP_SELECT, 50, -255 * (1.0f - alpha), color);
66 }
67
68 immAttr4fv(color_id, color);
69 immVertex2f(pos_id, x, y);
70}
71
72static void clip_draw_dopesheet_background(ARegion *region, MovieClip *clip, uint pos_id)
73{
74 View2D *v2d = &region->v2d;
75 MovieTracking *tracking = &clip->tracking;
76 MovieTrackingDopesheet *dopesheet = &tracking->dopesheet;
77
79 MovieTrackingDopesheetCoverageSegment *, coverage_segment, &dopesheet->coverage_segments)
80 {
81 if (coverage_segment->coverage < TRACKING_COVERAGE_OK) {
82 int start_frame = BKE_movieclip_remap_clip_to_scene_frame(clip,
83 coverage_segment->start_frame);
84 int end_frame = BKE_movieclip_remap_clip_to_scene_frame(clip, coverage_segment->end_frame);
85
86 if (coverage_segment->coverage == TRACKING_COVERAGE_BAD) {
87 immUniformColor4f(1.0f, 0.0f, 0.0f, 0.07f);
88 }
89 else {
90 immUniformColor4f(1.0f, 1.0f, 0.0f, 0.07f);
91 }
92
93 immRectf(pos_id, start_frame, v2d->cur.ymin, end_frame, v2d->cur.ymax);
94 }
95 }
96}
97
99{
101 View2D *v2d = &region->v2d;
102
103 /* Frame and preview range. */
105 ANIM_draw_framerange(scene, v2d);
106 ANIM_draw_previewrange(scene, v2d, 0);
107
108 if (clip) {
109 MovieTracking *tracking = &clip->tracking;
110 MovieTrackingDopesheet *dopesheet = &tracking->dopesheet;
111 float strip[4], selected_strip[4];
112 float height = (dopesheet->tot_channel * CHANNEL_STEP) + CHANNEL_HEIGHT;
113
114 uint keyframe_len = 0;
115
119
120 /* don't use totrect set, as the width stays the same
121 * (NOTE: this is ok here, the configuration is pretty straightforward)
122 */
123 v2d->tot.ymin = (-height);
124
125 float y = (CHANNEL_FIRST);
126
127 /* setup colors for regular and selected strips */
129 UI_GetThemeColor3fv(TH_STRIP_SELECT, selected_strip);
130
131 strip[3] = 0.5f;
132 selected_strip[3] = 1.0f;
133
135
136 clip_draw_dopesheet_background(region, clip, pos_id);
137
139 float yminc = (y - CHANNEL_HEIGHT_HALF);
140 float ymaxc = (y + CHANNEL_HEIGHT_HALF);
141
142 /* check if visible */
143 if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
144 IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax))
145 {
146 MovieTrackingTrack *track = channel->track;
147 int i;
148 bool sel = (track->flag & TRACK_DOPE_SEL) != 0;
149
150 /* selection background */
151 if (sel) {
152 float color[4] = {0.0f, 0.0f, 0.0f, 0.3f};
153 float default_color[4] = {0.8f, 0.93f, 0.8f, 0.3f};
154
155 track_channel_color(track, default_color, color);
156 immUniformColor4fv(color);
157
158 immRectf(pos_id,
159 v2d->cur.xmin,
163 }
164
165 /* tracked segments */
166 for (i = 0; i < channel->tot_segment; i++) {
167 int start_frame = BKE_movieclip_remap_clip_to_scene_frame(clip,
168 channel->segments[2 * i]);
169 int end_frame = BKE_movieclip_remap_clip_to_scene_frame(clip,
170 channel->segments[2 * i + 1]);
171
172 immUniformColor4fv(sel ? selected_strip : strip);
173
174 if (start_frame != end_frame) {
175 immRectf(pos_id, start_frame, y - STRIP_HEIGHT_HALF, end_frame, y + STRIP_HEIGHT_HALF);
176 keyframe_len += 2;
177 }
178 else {
179 keyframe_len++;
180 }
181 }
182
183 /* keyframes */
184 i = 0;
185 while (i < track->markersnr) {
186 MovieTrackingMarker *marker = &track->markers[i];
187
188 if ((marker->flag & (MARKER_DISABLED | MARKER_TRACKED)) == 0) {
189 keyframe_len++;
190 }
191
192 i++;
193 }
194 }
195
196 /* adjust y-position for next one */
197 y -= CHANNEL_STEP;
198 }
199
201
202 if (keyframe_len > 0) {
203 /* draw keyframe markers */
208 uint outline_color_id = GPU_vertformat_attr_add(
209 format, "outlineColor", GPU_COMP_U8, 4, GPU_FETCH_INT_TO_FLOAT_UNIT);
211
214 immUniform1f("outline_scale", 1.0f);
216 "ViewportSize", BLI_rcti_size_x(&v2d->mask) + 1, BLI_rcti_size_y(&v2d->mask) + 1);
217 immBegin(GPU_PRIM_POINTS, keyframe_len);
218
219 /* all same size with black outline */
220 immAttr1f(size_id, 2.0f * STRIP_HEIGHT_HALF);
221 immAttr4ub(outline_color_id, 0, 0, 0, 255);
222 immAttr1u(flags_id, 0);
223
224 y = (CHANNEL_FIRST); /* start again at the top */
226 float yminc = (y - CHANNEL_HEIGHT_HALF);
227 float ymaxc = (y + CHANNEL_HEIGHT_HALF);
228
229 /* check if visible */
230 if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
231 IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax))
232 {
233 MovieTrackingTrack *track = channel->track;
234 int i;
235 bool sel = (track->flag & TRACK_DOPE_SEL) != 0;
236 float alpha = (track->flag & TRACK_LOCKED) ? 0.5f : 1.0f;
237
238 /* tracked segments */
239 for (i = 0; i < channel->tot_segment; i++) {
240 int start_frame = BKE_movieclip_remap_clip_to_scene_frame(clip,
241 channel->segments[2 * i]);
242 int end_frame = BKE_movieclip_remap_clip_to_scene_frame(clip,
243 channel->segments[2 * i + 1]);
244
245 if (start_frame != end_frame) {
246 draw_keyframe_shape(start_frame, y, sel, alpha, pos_id, color_id);
247 draw_keyframe_shape(end_frame, y, sel, alpha, pos_id, color_id);
248 }
249 else {
250 draw_keyframe_shape(start_frame, y, sel, alpha, pos_id, color_id);
251 }
252 }
253
254 /* keyframes */
255 i = 0;
256 while (i < track->markersnr) {
257 MovieTrackingMarker *marker = &track->markers[i];
258
259 if ((marker->flag & (MARKER_DISABLED | MARKER_TRACKED)) == 0) {
260 int framenr = BKE_movieclip_remap_clip_to_scene_frame(clip, marker->framenr);
261
262 draw_keyframe_shape(framenr, y, sel, alpha, pos_id, color_id);
263 }
264
265 i++;
266 }
267 }
268
269 /* adjust y-position for next one */
270 y -= CHANNEL_STEP;
271 }
272
273 immEnd();
276 }
277
279 }
280}
281
283{
284 ScrArea *area = CTX_wm_area(C);
286 View2D *v2d = &region->v2d;
288 const uiStyle *style = UI_style_get();
289 int fontid = style->widget.uifont_id;
290
291 if (!clip) {
292 return;
293 }
294
295 MovieTracking *tracking = &clip->tracking;
296 MovieTrackingDopesheet *dopesheet = &tracking->dopesheet;
297 int height = (dopesheet->tot_channel * CHANNEL_STEP) + CHANNEL_HEIGHT;
298
299 if (height > BLI_rcti_size_y(&v2d->mask)) {
300 /* don't use totrect set, as the width stays the same
301 * (NOTE: this is ok here, the configuration is pretty straightforward)
302 */
303 v2d->tot.ymin = float(-height);
304 }
305
306 /* need to do a view-sync here, so that the keys area doesn't jump around
307 * (it must copy this) */
308 UI_view2d_sync(nullptr, area, v2d, V2D_LOCK_COPY);
309
310 /* loop through channels, and set up drawing depending on their type
311 * first pass: just the standard GL-drawing for backdrop + text
312 */
313 float y = (CHANNEL_FIRST);
314
317
319
321 float yminc = (y - CHANNEL_HEIGHT_HALF);
322 float ymaxc = (y + CHANNEL_HEIGHT_HALF);
323
324 /* check if visible */
325 if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
326 IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax))
327 {
328 MovieTrackingTrack *track = channel->track;
329 float color[3];
330 track_channel_color(track, nullptr, color);
331 immUniformColor3fv(color);
332
334 v2d->cur.xmin,
338 }
339
340 /* adjust y-position for next one */
341 y -= CHANNEL_STEP;
342 }
344
345 /* second pass: text */
346 y = (CHANNEL_FIRST);
347
348 BLF_size(fontid, 11.0f * UI_SCALE_FAC);
349
351 float yminc = (y - CHANNEL_HEIGHT_HALF);
352 float ymaxc = (y + CHANNEL_HEIGHT_HALF);
353
354 /* check if visible */
355 if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
356 IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax))
357 {
358 MovieTrackingTrack *track = channel->track;
359 bool sel = (track->flag & TRACK_DOPE_SEL) != 0;
360
361 UI_FontThemeColor(fontid, sel ? TH_TEXT_HI : TH_TEXT);
362
363 float font_height = BLF_height(fontid, channel->name, sizeof(channel->name));
364 BLF_position(fontid, v2d->cur.xmin + CHANNEL_PAD, y - font_height / 2.0f, 0.0f);
365 BLF_draw(fontid, channel->name, strlen(channel->name));
366 }
367
368 /* adjust y-position for next one */
369 y -= CHANNEL_STEP;
370 }
371
372 /* third pass: widgets */
373 uiBlock *block = UI_block_begin(C, region, __func__, blender::ui::EmbossType::Emboss);
374 y = (CHANNEL_FIRST);
375
376 /* get RNA properties (once) */
377 PropertyRNA *chan_prop_lock = RNA_struct_type_find_property(&RNA_MovieTrackingTrack, "lock");
378 BLI_assert(chan_prop_lock);
379
382 float yminc = (y - CHANNEL_HEIGHT_HALF);
383 float ymaxc = (y + CHANNEL_HEIGHT_HALF);
384
385 /* check if visible */
386 if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
387 IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax))
388 {
389 MovieTrackingTrack *track = channel->track;
390 const int icon = (track->flag & TRACK_LOCKED) ? ICON_LOCKED : ICON_UNLOCKED;
391 PointerRNA ptr = RNA_pointer_create_discrete(&clip->id, &RNA_MovieTrackingTrack, track);
392
394 uiDefIconButR_prop(block,
396 1,
397 icon,
398 v2d->cur.xmax - UI_UNIT_X - CHANNEL_PAD,
399 y - UI_UNIT_Y / 2.0f,
400 UI_UNIT_X,
401 UI_UNIT_Y,
402 &ptr,
403 chan_prop_lock,
404 0,
405 0,
406 0,
407 std::nullopt);
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}
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:440
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:840
void BLF_draw(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_NONNULL(2)
Definition blf.cc:582
void BLF_position(int fontid, float x, float y, float z)
Definition blf.cc:385
#define BLI_assert(a)
Definition BLI_assert.h:46
#define LISTBASE_FOREACH(type, var, list)
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)
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
@ MARKER_TRACKED
@ MARKER_DISABLED
@ TRACKING_COVERAGE_BAD
@ TRACKING_COVERAGE_OK
@ TRACK_CUSTOMCOLOR
@ TRACK_LOCKED
@ TRACK_DOPE_SEL
MovieClip * ED_space_clip_get_clip(const SpaceClip *sc)
void immEnd()
void immUnbindProgram()
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 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)
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(eGPUBlend blend)
Definition gpu_state.cc:42
@ GPU_FETCH_FLOAT
@ GPU_FETCH_INT_TO_FLOAT_UNIT
@ GPU_FETCH_INT
uint GPU_vertformat_attr_add(GPUVertFormat *, blender::StringRef name, GPUVertCompType, uint comp_len, GPUVertFetchMode)
@ GPU_COMP_F32
@ GPU_COMP_U32
@ GPU_COMP_U8
#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()
void UI_block_draw(const bContext *C, uiBlock *block)
uiBut * uiDefIconButR_prop(uiBlock *block, int 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)
#define UI_UNIT_X
@ UI_BTYPE_ICON_TOGGLE
void UI_block_end(const bContext *C, uiBlock *block)
void UI_GetThemeColor3fv(int colorid, float col[3])
@ TH_HEADER
@ TH_STRIP
@ TH_TEXT
@ TH_STRIP_SELECT
@ TH_TEXT_HI
void UI_GetThemeColorShadeAlpha4fv(int colorid, int coloffset, int alphaoffset, 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:75
void ANIM_draw_framerange(Scene *scene, View2D *v2d)
Definition anim_draw.cc:109
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
#define STRIP_HEIGHT_HALF
#define CHANNEL_PAD
#define CHANNEL_HEIGHT
#define CHANNEL_FIRST
#define CHANNEL_HEIGHT_HALF
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:4227