2012-03-09 01:44:22 +00:00
|
|
|
--[[
|
|
|
|
Copyright (C) 2011 Hans-Werner Hilse <hilse@web.de>
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
]]--
|
|
|
|
|
|
|
|
--[[
|
|
|
|
Codes for rotation modes:
|
|
|
|
|
2013-03-15 23:42:20 +00:00
|
|
|
1 for no rotation,
|
2012-03-09 01:44:22 +00:00
|
|
|
2 for landscape with bottom on the right side of screen, etc.
|
|
|
|
|
2012-03-09 10:45:55 +00:00
|
|
|
2
|
2012-03-09 01:44:22 +00:00
|
|
|
+--------------+
|
|
|
|
| +----------+ |
|
|
|
|
| | | |
|
|
|
|
| | Freedom! | |
|
2013-03-15 23:42:20 +00:00
|
|
|
| | | |
|
|
|
|
| | | |
|
2012-03-09 10:34:56 +00:00
|
|
|
3 | | | | 1
|
2012-03-09 01:44:22 +00:00
|
|
|
| | | |
|
|
|
|
| | | |
|
|
|
|
| +----------+ |
|
|
|
|
| |
|
|
|
|
| |
|
|
|
|
+--------------+
|
2012-03-09 10:45:55 +00:00
|
|
|
0
|
2012-03-09 01:44:22 +00:00
|
|
|
--]]
|
|
|
|
|
|
|
|
|
|
|
|
Screen = {
|
2013-02-02 06:36:29 +00:00
|
|
|
width = 0,
|
|
|
|
height = 0,
|
2012-04-06 05:51:37 +00:00
|
|
|
native_rotation_mode = nil,
|
2013-02-02 06:36:29 +00:00
|
|
|
cur_rotation_mode = 0,
|
2012-04-08 04:46:33 +00:00
|
|
|
|
2013-02-02 06:36:29 +00:00
|
|
|
bb = nil,
|
2012-04-08 04:46:33 +00:00
|
|
|
saved_bb = nil,
|
2012-06-10 15:36:19 +00:00
|
|
|
|
2013-02-02 06:36:29 +00:00
|
|
|
fb = einkfb.open("/dev/fb0"),
|
2012-03-09 01:44:22 +00:00
|
|
|
}
|
|
|
|
|
2013-02-02 06:36:29 +00:00
|
|
|
function Screen:init()
|
2013-02-18 07:49:53 +00:00
|
|
|
-- for unknown strange reason, pitch*2 is 10 px more than screen width in KPW
|
|
|
|
self.width, self.height = self.fb:getSize()
|
|
|
|
-- Blitbuffer still uses inverted 4bpp bitmap, so pitch should be
|
|
|
|
-- (self.width / 2)
|
|
|
|
self.bb = Blitbuffer.new(self.width, self.height, self.width/2)
|
2013-02-04 06:56:22 +00:00
|
|
|
if self.width > self.height then
|
|
|
|
-- For another unknown strange reason, self.fb:getOrientation always
|
|
|
|
-- return 0 in KPW, even though we are in landscape mode.
|
|
|
|
-- Seems like the native framework change framebuffer on the fly when
|
|
|
|
-- starting booklet. Starting KPV from ssh and KPVBooklet will get
|
|
|
|
-- different framebuffer height and width.
|
|
|
|
--
|
|
|
|
--self.native_rotation_mode = self.fb:getOrientation()
|
|
|
|
self.native_rotation_mode = 1
|
|
|
|
else
|
|
|
|
self.native_rotation_mode = 0
|
|
|
|
end
|
2013-02-02 06:36:29 +00:00
|
|
|
self.cur_rotation_mode = self.native_rotation_mode
|
|
|
|
end
|
|
|
|
|
2013-07-22 14:04:54 +00:00
|
|
|
function Screen:refresh(refesh_type, waveform_mode, x, y, w, h)
|
|
|
|
if x then x = x < 0 and 0 or math.floor(x) end
|
|
|
|
if y then y = y < 0 and 0 or math.floor(y) end
|
|
|
|
if w then w = w > self.width and self.width or math.ceil(w) end
|
|
|
|
if h then h = h > self.height and self.height or math.ceil(h) end
|
|
|
|
if self.native_rotation_mode == self.cur_rotation_mode then
|
2013-07-13 05:54:29 +00:00
|
|
|
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)
|
2013-07-22 14:04:54 +00:00
|
|
|
if x and y and w and h then
|
|
|
|
x, y = y, self.width - w - x
|
|
|
|
w, h = h, w
|
|
|
|
end
|
2013-07-13 05:54:29 +00:00
|
|
|
elseif self.native_rotation_mode == 0 and self.cur_rotation_mode == 3 then
|
|
|
|
self.fb.bb:blitFromRotate(self.bb, 90)
|
2013-07-22 14:04:54 +00:00
|
|
|
if x and y and w and h then
|
|
|
|
x, y = self.height - h - y, x
|
|
|
|
w, h = h, w
|
|
|
|
end
|
2013-07-13 05:54:29 +00:00
|
|
|
elseif self.native_rotation_mode == 1 and self.cur_rotation_mode == 0 then
|
|
|
|
self.fb.bb:blitFromRotate(self.bb, 90)
|
2013-07-22 14:04:54 +00:00
|
|
|
if x and y and w and h then
|
|
|
|
x, y = self.height - h - y, x
|
|
|
|
w, h = h, w
|
|
|
|
end
|
2013-07-13 05:54:29 +00:00
|
|
|
elseif self.native_rotation_mode == 1 and self.cur_rotation_mode == 3 then
|
|
|
|
self.fb.bb:blitFromRotate(self.bb, 180)
|
2013-07-22 14:04:54 +00:00
|
|
|
if x and y and w and h then
|
|
|
|
x, y = self.width - w - x, self.height - h - y
|
|
|
|
end
|
2013-07-13 05:54:29 +00:00
|
|
|
end
|
2013-07-22 15:38:18 +00:00
|
|
|
self.fb:refresh(refesh_type, waveform_mode, x, y, w, h)
|
2013-02-02 06:36:29 +00:00
|
|
|
end
|
|
|
|
|
2012-06-10 15:36:19 +00:00
|
|
|
function Screen:getSize()
|
2013-02-02 06:36:29 +00:00
|
|
|
return Geom:new{w = self.width, h = self.height}
|
2012-06-10 15:36:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Screen:getWidth()
|
2013-02-02 06:36:29 +00:00
|
|
|
return self.width
|
2012-06-10 15:36:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Screen:getHeight()
|
2013-02-02 06:36:29 +00:00
|
|
|
return self.height
|
2012-03-09 01:44:22 +00:00
|
|
|
end
|
|
|
|
|
2013-02-02 21:16:19 +00:00
|
|
|
function Screen:getDPI()
|
2013-07-10 07:10:38 +00:00
|
|
|
if(Device:getModel() == "KindlePaperWhite") or (Device:getModel() == "Kobo_kraken") then
|
|
|
|
return 212
|
|
|
|
elseif Device:getModel() == "Kobo_dragon" then
|
|
|
|
return 265
|
|
|
|
elseif Device:getModel() == "Kobo_pixie" then
|
|
|
|
return 200
|
|
|
|
else
|
|
|
|
return 167
|
|
|
|
end
|
2013-02-02 21:16:19 +00:00
|
|
|
end
|
|
|
|
|
2013-03-15 23:42:20 +00:00
|
|
|
function Screen:scaleByDPI(px)
|
2013-07-28 08:05:51 +00:00
|
|
|
return math.floor(px * self:getDPI()/167)
|
2013-03-15 23:42:20 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- make a shortcut to Screen:scaleByDPI
|
|
|
|
function scaleByDPI(px)
|
|
|
|
return Screen:scaleByDPI(px)
|
|
|
|
end
|
|
|
|
|
2013-01-10 03:31:03 +00:00
|
|
|
function Screen:getPitch()
|
2013-02-18 07:49:53 +00:00
|
|
|
return self.fb:getPitch()
|
2013-01-10 03:31:03 +00:00
|
|
|
end
|
|
|
|
|
2013-02-02 08:37:48 +00:00
|
|
|
function Screen:getNativeRotationMode()
|
2012-06-10 16:09:23 +00:00
|
|
|
-- in EMU mode, you will always get 0 from getOrientation()
|
2013-02-02 08:37:48 +00:00
|
|
|
return self.fb:getOrientation()
|
|
|
|
end
|
|
|
|
|
|
|
|
function Screen:getRotationMode()
|
|
|
|
return self.cur_rotation_mode
|
2012-03-09 01:44:22 +00:00
|
|
|
end
|
|
|
|
|
2013-02-03 05:10:11 +00:00
|
|
|
function Screen:getScreenMode()
|
|
|
|
if self.width > self.height then
|
|
|
|
return "landscape"
|
|
|
|
else
|
|
|
|
return "portrait"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-06-12 04:13:51 +00:00
|
|
|
function Screen:setRotationMode(mode)
|
2013-02-02 08:37:48 +00:00
|
|
|
if mode > 3 or mode < 0 then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-02-02 06:36:29 +00:00
|
|
|
-- mode 0 and mode 2 has the same width and height, so do mode 1 and 3
|
|
|
|
if (self.cur_rotation_mode % 2) ~= (mode % 2) then
|
|
|
|
self.width, self.height = self.height, self.width
|
|
|
|
end
|
|
|
|
self.cur_rotation_mode = mode
|
|
|
|
self.bb:free()
|
2013-02-18 07:49:53 +00:00
|
|
|
self.bb = Blitbuffer.new(self.width, self.height, self.width/2)
|
2013-02-02 08:37:48 +00:00
|
|
|
-- update mode for input module
|
|
|
|
Input.rotation = mode
|
2013-02-02 06:36:29 +00:00
|
|
|
end
|
|
|
|
|
2013-02-03 05:13:46 +00:00
|
|
|
function Screen:setScreenMode(mode)
|
2013-02-02 06:36:29 +00:00
|
|
|
if mode == "portrait" then
|
|
|
|
if self.cur_rotation_mode ~= 0 then
|
|
|
|
self:setRotationMode(0)
|
|
|
|
end
|
|
|
|
elseif mode == "landscape" then
|
2013-07-13 05:54:29 +00:00
|
|
|
if self.cur_rotation_mode == 0 or self.cur_rotation_mode == 2 then
|
2013-02-02 06:36:29 +00:00
|
|
|
self:setRotationMode(1)
|
2013-07-13 05:54:29 +00:00
|
|
|
elseif self.cur_rotation_mode == 1 or self.cur_rotation_mode == 3 then
|
|
|
|
self:setRotationMode((self.cur_rotation_mode + 2) % 4)
|
2013-02-02 06:36:29 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-04-08 04:46:33 +00:00
|
|
|
function Screen:saveCurrentBB()
|
2012-06-13 17:52:08 +00:00
|
|
|
local width, height = self:getWidth(), self:getHeight()
|
2012-04-09 07:42:19 +00:00
|
|
|
|
2012-04-08 04:46:33 +00:00
|
|
|
if not self.saved_bb then
|
2013-02-18 07:49:53 +00:00
|
|
|
self.saved_bb = Blitbuffer.new(width, height, self.width/2)
|
2012-04-08 04:46:33 +00:00
|
|
|
end
|
|
|
|
if self.saved_bb:getWidth() ~= width then
|
|
|
|
self.saved_bb:free()
|
2013-02-18 07:49:53 +00:00
|
|
|
self.saved_bb = Blitbuffer.new(width, height, self.width/2)
|
2012-04-08 04:46:33 +00:00
|
|
|
end
|
2013-02-02 08:37:48 +00:00
|
|
|
self.saved_bb:blitFullFrom(self.bb)
|
2012-04-08 04:46:33 +00:00
|
|
|
end
|
|
|
|
|
2012-04-14 17:28:59 +00:00
|
|
|
function Screen:restoreFromSavedBB()
|
2012-04-08 04:46:33 +00:00
|
|
|
self:restoreFromBB(self.saved_bb)
|
|
|
|
end
|
|
|
|
|
|
|
|
function Screen:getCurrentScreenBB()
|
2012-06-10 15:36:19 +00:00
|
|
|
local bb = Blitbuffer.new(self:getWidth(), self:getHeight())
|
2013-02-02 08:37:48 +00:00
|
|
|
bb:blitFullFrom(self.bb)
|
2012-04-08 04:46:33 +00:00
|
|
|
return bb
|
|
|
|
end
|
|
|
|
|
|
|
|
function Screen:restoreFromBB(bb)
|
2012-04-18 11:30:29 +00:00
|
|
|
if bb then
|
2013-02-02 08:37:48 +00:00
|
|
|
self.bb:blitFullFrom(bb)
|
2012-04-18 11:30:29 +00:00
|
|
|
else
|
2012-05-28 16:59:16 +00:00
|
|
|
DEBUG("Got nil bb in restoreFromSavedBB!")
|
2012-04-18 11:30:29 +00:00
|
|
|
end
|
2012-04-08 04:46:33 +00:00
|
|
|
end
|