From 3dbf9877bc68268e7969e3f81f0b3108b87bda29 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Thu, 8 Mar 2012 23:28:16 +0800 Subject: [PATCH] add: 90 degree rotation support demo for issue #51 --- filechooser.lua | 18 +++++++++++++----- filesearcher.lua | 12 ++++++++++++ keys.lua | 34 ++++++++++++++++++++-------------- reader.lua | 12 ++++++++---- unireader.lua | 34 ++++++++++++++++++++++++++++++++-- 5 files changed, 85 insertions(+), 25 deletions(-) diff --git a/filechooser.lua b/filechooser.lua index c70b12613..865a0147f 100644 --- a/filechooser.lua +++ b/filechooser.lua @@ -200,11 +200,19 @@ function FileChooser:choose(ypos, height) pagedirty = true elseif ev.code == KEY_S then -- invoke search input keywords = InputBox:input(height-100, 100, "Search:") - if keywords then -- display search result according to keywords - FileSearcher:init( self.path ) - file = FileSearcher:choose(ypos, height, keywords) - if file then - return file + if keywords then + -- call FileSearcher + --[[ + This might looks a little bit dirty for using callback. + But I cannot come up with a better solution for renewing + the height arguemtn according to screen rotation mode. + + The callback might also be useful for calling system + settings menu in the future. + --]] + return nil, function() + FileSearcher:init( self.path ) + FileSearcher:choose(ypos, height, keywords) end end pagedirty = true diff --git a/filesearcher.lua b/filesearcher.lua index 814865d51..667f787f9 100644 --- a/filesearcher.lua +++ b/filesearcher.lua @@ -262,8 +262,20 @@ function FileSearcher:choose(ypos, height, keywords) elseif ev.code == KEY_ENTER or ev.code == KEY_FW_PRESS then file_entry = self.result[perpage*(self.page-1)+self.current] file_full_path = file_entry.dir .. "/" .. file_entry.name + + -- rotation mode might be changed while reading, so + -- record height_percent here + local height_percent = height/fb.bb:getHeight() openFile(file_full_path) + --reset height and item index if screen has been rotated + local old_perpage = perpage + height = math.floor(fb.bb:getHeight()*height_percent) + perpage = math.floor(height / self.spacing) - 2 + self.current = (old_perpage * (self.page - 1) + + self.current) % perpage + self.page = math.floor(self.items / perpage) + 1 + pagedirty = true elseif ev.code == KEY_BACK or ev.code == KEY_HOME then return nil diff --git a/keys.lua b/keys.lua index a04c72e33..f7c6fe25a 100644 --- a/keys.lua +++ b/keys.lua @@ -178,26 +178,32 @@ function set_emu_keycodes() KEY_VMINUS = 96 -- F12 end +--@TODO rotation does not fit in key module, we should move it +-- to some other module in the future. 08.03 2012 +rotation_mode = {"Up","Right","Down","Left"} + function getRotationMode() --[[ return code for four kinds of rotation mode: - 0 for no rotation, + 0 for no rotation, 1 for landscape with bottom on the right side of screen, etc. - 2 - +-----------+ - | +-------+ | - | | | | - | | | | - | | | | - 3 | | | | 1 - | | | | - | | | | - | +-------+ | - | | - +-----------+ - 0 + 2 + +--------------+ + | +----------+ | + | | | | + | | Freedom! | | + | | | | + | | | | + 3 | | | | 1 + | | | | + | | | | + | +----------+ | + | | + | | + +--------------+ + 0 --]] if KEY_FW_DOWN == 116 then -- in EMU mode always return 0 return 0 diff --git a/reader.lua b/reader.lua index da64c633c..9d07f9d92 100755 --- a/reader.lua +++ b/reader.lua @@ -131,11 +131,15 @@ if ARGV[optind] and lfs.attributes(ARGV[optind], "mode") == "directory" then local running = true FileChooser:setPath(ARGV[optind]) while running do - local file = FileChooser:choose(0,height) - if file ~= nil then - running = openFile(file) + local file, callback = FileChooser:choose(0,height) + if callback then + callback() else - running = false + if file ~= nil then + running = openFile(file) + else + running = false + end end end elseif ARGV[optind] and lfs.attributes(ARGV[optind], "mode") == "file" then diff --git a/unireader.lua b/unireader.lua index c14f3e134..ef6adeffa 100644 --- a/unireader.lua +++ b/unireader.lua @@ -526,6 +526,28 @@ function UniReader:setrotate(rotate) self:goto(self.pageno) end +-- @ orien: 1 for clockwise rotate, -1 for anti-clockwise +function UniReader:screenRotate(orien) + if orien == "clockwise" then + orien = 1 + elseif orien == "anticlockwise" then + orien = -1 + else + return + end + + fb:close() + local mode = rotation_mode[(getRotationMode()+1*orien)%4 + 1] + os.execute("lipc-send-event -r 3 com.lab126.hal orientation"..mode) + fb = einkfb.open("/dev/fb0") + width, height = fb:getSize() + + self:clearcache() + --@TODO write a sleep in util module to replace it 08.03 2012 + os.execute("sleep 2") + self:goto(self.pageno) +end + function UniReader:cleanUpTOCTitle(title) return title:gsub("\13", "") end @@ -688,9 +710,17 @@ function UniReader:inputloop() self:showJumpStack() end elseif ev.code == KEY_J then - self:setrotate( self.globalrotate + 10 ) + if Keys.shiftmode then + self:screenRotate("anticlockwise") + else + self:setrotate( self.globalrotate + 10 ) + end elseif ev.code == KEY_K then - self:setrotate( self.globalrotate - 10 ) + if Keys.shiftmode then + self:screenRotate("clockwise") + else + self:setrotate( self.globalrotate - 10 ) + end elseif ev.code == KEY_HOME then if Keys.shiftmode or Keys.altmode then -- signal quit