Blender  V3.3
sequencer_channels_draw.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2022 Blender Foundation. All rights reserved. */
3 
8 #include "MEM_guardedalloc.h"
9 
10 #include "DNA_scene_types.h"
11 #include "DNA_screen_types.h"
12 
13 #include "BKE_context.h"
14 
15 #include "BLI_blenlib.h"
16 #include "BLI_utildefines.h"
17 
18 #include "ED_screen.h"
19 
20 #include "GPU_framebuffer.h"
21 #include "GPU_immediate.h"
22 #include "GPU_immediate_util.h"
23 #include "GPU_matrix.h"
24 #include "GPU_state.h"
25 #include "GPU_vertex_buffer.h"
26 #include "GPU_viewport.h"
27 
28 #include "RNA_access.h"
29 #include "RNA_prototypes.h"
30 
31 #include "SEQ_channels.h"
32 #include "SEQ_sequencer.h"
33 #include "SEQ_time.h"
34 
35 #include "UI_interface.h"
36 #include "UI_resources.h"
37 #include "UI_view2d.h"
38 
39 #include "WM_api.h"
40 
41 /* Own include. */
42 #include "sequencer_intern.h"
43 
45 {
46  LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
47  if (region->regiontype == RGN_TYPE_WINDOW) {
48  return region;
49  }
50  }
51 
53  return NULL;
54 }
55 
56 static float draw_offset_get(const View2D *timeline_region_v2d)
57 {
58  return timeline_region_v2d->cur.ymin;
59 }
60 
61 static float channel_height_pixelspace_get(const View2D *timeline_region_v2d)
62 {
63  return UI_view2d_view_to_region_y(timeline_region_v2d, 1.0f) -
64  UI_view2d_view_to_region_y(timeline_region_v2d, 0.0f);
65 }
66 
67 static float frame_width_pixelspace_get(const View2D *timeline_region_v2d)
68 {
69 
70  return UI_view2d_view_to_region_x(timeline_region_v2d, 1.0f) -
71  UI_view2d_view_to_region_x(timeline_region_v2d, 0.0f);
72 }
73 
75 {
76  return (U.widget_unit * 0.8 * context->scale);
77 }
78 
80 {
81  return (((context->channel_height / context->scale) - icon_width_get(context))) / 2;
82 }
83 
84 static float channel_index_y_min(const SeqChannelDrawContext *context, const int index)
85 {
86  float y = (index - context->draw_offset) * context->channel_height;
87  y /= context->scale;
88  return y;
89 }
90 
92  int r_channel_range[2])
93 {
94  /* Channel 0 is not usable, so should never be drawn. */
95  r_channel_range[0] = max_ii(1, floor(context->timeline_region_v2d->cur.ymin));
96  r_channel_range[1] = ceil(context->timeline_region_v2d->cur.ymax);
97 
98  rctf strip_boundbox;
99  BLI_rctf_init(&strip_boundbox, 0.0f, 0.0f, 1.0f, r_channel_range[1]);
100  SEQ_timeline_expand_boundbox(context->scene, context->seqbase, &strip_boundbox);
101  CLAMP(r_channel_range[0], strip_boundbox.ymin, strip_boundbox.ymax);
102  CLAMP(r_channel_range[1], strip_boundbox.ymin, MAXSEQ);
103 }
104 
105 static char *draw_channel_widget_tooltip(bContext *UNUSED(C), void *argN, const char *UNUSED(tip))
106 {
107  char *dyn_tooltip = argN;
108  return BLI_strdup(dyn_tooltip);
109 }
110 
112  uiBlock *block,
113  const int channel_index,
114  const float offset)
115 {
116  float y = channel_index_y_min(context, channel_index) + widget_y_offset(context);
117 
118  const float width = icon_width_get(context);
119  SeqTimelineChannel *channel = SEQ_channel_get_by_index(context->channels, channel_index);
120  const int icon = SEQ_channel_is_muted(channel) ? ICON_CHECKBOX_DEHLT : ICON_CHECKBOX_HLT;
121 
122  PointerRNA ptr;
123  RNA_pointer_create(&context->scene->id, &RNA_SequenceTimelineChannel, channel, &ptr);
124  PropertyRNA *hide_prop = RNA_struct_type_find_property(&RNA_SequenceTimelineChannel, "mute");
125 
127  uiBut *but = uiDefIconButR_prop(block,
129  1,
130  icon,
131  context->v2d->cur.xmax / context->scale - offset,
132  y,
133  width,
134  width,
135  &ptr,
136  hide_prop,
137  0,
138  0,
139  0,
140  0,
141  0,
142  NULL);
143 
144  char *tooltip = BLI_sprintfN(
145  "%s channel %d", SEQ_channel_is_muted(channel) ? "Unmute" : "Mute", channel_index);
147 
148  return width;
149 }
150 
152  uiBlock *block,
153  const int channel_index,
154  const float offset)
155 {
156 
157  float y = channel_index_y_min(context, channel_index) + widget_y_offset(context);
158  const float width = icon_width_get(context);
159 
160  SeqTimelineChannel *channel = SEQ_channel_get_by_index(context->channels, channel_index);
161  const int icon = SEQ_channel_is_locked(channel) ? ICON_LOCKED : ICON_UNLOCKED;
162 
163  PointerRNA ptr;
164  RNA_pointer_create(&context->scene->id, &RNA_SequenceTimelineChannel, channel, &ptr);
165  PropertyRNA *hide_prop = RNA_struct_type_find_property(&RNA_SequenceTimelineChannel, "lock");
166 
168  uiBut *but = uiDefIconButR_prop(block,
170  1,
171  icon,
172  context->v2d->cur.xmax / context->scale - offset,
173  y,
174  width,
175  width,
176  &ptr,
177  hide_prop,
178  0,
179  0,
180  0,
181  0,
182  0,
183  "");
184 
185  char *tooltip = BLI_sprintfN(
186  "%s channel %d", SEQ_channel_is_locked(channel) ? "Unlock" : "Lock", channel_index);
188 
189  return width;
190 }
191 
192 static bool channel_is_being_renamed(const SpaceSeq *sseq, const int channel_index)
193 {
194  return sseq->runtime.rename_channel_index == channel_index;
195 }
196 
198 {
199  const uiStyle *style = UI_style_get_dpi();
200  return UI_fontstyle_height_max(&style->widget) * 1.5f * context->scale;
201 }
202 
203 /* TODO: decide what gets priority - label or buttons. */
205  const int channel_index,
206  const float used_width)
207 {
208  float text_size = text_size_get(context);
209  float margin = (context->channel_height / context->scale - text_size) / 2.0f;
210  float y = channel_index_y_min(context, channel_index) + margin;
211 
212  float margin_x = icon_width_get(context) * 0.65;
213  float width = max_ff(0.0f, context->v2d->cur.xmax / context->scale - used_width);
214 
215  /* Text input has own margin. Prevent text jumping around and use as much space as possible. */
216  if (channel_is_being_renamed(CTX_wm_space_seq(context->C), channel_index)) {
217  float input_box_margin = icon_width_get(context) * 0.5f;
218  margin_x -= input_box_margin;
219  width += input_box_margin;
220  }
221 
222  rctf rect;
223  BLI_rctf_init(&rect, margin_x, margin_x + width, y, y + text_size);
224  return rect;
225 }
226 
228  uiBlock *block,
229  const int channel_index,
230  const float used_width)
231 {
232  SpaceSeq *sseq = CTX_wm_space_seq(context->C);
233  rctf rect = label_rect_init(context, channel_index, used_width);
234 
235  if (BLI_rctf_size_y(&rect) <= 1.0f || BLI_rctf_size_x(&rect) <= 1.0f) {
236  return;
237  }
238 
239  if (channel_is_being_renamed(sseq, channel_index)) {
240  SeqTimelineChannel *channel = SEQ_channel_get_by_index(context->channels, channel_index);
241  PointerRNA ptr = {NULL};
242  RNA_pointer_create(&context->scene->id, &RNA_SequenceTimelineChannel, channel, &ptr);
244 
246  uiBut *but = uiDefButR(block,
248  1,
249  "",
250  rect.xmin,
251  rect.ymin,
252  BLI_rctf_size_x(&rect),
253  BLI_rctf_size_y(&rect),
254  &ptr,
256  -1,
257  0,
258  0,
259  0,
260  0,
261  NULL);
263 
264  if (UI_but_active_only(context->C, context->region, block, but) == false) {
265  sseq->runtime.rename_channel_index = 0;
266  }
267 
269  }
270  else {
271  const char *label = SEQ_channel_name_get(context->channels, channel_index);
272  uiDefBut(block,
274  0,
275  label,
276  rect.xmin,
277  rect.ymin,
278  rect.xmax - rect.xmin,
279  (rect.ymax - rect.ymin),
280  NULL,
281  0,
282  0,
283  0,
284  0,
285  NULL);
286  }
287 }
288 
289 /* TODO: different text/buttons alignment. */
291  uiBlock *block,
292  const int channel_index)
293 {
294  float offset = icon_width_get(context) * 1.5f;
295  offset += draw_channel_widget_lock(context, block, channel_index, offset);
296  offset += draw_channel_widget_mute(context, block, channel_index, offset);
297 
298  draw_channel_labels(context, block, channel_index, offset);
299 }
300 
302 {
303  GPU_matrix_push();
304  wmOrtho2_pixelspace(context->region->winx / context->scale,
305  context->region->winy / context->scale);
306  uiBlock *block = UI_block_begin(context->C, context->region, __func__, UI_EMBOSS);
307 
308  int channel_range[2];
309  displayed_channel_range_get(context, channel_range);
310 
311  for (int channel = channel_range[0]; channel <= channel_range[1]; channel++) {
312  draw_channel_header(context, block, channel);
313  }
314 
315  UI_block_end(context->C, block);
316  UI_block_draw(context->C, block);
317 
318  GPU_matrix_pop();
319 }
320 
321 static void draw_background(void)
322 {
324 }
325 
327  ARegion *region,
328  SeqChannelDrawContext *r_context)
329 {
330  r_context->C = C;
331  r_context->area = CTX_wm_area(C);
332  r_context->region = region;
333  r_context->v2d = &region->v2d;
334  r_context->scene = CTX_data_scene(C);
335  r_context->ed = SEQ_editing_get(r_context->scene);
336  r_context->seqbase = SEQ_active_seqbase_get(r_context->ed);
337  r_context->channels = SEQ_channels_displayed_get(r_context->ed);
339  r_context->timeline_region_v2d = &r_context->timeline_region->v2d;
340 
343  r_context->draw_offset = draw_offset_get(r_context->timeline_region_v2d);
344 
345  r_context->scale = min_ff(r_context->channel_height / (U.widget_unit * 0.6), 1);
346 }
347 
348 void draw_channels(const bContext *C, ARegion *region)
349 {
350  draw_background();
351 
353  if (ed == NULL) {
354  return;
355  }
356 
359 
361 
363 
365 }
struct ScrArea * CTX_wm_area(const bContext *C)
Definition: context.c:738
struct Scene * CTX_data_scene(const bContext *C)
Definition: context.c:1090
struct SpaceSeq * CTX_wm_space_seq(const bContext *C)
Definition: context.c:851
#define BLI_assert_unreachable()
Definition: BLI_assert.h:93
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:336
MINLINE float max_ff(float a, float b)
MINLINE float min_ff(float a, float b)
MINLINE int max_ii(int a, int b)
void BLI_rctf_init(struct rctf *rect, float xmin, float xmax, float ymin, float ymax)
Definition: rct.c:407
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
Definition: BLI_rect.h:194
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
Definition: BLI_rect.h:198
size_t size_t char * BLI_sprintfN(const char *__restrict format,...) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_PRINTF_FORMAT(1
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL() ATTR_MALLOC
Definition: string.c:42
#define UNUSED(x)
@ RGN_TYPE_WINDOW
#define MAXSEQ
_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
_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 GLsizei width
void GPU_matrix_pop(void)
Definition: gpu_matrix.cc:126
void GPU_matrix_push(void)
Definition: gpu_matrix.cc:119
Read Guarded memory(de)allocation.
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 Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position CLAMP
#define C
Definition: RandGen.cpp:25
@ UI_EMBOSS_NONE
Definition: UI_interface.h:109
@ UI_EMBOSS
Definition: UI_interface.h:108
const struct uiStyle * UI_style_get_dpi(void)
uiBut * uiDefBut(uiBlock *block, int type, int retval, const char *str, int x, int y, short width, short height, void *poin, float min, float max, float a1, float a2, const char *tip)
Definition: interface.cc:4806
void UI_but_func_tooltip_set(uiBut *but, uiButToolTipFunc func, void *arg, uiFreeArgFunc free_arg)
Definition: interface.cc:6029
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.cc:5570
void UI_block_end(const struct bContext *C, uiBlock *block)
uiBut * uiDefButR(uiBlock *block, int type, int retval, const char *str, int x, int y, short width, short height, struct PointerRNA *ptr, const char *propname, int index, float min, float max, float a1, float a2, const char *tip)
Definition: interface.cc:5258
void UI_block_emboss_set(uiBlock *block, eUIEmbossType emboss)
Definition: interface.cc:3629
void UI_block_draw(const struct bContext *C, struct uiBlock *block)
bool UI_but_active_only(const struct bContext *C, struct ARegion *region, uiBlock *block, uiBut *but)
uiBlock * UI_block_begin(const struct bContext *C, struct ARegion *region, const char *name, eUIEmbossType emboss)
int int int UI_fontstyle_height_max(const struct uiFontStyle *fs)
@ UI_BTYPE_TOGGLE
Definition: UI_interface.h:340
@ UI_BTYPE_TEXT
Definition: UI_interface.h:332
@ UI_BTYPE_LABEL
Definition: UI_interface.h:354
@ TH_BACK
Definition: UI_resources.h:39
void UI_ThemeClearColor(int colorid)
Definition: resources.c:1448
float UI_view2d_view_to_region_x(const struct View2D *v2d, float x)
float UI_view2d_view_to_region_y(const struct View2D *v2d, float y)
void UI_view2d_view_restore(const struct bContext *C)
void UI_view2d_view_ortho(const struct View2D *v2d)
#define ND_SEQUENCER
Definition: WM_types.h:385
#define NC_SCENE
Definition: WM_types.h:328
unsigned int U
Definition: btGjkEpa3.h:78
SeqTimelineChannel * SEQ_channel_get_by_index(const ListBase *channels, const int channel_index)
Definition: channels.c:59
bool SEQ_channel_is_locked(const SeqTimelineChannel *channel)
Definition: channels.c:75
char * SEQ_channel_name_get(ListBase *channels, const int channel_index)
Definition: channels.c:64
bool SEQ_channel_is_muted(const SeqTimelineChannel *channel)
Definition: channels.c:80
ListBase * SEQ_channels_displayed_get(Editing *ed)
Definition: channels.c:23
const char * label
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
ccl_device_inline float3 ceil(const float3 &a)
Definition: math_float3.h:363
static void area(int d1, int d2, int e1, int e2, float weights[2])
T floor(const T &a)
void RNA_pointer_create(ID *id, StructRNA *type, void *data, PointerRNA *r_ptr)
Definition: rna_access.c:136
const char * RNA_property_identifier(const PropertyRNA *prop)
Definition: rna_access.c:1000
PropertyRNA * RNA_struct_type_find_property(StructRNA *srna, const char *identifier)
Definition: rna_access.c:806
PropertyRNA * RNA_struct_name_property(const StructRNA *type)
Definition: rna_access.c:624
ListBase * SEQ_active_seqbase_get(const Editing *ed)
Definition: sequencer.c:388
Editing * SEQ_editing_get(const Scene *scene)
Definition: sequencer.c:241
static char * draw_channel_widget_tooltip(bContext *UNUSED(C), void *argN, const char *UNUSED(tip))
void draw_channels(const bContext *C, ARegion *region)
static bool channel_is_being_renamed(const SpaceSeq *sseq, const int channel_index)
static float channel_index_y_min(const SeqChannelDrawContext *context, const int index)
static float channel_height_pixelspace_get(const View2D *timeline_region_v2d)
static float draw_channel_widget_mute(const SeqChannelDrawContext *context, uiBlock *block, const int channel_index, const float offset)
static void draw_channel_labels(const SeqChannelDrawContext *context, uiBlock *block, const int channel_index, const float used_width)
static float draw_channel_widget_lock(const SeqChannelDrawContext *context, uiBlock *block, const int channel_index, const float offset)
void channel_draw_context_init(const bContext *C, ARegion *region, SeqChannelDrawContext *r_context)
static void displayed_channel_range_get(const SeqChannelDrawContext *context, int r_channel_range[2])
static float draw_offset_get(const View2D *timeline_region_v2d)
static rctf label_rect_init(const SeqChannelDrawContext *context, const int channel_index, const float used_width)
static float widget_y_offset(const SeqChannelDrawContext *context)
static float frame_width_pixelspace_get(const View2D *timeline_region_v2d)
static void draw_background(void)
static void draw_channel_headers(const SeqChannelDrawContext *context)
static float icon_width_get(const SeqChannelDrawContext *context)
static void draw_channel_header(const SeqChannelDrawContext *context, uiBlock *block, const int channel_index)
static ARegion * timeline_region_get(const ScrArea *area)
static float text_size_get(const SeqChannelDrawContext *context)
void SEQ_timeline_expand_boundbox(const Scene *scene, const ListBase *seqbase, rctf *rect)
Definition: strip_time.c:354
struct StructRNA * type
Definition: RNA_types.h:37
struct View2D * timeline_region_v2d
struct ARegion * timeline_region
struct ARegion * region
struct Editing * ed
struct ScrArea * area
const struct bContext * C
struct ListBase * channels
struct ListBase * seqbase
SpaceSeqRuntime runtime
float xmax
Definition: DNA_vec_types.h:69
float xmin
Definition: DNA_vec_types.h:69
float ymax
Definition: DNA_vec_types.h:70
float ymin
Definition: DNA_vec_types.h:70
uiFontStyle widget
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
PointerRNA * ptr
Definition: wm_files.c:3480
void wmOrtho2_pixelspace(const float x, const float y)
Definition: wm_subwindow.c:108