2013-10-18 20:38:07 +00:00
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
2015-10-03 06:18:47 +00:00
|
|
|
local InfoMessage = require("ui/widget/infomessage")
|
2013-10-18 20:38:07 +00:00
|
|
|
local GestureRange = require("ui/gesturerange")
|
2015-10-03 06:18:47 +00:00
|
|
|
local DataStorage = require("datastorage")
|
2013-10-18 20:38:07 +00:00
|
|
|
local UIManager = require("ui/uimanager")
|
2015-10-03 06:18:47 +00:00
|
|
|
local Screen = require("device").screen
|
2014-11-28 13:10:37 +00:00
|
|
|
local T = require("ffi/util").template
|
|
|
|
local _ = require("gettext")
|
2013-03-06 14:36:51 +00:00
|
|
|
|
2015-10-03 06:18:47 +00:00
|
|
|
|
2016-01-03 08:47:01 +00:00
|
|
|
local Screenshoter = InputContainer:new{
|
|
|
|
prefix = 'Screenshot',
|
2014-11-05 08:58:09 +00:00
|
|
|
}
|
2013-03-06 14:36:51 +00:00
|
|
|
|
2016-01-03 08:47:01 +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 = {
|
2014-06-17 13:12:42 +00:00
|
|
|
TapDiagonal = {
|
2014-03-13 13:52:43 +00:00
|
|
|
GestureRange:new{
|
|
|
|
ges = "two_finger_tap",
|
2014-11-20 22:07:39 +00:00
|
|
|
scale = {diagonal - Screen:scaleBySize(200), diagonal},
|
2014-03-13 13:52:43 +00:00
|
|
|
rate = 1.0,
|
|
|
|
}
|
|
|
|
},
|
2014-06-17 13:12:42 +00:00
|
|
|
SwipeDiagonal = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "swipe",
|
2014-11-20 22:07:39 +00:00
|
|
|
scale = {diagonal - Screen:scaleBySize(200), diagonal},
|
2014-06-17 13:12:42 +00:00
|
|
|
rate = 1.0,
|
|
|
|
}
|
|
|
|
},
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
2013-03-06 14:36:51 +00:00
|
|
|
end
|
|
|
|
|
2016-01-03 08:47:01 +00:00
|
|
|
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{
|
2014-11-28 13:10:37 +00:00
|
|
|
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)
|
2014-11-30 00:12:00 +00:00
|
|
|
-- trigger full refresh
|
|
|
|
UIManager:setDirty(nil, "full")
|
2014-03-13 13:52:43 +00:00
|
|
|
return true
|
2013-03-06 14:36:51 +00:00
|
|
|
end
|
|
|
|
|
2016-01-03 08:47:01 +00:00
|
|
|
function Screenshoter:onTapDiagonal()
|
2014-06-17 13:12:42 +00:00
|
|
|
return self:onScreenshot()
|
|
|
|
end
|
|
|
|
|
2016-01-03 08:47:01 +00:00
|
|
|
function Screenshoter:onSwipeDiagonal()
|
2014-06-17 13:12:42 +00:00
|
|
|
return self:onScreenshot()
|
|
|
|
end
|
|
|
|
|
2016-01-03 08:47:01 +00:00
|
|
|
return Screenshoter
|