Commit 8b3e8abfaa7e1248f00ace9110f20e935b498524
1 parent
dd1bcf84
test
git-svn-id: http://svn.net-core.org/repos/t-engine4@3323 51575b47-30f0-44d4-a5cc-537603b46e54
Showing
4 changed files
with
42 additions
and
13 deletions
... | ... | @@ -32,9 +32,16 @@ function _M:init(actor, x, y, w, h, bgcolor, fontname, fontsize) |
32 | 32 | self.font = core.display.newFont(fontname or "/data/font/VeraMono.ttf", fontsize or 10) |
33 | 33 | self.font_h = self.font:lineSkip() |
34 | 34 | self.clics = {} |
35 | + self.items = {} | |
36 | + self.cache = {} | |
37 | + setmetatable(self.cache, {__mode="v"}) | |
35 | 38 | self:resize(x, y, w, h) |
36 | 39 | end |
37 | 40 | |
41 | +function _M:enableShadow(v) | |
42 | + self.shadow = v | |
43 | +end | |
44 | + | |
38 | 45 | --- Resize the display area |
39 | 46 | function _M:resize(x, y, w, h) |
40 | 47 | self.display_x, self.display_y = math.floor(x), math.floor(y) |
... | ... | @@ -55,6 +62,7 @@ function _M:resize(x, y, w, h) |
55 | 62 | for i = 0, w, fw do for j = 0, h, fh do |
56 | 63 | self.bg_surface:merge(fill, i, j) |
57 | 64 | end end |
65 | + self.bg_texture, self.bg_texture_w, self.bg_texture_h = self.bg_surface:glTexture() | |
58 | 66 | end |
59 | 67 | end |
60 | 68 | |
... | ... | @@ -82,6 +90,7 @@ function _M:display() |
82 | 90 | local x = 0 |
83 | 91 | local y = 0 |
84 | 92 | self.clics = {} |
93 | + self.items = {} | |
85 | 94 | |
86 | 95 | for ii, ts in ipairs(hks) do |
87 | 96 | local s |
... | ... | @@ -114,9 +123,18 @@ function _M:display() |
114 | 123 | end |
115 | 124 | |
116 | 125 | txt = ("%1d/%2d) %-"..(self.max_char_w-4-24).."s Key: %s"):format(a.hotkey_page, i - (a.hotkey_page-1) * 12, txt, ts[4]) |
117 | - local w, h = self.font:size(txt) | |
118 | - if self.cur_sel and self.cur_sel == i then self.surface:erase(0, 50, 120, nil, x, y, w+4, h+4) end | |
119 | - self.surface:drawStringBlended(self.font, txt, x+2, y+2, color[1], color[2], color[3]) | |
126 | + local w, h, gen | |
127 | + if self.cache[txt] then | |
128 | + gen = self.cache[txt] | |
129 | + w, h = gen.fw, gen.fh | |
130 | + else | |
131 | + w, h = self.font:size(txt) | |
132 | + gen = self.font:draw(txt, self.w, color[1], color[2], color[3], true)[1] | |
133 | + gen.fw, gen.fh = w, h | |
134 | + end | |
135 | + gen.x, gen.y = x, y | |
136 | + gen.i = i | |
137 | + self.items[#self.items+1] = gen | |
120 | 138 | self.clics[i] = {x,y,w+4,h+4} |
121 | 139 | |
122 | 140 | if y + self.font_h * 2 > self.h then |
... | ... | @@ -126,14 +144,17 @@ function _M:display() |
126 | 144 | y = y + self.font_h |
127 | 145 | end |
128 | 146 | end |
129 | - | |
130 | - self.surface:updateTexture(self.texture) | |
131 | - return self.surface | |
132 | 147 | end |
133 | 148 | |
134 | 149 | function _M:toScreen() |
135 | 150 | self:display() |
136 | - self.texture:toScreenFull(self.display_x, self.display_y, self.w, self.h, self.texture_w, self.texture_h) | |
151 | + if self.bg_texture then self.bg_texture:toScreenFull(self.display_x, self.display_y, self.w, self.h, self.bg_texture_w, self.bg_texture_h) end | |
152 | + for i = 1, #self.items do | |
153 | + local item = self.items[i] | |
154 | + if self.cur_sel == item.i then core.display.drawQuad(self.display_x + item.x, self.display_y + item.y, item.w, item.h, 0, 50, 120, 180) end | |
155 | + if self.shadow then item._tex:toScreenFull(self.display_x + item.x + 2, self.display_y + item.y + 2, item.w, item.h, item._tex_w, item._tex_h, 0, 0, 0, self.shadow) end | |
156 | + item._tex:toScreenFull(self.display_x + item.x, self.display_y + item.y, item.w, item.h, item._tex_w, item._tex_h) | |
157 | + end | |
137 | 158 | end |
138 | 159 | |
139 | 160 | --- Call when a mouse event arrives in this zone | ... | ... |
... | ... | @@ -103,6 +103,7 @@ function _M:run() |
103 | 103 | self.logdisplay:enableShadow(0.6) |
104 | 104 | profile.chat:resize(0, self.h * 0.8 + 7, self.w * 0.5 - 46, self.h * 0.2 - 7, font, size, {255,255,255}, "/data/gfx/ui/message-log.png") |
105 | 105 | self.hotkeys_display = HotkeysDisplay.new(nil, self.w * 0.5 + 46, self.h * 0.8 + 7, self.w * 0.5 - 46, self.h * 0.2 - 7, "/data/gfx/ui/talents-list.png", font_mono, size_mono) |
106 | + self.hotkeys_display:enableShadow(0.6) | |
106 | 107 | self.npcs_display = ActorsSeenDisplay.new(nil, self.w * 0.5 + 46, self.h * 0.8 + 7, self.w * 0.5 - 46, self.h * 0.2 - 7, "/data/gfx/ui/talents-list.png", font_mono, size_mono) |
107 | 108 | self.tooltip = Tooltip.new(font_mono, size, {255,255,255}, {30,30,30,230}) |
108 | 109 | self.tooltip2 = Tooltip.new(font_mono, size, {255,255,255}, {30,30,30,230}) | ... | ... |
... | ... | @@ -526,12 +526,10 @@ static int sdl_font_draw(lua_State *L) |
526 | 526 | int r = luaL_checknumber(L, 4); |
527 | 527 | int g = luaL_checknumber(L, 5); |
528 | 528 | int b = luaL_checknumber(L, 6); |
529 | + bool no_linefeed = lua_toboolean(L, 7); | |
529 | 530 | int h = TTF_FontLineSkip(*f); |
530 | 531 | SDL_Color color = {r,g,b}; |
531 | 532 | |
532 | - int space_w = 0, space_h = 0; | |
533 | - TTF_SizeUTF8(*f, " ", &space_w, &space_h); | |
534 | - | |
535 | 533 | Uint32 rmask, gmask, bmask, amask; |
536 | 534 | #if SDL_BYTEORDER == SDL_BIG_ENDIAN |
537 | 535 | rmask = 0xff000000; gmask = 0x00ff0000; bmask = 0x0000ff00; amask = 0x000000ff; |
... | ... | @@ -554,7 +552,14 @@ static int sdl_font_draw(lua_State *L) |
554 | 552 | { |
555 | 553 | if ((*next == '\n') || (*next == ' ') || (*next == '\0') || (*next == '#')) |
556 | 554 | { |
557 | - stop = next - 1; | |
555 | + bool inced = FALSE; | |
556 | + if (*next == ' ' && *(next+1)) | |
557 | + { | |
558 | + inced = TRUE; | |
559 | + stop = next; | |
560 | + next++; | |
561 | + } | |
562 | + else stop = next - 1; | |
558 | 563 | |
559 | 564 | // Make a surface for the word |
560 | 565 | char old = *next; |
... | ... | @@ -564,7 +569,7 @@ static int sdl_font_draw(lua_State *L) |
564 | 569 | else txt = TTF_RenderUTF8_Blended(*f, start, color); |
565 | 570 | |
566 | 571 | // If we must do a newline, flush the previous word and the start the new line |
567 | - if (force_nl || (txt && (size + txt->w + space_w > max_width))) | |
572 | + if (!no_linefeed && (force_nl || (txt && (size + txt->w > max_width)))) | |
568 | 573 | { |
569 | 574 | // Push it & reset the surface |
570 | 575 | font_make_texture_line(L, s, nb_lines); |
... | ... | @@ -581,9 +586,10 @@ static int sdl_font_draw(lua_State *L) |
581 | 586 | // printf("Drawing word '%s'\n", start); |
582 | 587 | SDL_SetAlpha(txt, 0, 0); |
583 | 588 | sdlDrawImage(s, txt, size, 0); |
584 | - size += txt->w + space_w; | |
589 | + size += txt->w; | |
585 | 590 | } |
586 | 591 | *next = old; |
592 | + if (inced) next--; | |
587 | 593 | start = next + 1; |
588 | 594 | |
589 | 595 | // Force a linefeed | ... | ... |
-
Please register or login to post a comment