Cleanup: remove window_manager & editor includes from BLF

Remove the need to include the window manager & editor functions
in low level font rendering code.

- The default font size is now set when changed in the preferences.
- Flushing cache is set as a callback.
This commit is contained in:
Campbell Barton 2021-11-06 16:26:09 +11:00
parent a804a11db1
commit 81baeec59b
6 changed files with 46 additions and 22 deletions

View File

@ -43,6 +43,8 @@ void BLF_exit(void);
void BLF_cache_clear(void);
void BLF_cache_flush_set_fn(void (*cache_flush_fn)(void));
/* Loads a font, or returns an already loaded font and increments its reference count. */
int BLF_load(const char *name) ATTR_NONNULL();
int BLF_load_mem(const char *name, const unsigned char *mem, int mem_size) ATTR_NONNULL();
@ -250,6 +252,7 @@ void BLF_thumb_preview(const char *filename,
/* blf_default.c */
void BLF_default_dpi(int dpi);
void BLF_default_size(int size);
void BLF_default_set(int fontid);
int BLF_default(void); /* get default font ID so we can pass it to other functions */
/* Draw the string using the default font, size and dpi. */

View File

@ -23,12 +23,10 @@ set(INC
../blenkernel
../blenlib
../blentranslation
../editors/include
../gpu
../imbuf
../makesdna
../makesrna
../windowmanager
../../../intern/glew-mx
../../../intern/guardedalloc
)

View File

@ -29,8 +29,6 @@
#include "BLF_api.h"
#include "UI_interface.h"
#include "blf_internal.h"
/* call BLF_default_set first! */
@ -39,12 +37,19 @@
/* Default size and dpi, for BLF_draw_default. */
static int global_font_default = -1;
static int global_font_dpi = 72;
/* Keep in sync with `UI_style_get()->widgetlabel.points` */
static int global_font_size = 11;
void BLF_default_dpi(int dpi)
{
global_font_dpi = dpi;
}
void BLF_default_size(int size)
{
global_font_size = size;
}
void BLF_default_set(int fontid)
{
if ((fontid == -1) || blf_font_id_is_valid(fontid)) {
@ -62,8 +67,7 @@ int BLF_set_default(void)
{
ASSERT_DEFAULT_SET;
const uiStyle *style = UI_style_get();
BLF_size(global_font_default, style->widgetlabel.points, global_font_dpi);
BLF_size(global_font_default, global_font_size, global_font_dpi);
return global_font_default;
}
@ -71,9 +75,7 @@ int BLF_set_default(void)
void BLF_draw_default(float x, float y, float z, const char *str, const size_t str_len)
{
ASSERT_DEFAULT_SET;
const uiStyle *style = UI_style_get();
BLF_size(global_font_default, style->widgetlabel.points, global_font_dpi);
BLF_size(global_font_default, global_font_size, global_font_dpi);
BLF_position(global_font_default, x, y, z);
BLF_draw(global_font_default, str, str_len);
}

View File

@ -50,8 +50,6 @@
#include "BLF_api.h"
#include "UI_interface.h"
#include "GPU_batch.h"
#include "GPU_matrix.h"
@ -72,6 +70,9 @@ static FT_Library ft_lib;
static SpinLock ft_lib_mutex;
static SpinLock blf_glyph_cache_mutex;
/* May be set to #UI_widgetbase_draw_cache_flush. */
static void (*blf_draw_cache_flush)(void) = NULL;
/* -------------------------------------------------------------------- */
/** \name FreeType Utilities (Internal)
* \{ */
@ -255,10 +256,10 @@ void blf_batch_draw(void)
GPU_blend(GPU_BLEND_ALPHA);
#ifndef BLF_STANDALONE
/* We need to flush widget base first to ensure correct ordering. */
UI_widgetbase_draw_cache_flush();
#endif
if (blf_draw_cache_flush != NULL) {
blf_draw_cache_flush();
}
GPUTexture *texture = blf_batch_cache_texture_load();
GPU_vertbuf_data_len_set(g_batch.verts, g_batch.glyph_len);
@ -1167,6 +1168,14 @@ void blf_font_exit(void)
blf_batch_draw_exit();
}
/**
* Optional cache flushing function, called before #blf_batch_draw.
*/
void BLF_cache_flush_set_fn(void (*cache_flush_fn)(void))
{
blf_draw_cache_flush = cache_flush_fn;
}
/** \} */
/* -------------------------------------------------------------------- */

View File

@ -419,7 +419,7 @@ int UI_fontstyle_height_max(const uiFontStyle *fs)
/* reading without uifont will create one */
void uiStyleInit(void)
{
uiStyle *style = U.uistyles.first;
const uiStyle *style = U.uistyles.first;
/* recover from uninitialized dpi */
if (U.dpi == 0) {
@ -490,9 +490,13 @@ void uiStyleInit(void)
}
if (style == NULL) {
ui_style_new(&U.uistyles, "Default Style", UIFONT_DEFAULT);
style = ui_style_new(&U.uistyles, "Default Style", UIFONT_DEFAULT);
}
BLF_cache_flush_set_fn(UI_widgetbase_draw_cache_flush);
BLF_default_size(style->widgetlabel.points);
/* XXX, this should be moved into a style,
* but for now best only load the monospaced font once. */
BLI_assert(blf_mono_font == -1);

View File

@ -265,6 +265,14 @@ static void rna_userdef_theme_update(Main *bmain, Scene *scene, PointerRNA *ptr)
rna_userdef_update(bmain, scene, ptr);
}
static void rna_userdef_theme_text_style_update(Main *bmain, Scene *scene, PointerRNA *ptr)
{
const uiStyle *style = UI_style_get();
BLF_default_size(style->widgetlabel.points);
rna_userdef_update(bmain, scene, ptr);
}
static void rna_userdef_gizmo_update(Main *bmain, Scene *scene, PointerRNA *ptr)
{
WM_reinit_gizmomap_all(bmain);
@ -1131,36 +1139,36 @@ static void rna_def_userdef_theme_ui_font_style(BlenderRNA *brna)
prop = RNA_def_property(srna, "points", PROP_INT, PROP_NONE);
RNA_def_property_range(prop, 6, 24);
RNA_def_property_ui_text(prop, "Points", "Font size in points");
RNA_def_property_update(prop, 0, "rna_userdef_theme_update");
RNA_def_property_update(prop, 0, "rna_userdef_theme_text_style_update");
prop = RNA_def_property(srna, "shadow", PROP_INT, PROP_PIXEL);
RNA_def_property_range(prop, 0, 5);
RNA_def_property_ui_text(prop, "Shadow Size", "Shadow size (0, 3 and 5 supported)");
RNA_def_property_update(prop, 0, "rna_userdef_theme_update");
RNA_def_property_update(prop, 0, "rna_userdef_theme_text_style_update");
prop = RNA_def_property(srna, "shadow_offset_x", PROP_INT, PROP_PIXEL);
RNA_def_property_int_sdna(prop, NULL, "shadx");
RNA_def_property_range(prop, -10, 10);
RNA_def_property_ui_text(prop, "Shadow X Offset", "Shadow offset in pixels");
RNA_def_property_update(prop, 0, "rna_userdef_theme_update");
RNA_def_property_update(prop, 0, "rna_userdef_theme_text_style_update");
prop = RNA_def_property(srna, "shadow_offset_y", PROP_INT, PROP_PIXEL);
RNA_def_property_int_sdna(prop, NULL, "shady");
RNA_def_property_range(prop, -10, 10);
RNA_def_property_ui_text(prop, "Shadow Y Offset", "Shadow offset in pixels");
RNA_def_property_update(prop, 0, "rna_userdef_theme_update");
RNA_def_property_update(prop, 0, "rna_userdef_theme_text_style_update");
prop = RNA_def_property(srna, "shadow_alpha", PROP_FLOAT, PROP_FACTOR);
RNA_def_property_float_sdna(prop, NULL, "shadowalpha");
RNA_def_property_range(prop, 0.0f, 1.0f);
RNA_def_property_ui_text(prop, "Shadow Alpha", "");
RNA_def_property_update(prop, 0, "rna_userdef_theme_update");
RNA_def_property_update(prop, 0, "rna_userdef_theme_text_style_update");
prop = RNA_def_property(srna, "shadow_value", PROP_FLOAT, PROP_FACTOR);
RNA_def_property_float_sdna(prop, NULL, "shadowcolor");
RNA_def_property_range(prop, 0.0f, 1.0f);
RNA_def_property_ui_text(prop, "Shadow Brightness", "Shadow color in gray value");
RNA_def_property_update(prop, 0, "rna_userdef_theme_update");
RNA_def_property_update(prop, 0, "rna_userdef_theme_text_style_update");
}
static void rna_def_userdef_theme_ui_style(BlenderRNA *brna)