[Bf-blender-cvs] [89145341e5d] master: BLF: UI_fontstyle_draw Usage

Harley Acheson noreply at git.blender.org
Tue Jan 11 23:53:31 CET 2022


Commit: 89145341e5ddcefbe71c664db8a853abe3b93344
Author: Harley Acheson
Date:   Tue Jan 11 14:52:39 2022 -0800
Branches: master
https://developer.blender.org/rB89145341e5ddcefbe71c664db8a853abe3b93344

BLF: UI_fontstyle_draw Usage

Add maximum string length argument to UI_fontstyle_draw to reduce usage
of BLF_DRAW_STR_DUMMY_MAX. Reorders arguments to UI_fontstyle_draw_ex

See D13794 for more details.

Differential Revision: https://developer.blender.org/D13794

Reviewed by Campbell Barton

===================================================================

M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface_panel.c
M	source/blender/editors/interface/interface_region_tooltip.c
M	source/blender/editors/interface/interface_style.c
M	source/blender/editors/interface/interface_widgets.c
M	source/blender/editors/space_file/file_draw.c

===================================================================

diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index f01b8318e98..5ecc43a9fc9 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -2957,15 +2957,17 @@ void UI_fontstyle_set(const struct uiFontStyle *fs);
 void UI_fontstyle_draw_ex(const struct uiFontStyle *fs,
                           const struct rcti *rect,
                           const char *str,
+                          size_t str_len,
                           const uchar col[4],
                           const struct uiFontStyleDraw_Params *fs_params,
-                          size_t len,
                           int *r_xofs,
                           int *r_yofs,
                           struct ResultBLF *r_info);
+
 void UI_fontstyle_draw(const struct uiFontStyle *fs,
                        const struct rcti *rect,
                        const char *str,
+                       size_t str_len,
                        const uchar col[4],
                        const struct uiFontStyleDraw_Params *fs_params);
 /**
diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c
index bc1d3387ad7..135cef5fe53 100644
--- a/source/blender/editors/interface/interface_panel.c
+++ b/source/blender/editors/interface/interface_panel.c
@@ -1146,6 +1146,7 @@ static void panel_draw_aligned_widgets(const uiStyle *style,
     UI_fontstyle_draw(fontstyle,
                       &title_rect,
                       panel->drawname,
+                      sizeof(panel->drawname),
                       title_color,
                       &(struct uiFontStyleDraw_Params){
                           .align = UI_STYLE_TEXT_LEFT,
diff --git a/source/blender/editors/interface/interface_region_tooltip.c b/source/blender/editors/interface/interface_region_tooltip.c
index e146443faaa..fe58a6a05ae 100644
--- a/source/blender/editors/interface/interface_region_tooltip.c
+++ b/source/blender/editors/interface/interface_region_tooltip.c
@@ -74,6 +74,8 @@
 #define UI_TIP_PADDING (int)(UI_TIP_PAD_FAC * UI_UNIT_Y)
 #define UI_TIP_MAXWIDTH 600
 
+#define UI_TIP_STR_MAX 1024
+
 typedef struct uiTooltipFormat {
   enum {
     UI_TIP_STYLE_NORMAL = 0,
@@ -214,7 +216,7 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *region
       /* draw header and active data (is done here to be able to change color) */
       rgb_float_to_uchar(drawcol, tip_colors[UI_TIP_LC_MAIN]);
       UI_fontstyle_set(&data->fstyle);
-      UI_fontstyle_draw(&data->fstyle, &bbox, field->text, drawcol, &fs_params);
+      UI_fontstyle_draw(&data->fstyle, &bbox, field->text, UI_TIP_STR_MAX, drawcol, &fs_params);
 
       /* offset to the end of the last line */
       if (field->text_suffix) {
@@ -224,7 +226,8 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *region
         bbox.ymax -= yofs;
 
         rgb_float_to_uchar(drawcol, tip_colors[UI_TIP_LC_ACTIVE]);
-        UI_fontstyle_draw(&data->fstyle, &bbox, field->text_suffix, drawcol, &fs_params);
+        UI_fontstyle_draw(
+            &data->fstyle, &bbox, field->text_suffix, UI_TIP_STR_MAX, drawcol, &fs_params);
 
         /* undo offset */
         bbox.xmin -= xofs;
@@ -243,7 +246,7 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *region
       /* XXX, needed because we don't have mono in 'U.uifonts' */
       BLF_size(fstyle_mono.uifont_id, fstyle_mono.points * U.pixelsize, U.dpi);
       rgb_float_to_uchar(drawcol, tip_colors[field->format.color_id]);
-      UI_fontstyle_draw(&fstyle_mono, &bbox, field->text, drawcol, &fs_params);
+      UI_fontstyle_draw(&fstyle_mono, &bbox, field->text, UI_TIP_STR_MAX, drawcol, &fs_params);
     }
     else {
       BLI_assert(field->format.style == UI_TIP_STYLE_NORMAL);
@@ -255,7 +258,7 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *region
       /* draw remaining data */
       rgb_float_to_uchar(drawcol, tip_colors[field->format.color_id]);
       UI_fontstyle_set(&data->fstyle);
-      UI_fontstyle_draw(&data->fstyle, &bbox, field->text, drawcol, &fs_params);
+      UI_fontstyle_draw(&data->fstyle, &bbox, field->text, UI_TIP_STR_MAX, drawcol, &fs_params);
     }
 
     bbox.ymax -= data->lineh * field->geom.lines;
@@ -1215,12 +1218,12 @@ static ARegion *ui_tooltip_create_with_data(bContext *C,
       BLI_assert(ELEM(field->format.style, UI_TIP_STYLE_NORMAL, UI_TIP_STYLE_HEADER));
       font_id = data->fstyle.uifont_id;
     }
-    w = BLF_width_ex(font_id, field->text, BLF_DRAW_STR_DUMMY_MAX, &info);
+    w = BLF_width_ex(font_id, field->text, UI_TIP_STR_MAX, &info);
 
     /* check for suffix (enum label) */
     if (field->text_suffix && field->text_suffix[0]) {
       x_pos = info.width;
-      w = max_ii(w, x_pos + BLF_width(font_id, field->text_suffix, BLF_DRAW_STR_DUMMY_MAX));
+      w = max_ii(w, x_pos + BLF_width(font_id, field->text_suffix, UI_TIP_STR_MAX));
     }
     fontw = max_ii(fontw, w);
 
diff --git a/source/blender/editors/interface/interface_style.c b/source/blender/editors/interface/interface_style.c
index c28769a4951..44942d508ca 100644
--- a/source/blender/editors/interface/interface_style.c
+++ b/source/blender/editors/interface/interface_style.c
@@ -140,9 +140,9 @@ static uiFont *uifont_to_blfont(int id)
 void UI_fontstyle_draw_ex(const uiFontStyle *fs,
                           const rcti *rect,
                           const char *str,
+                          const size_t str_len,
                           const uchar col[4],
                           const struct uiFontStyleDraw_Params *fs_params,
-                          size_t len,
                           int *r_xofs,
                           int *r_yofs,
                           struct ResultBLF *r_info)
@@ -183,10 +183,10 @@ void UI_fontstyle_draw_ex(const uiFontStyle *fs,
   }
 
   if (fs_params->align == UI_STYLE_TEXT_CENTER) {
-    xofs = floor(0.5f * (BLI_rcti_size_x(rect) - BLF_width(fs->uifont_id, str, len)));
+    xofs = floor(0.5f * (BLI_rcti_size_x(rect) - BLF_width(fs->uifont_id, str, str_len)));
   }
   else if (fs_params->align == UI_STYLE_TEXT_RIGHT) {
-    xofs = BLI_rcti_size_x(rect) - BLF_width(fs->uifont_id, str, len);
+    xofs = BLI_rcti_size_x(rect) - BLF_width(fs->uifont_id, str, str_len);
   }
 
   yofs = MAX2(0, yofs);
@@ -196,7 +196,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, len, r_info);
+  BLF_draw_ex(fs->uifont_id, str, str_len, r_info);
 
   BLF_disable(fs->uifont_id, font_flag);
 
@@ -211,12 +211,11 @@ void UI_fontstyle_draw_ex(const uiFontStyle *fs,
 void UI_fontstyle_draw(const uiFontStyle *fs,
                        const rcti *rect,
                        const char *str,
+                       const size_t str_len,
                        const uchar col[4],
                        const struct uiFontStyleDraw_Params *fs_params)
 {
-  int xofs, yofs;
-
-  UI_fontstyle_draw_ex(fs, rect, str, col, fs_params, BLF_DRAW_STR_DUMMY_MAX, &xofs, &yofs, NULL);
+  UI_fontstyle_draw_ex(fs, rect, str, str_len, col, fs_params, NULL, NULL, NULL);
 }
 
 void UI_fontstyle_draw_rotated(const uiFontStyle *fs,
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index 06de4f09d06..b44496731f7 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -2130,11 +2130,11 @@ static void widget_draw_text(const uiFontStyle *fstyle,
       UI_fontstyle_draw_ex(fstyle,
                            rect,
                            drawstr + but->ofs,
+                           drawlen,
                            wcol->text,
                            &(struct uiFontStyleDraw_Params){
                                .align = align,
                            },
-                           drawlen,
                            &font_xofs,
                            &font_yofs,
                            NULL);
@@ -2194,6 +2194,7 @@ static void widget_draw_text(const uiFontStyle *fstyle,
     UI_fontstyle_draw(fstyle,
                       rect,
                       drawstr_right,
+                      UI_MAX_DRAW_STR,
                       col,
                       &(struct uiFontStyleDraw_Params){
                           .align = UI_STYLE_TEXT_RIGHT,
@@ -5417,11 +5418,11 @@ void ui_draw_menu_item(const uiFontStyle *fstyle,
     UI_fontstyle_draw_ex(fstyle,
                          rect,
                          drawstr,
+                         sizeof(drawstr),
                          wt->wcol.text,
                          &(struct uiFontStyleDraw_Params){
                              .align = UI_STYLE_TEXT_LEFT,
                          },
-                         sizeof(drawstr),
                          &xofs,
                          &yofs,
                          &info);
@@ -5468,6 +5469,7 @@ void ui_draw_menu_item(const uiFontStyle *fstyle,
       UI_fontstyle_draw(fstyle,
                         rect,
                         hint_drawstr,
+                        sizeof(hint_drawstr),
                         wt->wcol.text,
                         &(struct uiFontStyleDraw_Params){
                             .align = UI_STYLE_TEXT_RIGHT,
@@ -5523,6 +5525,7 @@ void ui_draw_preview_item_stateless(const uiFontStyle *fstyle,
     UI_fontstyle_draw(fstyle,
                       &trect,
                       drawstr,
+                      sizeof(drawstr),
                       text_col,
                       &(struct uiFontStyleDraw_Params){
                           .align = text_align,
diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c
index 44e9735866d..dd1b4e10e60 100644
--- a/source/blender/editors/space_file/file_draw.c
+++ b/source/blender/editors/space_file/file_draw.c
@@ -240,6 +240,7 @@ static void file_draw_string(int sx,
   UI_fontstyle_draw(&fs,
 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list