UI: Fix time labels drawing
Calculate frequency of time/frame label drawing, such that labels have at least 10px margin and don't overlap. Change timecode format: - Use at least `mm:ss` format - Don't display frames if all labels would end with +00 Reviewed By: Severin Differential Revision: https://developer.blender.org/D11792
This commit is contained in:
parent
a70f37bd8a
commit
3964785a14
Notes:
blender-bot
2023-02-14 10:21:15 +01:00
Referenced by commit 3f84f0123e
, Cleanup: Fix build warning
|
@ -115,7 +115,7 @@ size_t BLI_timecode_string_from_time(char *str,
|
|||
str, maxncpy, "%s%02d:%02d+%02d", neg, minutes, seconds, frames);
|
||||
}
|
||||
else {
|
||||
rlen = BLI_snprintf_rlen(str, maxncpy, "%s%d+%02d", neg, seconds, frames);
|
||||
rlen = BLI_snprintf_rlen(str, maxncpy, "%s00:%02d+%02d", neg, seconds, frames);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -326,10 +326,27 @@ static void draw_horizontal_scale_indicators(const ARegion *region,
|
|||
const float xmin = rect->xmin;
|
||||
const float xmax = rect->xmax;
|
||||
|
||||
for (uint i = 0; i < steps; i++) {
|
||||
char text[32];
|
||||
|
||||
/* Calculate max_label_count and draw_frequency based on largest visible label. */
|
||||
to_string(to_string_data, start, 0, sizeof(text), text);
|
||||
const float left_text_width = BLF_width(font_id, text, strlen(text));
|
||||
to_string(to_string_data, start + steps * distance, 0, sizeof(text), text);
|
||||
const float right_text_width = BLF_width(font_id, text, strlen(text));
|
||||
const float max_text_width = max_ff(left_text_width, right_text_width);
|
||||
const float max_label_count = BLI_rcti_size_x(&v2d->mask) / (max_text_width + 10.0f);
|
||||
const int draw_frequency = ceil((float)steps / max_label_count);
|
||||
|
||||
if (draw_frequency == 0) {
|
||||
BLF_batch_draw_end();
|
||||
GPU_matrix_pop_projection();
|
||||
return;
|
||||
}
|
||||
|
||||
const int start_index = abs(start / distance) % draw_frequency;
|
||||
for (uint i = start_index; i < steps; i += draw_frequency) {
|
||||
const float xpos_view = start + i * distance;
|
||||
const float xpos_region = UI_view2d_view_to_region_x(v2d, xpos_view);
|
||||
char text[32];
|
||||
to_string(to_string_data, xpos_view, distance, sizeof(text), text);
|
||||
const float text_width = BLF_width(font_id, text, strlen(text));
|
||||
|
||||
|
@ -339,7 +356,6 @@ static void draw_horizontal_scale_indicators(const ARegion *region,
|
|||
}
|
||||
|
||||
BLF_batch_draw_end();
|
||||
|
||||
GPU_matrix_pop_projection();
|
||||
}
|
||||
|
||||
|
@ -413,11 +429,15 @@ static void view_to_string__frame_number(
|
|||
}
|
||||
|
||||
static void view_to_string__time(
|
||||
void *user_data, float v2d_pos, float UNUSED(v2d_step), uint max_len, char *r_str)
|
||||
void *user_data, float v2d_pos, float v2d_step, uint max_len, char *r_str)
|
||||
{
|
||||
const Scene *scene = (const Scene *)user_data;
|
||||
|
||||
const int brevity_level = 0;
|
||||
int brevity_level = 0;
|
||||
if (U.timecode_style == USER_TIMECODE_MINIMAL && v2d_step >= FPS) {
|
||||
brevity_level = 1;
|
||||
}
|
||||
|
||||
BLI_timecode_string_from_time(
|
||||
r_str, max_len, brevity_level, v2d_pos / (float)FPS, FPS, U.timecode_style);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue