From cee6f6a616516cf1553e6729a87b110bc0a53aa1 Mon Sep 17 00:00:00 2001 From: chrox Date: Sat, 13 Jul 2013 13:52:30 +0800 Subject: [PATCH 1/5] fix typo in readerrotation.lua --- frontend/ui/reader/readerrotation.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend/ui/reader/readerrotation.lua b/frontend/ui/reader/readerrotation.lua index 25881a58d..8f700b99a 100644 --- a/frontend/ui/reader/readerrotation.lua +++ b/frontend/ui/reader/readerrotation.lua @@ -52,17 +52,17 @@ function ReaderRotation:onRotate(rotate_by) end function ReaderRotation:onRotateGes(arg, ges) - self.ratate_angle = ges.angle + self.rotate_angle = ges.angle return true end function ReaderRotation:onTwoFingerPanRelease(arg, ges) - if self.ratate_angle and self.ratate_angle > self.ROTATE_ANGLE_THRESHOLD then + if self.rotate_angle and self.rotate_angle > self.ROTATE_ANGLE_THRESHOLD then if Screen:getScreenMode() == "portrait" then self.ui:handleEvent(Event:new("SetScreenMode", "landscape")) else self.ui:handleEvent(Event:new("SetScreenMode", "portrait")) end - self.ratate_angle = nil + self.rotate_angle = nil end end From 703e9da698b68cb09ab225e377679ebdc5ad0a6c Mon Sep 17 00:00:00 2001 From: chrox Date: Sat, 13 Jul 2013 13:54:29 +0800 Subject: [PATCH 2/5] add 90 degrees of landscape mode --- frontend/ui/screen.lua | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/frontend/ui/screen.lua b/frontend/ui/screen.lua index 80ffeaee3..819efd584 100644 --- a/frontend/ui/screen.lua +++ b/frontend/ui/screen.lua @@ -74,12 +74,16 @@ end function Screen:refresh(refesh_type) if self.native_rotation_mode == self.cur_rotation_mode then - self.fb.bb:blitFrom(self.bb, 0, 0, 0, 0, self.width, self.height) - elseif self.native_rotation_mode == 0 and self.cur_rotation_mode == 1 then - self.fb.bb:blitFromRotate(self.bb, 270) - elseif self.native_rotation_mode == 1 and self.cur_rotation_mode == 0 then - self.fb.bb:blitFromRotate(self.bb, 90) - end + self.fb.bb:blitFrom(self.bb, 0, 0, 0, 0, self.width, self.height) + elseif self.native_rotation_mode == 0 and self.cur_rotation_mode == 1 then + self.fb.bb:blitFromRotate(self.bb, 270) + elseif self.native_rotation_mode == 0 and self.cur_rotation_mode == 3 then + self.fb.bb:blitFromRotate(self.bb, 90) + elseif self.native_rotation_mode == 1 and self.cur_rotation_mode == 0 then + self.fb.bb:blitFromRotate(self.bb, 90) + elseif self.native_rotation_mode == 1 and self.cur_rotation_mode == 3 then + self.fb.bb:blitFromRotate(self.bb, 180) + end self.fb:refresh(refesh_type) end @@ -159,8 +163,10 @@ function Screen:setScreenMode(mode) self:setRotationMode(0) end elseif mode == "landscape" then - if self.cur_rotation_mode ~= 1 then + if self.cur_rotation_mode == 0 or self.cur_rotation_mode == 2 then self:setRotationMode(1) + elseif self.cur_rotation_mode == 1 or self.cur_rotation_mode == 3 then + self:setRotationMode((self.cur_rotation_mode + 2) % 4) end end end From 7f1d682a98e4a44270fdcf5725a26ddac7685993 Mon Sep 17 00:00:00 2001 From: chrox Date: Sat, 13 Jul 2013 13:55:21 +0800 Subject: [PATCH 3/5] adapt gesture detector for 90 degrees rotation --- frontend/ui/gesturedetector.lua | 36 ++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/frontend/ui/gesturedetector.lua b/frontend/ui/gesturedetector.lua index 02af6557d..2b6ae0f10 100644 --- a/frontend/ui/gesturedetector.lua +++ b/frontend/ui/gesturedetector.lua @@ -609,7 +609,7 @@ end --]] function GestureDetector:adjustGesCoordinate(ges) if Screen.cur_rotation_mode == 1 then - -- in landscape mode + -- in landscape mode rotated 270 if ges.pos then ges.pos.x, ges.pos.y = (Screen.width - ges.pos.y), (ges.pos.x) end @@ -642,6 +642,40 @@ function GestureDetector:adjustGesCoordinate(ges) ges.direction = "horizontal" end end + elseif Screen.cur_rotation_mode == 3 then + -- in landscape mode rotated 90 + if ges.pos then + ges.pos.x, ges.pos.y = (ges.pos.y), (Screen.height - ges.pos.x) + end + if ges.ges == "swipe" or ges.ges == "pan" + or ges.ges == "two_finger_swipe" + or ges.ges == "two_finger_pan" then + if ges.direction == "north" then + ges.direction = "west" + elseif ges.direction == "south" then + ges.direction = "east" + elseif ges.direction == "east" then + ges.direction = "north" + elseif ges.direction == "west" then + ges.direction = "south" + elseif ges.direction == "northeast" then + ges.direction = "northwest" + elseif ges.direction == "northwest" then + ges.direction = "southeast" + elseif ges.direction == "southeast" then + ges.direction = "northeast" + elseif ges.direction == "southwest" then + ges.direction = "southeast" + end + elseif ges.ges == "pinch" or ges.ges == "spread" + or ges.ges == "inward_pan" + or ges.ges == "outward_pan" then + if ges.direction == "horizontal" then + ges.direction = "vertical" + elseif ges.direction == "vertical" then + ges.direction = "horizontal" + end + end end return ges end From c19de743badf714a80398a22b47c53121916ed90 Mon Sep 17 00:00:00 2001 From: chrox Date: Sat, 13 Jul 2013 13:56:25 +0800 Subject: [PATCH 4/5] toggle landscape will change orientation for landscape mode --- frontend/ui/data/koptoptions.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/ui/data/koptoptions.lua b/frontend/ui/data/koptoptions.lua index 7e723000c..5cca03d70 100644 --- a/frontend/ui/data/koptoptions.lua +++ b/frontend/ui/data/koptoptions.lua @@ -10,6 +10,7 @@ KoptOptions = { name = "screen_mode", name_text = SCREEN_MODE_STR, toggle = {PORTRAIT_STR, LANDSCAPE_STR}, + alternate = false, args = {"portrait", "landscape"}, default_arg = "portrait", current_func = function() return Screen:getScreenMode() end, From 52c4ada11145406ad8f9d828d1a92ef42c4c273d Mon Sep 17 00:00:00 2001 From: chrox Date: Sat, 13 Jul 2013 13:57:02 +0800 Subject: [PATCH 5/5] save rotation mode in doc settings --- frontend/ui/reader/readerview.lua | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/frontend/ui/reader/readerview.lua b/frontend/ui/reader/readerview.lua index ecc6512e4..1967790a0 100644 --- a/frontend/ui/reader/readerview.lua +++ b/frontend/ui/reader/readerview.lua @@ -415,12 +415,17 @@ function ReaderView:PanningUpdate(dx, dy) return true end -function ReaderView:onSetScreenMode(new_mode) +function ReaderView:onSetScreenMode(new_mode, rotation) if new_mode == "landscape" or new_mode == "portrait" then self.screen_mode = new_mode - Screen:setScreenMode(new_mode) + if rotation ~= nil then + Screen:setRotationMode(rotation) + else + Screen:setScreenMode(new_mode) + end self.ui:handleEvent(Event:new("SetDimensions", Screen:getSize())) end + self.cur_rotation_mode = Screen.cur_rotation_mode if new_mode == "landscape" and self.document.info.has_pages then self.ui:handleEvent(Event:new("SetZoomMode", "contentwidth")) @@ -473,7 +478,8 @@ function ReaderView:onReadSettings(config) local screen_mode = config:readSetting("screen_mode") if screen_mode then table.insert(self.ui.postInitCallback, function() - self:onSetScreenMode(screen_mode) end) + self:onSetScreenMode(screen_mode, config:readSetting("rotation_mode")) + end) end self.state.gamma = config:readSetting("gamma") or DGLOBALGAMMA local full_screen = config:readSetting("kopt_full_screen") @@ -556,6 +562,7 @@ end function ReaderView:onCloseDocument() self.ui.doc_settings:saveSetting("render_mode", self.render_mode) self.ui.doc_settings:saveSetting("screen_mode", self.screen_mode) + self.ui.doc_settings:saveSetting("rotation_mode", self.cur_rotation_mode) self.ui.doc_settings:saveSetting("gamma", self.state.gamma) self.ui.doc_settings:saveSetting("highlight", self.highlight.saved) end