forked from bartvdbraak/blender
get the width and height of the font at once when drawing auto-key,
also move BLF'g global font init into its own static function.
This commit is contained in:
parent
0e6e171cdd
commit
4124e2e0c9
@ -109,6 +109,7 @@ float BLF_fixed_width(int fontid);
|
||||
* of the string, using the default font and both value
|
||||
* are multiplied by the aspect of the font.
|
||||
*/
|
||||
void BLF_width_and_height_default(const char *str, float *width, float *height);
|
||||
float BLF_width_default(const char *str);
|
||||
float BLF_height_default(const char *str);
|
||||
|
||||
|
@ -69,7 +69,7 @@ static int global_font_dpi = 72;
|
||||
int blf_mono_font = -1;
|
||||
int blf_mono_font_render = -1;
|
||||
|
||||
static FontBLF *BLF_get(int fontid)
|
||||
static FontBLF *blf_get(int fontid)
|
||||
{
|
||||
if (fontid >= 0 && fontid < BLF_MAX_FONT)
|
||||
return global_font[fontid];
|
||||
@ -141,6 +141,21 @@ static int blf_search_available(void)
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int blf_global_font_init(void)
|
||||
{
|
||||
if (global_font_default == -1) {
|
||||
global_font_default = blf_search("default");
|
||||
}
|
||||
|
||||
if (global_font_default == -1) {
|
||||
printf("Warning: Can't find default font!\n");
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
int BLF_load(const char *name)
|
||||
{
|
||||
FontBLF *font;
|
||||
@ -219,7 +234,7 @@ int BLF_load_unique(const char *name)
|
||||
|
||||
void BLF_metrics_attach(int fontid, unsigned char *mem, int mem_size)
|
||||
{
|
||||
FontBLF *font = BLF_get(fontid);
|
||||
FontBLF *font = blf_get(fontid);
|
||||
|
||||
if (font) {
|
||||
blf_font_attach_from_mem(font, mem, mem_size);
|
||||
@ -311,7 +326,7 @@ void BLF_unload(const char *name)
|
||||
|
||||
void BLF_enable(int fontid, int option)
|
||||
{
|
||||
FontBLF *font = BLF_get(fontid);
|
||||
FontBLF *font = blf_get(fontid);
|
||||
|
||||
if (font) {
|
||||
font->flags |= option;
|
||||
@ -320,7 +335,7 @@ void BLF_enable(int fontid, int option)
|
||||
|
||||
void BLF_disable(int fontid, int option)
|
||||
{
|
||||
FontBLF *font = BLF_get(fontid);
|
||||
FontBLF *font = blf_get(fontid);
|
||||
|
||||
if (font) {
|
||||
font->flags &= ~option;
|
||||
@ -329,7 +344,7 @@ void BLF_disable(int fontid, int option)
|
||||
|
||||
void BLF_enable_default(int option)
|
||||
{
|
||||
FontBLF *font = BLF_get(global_font_default);
|
||||
FontBLF *font = blf_get(global_font_default);
|
||||
|
||||
if (font) {
|
||||
font->flags |= option;
|
||||
@ -338,7 +353,7 @@ void BLF_enable_default(int option)
|
||||
|
||||
void BLF_disable_default(int option)
|
||||
{
|
||||
FontBLF *font = BLF_get(global_font_default);
|
||||
FontBLF *font = blf_get(global_font_default);
|
||||
|
||||
if (font) {
|
||||
font->flags &= ~option;
|
||||
@ -347,7 +362,7 @@ void BLF_disable_default(int option)
|
||||
|
||||
void BLF_aspect(int fontid, float x, float y, float z)
|
||||
{
|
||||
FontBLF *font = BLF_get(fontid);
|
||||
FontBLF *font = blf_get(fontid);
|
||||
|
||||
if (font) {
|
||||
font->aspect[0] = x;
|
||||
@ -358,7 +373,7 @@ void BLF_aspect(int fontid, float x, float y, float z)
|
||||
|
||||
void BLF_matrix(int fontid, const double m[16])
|
||||
{
|
||||
FontBLF *font = BLF_get(fontid);
|
||||
FontBLF *font = blf_get(fontid);
|
||||
|
||||
if (font) {
|
||||
memcpy(font->m, m, sizeof(font->m));
|
||||
@ -367,7 +382,7 @@ void BLF_matrix(int fontid, const double m[16])
|
||||
|
||||
void BLF_position(int fontid, float x, float y, float z)
|
||||
{
|
||||
FontBLF *font = BLF_get(fontid);
|
||||
FontBLF *font = blf_get(fontid);
|
||||
|
||||
if (font) {
|
||||
float xa, ya, za;
|
||||
@ -416,7 +431,7 @@ void BLF_position(int fontid, float x, float y, float z)
|
||||
|
||||
void BLF_size(int fontid, int size, int dpi)
|
||||
{
|
||||
FontBLF *font = BLF_get(fontid);
|
||||
FontBLF *font = blf_get(fontid);
|
||||
|
||||
if (font) {
|
||||
blf_font_size(font, size, dpi);
|
||||
@ -425,7 +440,7 @@ void BLF_size(int fontid, int size, int dpi)
|
||||
|
||||
void BLF_blur(int fontid, int size)
|
||||
{
|
||||
FontBLF *font = BLF_get(fontid);
|
||||
FontBLF *font = blf_get(fontid);
|
||||
|
||||
if (font) {
|
||||
font->blur = size;
|
||||
@ -437,13 +452,8 @@ void BLF_draw_default(float x, float y, float z, const char *str, size_t len)
|
||||
if (!str)
|
||||
return;
|
||||
|
||||
if (global_font_default == -1)
|
||||
global_font_default = blf_search("default");
|
||||
|
||||
if (global_font_default == -1) {
|
||||
printf("Warning: Can't found default font!!\n");
|
||||
if (!blf_global_font_init())
|
||||
return;
|
||||
}
|
||||
|
||||
BLF_size(global_font_default, global_font_points, global_font_dpi);
|
||||
BLF_position(global_font_default, x, y, z);
|
||||
@ -456,13 +466,8 @@ void BLF_draw_default_ascii(float x, float y, float z, const char *str, size_t l
|
||||
if (!str)
|
||||
return;
|
||||
|
||||
if (global_font_default == -1)
|
||||
global_font_default = blf_search("default");
|
||||
|
||||
if (global_font_default == -1) {
|
||||
printf("Warning: Can't found default font!!\n");
|
||||
if (!blf_global_font_init())
|
||||
return;
|
||||
}
|
||||
|
||||
BLF_size(global_font_default, global_font_points, global_font_dpi);
|
||||
BLF_position(global_font_default, x, y, z);
|
||||
@ -471,7 +476,7 @@ void BLF_draw_default_ascii(float x, float y, float z, const char *str, size_t l
|
||||
|
||||
void BLF_rotation_default(float angle)
|
||||
{
|
||||
FontBLF *font = BLF_get(global_font_default);
|
||||
FontBLF *font = blf_get(global_font_default);
|
||||
|
||||
if (font) {
|
||||
font->angle = angle;
|
||||
@ -543,7 +548,7 @@ static void blf_draw__end(GLint mode, GLint param)
|
||||
|
||||
void BLF_draw(int fontid, const char *str, size_t len)
|
||||
{
|
||||
FontBLF *font = BLF_get(fontid);
|
||||
FontBLF *font = blf_get(fontid);
|
||||
GLint mode, param;
|
||||
|
||||
if (font && font->glyph_cache) {
|
||||
@ -555,7 +560,7 @@ void BLF_draw(int fontid, const char *str, size_t len)
|
||||
|
||||
void BLF_draw_ascii(int fontid, const char *str, size_t len)
|
||||
{
|
||||
FontBLF *font = BLF_get(fontid);
|
||||
FontBLF *font = blf_get(fontid);
|
||||
GLint mode, param;
|
||||
|
||||
if (font && font->glyph_cache) {
|
||||
@ -567,7 +572,7 @@ void BLF_draw_ascii(int fontid, const char *str, size_t len)
|
||||
|
||||
void BLF_boundbox(int fontid, const char *str, rctf *box)
|
||||
{
|
||||
FontBLF *font = BLF_get(fontid);
|
||||
FontBLF *font = blf_get(fontid);
|
||||
|
||||
if (font) {
|
||||
blf_font_boundbox(font, str, box);
|
||||
@ -576,16 +581,29 @@ void BLF_boundbox(int fontid, const char *str, rctf *box)
|
||||
|
||||
void BLF_width_and_height(int fontid, const char *str, float *width, float *height)
|
||||
{
|
||||
FontBLF *font = BLF_get(fontid);
|
||||
FontBLF *font = blf_get(fontid);
|
||||
|
||||
if (font && font->glyph_cache) {
|
||||
blf_font_width_and_height(font, str, width, height);
|
||||
}
|
||||
else {
|
||||
*width = *height = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
void BLF_width_and_height_default(const char *str, float *width, float *height)
|
||||
{
|
||||
if (!blf_global_font_init()) {
|
||||
*width = *height = 0.0f;
|
||||
return;
|
||||
}
|
||||
|
||||
BLF_width_and_height(global_font_default, str, width, height);
|
||||
}
|
||||
|
||||
float BLF_width(int fontid, const char *str)
|
||||
{
|
||||
FontBLF *font = BLF_get(fontid);
|
||||
FontBLF *font = blf_get(fontid);
|
||||
|
||||
if (font && font->glyph_cache) {
|
||||
return blf_font_width(font, str);
|
||||
@ -596,7 +614,7 @@ float BLF_width(int fontid, const char *str)
|
||||
|
||||
float BLF_fixed_width(int fontid)
|
||||
{
|
||||
FontBLF *font = BLF_get(fontid);
|
||||
FontBLF *font = blf_get(fontid);
|
||||
|
||||
if (font && font->glyph_cache) {
|
||||
return blf_font_fixed_width(font);
|
||||
@ -607,13 +625,8 @@ float BLF_fixed_width(int fontid)
|
||||
|
||||
float BLF_width_default(const char *str)
|
||||
{
|
||||
if (global_font_default == -1)
|
||||
global_font_default = blf_search("default");
|
||||
|
||||
if (global_font_default == -1) {
|
||||
printf("Error: Can't found default font!!\n");
|
||||
if (!blf_global_font_init())
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
BLF_size(global_font_default, global_font_points, global_font_dpi);
|
||||
return BLF_width(global_font_default, str);
|
||||
@ -621,7 +634,7 @@ float BLF_width_default(const char *str)
|
||||
|
||||
float BLF_height(int fontid, const char *str)
|
||||
{
|
||||
FontBLF *font = BLF_get(fontid);
|
||||
FontBLF *font = blf_get(fontid);
|
||||
|
||||
if (font && font->glyph_cache) {
|
||||
return blf_font_height(font, str);
|
||||
@ -632,7 +645,7 @@ float BLF_height(int fontid, const char *str)
|
||||
|
||||
float BLF_height_max(int fontid)
|
||||
{
|
||||
FontBLF *font = BLF_get(fontid);
|
||||
FontBLF *font = blf_get(fontid);
|
||||
|
||||
if (font && font->glyph_cache) {
|
||||
return font->glyph_cache->max_glyph_height;
|
||||
@ -643,7 +656,7 @@ float BLF_height_max(int fontid)
|
||||
|
||||
float BLF_width_max(int fontid)
|
||||
{
|
||||
FontBLF *font = BLF_get(fontid);
|
||||
FontBLF *font = blf_get(fontid);
|
||||
|
||||
if (font && font->glyph_cache) {
|
||||
return font->glyph_cache->max_glyph_width;
|
||||
@ -654,7 +667,7 @@ float BLF_width_max(int fontid)
|
||||
|
||||
float BLF_descender(int fontid)
|
||||
{
|
||||
FontBLF *font = BLF_get(fontid);
|
||||
FontBLF *font = blf_get(fontid);
|
||||
|
||||
if (font && font->glyph_cache) {
|
||||
return font->glyph_cache->descender;
|
||||
@ -665,7 +678,7 @@ float BLF_descender(int fontid)
|
||||
|
||||
float BLF_ascender(int fontid)
|
||||
{
|
||||
FontBLF *font = BLF_get(fontid);
|
||||
FontBLF *font = blf_get(fontid);
|
||||
|
||||
if (font && font->glyph_cache) {
|
||||
return font->glyph_cache->ascender;
|
||||
@ -676,13 +689,8 @@ float BLF_ascender(int fontid)
|
||||
|
||||
float BLF_height_default(const char *str)
|
||||
{
|
||||
if (global_font_default == -1)
|
||||
global_font_default = blf_search("default");
|
||||
|
||||
if (global_font_default == -1) {
|
||||
printf("Error: Can't found default font!!\n");
|
||||
if (!blf_global_font_init())
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
BLF_size(global_font_default, global_font_points, global_font_dpi);
|
||||
|
||||
@ -691,7 +699,7 @@ float BLF_height_default(const char *str)
|
||||
|
||||
void BLF_rotation(int fontid, float angle)
|
||||
{
|
||||
FontBLF *font = BLF_get(fontid);
|
||||
FontBLF *font = blf_get(fontid);
|
||||
|
||||
if (font) {
|
||||
font->angle = angle;
|
||||
@ -700,7 +708,7 @@ void BLF_rotation(int fontid, float angle)
|
||||
|
||||
void BLF_clipping(int fontid, float xmin, float ymin, float xmax, float ymax)
|
||||
{
|
||||
FontBLF *font = BLF_get(fontid);
|
||||
FontBLF *font = blf_get(fontid);
|
||||
|
||||
if (font) {
|
||||
font->clip_rec.xmin = xmin;
|
||||
@ -712,7 +720,7 @@ void BLF_clipping(int fontid, float xmin, float ymin, float xmax, float ymax)
|
||||
|
||||
void BLF_clipping_default(float xmin, float ymin, float xmax, float ymax)
|
||||
{
|
||||
FontBLF *font = BLF_get(global_font_default);
|
||||
FontBLF *font = blf_get(global_font_default);
|
||||
|
||||
if (font) {
|
||||
font->clip_rec.xmin = xmin;
|
||||
@ -724,7 +732,7 @@ void BLF_clipping_default(float xmin, float ymin, float xmax, float ymax)
|
||||
|
||||
void BLF_shadow(int fontid, int level, float r, float g, float b, float a)
|
||||
{
|
||||
FontBLF *font = BLF_get(fontid);
|
||||
FontBLF *font = blf_get(fontid);
|
||||
|
||||
if (font) {
|
||||
font->shadow = level;
|
||||
@ -737,7 +745,7 @@ void BLF_shadow(int fontid, int level, float r, float g, float b, float a)
|
||||
|
||||
void BLF_shadow_offset(int fontid, int x, int y)
|
||||
{
|
||||
FontBLF *font = BLF_get(fontid);
|
||||
FontBLF *font = blf_get(fontid);
|
||||
|
||||
if (font) {
|
||||
font->shadow_x = x;
|
||||
@ -747,7 +755,7 @@ void BLF_shadow_offset(int fontid, int x, int y)
|
||||
|
||||
void BLF_buffer(int fontid, float *fbuf, unsigned char *cbuf, int w, int h, int nch, struct ColorManagedDisplay *display)
|
||||
{
|
||||
FontBLF *font = BLF_get(fontid);
|
||||
FontBLF *font = blf_get(fontid);
|
||||
|
||||
if (font) {
|
||||
font->buf_info.fbuf = fbuf;
|
||||
@ -761,7 +769,7 @@ void BLF_buffer(int fontid, float *fbuf, unsigned char *cbuf, int w, int h, int
|
||||
|
||||
void BLF_buffer_col(int fontid, float r, float g, float b, float a)
|
||||
{
|
||||
FontBLF *font = BLF_get(fontid);
|
||||
FontBLF *font = blf_get(fontid);
|
||||
|
||||
if (font) {
|
||||
font->buf_info.col[0] = r;
|
||||
@ -773,7 +781,7 @@ void BLF_buffer_col(int fontid, float r, float g, float b, float a)
|
||||
|
||||
void BLF_draw_buffer(int fontid, const char *str)
|
||||
{
|
||||
FontBLF *font = BLF_get(fontid);
|
||||
FontBLF *font = blf_get(fontid);
|
||||
|
||||
if (font && font->glyph_cache && (font->buf_info.fbuf || font->buf_info.cbuf)) {
|
||||
blf_font_buffer(font, str);
|
||||
|
@ -1561,13 +1561,16 @@ static void drawTransformView(const struct bContext *C, ARegion *UNUSED(ar), voi
|
||||
}
|
||||
|
||||
/* just draw a little warning message in the top-right corner of the viewport to warn that autokeying is enabled */
|
||||
static void drawAutoKeyWarning(TransInfo *t, ARegion *ar)
|
||||
static void drawAutoKeyWarning(TransInfo *UNUSED(t), ARegion *ar)
|
||||
{
|
||||
const char printable[] = "Auto Keying On";
|
||||
float printable_size[2];
|
||||
int xco, yco;
|
||||
|
||||
BLF_width_and_height_default(printable, &printable_size[0], &printable_size[1]);
|
||||
|
||||
xco = ar->winx - BLF_width_default(printable) - 10;
|
||||
yco = ar->winy - BLF_height_default(printable) - 10;
|
||||
xco = ar->winx - (int)printable_size[0] - 10;
|
||||
yco = ar->winy - (int)printable_size[1] - 10;
|
||||
|
||||
/* warning text (to clarify meaning of overlays)
|
||||
* - original color was red to match the icon, but that clashes badly with a less nasty border
|
||||
|
Loading…
Reference in New Issue
Block a user