Merge pull request #1699 from natinusala/master

(Font) Added get_message_width in font_renderer_t
This commit is contained in:
Twinaphex 2015-05-16 17:38:12 +02:00
commit c65484fa83
7 changed files with 29 additions and 5 deletions

View File

@ -118,4 +118,5 @@ font_renderer_t d3d_win32_font = {
NULL, /* get_glyph */
NULL, /* bind_block */
NULL, /* flush */
NULL /* get_message_width */
};

View File

@ -126,8 +126,12 @@ static void gl_raster_font_free_font(void *data)
free(font);
}
static int get_message_width(gl_raster_t *font, const char *msg, float scale)
static int gl_get_message_width(void *data, const char *msg, float scale)
{
gl_raster_t *font = (gl_raster_t*)data;
if (!font)
return 0;
unsigned i;
unsigned msg_len_full = strlen(msg);
unsigned msg_len = min(msg_len_full, MAX_MSG_LEN_CHUNK);
@ -194,10 +198,10 @@ static void gl_raster_font_render_message(
switch (text_align)
{
case TEXT_ALIGN_RIGHT:
x -= get_message_width(font, msg, scale);
x -= gl_get_message_width(font, msg, scale);
break;
case TEXT_ALIGN_CENTER:
x -= get_message_width(font, msg, scale) / 2.0;
x -= gl_get_message_width(font, msg, scale) / 2.0;
break;
}
@ -407,5 +411,6 @@ font_renderer_t gl_raster_font = {
"GL raster",
gl_raster_font_get_glyph,
gl_raster_font_bind_block,
gl_raster_font_flush_block
gl_raster_font_flush_block,
gl_get_message_width
};

View File

@ -104,5 +104,6 @@ font_renderer_t libdbg_font = {
"libdbgfont",
NULL, /* get_glyph */
NULL, /* bind_block */
NULL, /* flush */
NULL, /* flush */,
NULL, /* get_message_width */
};

View File

@ -92,4 +92,5 @@ font_renderer_t d3d_xdk1_font = {
NULL, /* get_glyph */
NULL, /* bind_block */
NULL, /* flush */
NULL /* get_message_width */
};

View File

@ -497,4 +497,5 @@ font_renderer_t d3d_xbox360_font = {
NULL, /* get_glyph */
NULL, /* bind_block */
NULL, /* flush */
NULL /* get_message_width */
};

View File

@ -32,6 +32,17 @@ static const font_renderer_driver_t *font_backends[] = {
NULL
};
int font_renderer_get_message_width(const char *msg, float scale)
{
driver_t *driver = driver_get_ptr();
const struct font_renderer *font_driver = driver ? driver->font_osd_driver : NULL;
if (!font_driver || !font_driver->get_message_width)
return 0;
return font_driver->get_message_width(driver->font_osd_data, msg, scale);
}
bool font_renderer_create_default(
const font_renderer_driver_t **drv, void **handle,
const char *font_path, unsigned font_size)

View File

@ -70,6 +70,8 @@ typedef struct font_renderer
const struct font_glyph *(*get_glyph)(void *data, uint32_t code);
void (*bind_block)(void *data, void *block);
void (*flush)(void *data);
int (*get_message_width)(void *data, const char *msg, float scale);
} font_renderer_t;
extern font_renderer_t gl_raster_font;
@ -101,6 +103,8 @@ extern font_renderer_driver_t bitmap_font_renderer;
/* font_path can be NULL for default font. */
bool font_renderer_create_default(const font_renderer_driver_t **driver,
void **handle, const char *font_path, unsigned font_size);
int font_renderer_get_message_width(const char *msg, float scale);
#ifdef __cplusplus
}