Resolve review comments

pull/1969/head
Zijie He 8 years ago
parent 865b2a8f90
commit 7d4bd076f7

@ -79,6 +79,9 @@ local KoboAlyssum = Kobo:new{
} }
function Kobo:init() function Kobo:init()
-- Default screensaver folder
KOBO_SCREEN_SAVER = "/mnt/onboard/screensaver"
self.screen = require("ffi/framebuffer_mxcfb"):new{device = self, debug = dbg} self.screen = require("ffi/framebuffer_mxcfb"):new{device = self, debug = dbg}
self.powerd = require("device/kobo/powerd"):new{device = self} self.powerd = require("device/kobo/powerd"):new{device = self}
self.input = require("device/input"):new{ self.input = require("device/input"):new{

@ -8,57 +8,32 @@ local _ = require("gettext")
local Screensaver = { local Screensaver = {
} }
function Screensaver:getCoverImage(file) local function createWidgetFromImage(imageWidget)
local ImageWidget = require("ui/widget/imagewidget") if imageWidget then
local CenterContainer = require("ui/widget/container/centercontainer") local AlphaContainer = require("ui/widget/container/alphacontainer")
local FrameContainer = require("ui/widget/container/framecontainer") local CenterContainer = require("ui/widget/container/centercontainer")
local AlphaContainer = require("ui/widget/container/alphacontainer") return AlphaContainer:new{
local image_height alpha = 1,
local image_width height = Screen:getHeight(),
local screen_height = Screen:getHeight() width = Screen:getWidth(),
local screen_width = Screen:getWidth() CenterContainer:new{
local doc = DocumentRegistry:openDocument(file) dimen = Screen:getSize(),
if doc then imageWidget,
local image = doc:getCoverPageImage()
doc:close()
local lastfile = G_reader_settings:readSetting("lastfile")
local data = DocSettings:open(lastfile)
local proportional_cover = data:readSetting("proportional_screensaver")
if image then
return AlphaContainer:new{
alpha = 1,
height = screen_height,
width = screen_width,
CenterContainer:new{
dimen = Screen:getSize(),
FrameContainer:new{
bordersize = 0,
padding = 0,
height = screen_height,
width = screen_width,
ImageWidget:new{
image = image,
height = screen_height,
width = screen_width,
overflow = proportional_cover,
}
}
}
} }
end }
end end
end end
local function createWidget(file) local function createWidgetFromFile(file)
if lfs.attributes(file, "mode") == "file" then if lfs.attributes(file, "mode") == "file" then
local ImageWidget = require("ui/widget/imagewidget") local ImageWidget = require("ui/widget/imagewidget")
return ImageWidget:new{ return createWidgetFromImage(
file = file, ImageWidget:new{
width = Screen:getWidth(), file = file,
height = Screen:getHeight(), height = Screen:getHeight(),
overflow = true, width = Screen:getWidth(),
centering = true, autostretch = true,
} })
end end
end end
@ -71,16 +46,37 @@ local function getRandomImage(dir)
math.randomseed(os.time()) math.randomseed(os.time())
for entry in lfs.dir(dir) do for entry in lfs.dir(dir) do
if lfs.attributes(dir .. entry, "mode") == "file" then if lfs.attributes(dir .. entry, "mode") == "file" then
local extension = string.lower(string.match(entry, ".+%.([^.]+)") or "") local extension =
if extension == "jpg" or extension == "jpeg" or extension == "png" then string.lower(string.match(entry, ".+%.([^.]+)") or "")
if extension == "jpg"
or extension == "jpeg"
or extension == "png" then
i = i + 1 i = i + 1
pics[i] = entry pics[i] = entry
end end
end end
end end
local image = pics[math.random(i)] return createWidgetFromFile(dir .. pics[math.random(i)])
if image then end
return createWidget(dir .. image)
function Screensaver:getCoverImage(file)
local ImageWidget = require("ui/widget/imagewidget")
local doc = DocumentRegistry:openDocument(file)
if doc then
local image = doc:getCoverPageImage()
doc:close()
local lastfile = G_reader_settings:readSetting("lastfile")
local data = DocSettings:open(lastfile)
local proportional_cover = data:readSetting("proportional_screensaver")
if image then
return createWidgetFromImage(
ImageWidget:new{
image = image,
height = Screen:getHeight(),
width = Screen:getWidth(),
autostretch = proportional_cover,
})
end
end end
end end
@ -105,7 +101,7 @@ function Screensaver:show()
if lfs.attributes(file, "mode") == "directory" then if lfs.attributes(file, "mode") == "directory" then
self.suspend_msg = getRandomImage(file) self.suspend_msg = getRandomImage(file)
else else
self.suspend_msg = createWidget(file) self.suspend_msg = createWidgetFromFile(file)
end end
end end
end end

@ -47,13 +47,6 @@ local ImageWidget = Widget:new{
-- size vertically and horizontally, without impact original aspect ratio. -- size vertically and horizontally, without impact original aspect ratio.
-- But overflow part will be ignored. -- But overflow part will be ignored.
overflow = false, overflow = false,
-- when nostretch is set to true, image won't be stretched.
nostretch = false,
-- when centering is set to true, image will be placed in the middle of the
-- widget. This setting takes effect only with overflow, autostretch and
-- nostretch. i.e. only when the image size is not consistent with widget
-- size.
centering = false,
_bb = nil _bb = nil
} }
@ -100,25 +93,25 @@ function ImageWidget:_render()
-- rounding off to power of 2 to avoid alias with pow(2, floor(log(x)/log(2)) -- rounding off to power of 2 to avoid alias with pow(2, floor(log(x)/log(2))
local scale = math.pow(2, math.max(0, math.floor(math.log(dpi_scale)/0.69))) local scale = math.pow(2, math.max(0, math.floor(math.log(dpi_scale)/0.69)))
w, h = scale * native_w, scale * native_h w, h = scale * native_w, scale * native_h
elseif self.autostretch then elseif self.width and self.height then
local ratio = native_w / self.width / native_h * self.height if self.autostretch then
if ratio < 1 then local ratio = native_w / self.width / native_h * self.height
h = self.height if ratio < 1 then
w = self.width * ratio h = self.height
else w = self.width * ratio
h = self.height * ratio else
w = self.width h = self.height * ratio
end w = self.width
elseif self.nostretch then end
w, h = native_w, native_h elseif self.overflow then
elseif self.overflow then local ratio = native_w / self.width / native_h * self.height
local ratio = native_w / self.width / native_h * self.height if ratio < 1 then
if ratio < 1 then h = self.height / ratio
h = self.height / ratio w = self.width
w = self.width else
else h = self.height
h = self.height w = self.width / ratio
w = self.width / ratio end
end end
end end
if (w and w ~= native_w) or (h and h ~= native_h) then if (w and w ~= native_w) or (h and h ~= native_h) then
@ -145,10 +138,6 @@ function ImageWidget:paintTo(bb, x, y)
w = size.w, w = size.w,
h = size.h h = size.h
} }
if self.centering then
x = x - (size.w - self.width) / 2
y = y - (size.h - self.height) / 2
end
if self.alpha == true then if self.alpha == true then
bb:alphablitFrom(self._bb, x, y, 0, 0, size.w, size.h) bb:alphablitFrom(self._bb, x, y, 0, 0, size.w, size.h)
else else

@ -97,11 +97,6 @@ local UIManager = require("ui/uimanager")
local Device = require("device") local Device = require("device")
local Font = require("ui/font") local Font = require("ui/font")
-- change some global default values according to the device types
if Device:isKobo() then
KOBO_SCREEN_SAVER = "/mnt/onboard/screensaver"
end
-- read some global reader settings here: -- read some global reader settings here:
-- font -- font
local fontmap = G_reader_settings:readSetting("fontmap") local fontmap = G_reader_settings:readSetting("fontmap")

Loading…
Cancel
Save