mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
ImageViewer: menu to invert rotations and set auto rotation (#11206)
Add some menu items under Screen>Rotation to allow inverting the default rotation of ImageViewer, and to auto-rotate for best fit on launch, so landscape images are auto-rotated to the preferred rotation.
This commit is contained in:
@@ -36,10 +36,6 @@ DCREREADER_VIEW_MODE = "page",
|
||||
-- default to false
|
||||
DSHOWOVERLAP = false,
|
||||
|
||||
-- landscape clockwise rotation
|
||||
-- default to true, set to false for counterclockwise rotation
|
||||
DLANDSCAPE_CLOCKWISE_ROTATION = true,
|
||||
|
||||
-- default minimum screen height for reading with 2 pages in landscape mode
|
||||
DCREREADER_TWO_PAGE_THRESHOLD = 7,
|
||||
|
||||
|
||||
@@ -85,6 +85,41 @@ When unchecked, the default rotation of the file browser and the default/saved r
|
||||
table.insert(rotation_table, genMenuItem(C_("Rotation", "↓ 180°"), Screen.DEVICE_ROTATED_UPSIDE_DOWN))
|
||||
end
|
||||
|
||||
rotation_table[#rotation_table].separator = true
|
||||
table.insert(rotation_table, {
|
||||
text = _("Image viewer rotation"),
|
||||
sub_item_table = {
|
||||
{
|
||||
text = _("Invert default rotation in portrait mode"),
|
||||
checked_func = function()
|
||||
return G_reader_settings:isTrue("imageviewer_rotation_portrait_invert")
|
||||
end,
|
||||
callback = function()
|
||||
G_reader_settings:flipNilOrFalse("imageviewer_rotation_portrait_invert")
|
||||
end,
|
||||
},
|
||||
{
|
||||
text = _("Invert default rotation in landscape mode"),
|
||||
checked_func = function()
|
||||
return G_reader_settings:isTrue("imageviewer_rotation_landscape_invert")
|
||||
end,
|
||||
callback = function()
|
||||
G_reader_settings:flipNilOrFalse("imageviewer_rotation_landscape_invert")
|
||||
end,
|
||||
separator = true,
|
||||
},
|
||||
{
|
||||
text = _("Auto-rotate for best fit"),
|
||||
help_text = _("Auto-rotate the image to best match screen and image aspect ratios on image viewer launch (ie. if in portrait mode, a landscape image will be rotated).");
|
||||
checked_func = function()
|
||||
return G_reader_settings:isTrue("imageviewer_rotate_auto_for_best_fit")
|
||||
end,
|
||||
callback = function()
|
||||
G_reader_settings:flipTrue("imageviewer_rotate_auto_for_best_fit")
|
||||
end,
|
||||
}
|
||||
}
|
||||
})
|
||||
return rotation_table
|
||||
end,
|
||||
}
|
||||
|
||||
@@ -156,6 +156,10 @@ function ImageViewer:init()
|
||||
self.image = self._scaled_image_func(1) -- native image size, that we need to know
|
||||
end
|
||||
|
||||
if G_reader_settings:isTrue("imageviewer_rotate_auto_for_best_fit") then
|
||||
self.rotated = (Screen:getWidth() > Screen:getHeight()) ~= (self.image:getWidth() > self.image:getHeight())
|
||||
end
|
||||
|
||||
-- Widget layout
|
||||
if self._scale_to_fit == nil then -- initialize our toggle
|
||||
self._scale_to_fit = self.scale_factor == 0
|
||||
@@ -398,16 +402,24 @@ function ImageViewer:_new_image_wg()
|
||||
|
||||
local rotation_angle = 0
|
||||
if self.rotated then
|
||||
-- in portrait mode, rotate according to this global setting so we are
|
||||
-- like in landscape mode
|
||||
-- NOTE: This is the sole user of this legacy global left!
|
||||
local rotate_clockwise = G_defaults:readSetting("DLANDSCAPE_CLOCKWISE_ROTATION")
|
||||
if Screen:getWidth() > Screen:getHeight() then
|
||||
-- in landscape mode, counter-rotate landscape rotation so we are
|
||||
-- back like in portrait mode
|
||||
rotate_clockwise = not rotate_clockwise
|
||||
local rotate_clockwise
|
||||
if Screen:getWidth() <= Screen:getHeight() then
|
||||
-- In portraite mode, the default is to rotate the image counterclockwise, so devices
|
||||
-- with hardware buttons on their thick right side get to be rotated clockwise
|
||||
-- with that thicker side at the bottom in the hand of the user.
|
||||
rotate_clockwise = false
|
||||
if G_reader_settings:isTrue("imageviewer_rotation_portrait_invert") then
|
||||
rotate_clockwise = true
|
||||
end
|
||||
else
|
||||
-- In landscape mode, the default is to rotate the image clockwise, so such devices
|
||||
-- (see above) get back to their original orientation with their thick side on the right.
|
||||
rotate_clockwise = true
|
||||
if G_reader_settings:isTrue("imageviewer_rotation_landscape_invert") then
|
||||
rotate_clockwise = false
|
||||
end
|
||||
end
|
||||
rotation_angle = rotate_clockwise and 90 or 270
|
||||
rotation_angle = rotate_clockwise and 270 or 90 -- (unintuitive, but this does it)
|
||||
end
|
||||
|
||||
if self._scaled_image_func then
|
||||
|
||||
Reference in New Issue
Block a user