mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Merge pull request #931 from hwhw/master
alpha-blitting widget and a few fixes
This commit is contained in:
@@ -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
|
||||
|
||||
54
frontend/ui/widget/container/alphacontainer.lua
Normal file
54
frontend/ui/widget/container/alphacontainer.lua
Normal file
@@ -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
|
||||
Submodule koreader-base updated: b7cd355807...26003b13e6
26
wtest.lua
26
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)
|
||||
|
||||
Reference in New Issue
Block a user