2013-10-22 15:11:31 +00:00
|
|
|
local TimeVal = require("ui/timeval")
|
2013-10-18 20:38:07 +00:00
|
|
|
|
|
|
|
local GestureRange = {
|
2014-07-24 14:08:26 +00:00
|
|
|
-- gesture matching type
|
2014-03-13 13:52:43 +00:00
|
|
|
ges = nil,
|
|
|
|
-- spatial range limits the gesture emitting position
|
|
|
|
range = nil,
|
|
|
|
-- temproal range limits the gesture emitting rate
|
|
|
|
rate = nil,
|
2014-07-24 14:08:26 +00:00
|
|
|
-- scale limits of this gesture
|
2014-03-13 13:52:43 +00:00
|
|
|
scale = nil,
|
2013-10-18 20:38:07 +00:00
|
|
|
}
|
|
|
|
|
2016-02-14 21:47:36 +00:00
|
|
|
function GestureRange:new(from_o)
|
|
|
|
local o = from_o or {}
|
2014-03-13 13:52:43 +00:00
|
|
|
setmetatable(o, self)
|
|
|
|
self.__index = self
|
|
|
|
return o
|
2013-10-18 20:38:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function GestureRange:match(gs)
|
2014-03-13 13:52:43 +00:00
|
|
|
if gs.ges ~= self.ges then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
if self.range then
|
2014-07-24 14:08:26 +00:00
|
|
|
-- sometimes widget dimenension is not available when creating a gesturerage
|
|
|
|
-- for some action, now we accept a range function that will be later called
|
|
|
|
-- and the result of which will be used to check gesture match
|
|
|
|
-- e.g. range = function() return self.dimen end
|
|
|
|
-- for inputcontainer given that the x and y field of `self.dimen` is only
|
|
|
|
-- filled when the inputcontainer is painted into blitbuffer
|
2016-02-14 21:47:36 +00:00
|
|
|
local range
|
2014-07-24 14:08:26 +00:00
|
|
|
if type(self.range) == "function" then
|
|
|
|
range = self.range()
|
|
|
|
else
|
|
|
|
range = self.range
|
|
|
|
end
|
|
|
|
if not range:contains(gs.pos) then
|
2014-03-13 13:52:43 +00:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
2016-03-06 23:56:16 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.rate then
|
2014-07-24 14:08:26 +00:00
|
|
|
-- This filed restraints the upper limit rate(matches per second).
|
|
|
|
-- It's most useful for e-ink devices with less powerfull CPUs and
|
|
|
|
-- screens that cannot handle gesture events that otherwise will be
|
|
|
|
-- generated
|
2014-03-13 13:52:43 +00:00
|
|
|
local last_time = self.last_time or TimeVal:new{}
|
|
|
|
if gs.time - last_time > TimeVal:new{usec = 1000000 / self.rate} then
|
|
|
|
self.last_time = gs.time
|
|
|
|
else
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if self.scale then
|
2014-06-17 13:11:48 +00:00
|
|
|
local scale = gs.distance or gs.span
|
|
|
|
if self.scale[1] > scale or self.scale[2] < scale then
|
2014-03-13 13:52:43 +00:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if self.direction then
|
|
|
|
if self.direction ~= gs.direction then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return true
|
2013-10-18 20:38:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return GestureRange
|