2013-10-22 15:11:31 +00:00
|
|
|
local TimeVal = require("ui/timeval")
|
2013-10-18 20:38:07 +00:00
|
|
|
|
|
|
|
local GestureRange = {
|
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,
|
|
|
|
-- span limits of this gesture
|
|
|
|
scale = nil,
|
2013-10-18 20:38:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function GestureRange:new(o)
|
2014-03-13 13:52:43 +00:00
|
|
|
local o = o or {}
|
|
|
|
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
|
|
|
|
if not self.range:contains(gs.pos) then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if self.rate then
|
|
|
|
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
|
|
|
|
if self.scale[1] > gs.span or self.scale[2] < gs.span then
|
|
|
|
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
|