mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Merge pull request #399 from chrox/master
customizable tap zones for page flipping and bookmarking
This commit is contained in:
@@ -43,9 +43,12 @@ DSHOWHIDDENFILES = false
|
||||
-- y: y coordinate of top left corner in proportion of screen height
|
||||
-- w: width of tap zone in proportion of screen width
|
||||
-- h: height of tap zone in proportion of screen height
|
||||
DTAP_ZONE_MENU = {x = 1/8, y = 0, w = 3/4, h = 1/4}
|
||||
DTAP_ZONE_CONFIG = {x = 0, y = 11/12, w = 1, h = 1/12}
|
||||
DTAP_ZONE_FORWARD = {x = 1/4, y = 0, w = 3/4, h = 1}
|
||||
DTAP_ZONE_BACKWARD = {x = 0, y = 0, w = 1/4, h = 1}
|
||||
DTAP_ZONE_CONFIG = {x = 0, y = 11/12, w = 1, h = 1/12}
|
||||
DTAP_ZONE_BOOKMARK = {x = 7/8, y = 0, w = 1/8, h = 1/8}
|
||||
DTAP_ZONE_FLIPPING = {x = 0, y = 0, w = 1/8, h = 1/8}
|
||||
|
||||
-- koptreader config defaults
|
||||
DKOPTREADER_CONFIG_FONT_SIZE = 1.0 -- range from 0.1 to 3.0
|
||||
|
||||
@@ -25,21 +25,6 @@ function ReaderBookmark:init()
|
||||
self.ui.menu:registerToMainMenu(self)
|
||||
end
|
||||
|
||||
function ReaderBookmark:initGesListener()
|
||||
self.ges_events = {
|
||||
ToggleBookmark = {
|
||||
GestureRange:new{
|
||||
ges = "tap",
|
||||
range = Geom:new{
|
||||
x = Screen:getWidth()*7/8, y = 0,
|
||||
w = Screen:getWidth()/8,
|
||||
h = Screen:getHeight()/8
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
function ReaderBookmark:onReadSettings(config)
|
||||
self.bookmarks = config:readSetting("bookmarks") or {}
|
||||
end
|
||||
@@ -48,13 +33,6 @@ function ReaderBookmark:onCloseDocument()
|
||||
self.ui.doc_settings:saveSetting("bookmarks", self.bookmarks)
|
||||
end
|
||||
|
||||
function ReaderBookmark:onSetDimensions(dimen)
|
||||
-- update listening according to new screen dimen
|
||||
if Device:isTouchDevice() then
|
||||
self:initGesListener()
|
||||
end
|
||||
end
|
||||
|
||||
function ReaderBookmark:onToggleBookmark()
|
||||
local pn_or_xp = nil
|
||||
if self.ui.document.getXPointer then
|
||||
@@ -65,6 +43,7 @@ function ReaderBookmark:onToggleBookmark()
|
||||
self:toggleBookmark(pn_or_xp)
|
||||
self.view.dogear_visible = not self.view.dogear_visible
|
||||
UIManager:setDirty(self.view.dialog, "partial")
|
||||
return true
|
||||
end
|
||||
|
||||
function ReaderBookmark:setDogearVisibility(pn_or_xp)
|
||||
|
||||
@@ -1,17 +1,42 @@
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local RightContainer = require("ui/widget/container/rightcontainer")
|
||||
local ImageWidget = require("ui/widget/imagewidget")
|
||||
local GestureRange = require("ui/gesturerange")
|
||||
local Device = require("ui/device")
|
||||
local Geom = require("ui/geometry")
|
||||
local Screen = require("ui/screen")
|
||||
local Event = require("ui/event")
|
||||
|
||||
local ReaderDogear = RightContainer:new{}
|
||||
local ReaderDogear = InputContainer:new{}
|
||||
|
||||
function ReaderDogear:init()
|
||||
local widget = ImageWidget:new{
|
||||
file = "resources/icons/dogear.png",
|
||||
}
|
||||
local icon_size = widget:getSize()
|
||||
self.dimen = Geom:new{w = Screen:getWidth(), h = icon_size.h}
|
||||
self[1] = widget
|
||||
self[1] = RightContainer:new{
|
||||
dimen = Geom:new{w = Screen:getWidth(), h = widget:getSize().h},
|
||||
widget,
|
||||
}
|
||||
if Device:isTouchDevice() then
|
||||
self.ges_events = {
|
||||
Tap = {
|
||||
GestureRange:new{
|
||||
ges = "tap",
|
||||
range = Geom:new{
|
||||
x = Screen:getWidth()*DTAP_ZONE_BOOKMARK.x,
|
||||
y = Screen:getHeight()*DTAP_ZONE_BOOKMARK.y,
|
||||
w = Screen:getWidth()*DTAP_ZONE_BOOKMARK.w,
|
||||
h = Screen:getHeight()*DTAP_ZONE_BOOKMARK.h
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
function ReaderDogear:onTap()
|
||||
self.ui:handleEvent(Event:new("ToggleBookmark"))
|
||||
return true
|
||||
end
|
||||
|
||||
function ReaderDogear:onSetDogearVisibility(visible)
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local LeftContainer = require("ui/widget/container/leftcontainer")
|
||||
local ImageWidget = require("ui/widget/imagewidget")
|
||||
local GestureRange = require("ui/gesturerange")
|
||||
local Device = require("ui/device")
|
||||
local Geom = require("ui/geometry")
|
||||
local Screen = require("ui/screen")
|
||||
local Event = require("ui/event")
|
||||
|
||||
local ReaderFlipping = LeftContainer:new{
|
||||
local ReaderFlipping = InputContainer:new{
|
||||
orig_reflow_mode = 0,
|
||||
}
|
||||
|
||||
@@ -11,21 +15,29 @@ function ReaderFlipping:init()
|
||||
local widget = ImageWidget:new{
|
||||
file = "resources/icons/appbar.book.open.png",
|
||||
}
|
||||
local icon_size = widget:getSize()
|
||||
self.dimen = Geom:new{w = Screen:getWidth(), h = icon_size.h}
|
||||
self[1] = widget
|
||||
self[1] = LeftContainer:new{
|
||||
dimen = Geom:new{w = Screen:getWidth(), h = widget:getSize().h},
|
||||
widget,
|
||||
}
|
||||
if Device:isTouchDevice() then
|
||||
self.ges_events = {
|
||||
Tap = {
|
||||
GestureRange:new{
|
||||
ges = "tap",
|
||||
range = Geom:new{
|
||||
x = Screen:getWidth()*DTAP_ZONE_FLIPPING.x,
|
||||
y = Screen:getHeight()*DTAP_ZONE_FLIPPING.y,
|
||||
w = Screen:getWidth()*DTAP_ZONE_FLIPPING.w,
|
||||
h = Screen:getHeight()*DTAP_ZONE_FLIPPING.h
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
function ReaderFlipping:onSetFlippingMode(flipping_mode)
|
||||
if flipping_mode then
|
||||
self.orig_reflow_mode = self.view.document.configurable.text_wrap
|
||||
self.orig_scroll_mode = self.view.page_scroll
|
||||
self.view.document.configurable.text_wrap = 0
|
||||
self.view.page_scroll = false
|
||||
else
|
||||
self.view.document.configurable.text_wrap = self.orig_reflow_mode
|
||||
self.view.page_scroll = self.orig_scroll_mode
|
||||
end
|
||||
function ReaderFlipping:onTap()
|
||||
self.ui:handleEvent(Event:new("ToggleFlipping"))
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ local UIManager = require("ui/uimanager")
|
||||
local Device = require("ui/device")
|
||||
local Screen = require("ui/screen")
|
||||
local Geom = require("ui/geometry")
|
||||
local Event = require("ui/event")
|
||||
local Font = require("ui/font")
|
||||
local DEBUG = require("dbg")
|
||||
|
||||
@@ -21,8 +22,8 @@ local ReaderFooter = InputContainer:new{
|
||||
progress_percentage = 0.0,
|
||||
progress_text = "0 / 0",
|
||||
show_time = false,
|
||||
bar_width = 0.88,
|
||||
text_width = 0.12,
|
||||
bar_width = 0.85,
|
||||
text_width = 0.15,
|
||||
text_font_face = "ffont",
|
||||
text_font_size = 14,
|
||||
height = 19,
|
||||
@@ -90,10 +91,17 @@ function ReaderFooter:onPageUpdate(pageno)
|
||||
self:updateFooter()
|
||||
end
|
||||
|
||||
function ReaderFooter:onTapFooter(arg, gev)
|
||||
self.show_time = not self.show_time
|
||||
function ReaderFooter:onTapFooter(arg, ges)
|
||||
if self.view.flipping_visible then
|
||||
local pos = ges.pos
|
||||
local dimen = self.progress_bar.dimen
|
||||
local percentage = (pos.x - dimen.x)/dimen.w
|
||||
self.ui:handleEvent(Event:new("GotoPercentage", percentage))
|
||||
else
|
||||
self.show_time = not self.show_time
|
||||
end
|
||||
self:updateFooter()
|
||||
UIManager:setDirty(self.view.dialog)
|
||||
UIManager:setDirty(self.view.dialog, "partial")
|
||||
-- consume this tap when footer is visible
|
||||
if self.visible then
|
||||
return true
|
||||
|
||||
@@ -52,10 +52,10 @@ function ReaderMenu:initGesListener()
|
||||
GestureRange:new{
|
||||
ges = "tap",
|
||||
range = Geom:new{
|
||||
x = Screen:getWidth()/8,
|
||||
y = 0,
|
||||
w = Screen:getWidth()*3/4,
|
||||
h = Screen:getHeight()/4,
|
||||
x = Screen:getWidth()*DTAP_ZONE_MENU.x,
|
||||
y = Screen:getHeight()*DTAP_ZONE_MENU.y,
|
||||
w = Screen:getWidth()*DTAP_ZONE_MENU.w,
|
||||
h = Screen:getHeight()*DTAP_ZONE_MENU.h
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -80,16 +80,6 @@ function ReaderPaging:initGesListener()
|
||||
}
|
||||
}
|
||||
},
|
||||
ToggleFlipping = {
|
||||
GestureRange:new{
|
||||
ges = "tap",
|
||||
range = Geom:new{
|
||||
x = 0, y = 0,
|
||||
w = Screen:getWidth()/8,
|
||||
h = Screen:getHeight()/8
|
||||
}
|
||||
}
|
||||
},
|
||||
Swipe = {
|
||||
GestureRange:new{
|
||||
ges = "swipe",
|
||||
@@ -186,17 +176,37 @@ function ReaderPaging:onToggleFlipping()
|
||||
self.view.flipping_visible = not self.view.flipping_visible
|
||||
self.flipping_mode = self.view.flipping_visible
|
||||
self.flipping_page = self.current_page
|
||||
|
||||
if self.flipping_mode then
|
||||
self:updateOriginalPage(self.current_page)
|
||||
self:enterFlippingMode()
|
||||
else
|
||||
self:updateOriginalPage(nil)
|
||||
self:exitFlippingMode()
|
||||
end
|
||||
self.view:resetLayout()
|
||||
self.ui:handleEvent(Event:new("SetFlippingMode", self.flipping_mode))
|
||||
self.ui:handleEvent(Event:new("SetHinting", not self.flipping_mode))
|
||||
self.ui:handleEvent(Event:new("ReZoom"))
|
||||
UIManager:setDirty(self.view.dialog, "partial")
|
||||
end
|
||||
|
||||
function ReaderPaging:enterFlippingMode()
|
||||
self.orig_reflow_mode = self.view.document.configurable.text_wrap
|
||||
self.orig_footer_mode = self.view.footer_visible
|
||||
self.orig_scroll_mode = self.view.page_scroll
|
||||
|
||||
self.view.document.configurable.text_wrap = 0
|
||||
self.view.page_scroll = false
|
||||
self.view.footer_visible = true
|
||||
end
|
||||
|
||||
function ReaderPaging:exitFlippingMode()
|
||||
self.view.document.configurable.text_wrap = self.orig_reflow_mode
|
||||
self.view.page_scroll = self.orig_scroll_mode
|
||||
self.view.footer_visible = self.orig_footer_mode
|
||||
end
|
||||
|
||||
function ReaderPaging:updateOriginalPage(page)
|
||||
self.original_page = page
|
||||
end
|
||||
@@ -685,4 +695,11 @@ function ReaderPaging:onGotoPage(number)
|
||||
return true
|
||||
end
|
||||
|
||||
function ReaderPaging:onGotoPercentage(percentage)
|
||||
if percentage < 0 then percentage = 0 end
|
||||
if percentage > 1 then percentage = 1 end
|
||||
self:gotoPage(math.floor(percentage*self.number_of_pages))
|
||||
return true
|
||||
end
|
||||
|
||||
return ReaderPaging
|
||||
|
||||
@@ -68,13 +68,16 @@ end
|
||||
function ReaderView:resetLayout()
|
||||
self.dogear = ReaderDogear:new{
|
||||
view = self,
|
||||
ui = self.ui,
|
||||
}
|
||||
self.footer = ReaderFooter:new{
|
||||
view = self,
|
||||
ui = self.ui,
|
||||
visible = self.footer_visible,
|
||||
}
|
||||
self.flipping = ReaderFlipping:new{
|
||||
view = self,
|
||||
ui = self.ui,
|
||||
}
|
||||
self[1] = self.dogear
|
||||
self[2] = self.footer
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
local Widget = require("ui/widget/widget")
|
||||
local Geom = require("ui/geometry")
|
||||
|
||||
--[[
|
||||
ProgressWidget shows a progress bar
|
||||
@@ -22,6 +23,11 @@ end
|
||||
|
||||
function ProgressWidget:paintTo(bb, x, y)
|
||||
local my_size = self:getSize()
|
||||
self.dimen = Geom:new{
|
||||
x = x, y = y,
|
||||
w = my_size.w,
|
||||
h = my_size.h
|
||||
}
|
||||
bb:paintRoundedRect(x, y, my_size.w, my_size.h, self.bgcolor, self.radius)
|
||||
bb:paintBorder(x, y, my_size.w, my_size.h,
|
||||
self.bordersize, self.bordercolor, self.radius)
|
||||
|
||||
Reference in New Issue
Block a user