mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
* ImageViewer: Minor code cleanups * GestureDetector: Fix the `distance` field of `two_finger_pan` & `two_finger_swipe` gestures so that it's no longer the double of the actual distance traveled. Get rid of existing workarounds throughout the codebase that had to deal with this quirk.
This commit is contained in:
@@ -26,7 +26,6 @@ local ReaderFont = InputContainer:new{
|
||||
-- default gamma from crengine's lvfntman.cpp
|
||||
gamma_index = nil,
|
||||
steps = {0,1,1,1,1,1,2,2,2,3,3,3,4,4,5},
|
||||
gestureScale = Screen:getWidth() * FRONTLIGHT_SENSITIVITY_DECREASE,
|
||||
}
|
||||
|
||||
function ReaderFont:init()
|
||||
@@ -369,11 +368,24 @@ function ReaderFont:addToMainMenu(menu_items)
|
||||
end
|
||||
|
||||
function ReaderFont:gesToFontSize(ges)
|
||||
-- Dispatcher feeds us a number, not a gesture
|
||||
if type(ges) ~= "table" then return ges end
|
||||
|
||||
if ges.distance == nil then
|
||||
ges.distance = 1
|
||||
end
|
||||
local step = math.ceil(2 * #self.steps * ges.distance / self.gestureScale)
|
||||
-- Compute the scaling based on the gesture's direction (for pinch/spread)
|
||||
local step
|
||||
if ges.direction and ges.direction == "vertical" then
|
||||
step = math.ceil(2 * #self.steps * ges.distance / Screen:getHeight())
|
||||
elseif ges.direction and ges.direction == "horizontal" then
|
||||
step = math.ceil(2 * #self.steps * ges.distance / Screen:getWidth())
|
||||
elseif ges.direction and ges.direction == "diagonal" then
|
||||
local screen_diagonal = math.sqrt(Screen:getWidth()^2 + Screen:getHeight()^2)
|
||||
step = math.ceil(2 * #self.steps * ges.distance / screen_diagonal)
|
||||
else
|
||||
step = math.ceil(2 * #self.steps * ges.distance / math.min(Screen:getWidth(), Screen:getHeight()))
|
||||
end
|
||||
local delta_int = self.steps[step] or self.steps[#self.steps]
|
||||
return delta_int
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user