diff options
author | Richard Antalik <richardantalik@gmail.com> | 2021-07-29 11:24:28 +0300 |
---|---|---|
committer | Richard Antalik <richardantalik@gmail.com> | 2021-07-29 12:38:43 +0300 |
commit | 3964785a1458ef5ba6d28485ff5f7343ccf3f61c (patch) | |
tree | df246144f2e6cdce2b61b9463459cc1d5e62e655 /source/blender/editors/interface/view2d_draw.c | |
parent | a70f37bd8a062f2b5c932c6bc8cff84919ca4d43 (diff) |
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
Diffstat (limited to 'source/blender/editors/interface/view2d_draw.c')
-rw-r--r-- | source/blender/editors/interface/view2d_draw.c | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/source/blender/editors/interface/view2d_draw.c b/source/blender/editors/interface/view2d_draw.c index f7ef8c06389..37c84b707fd 100644 --- a/source/blender/editors/interface/view2d_draw.c +++ b/source/blender/editors/interface/view2d_draw.c @@ -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); } |