first demo of screen rotate

This commit is contained in:
Qingping Hou
2013-02-02 14:36:29 +08:00
parent 78691fd499
commit d4ff6f9291
14 changed files with 482 additions and 333 deletions

View File

@@ -40,18 +40,42 @@ Codes for rotation modes:
Screen = {
cur_rotation_mode = 0,
-- these two variabls are used to help switching from framework to reader
width = 0,
height = 0,
pitch = 0,
native_rotation_mode = nil,
kpv_rotation_mode = nil,
cur_rotation_mode = 0,
bb = nil,
saved_bb = nil,
fb = einkfb.open("/dev/fb0")
fb = einkfb.open("/dev/fb0"),
}
function Screen:init()
_, self.height = self.fb:getSize()
-- for unknown strange reason, pitch*2 is less than screen width in KPW
-- so we need to calculate width by pitch here
self.width = self.fb:getPitch()*2
self.pitch = self:getPitch()
self.bb = Blitbuffer.new(self.width, self.height, self.pitch)
self.native_rotation_mode = self.fb:getOrientation()
self.cur_rotation_mode = self.native_rotation_mode
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)
end
self.fb:refresh(refesh_type)
end
-- @orien: 1 for clockwise rotate, -1 for anti-clockwise
-- Remember to reread screen resolution after this function call
-- WARNING: this method is deprecated!!! use setRotationMode() or
-- setViewMode() instead.
function Screen:screenRotate(orien)
if orien == "clockwise" then
orien = -1
@@ -70,22 +94,19 @@ function Screen:screenRotate(orien)
end
function Screen:getSize()
local w, h = self.fb:getSize()
return Geom:new{w = w, h = h}
return Geom:new{w = self.width, h = self.height}
end
function Screen:getWidth()
local w, _ = self.fb:getSize()
return w
return self.width
end
function Screen:getHeight()
local _, h = self.fb:getSize()
return h
return self.height
end
function Screen:getPitch()
return self.fb:getPitch()
return self.ptich
end
function Screen:updateRotationMode()
@@ -94,7 +115,46 @@ function Screen:updateRotationMode()
end
function Screen:setRotationMode(mode)
self.fb:setOrientation(Screen.native_rotation_mode)
-- 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()
self.pitch = self.width/2
self.bb = Blitbuffer.new(self.width, self.height, self.pitch)
end
function Screen:setViewMode(mode)
if mode == "portrait" then
if self.cur_rotation_mode ~= 0 then
self:setRotationMode(0)
end
elseif mode == "landscape" then
if self.cur_rotation_mode ~= 1 then
self:setRotationMode(1)
end
end
end
--[[
@brief change gesture's x and y coordinates according to screen view mode
@param ges gesture that you want to adjust
@return adjusted gesture.
--]]
function Screen:adjustGesCoordinate(ges)
-- we do nothing is screen is not rotated
if self.native_rotation_mode == self.cur_rotation_mode then
return ges
end
if self.native_rotation_mode == 0 and self.cur_rotation_mode == 1 then
ges.pos.x, ges.pos.y = (self.width - ges.pos.y), (ges.pos.x)
end
return ges
end
function Screen:saveCurrentBB()