|
|
|
@ -8,6 +8,7 @@ local Event = require("ui/event")
|
|
|
|
|
local Geom = require("ui/geometry")
|
|
|
|
|
local GestureRange = require("ui/gesturerange")
|
|
|
|
|
local Math = require("optmath")
|
|
|
|
|
local Screen = Device.screen
|
|
|
|
|
local Size = require("ui/size")
|
|
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
|
|
|
|
|
@ -48,6 +49,12 @@ function BBoxWidget:init()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
self._confirm_stage = 1 -- 1 for left-top, 2 for right-bottom
|
|
|
|
|
self.key_events.MoveIndicatorUp = { { "Up" }, doc="Move indicator up", event="MoveIndicator", args = { 0, -1 } }
|
|
|
|
|
self.key_events.MoveIndicatorDown = { { "Down" }, doc="Move indicator down", event="MoveIndicator", args = { 0, 1 } }
|
|
|
|
|
self.key_events.MoveIndicatorLeft = { { "Left" }, doc="Move indicator left", event="MoveIndicator", args = { -1, 0 } }
|
|
|
|
|
self.key_events.MoveIndicatorRight = { { "Right" }, doc="Move indicator right", event="MoveIndicator", args = { 1, 0 } }
|
|
|
|
|
end
|
|
|
|
|
if Device:hasKeys() then
|
|
|
|
|
self.key_events.Close = { {Device.input.group.Back}, doc = "close windows" }
|
|
|
|
@ -74,6 +81,35 @@ function BBoxWidget:paintTo(bb, x, y)
|
|
|
|
|
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)
|
|
|
|
|
if self._confirm_stage == 1 then
|
|
|
|
|
-- left top indicator
|
|
|
|
|
self:_drawIndicator(bb, bbox.x0, bbox.y0)
|
|
|
|
|
elseif self._confirm_stage == 2 then
|
|
|
|
|
-- right bottom indicator
|
|
|
|
|
self:_drawIndicator(bb, bbox.x1, bbox.y1)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function BBoxWidget:_drawIndicator(bb, x, y)
|
|
|
|
|
local rect = Geom:new({
|
|
|
|
|
x = x - Size.item.height_default / 2,
|
|
|
|
|
y = y - Size.item.height_default / 2,
|
|
|
|
|
w = Size.item.height_default,
|
|
|
|
|
h = Size.item.height_default,
|
|
|
|
|
})
|
|
|
|
|
-- paint big cross line +
|
|
|
|
|
bb:invertRect(
|
|
|
|
|
rect.x,
|
|
|
|
|
rect.y + rect.h / 2 - Size.border.thick / 2,
|
|
|
|
|
rect.w,
|
|
|
|
|
Size.border.thick
|
|
|
|
|
)
|
|
|
|
|
bb:invertRect(
|
|
|
|
|
rect.x + rect.w / 2 - Size.border.thick / 2,
|
|
|
|
|
rect.y,
|
|
|
|
|
Size.border.thick,
|
|
|
|
|
rect.h
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- transform page bbox to screen bbox
|
|
|
|
@ -194,7 +230,82 @@ function BBoxWidget:adjustScreenBBox(ges, relative)
|
|
|
|
|
y1 = Math.round(bottom_right.y)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UIManager:setDirty("all")
|
|
|
|
|
UIManager:setDirty(self.ui, "ui")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function BBoxWidget:onMoveIndicator(args)
|
|
|
|
|
local dx, dy = unpack(args)
|
|
|
|
|
local bbox = self.screen_bbox
|
|
|
|
|
local move_distance = Size.item.height_default / 4
|
|
|
|
|
local half_indicator_size = move_distance * 2
|
|
|
|
|
-- mark edges dirty to redraw
|
|
|
|
|
-- top edge
|
|
|
|
|
UIManager:setDirty(self.ui, "ui", Geom:new{
|
|
|
|
|
x = bbox.x0 - move_distance,
|
|
|
|
|
y = bbox.y0 - move_distance,
|
|
|
|
|
w = bbox.x1 - bbox.x0 + move_distance,
|
|
|
|
|
h = move_distance * 2
|
|
|
|
|
})
|
|
|
|
|
-- left edge
|
|
|
|
|
UIManager:setDirty(self.ui, "ui", Geom:new{
|
|
|
|
|
x = bbox.x0 - move_distance,
|
|
|
|
|
y = bbox.y0 - move_distance,
|
|
|
|
|
w = move_distance * 2,
|
|
|
|
|
h = bbox.y1 - bbox.y0 + move_distance,
|
|
|
|
|
})
|
|
|
|
|
-- right edge
|
|
|
|
|
UIManager:setDirty(self.ui, "ui", Geom:new{
|
|
|
|
|
x = bbox.x1 - move_distance,
|
|
|
|
|
y = bbox.y0 - move_distance,
|
|
|
|
|
w = move_distance * 2,
|
|
|
|
|
h = bbox.y1 - bbox.y0 + move_distance,
|
|
|
|
|
})
|
|
|
|
|
-- bottom edge
|
|
|
|
|
UIManager:setDirty(self.ui, "ui", Geom:new{
|
|
|
|
|
x = bbox.x0 - move_distance,
|
|
|
|
|
y = bbox.y1 - move_distance,
|
|
|
|
|
w = bbox.x1 - bbox.x0 + move_distance,
|
|
|
|
|
h = move_distance * 2,
|
|
|
|
|
})
|
|
|
|
|
-- left top indicator
|
|
|
|
|
UIManager:setDirty(self.ui, "ui", Geom:new{
|
|
|
|
|
x = bbox.x0 - half_indicator_size - move_distance,
|
|
|
|
|
y = bbox.y0 - half_indicator_size - move_distance,
|
|
|
|
|
w = half_indicator_size * 2 + move_distance,
|
|
|
|
|
h = half_indicator_size * 2 + move_distance
|
|
|
|
|
})
|
|
|
|
|
-- bottom right indicator
|
|
|
|
|
UIManager:setDirty(self.ui, "ui", Geom:new{
|
|
|
|
|
x = bbox.x1 - half_indicator_size,
|
|
|
|
|
y = bbox.y1 - half_indicator_size,
|
|
|
|
|
w = half_indicator_size * 2 + move_distance,
|
|
|
|
|
h = half_indicator_size * 2 + move_distance
|
|
|
|
|
})
|
|
|
|
|
if self._confirm_stage == 1 then
|
|
|
|
|
local x = self.screen_bbox.x0 + dx * Size.item.height_default / 4
|
|
|
|
|
local y = self.screen_bbox.y0 + dy * Size.item.height_default / 4
|
|
|
|
|
local max_x = self.screen_bbox.x1 - Size.item.height_default
|
|
|
|
|
local max_y = self.screen_bbox.y1 - Size.item.height_default
|
|
|
|
|
x = (x > 0 and x) or 0
|
|
|
|
|
x = (x < max_x and x) or max_x
|
|
|
|
|
y = (y > 0 and y) or 0
|
|
|
|
|
y = (y < max_y and y) or max_y
|
|
|
|
|
self.screen_bbox.x0 = Math.round(x)
|
|
|
|
|
self.screen_bbox.y0 = Math.round(y)
|
|
|
|
|
return true
|
|
|
|
|
elseif self._confirm_stage == 2 then
|
|
|
|
|
local x = self.screen_bbox.x1 + dx * Size.item.height_default / 4
|
|
|
|
|
local y = self.screen_bbox.y1 + dy * Size.item.height_default / 4
|
|
|
|
|
local min_x = self.screen_bbox.x0 + Size.item.height_default
|
|
|
|
|
local min_y = self.screen_bbox.y0 + Size.item.height_default
|
|
|
|
|
x = (x > min_x and x) or min_x
|
|
|
|
|
x = (x < Screen:getWidth() and x) or Screen:getWidth()
|
|
|
|
|
y = (y > min_y and y) or min_y
|
|
|
|
|
y = (y < Screen:getHeight() and y) or Screen:getHeight()
|
|
|
|
|
self.screen_bbox.x1 = Math.round(x)
|
|
|
|
|
self.screen_bbox.y1 = Math.round(y)
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function BBoxWidget:getModifiedPageBBox()
|
|
|
|
@ -228,10 +339,31 @@ end
|
|
|
|
|
|
|
|
|
|
function BBoxWidget:onClose()
|
|
|
|
|
self.ui:handleEvent(Event:new("CancelPageCrop"))
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function BBoxWidget:onSelect()
|
|
|
|
|
self.ui:handleEvent(Event:new("ConfirmPageCrop"))
|
|
|
|
|
if not self._confirm_stage or self._confirm_stage == 2 then
|
|
|
|
|
self.ui:handleEvent(Event:new("ConfirmPageCrop"))
|
|
|
|
|
else
|
|
|
|
|
local bbox = self.screen_bbox
|
|
|
|
|
self._confirm_stage = self._confirm_stage + 1
|
|
|
|
|
-- left top indicator
|
|
|
|
|
UIManager:setDirty(self.ui, "ui", Geom:new{
|
|
|
|
|
x = bbox.x0 - Size.item.height_default / 2,
|
|
|
|
|
y = bbox.y0 - Size.item.height_default / 2,
|
|
|
|
|
w = Size.item.height_default,
|
|
|
|
|
h = Size.item.height_default,
|
|
|
|
|
})
|
|
|
|
|
-- right bottom indicator
|
|
|
|
|
UIManager:setDirty(self.ui, "ui", Geom:new{
|
|
|
|
|
x = bbox.x1 - Size.item.height_default / 2,
|
|
|
|
|
y = bbox.y1 - Size.item.height_default / 2,
|
|
|
|
|
w = Size.item.height_default,
|
|
|
|
|
h = Size.item.height_default,
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|