From adbcdddb5625d7cd49b80d5c560eb8998446183a Mon Sep 17 00:00:00 2001 From: Hans-Werner Hilse Date: Sun, 28 Sep 2014 21:02:55 +0200 Subject: [PATCH 1/4] undo wrong use of addblitFrom() rendertext.lua did use addblitFrom() for rendering text - i.e. blitting the letters to a BlitBuffer. However, it used intensity=1.0, which is the same as doing a (faster, more efficient) blitFrom(). So use that instead. What was probably intented here is a different kind of blitting - using the bitbuffer of the glyph as a mask. --- frontend/ui/rendertext.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/ui/rendertext.lua b/frontend/ui/rendertext.lua index 03a7e9464..f0eeeb6e6 100644 --- a/frontend/ui/rendertext.lua +++ b/frontend/ui/rendertext.lua @@ -163,11 +163,11 @@ function RenderText:renderUtf8Text(buffer, x, y, face, text, kerning, bold, bgco if kerning and (prevcharcode ~= 0) then pen_x = pen_x + face.ftface:getKerning(prevcharcode, charcode) end - buffer:addblitFrom( + buffer:blitFrom( glyph.bb, x + pen_x + glyph.l, y - glyph.t, 0, 0, - glyph.bb:getWidth(), glyph.bb:getHeight(), 1) + glyph.bb:getWidth(), glyph.bb:getHeight()) pen_x = pen_x + glyph.ax prevcharcode = charcode end -- if pen_x < text_width From e47b43e8b5f0ef25e07fcbcf54c3d87569d997c1 Mon Sep 17 00:00:00 2001 From: Hans-Werner Hilse Date: Sun, 28 Sep 2014 21:48:06 +0200 Subject: [PATCH 2/4] add implementation of a container widget with alpha-blitting This is a container that will honor a given alpha value (0..1) when painting, so it will be translucent for values < 1. --- .../ui/widget/container/alphacontainer.lua | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 frontend/ui/widget/container/alphacontainer.lua diff --git a/frontend/ui/widget/container/alphacontainer.lua b/frontend/ui/widget/container/alphacontainer.lua new file mode 100644 index 000000000..71359624c --- /dev/null +++ b/frontend/ui/widget/container/alphacontainer.lua @@ -0,0 +1,54 @@ +local WidgetContainer = require("ui/widget/container/widgetcontainer") +local BlitBuffer = require("ffi/blitbuffer") + +--[[ +AlphaContainer will paint its content (1 widget) onto lower levels using +a transparency (0..1) +--]] +local AlphaContainer = WidgetContainer:new{ + alpha = 1, + -- we cache a blitbuffer object for re-use here: + private_bb = nil, + -- we save the underlying area here: + background_bb = nil, + background_bb_x = nil, + background_bb_y = nil +} + +function AlphaContainer:paintTo(bb, x, y) + local contentSize = self[1]:getSize() + local private_bb = self.private_bb + + if self.background_bb then + -- we have a saved copy of what was below our paint area + -- we restore this first + bb:blitFrom(self.background_bb, self.background_bb_x, self.background_bb_y) + end + + if not private_bb + or private_bb:getWidth() ~= contentSize.w + or private_bb:getHeight() ~= contentSize.h + then + -- create private blitbuffer for our child widget to paint to + private_bb = BlitBuffer.new(contentSize.w, contentSize.h, bb:getType()) + self.private_bb = private_bb + + -- save what is below our painting area + if not self.background_bb + or self.background_bb:getWidth() ~= contentSize.w + or self.background_bb:getHeight() ~= contentSize.h + then + self.background_bb = BlitBuffer.new(contentSize.w, contentSize.h, bb:getType()) + end + self.background_bb:blitFrom(bb, 0, 0, x, y) + end + + -- now have our childs paint to the private blitbuffer + -- TODO: should we clean before painting? + self[1]:paintTo(private_bb, 0, 0) + + -- blit the private blitbuffer to our parent blitbuffer + bb:addblitFrom(private_bb, x, y, nil, nil, nil, nil, self.alpha) +end + +return AlphaContainer From feb774afa92bfee05e9b0b0513bd8a414e820aff Mon Sep 17 00:00:00 2001 From: Hans-Werner Hilse Date: Sun, 28 Sep 2014 21:49:12 +0200 Subject: [PATCH 3/4] update koreader-base with bugfix for alpha-blitting --- koreader-base | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/koreader-base b/koreader-base index b7cd35580..26003b13e 160000 --- a/koreader-base +++ b/koreader-base @@ -1 +1 @@ -Subproject commit b7cd355807fffdfaf104aece03052e5153af49aa +Subproject commit 26003b13e6c08df8d23b4ea46e68125b763374ed From 18be385321a6ad10a36577799c5c2783247e22aa Mon Sep 17 00:00:00 2001 From: Hans-Werner Hilse Date: Sun, 28 Sep 2014 21:49:38 +0200 Subject: [PATCH 4/4] add showcase of alpha-blitting to wtest.lua --- wtest.lua | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/wtest.lua b/wtest.lua index b76153fce..24ec22c3a 100755 --- a/wtest.lua +++ b/wtest.lua @@ -22,10 +22,12 @@ local Font = require("ui/font") local Geom = require("ui/geometry") local Menu = require("ui/widget/menu") local Widget = require("ui/widget/widget") +local TextWidget = require("ui/widget/textwidget") local InfoMessage = require("ui/widget/infomessage") local InputContainer = require("ui/widget/container/inputcontainer") local CenterContainer = require("ui/widget/container/centercontainer") local FrameContainer = require("ui/widget/container/framecontainer") +local AlphaContainer = require("ui/widget/container/alphacontainer") local ConfirmBox = require("ui/widget/confirmbox") local TouchMenu = require("ui/widget/touchmenu") local InputText = require("ui/widget/inputtext") @@ -163,16 +165,20 @@ end ----------------------------------------------------- -- example widget: a clock ----------------------------------------------------- -Clock = FrameContainer:new{ - background = 0, - bordersize = 1, - margin = 0, - padding = 1 +Clock = AlphaContainer:new{ + alpha = 0.7, + + FrameContainer:new{ + background = 0, + bordersize = 1, + margin = 0, + padding = 1 + } } function Clock:schedFunc() - self[1]:free() - self[1] = self:getTextWidget() + self[1][1]:free() + self[1][1] = self:getTextWidget() UIManager:setDirty(self) -- reschedule -- TODO: wait until next real second shift @@ -180,7 +186,7 @@ function Clock:schedFunc() end function Clock:onShow() - self[1] = self:getTextWidget() + self[1][1] = self:getTextWidget() self:schedFunc() end @@ -341,10 +347,10 @@ inputtext = InputText:new{ ----------------------------------------------------------------------- -- you may want to uncomment following show calls to see the changes ----------------------------------------------------------------------- -UIManager:show(Background:new()) +--UIManager:show(Background:new()) -- UIManager:show(TestGrid) UIManager:show(TestVisible) ---UIManager:show(Clock:new()) +UIManager:show(Clock:new()) --UIManager:show(M) --UIManager:show(Quiz) --UIManager:show(readerwindow)