Blender V4.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_rect.h"
13#include "BLI_utildefines.h"
14
15#include "BKE_context.hh"
16#include "BKE_movieclip.h"
17
18#include "ED_clip.hh"
19#include "ED_screen.hh"
20
21#include "WM_types.hh"
22
23#include "UI_interface.hh"
24#include "UI_resources.hh"
25#include "UI_view2d.hh"
26
27#include "BLF_api.hh"
28
29#include "RNA_access.hh"
30#include "RNA_prototypes.hh"
31
32#include "GPU_immediate.hh"
33#include "GPU_state.hh"
34
35#include "clip_intern.hh" /* 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
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
69static 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
76 MovieTrackingDopesheetCoverageSegment *, coverage_segment, &dopesheet->coverage_segments)
77 {
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 */
101 clip_draw_sfra_efra(v2d, scene);
102
103 if (clip) {
104 MovieTracking *tracking = &clip->tracking;
105 MovieTrackingDopesheet *dopesheet = &tracking->dopesheet;
106 float strip[4], selected_strip[4];
107 float height = (dopesheet->tot_channel * CHANNEL_STEP) + CHANNEL_HEIGHT;
108
109 uint keyframe_len = 0;
110
114
115 /* don't use totrect set, as the width stays the same
116 * (NOTE: this is ok here, the configuration is pretty straightforward)
117 */
118 v2d->tot.ymin = float(-height);
119
120 float y = float(CHANNEL_FIRST);
121
122 /* setup colors for regular and selected strips */
124 UI_GetThemeColor3fv(TH_STRIP_SELECT, selected_strip);
125
126 strip[3] = 0.5f;
127 selected_strip[3] = 1.0f;
128
130
131 clip_draw_dopesheet_background(region, clip, pos_id);
132
134 float yminc = float(y - CHANNEL_HEIGHT_HALF);
135 float ymaxc = float(y + CHANNEL_HEIGHT_HALF);
136
137 /* check if visible */
138 if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
139 IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax))
140 {
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,
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);
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 */
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 {
232 MovieTrackingTrack *track = channel->track;
233 int i;
234 bool sel = (track->flag & TRACK_DOPE_SEL) != 0;
235 float alpha = (track->flag & TRACK_LOCKED) ? 0.5f : 1.0f;
236
237 /* tracked segments */
238 for (i = 0; i < channel->tot_segment; i++) {
239 int start_frame = BKE_movieclip_remap_clip_to_scene_frame(clip,
240 channel->segments[2 * i]);
241 int end_frame = BKE_movieclip_remap_clip_to_scene_frame(clip,
242 channel->segments[2 * i + 1]);
243
244 if (start_frame != end_frame) {
245 draw_keyframe_shape(start_frame, y, sel, alpha, pos_id, color_id);
246 draw_keyframe_shape(end_frame, y, sel, alpha, pos_id, color_id);
247 }
248 else {
249 draw_keyframe_shape(start_frame, y, sel, alpha, pos_id, color_id);
250 }
251 }
252
253 /* keyframes */
254 i = 0;
255 while (i < track->markersnr) {
256 MovieTrackingMarker *marker = &track->markers[i];
257
258 if ((marker->flag & (MARKER_DISABLED | MARKER_TRACKED)) == 0) {
259 int framenr = BKE_movieclip_remap_clip_to_scene_frame(clip, marker->framenr);
260
261 draw_keyframe_shape(framenr, y, sel, alpha, pos_id, color_id);
262 }
263
264 i++;
265 }
266 }
267
268 /* adjust y-position for next one */
269 y -= CHANNEL_STEP;
270 }
271
272 immEnd();
275 }
276
278 }
279}
280
282{
283 ScrArea *area = CTX_wm_area(C);
285 View2D *v2d = &region->v2d;
287 const uiStyle *style = UI_style_get();
288 int fontid = style->widget.uifont_id;
289
290 if (!clip) {
291 return;
292 }
293
294 MovieTracking *tracking = &clip->tracking;
295 MovieTrackingDopesheet *dopesheet = &tracking->dopesheet;
296 int height = (dopesheet->tot_channel * CHANNEL_STEP) + CHANNEL_HEIGHT;
297
298 if (height > BLI_rcti_size_y(&v2d->mask)) {
299 /* don't use totrect set, as the width stays the same
300 * (NOTE: this is ok here, the configuration is pretty straightforward)
301 */
302 v2d->tot.ymin = float(-height);
303 }
304
305 /* need to do a view-sync here, so that the keys area doesn't jump around
306 * (it must copy this) */
307 UI_view2d_sync(nullptr, area, v2d, V2D_LOCK_COPY);
308
309 /* loop through channels, and set up drawing depending on their type
310 * first pass: just the standard GL-drawing for backdrop + text
311 */
312 float y = float(CHANNEL_FIRST);
313
316
318
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 {
327 MovieTrackingTrack *track = channel->track;
328 float color[3];
329 track_channel_color(track, nullptr, color);
331
333 v2d->cur.xmin,
334 float(y) - CHANNEL_HEIGHT_HALF,
336 float(y) + CHANNEL_HEIGHT_HALF);
337 }
338
339 /* adjust y-position for next one */
340 y -= CHANNEL_STEP;
341 }
343
344 /* second pass: text */
346
347 BLF_size(fontid, 11.0f * UI_SCALE_FAC);
348
350 float yminc = float(y - CHANNEL_HEIGHT_HALF);
351 float ymaxc = float(y + CHANNEL_HEIGHT_HALF);
352
353 /* check if visible */
354 if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
355 IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax))
356 {
357 MovieTrackingTrack *track = channel->track;
358 bool sel = (track->flag & TRACK_DOPE_SEL) != 0;
359
360 UI_FontThemeColor(fontid, sel ? TH_TEXT_HI : TH_TEXT);
361
362 float font_height = BLF_height(fontid, channel->name, sizeof(channel->name));
363 BLF_position(fontid, v2d->cur.xmin + CHANNEL_PAD, y - font_height / 2.0f, 0.0f);
364 BLF_draw(fontid, channel->name, strlen(channel->name));
365 }
366
367 /* adjust y-position for next one */
368 y -= CHANNEL_STEP;
369 }
370
371 /* third pass: widgets */
372 uiBlock *block = UI_block_begin(C, region, __func__, UI_EMBOSS);
374
375 /* get RNA properties (once) */
376 PropertyRNA *chan_prop_lock = RNA_struct_type_find_property(&RNA_MovieTrackingTrack, "lock");
377 BLI_assert(chan_prop_lock);
378
381 float yminc = float(y - CHANNEL_HEIGHT_HALF);
382 float ymaxc = float(y + CHANNEL_HEIGHT_HALF);
383
384 /* check if visible */
385 if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
386 IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax))
387 {
388 MovieTrackingTrack *track = channel->track;
389 const int icon = (track->flag & TRACK_LOCKED) ? ICON_LOCKED : ICON_UNLOCKED;
390 PointerRNA ptr = RNA_pointer_create(&clip->id, &RNA_MovieTrackingTrack, track);
391
393 uiDefIconButR_prop(block,
395 1,
396 icon,
397 v2d->cur.xmax - UI_UNIT_X - CHANNEL_PAD,
398 y - UI_UNIT_Y / 2.0f,
399 UI_UNIT_X,
400 UI_UNIT_Y,
401 &ptr,
402 chan_prop_lock,
403 0,
404 0,
405 0,
406 nullptr);
408 }
409
410 /* adjust y-position for next one */
411 y -= CHANNEL_STEP;
412 }
414
415 UI_block_end(C, block);
416 UI_block_draw(C, block);
417}
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:426
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:815
void BLF_draw(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_NONNULL(2)
Definition blf.cc:568
void BLF_position(int fontid, float x, float y, float z)
Definition blf.cc:371
#define BLI_assert(a)
Definition BLI_assert.h:50
#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)
Definition math_vector.c:36
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
Definition BLI_rect.h:193
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
Definition BLI_rect.h:189
unsigned int uint
#define IN_RANGE(a, b, c)
@ TRACK_CUSTOMCOLOR
@ TRACK_LOCKED
@ TRACK_DOPE_SEL
@ MARKER_TRACKED
@ MARKER_DISABLED
@ TRACKING_COVERAGE_BAD
@ TRACKING_COVERAGE_OK
#define UI_SCALE_FAC
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:175
@ 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 *, 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 Brightness Control the brightness and contrast of the input color Vector Map input vector components with curves 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 Invert a color
#define C
Definition RandGen.cpp:29
#define UI_UNIT_Y
@ UI_EMBOSS_NONE
@ UI_EMBOSS
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, const char *tip)
uiBlock * UI_block_begin(const bContext *C, ARegion *region, std::string name, eUIEmbossType emboss)
const uiStyle * UI_style_get()
void UI_block_emboss_set(uiBlock *block, eUIEmbossType emboss)
void UI_block_draw(const bContext *C, uiBlock *block)
#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:861
#define V2D_LOCK_COPY
Definition UI_view2d.hh:85
#define EXTRA_SCROLL_PAD
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
void clip_draw_sfra_efra(View2D *v2d, Scene *scene)
#define CHANNEL_HEIGHT
#define CHANNEL_FIRST
#define CHANNEL_HEIGHT_HALF
draw_view in_light_buf[] float
format
PropertyRNA * RNA_struct_type_find_property(StructRNA *srna, const char *identifier)
PointerRNA RNA_pointer_create(ID *id, StructRNA *type, void *data)
struct MovieTracking tracking
MovieTrackingMarker * markers
MovieTrackingDopesheet dopesheet
float xmax
float xmin
float ymax
float ymin
uiFontStyle widget
PointerRNA * ptr
Definition wm_files.cc:4126