diff --git a/frontend/device/kobo/device.lua b/frontend/device/kobo/device.lua index d0604ea63..ad5cb8384 100644 --- a/frontend/device/kobo/device.lua +++ b/frontend/device/kobo/device.lua @@ -79,6 +79,9 @@ local KoboAlyssum = Kobo:new{ } function Kobo:init() + -- Default screensaver folder + KOBO_SCREEN_SAVER = "/mnt/onboard/screensaver" + self.screen = require("ffi/framebuffer_mxcfb"):new{device = self, debug = dbg} self.powerd = require("device/kobo/powerd"):new{device = self} self.input = require("device/input"):new{ diff --git a/frontend/ui/screensaver.lua b/frontend/ui/screensaver.lua index ffb79da28..2f0e856ba 100644 --- a/frontend/ui/screensaver.lua +++ b/frontend/ui/screensaver.lua @@ -8,57 +8,32 @@ local _ = require("gettext") local Screensaver = { } -function Screensaver:getCoverImage(file) - local ImageWidget = require("ui/widget/imagewidget") - local CenterContainer = require("ui/widget/container/centercontainer") - local FrameContainer = require("ui/widget/container/framecontainer") - local AlphaContainer = require("ui/widget/container/alphacontainer") - local image_height - local image_width - local screen_height = Screen:getHeight() - local screen_width = Screen:getWidth() - 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 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, - } - } - } +local function createWidgetFromImage(imageWidget) + if imageWidget then + local AlphaContainer = require("ui/widget/container/alphacontainer") + local CenterContainer = require("ui/widget/container/centercontainer") + return AlphaContainer:new{ + alpha = 1, + height = Screen:getHeight(), + width = Screen:getWidth(), + CenterContainer:new{ + dimen = Screen:getSize(), + imageWidget, } - end + } end end -local function createWidget(file) +local function createWidgetFromFile(file) if lfs.attributes(file, "mode") == "file" then local ImageWidget = require("ui/widget/imagewidget") - return ImageWidget:new{ - file = file, - width = Screen:getWidth(), - height = Screen:getHeight(), - overflow = true, - centering = true, - } + return createWidgetFromImage( + ImageWidget:new{ + file = file, + height = Screen:getHeight(), + width = Screen:getWidth(), + autostretch = true, + }) end end @@ -71,16 +46,37 @@ local function getRandomImage(dir) math.randomseed(os.time()) for entry in lfs.dir(dir) do if lfs.attributes(dir .. entry, "mode") == "file" then - local extension = string.lower(string.match(entry, ".+%.([^.]+)") or "") - if extension == "jpg" or extension == "jpeg" or extension == "png" then + local extension = + string.lower(string.match(entry, ".+%.([^.]+)") or "") + if extension == "jpg" + or extension == "jpeg" + or extension == "png" then i = i + 1 pics[i] = entry end end end - local image = pics[math.random(i)] - if image then - return createWidget(dir .. image) + return createWidgetFromFile(dir .. pics[math.random(i)]) +end + +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 @@ -105,7 +101,7 @@ function Screensaver:show() if lfs.attributes(file, "mode") == "directory" then self.suspend_msg = getRandomImage(file) else - self.suspend_msg = createWidget(file) + self.suspend_msg = createWidgetFromFile(file) end end end diff --git a/frontend/ui/widget/imagewidget.lua b/frontend/ui/widget/imagewidget.lua index e2a4efd7f..d17511d46 100644 --- a/frontend/ui/widget/imagewidget.lua +++ b/frontend/ui/widget/imagewidget.lua @@ -47,13 +47,6 @@ local ImageWidget = Widget:new{ -- size vertically and horizontally, without impact original aspect ratio. -- But overflow part will be ignored. 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 } @@ -100,25 +93,25 @@ function ImageWidget:_render() -- 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))) w, h = scale * native_w, scale * native_h - elseif self.autostretch then - local ratio = native_w / self.width / native_h * self.height - if ratio < 1 then - h = self.height - w = self.width * ratio - else - h = self.height * ratio - w = self.width - end - elseif self.nostretch then - w, h = native_w, native_h - elseif self.overflow then - local ratio = native_w / self.width / native_h * self.height - if ratio < 1 then - h = self.height / ratio - w = self.width - else - h = self.height - w = self.width / ratio + elseif self.width and self.height then + if self.autostretch then + local ratio = native_w / self.width / native_h * self.height + if ratio < 1 then + h = self.height + w = self.width * ratio + else + h = self.height * ratio + w = self.width + end + elseif self.overflow then + local ratio = native_w / self.width / native_h * self.height + if ratio < 1 then + h = self.height / ratio + w = self.width + else + h = self.height + w = self.width / ratio + end end end 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, 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 bb:alphablitFrom(self._bb, x, y, 0, 0, size.w, size.h) else diff --git a/reader.lua b/reader.lua index f3a64144a..2b6267137 100755 --- a/reader.lua +++ b/reader.lua @@ -97,11 +97,6 @@ local UIManager = require("ui/uimanager") local Device = require("device") 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: -- font local fontmap = G_reader_settings:readSetting("fontmap")