2019-12-06 21:55:39 +00:00
|
|
|
local BD = require("ui/bidi")
|
2014-10-30 18:42:18 +00:00
|
|
|
local Device = require("device")
|
2013-10-18 20:38:07 +00:00
|
|
|
local Event = require("ui/event")
|
2019-08-30 11:25:51 +00:00
|
|
|
local Geom = require("ui/geometry")
|
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
2013-10-18 20:38:07 +00:00
|
|
|
local Math = require("optmath")
|
2019-10-25 15:25:26 +00:00
|
|
|
local MultiConfirmBox = require("ui/widget/multiconfirmbox")
|
2020-07-12 18:47:49 +00:00
|
|
|
local Notification = require("ui/widget/notification")
|
2019-08-30 11:25:51 +00:00
|
|
|
local UIManager = require("ui/uimanager")
|
2020-07-12 18:47:49 +00:00
|
|
|
local bit = require("bit")
|
2016-12-29 08:10:38 +00:00
|
|
|
local logger = require("logger")
|
2013-12-28 09:33:21 +00:00
|
|
|
local _ = require("gettext")
|
2019-08-30 11:25:51 +00:00
|
|
|
local Screen = Device.screen
|
2013-10-18 20:38:07 +00:00
|
|
|
|
2016-11-24 02:48:00 +00:00
|
|
|
|
|
|
|
local function copyPageState(page_state)
|
|
|
|
return {
|
|
|
|
page = page_state.page,
|
|
|
|
zoom = page_state.zoom,
|
|
|
|
rotation = page_state.rotation,
|
|
|
|
gamma = page_state.gamma,
|
|
|
|
offset = page_state.offset:copy(),
|
|
|
|
visible_area = page_state.visible_area:copy(),
|
|
|
|
page_area = page_state.page_area:copy(),
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
local ReaderPaging = InputContainer:new{
|
2017-03-23 18:40:42 +00:00
|
|
|
pan_rate = 30, -- default 30 ops, will be adjusted in readerui
|
2014-03-13 13:52:43 +00:00
|
|
|
current_page = 0,
|
|
|
|
number_of_pages = 0,
|
|
|
|
last_pan_relative_y = 0,
|
|
|
|
visible_area = nil,
|
|
|
|
page_area = nil,
|
|
|
|
show_overlap_enable = nil,
|
2014-11-20 22:07:39 +00:00
|
|
|
overlap = Screen:scaleBySize(DOVERLAPPIXELS),
|
2014-05-19 06:23:31 +00:00
|
|
|
|
2019-08-30 11:25:51 +00:00
|
|
|
inverse_reading_order = nil,
|
2014-03-13 13:52:43 +00:00
|
|
|
page_flipping_mode = false,
|
|
|
|
bookmark_flipping_mode = false,
|
|
|
|
flip_steps = {0,1,2,5,10,20,50,100}
|
2012-05-18 22:50:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function ReaderPaging:init()
|
A few graphics fixes after #4541 (#4554)
* Various FocusManager related tweaks to limit its usage to devices with a DPad, and prevent initial button highlights in Dialogs on devices where it makes no sense (i.e., those without a DPad. And even on DPad devices, I'm not even sure how we'd go about making one of those pop up anyway, because no Touch ;)!).
* One mysterious fix to text-only Buttons so that the flash_ui highlight always works, and always honors `FrameContainer`'s pill shape. (Before that, an unhighlight on a text button with a callback that didn't repaint anything [say, the find first/find last buttons in the Reader's search bar when you're already on the first/last match] would do a square black highlight, and a white pill-shaped unhighlight (leaving the black corners visible)).
The workaround makes *absolutely* no sense to me (as `self[1] -> self.frame`, AFAICT), but it works, and ensures all highlights/unhighlights are pill-shaped, so at least we're not doing maths for rounded corners for nothing ;).
2019-02-07 23:56:32 +00:00
|
|
|
self.key_events = {}
|
|
|
|
if Device:hasKeys() then
|
|
|
|
self.key_events.GotoNextPage = {
|
2019-07-28 11:57:03 +00:00
|
|
|
{ {"RPgFwd", "LPgFwd", "Right" } }, doc = "go to next page",
|
2019-03-01 15:05:03 +00:00
|
|
|
event = "GotoViewRel", args = 1,
|
A few graphics fixes after #4541 (#4554)
* Various FocusManager related tweaks to limit its usage to devices with a DPad, and prevent initial button highlights in Dialogs on devices where it makes no sense (i.e., those without a DPad. And even on DPad devices, I'm not even sure how we'd go about making one of those pop up anyway, because no Touch ;)!).
* One mysterious fix to text-only Buttons so that the flash_ui highlight always works, and always honors `FrameContainer`'s pill shape. (Before that, an unhighlight on a text button with a callback that didn't repaint anything [say, the find first/find last buttons in the Reader's search bar when you're already on the first/last match] would do a square black highlight, and a white pill-shaped unhighlight (leaving the black corners visible)).
The workaround makes *absolutely* no sense to me (as `self[1] -> self.frame`, AFAICT), but it works, and ensures all highlights/unhighlights are pill-shaped, so at least we're not doing maths for rounded corners for nothing ;).
2019-02-07 23:56:32 +00:00
|
|
|
}
|
|
|
|
self.key_events.GotoPrevPage = {
|
2019-07-28 11:57:03 +00:00
|
|
|
{ { "RPgBack", "LPgBack", "Left" } }, doc = "go to previous page",
|
2019-03-01 15:05:03 +00:00
|
|
|
event = "GotoViewRel", args = -1,
|
A few graphics fixes after #4541 (#4554)
* Various FocusManager related tweaks to limit its usage to devices with a DPad, and prevent initial button highlights in Dialogs on devices where it makes no sense (i.e., those without a DPad. And even on DPad devices, I'm not even sure how we'd go about making one of those pop up anyway, because no Touch ;)!).
* One mysterious fix to text-only Buttons so that the flash_ui highlight always works, and always honors `FrameContainer`'s pill shape. (Before that, an unhighlight on a text button with a callback that didn't repaint anything [say, the find first/find last buttons in the Reader's search bar when you're already on the first/last match] would do a square black highlight, and a white pill-shaped unhighlight (leaving the black corners visible)).
The workaround makes *absolutely* no sense to me (as `self[1] -> self.frame`, AFAICT), but it works, and ensures all highlights/unhighlights are pill-shaped, so at least we're not doing maths for rounded corners for nothing ;).
2019-02-07 23:56:32 +00:00
|
|
|
}
|
2020-06-04 11:26:18 +00:00
|
|
|
if Device:hasFewKeys() then
|
|
|
|
table.remove(self.key_events.GotoNextPage[1][1], 3) -- right
|
|
|
|
table.remove(self.key_events.GotoPrevPage[1][1], 3) -- left
|
|
|
|
end
|
2019-07-28 11:57:03 +00:00
|
|
|
self.key_events.GotoNextPos = {
|
|
|
|
{ {"Down" } }, doc = "go to next position",
|
|
|
|
event = "GotoPosRel", args = 1,
|
|
|
|
}
|
|
|
|
self.key_events.GotoPrevPos = {
|
|
|
|
{ { "Up" } }, doc = "go to previous position",
|
|
|
|
event = "GotoPosRel", args = -1,
|
|
|
|
}
|
|
|
|
|
A few graphics fixes after #4541 (#4554)
* Various FocusManager related tweaks to limit its usage to devices with a DPad, and prevent initial button highlights in Dialogs on devices where it makes no sense (i.e., those without a DPad. And even on DPad devices, I'm not even sure how we'd go about making one of those pop up anyway, because no Touch ;)!).
* One mysterious fix to text-only Buttons so that the flash_ui highlight always works, and always honors `FrameContainer`'s pill shape. (Before that, an unhighlight on a text button with a callback that didn't repaint anything [say, the find first/find last buttons in the Reader's search bar when you're already on the first/last match] would do a square black highlight, and a white pill-shaped unhighlight (leaving the black corners visible)).
The workaround makes *absolutely* no sense to me (as `self[1] -> self.frame`, AFAICT), but it works, and ensures all highlights/unhighlights are pill-shaped, so at least we're not doing maths for rounded corners for nothing ;).
2019-02-07 23:56:32 +00:00
|
|
|
end
|
|
|
|
if Device:hasKeyboard() then
|
|
|
|
self.key_events.GotoFirst = {
|
|
|
|
{"1"}, doc = "go to start", event = "GotoPercent", args = 0,
|
|
|
|
}
|
|
|
|
self.key_events.Goto11 = {
|
|
|
|
{"2"}, doc = "go to 11%", event = "GotoPercent", args = 11,
|
|
|
|
}
|
|
|
|
self.key_events.Goto22 = {
|
|
|
|
{"3"}, doc = "go to 22%", event = "GotoPercent", args = 22,
|
|
|
|
}
|
|
|
|
self.key_events.Goto33 = {
|
|
|
|
{"4"}, doc = "go to 33%", event = "GotoPercent", args = 33,
|
|
|
|
}
|
|
|
|
self.key_events.Goto44 = {
|
|
|
|
{"5"}, doc = "go to 44%", event = "GotoPercent", args = 44,
|
|
|
|
}
|
|
|
|
self.key_events.Goto55 = {
|
|
|
|
{"6"}, doc = "go to 55%", event = "GotoPercent", args = 55,
|
|
|
|
}
|
|
|
|
self.key_events.Goto66 = {
|
|
|
|
{"7"}, doc = "go to 66%", event = "GotoPercent", args = 66,
|
|
|
|
}
|
|
|
|
self.key_events.Goto77 = {
|
|
|
|
{"8"}, doc = "go to 77%", event = "GotoPercent", args = 77,
|
|
|
|
}
|
|
|
|
self.key_events.Goto88 = {
|
|
|
|
{"9"}, doc = "go to 88%", event = "GotoPercent", args = 88,
|
|
|
|
}
|
|
|
|
self.key_events.GotoLast = {
|
|
|
|
{"0"}, doc = "go to end", event = "GotoPercent", args = 100,
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
self.number_of_pages = self.ui.document.info.number_of_pages
|
|
|
|
self.ui.menu:registerToMainMenu(self)
|
2012-05-18 22:50:26 +00:00
|
|
|
end
|
|
|
|
|
2016-12-04 06:57:57 +00:00
|
|
|
function ReaderPaging:onReaderReady()
|
|
|
|
self:setupTouchZones()
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderPaging:setupTapTouchZones()
|
|
|
|
local forward_zone = {
|
|
|
|
ratio_x = DTAP_ZONE_FORWARD.x, ratio_y = DTAP_ZONE_FORWARD.y,
|
|
|
|
ratio_w = DTAP_ZONE_FORWARD.w, ratio_h = DTAP_ZONE_FORWARD.h,
|
|
|
|
}
|
|
|
|
local backward_zone = {
|
|
|
|
ratio_x = DTAP_ZONE_BACKWARD.x, ratio_y = DTAP_ZONE_BACKWARD.y,
|
|
|
|
ratio_w = DTAP_ZONE_BACKWARD.w, ratio_h = DTAP_ZONE_BACKWARD.h,
|
|
|
|
}
|
|
|
|
|
2019-12-06 21:55:39 +00:00
|
|
|
local do_mirror = BD.mirroredUILayout()
|
2016-12-04 06:57:57 +00:00
|
|
|
if self.inverse_reading_order then
|
2019-12-06 21:55:39 +00:00
|
|
|
do_mirror = not do_mirror
|
|
|
|
end
|
|
|
|
if do_mirror then
|
2016-12-04 06:57:57 +00:00
|
|
|
forward_zone.ratio_x = 1 - forward_zone.ratio_x - forward_zone.ratio_w
|
|
|
|
backward_zone.ratio_x = 1 - backward_zone.ratio_x - backward_zone.ratio_w
|
|
|
|
end
|
|
|
|
|
|
|
|
self.ui:registerTouchZones({
|
|
|
|
{
|
|
|
|
id = "tap_forward",
|
|
|
|
ges = "tap",
|
|
|
|
screen_zone = forward_zone,
|
2019-03-01 15:05:03 +00:00
|
|
|
handler = function() return self:onGotoViewRel(1) end,
|
2014-03-13 13:52:43 +00:00
|
|
|
},
|
2016-12-04 06:57:57 +00:00
|
|
|
{
|
|
|
|
id = "tap_backward",
|
|
|
|
ges = "tap",
|
|
|
|
screen_zone = backward_zone,
|
2019-03-01 15:05:03 +00:00
|
|
|
handler = function() return self:onGotoViewRel(-1) end,
|
2014-03-13 13:52:43 +00:00
|
|
|
},
|
2016-12-04 06:57:57 +00:00
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
-- This method will be called in onSetDimensions handler
|
|
|
|
function ReaderPaging:setupTouchZones()
|
|
|
|
-- deligate gesture listener to readerui
|
|
|
|
self.ges_events = {}
|
|
|
|
self.onGesture = nil
|
|
|
|
|
|
|
|
if not Device:isTouchDevice() then return end
|
|
|
|
|
|
|
|
self:setupTapTouchZones()
|
|
|
|
self.ui:registerTouchZones({
|
|
|
|
{
|
|
|
|
id = "paging_swipe",
|
|
|
|
ges = "swipe",
|
|
|
|
screen_zone = {
|
|
|
|
ratio_x = 0, ratio_y = 0, ratio_w = 1, ratio_h = 1,
|
|
|
|
},
|
|
|
|
handler = function(ges) return self:onSwipe(nil, ges) end
|
2014-03-13 13:52:43 +00:00
|
|
|
},
|
2016-12-04 06:57:57 +00:00
|
|
|
{
|
|
|
|
id = "paging_pan",
|
|
|
|
ges = "pan",
|
2017-03-23 18:40:42 +00:00
|
|
|
rate = self.pan_rate,
|
2016-12-04 06:57:57 +00:00
|
|
|
screen_zone = {
|
|
|
|
ratio_x = 0, ratio_y = 0, ratio_w = 1, ratio_h = 1,
|
|
|
|
},
|
|
|
|
handler = function(ges) return self:onPan(nil, ges) end
|
2014-03-13 13:52:43 +00:00
|
|
|
},
|
2016-12-04 06:57:57 +00:00
|
|
|
{
|
|
|
|
id = "paging_pan_release",
|
|
|
|
ges = "pan_release",
|
|
|
|
screen_zone = {
|
|
|
|
ratio_x = 0, ratio_y = 0, ratio_w = 1, ratio_h = 1,
|
|
|
|
},
|
|
|
|
handler = function(ges) return self:onPanRelease(nil, ges) end
|
2014-03-13 13:52:43 +00:00
|
|
|
},
|
2016-12-04 06:57:57 +00:00
|
|
|
})
|
2013-02-02 06:36:29 +00:00
|
|
|
end
|
|
|
|
|
2012-12-04 07:19:50 +00:00
|
|
|
function ReaderPaging:onReadSettings(config)
|
2014-03-13 13:52:43 +00:00
|
|
|
self.page_positions = config:readSetting("page_positions") or {}
|
2016-03-27 22:39:47 +00:00
|
|
|
self:_gotoPage(config:readSetting("last_page") or 1)
|
2014-03-13 13:52:43 +00:00
|
|
|
self.show_overlap_enable = config:readSetting("show_overlap_enable")
|
|
|
|
if self.show_overlap_enable == nil then
|
|
|
|
self.show_overlap_enable = DSHOWOVERLAP
|
|
|
|
end
|
2015-03-12 06:52:55 +00:00
|
|
|
self.flipping_zoom_mode = config:readSetting("flipping_zoom_mode") or "page"
|
2015-03-24 01:34:07 +00:00
|
|
|
self.flipping_scroll_mode = config:readSetting("flipping_scroll_mode") or false
|
2019-08-30 11:25:51 +00:00
|
|
|
self.inverse_reading_order = config:readSetting("inverse_reading_order")
|
2019-09-09 15:34:27 +00:00
|
|
|
if self.inverse_reading_order == nil then
|
2019-08-30 11:25:51 +00:00
|
|
|
self.inverse_reading_order = G_reader_settings:isTrue("inverse_reading_order")
|
|
|
|
end
|
2012-12-04 07:19:50 +00:00
|
|
|
end
|
|
|
|
|
2013-12-27 15:18:16 +00:00
|
|
|
function ReaderPaging:onSaveSettings()
|
2019-08-23 17:53:53 +00:00
|
|
|
--- @todo only save current_page page position
|
2014-03-13 13:52:43 +00:00
|
|
|
self.ui.doc_settings:saveSetting("page_positions", self.page_positions)
|
|
|
|
self.ui.doc_settings:saveSetting("last_page", self:getTopPage())
|
2015-03-09 12:20:32 +00:00
|
|
|
self.ui.doc_settings:saveSetting("percent_finished", self:getLastPercent())
|
2014-03-13 13:52:43 +00:00
|
|
|
self.ui.doc_settings:saveSetting("show_overlap_enable", self.show_overlap_enable)
|
2015-03-12 06:52:55 +00:00
|
|
|
self.ui.doc_settings:saveSetting("flipping_zoom_mode", self.flipping_zoom_mode)
|
2015-03-24 01:34:07 +00:00
|
|
|
self.ui.doc_settings:saveSetting("flipping_scroll_mode", self.flipping_scroll_mode)
|
2016-06-10 12:14:03 +00:00
|
|
|
self.ui.doc_settings:saveSetting("inverse_reading_order", self.inverse_reading_order)
|
2013-12-28 09:33:21 +00:00
|
|
|
end
|
|
|
|
|
2015-03-09 12:20:32 +00:00
|
|
|
function ReaderPaging:getLastProgress()
|
|
|
|
return self:getTopPage()
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderPaging:getLastPercent()
|
|
|
|
if self.current_page > 0 and self.number_of_pages > 0 then
|
|
|
|
return self.current_page/self.number_of_pages
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-04 13:46:38 +00:00
|
|
|
function ReaderPaging:addToMainMenu(menu_items)
|
2019-08-23 17:53:53 +00:00
|
|
|
--- @fixme repeated code with page overlap menu for readerrolling
|
2014-11-17 13:44:13 +00:00
|
|
|
-- needs to keep only one copy of the logic as for the DRY principle.
|
|
|
|
-- The difference between the two menus is only the enabled func.
|
|
|
|
local page_overlap_menu = {
|
|
|
|
{
|
2019-02-03 10:17:27 +00:00
|
|
|
text = _("Page overlap"),
|
|
|
|
checked_func = function()
|
|
|
|
return self.show_overlap_enable
|
2014-11-17 13:44:13 +00:00
|
|
|
end,
|
|
|
|
callback = function()
|
|
|
|
self.show_overlap_enable = not self.show_overlap_enable
|
|
|
|
if not self.show_overlap_enable then
|
|
|
|
self.view:resetDimArea()
|
|
|
|
end
|
2019-02-03 10:17:27 +00:00
|
|
|
end,
|
|
|
|
separator = true,
|
2014-11-17 13:44:13 +00:00
|
|
|
},
|
|
|
|
}
|
2019-02-03 10:17:27 +00:00
|
|
|
local overlap_enabled_func = function() return self.show_overlap_enable end
|
|
|
|
for _, menu_entry in ipairs(self.view:genOverlapStyleMenu(overlap_enabled_func)) do
|
2014-11-17 13:44:13 +00:00
|
|
|
table.insert(page_overlap_menu, menu_entry)
|
|
|
|
end
|
2017-03-04 13:46:38 +00:00
|
|
|
menu_items.page_overlap = {
|
2014-11-17 13:44:13 +00:00
|
|
|
text = _("Page overlap"),
|
2014-11-13 04:37:10 +00:00
|
|
|
enabled_func = function()
|
|
|
|
return not self.view.page_scroll and self.zoom_mode ~= "page"
|
|
|
|
and not self.zoom_mode:find("height")
|
|
|
|
end,
|
2014-11-17 13:44:13 +00:00
|
|
|
sub_item_table = page_overlap_menu,
|
2017-02-28 21:46:32 +00:00
|
|
|
}
|
2019-08-30 11:25:51 +00:00
|
|
|
menu_items.invert_page_turn_gestures = {
|
|
|
|
text = _("Invert page turn taps and swipes"),
|
2016-06-10 12:14:03 +00:00
|
|
|
checked_func = function() return self.inverse_reading_order end,
|
|
|
|
callback = function()
|
2019-09-25 22:28:07 +00:00
|
|
|
self.ui:handleEvent(Event:new("ToggleReadingOrder"))
|
2016-06-10 12:14:03 +00:00
|
|
|
end,
|
2019-08-30 11:25:51 +00:00
|
|
|
hold_callback = function(touchmenu_instance)
|
2019-10-25 15:25:26 +00:00
|
|
|
local inverse_reading_order = G_reader_settings:isTrue("inverse_reading_order")
|
|
|
|
UIManager:show(MultiConfirmBox:new{
|
|
|
|
text = inverse_reading_order and _("The default (★) for newly opened books is right-to-left (RTL) page turning.\n\nWould you like to change it?")
|
|
|
|
or _("The default (★) for newly opened books is left-to-right (LTR) page turning.\n\nWould you like to change it?"),
|
|
|
|
choice1_text_func = function()
|
|
|
|
return inverse_reading_order and _("LTR") or _("LTR (★)")
|
|
|
|
end,
|
|
|
|
choice1_callback = function()
|
|
|
|
G_reader_settings:saveSetting("inverse_reading_order", false)
|
|
|
|
if touchmenu_instance then touchmenu_instance:updateItems() end
|
|
|
|
end,
|
|
|
|
choice2_text_func = function()
|
|
|
|
return inverse_reading_order and _("RTL (★)") or _("RTL")
|
|
|
|
end,
|
|
|
|
choice2_callback = function()
|
|
|
|
G_reader_settings:saveSetting("inverse_reading_order", true)
|
2019-08-30 11:25:51 +00:00
|
|
|
if touchmenu_instance then touchmenu_instance:updateItems() end
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
end,
|
2017-02-28 21:46:32 +00:00
|
|
|
}
|
2012-12-04 07:19:50 +00:00
|
|
|
end
|
|
|
|
|
2017-10-01 17:23:06 +00:00
|
|
|
function ReaderPaging:onColorRenderingUpdate()
|
|
|
|
self.ui.document:updateColorRendering()
|
2019-03-24 20:54:58 +00:00
|
|
|
UIManager:setDirty(self.view.dialog, "partial")
|
2017-10-01 17:23:06 +00:00
|
|
|
end
|
|
|
|
|
2013-04-27 08:37:18 +00:00
|
|
|
--[[
|
|
|
|
Set reading position on certain page
|
2016-03-27 22:39:47 +00:00
|
|
|
Page position is a fractional number ranging from 0 to 1, indicating the read
|
|
|
|
percentage on certain page. With the position information on each page whenever
|
|
|
|
users change font size, page margin or line spacing or close and reopen the
|
|
|
|
book, the page view will be roughly the same.
|
2013-04-27 08:37:18 +00:00
|
|
|
--]]
|
|
|
|
function ReaderPaging:setPagePosition(page, pos)
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("set page position", pos)
|
2014-03-13 13:52:43 +00:00
|
|
|
self.page_positions[page] = pos
|
2020-11-03 21:51:11 +00:00
|
|
|
self.ui:handleEvent(Event:new("PagePositionUpdated"))
|
2013-04-27 08:37:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
--[[
|
|
|
|
Get reading position on certain page
|
|
|
|
--]]
|
|
|
|
function ReaderPaging:getPagePosition(page)
|
2014-05-19 06:23:31 +00:00
|
|
|
-- Page number ought to be integer, somehow I notice that with
|
|
|
|
-- fractional page number the reader runs silently well, but the
|
|
|
|
-- number won't fit to retrieve page position.
|
2014-03-13 13:52:43 +00:00
|
|
|
page = math.floor(page)
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("get page position", self.page_positions[page])
|
2014-03-13 13:52:43 +00:00
|
|
|
return self.page_positions[page] or 0
|
2013-04-27 08:37:18 +00:00
|
|
|
end
|
|
|
|
|
2014-01-03 19:14:24 +00:00
|
|
|
function ReaderPaging:onTogglePageFlipping()
|
2019-08-27 12:07:14 +00:00
|
|
|
if self.bookmark_flipping_mode then
|
2019-08-28 10:59:54 +00:00
|
|
|
-- do nothing if we're in bookmark flipping mode
|
2019-08-27 12:07:14 +00:00
|
|
|
return
|
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
self.view.flipping_visible = not self.view.flipping_visible
|
|
|
|
self.page_flipping_mode = self.view.flipping_visible
|
|
|
|
self.flipping_page = self.current_page
|
2014-05-19 06:23:31 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.page_flipping_mode then
|
|
|
|
self:updateOriginalPage(self.current_page)
|
|
|
|
self:enterFlippingMode()
|
|
|
|
else
|
|
|
|
self:updateOriginalPage(nil)
|
|
|
|
self:exitFlippingMode()
|
|
|
|
end
|
|
|
|
self.ui:handleEvent(Event:new("SetHinting", not self.page_flipping_mode))
|
|
|
|
self.ui:handleEvent(Event:new("ReZoom"))
|
|
|
|
UIManager:setDirty(self.view.dialog, "partial")
|
2014-01-03 19:14:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderPaging:onToggleBookmarkFlipping()
|
2019-08-27 12:07:14 +00:00
|
|
|
self.bookmark_flipping_mode = not self.bookmark_flipping_mode
|
2014-05-19 06:23:31 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.bookmark_flipping_mode then
|
|
|
|
self.orig_flipping_mode = self.view.flipping_visible
|
|
|
|
self.orig_dogear_mode = self.view.dogear_visible
|
2014-05-19 06:23:31 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
self.view.flipping_visible = true
|
|
|
|
self.view.dogear_visible = true
|
|
|
|
self.bm_flipping_orig_page = self.current_page
|
|
|
|
self:enterFlippingMode()
|
|
|
|
else
|
|
|
|
self.view.flipping_visible = self.orig_flipping_mode
|
|
|
|
self.view.dogear_visible = self.orig_dogear_mode
|
|
|
|
self:exitFlippingMode()
|
2016-03-27 22:39:47 +00:00
|
|
|
self:_gotoPage(self.bm_flipping_orig_page)
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
|
|
|
self.ui:handleEvent(Event:new("SetHinting", not self.bookmark_flipping_mode))
|
|
|
|
self.ui:handleEvent(Event:new("ReZoom"))
|
|
|
|
UIManager:setDirty(self.view.dialog, "partial")
|
2013-03-12 03:28:47 +00:00
|
|
|
end
|
|
|
|
|
2013-12-17 14:42:25 +00:00
|
|
|
function ReaderPaging:enterFlippingMode()
|
2014-03-13 13:52:43 +00:00
|
|
|
self.orig_reflow_mode = self.view.document.configurable.text_wrap
|
|
|
|
self.orig_scroll_mode = self.view.page_scroll
|
|
|
|
self.orig_zoom_mode = self.view.zoom_mode
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("store zoom mode", self.orig_zoom_mode)
|
2014-03-13 13:52:43 +00:00
|
|
|
self.view.document.configurable.text_wrap = 0
|
2015-03-24 01:34:07 +00:00
|
|
|
self.view.page_scroll = self.flipping_scroll_mode
|
2016-06-14 17:50:59 +00:00
|
|
|
self.ui:handleEvent(Event:new("EnterFlippingMode", self.flipping_zoom_mode))
|
2013-12-17 14:42:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderPaging:exitFlippingMode()
|
2014-03-13 13:52:43 +00:00
|
|
|
self.view.document.configurable.text_wrap = self.orig_reflow_mode
|
|
|
|
self.view.page_scroll = self.orig_scroll_mode
|
2015-03-12 06:52:55 +00:00
|
|
|
self.flipping_zoom_mode = self.view.zoom_mode
|
2015-03-24 01:34:07 +00:00
|
|
|
self.flipping_scroll_mode = self.view.page_scroll
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("restore zoom mode", self.orig_zoom_mode)
|
2016-06-14 17:50:59 +00:00
|
|
|
self.ui:handleEvent(Event:new("ExitFlippingMode", self.orig_zoom_mode))
|
2013-12-17 14:42:25 +00:00
|
|
|
end
|
|
|
|
|
2013-03-12 03:28:47 +00:00
|
|
|
function ReaderPaging:updateOriginalPage(page)
|
2014-03-13 13:52:43 +00:00
|
|
|
self.original_page = page
|
2013-03-12 03:28:47 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderPaging:updateFlippingPage(page)
|
2014-03-13 13:52:43 +00:00
|
|
|
self.flipping_page = page
|
2013-03-12 03:28:47 +00:00
|
|
|
end
|
|
|
|
|
2014-01-03 19:14:24 +00:00
|
|
|
function ReaderPaging:pageFlipping(flipping_page, flipping_ges)
|
2014-03-13 13:52:43 +00:00
|
|
|
local whole = self.number_of_pages
|
|
|
|
local steps = #self.flip_steps
|
|
|
|
local stp_proportion = flipping_ges.distance / Screen:getWidth()
|
|
|
|
local abs_proportion = flipping_ges.distance / Screen:getHeight()
|
2019-12-06 21:55:39 +00:00
|
|
|
local direction = BD.flipDirectionIfMirroredUILayout(flipping_ges.direction)
|
|
|
|
if direction == "east" then
|
2016-03-27 22:39:47 +00:00
|
|
|
self:_gotoPage(flipping_page - self.flip_steps[math.ceil(steps*stp_proportion)])
|
2019-12-06 21:55:39 +00:00
|
|
|
elseif direction == "west" then
|
2016-03-27 22:39:47 +00:00
|
|
|
self:_gotoPage(flipping_page + self.flip_steps[math.ceil(steps*stp_proportion)])
|
2019-12-06 21:55:39 +00:00
|
|
|
elseif direction == "south" then
|
2016-03-27 22:39:47 +00:00
|
|
|
self:_gotoPage(flipping_page - math.floor(whole*abs_proportion))
|
2019-12-06 21:55:39 +00:00
|
|
|
elseif direction == "north" then
|
2016-03-27 22:39:47 +00:00
|
|
|
self:_gotoPage(flipping_page + math.floor(whole*abs_proportion))
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
|
|
|
UIManager:setDirty(self.view.dialog, "partial")
|
2013-03-03 14:23:28 +00:00
|
|
|
end
|
|
|
|
|
2014-01-03 19:14:24 +00:00
|
|
|
function ReaderPaging:bookmarkFlipping(flipping_page, flipping_ges)
|
2019-12-06 21:55:39 +00:00
|
|
|
local direction = BD.flipDirectionIfMirroredUILayout(flipping_ges.direction)
|
|
|
|
if direction == "east" then
|
2014-03-13 13:52:43 +00:00
|
|
|
self.ui:handleEvent(Event:new("GotoPreviousBookmark", flipping_page))
|
2019-12-06 21:55:39 +00:00
|
|
|
elseif direction == "west" then
|
2014-03-13 13:52:43 +00:00
|
|
|
self.ui:handleEvent(Event:new("GotoNextBookmark", flipping_page))
|
|
|
|
end
|
|
|
|
UIManager:setDirty(self.view.dialog, "partial")
|
2014-01-03 19:14:24 +00:00
|
|
|
end
|
|
|
|
|
2016-12-04 06:57:57 +00:00
|
|
|
function ReaderPaging:onSwipe(_, ges)
|
2019-12-06 21:55:39 +00:00
|
|
|
local direction = BD.flipDirectionIfMirroredUILayout(ges.direction)
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.bookmark_flipping_mode then
|
|
|
|
self:bookmarkFlipping(self.current_page, ges)
|
|
|
|
elseif self.page_flipping_mode and self.original_page then
|
2016-03-27 22:39:47 +00:00
|
|
|
self:_gotoPage(self.original_page)
|
2019-12-06 21:55:39 +00:00
|
|
|
elseif direction == "west" then
|
2016-06-10 12:14:03 +00:00
|
|
|
if self.inverse_reading_order then
|
2019-03-01 15:05:03 +00:00
|
|
|
self:onGotoViewRel(-1)
|
2016-06-10 12:14:03 +00:00
|
|
|
else
|
2019-03-01 15:05:03 +00:00
|
|
|
self:onGotoViewRel(1)
|
2016-06-10 12:14:03 +00:00
|
|
|
end
|
2019-12-06 21:55:39 +00:00
|
|
|
elseif direction == "east" then
|
2016-06-10 12:14:03 +00:00
|
|
|
if self.inverse_reading_order then
|
2019-03-01 15:05:03 +00:00
|
|
|
self:onGotoViewRel(1)
|
2016-06-10 12:14:03 +00:00
|
|
|
else
|
2019-03-01 15:05:03 +00:00
|
|
|
self:onGotoViewRel(-1)
|
2016-06-10 12:14:03 +00:00
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
else
|
2017-03-19 20:35:18 +00:00
|
|
|
-- update footer (time & battery)
|
2020-07-12 18:47:49 +00:00
|
|
|
self.view.footer:onUpdateFooter()
|
2014-11-30 00:12:00 +00:00
|
|
|
-- trigger full refresh
|
|
|
|
UIManager:setDirty(nil, "full")
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2013-03-03 14:23:28 +00:00
|
|
|
end
|
|
|
|
|
2016-12-04 06:57:57 +00:00
|
|
|
function ReaderPaging:onPan(_, ges)
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.bookmark_flipping_mode then
|
|
|
|
return true
|
|
|
|
elseif self.page_flipping_mode then
|
|
|
|
if self.view.zoom_mode == "page" then
|
|
|
|
self:pageFlipping(self.flipping_page, ges)
|
|
|
|
else
|
|
|
|
self.view:PanningStart(-ges.relative.x, -ges.relative.y)
|
|
|
|
end
|
|
|
|
elseif ges.direction == "north" or ges.direction == "south" then
|
2019-02-28 22:49:23 +00:00
|
|
|
local relative_type = "relative"
|
|
|
|
if self.ui.gesture and self.ui.gesture.multiswipes_enabled then
|
|
|
|
relative_type = "relative_delayed"
|
|
|
|
end
|
2019-07-28 11:57:03 +00:00
|
|
|
-- this is only used when mouse wheel is used
|
|
|
|
if ges.mousewheel_direction and not self.view.page_scroll then
|
|
|
|
self:onGotoViewRel(-1 * ges.mousewheel_direction)
|
|
|
|
else
|
|
|
|
self:onPanningRel(self.last_pan_relative_y - ges[relative_type].y)
|
|
|
|
self.last_pan_relative_y = ges[relative_type].y
|
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
|
|
|
return true
|
2013-03-03 14:23:28 +00:00
|
|
|
end
|
|
|
|
|
2016-12-04 06:57:57 +00:00
|
|
|
function ReaderPaging:onPanRelease(_, ges)
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.page_flipping_mode then
|
|
|
|
if self.view.zoom_mode == "page" then
|
|
|
|
self:updateFlippingPage(self.current_page)
|
|
|
|
else
|
|
|
|
self.view:PanningStop()
|
|
|
|
end
|
|
|
|
else
|
|
|
|
self.last_pan_relative_y = 0
|
2014-12-03 10:37:00 +00:00
|
|
|
-- trigger full refresh to clear ghosting generated by previous fast refresh
|
2014-12-03 03:33:54 +00:00
|
|
|
UIManager:setDirty(nil, "full")
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2013-03-12 03:28:47 +00:00
|
|
|
end
|
|
|
|
|
2012-12-03 05:48:41 +00:00
|
|
|
function ReaderPaging:onZoomModeUpdate(new_mode)
|
2014-03-13 13:52:43 +00:00
|
|
|
-- we need to remember zoom mode to handle page turn event
|
|
|
|
self.zoom_mode = new_mode
|
2012-12-03 05:48:41 +00:00
|
|
|
end
|
|
|
|
|
2016-03-27 22:39:47 +00:00
|
|
|
function ReaderPaging:onPageUpdate(new_page_no, orig_mode)
|
2014-03-13 13:52:43 +00:00
|
|
|
self.current_page = new_page_no
|
2016-03-27 22:39:47 +00:00
|
|
|
if self.view.page_scroll and orig_mode ~= "scrolling" then
|
|
|
|
self.ui:handleEvent(Event:new("InitScrollPageStates", orig_mode))
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2012-05-18 22:50:26 +00:00
|
|
|
end
|
|
|
|
|
2012-12-03 05:48:41 +00:00
|
|
|
function ReaderPaging:onViewRecalculate(visible_area, page_area)
|
2014-03-13 13:52:43 +00:00
|
|
|
-- we need to remember areas to handle page turn event
|
|
|
|
self.visible_area = visible_area:copy()
|
|
|
|
self.page_area = page_area
|
2012-12-03 05:48:41 +00:00
|
|
|
end
|
|
|
|
|
2012-05-18 22:50:26 +00:00
|
|
|
function ReaderPaging:onGotoPercent(percent)
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("goto document offset in percent:", percent)
|
2014-03-13 13:52:43 +00:00
|
|
|
local dest = math.floor(self.number_of_pages * percent / 100)
|
|
|
|
if dest < 1 then dest = 1 end
|
|
|
|
if dest > self.number_of_pages then
|
|
|
|
dest = self.number_of_pages
|
|
|
|
end
|
2016-03-27 22:39:47 +00:00
|
|
|
self:_gotoPage(dest)
|
2014-03-13 13:52:43 +00:00
|
|
|
return true
|
2012-05-18 22:50:26 +00:00
|
|
|
end
|
|
|
|
|
2019-03-01 15:05:03 +00:00
|
|
|
function ReaderPaging:onGotoViewRel(diff)
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.view.page_scroll then
|
|
|
|
self:onScrollPageRel(diff)
|
|
|
|
else
|
|
|
|
self:onGotoPageRel(diff)
|
|
|
|
end
|
|
|
|
self:setPagePosition(self:getTopPage(), self:getTopPosition())
|
|
|
|
return true
|
2013-03-10 06:23:26 +00:00
|
|
|
end
|
|
|
|
|
2019-07-28 11:57:03 +00:00
|
|
|
function ReaderPaging:onGotoPosRel(diff)
|
|
|
|
if self.view.page_scroll then
|
|
|
|
self:onPanningRel(100*diff)
|
|
|
|
else
|
|
|
|
self:onGotoPageRel(diff)
|
|
|
|
end
|
|
|
|
self:setPagePosition(self:getTopPage(), self:getTopPosition())
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2013-04-14 09:39:12 +00:00
|
|
|
function ReaderPaging:onPanningRel(diff)
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.view.page_scroll then
|
|
|
|
self:onScrollPanRel(diff)
|
|
|
|
end
|
|
|
|
self:setPagePosition(self:getTopPage(), self:getTopPosition())
|
|
|
|
return true
|
2013-04-14 09:39:12 +00:00
|
|
|
end
|
|
|
|
|
2016-03-27 22:39:47 +00:00
|
|
|
function ReaderPaging:getBookLocation()
|
|
|
|
return self.view:getViewContext()
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderPaging:onRestoreBookLocation(saved_location)
|
|
|
|
if self.view.page_scroll then
|
2020-11-03 21:51:11 +00:00
|
|
|
if self.view:restoreViewContext(saved_location) then
|
|
|
|
self:_gotoPage(saved_location[1].page, "scrolling")
|
|
|
|
else
|
|
|
|
-- If context is unusable (not from scroll mode), trigger
|
|
|
|
-- this to go at least to its page and redraw it
|
|
|
|
self.ui:handleEvent(Event:new("PageUpdate", saved_location[1].page))
|
|
|
|
end
|
2016-03-27 22:39:47 +00:00
|
|
|
else
|
2020-11-03 21:51:11 +00:00
|
|
|
-- gotoPage may emit PageUpdate event, which will trigger recalculate
|
2016-03-27 22:39:47 +00:00
|
|
|
-- in ReaderView and resets the view context. So we need to call
|
2020-11-03 21:51:11 +00:00
|
|
|
-- restoreViewContext after gotoPage.
|
|
|
|
-- But if we're restoring to the same page, it will not emit
|
|
|
|
-- PageUpdate event - so we need to do it for a correct redrawing
|
|
|
|
local send_PageUpdate = saved_location[1].page == self.current_page
|
2016-03-27 22:39:47 +00:00
|
|
|
self:_gotoPage(saved_location[1].page)
|
2020-11-03 21:51:11 +00:00
|
|
|
if not self.view:restoreViewContext(saved_location) then
|
|
|
|
-- If context is unusable (not from page mode), also
|
|
|
|
-- send PageUpdate event to go to its page and redraw it
|
|
|
|
send_PageUpdate = true
|
|
|
|
end
|
|
|
|
if send_PageUpdate then
|
|
|
|
self.ui:handleEvent(Event:new("PageUpdate", saved_location[1].page))
|
|
|
|
end
|
2016-03-27 22:39:47 +00:00
|
|
|
end
|
|
|
|
self:setPagePosition(self:getTopPage(), self:getTopPosition())
|
2020-11-03 21:51:11 +00:00
|
|
|
-- In some cases (same page, different offset), doing the above
|
|
|
|
-- might not redraw the screen. Ensure it is.
|
|
|
|
UIManager:setDirty(self.view.dialog, "partial")
|
2016-03-27 22:39:47 +00:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2013-04-27 08:37:18 +00:00
|
|
|
--[[
|
|
|
|
Get read percentage on current page.
|
|
|
|
--]]
|
|
|
|
function ReaderPaging:getTopPosition()
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.view.page_scroll then
|
|
|
|
local state = self.view.page_states[1]
|
|
|
|
return (state.visible_area.y - state.page_area.y)/state.page_area.h
|
|
|
|
else
|
|
|
|
return 0
|
|
|
|
end
|
2013-04-27 08:37:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
--[[
|
|
|
|
Get page number of the page drawn at the very top part of the screen.
|
|
|
|
--]]
|
|
|
|
function ReaderPaging:getTopPage()
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.view.page_scroll then
|
|
|
|
local state = self.view.page_states[1]
|
|
|
|
return state and state.page or self.current_page
|
|
|
|
else
|
|
|
|
return self.current_page
|
|
|
|
end
|
2013-04-27 08:37:18 +00:00
|
|
|
end
|
|
|
|
|
2016-03-27 22:39:47 +00:00
|
|
|
function ReaderPaging:onInitScrollPageStates(orig_mode)
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("init scroll page states", orig_mode)
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.view.page_scroll and self.view.state.page then
|
|
|
|
self.orig_page = self.current_page
|
|
|
|
self.view.page_states = {}
|
|
|
|
local blank_area = Geom:new{}
|
2019-12-08 18:27:14 +00:00
|
|
|
blank_area:setSizeTo(self.view.visible_area)
|
2014-03-13 13:52:43 +00:00
|
|
|
while blank_area.h > 0 do
|
|
|
|
local offset = Geom:new{}
|
|
|
|
-- caculate position in current page
|
|
|
|
if self.current_page == self.orig_page then
|
|
|
|
local page_area = self.view:getPageArea(
|
|
|
|
self.view.state.page,
|
|
|
|
self.view.state.zoom,
|
|
|
|
self.view.state.rotation)
|
|
|
|
offset.y = page_area.h * self:getPagePosition(self.current_page)
|
|
|
|
end
|
|
|
|
local state = self:getNextPageState(blank_area, offset)
|
|
|
|
table.insert(self.view.page_states, state)
|
|
|
|
if blank_area.h > 0 then
|
|
|
|
blank_area.h = blank_area.h - self.view.page_gap.height
|
|
|
|
end
|
|
|
|
if blank_area.h > 0 then
|
2016-03-27 22:39:47 +00:00
|
|
|
self:_gotoPage(self.current_page + 1, "scrolling")
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
|
|
|
end
|
2016-03-27 22:39:47 +00:00
|
|
|
self:_gotoPage(self.orig_page, "scrolling")
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
|
|
|
return true
|
2013-03-10 06:23:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderPaging:onUpdateScrollPageRotation(rotation)
|
2014-03-13 13:52:43 +00:00
|
|
|
for _, state in ipairs(self.view.page_states) do
|
|
|
|
state.rotation = rotation
|
|
|
|
end
|
|
|
|
return true
|
2013-03-10 06:23:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderPaging:onUpdateScrollPageGamma(gamma)
|
2014-03-13 13:52:43 +00:00
|
|
|
for _, state in ipairs(self.view.page_states) do
|
|
|
|
state.gamma = gamma
|
|
|
|
end
|
|
|
|
return true
|
2013-03-10 06:23:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderPaging:getNextPageState(blank_area, offset)
|
2014-03-13 13:52:43 +00:00
|
|
|
local page_area = self.view:getPageArea(
|
|
|
|
self.view.state.page,
|
|
|
|
self.view.state.zoom,
|
|
|
|
self.view.state.rotation)
|
|
|
|
local visible_area = Geom:new{x = 0, y = 0}
|
|
|
|
visible_area.w, visible_area.h = blank_area.w, blank_area.h
|
|
|
|
visible_area.x, visible_area.y = page_area.x, page_area.y
|
|
|
|
visible_area = visible_area:shrinkInside(page_area, offset.x, offset.y)
|
|
|
|
-- shrink blank area by the height of visible area
|
|
|
|
blank_area.h = blank_area.h - visible_area.h
|
|
|
|
return {
|
|
|
|
page = self.view.state.page,
|
|
|
|
zoom = self.view.state.zoom,
|
|
|
|
rotation = self.view.state.rotation,
|
|
|
|
gamma = self.view.state.gamma,
|
|
|
|
offset = Geom:new{ x = self.view.state.offset.x, y = 0},
|
|
|
|
visible_area = visible_area,
|
|
|
|
page_area = page_area,
|
|
|
|
}
|
2013-03-10 06:23:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderPaging:getPrevPageState(blank_area, offset)
|
2014-03-13 13:52:43 +00:00
|
|
|
local page_area = self.view:getPageArea(
|
|
|
|
self.view.state.page,
|
|
|
|
self.view.state.zoom,
|
|
|
|
self.view.state.rotation)
|
|
|
|
local visible_area = Geom:new{x = 0, y = 0}
|
|
|
|
visible_area.w, visible_area.h = blank_area.w, blank_area.h
|
|
|
|
visible_area.x = page_area.x
|
|
|
|
visible_area.y = page_area.y + page_area.h - visible_area.h
|
|
|
|
visible_area = visible_area:shrinkInside(page_area, offset.x, offset.y)
|
|
|
|
-- shrink blank area by the height of visible area
|
|
|
|
blank_area.h = blank_area.h - visible_area.h
|
|
|
|
return {
|
|
|
|
page = self.view.state.page,
|
|
|
|
zoom = self.view.state.zoom,
|
|
|
|
rotation = self.view.state.rotation,
|
|
|
|
gamma = self.view.state.gamma,
|
|
|
|
offset = Geom:new{ x = self.view.state.offset.x, y = 0},
|
|
|
|
visible_area = visible_area,
|
|
|
|
page_area = page_area,
|
|
|
|
}
|
2013-03-10 06:23:26 +00:00
|
|
|
end
|
|
|
|
|
2013-04-14 09:39:12 +00:00
|
|
|
function ReaderPaging:updateTopPageState(state, blank_area, offset)
|
2016-11-24 02:48:00 +00:00
|
|
|
local visible_area = Geom:new{
|
|
|
|
x = state.visible_area.x,
|
|
|
|
y = state.visible_area.y,
|
|
|
|
w = blank_area.w,
|
|
|
|
h = blank_area.h,
|
|
|
|
}
|
2014-03-13 13:52:43 +00:00
|
|
|
if state.page == self.number_of_pages then
|
|
|
|
visible_area:offsetWithin(state.page_area, offset.x, offset.y)
|
|
|
|
else
|
|
|
|
visible_area = visible_area:shrinkInside(state.page_area, offset.x, offset.y)
|
|
|
|
end
|
|
|
|
-- shrink blank area by the height of visible area
|
|
|
|
blank_area.h = blank_area.h - visible_area.h
|
|
|
|
state.visible_area = visible_area
|
2013-03-10 06:23:26 +00:00
|
|
|
end
|
|
|
|
|
2013-04-14 09:39:12 +00:00
|
|
|
function ReaderPaging:updateBottomPageState(state, blank_area, offset)
|
2016-11-24 02:48:00 +00:00
|
|
|
local visible_area = Geom:new{
|
|
|
|
x = state.page_area.x,
|
|
|
|
y = state.visible_area.y + state.visible_area.h - blank_area.h,
|
|
|
|
w = blank_area.w,
|
|
|
|
h = blank_area.h,
|
|
|
|
}
|
2014-03-13 13:52:43 +00:00
|
|
|
if state.page == 1 then
|
|
|
|
visible_area:offsetWithin(state.page_area, offset.x, offset.y)
|
|
|
|
else
|
|
|
|
visible_area = visible_area:shrinkInside(state.page_area, offset.x, offset.y)
|
|
|
|
end
|
|
|
|
-- shrink blank area by the height of visible area
|
|
|
|
blank_area.h = blank_area.h - visible_area.h
|
|
|
|
state.visible_area = visible_area
|
2013-03-10 06:23:26 +00:00
|
|
|
end
|
|
|
|
|
2013-04-14 09:39:12 +00:00
|
|
|
function ReaderPaging:genPageStatesFromTop(top_page_state, blank_area, offset)
|
2014-03-13 13:52:43 +00:00
|
|
|
-- Offset should always be greater than 0
|
|
|
|
-- otherwise if offset is less than 0 the height of blank area will be
|
|
|
|
-- larger than 0 even if page area is much larger than visible area,
|
|
|
|
-- which will trigger the drawing of next page leaving part of current
|
|
|
|
-- page undrawn. This should also be true for generating from bottom.
|
|
|
|
if offset.y < 0 then offset.y = 0 end
|
2016-11-24 02:48:00 +00:00
|
|
|
self:updateTopPageState(top_page_state, blank_area, offset)
|
2014-03-13 13:52:43 +00:00
|
|
|
local page_states = {}
|
2016-11-24 02:48:00 +00:00
|
|
|
if top_page_state.visible_area.h > 0 then
|
|
|
|
-- offset does not scroll pass top_page_state
|
|
|
|
table.insert(page_states, top_page_state)
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2016-11-24 02:48:00 +00:00
|
|
|
local state
|
|
|
|
local current_page = top_page_state.page
|
2014-03-13 13:52:43 +00:00
|
|
|
while blank_area.h > 0 do
|
|
|
|
blank_area.h = blank_area.h - self.view.page_gap.height
|
|
|
|
if blank_area.h > 0 then
|
2016-11-24 02:48:00 +00:00
|
|
|
if current_page == self.number_of_pages then break end
|
2016-03-27 22:39:47 +00:00
|
|
|
self:_gotoPage(current_page + 1, "scrolling")
|
2014-03-13 13:52:43 +00:00
|
|
|
current_page = current_page + 1
|
2016-06-27 16:43:23 +00:00
|
|
|
state = self:getNextPageState(blank_area, Geom:new{})
|
2014-03-13 13:52:43 +00:00
|
|
|
table.insert(page_states, state)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return page_states
|
2013-04-14 09:39:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderPaging:genPageStatesFromBottom(bottom_page_state, blank_area, offset)
|
2014-03-13 13:52:43 +00:00
|
|
|
-- scroll up offset should always be less than 0
|
|
|
|
if offset.y > 0 then offset.y = 0 end
|
2016-11-24 02:48:00 +00:00
|
|
|
-- find out number of pages need to be removed from current view
|
|
|
|
self:updateBottomPageState(bottom_page_state, blank_area, offset)
|
2014-03-13 13:52:43 +00:00
|
|
|
local page_states = {}
|
2016-11-24 02:48:00 +00:00
|
|
|
if bottom_page_state.visible_area.h > 0 then
|
|
|
|
table.insert(page_states, bottom_page_state)
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2016-11-24 02:48:00 +00:00
|
|
|
-- fill up current view from bottom to top
|
|
|
|
local state
|
|
|
|
local current_page = bottom_page_state.page
|
2014-03-13 13:52:43 +00:00
|
|
|
while blank_area.h > 0 do
|
|
|
|
blank_area.h = blank_area.h - self.view.page_gap.height
|
|
|
|
if blank_area.h > 0 then
|
2016-11-24 02:48:00 +00:00
|
|
|
if current_page == 1 then break end
|
2016-03-27 22:39:47 +00:00
|
|
|
self:_gotoPage(current_page - 1, "scrolling")
|
2014-03-13 13:52:43 +00:00
|
|
|
current_page = current_page - 1
|
2016-06-27 16:43:23 +00:00
|
|
|
state = self:getPrevPageState(blank_area, Geom:new{})
|
2014-03-13 13:52:43 +00:00
|
|
|
table.insert(page_states, 1, state)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return page_states
|
2013-04-14 09:39:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderPaging:onScrollPanRel(diff)
|
2016-11-24 02:48:00 +00:00
|
|
|
if diff == 0 then return true end
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("pan relative height:", diff)
|
2016-11-24 02:48:00 +00:00
|
|
|
local offset = Geom:new{x = 0, y = diff}
|
2014-03-13 13:52:43 +00:00
|
|
|
local blank_area = Geom:new{}
|
2019-12-08 18:27:14 +00:00
|
|
|
blank_area:setSizeTo(self.view.visible_area)
|
2016-11-24 02:48:00 +00:00
|
|
|
local new_page_states
|
2014-03-13 13:52:43 +00:00
|
|
|
if diff > 0 then
|
2016-11-24 02:48:00 +00:00
|
|
|
-- pan to scroll down
|
|
|
|
local first_page_state = copyPageState(self.view.page_states[1])
|
|
|
|
new_page_states = self:genPageStatesFromTop(
|
|
|
|
first_page_state, blank_area, offset)
|
|
|
|
elseif diff < 0 then
|
|
|
|
local last_page_state = copyPageState(
|
|
|
|
self.view.page_states[#self.view.page_states])
|
|
|
|
new_page_states = self:genPageStatesFromBottom(
|
|
|
|
last_page_state, blank_area, offset)
|
|
|
|
end
|
|
|
|
if #new_page_states == 0 then
|
|
|
|
-- if we are already at the top of first page or bottom of the last
|
|
|
|
-- page, new_page_states will be empty, in this case, nothing to update
|
|
|
|
return true
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2016-11-24 02:48:00 +00:00
|
|
|
self.view.page_states = new_page_states
|
2014-03-13 13:52:43 +00:00
|
|
|
-- update current pageno to the very last part in current view
|
2016-11-24 02:48:00 +00:00
|
|
|
self:_gotoPage(self.view.page_states[#self.view.page_states].page,
|
|
|
|
"scrolling")
|
2019-02-11 02:28:46 +00:00
|
|
|
UIManager:setDirty(self.view.dialog, "partial")
|
2016-11-24 02:48:00 +00:00
|
|
|
return true
|
2013-04-14 09:39:12 +00:00
|
|
|
end
|
|
|
|
|
2016-11-24 02:48:00 +00:00
|
|
|
function ReaderPaging:onScrollPageRel(page_diff)
|
|
|
|
if page_diff == 0 then return true end
|
|
|
|
if page_diff > 0 then
|
|
|
|
-- page down, last page should be moved to top
|
2014-03-13 13:52:43 +00:00
|
|
|
local last_page_state = table.remove(self.view.page_states)
|
2016-02-22 01:46:19 +00:00
|
|
|
local last_visible_area = last_page_state.visible_area
|
|
|
|
if last_page_state.page == self.number_of_pages and
|
|
|
|
last_visible_area.y + last_visible_area.h >= last_page_state.page_area.h then
|
|
|
|
table.insert(self.view.page_states, last_page_state)
|
|
|
|
self.ui:handleEvent(Event:new("EndOfBook"))
|
|
|
|
return true
|
|
|
|
end
|
2016-03-27 22:39:47 +00:00
|
|
|
|
|
|
|
local blank_area = Geom:new{}
|
2019-12-08 18:27:14 +00:00
|
|
|
blank_area:setSizeTo(self.view.visible_area)
|
2019-11-21 09:05:40 +00:00
|
|
|
local overlap = self.overlap
|
2016-03-27 22:39:47 +00:00
|
|
|
local offset = Geom:new{
|
|
|
|
x = 0,
|
|
|
|
y = last_visible_area.h - overlap
|
|
|
|
}
|
|
|
|
self.view.page_states = self:genPageStatesFromTop(last_page_state, blank_area, offset)
|
2016-11-24 02:48:00 +00:00
|
|
|
elseif page_diff < 0 then
|
|
|
|
-- page up, first page should be moved to bottom
|
2016-02-22 01:46:19 +00:00
|
|
|
local blank_area = Geom:new{}
|
2019-12-08 18:27:14 +00:00
|
|
|
blank_area:setSizeTo(self.view.visible_area)
|
2019-11-21 09:05:40 +00:00
|
|
|
local overlap = self.overlap
|
2014-03-13 13:52:43 +00:00
|
|
|
local first_page_state = table.remove(self.view.page_states, 1)
|
|
|
|
local offset = Geom:new{
|
|
|
|
x = 0,
|
2014-07-17 13:27:35 +00:00
|
|
|
y = -first_page_state.visible_area.h + overlap
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
2016-11-24 02:48:00 +00:00
|
|
|
self.view.page_states = self:genPageStatesFromBottom(
|
|
|
|
first_page_state, blank_area, offset)
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
|
|
|
-- update current pageno to the very last part in current view
|
2016-03-27 22:39:47 +00:00
|
|
|
self:_gotoPage(self.view.page_states[#self.view.page_states].page, "scrolling")
|
2014-11-30 00:12:00 +00:00
|
|
|
UIManager:setDirty(self.view.dialog, "partial")
|
2016-02-22 01:46:19 +00:00
|
|
|
return true
|
2013-03-10 06:23:26 +00:00
|
|
|
end
|
|
|
|
|
2012-05-18 22:50:26 +00:00
|
|
|
function ReaderPaging:onGotoPageRel(diff)
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("goto relative page:", diff)
|
2014-03-13 13:52:43 +00:00
|
|
|
local new_va = self.visible_area:copy()
|
|
|
|
local x_pan_off, y_pan_off = 0, 0
|
|
|
|
|
2016-09-12 04:47:24 +00:00
|
|
|
if self.zoom_mode:find("width") then
|
2014-03-13 13:52:43 +00:00
|
|
|
y_pan_off = self.visible_area.h * diff
|
|
|
|
elseif self.zoom_mode:find("height") then
|
2014-08-06 14:06:34 +00:00
|
|
|
-- negative x panning if writing direction is right to left
|
|
|
|
local direction = self.ui.document.configurable.writing_direction
|
|
|
|
x_pan_off = self.visible_area.w * diff * (direction == 1 and -1 or 1)
|
2018-02-10 13:58:39 +00:00
|
|
|
elseif self.zoom_mode:find("column") then
|
|
|
|
-- zoom mode for two-column navigation
|
|
|
|
|
|
|
|
y_pan_off = self.visible_area.h * diff
|
|
|
|
y_pan_off = Math.roundAwayFromZero(y_pan_off)
|
|
|
|
new_va.x = Math.roundAwayFromZero(self.visible_area.x)
|
|
|
|
new_va.y = Math.roundAwayFromZero(self.visible_area.y+y_pan_off)
|
|
|
|
-- intra-column navigation (vertical), this is the default behavior
|
|
|
|
-- if we do not reach the end of a column
|
|
|
|
|
|
|
|
if new_va:notIntersectWith(self.page_area) then
|
|
|
|
-- if we leave the page, we must either switch to the other column
|
|
|
|
-- or switch to another page (we are crossing the end of a column)
|
|
|
|
|
|
|
|
x_pan_off = self.visible_area.w * diff
|
|
|
|
x_pan_off = Math.roundAwayFromZero(x_pan_off)
|
|
|
|
new_va.x = Math.roundAwayFromZero(self.visible_area.x+x_pan_off)
|
|
|
|
new_va.y = Math.roundAwayFromZero(self.visible_area.y)
|
|
|
|
-- inter-column displacement (horizontal)
|
|
|
|
|
|
|
|
if new_va:notIntersectWith(self.page_area) then
|
|
|
|
-- if we leave the page with horizontal displacement, then we are
|
|
|
|
-- already in the border column, we must turn the page
|
|
|
|
|
|
|
|
local new_page = self.current_page + diff
|
|
|
|
if diff > 0 and new_page == self.number_of_pages + 1 then
|
|
|
|
self.ui:handleEvent(Event:new("EndOfBook"))
|
|
|
|
else
|
|
|
|
self:_gotoPage(new_page)
|
|
|
|
end
|
|
|
|
|
|
|
|
if y_pan_off < 0 then
|
|
|
|
-- if we are going back to previous page, reset view area
|
|
|
|
-- to bottom right of previous page, end of second column
|
|
|
|
self.view:PanningUpdate(self.page_area.w, self.page_area.h)
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
|
|
|
-- if we do not leave the page with horizontal displacement,
|
|
|
|
-- it means that we can stay on this page and switch column
|
|
|
|
|
|
|
|
if diff > 0 then
|
|
|
|
-- end of first column, set view area to the top right of
|
|
|
|
-- current page, beginning of second column
|
|
|
|
self.view:PanningUpdate(self.page_area.w, -self.page_area.h)
|
|
|
|
else
|
|
|
|
-- move backwards to the first column, set the view area to the
|
|
|
|
-- bottom left of the current page
|
|
|
|
self.view:PanningUpdate(-self.page_area.w, self.page_area.h)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- if we are here, the panning has already been updated so return
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2016-09-12 04:47:24 +00:00
|
|
|
elseif self.zoom_mode ~= "free" then -- do nothing in "free" zoom mode
|
2014-03-13 13:52:43 +00:00
|
|
|
-- must be fit content or page zoom mode
|
|
|
|
if self.visible_area.w == self.page_area.w then
|
|
|
|
y_pan_off = self.visible_area.h * diff
|
|
|
|
else
|
|
|
|
x_pan_off = self.visible_area.w * diff
|
|
|
|
end
|
|
|
|
end
|
|
|
|
-- adjust offset to help with page turn decision
|
|
|
|
-- we dont take overlap into account here yet, otherwise new_va will
|
|
|
|
-- always intersect with page_area
|
|
|
|
x_pan_off = Math.roundAwayFromZero(x_pan_off)
|
|
|
|
y_pan_off = Math.roundAwayFromZero(y_pan_off)
|
|
|
|
new_va.x = Math.roundAwayFromZero(self.visible_area.x+x_pan_off)
|
|
|
|
new_va.y = Math.roundAwayFromZero(self.visible_area.y+y_pan_off)
|
|
|
|
|
|
|
|
if new_va:notIntersectWith(self.page_area) then
|
|
|
|
-- view area out of page area, do a page turn
|
2016-02-22 01:46:19 +00:00
|
|
|
local new_page = self.current_page + diff
|
|
|
|
if diff > 0 and new_page == self.number_of_pages + 1 then
|
|
|
|
self.ui:handleEvent(Event:new("EndOfBook"))
|
|
|
|
else
|
2016-03-27 22:39:47 +00:00
|
|
|
self:_gotoPage(new_page)
|
2016-02-22 01:46:19 +00:00
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
-- if we are going back to previous page, reset
|
|
|
|
-- view area to bottom of previous page
|
|
|
|
if x_pan_off < 0 then
|
|
|
|
self.view:PanningUpdate(self.page_area.w, 0)
|
|
|
|
elseif y_pan_off < 0 then
|
|
|
|
self.view:PanningUpdate(0, self.page_area.h)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
-- not end of page yet, goto next view
|
|
|
|
-- adjust panning step according to overlap
|
2019-11-21 09:05:40 +00:00
|
|
|
local overlap = self.overlap
|
2014-07-17 13:27:35 +00:00
|
|
|
if x_pan_off > overlap then
|
2014-03-13 13:52:43 +00:00
|
|
|
-- moving to next view, move view
|
2014-07-17 13:27:35 +00:00
|
|
|
x_pan_off = x_pan_off - overlap
|
|
|
|
elseif x_pan_off < -overlap then
|
|
|
|
x_pan_off = x_pan_off + overlap
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2014-07-17 13:27:35 +00:00
|
|
|
if y_pan_off > overlap then
|
|
|
|
y_pan_off = y_pan_off - overlap
|
|
|
|
elseif y_pan_off < -overlap then
|
|
|
|
y_pan_off = y_pan_off + overlap
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
|
|
|
-- we have to calculate again to count into overlap
|
|
|
|
new_va.x = Math.roundAwayFromZero(self.visible_area.x+x_pan_off)
|
|
|
|
new_va.y = Math.roundAwayFromZero(self.visible_area.y+y_pan_off)
|
|
|
|
-- fit new view area into page area
|
|
|
|
new_va:offsetWithin(self.page_area, 0, 0)
|
|
|
|
-- calculate panning offsets
|
|
|
|
local panned_x = new_va.x - self.visible_area.x
|
|
|
|
local panned_y = new_va.y - self.visible_area.y
|
2016-03-28 01:50:23 +00:00
|
|
|
-- adjust for crazy floating point overflow...
|
2014-03-13 13:52:43 +00:00
|
|
|
if math.abs(panned_x) < 1 then
|
|
|
|
panned_x = 0
|
|
|
|
end
|
|
|
|
if math.abs(panned_y) < 1 then
|
|
|
|
panned_y = 0
|
|
|
|
end
|
|
|
|
-- singal panning update
|
|
|
|
self.view:PanningUpdate(panned_x, panned_y)
|
|
|
|
-- update dime area in ReaderView
|
|
|
|
if self.show_overlap_enable then
|
|
|
|
self.view.dim_area.h = new_va.h - math.abs(panned_y)
|
|
|
|
self.view.dim_area.w = new_va.w - math.abs(panned_x)
|
|
|
|
if panned_y < 0 then
|
|
|
|
self.view.dim_area.y = new_va.y - panned_y
|
|
|
|
else
|
|
|
|
self.view.dim_area.y = 0
|
|
|
|
end
|
|
|
|
if panned_x < 0 then
|
|
|
|
self.view.dim_area.x = new_va.x - panned_x
|
|
|
|
else
|
|
|
|
self.view.dim_area.x = 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
-- update self.visible_area
|
|
|
|
self.visible_area = new_va
|
|
|
|
end
|
|
|
|
|
|
|
|
return true
|
2012-05-18 22:50:26 +00:00
|
|
|
end
|
2012-06-26 17:00:21 +00:00
|
|
|
|
2013-01-03 14:24:38 +00:00
|
|
|
function ReaderPaging:onRedrawCurrentPage()
|
2014-03-13 13:52:43 +00:00
|
|
|
self.ui:handleEvent(Event:new("PageUpdate", self.current_page))
|
|
|
|
return true
|
2013-01-03 14:24:38 +00:00
|
|
|
end
|
2013-02-02 06:36:29 +00:00
|
|
|
|
|
|
|
-- wrapper for bounds checking
|
2016-03-27 22:39:47 +00:00
|
|
|
function ReaderPaging:_gotoPage(number, orig_mode)
|
2014-03-13 13:52:43 +00:00
|
|
|
if number == self.current_page or not number then
|
2017-03-19 20:35:18 +00:00
|
|
|
-- update footer even if we stay on the same page (like when
|
|
|
|
-- viewing the bottom part of a page from a top part view)
|
2020-07-12 18:47:49 +00:00
|
|
|
self.view.footer:onUpdateFooter()
|
2014-03-13 13:52:43 +00:00
|
|
|
return true
|
|
|
|
end
|
2019-08-30 11:47:51 +00:00
|
|
|
if number > self.number_of_pages then
|
|
|
|
logger.warn("page number too high: "..number.."!")
|
|
|
|
number = self.number_of_pages
|
|
|
|
elseif number < 1 then
|
|
|
|
logger.warn("page number too low: "..number.."!")
|
|
|
|
number = 1
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
|
|
|
-- this is an event to allow other controllers to be aware of this change
|
2016-03-27 22:39:47 +00:00
|
|
|
self.ui:handleEvent(Event:new("PageUpdate", number, orig_mode))
|
2014-03-13 13:52:43 +00:00
|
|
|
return true
|
2013-02-02 06:36:29 +00:00
|
|
|
end
|
|
|
|
|
2013-07-30 15:37:51 +00:00
|
|
|
function ReaderPaging:onGotoPage(number)
|
2016-03-27 22:39:47 +00:00
|
|
|
self:_gotoPage(number)
|
2014-03-13 13:52:43 +00:00
|
|
|
return true
|
2013-07-30 15:37:51 +00:00
|
|
|
end
|
2013-10-18 20:38:07 +00:00
|
|
|
|
2015-03-12 07:45:58 +00:00
|
|
|
function ReaderPaging:onGotoRelativePage(number)
|
2016-03-27 22:39:47 +00:00
|
|
|
self:_gotoPage(self.current_page + number)
|
2015-03-12 07:45:58 +00:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2013-12-17 14:42:25 +00:00
|
|
|
function ReaderPaging:onGotoPercentage(percentage)
|
2014-03-13 13:52:43 +00:00
|
|
|
if percentage < 0 then percentage = 0 end
|
|
|
|
if percentage > 1 then percentage = 1 end
|
2016-03-27 22:39:47 +00:00
|
|
|
self:_gotoPage(math.floor(percentage*self.number_of_pages))
|
2014-03-13 13:52:43 +00:00
|
|
|
return true
|
2013-12-17 14:42:25 +00:00
|
|
|
end
|
|
|
|
|
2019-03-01 13:54:38 +00:00
|
|
|
-- These might need additional work to behave fine in scroll
|
|
|
|
-- mode, and other zoom modes than Fit page
|
|
|
|
function ReaderPaging:onGotoNextChapter()
|
|
|
|
local pageno = self.current_page
|
|
|
|
local new_page = self.ui.toc:getNextChapter(pageno, 0)
|
|
|
|
if new_page then
|
|
|
|
self.ui.link:addCurrentLocationToStack()
|
|
|
|
self:onGotoPage(new_page)
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderPaging:onGotoPrevChapter()
|
|
|
|
local pageno = self.current_page
|
|
|
|
local new_page = self.ui.toc:getPreviousChapter(pageno, 0)
|
|
|
|
if new_page then
|
|
|
|
self.ui.link:addCurrentLocationToStack()
|
|
|
|
self:onGotoPage(new_page)
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2020-07-12 18:47:49 +00:00
|
|
|
function ReaderPaging:onToggleReflow()
|
|
|
|
self.view.document.configurable.text_wrap = bit.bxor(self.view.document.configurable.text_wrap, 1)
|
|
|
|
self.ui:handleEvent(Event:new("RedrawCurrentPage"))
|
|
|
|
self.ui:handleEvent(Event:new("RestoreZoomMode"))
|
|
|
|
self.ui:handleEvent(Event:new("InitScrollPageStates"))
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Duplicated in ReaderRolling
|
|
|
|
function ReaderPaging:onToggleReadingOrder()
|
|
|
|
self.inverse_reading_order = not self.inverse_reading_order
|
|
|
|
self:setupTouchZones()
|
|
|
|
local is_rtl = BD.mirroredUILayout()
|
|
|
|
if self.inverse_reading_order then
|
|
|
|
is_rtl = not is_rtl
|
|
|
|
end
|
|
|
|
UIManager:show(Notification:new{
|
|
|
|
text = is_rtl and _("RTL page turning.") or _("LTR page turning."),
|
|
|
|
timeout = 2.5,
|
|
|
|
})
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
return ReaderPaging
|