UI: Remove Hard-coded Default Font Size

Default text output routines (which do not specify a size) will now use Text Style point size.

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

Reviewed by Brecht Van Lommel
This commit is contained in:
Harley Acheson 2020-10-12 09:53:00 -07:00
parent 1b7458f85a
commit 19dcd32ee5
5 changed files with 35 additions and 10 deletions

View file

@ -163,8 +163,13 @@ float BLF_height_ex(int fontid, const char *str, size_t len, struct ResultBLF *r
float BLF_height(int fontid, const char *str, size_t len) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
/* Return dimensions of the font without any sample text. */
int BLF_height_max(int fontid) ATTR_WARN_UNUSED_RESULT;
int BLF_default_height_max(void) ATTR_WARN_UNUSED_RESULT;
float BLF_width_max(int fontid) ATTR_WARN_UNUSED_RESULT;
float BLF_default_width_max(void) ATTR_WARN_UNUSED_RESULT;
float BLF_descender(int fontid) ATTR_WARN_UNUSED_RESULT;
float BLF_ascender(int fontid) ATTR_WARN_UNUSED_RESULT;

View file

@ -38,6 +38,7 @@
#include "MEM_guardedalloc.h"
#include "DNA_listBase.h"
#include "DNA_userdef_types.h"
#include "DNA_vec_types.h"
#include "BLI_math.h"
@ -47,6 +48,8 @@
#include "IMB_colormanagement.h"
#include "UI_interface.h"
#include "GPU_immediate.h"
#include "GPU_matrix.h"
#include "GPU_shader.h"
@ -75,7 +78,6 @@ static FontBLF *global_font[BLF_MAX_FONT] = {NULL};
/* Default size and dpi, for BLF_draw_default. */
static int global_font_default = -1;
static int global_font_points = 11;
static int global_font_dpi = 72;
/* XXX, should these be made into global_font_'s too? */
@ -96,7 +98,6 @@ int BLF_init(void)
global_font[i] = NULL;
}
global_font_points = 11;
global_font_dpi = 72;
return blf_font_init();
@ -518,7 +519,8 @@ void BLF_draw_default(float x, float y, float z, const char *str, size_t len)
{
ASSERT_DEFAULT_SET;
BLF_size(global_font_default, global_font_points, global_font_dpi);
const uiStyle *style = UI_style_get();
BLF_size(global_font_default, style->widgetlabel.points, global_font_dpi);
BLF_position(global_font_default, x, y, z);
BLF_draw(global_font_default, str, len);
}
@ -528,7 +530,8 @@ void BLF_draw_default_ascii(float x, float y, float z, const char *str, size_t l
{
ASSERT_DEFAULT_SET;
BLF_size(global_font_default, global_font_points, global_font_dpi);
const uiStyle *style = UI_style_get();
BLF_size(global_font_default, style->widgetlabel.points, global_font_dpi);
BLF_position(global_font_default, x, y, z);
BLF_draw_ascii(global_font_default, str, len); /* XXX, use real length */
}
@ -537,7 +540,8 @@ int BLF_set_default(void)
{
ASSERT_DEFAULT_SET;
BLF_size(global_font_default, global_font_points, global_font_dpi);
const uiStyle *style = UI_style_get();
BLF_size(global_font_default, style->widgetlabel.points, global_font_dpi);
return global_font_default;
}
@ -820,6 +824,11 @@ int BLF_height_max(int fontid)
return 0;
}
int BLF_default_height_max(void)
{
return BLF_height_max(global_font_default);
}
float BLF_width_max(int fontid)
{
FontBLF *font = blf_get(fontid);
@ -831,6 +840,11 @@ float BLF_width_max(int fontid)
return 0.0f;
}
float BLF_default_width_max(void)
{
return BLF_width_max(global_font_default);
}
float BLF_descender(int fontid)
{
FontBLF *font = blf_get(fontid);

View file

@ -226,6 +226,12 @@ enum {
UI_BUT_OVERRIDEN = 1u << 31u,
};
/* Default font size for normal text. */
#define UI_DEFAULT_TEXT_POINTS 11
/* Larger size used for title text. */
#define UI_DEFAULT_TITLE_POINTS 12
#define UI_PANEL_WIDTH 340
#define UI_COMPACT_PANEL_WIDTH 160
#define UI_SIDEBAR_PANEL_WIDTH 220

View file

@ -81,7 +81,7 @@ static uiStyle *ui_style_new(ListBase *styles, const char *name, short uifont_id
style->panelzoom = 1.0; /* unused */
style->paneltitle.uifont_id = uifont_id;
style->paneltitle.points = 12;
style->paneltitle.points = UI_DEFAULT_TITLE_POINTS;
style->paneltitle.kerning = 1;
style->paneltitle.shadow = 3;
style->paneltitle.shadx = 0;
@ -90,7 +90,7 @@ static uiStyle *ui_style_new(ListBase *styles, const char *name, short uifont_id
style->paneltitle.shadowcolor = 0.0f;
style->grouplabel.uifont_id = uifont_id;
style->grouplabel.points = 12;
style->grouplabel.points = UI_DEFAULT_TITLE_POINTS;
style->grouplabel.kerning = 1;
style->grouplabel.shadow = 3;
style->grouplabel.shadx = 0;
@ -99,7 +99,7 @@ static uiStyle *ui_style_new(ListBase *styles, const char *name, short uifont_id
style->grouplabel.shadowcolor = 0.0f;
style->widgetlabel.uifont_id = uifont_id;
style->widgetlabel.points = 11;
style->widgetlabel.points = UI_DEFAULT_TEXT_POINTS;
style->widgetlabel.kerning = 1;
style->widgetlabel.shadow = 3;
style->widgetlabel.shadx = 0;
@ -108,7 +108,7 @@ static uiStyle *ui_style_new(ListBase *styles, const char *name, short uifont_id
style->widgetlabel.shadowcolor = 0.0f;
style->widget.uifont_id = uifont_id;
style->widget.points = 11;
style->widget.points = UI_DEFAULT_TEXT_POINTS;
style->widget.kerning = 1;
style->widget.shadow = 1;
style->widget.shady = -1;

View file

@ -102,7 +102,7 @@
#define M_GOLDEN_RATIO_CONJUGATE 0.618033988749895f
#define VIEW3D_OVERLAY_LINEHEIGHT (0.9f * U.widget_unit)
#define VIEW3D_OVERLAY_LINEHEIGHT (int)(1.1f * BLF_default_height_max())
/* -------------------------------------------------------------------- */
/** \name General Functions