mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
add double tap gesture on page area to confirm cropping
And round bbox coordinates.
This commit is contained in:
@@ -26,6 +26,12 @@ function BBoxWidget:init()
|
||||
range = self.view.dimen,
|
||||
}
|
||||
},
|
||||
ConfirmAdjust = {
|
||||
GestureRange:new{
|
||||
ges = "double_tap",
|
||||
range = self.view.dimen,
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
@@ -38,11 +44,13 @@ function BBoxWidget:paintTo(bb, x, y)
|
||||
-- As getScreenBBox uses view states, screen_bbox initialization is postponed.
|
||||
self.screen_bbox = self.screen_bbox or self:getScreenBBox(self.page_bbox)
|
||||
local bbox = self.screen_bbox
|
||||
-- upper_left
|
||||
-- top edge
|
||||
bb:invertRect(bbox.x0 + self.linesize, bbox.y0, bbox.x1 - bbox.x0, self.linesize)
|
||||
bb:invertRect(bbox.x0, bbox.y0, self.linesize, bbox.y1 - bbox.y0 + self.linesize)
|
||||
-- bottom_right
|
||||
-- bottom edge
|
||||
bb:invertRect(bbox.x0 + self.linesize, bbox.y1, bbox.x1 - bbox.x0 - self.linesize, self.linesize)
|
||||
-- left edge
|
||||
bb:invertRect(bbox.x0, bbox.y0, self.linesize, bbox.y1 - bbox.y0 + self.linesize)
|
||||
-- right edge
|
||||
bb:invertRect(bbox.x1, bbox.y0 + self.linesize, self.linesize, bbox.y1 - bbox.y0)
|
||||
end
|
||||
|
||||
@@ -52,10 +60,10 @@ function BBoxWidget:getScreenBBox(page_bbox)
|
||||
local scale = self.view.state.zoom
|
||||
local screen_offset = self.view.state.offset
|
||||
--DEBUG("screen offset in page_to_screen", screen_offset)
|
||||
bbox.x0 = page_bbox.x0 * scale + screen_offset.x
|
||||
bbox.y0 = page_bbox.y0 * scale + screen_offset.y
|
||||
bbox.x1 = page_bbox.x1 * scale + screen_offset.x
|
||||
bbox.y1 = page_bbox.y1 * scale + screen_offset.y
|
||||
bbox.x0 = math.round(page_bbox.x0 * scale + screen_offset.x)
|
||||
bbox.y0 = math.round(page_bbox.y0 * scale + screen_offset.y)
|
||||
bbox.x1 = math.round(page_bbox.x1 * scale + screen_offset.x)
|
||||
bbox.y1 = math.round(page_bbox.y1 * scale + screen_offset.y)
|
||||
return bbox
|
||||
end
|
||||
|
||||
@@ -65,10 +73,10 @@ function BBoxWidget:getPageBBox(screen_bbox)
|
||||
local scale = self.view.state.zoom
|
||||
local screen_offset = self.view.state.offset
|
||||
--DEBUG("screen offset in screen_to_page", screen_offset)
|
||||
bbox.x0 = (screen_bbox.x0 - screen_offset.x) / scale
|
||||
bbox.y0 = (screen_bbox.y0 - screen_offset.y) / scale
|
||||
bbox.x1 = (screen_bbox.x1 - screen_offset.x) / scale
|
||||
bbox.y1 = (screen_bbox.y1 - screen_offset.y) / scale
|
||||
bbox.x0 = math.round((screen_bbox.x0 - screen_offset.x) / scale)
|
||||
bbox.y0 = math.round((screen_bbox.y0 - screen_offset.y) / scale)
|
||||
bbox.x1 = math.round((screen_bbox.x1 - screen_offset.x) / scale)
|
||||
bbox.y1 = math.round((screen_bbox.y1 - screen_offset.y) / scale)
|
||||
return bbox
|
||||
end
|
||||
|
||||
@@ -122,10 +130,10 @@ function BBoxWidget:adjustScreenBBox(ges, rate)
|
||||
upper_left.x = ges.pos.x
|
||||
end
|
||||
self.screen_bbox = {
|
||||
x0 = upper_left.x,
|
||||
y0 = upper_left.y,
|
||||
x1 = bottom_right.x,
|
||||
y1 = bottom_right.y
|
||||
x0 = math.round(upper_left.x),
|
||||
y0 = math.round(upper_left.y),
|
||||
x1 = math.round(bottom_right.x),
|
||||
y1 = math.round(bottom_right.y)
|
||||
}
|
||||
if rate then
|
||||
local last_time = self.last_time or {0, 0}
|
||||
@@ -154,3 +162,10 @@ function BBoxWidget:onPanAdjust(arg, ges)
|
||||
self:adjustScreenBBox(ges, 3.0)
|
||||
return true
|
||||
end
|
||||
|
||||
function BBoxWidget:onConfirmAdjust(arg, ges)
|
||||
if self:inPageArea(ges) then
|
||||
self.ui:handleEvent(Event:new("ConfirmPageCrop"))
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
@@ -69,20 +69,21 @@ function ReaderCropping:onPageCrop(mode)
|
||||
Geom:new{w = Screen:getWidth(), h = Screen:getHeight()*11/12})
|
||||
)
|
||||
self.bbox_widget = BBoxWidget:new{
|
||||
crop = self,
|
||||
ui = self.ui,
|
||||
view = self.view,
|
||||
document = self.document,
|
||||
}
|
||||
self.crop_dialog = PageCropDialog:new{
|
||||
self.bbox_widget,
|
||||
ok_callback = function() self:confirmPageCrop() end,
|
||||
cancel_callback = function() self:cancelPageCrop() end,
|
||||
ok_callback = function() self:onConfirmPageCrop() end,
|
||||
cancel_callback = function() self:onCancelPageCrop() end,
|
||||
}
|
||||
UIManager:show(self.crop_dialog)
|
||||
return true
|
||||
end
|
||||
|
||||
function ReaderCropping:confirmPageCrop()
|
||||
function ReaderCropping:onConfirmPageCrop()
|
||||
--DEBUG("new bbox", new_bbox)
|
||||
UIManager:close(self.crop_dialog)
|
||||
local new_bbox = self.bbox_widget:getModifiedPageBBox()
|
||||
@@ -94,7 +95,7 @@ function ReaderCropping:confirmPageCrop()
|
||||
return true
|
||||
end
|
||||
|
||||
function ReaderCropping:cancelPageCrop()
|
||||
function ReaderCropping:onCancelPageCrop()
|
||||
UIManager:close(self.crop_dialog)
|
||||
self:exitPageCrop(false)
|
||||
return true
|
||||
|
||||
Reference in New Issue
Block a user