Blender V5.3
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_math_base_c.hh"
18#include "BLI_string.hh"
19#include "BLI_utildefines.hh"
20
21#include "ED_screen.hh"
22
23#include "GPU_matrix.hh"
24
25#include "RNA_prototypes.hh"
26
27#include "SEQ_channels.hh"
28#include "SEQ_sequencer.hh"
29#include "SEQ_time.hh"
30
31#include "UI_interface.hh"
32#include "UI_resources.hh"
33#include "UI_view2d.hh"
34
35#include "WM_api.hh"
36
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 StringRef /*tip*/)
93{
94 char *dyn_tooltip = static_cast<char *>(argN);
95 return dyn_tooltip;
96}
97
99 ui::Block *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 = channel->is_muted() ? 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
113 block_emboss_set(block, ui::EmbossType::None);
114 ui::Button *but = uiDefIconButR_prop(block,
116 icon,
117 context->v2d->cur.xmax / context->scale - offset,
118 y,
119 width,
120 width,
121 &ptr,
122 hide_prop,
123 0,
124 0,
125 0,
126 std::nullopt);
127
128 char *tooltip = BLI_sprintfN(
129 "%s channel %d", channel->is_muted() ? "Unmute" : "Mute", channel_index);
130 button_func_tooltip_set(but, draw_channel_widget_tooltip, tooltip, MEM_delete_void);
131
132 return width;
133}
134
136 ui::Block *block,
137 const int channel_index,
138 const float offset)
139{
140
141 float y = channel_index_y_min(context, channel_index) + widget_y_offset(context);
142 const float width = icon_width_get(context);
143
144 SeqTimelineChannel *channel = seq::channel_get_by_index(context->channels, channel_index);
145 const int icon = channel->is_locked() ? ICON_LOCKED : ICON_UNLOCKED;
146
148 &context->scene->id, RNA_SequenceTimelineChannel, channel);
149 PropertyRNA *hide_prop = RNA_struct_type_find_property(RNA_SequenceTimelineChannel, "lock");
150
151 block_emboss_set(block, ui::EmbossType::None);
152 ui::Button *but = uiDefIconButR_prop(block,
154 icon,
155 context->v2d->cur.xmax / context->scale - offset,
156 y,
157 width,
158 width,
159 &ptr,
160 hide_prop,
161 0,
162 0,
163 0,
164 "");
165
166 char *tooltip = BLI_sprintfN(
167 "%s channel %d", channel->is_locked() ? "Unlock" : "Lock", channel_index);
168 button_func_tooltip_set(but, draw_channel_widget_tooltip, tooltip, MEM_delete_void);
169
170 return width;
171}
172
173static bool channel_is_being_renamed(const SpaceSeq *sseq, const int channel_index)
174{
175 return sseq->runtime->rename_channel_index == channel_index;
176}
177
178static float text_size_get(const SeqChannelDrawContext *context)
179{
180 const uiStyle *style = ui::style_get_dpi();
181 return ui::fontstyle_height_max(&style->widget) * 1.5f * context->scale;
182}
183
184/* TODO: decide what gets priority - label or buttons. */
186 const int channel_index,
187 const float used_width)
188{
189 float text_size = text_size_get(context);
190 float margin = (context->channel_height / context->scale - text_size) / 2.0f;
191 float y = channel_index_y_min(context, channel_index) + margin;
192
193 float margin_x = icon_width_get(context) * 0.65;
194 float width = max_ff(0.0f, context->v2d->cur.xmax / context->scale - used_width);
195
196 /* Text input has its own margin. Prevent text jumping around and use as much space as possible.
197 */
198 if (channel_is_being_renamed(CTX_wm_space_seq(context->C), channel_index)) {
199 float input_box_margin = icon_width_get(context) * 0.5f;
200 margin_x -= input_box_margin;
201 width += input_box_margin;
202 }
203
204 rctf rect;
205 BLI_rctf_init(&rect, margin_x, margin_x + width, y, y + text_size);
206 return rect;
207}
208
210 ui::Block *block,
211 const int channel_index,
212 const float used_width)
213{
214 SpaceSeq *sseq = CTX_wm_space_seq(context->C);
215 rctf rect = label_rect_init(context, channel_index, used_width);
216
217 if (BLI_rctf_size_y(&rect) <= 1.0f || BLI_rctf_size_x(&rect) <= 1.0f) {
218 return;
219 }
220
221 SeqTimelineChannel *channel = seq::channel_get_by_index(context->channels, channel_index);
222 if (channel_is_being_renamed(sseq, channel_index)) {
224 &context->scene->id, RNA_SequenceTimelineChannel, channel);
226
227 block_emboss_set(block, ui::EmbossType::Emboss);
228 ui::Button *but = uiDefButR(block,
230 "",
231 rect.xmin,
232 rect.ymin,
233 BLI_rctf_size_x(&rect),
234 BLI_rctf_size_y(&rect),
235 &ptr,
237 -1,
238 0,
239 0,
240 std::nullopt);
241 block_emboss_set(block, ui::EmbossType::None);
242
243 if (button_active_only(context->C, context->region, block, but) == false) {
244 sseq->runtime->rename_channel_index = 0;
245 }
246
247 WM_event_add_notifier(context->C, NC_SCENE | ND_SEQUENCER, context->scene);
248 }
249 else {
250 const char *label = channel->name;
251 uiDefBut(block,
253 label,
254 rect.xmin,
255 rect.ymin,
256 rect.xmax - rect.xmin,
257 (rect.ymax - rect.ymin),
258 nullptr,
259 0,
260 0,
261 std::nullopt);
262 }
263}
264
266{
268 wmOrtho2_pixelspace(context->region->winx / context->scale,
269 context->region->winy / context->scale);
270 ui::Block *block = block_begin(context->C, context->region, __func__, ui::EmbossType::Emboss);
271
272 int channel_range[2];
273 displayed_channel_range_get(context, channel_range);
274
275 const float icon_width = icon_width_get(context);
276 const float offset_lock = icon_width * 1.5f;
277 const float offset_mute = icon_width * 2.5f;
278 const float offset_width = icon_width * 3.5f;
279 /* Draw widgets separately from text labels so they are batched together,
280 * instead of alternating between two fonts (regular and SVG/icons). */
281 for (int channel = channel_range[0]; channel <= channel_range[1]; channel++) {
282 draw_channel_widget_lock(context, block, channel, offset_lock);
283 draw_channel_widget_mute(context, block, channel, offset_mute);
284 }
285 for (int channel = channel_range[0]; channel <= channel_range[1]; channel++) {
286 draw_channel_labels(context, block, channel, offset_width);
287 }
288
289 block_end(context->C, block);
290 block_draw(context->C, block);
291
293}
294
299
301 ARegion *region,
302 SeqChannelDrawContext *r_context)
303{
304 r_context->C = C;
305 r_context->area = CTX_wm_area(C);
306 r_context->region = region;
307 r_context->v2d = &region->v2d;
308 r_context->scene = CTX_data_sequencer_scene(C);
309 r_context->ed = seq::editing_get(r_context->scene);
310 r_context->seqbase = seq::active_seqbase_get(r_context->ed);
311 r_context->channels = seq::channels_displayed_get(r_context->ed);
313 BLI_assert(r_context->timeline_region != nullptr);
314 r_context->timeline_region_v2d = &r_context->timeline_region->v2d;
315
318 r_context->draw_offset = draw_offset_get(r_context->timeline_region_v2d);
319
320 r_context->scale = min_ff(r_context->channel_height / (U.widget_unit * 0.6), 1);
321}
322
323void draw_channels(const bContext *C, ARegion *region)
324{
327 if (!scene) {
328 return;
329 }
330
331 Editing *ed = seq::editing_get(scene);
332 if (ed == nullptr) {
333 return;
334 }
335
336 SeqChannelDrawContext context;
337 channel_draw_context_init(C, region, &context);
338
339 if (round_fl_to_int(context.channel_height) == 0) {
340 return;
341 }
342
343 ui::view2d_view_ortho(context.v2d);
344
345 draw_channel_headers(&context);
346
348}
349
350} // namespace blender::ed::vse
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define ND_SEQUENCER
Definition WM_types.hh:456
#define NC_SCENE
Definition WM_types.hh:391
#define CLAMP(a, b, c)
#define floor
#define ceil
static std::string draw_channel_widget_tooltip(bContext *, void *argN, const 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_lock(const SeqChannelDrawContext *context, ui::Block *block, const int channel_index, const float offset)
static void draw_channel_labels(const SeqChannelDrawContext *context, ui::Block *block, const int channel_index, const float used_width)
static float frame_width_pixelspace_get(const View2D *timeline_region_v2d)
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)
static float draw_channel_widget_mute(const SeqChannelDrawContext *context, ui::Block *block, const int channel_index, const float offset)
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)
ListBaseT< Strip > * active_seqbase_get(const Editing *ed)
Definition sequencer.cc:463
Editing * editing_get(const Scene *scene)
Definition sequencer.cc:304
constexpr int MAX_CHANNELS
SeqTimelineChannel * channel_get_by_index(const ListBaseT< SeqTimelineChannel > *channels, const int channel_index)
Definition channels.cc:59
void timeline_expand_boundbox(const Scene *scene, const ListBaseT< Strip > *seqbase, rctf *rect)
ListBaseT< SeqTimelineChannel > * channels_displayed_get(const Editing *ed)
Definition channels.cc:26
void frame_buffer_clear(int colorid)
void view2d_view_ortho(const View2D *v2d)
Definition view2d.cc:1080
void view2d_view_restore(const bContext *C)
Definition view2d.cc:1147
float view2d_view_to_region_y(const View2D *v2d, float y)
Definition view2d.cc:1678
const uiStyle * style_get_dpi()
int fontstyle_height_max(const uiFontStyle *fs)
float view2d_view_to_region_x(const View2D *v2d, float x)
Definition view2d.cc:1673
MINLINE float min_ff(float a, float b)
UserDef U
Definition blender.cc:58
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
ScrArea * CTX_wm_area(const bContext *C)
Scene * CTX_data_sequencer_scene(const bContext *C)
void wmOrtho2_pixelspace(const float x, const float y)
MINLINE int round_fl_to_int(float a)
const char * RNA_property_identifier(const PropertyRNA *prop)
char * BLI_sprintfN(const char *__restrict format,...) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_PRINTF_FORMAT(1
MINLINE int max_ii(int a, int b)
void MEM_delete_void(void *vmemh)
SpaceSeq * CTX_wm_space_seq(const bContext *C)
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
Definition BLI_rect.hh:215
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
PropertyRNA * RNA_struct_type_find_property(StructRNA *srna, const char *identifier)
PropertyRNA * RNA_struct_name_property(const StructRNA *type)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
ARegion * BKE_area_find_region_type(const ScrArea *area, int region_type)
Definition screen.cc:1024
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
Definition BLI_rect.hh:211
MINLINE float max_ff(float a, float b)
void GPU_matrix_pop()
void GPU_matrix_push()
void BLI_rctf_init(struct rctf *rect, float xmin, float xmax, float ymin, float ymax)
Definition rct.cc:418
StructRNA * type
Definition RNA_types.hh:63
ed::vse::SpaceSeq_Runtime * runtime
ListBaseT< SeqTimelineChannel > * channels
uiFontStyle widget