Converted all ints to floats for x coordinate purposes.
This commit is contained in:
parent
d07d0e6d22
commit
806e4bc970
|
@ -168,11 +168,11 @@ static int f_draw_rect(lua_State *L) {
|
|||
static int f_draw_text(lua_State *L) {
|
||||
RenFont** font = luaL_checkudata(L, 1, API_TYPE_FONT);
|
||||
const char *text = luaL_checkstring(L, 2);
|
||||
int x_subpixel = luaL_checknumber(L, 3);
|
||||
float x = luaL_checknumber(L, 3);
|
||||
int y = luaL_checknumber(L, 4);
|
||||
RenColor color = checkcolor(L, 5, 255);
|
||||
x_subpixel = rencache_draw_text(L, *font, text, x_subpixel, y, color);
|
||||
lua_pushnumber(L, x_subpixel);
|
||||
x = rencache_draw_text(L, *font, text, x, y, color);
|
||||
lua_pushnumber(L, x);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -127,9 +127,10 @@ void rencache_draw_rect(RenRect rect, RenColor color) {
|
|||
}
|
||||
}
|
||||
|
||||
int rencache_draw_text(lua_State *L, RenFont *font, const char *text, int x, int y, RenColor color)
|
||||
float rencache_draw_text(lua_State *L, RenFont *font, const char *text, int x, int y, RenColor color)
|
||||
{
|
||||
RenRect rect = { x, y, ren_font_get_width(font, text), ren_font_get_height(font) };
|
||||
float width = ren_font_get_width(font, text);
|
||||
RenRect rect = { x, y, (int)width, ren_font_get_height(font) };
|
||||
if (rects_overlap(screen_rect, rect)) {
|
||||
int sz = strlen(text) + 1;
|
||||
Command *cmd = push_command(DRAW_TEXT, COMMAND_BARE_SIZE + sz);
|
||||
|
@ -141,7 +142,7 @@ int rencache_draw_text(lua_State *L, RenFont *font, const char *text, int x, int
|
|||
cmd->tab_size = ren_font_get_tab_size(font);
|
||||
}
|
||||
}
|
||||
return x + rect.width;
|
||||
return x + width;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -5,13 +5,13 @@
|
|||
#include <lua.h>
|
||||
#include "renderer.h"
|
||||
|
||||
void rencache_show_debug(bool enable);
|
||||
void rencache_set_clip_rect(RenRect rect);
|
||||
void rencache_draw_rect(RenRect rect, RenColor color);
|
||||
int rencache_draw_text(lua_State *L, RenFont *font,
|
||||
const char *text, int x, int y, RenColor color);
|
||||
void rencache_invalidate(void);
|
||||
void rencache_begin_frame(lua_State *L);
|
||||
void rencache_end_frame(lua_State *L);
|
||||
void rencache_show_debug(bool enable);
|
||||
void rencache_set_clip_rect(RenRect rect);
|
||||
void rencache_draw_rect(RenRect rect, RenColor color);
|
||||
float rencache_draw_text(lua_State *L, RenFont *font,
|
||||
const char *text, float x, int y, RenColor color);
|
||||
void rencache_invalidate(void);
|
||||
void rencache_begin_frame(lua_State *L);
|
||||
void rencache_end_frame(lua_State *L);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -42,8 +42,8 @@ typedef struct {
|
|||
typedef struct RenFont {
|
||||
FT_Face face;
|
||||
GlyphSet* sets[MAX_GLYPHSET];
|
||||
float size;
|
||||
short max_height, space_advance, tab_advance;
|
||||
float size, space_advance, tab_advance;
|
||||
short max_height;
|
||||
bool subpixel;
|
||||
ERenFontHinting hinting;
|
||||
unsigned char style;
|
||||
|
@ -212,7 +212,8 @@ float ren_font_get_width(RenFont *font, const char *text) {
|
|||
while (text < end) {
|
||||
unsigned int codepoint;
|
||||
text = utf8_to_codepoint(text, &codepoint);
|
||||
width += font_get_glyphset(font, codepoint)->metrics[codepoint % 256].xadvance;
|
||||
float advance = font_get_glyphset(font, codepoint)->metrics[codepoint % 256].xadvance;
|
||||
width += advance ? advance : font->space_advance;
|
||||
}
|
||||
const int surface_scale = renwin_surface_scale(&window_renderer);
|
||||
return width / surface_scale;
|
||||
|
@ -225,7 +226,7 @@ int ren_font_get_height(RenFont *font) {
|
|||
return font->size + 3;
|
||||
}
|
||||
|
||||
int ren_draw_text(RenFont *font, const char *text, float x, int y, RenColor color) {
|
||||
float ren_draw_text(RenFont *font, const char *text, float x, int y, RenColor color) {
|
||||
SDL_Surface *surface = renwin_get_surface(&window_renderer);
|
||||
const RenRect clip = window_renderer.clip;
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ int ren_font_get_tab_size(RenFont *font);
|
|||
float ren_font_get_width(RenFont *font, const char *text);
|
||||
int ren_font_get_height(RenFont *font);
|
||||
float ren_font_get_size(RenFont *font);
|
||||
int ren_draw_text(RenFont *font, const char *text, float x, int y, RenColor color);
|
||||
float ren_draw_text(RenFont *font, const char *text, float x, int y, RenColor color);
|
||||
|
||||
void ren_draw_rect(RenRect rect, RenColor color);
|
||||
|
||||
|
|
Loading…
Reference in New Issue