diff --git a/frontend/ui/rendertext.lua b/frontend/ui/rendertext.lua index f0eeeb6e6..e059b0e95 100644 --- a/frontend/ui/rendertext.lua +++ b/frontend/ui/rendertext.lua @@ -2,6 +2,7 @@ local Font = require("ui/font") local Screen = require("ui/screen") local Cache = require("cache") local CacheItem = require("cacheitem") +local BlitBuffer = require("ffi/blitbuffer") local DEBUG = require("dbg") --[[ @@ -61,22 +62,20 @@ local function utf8Chars(input) return read_next_glyph, input, 1 end -function RenderText:getGlyph(face, charcode, bold, bgcolor, fgcolor) - if bgcolor == nil then bgcolor = 0.0 end - if fgcolor == nil then fgcolor = 1.0 end - local hash = "glyph|"..face.hash.."|"..charcode.."|"..(bold and 1 or 0).."|"..bgcolor.."|"..fgcolor +function RenderText:getGlyph(face, charcode, bold) + local hash = "glyph|"..face.hash.."|"..charcode.."|"..(bold and 1 or 0) local glyph = GlyphCache:check(hash) if glyph then -- cache hit return glyph[1] end - local rendered_glyph = face.ftface:renderGlyph(charcode, bgcolor, fgcolor, bold) + local rendered_glyph = face.ftface:renderGlyph(charcode, bold) if face.ftface:checkGlyph(charcode) == 0 then for index, font in pairs(Font.fallbacks) do -- use original size before scaling by screen DPI local fb_face = Font:getFace(font, face.orig_size) if fb_face.ftface:checkGlyph(charcode) ~= 0 then - rendered_glyph = fb_face.ftface:renderGlyph(charcode, bgcolor, fgcolor, bold) + rendered_glyph = fb_face.ftface:renderGlyph(charcode, bold) --DEBUG("fallback to font", font) break end @@ -143,12 +142,18 @@ function RenderText:sizeUtf8Text(x, width, face, text, kerning, bold) return { x = pen_x, y_top = pen_y_top, y_bottom = pen_y_bottom} end -function RenderText:renderUtf8Text(buffer, x, y, face, text, kerning, bold, bgcolor, fgcolor, width) +function RenderText:renderUtf8Text(buffer, x, y, face, text, kerning, bold, fgcolor, width) if not text then DEBUG("renderUtf8Text called without text"); return 0 end + if not fgcolor then + fgcolor = BlitBuffer.Color8(0xFF) + elseif type(fgcolor) == "number" then + fgcolor = BlitBuffer.Color8(fgcolor*0xFF) + end + -- may still need more adaptive pen placement when kerning, -- see: http://freetype.org/freetype2/docs/glyphs/glyphs-4.html local pen_x = 0 @@ -159,15 +164,16 @@ function RenderText:renderUtf8Text(buffer, x, y, face, text, kerning, bold, bgco end for _, charcode, uchar in utf8Chars(text) do if pen_x < text_width then - local glyph = self:getGlyph(face, charcode, bold, bgcolor, fgcolor) + local glyph = self:getGlyph(face, charcode, bold) if kerning and (prevcharcode ~= 0) then pen_x = pen_x + face.ftface:getKerning(prevcharcode, charcode) end - buffer:blitFrom( + buffer:colorblitFrom( glyph.bb, x + pen_x + glyph.l, y - glyph.t, 0, 0, - glyph.bb:getWidth(), glyph.bb:getHeight()) + glyph.bb:getWidth(), glyph.bb:getHeight(), + fgcolor) pen_x = pen_x + glyph.ax prevcharcode = charcode end -- if pen_x < text_width diff --git a/frontend/ui/widget/button.lua b/frontend/ui/widget/button.lua index dfab32baa..fbc5abc33 100644 --- a/frontend/ui/widget/button.lua +++ b/frontend/ui/widget/button.lua @@ -34,7 +34,6 @@ function Button:init() if self.text then self.label_widget = TextWidget:new{ text = self.text, - bgcolor = 0.0, fgcolor = self.enabled and 1.0 or 0.5, bold = true, face = Font:getFace(self.text_font_face, self.text_font_size) diff --git a/frontend/ui/widget/fixedtextwidget.lua b/frontend/ui/widget/fixedtextwidget.lua index 668dd789e..8febb43b6 100644 --- a/frontend/ui/widget/fixedtextwidget.lua +++ b/frontend/ui/widget/fixedtextwidget.lua @@ -23,7 +23,7 @@ end function FixedTextWidget:paintTo(bb, x, y) RenderText:renderUtf8Text(bb, x, y+self._height, self.face, self.text, true, self.bold, - self.bgcolor, self.fgcolor) + self.fgcolor) end return FixedTextWidget diff --git a/frontend/ui/widget/inputtext.lua b/frontend/ui/widget/inputtext.lua index 88092b310..28d185d4e 100644 --- a/frontend/ui/widget/inputtext.lua +++ b/frontend/ui/widget/inputtext.lua @@ -51,7 +51,7 @@ end function InputText:initTextBox(text) self.text = text self:initCharlist(text) - local bgcolor, fgcolor = 0.0, self.text == "" and 0.5 or 1.0 + local fgcolor = 0.0, self.text == "" and 0.5 or 1.0 local text_widget = nil local show_text = self.text @@ -65,7 +65,6 @@ function InputText:initTextBox(text) text_widget = ScrollTextWidget:new{ text = show_text, face = self.face, - bgcolor = bgcolor, fgcolor = fgcolor, width = self.width, height = self.height, @@ -74,7 +73,6 @@ function InputText:initTextBox(text) text_widget = TextBoxWidget:new{ text = show_text, face = self.face, - bgcolor = bgcolor, fgcolor = fgcolor, width = self.width, height = self.height, diff --git a/frontend/ui/widget/menu.lua b/frontend/ui/widget/menu.lua index 2064eb1ae..724a94b22 100644 --- a/frontend/ui/widget/menu.lua +++ b/frontend/ui/widget/menu.lua @@ -70,7 +70,6 @@ function ItemShortCutIcon:init() TextWidget:new{ text = self.key, face = sc_face, - bgcolor = background/15, }, }, } diff --git a/frontend/ui/widget/scrolltextwidget.lua b/frontend/ui/widget/scrolltextwidget.lua index 43effb72e..2df47bc59 100644 --- a/frontend/ui/widget/scrolltextwidget.lua +++ b/frontend/ui/widget/scrolltextwidget.lua @@ -15,7 +15,6 @@ Text widget with vertical scroll bar local ScrollTextWidget = InputContainer:new{ text = nil, face = nil, - bgcolor = 0.0, -- [0.0, 1.0] fgcolor = 1.0, -- [0.0, 1.0] width = 400, height = 20, @@ -28,7 +27,6 @@ function ScrollTextWidget:init() self.text_widget = TextBoxWidget:new{ text = self.text, face = self.face, - bgcolor = self.bgcolor, fgcolor = self.fgcolor, width = self.width - self.scroll_bar_width - self.text_scroll_span, height = self.height diff --git a/frontend/ui/widget/textboxwidget.lua b/frontend/ui/widget/textboxwidget.lua index 7964af4d0..36dd7e904 100644 --- a/frontend/ui/widget/textboxwidget.lua +++ b/frontend/ui/widget/textboxwidget.lua @@ -13,7 +13,6 @@ local TextBoxWidget = Widget:new{ text = nil, face = nil, bold = nil, - bgcolor = 0.0, -- [0.0, 1.0] fgcolor = 1.0, -- [0.0, 1.0] width = 400, -- in pixels height = nil, @@ -217,7 +216,7 @@ function TextBoxWidget:_render(v_list) for _,w in ipairs(l) do --@TODO Don't use kerning for monospaced fonts. (houqp) -- refert to cb25029dddc42693cc7aaefbe47e9bd3b7e1a750 in master tree - RenderText:renderUtf8Text(self._bb, pen_x, y, self.face, w.word, true, self.bold, self.bgcolor, self.fgcolor) + RenderText:renderUtf8Text(self._bb, pen_x, y, self.face, w.word, true, self.bold, self.fgcolor) pen_x = pen_x + w.width end y = y + line_height_px + font_height diff --git a/frontend/ui/widget/textwidget.lua b/frontend/ui/widget/textwidget.lua index 393b14dc4..7de33edcc 100644 --- a/frontend/ui/widget/textwidget.lua +++ b/frontend/ui/widget/textwidget.lua @@ -10,7 +10,6 @@ local TextWidget = Widget:new{ text = nil, face = nil, bold = nil, - bgcolor = 0.0, -- [0.0, 1.0] fgcolor = 1.0, -- [0.0, 1.0] _bb = nil, _length = 0, @@ -48,7 +47,7 @@ function TextWidget:paintTo(bb, x, y) --bb:blitFrom(self._bb, x, y, 0, 0, self._length, self._bb:getHeight()) --@TODO Don't use kerning for monospaced fonts. (houqp) RenderText:renderUtf8Text(bb, x, y+self._height*0.7, self.face, self.text, true, self.bold, - self.bgcolor, self.fgcolor, self.width) + self.fgcolor, self.width) end function TextWidget:free() diff --git a/frontend/ui/widget/toggleswitch.lua b/frontend/ui/widget/toggleswitch.lua index fef772653..34af362e9 100644 --- a/frontend/ui/widget/toggleswitch.lua +++ b/frontend/ui/widget/toggleswitch.lua @@ -20,13 +20,12 @@ local ToggleLabel = TextWidget:new{ } function ToggleLabel:paintTo(bb, x, y) - RenderText:renderUtf8Text(bb, x, y+self._height*0.75, self.face, self.text, true, self.bold, self.bgcolor, self.fgcolor) + RenderText:renderUtf8Text(bb, x, y+self._height*0.75, self.face, self.text, true, self.bold, self.fgcolor) end local ToggleSwitch = InputContainer:new{ width = Screen:scaleByDPI(216), height = Screen:scaleByDPI(30), - bgcolor = 0, -- unfoused item color fgcolor = 7, -- focused item color } @@ -91,12 +90,10 @@ function ToggleSwitch:update() if pos == i then self.toggle_content[i].color = self.fgcolor self.toggle_content[i].background = self.fgcolor - self.toggle_content[i][1][1].bgcolor = self.fgcolor/15 self.toggle_content[i][1][1].fgcolor = 0.0 else self.toggle_content[i].color = self.bgcolor self.toggle_content[i].background = self.bgcolor - self.toggle_content[i][1][1].bgcolor = 0.0 self.toggle_content[i][1][1].fgcolor = 1.0 end end diff --git a/frontend/ui/widget/touchmenu.lua b/frontend/ui/widget/touchmenu.lua index 7888324a9..1ea8a0b0f 100644 --- a/frontend/ui/widget/touchmenu.lua +++ b/frontend/ui/widget/touchmenu.lua @@ -80,7 +80,6 @@ function TouchMenuItem:init() }, TextWidget:new{ text = self.item.text or self.item.text_func(), - bgcolor = 0.0, fgcolor = item_enabled ~= false and 1.0 or 0.5, face = self.face, },