diff options
author | Campbell Barton <campbell@blender.org> | 2022-04-13 05:45:41 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-04-13 06:06:29 +0300 |
commit | 21ae323dbf28b4e0049e68153fe1a310ccf5ebef (patch) | |
tree | 184d0ff206289632094a71f574d6c8270c872a3c /source/blender/editors | |
parent | ae43872ad572eb3e6ad1ebfd02921fc2403059bc (diff) |
Cleanup: avoid redundant float/int conversions in BLF
Internally many offsets for BLF were integers but exposed as floats,
since these are used in pixel-space, many callers were converging them
back to integers. Simplify logic by using ints.
Diffstat (limited to 'source/blender/editors')
5 files changed, 12 insertions, 12 deletions
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 8935df7b581..2c408619fe7 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -3018,12 +3018,12 @@ static bool ui_textedit_set_cursor_pos_foreach_glyph(const char *UNUSED(str), const size_t str_step_ofs, const rcti *glyph_step_bounds, const int UNUSED(glyph_advance_x), - const rctf *glyph_bounds, + const rcti *glyph_bounds, const int UNUSED(glyph_bearing[2]), void *user_data) { int *cursor_data = user_data; - const float center = glyph_step_bounds->xmin + (BLI_rctf_size_x(glyph_bounds) / 2.0f); + const int center = glyph_step_bounds->xmin + (BLI_rcti_size_x(glyph_bounds) / 2.0f); if (cursor_data[0] < center) { cursor_data[1] = str_step_ofs; return false; diff --git a/source/blender/editors/interface/interface_style.cc b/source/blender/editors/interface/interface_style.cc index b4e97f8a396..0156a943015 100644 --- a/source/blender/editors/interface/interface_style.cc +++ b/source/blender/editors/interface/interface_style.cc @@ -161,7 +161,7 @@ void UI_fontstyle_draw_ex(const uiFontStyle *fs, } else { /* Draw from bound-box center. */ - const float height = BLF_ascender(fs->uifont_id) + BLF_descender(fs->uifont_id); + const int height = BLF_ascender(fs->uifont_id) + BLF_descender(fs->uifont_id); yofs = ceil(0.5f * (BLI_rcti_size_y(rect) - height)); } @@ -279,9 +279,9 @@ void UI_fontstyle_draw_simple_backdrop(const uiFontStyle *fs, UI_fontstyle_set(fs); { - const float width = BLF_width(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX); - const float height = BLF_height_max(fs->uifont_id); - const float decent = BLF_descender(fs->uifont_id); + const int width = BLF_width(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX); + const int height = BLF_height_max(fs->uifont_id); + const int decent = BLF_descender(fs->uifont_id); const float margin = height / 4.0f; rctf rect; diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index a16c24f63cd..98ecf91adbc 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -1859,15 +1859,15 @@ static bool widget_draw_text_underline_calc_position(const char *UNUSED(str), const size_t str_step_ofs, const rcti *glyph_step_bounds, const int UNUSED(glyph_advance_x), - const rctf *glyph_bounds, + const rcti *glyph_bounds, const int UNUSED(glyph_bearing[2]), void *user_data) { struct UnderlineData *ul_data = user_data; if (ul_data->str_offset == str_step_ofs) { /* Full width of this glyph including both bearings. */ - const float width = glyph_bounds->xmin + BLI_rctf_size_x(glyph_bounds) + glyph_bounds->xmin; - ul_data->r_offset_px[0] = glyph_step_bounds->xmin + ((width - ul_data->width_px) * 0.5f); + const int width = glyph_bounds->xmin + BLI_rcti_size_x(glyph_bounds) + glyph_bounds->xmin; + ul_data->r_offset_px[0] = glyph_step_bounds->xmin + ((width - ul_data->width_px) / 2); /* One line-width below the lower glyph bounds. */ ul_data->r_offset_px[1] = glyph_bounds->ymin - U.pixelsize; /* Early exit. */ diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c index 0438ba8dcd2..0e2b98ca349 100644 --- a/source/blender/editors/space_file/file_draw.c +++ b/source/blender/editors/space_file/file_draw.c @@ -248,7 +248,7 @@ static void file_draw_string_multiline(int sx, int font_id = style->widgetlabel.uifont_id; int len = strlen(string); - rctf textbox; + rcti textbox; BLF_wordwrap(font_id, wrap_width); BLF_enable(font_id, BLF_WORD_WRAP); BLF_boundbox(font_id, string, len, &textbox); @@ -260,7 +260,7 @@ static void file_draw_string_multiline(int sx, rect.xmax = sx + wrap_width; /* Need to increase the clipping rect by one more line, since the #UI_fontstyle_draw_ex() will * actually start drawing at (ymax - line-height). */ - rect.ymin = sy - round_fl_to_int(BLI_rctf_size_y(&textbox)) - line_height; + rect.ymin = sy - BLI_rcti_size_y(&textbox) - line_height; rect.ymax = sy; struct ResultBLF result; diff --git a/source/blender/editors/util/ed_draw.c b/source/blender/editors/util/ed_draw.c index eaa1684930d..1b6a3efe19c 100644 --- a/source/blender/editors/util/ed_draw.c +++ b/source/blender/editors/util/ed_draw.c @@ -711,7 +711,7 @@ static float metadata_box_height_get(ImBuf *ibuf, int fontid, const bool is_top) if (i == 4) { struct { struct ResultBLF info; - rctf rect; + rcti rect; } wrap; BLF_enable(fontid, BLF_WORD_WRAP); |