Blender V4.5
sequencer_channels_draw.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "MEM_guardedalloc.h"
10
11#include "DNA_scene_types.h"
12#include "DNA_screen_types.h"
13
14#include "BKE_context.hh"
15#include "BKE_screen.hh"
16
17#include "BLI_string.h"
18#include "BLI_utildefines.h"
19
20#include "ED_screen.hh"
21
22#include "GPU_matrix.hh"
23
24#include "RNA_prototypes.hh"
25
26#include "SEQ_channels.hh"
27#include "SEQ_sequencer.hh"
28#include "SEQ_time.hh"
29
30#include "UI_interface.hh"
31#include "UI_resources.hh"
32#include "UI_view2d.hh"
33
34#include "WM_api.hh"
35
36/* Own include. */
37#include "sequencer_intern.hh"
38
39namespace blender::ed::vse {
40
41static float draw_offset_get(const View2D *timeline_region_v2d)
42{
43 return timeline_region_v2d->cur.ymin;
44}
45
46static float channel_height_pixelspace_get(const View2D *timeline_region_v2d)
47{
48 return UI_view2d_view_to_region_y(timeline_region_v2d, 1.0f) -
49 UI_view2d_view_to_region_y(timeline_region_v2d, 0.0f);
50}
51
52static float frame_width_pixelspace_get(const View2D *timeline_region_v2d)
53{
54
55 return UI_view2d_view_to_region_x(timeline_region_v2d, 1.0f) -
56 UI_view2d_view_to_region_x(timeline_region_v2d, 0.0f);
57}
58
59static float icon_width_get(const SeqChannelDrawContext *context)
60{
61 return (U.widget_unit * 0.8 * context->scale);
62}
63
64static float widget_y_offset(const SeqChannelDrawContext *context)
65{
66 return ((context->channel_height / context->scale) - icon_width_get(context)) / 2;
67}
68
69static float channel_index_y_min(const SeqChannelDrawContext *context, const int index)
70{
71 float y = (index - context->draw_offset) * context->channel_height;
72 y /= context->scale;
73 return y;
74}
75
77 int r_channel_range[2])
78{
79 /* Channel 0 is not usable, so should never be drawn. */
80 r_channel_range[0] = max_ii(1, floor(context->timeline_region_v2d->cur.ymin));
81 r_channel_range[1] = ceil(context->timeline_region_v2d->cur.ymax);
82
83 rctf strip_boundbox;
84 BLI_rctf_init(&strip_boundbox, 0.0f, 0.0f, 1.0f, r_channel_range[1]);
85 seq::timeline_expand_boundbox(context->scene, context->seqbase, &strip_boundbox);
86 CLAMP(r_channel_range[0], strip_boundbox.ymin, strip_boundbox.ymax);
87 CLAMP(r_channel_range[1], strip_boundbox.ymin, seq::MAX_CHANNELS);
88}
89
90static std::string draw_channel_widget_tooltip(bContext * /*C*/,
91 void *argN,
92 const blender::StringRef /*tip*/)
93{
94 char *dyn_tooltip = static_cast<char *>(argN);
95 return dyn_tooltip;
96}
97
99 uiBlock *block,
100 const int channel_index,
101 const float offset)
102{
103 float y = channel_index_y_min(context, channel_index) + widget_y_offset(context);
104
105 const float width = icon_width_get(context);
106 SeqTimelineChannel *channel = seq::channel_get_by_index(context->channels, channel_index);
107 const int icon = seq::channel_is_muted(channel) ? ICON_CHECKBOX_DEHLT : ICON_CHECKBOX_HLT;
108
110 &context->scene->id, &RNA_SequenceTimelineChannel, channel);
111 PropertyRNA *hide_prop = RNA_struct_type_find_property(&RNA_SequenceTimelineChannel, "mute");
112
114 uiBut *but = uiDefIconButR_prop(block,
116 1,
117 icon,
118 context->v2d->cur.xmax / context->scale - offset,
119 y,
120 width,
121 width,
122 &ptr,
123 hide_prop,
124 0,
125 0,
126 0,
127 std::nullopt);
128
129 char *tooltip = BLI_sprintfN(
130 "%s channel %d", seq::channel_is_muted(channel) ? "Unmute" : "Mute", channel_index);
132
133 return width;
134}
135
137 uiBlock *block,
138 const int channel_index,
139 const float offset)
140{
141
142 float y = channel_index_y_min(context, channel_index) + widget_y_offset(context);
143 const float width = icon_width_get(context);
144
145 SeqTimelineChannel *channel = seq::channel_get_by_index(context->channels, channel_index);
146 const int icon = seq::channel_is_locked(channel) ? ICON_LOCKED : ICON_UNLOCKED;
147
149 &context->scene->id, &RNA_SequenceTimelineChannel, channel);
150 PropertyRNA *hide_prop = RNA_struct_type_find_property(&RNA_SequenceTimelineChannel, "lock");
151
153 uiBut *but = uiDefIconButR_prop(block,
155 1,
156 icon,
157 context->v2d->cur.xmax / context->scale - offset,
158 y,
159 width,
160 width,
161 &ptr,
162 hide_prop,
163 0,
164 0,
165 0,
166 "");
167
168 char *tooltip = BLI_sprintfN(
169 "%s channel %d", seq::channel_is_locked(channel) ? "Unlock" : "Lock", channel_index);
171
172 return width;
173}
174
175static bool channel_is_being_renamed(const SpaceSeq *sseq, const int channel_index)
176{
177 return sseq->runtime->rename_channel_index == channel_index;
178}
179
180static float text_size_get(const SeqChannelDrawContext *context)
181{
182 const uiStyle *style = UI_style_get_dpi();
183 return UI_fontstyle_height_max(&style->widget) * 1.5f * context->scale;
184}
185
186/* TODO: decide what gets priority - label or buttons. */
188 const int channel_index,
189 const float used_width)
190{
191 float text_size = text_size_get(context);
192 float margin = (context->channel_height / context->scale - text_size) / 2.0f;
193 float y = channel_index_y_min(context, channel_index) + margin;
194
195 float margin_x = icon_width_get(context) * 0.65;
196 float width = max_ff(0.0f, context->v2d->cur.xmax / context->scale - used_width);
197
198 /* Text input has its own margin. Prevent text jumping around and use as much space as possible.
199 */
200 if (channel_is_being_renamed(CTX_wm_space_seq(context->C), channel_index)) {
201 float input_box_margin = icon_width_get(context) * 0.5f;
202 margin_x -= input_box_margin;
203 width += input_box_margin;
204 }
205
206 rctf rect;
207 BLI_rctf_init(&rect, margin_x, margin_x + width, y, y + text_size);
208 return rect;
209}
210
212 uiBlock *block,
213 const int channel_index,
214 const float used_width)
215{
216 SpaceSeq *sseq = CTX_wm_space_seq(context->C);
217 rctf rect = label_rect_init(context, channel_index, used_width);
218
219 if (BLI_rctf_size_y(&rect) <= 1.0f || BLI_rctf_size_x(&rect) <= 1.0f) {
220 return;
221 }
222
223 if (channel_is_being_renamed(sseq, channel_index)) {
224 SeqTimelineChannel *channel = seq::channel_get_by_index(context->channels, channel_index);
226 &context->scene->id, &RNA_SequenceTimelineChannel, channel);
228
230 uiBut *but = uiDefButR(block,
232 1,
233 "",
234 rect.xmin,
235 rect.ymin,
236 BLI_rctf_size_x(&rect),
237 BLI_rctf_size_y(&rect),
238 &ptr,
240 -1,
241 0,
242 0,
243 std::nullopt);
245
246 if (UI_but_active_only(context->C, context->region, block, but) == false) {
247 sseq->runtime->rename_channel_index = 0;
248 }
249
250 WM_event_add_notifier(context->C, NC_SCENE | ND_SEQUENCER, context->scene);
251 }
252 else {
253 const char *label = seq::channel_name_get(context->channels, channel_index);
254 uiDefBut(block,
256 0,
257 label,
258 rect.xmin,
259 rect.ymin,
260 rect.xmax - rect.xmin,
261 (rect.ymax - rect.ymin),
262 nullptr,
263 0,
264 0,
265 std::nullopt);
266 }
267}
268
270{
272 wmOrtho2_pixelspace(context->region->winx / context->scale,
273 context->region->winy / context->scale);
274 uiBlock *block = UI_block_begin(
275 context->C, context->region, __func__, blender::ui::EmbossType::Emboss);
276
277 int channel_range[2];
278 displayed_channel_range_get(context, channel_range);
279
280 const float icon_width = icon_width_get(context);
281 const float offset_lock = icon_width * 1.5f;
282 const float offset_mute = icon_width * 2.5f;
283 const float offset_width = icon_width * 3.5f;
284 /* Draw widgets separately from text labels so they are batched together,
285 * instead of alternating between two fonts (regular and SVG/icons). */
286 for (int channel = channel_range[0]; channel <= channel_range[1]; channel++) {
287 draw_channel_widget_lock(context, block, channel, offset_lock);
288 draw_channel_widget_mute(context, block, channel, offset_mute);
289 }
290 for (int channel = channel_range[0]; channel <= channel_range[1]; channel++) {
291 draw_channel_labels(context, block, channel, offset_width);
292 }
293
294 UI_block_end(context->C, block);
295 UI_block_draw(context->C, block);
296
298}
299
300static void draw_background()
301{
303}
304
306 ARegion *region,
307 SeqChannelDrawContext *r_context)
308{
309 r_context->C = C;
310 r_context->area = CTX_wm_area(C);
311 r_context->region = region;
312 r_context->v2d = &region->v2d;
313 r_context->scene = CTX_data_scene(C);
314 r_context->ed = seq::editing_get(r_context->scene);
315 r_context->seqbase = seq::active_seqbase_get(r_context->ed);
316 r_context->channels = seq::channels_displayed_get(r_context->ed);
318 BLI_assert(r_context->timeline_region != nullptr);
319 r_context->timeline_region_v2d = &r_context->timeline_region->v2d;
320
323 r_context->draw_offset = draw_offset_get(r_context->timeline_region_v2d);
324
325 r_context->scale = min_ff(r_context->channel_height / (U.widget_unit * 0.6), 1);
326}
327
328void draw_channels(const bContext *C, ARegion *region)
329{
331
333 if (ed == nullptr) {
334 return;
335 }
336
337 SeqChannelDrawContext context;
338 channel_draw_context_init(C, region, &context);
339
340 if (round_fl_to_int(context.channel_height) == 0) {
341 return;
342 }
343
344 UI_view2d_view_ortho(context.v2d);
345
346 draw_channel_headers(&context);
347
349}
350
351} // namespace blender::ed::vse
ScrArea * CTX_wm_area(const bContext *C)
Scene * CTX_data_scene(const bContext *C)
SpaceSeq * CTX_wm_space_seq(const bContext *C)
ARegion * BKE_area_find_region_type(const ScrArea *area, int region_type)
Definition screen.cc:840
#define BLI_assert(a)
Definition BLI_assert.h:46
MINLINE int round_fl_to_int(float a)
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.cc:404
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
Definition BLI_rect.h:202
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
Definition BLI_rect.h:206
char * BLI_sprintfN(const char *__restrict format,...) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_PRINTF_FORMAT(1
#define CLAMP(a, b, c)
@ RGN_TYPE_WINDOW
void GPU_matrix_push()
void GPU_matrix_pop()
Read Guarded memory(de)allocation.
#define C
Definition RandGen.cpp:29
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)
void UI_but_func_tooltip_set(uiBut *but, uiButToolTipFunc func, void *arg, uiFreeArgFunc free_arg)
uiBut * uiDefBut(uiBlock *block, int type, int retval, blender::StringRef str, int x, int y, short width, short height, void *poin, float min, float max, std::optional< blender::StringRef > tip)
const uiStyle * UI_style_get_dpi()
int UI_fontstyle_height_max(const uiFontStyle *fs)
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)
bool UI_but_active_only(const bContext *C, ARegion *region, uiBlock *block, uiBut *but)
@ UI_BTYPE_TOGGLE
@ UI_BTYPE_TEXT
@ UI_BTYPE_LABEL
uiBut * uiDefButR(uiBlock *block, int type, int retval, std::optional< blender::StringRef > str, int x, int y, short width, short height, PointerRNA *ptr, blender::StringRefNull propname, int index, float min, float max, std::optional< blender::StringRef > tip)
void UI_block_end(const bContext *C, uiBlock *block)
@ TH_BACK
void UI_ThemeClearColor(int colorid)
void UI_view2d_view_restore(const bContext *C)
Definition view2d.cc:1162
float UI_view2d_view_to_region_y(const View2D *v2d, float y)
Definition view2d.cc:1695
void UI_view2d_view_ortho(const View2D *v2d)
Definition view2d.cc:1095
float UI_view2d_view_to_region_x(const View2D *v2d, float x)
Definition view2d.cc:1690
#define ND_SEQUENCER
Definition WM_types.hh:434
#define NC_SCENE
Definition WM_types.hh:375
#define U
#define floor
#define ceil
void MEM_freeN(void *vmemh)
Definition mallocn.cc:113
static std::string draw_channel_widget_tooltip(bContext *, void *argN, const blender::StringRef)
static bool channel_is_being_renamed(const SpaceSeq *sseq, const int channel_index)
static float icon_width_get(const SeqChannelDrawContext *context)
static void draw_channel_headers(const SeqChannelDrawContext *context)
void channel_draw_context_init(const bContext *C, ARegion *region, SeqChannelDrawContext *r_context)
static float draw_offset_get(const View2D *timeline_region_v2d)
static float text_size_get(const SeqChannelDrawContext *context)
static float draw_channel_widget_mute(const SeqChannelDrawContext *context, uiBlock *block, const int channel_index, const float offset)
static float frame_width_pixelspace_get(const View2D *timeline_region_v2d)
static float draw_channel_widget_lock(const SeqChannelDrawContext *context, uiBlock *block, const int channel_index, const float offset)
static float widget_y_offset(const SeqChannelDrawContext *context)
static void displayed_channel_range_get(const SeqChannelDrawContext *context, int r_channel_range[2])
static rctf label_rect_init(const SeqChannelDrawContext *context, const int channel_index, const float used_width)
void draw_channels(const bContext *C, ARegion *region)
static float channel_height_pixelspace_get(const View2D *timeline_region_v2d)
static float channel_index_y_min(const SeqChannelDrawContext *context, const int index)
static void draw_channel_labels(const SeqChannelDrawContext *context, uiBlock *block, const int channel_index, const float used_width)
SeqTimelineChannel * channel_get_by_index(const ListBase *channels, const int channel_index)
Definition channels.cc:65
ListBase * channels_displayed_get(const Editing *ed)
Definition channels.cc:28
bool channel_is_locked(const SeqTimelineChannel *channel)
Definition channels.cc:81
Editing * editing_get(const Scene *scene)
Definition sequencer.cc:272
constexpr int MAX_CHANNELS
void timeline_expand_boundbox(const Scene *scene, const ListBase *seqbase, rctf *rect)
char * channel_name_get(ListBase *channels, const int channel_index)
Definition channels.cc:70
bool channel_is_muted(const SeqTimelineChannel *channel)
Definition channels.cc:86
ListBase * active_seqbase_get(const Editing *ed)
Definition sequencer.cc:420
PropertyRNA * RNA_struct_type_find_property(StructRNA *srna, const char *identifier)
PropertyRNA * RNA_struct_name_property(const StructRNA *type)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
const char * RNA_property_identifier(const PropertyRNA *prop)
SpaceSeq_Runtime * runtime
float xmax
float xmin
float ymax
float ymin
uiFontStyle widget
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
PointerRNA * ptr
Definition wm_files.cc:4226
void wmOrtho2_pixelspace(const float x, const float y)