From 27c95da888ad47b5edfbc985e52782a5d9f052fe Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Thu, 28 Mar 2024 04:02:13 +0100 Subject: [PATCH] Refactor: Remove BLF _ex functions using default arguments Remove all BLF "_ex" versions of functions by using default arguments. These functions only differ by having an optional argument that can return extra details about the result of the operation. This PR just make these part of the main function as optional arguments with default values - all nullptr. Pull Request: https://projects.blender.org/blender/blender/pulls/119994 --- source/blender/blenfont/BLF_api.hh | 23 ++++---- source/blender/blenfont/intern/blf.cc | 52 ++++++------------- source/blender/blenkernel/intern/image.cc | 2 +- .../editors/interface/interface_style.cc | 2 +- .../regions/interface_region_tooltip.cc | 2 +- .../blender/editors/space_node/node_draw.cc | 2 +- source/blender/editors/util/ed_draw.cc | 4 +- source/blender/sequencer/intern/effects.cc | 2 +- 8 files changed, 32 insertions(+), 57 deletions(-) diff --git a/source/blender/blenfont/BLF_api.hh b/source/blender/blenfont/BLF_api.hh index 81198ebbee0..2b644705376 100644 --- a/source/blender/blenfont/BLF_api.hh +++ b/source/blender/blenfont/BLF_api.hh @@ -144,8 +144,8 @@ void BLF_batch_draw_end(); /** * Draw the string using the current font. */ -void BLF_draw_ex(int fontid, const char *str, size_t str_len, ResultBLF *r_info) ATTR_NONNULL(2); -void BLF_draw(int fontid, const char *str, size_t str_len) ATTR_NONNULL(2); +void BLF_draw(int fontid, const char *str, size_t str_len, ResultBLF *r_info = nullptr) + ATTR_NONNULL(2); int BLF_draw_mono(int fontid, const char *str, size_t str_len, int cwidth, int tab_columns) ATTR_NONNULL(2); @@ -205,23 +205,21 @@ size_t BLF_width_to_rstrlen(int fontid, * This function return the bounding box of the string * and are not multiplied by the aspect. */ -void BLF_boundbox_ex(int fontid, const char *str, size_t str_len, rcti *box, ResultBLF *r_info) - ATTR_NONNULL(2); -void BLF_boundbox(int fontid, const char *str, size_t str_len, rcti *box) ATTR_NONNULL(); +void BLF_boundbox(int fontid, + const char *str, + size_t str_len, + rcti *box, + ResultBLF *r_info = nullptr) ATTR_NONNULL(2); /** * The next both function return the width and height * of the string, using the current font and both value * are multiplied by the aspect of the font. */ -float BLF_width_ex(int fontid, const char *str, size_t str_len, ResultBLF *r_info) +float BLF_width(int fontid, const char *str, size_t str_len, ResultBLF *r_info = nullptr) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2); -float BLF_width(int fontid, const char *str, size_t str_len) ATTR_WARN_UNUSED_RESULT - ATTR_NONNULL(); -float BLF_height_ex(int fontid, const char *str, size_t str_len, ResultBLF *r_info) +float BLF_height(int fontid, const char *str, size_t str_len, ResultBLF *r_info = nullptr) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2); -float BLF_height(int fontid, const char *str, size_t str_len) ATTR_WARN_UNUSED_RESULT - ATTR_NONNULL(); /** * Return dimensions of the font without any sample text. @@ -306,9 +304,8 @@ void BLF_buffer_col(int fontid, const float rgba[4]) ATTR_NONNULL(2); * Draw the string into the buffer, this function draw in both buffer, * float and unsigned char _BUT_ it's not necessary set both buffer, NULL is valid here. */ -void BLF_draw_buffer_ex(int fontid, const char *str, size_t str_len, ResultBLF *r_info) +void BLF_draw_buffer(int fontid, const char *str, size_t str_len, ResultBLF *r_info = nullptr) ATTR_NONNULL(2); -void BLF_draw_buffer(int fontid, const char *str, size_t str_len) ATTR_NONNULL(2); /* `blf_thumbs.cc` */ diff --git a/source/blender/blenfont/intern/blf.cc b/source/blender/blenfont/intern/blf.cc index 6f961630db4..e5a4e83d4e9 100644 --- a/source/blender/blenfont/intern/blf.cc +++ b/source/blender/blenfont/intern/blf.cc @@ -567,13 +567,21 @@ static void blf_draw_gpu__end(const FontBLF *font) } } -void BLF_draw_ex(int fontid, const char *str, const size_t str_len, ResultBLF *r_info) +void BLF_draw(int fontid, const char *str, const size_t str_len, ResultBLF *r_info) { - FontBLF *font = blf_get(fontid); - BLF_RESULT_CHECK_INIT(r_info); + if (str_len == 0 || str[0] == '\0') { + return; + } + + FontBLF *font = blf_get(fontid); + if (font) { + + /* Avoid bgl usage to corrupt BLF drawing. */ + GPU_bgl_end(); + blf_draw_gpu__start(font); if (font->flags & BLF_WORD_WRAP) { blf_font_draw__wrap(font, str, str_len, r_info); @@ -584,17 +592,6 @@ void BLF_draw_ex(int fontid, const char *str, const size_t str_len, ResultBLF *r blf_draw_gpu__end(font); } } -void BLF_draw(int fontid, const char *str, const size_t str_len) -{ - if (str_len == 0 || str[0] == '\0') { - return; - } - - /* Avoid bgl usage to corrupt BLF drawing. */ - GPU_bgl_end(); - - BLF_draw_ex(fontid, str, str_len, nullptr); -} int BLF_draw_mono(int fontid, const char *str, const size_t str_len, int cwidth, int tab_columns) { @@ -699,7 +696,7 @@ size_t BLF_width_to_rstrlen( return 0; } -void BLF_boundbox_ex( +void BLF_boundbox( int fontid, const char *str, const size_t str_len, rcti *r_box, ResultBLF *r_info) { FontBLF *font = blf_get(fontid); @@ -716,11 +713,6 @@ void BLF_boundbox_ex( } } -void BLF_boundbox(int fontid, const char *str, const size_t str_len, rcti *r_box) -{ - BLF_boundbox_ex(fontid, str, str_len, r_box, nullptr); -} - void BLF_width_and_height( int fontid, const char *str, const size_t str_len, float *r_width, float *r_height) { @@ -734,7 +726,7 @@ void BLF_width_and_height( } } -float BLF_width_ex(int fontid, const char *str, const size_t str_len, ResultBLF *r_info) +float BLF_width(int fontid, const char *str, const size_t str_len, ResultBLF *r_info) { FontBLF *font = blf_get(fontid); @@ -747,11 +739,6 @@ float BLF_width_ex(int fontid, const char *str, const size_t str_len, ResultBLF return 0.0f; } -float BLF_width(int fontid, const char *str, const size_t str_len) -{ - return BLF_width_ex(fontid, str, str_len, nullptr); -} - float BLF_fixed_width(int fontid) { FontBLF *font = blf_get(fontid); @@ -763,7 +750,7 @@ float BLF_fixed_width(int fontid) return 0.0f; } -float BLF_height_ex(int fontid, const char *str, const size_t str_len, ResultBLF *r_info) +float BLF_height(int fontid, const char *str, const size_t str_len, ResultBLF *r_info) { FontBLF *font = blf_get(fontid); @@ -776,11 +763,6 @@ float BLF_height_ex(int fontid, const char *str, const size_t str_len, ResultBLF return 0.0f; } -float BLF_height(int fontid, const char *str, const size_t str_len) -{ - return BLF_height_ex(fontid, str, str_len, nullptr); -} - int BLF_height_max(int fontid) { FontBLF *font = blf_get(fontid); @@ -915,7 +897,7 @@ void blf_draw_buffer__start(FontBLF *font) } void blf_draw_buffer__end() {} -void BLF_draw_buffer_ex(int fontid, const char *str, const size_t str_len, ResultBLF *r_info) +void BLF_draw_buffer(int fontid, const char *str, const size_t str_len, ResultBLF *r_info) { FontBLF *font = blf_get(fontid); @@ -930,10 +912,6 @@ void BLF_draw_buffer_ex(int fontid, const char *str, const size_t str_len, Resul blf_draw_buffer__end(); } } -void BLF_draw_buffer(int fontid, const char *str, const size_t str_len) -{ - BLF_draw_buffer_ex(fontid, str, str_len, nullptr); -} blender::Vector BLF_string_wrap(int fontid, blender::StringRef str, diff --git a/source/blender/blenkernel/intern/image.cc b/source/blender/blenkernel/intern/image.cc index b770952b735..b33cd6cb1b6 100644 --- a/source/blender/blenkernel/intern/image.cc +++ b/source/blender/blenkernel/intern/image.cc @@ -2003,7 +2003,7 @@ void BKE_image_stamp_buf(Scene *scene, /* must enable BLF_WORD_WRAP before using */ #define TEXT_SIZE_CHECK_WORD_WRAP(str, w, h) \ - ((str[0]) && (BLF_boundbox_ex(mono, str, sizeof(str), &wrap.rect, &wrap.info), \ + ((str[0]) && (BLF_boundbox(mono, str, sizeof(str), &wrap.rect, &wrap.info), \ (void)(h = h_fixed * wrap.info.lines), \ (w = BLI_rcti_size_x(&wrap.rect)))) diff --git a/source/blender/editors/interface/interface_style.cc b/source/blender/editors/interface/interface_style.cc index a15fd5b1f6f..cb378cbddc6 100644 --- a/source/blender/editors/interface/interface_style.cc +++ b/source/blender/editors/interface/interface_style.cc @@ -182,7 +182,7 @@ void UI_fontstyle_draw_ex(const uiFontStyle *fs, BLF_position(fs->uifont_id, rect->xmin + xofs, rect->ymin + yofs, 0.0f); BLF_color4ubv(fs->uifont_id, col); - BLF_draw_ex(fs->uifont_id, str, str_len, r_info); + BLF_draw(fs->uifont_id, str, str_len, r_info); BLF_disable(fs->uifont_id, font_flag); diff --git a/source/blender/editors/interface/regions/interface_region_tooltip.cc b/source/blender/editors/interface/regions/interface_region_tooltip.cc index e6d8ea13c47..045e7e05401 100644 --- a/source/blender/editors/interface/regions/interface_region_tooltip.cc +++ b/source/blender/editors/interface/regions/interface_region_tooltip.cc @@ -1208,7 +1208,7 @@ static ARegion *ui_tooltip_create_with_data(bContext *C, } if (!field->text.empty()) { - w = BLF_width_ex(font_id, field->text.c_str(), field->text.size(), &info); + w = BLF_width(font_id, field->text.c_str(), field->text.size(), &info); } /* check for suffix (enum label) */ diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc index 245c1094825..607932e6807 100644 --- a/source/blender/editors/space_node/node_draw.cc +++ b/source/blender/editors/space_node/node_draw.cc @@ -3773,7 +3773,7 @@ static void frame_node_draw_label(TreeDrawContext &tree_draw_ctx, if (line->line[0]) { BLF_position(fontid, x, y, 0); ResultBLF info; - BLF_draw_ex(fontid, line->line, line->len, &info); + BLF_draw(fontid, line->line, line->len, &info); y -= line_spacing * info.lines; } else { diff --git a/source/blender/editors/util/ed_draw.cc b/source/blender/editors/util/ed_draw.cc index 28cdfdaee4e..1e8474735f5 100644 --- a/source/blender/editors/util/ed_draw.cc +++ b/source/blender/editors/util/ed_draw.cc @@ -731,7 +731,7 @@ static void metadata_draw_imbuf(ImBuf *ibuf, const rctf *rect, int fontid, const BLF_enable(fontid, BLF_WORD_WRAP); BLF_wordwrap(fontid, ibuf->x - (margin * 2)); BLF_position(fontid, xmin, ymax - vertical_offset - ofs_y, 0.0f); - BLF_draw_ex(fontid, temp_str, sizeof(temp_str), &info); + BLF_draw(fontid, temp_str, sizeof(temp_str), &info); BLF_wordwrap(fontid, 0); BLF_disable(fontid, BLF_WORD_WRAP); ofs_y += vertical_offset * info.lines; @@ -804,7 +804,7 @@ static float metadata_box_height_get(ImBuf *ibuf, int fontid, const bool is_top) BLF_enable(fontid, BLF_WORD_WRAP); BLF_wordwrap(fontid, ibuf->x - (margin * 2)); - BLF_boundbox_ex(fontid, str, sizeof(str), &wrap.rect, &wrap.info); + BLF_boundbox(fontid, str, sizeof(str), &wrap.rect, &wrap.info); BLF_wordwrap(fontid, 0); BLF_disable(fontid, BLF_WORD_WRAP); diff --git a/source/blender/sequencer/intern/effects.cc b/source/blender/sequencer/intern/effects.cc index c41a0e63efb..00146c174e1 100644 --- a/source/blender/sequencer/intern/effects.cc +++ b/source/blender/sequencer/intern/effects.cc @@ -2770,7 +2770,7 @@ static ImBuf *do_text_effect(const SeqRenderData *context, rcti rect; } wrap; - BLF_boundbox_ex(font, data->text, sizeof(data->text), &wrap.rect, &wrap.info); + BLF_boundbox(font, data->text, sizeof(data->text), &wrap.rect, &wrap.info); if ((data->align == SEQ_TEXT_ALIGN_X_LEFT) && (data->align_y == SEQ_TEXT_ALIGN_Y_TOP)) { y -= line_height;