mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
first demo for credocument
This commit is contained in:
50
frontend/ui/reader/readerrolling.lua
Normal file
50
frontend/ui/reader/readerrolling.lua
Normal file
@@ -0,0 +1,50 @@
|
||||
ReaderRolling = InputContainer:new{
|
||||
key_events = {
|
||||
GotoNextView = { {Input.group.PgFwd}, doc = "go to next view", event = "GotoViewRel", args = 1 },
|
||||
GotoPrevView = { {Input.group.PgBack}, doc = "go to previous view", event = "GotoViewRel", args = -1 },
|
||||
|
||||
GotoFirst = { {"1"}, doc = "go to start", event = "GotoPercent", args = 0},
|
||||
Goto11 = { {"2"}, doc = "go to 11%", event = "GotoPercent", args = 11},
|
||||
Goto22 = { {"3"}, doc = "go to 22%", event = "GotoPercent", args = 22},
|
||||
Goto33 = { {"4"}, doc = "go to 33%", event = "GotoPercent", args = 33},
|
||||
Goto44 = { {"5"}, doc = "go to 44%", event = "GotoPercent", args = 44},
|
||||
Goto55 = { {"6"}, doc = "go to 55%", event = "GotoPercent", args = 55},
|
||||
Goto66 = { {"7"}, doc = "go to 66%", event = "GotoPercent", args = 66},
|
||||
Goto77 = { {"8"}, doc = "go to 77%", event = "GotoPercent", args = 77},
|
||||
Goto88 = { {"9"}, doc = "go to 88%", event = "GotoPercent", args = 88},
|
||||
GotoLast = { {"0"}, doc = "go to end", event = "GotoPercent", args = 100},
|
||||
},
|
||||
current_pos = 0,
|
||||
length = nil,
|
||||
}
|
||||
|
||||
function ReaderRolling:init()
|
||||
self.length = self.ui.document.info.length
|
||||
end
|
||||
|
||||
function ReaderRolling:onPosUpdate(new_pos)
|
||||
self.current_pos = new_pos
|
||||
end
|
||||
|
||||
function ReaderRolling:gotoPos(new_pos)
|
||||
if new_pos == self.current_pos then return end
|
||||
if new_pos < 0 then new_pos = 0 end
|
||||
if new_pos > self.length then new_pos = self.length end
|
||||
self.ui:handleEvent(Event:new("PosUpdate", new_pos))
|
||||
end
|
||||
|
||||
function ReaderRolling:onGotoPercent(percent)
|
||||
DEBUG("goto document offset in percent:", percent)
|
||||
self:gotoPos(percent * self.length / 10000)
|
||||
return true
|
||||
end
|
||||
|
||||
function ReaderRolling:onGotoViewRel(diff)
|
||||
DEBUG("goto relative screen:", diff)
|
||||
self:gotoPos(self.current_pos + diff * self.ui.dimen.h)
|
||||
return true
|
||||
end
|
||||
|
||||
function ReaderRolling:onZoom()
|
||||
--@TODO re-read length info after font or lineheight changes 05.06 2012 (houqp)
|
||||
end
|
||||
@@ -4,6 +4,7 @@ ReaderToc = InputContainer:new{
|
||||
},
|
||||
dimen = Geom:new{ w = G_width-20, h = G_height-20},
|
||||
current_page = 0,
|
||||
current_pos = 0,
|
||||
}
|
||||
|
||||
function ReaderToc:cleanUpTocTitle(title)
|
||||
@@ -74,4 +75,8 @@ function ReaderToc:onPageUpdate(new_page_no)
|
||||
self.current_page = new_page_no
|
||||
end
|
||||
|
||||
function ReaderToc:onPosUpdate(new_pos)
|
||||
self.current_pos = new_pos
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ ReaderView = WidgetContainer:new{
|
||||
|
||||
state = {
|
||||
page = 0,
|
||||
pos = 0,
|
||||
zoom = 1.0,
|
||||
rotation = 0,
|
||||
offset = {},
|
||||
@@ -32,25 +33,38 @@ function ReaderView:paintTo(bb, x, y)
|
||||
end
|
||||
|
||||
-- draw content
|
||||
self.ui.document:drawPage(
|
||||
bb,
|
||||
x + inner_offset.x,
|
||||
y + inner_offset.y,
|
||||
self.visible_area,
|
||||
self.state.page,
|
||||
self.state.zoom,
|
||||
self.state.rotation)
|
||||
if self.ui.document.info.has_pages then
|
||||
self.ui.document:drawPage(
|
||||
bb,
|
||||
x + inner_offset.x,
|
||||
y + inner_offset.y,
|
||||
self.visible_area,
|
||||
self.state.page,
|
||||
self.state.zoom,
|
||||
self.state.rotation)
|
||||
else
|
||||
self.ui.document:drawCurrentView(
|
||||
bb,
|
||||
x + inner_offset.x,
|
||||
y + inner_offset.y,
|
||||
self.visible_area,
|
||||
self.state.pos)
|
||||
end
|
||||
end
|
||||
|
||||
function ReaderView:recalculate()
|
||||
local page_size = self.ui.document:getPageDimensions(self.state.page, self.state.zoom, self.state.rotation)
|
||||
-- TODO: bbox
|
||||
self.page_area = page_size
|
||||
if self.ui.document.info.has_pages then
|
||||
local page_size = self.ui.document:getPageDimensions(self.state.page, self.state.zoom, self.state.rotation)
|
||||
-- TODO: bbox
|
||||
self.page_area = page_size
|
||||
|
||||
-- reset our size
|
||||
self.visible_area:setSizeTo(self.ui.dimen)
|
||||
-- and recalculate it according to page size
|
||||
self.visible_area:offsetWithin(self.page_area, 0, 0)
|
||||
-- reset our size
|
||||
self.visible_area:setSizeTo(self.ui.dimen)
|
||||
-- and recalculate it according to page size
|
||||
self.visible_area:offsetWithin(self.page_area, 0, 0)
|
||||
else
|
||||
self.visible_area:setSizeTo(self.ui.dimen)
|
||||
end
|
||||
-- flag a repaint
|
||||
UIManager:setDirty(self.dialog)
|
||||
end
|
||||
@@ -78,6 +92,11 @@ function ReaderView:onPageUpdate(new_page_no)
|
||||
self:recalculate()
|
||||
end
|
||||
|
||||
function ReaderView:onPosUpdate(new_pos)
|
||||
self.state.pos = new_pos
|
||||
self:recalculate()
|
||||
end
|
||||
|
||||
function ReaderView:ZoomUpdate(zoom)
|
||||
self.state.zoom = zoom
|
||||
self:recalculate()
|
||||
|
||||
Reference in New Issue
Block a user