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:
|
|
|
|
|
|
|
|
1 for no rotation,
|
|
|
|
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! | |
|
|
|
|
| | | |
|
|
|
|
| | | |
|
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 = {
|
2012-03-09 10:34:56 +00:00
|
|
|
cur_rotation_mode = 0,
|
2012-04-06 05:51:37 +00:00
|
|
|
-- these two variabls are used to help switching from framework to reader
|
|
|
|
native_rotation_mode = nil,
|
|
|
|
kpv_rotation_mode = nil,
|
2012-04-08 04:46:33 +00:00
|
|
|
|
|
|
|
saved_bb = nil,
|
2012-06-10 15:36:19 +00:00
|
|
|
|
|
|
|
fb = einkfb.open("/dev/fb0")
|
2012-03-09 01:44:22 +00:00
|
|
|
}
|
|
|
|
|
2012-03-10 08:41:23 +00:00
|
|
|
-- @orien: 1 for clockwise rotate, -1 for anti-clockwise
|
|
|
|
-- Remember to reread screen resolution after this function call
|
2012-03-09 01:44:22 +00:00
|
|
|
function Screen:screenRotate(orien)
|
|
|
|
if orien == "clockwise" then
|
|
|
|
orien = -1
|
2012-03-09 10:34:56 +00:00
|
|
|
elseif orien == "anticlockwise" then
|
|
|
|
orien = 1
|
2012-03-09 01:44:22 +00:00
|
|
|
else
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2012-03-09 10:34:56 +00:00
|
|
|
self.cur_rotation_mode = (self.cur_rotation_mode + orien) % 4
|
2012-03-09 10:45:55 +00:00
|
|
|
-- you have to reopen framebuffer after rotate
|
2012-06-10 15:36:19 +00:00
|
|
|
self.fb:setOrientation(self.cur_rotation_mode)
|
|
|
|
self.fb:close()
|
|
|
|
self.fb = einkfb.open("/dev/fb0")
|
2012-06-12 16:14:23 +00:00
|
|
|
Input.rotation = self.cur_rotation_mode
|
2012-06-10 15:36:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Screen:getSize()
|
|
|
|
local w, h = self.fb:getSize()
|
|
|
|
return Geom:new{w = w, h = h}
|
|
|
|
end
|
|
|
|
|
|
|
|
function Screen:getWidth()
|
|
|
|
local w, _ = self.fb:getSize()
|
|
|
|
return w
|
|
|
|
end
|
|
|
|
|
|
|
|
function Screen:getHeight()
|
|
|
|
local _, h = self.fb:getSize()
|
|
|
|
return h
|
2012-03-09 01:44:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Screen:updateRotationMode()
|
2012-06-10 16:09:23 +00:00
|
|
|
-- in EMU mode, you will always get 0 from getOrientation()
|
|
|
|
self.cur_rotation_mode = self.fb:getOrientation()
|
2012-03-09 01:44:22 +00:00
|
|
|
end
|
|
|
|
|
2012-06-12 04:13:51 +00:00
|
|
|
function Screen:setRotationMode(mode)
|
|
|
|
self.fb:setOrientation(Screen.native_rotation_mode)
|
|
|
|
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
|
|
|
|
self.saved_bb = Blitbuffer.new(width, height)
|
|
|
|
end
|
|
|
|
if self.saved_bb:getWidth() ~= width then
|
|
|
|
self.saved_bb:free()
|
|
|
|
self.saved_bb = Blitbuffer.new(width, height)
|
|
|
|
end
|
2012-06-13 17:52:08 +00:00
|
|
|
self.saved_bb:blitFullFrom(self.fb.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())
|
|
|
|
bb:blitFullFrom(self.fb.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
|
2012-06-10 15:36:19 +00:00
|
|
|
self.fb.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
|