|
|
|
@ -25,26 +25,6 @@ function Screensaver:getCoverImage(file)
|
|
|
|
|
local data = DocSettings:open(lastfile)
|
|
|
|
|
local proportional_cover = data:readSetting("proportional_screensaver")
|
|
|
|
|
if image then
|
|
|
|
|
if proportional_cover then
|
|
|
|
|
image_height = image:getHeight()
|
|
|
|
|
image_width = image:getWidth()
|
|
|
|
|
local image_ratio = image_width / image_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 = image_width,
|
|
|
|
|
height = image_height,
|
|
|
|
|
}
|
|
|
|
|
return AlphaContainer:new{
|
|
|
|
|
alpha = 1,
|
|
|
|
|
height = screen_height,
|
|
|
|
@ -56,7 +36,12 @@ function Screensaver:getCoverImage(file)
|
|
|
|
|
padding = 0,
|
|
|
|
|
height = screen_height,
|
|
|
|
|
width = screen_width,
|
|
|
|
|
image_widget
|
|
|
|
|
ImageWidget:new{
|
|
|
|
|
image = image,
|
|
|
|
|
height = screen_height,
|
|
|
|
|
width = screen_width,
|
|
|
|
|
overflow = proportional_cover,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -64,8 +49,23 @@ function Screensaver:getCoverImage(file)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function Screensaver:getRandomImage(dir)
|
|
|
|
|
local ImageWidget = require("ui/widget/imagewidget")
|
|
|
|
|
local function createWidget(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,
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function getRandomImage(dir)
|
|
|
|
|
if string.sub(dir, string.len(dir)) ~= "/" then
|
|
|
|
|
dir = dir .. "/"
|
|
|
|
|
end
|
|
|
|
|
local pics = {}
|
|
|
|
|
local i = 0
|
|
|
|
|
math.randomseed(os.time())
|
|
|
|
@ -80,14 +80,7 @@ function Screensaver:getRandomImage(dir)
|
|
|
|
|
end
|
|
|
|
|
local image = pics[math.random(i)]
|
|
|
|
|
if image then
|
|
|
|
|
image = dir .. image
|
|
|
|
|
if lfs.attributes(image, "mode") == "file" then
|
|
|
|
|
return ImageWidget:new{
|
|
|
|
|
file = image,
|
|
|
|
|
width = Screen:getWidth(),
|
|
|
|
|
height = Screen:getHeight(),
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
return createWidget(dir .. image)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
@ -110,17 +103,9 @@ function Screensaver:show()
|
|
|
|
|
if type(KOBO_SCREEN_SAVER) == "string" then
|
|
|
|
|
local file = KOBO_SCREEN_SAVER
|
|
|
|
|
if lfs.attributes(file, "mode") == "directory" then
|
|
|
|
|
if string.sub(file,string.len(file)) ~= "/" then
|
|
|
|
|
file = file .. "/"
|
|
|
|
|
end
|
|
|
|
|
self.suspend_msg = self:getRandomImage(file)
|
|
|
|
|
elseif lfs.attributes(file, "mode") == "file" then
|
|
|
|
|
local ImageWidget = require("ui/widget/imagewidget")
|
|
|
|
|
self.suspend_msg = ImageWidget:new{
|
|
|
|
|
file = file,
|
|
|
|
|
width = Screen:getWidth(),
|
|
|
|
|
height = Screen:getHeight(),
|
|
|
|
|
}
|
|
|
|
|
self.suspend_msg = getRandomImage(file)
|
|
|
|
|
else
|
|
|
|
|
self.suspend_msg = createWidget(file)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|