Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2021-07-30 09:43:47 +0300
committerCampbell Barton <ideasman42@gmail.com>2021-07-30 09:44:39 +0300
commit020431408f12ab7e1c3024e08a4067dce0ae2433 (patch)
tree554a4408bdb7c543cbd194a8851772f8339b877d /source/blender/editors/interface
parent93eb460dd0aca4de33bf780de76eee319c224bae (diff)
Cleanup: limit scope of temporary variables
Also remove early return as it duplicates cleanup calls.
Diffstat (limited to 'source/blender/editors/interface')
-rw-r--r--source/blender/editors/interface/view2d_draw.c45
1 files changed, 22 insertions, 23 deletions
diff --git a/source/blender/editors/interface/view2d_draw.c b/source/blender/editors/interface/view2d_draw.c
index 1496ce027ae..95427e49495 100644
--- a/source/blender/editors/interface/view2d_draw.c
+++ b/source/blender/editors/interface/view2d_draw.c
@@ -329,29 +329,28 @@ static void draw_horizontal_scale_indicators(const ARegion *region,
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((int)(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);
- to_string(to_string_data, xpos_view, distance, sizeof(text), text);
- const float text_width = BLF_width(font_id, text, strlen(text));
-
- if (xpos_region - text_width / 2.0f >= xmin && xpos_region + text_width / 2.0f <= xmax) {
- BLF_draw_default_ascii(xpos_region - text_width / 2.0f, ypos, 0.0f, text, sizeof(text));
+ int draw_frequency;
+ {
+ 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);
+ draw_frequency = ceil((float)steps / max_label_count);
+ }
+
+ if (draw_frequency != 0) {
+ const int start_index = abs((int)(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);
+ to_string(to_string_data, xpos_view, distance, sizeof(text), text);
+ const float text_width = BLF_width(font_id, text, strlen(text));
+
+ if (xpos_region - text_width / 2.0f >= xmin && xpos_region + text_width / 2.0f <= xmax) {
+ BLF_draw_default_ascii(xpos_region - text_width / 2.0f, ypos, 0.0f, text, sizeof(text));
+ }
}
}