add gesture emitting rate in GestureRange

pull/2/merge
chrox 11 years ago
parent 4d4ad5fd4b
commit 94a69b87a7

@ -2,7 +2,10 @@ require "ui/geometry"
GestureRange = { GestureRange = {
ges = nil, ges = nil,
-- spatial range limits the gesture emitting position
range = nil, range = nil,
-- temproal range limits the gesture emitting rate
rate = nil,
} }
function GestureRange:new(o) function GestureRange:new(o)
@ -18,6 +21,15 @@ function GestureRange:match(gs)
end end
if self.range:contains(gs.pos) then if self.range:contains(gs.pos) then
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
return true
else
return false
end
end
return true return true
end end
@ -194,7 +206,8 @@ function GestureDetector:tapState(tev)
x = self.last_tevs[slot].x, x = self.last_tevs[slot].x,
y = self.last_tevs[slot].y, y = self.last_tevs[slot].y,
w = 0, h = 0, w = 0, h = 0,
} },
time = tev.timev,
} }
-- cur_tap is used for double tap detection -- cur_tap is used for double tap detection
local cur_tap = { local cur_tap = {
@ -281,6 +294,7 @@ function GestureDetector:panState(tev)
direction = swipe_direct, direction = swipe_direct,
-- use first pan tev coordination as swipe start point -- use first pan tev coordination as swipe start point
pos = start_pos, pos = start_pos,
time = tev.timev,
--@TODO add start and end points? (houqp) --@TODO add start and end points? (houqp)
} }
end end
@ -298,6 +312,7 @@ function GestureDetector:panState(tev)
y = 0, y = 0,
}, },
pos = nil, pos = nil,
time = tev.timev,
} }
pan_ev.relative.x = tev.x - self.last_tevs[slot].x pan_ev.relative.x = tev.x - self.last_tevs[slot].x
pan_ev.relative.y = tev.y - self.last_tevs[slot].y pan_ev.relative.y = tev.y - self.last_tevs[slot].y
@ -322,7 +337,8 @@ function GestureDetector:holdState(tev, hold)
x = self.last_tevs[slot].x, x = self.last_tevs[slot].x,
y = self.last_tevs[slot].y, y = self.last_tevs[slot].y,
w = 0, h = 0, w = 0, h = 0,
} },
time = tev.timev,
} }
end end
if tev.id == -1 then if tev.id == -1 then
@ -337,7 +353,8 @@ function GestureDetector:holdState(tev, hold)
x = last_x, x = last_x,
y = last_y, y = last_y,
w = 0, h = 0, w = 0, h = 0,
} },
time = tev.timev,
} }
end end
end end

Loading…
Cancel
Save