Skip to content
Snippets Groups Projects
Commit 9463c8cb authored by dg's avatar dg
Browse files

fix!

git-svn-id: http://svn.net-core.org/repos/t-engine4@3321 51575b47-30f0-44d4-a5cc-537603b46e54
parent cba88f0a
No related branches found
No related tags found
No related merge requests found
......@@ -40,6 +40,7 @@ function _M:init(x, y, w, h, max, fontname, fontsize, color, bgcolor)
self.max_log = max or 4000
self.scroll = 0
self.changed = true
self.cache = {}
self:resize(x, y, w, h)
end
......@@ -80,7 +81,8 @@ function _M:call(str, ...)
local tstr = str:toString()
table.insert(self.log, 1, tstr)
while #self.log > self.max_log do
table.remove(self.log)
local old = table.remove(self.log)
self.cache[old] = nil
end
self.max = #self.log
self.changed = true
......@@ -88,6 +90,7 @@ end
--- Clear the log
function _M:empty()
self.cache = {}
self.log = {}
self.changed = true
end
......@@ -116,8 +119,13 @@ function _M:display()
for z = 1 + self.scroll, #self.log do
local stop = false
local tstr = self.log[z]
-- local gen = tstring.makeLineTextures(tstr, self.w - 4, self.font)
local gen = self.font:draw(tstr, self.w, 255, 255, 255)
local gen
if self.cache[tstr] then
gen = self.cache[tstr]
else
gen = self.font:draw(tstr, self.w, 255, 255, 255)
self.cache[tstr] = gen
end
for i = #gen, 1, -1 do
self.dlist[#self.dlist+1] = gen[i]
h = h + self.fh
......
......@@ -69,7 +69,7 @@ function _M:createItem(item, text)
local old_style = self.font:getStyle()
-- Handle normal text
if type(text) == "string" then
if false and type(text) == "string" then
local list = text:splitLines(self.w, self.font)
local scroll = 1
local max = #list
......@@ -98,7 +98,7 @@ function _M:createItem(item, text)
-- Handle "pre formated" text, as a table
else
-- Draw the list items
local gen = tstring.makeLineTextures(text, self.fw, self.font)
local gen = self.font:draw(text:toString(), self.fw, 255, 255, 255)
local scroll = 1
local max = #gen
......
......@@ -488,7 +488,7 @@ static int sdl_surface_drawstring_newsurface_aa(lua_State *L)
static font_make_texture_line(lua_State *L, SDL_Surface *s, int id)
{
lua_newtable(L);
lua_createtable(L, 0, 5);
lua_pushstring(L, "_tex");
GLuint *t = (GLuint*)lua_newuserdata(L, sizeof(GLuint));
......@@ -520,7 +520,6 @@ static font_make_texture_line(lua_State *L, SDL_Surface *s, int id)
static int sdl_font_draw(lua_State *L)
{
// if (no_text_aa) return sdl_surface_drawstring(L);
TTF_Font **f = (TTF_Font**)auxiliar_checkclass(L, "sdl{font}", 1);
const char *str = luaL_checkstring(L, 2);
int max_width = luaL_checknumber(L, 3);
......@@ -528,6 +527,7 @@ static int sdl_font_draw(lua_State *L)
int g = luaL_checknumber(L, 5);
int b = luaL_checknumber(L, 6);
int h = TTF_FontLineSkip(*f);
SDL_Color color = {r,g,b};
int space_w = 0, space_h = 0;
TTF_SizeUTF8(*f, " ", &space_w, &space_h);
......@@ -538,17 +538,9 @@ static int sdl_font_draw(lua_State *L)
#else
rmask = 0x000000ff; gmask = 0x0000ff00; bmask = 0x00ff0000; amask = 0xff000000;
#endif
SDL_Surface *s = SDL_CreateRGBSurface(
SDL_SWSURFACE | SDL_SRCALPHA,
max_width,
h,
32,
rmask, gmask, bmask, amask
);
SDL_Surface *s = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_SRCALPHA, max_width, h, 32, rmask, gmask, bmask, amask);
SDL_FillRect(s, NULL, SDL_MapRGBA(s->format, 0, 0, 0, 0));
SDL_Color color = {r,g,b};
lua_newtable(L);
int nb_lines = 1;
......@@ -568,7 +560,8 @@ static int sdl_font_draw(lua_State *L)
char old = *next;
*next = '\0';
if (txt) SDL_FreeSurface(txt);
txt = TTF_RenderUTF8_Blended(*f, start, color);
if (no_text_aa) txt = TTF_RenderUTF8_Solid(*f, start, color);
else txt = TTF_RenderUTF8_Blended(*f, start, color);
// If we must do a newline, flush the previous word and the start the new line
if (force_nl || (txt && (size + txt->w + space_w > max_width)))
......@@ -688,7 +681,7 @@ static int sdl_font_draw(lua_State *L)
color.g = gh;
color.b = bh;
}
lua_pop(L, 1);
lua_pop(L, 2);
}
char old = *codestop;
......@@ -705,6 +698,7 @@ static int sdl_font_draw(lua_State *L)
}
font_make_texture_line(L, s, nb_lines);
if (size > max_size) max_size = size;
if (txt) SDL_FreeSurface(txt);
SDL_FreeSurface(s);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment