2
0
mirror of https://github.com/koreader/koreader synced 2024-11-16 06:12:56 +00:00
koreader/frontend/ui/widget/screenshoter.lua

61 lines
1.7 KiB
Lua
Raw Normal View History

2013-10-18 20:38:07 +00:00
local InputContainer = require("ui/widget/container/inputcontainer")
local InfoMessage = require("ui/widget/infomessage")
2013-10-18 20:38:07 +00:00
local GestureRange = require("ui/gesturerange")
local DataStorage = require("datastorage")
2013-10-18 20:38:07 +00:00
local UIManager = require("ui/uimanager")
local Screen = require("device").screen
local T = require("ffi/util").template
local _ = require("gettext")
local Screenshoter = InputContainer:new{
prefix = 'Screenshot',
2014-11-05 08:58:09 +00:00
}
function Screenshoter:init()
local screenshots_dir = DataStorage:getDataDir() .. "/screenshots/"
self.screenshot_fn_fmt = screenshots_dir .. self.prefix .. "_%Y-%b-%d_%H%M%S.png"
2014-03-13 13:52:43 +00:00
local diagonal = math.sqrt(
math.pow(Screen:getWidth(), 2) +
math.pow(Screen:getHeight(), 2)
)
self.ges_events = {
TapDiagonal = {
2014-03-13 13:52:43 +00:00
GestureRange:new{
ges = "two_finger_tap",
scale = {diagonal - Screen:scaleBySize(200), diagonal},
2014-03-13 13:52:43 +00:00
rate = 1.0,
}
},
SwipeDiagonal = {
GestureRange:new{
ges = "swipe",
scale = {diagonal - Screen:scaleBySize(200), diagonal},
rate = 1.0,
}
},
2014-03-13 13:52:43 +00:00
}
end
function Screenshoter:onScreenshot(filename)
local screenshot_name = filename or os.date(self.screenshot_fn_fmt)
2014-11-05 08:58:09 +00:00
UIManager:show(InfoMessage:new{
text = T( _("Saving screenshot to %1."), screenshot_name),
2016-01-03 07:44:23 +00:00
timeout = 3,
2014-11-05 08:58:09 +00:00
})
Screen:shot(screenshot_name)
-- trigger full refresh
UIManager:setDirty(nil, "full")
2014-03-13 13:52:43 +00:00
return true
end
function Screenshoter:onTapDiagonal()
return self:onScreenshot()
end
function Screenshoter:onSwipeDiagonal()
return self:onScreenshot()
end
return Screenshoter