From 79cb75b1533cc855acfe2e543f9266ff383a3ddf Mon Sep 17 00:00:00 2001 From: Michael Hall Date: Sun, 26 Oct 2014 14:47:48 +0000 Subject: [PATCH] Added option for proportional cover image screensaver --- frontend/apps/reader/modules/readermenu.lua | 10 +++++ frontend/ui/screensaver.lua | 47 +++++++++++++++++++-- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/frontend/apps/reader/modules/readermenu.lua b/frontend/apps/reader/modules/readermenu.lua index 8b171961d..8c79c3c90 100644 --- a/frontend/apps/reader/modules/readermenu.lua +++ b/frontend/apps/reader/modules/readermenu.lua @@ -155,6 +155,16 @@ function ReaderMenu:setUpdateItemTable() self.ui:saveSettings() end }) + local proportional = self.ui.doc_settings:readSetting("proportional_screensaver") or false + table.insert(self.tab_item_table.typeset, { + text = _("Display proportional cover image in screensaver"), + checked_func = function() return (self.ui.doc_settings:readSetting("proportional_screensaver") or false) end, + callback = function() + local proportional = self.ui.doc_settings:readSetting("proportional_screensaver") or false + self.ui.doc_settings:saveSetting("proportional_screensaver", not proportional) + self.ui:saveSettings() + end + }) end end diff --git a/frontend/ui/screensaver.lua b/frontend/ui/screensaver.lua index 6f03e1fff..0b79eda3b 100644 --- a/frontend/ui/screensaver.lua +++ b/frontend/ui/screensaver.lua @@ -10,15 +10,56 @@ 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 ImageWidget:new{ + if proportional_cover then + image_height = image:getHeight() + image_width = image:getWidth() + local image_ratio = image_width / image_height + local screen_ratio = screen_width / screen_height + if image_ratio < 1 then + image_height = screen_height + image_width = image_height * image_ratio + else + image_width = screen_width + image_height = image_width / image_ratio + end + else + image_height = screen_height + image_width = screen_width + end + local image_widget = ImageWidget:new{ image = image, - width = Screen:getWidth(), - height = Screen:getHeight(), + width = image_width, + height = image_height, + } + 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, + image_widget + } + } } end end