Merge branch 'rotate'

Conflicts:
	filechooser.lua

* merge rotate branch with search branch
* fix font display bug in font menu

not fully tested the new rotation implemention yet.
pull/2/merge
Qingping Hou 13 years ago
commit 417ef640a7

@ -54,33 +54,6 @@ function FileChooser:setPath(newPath)
return true return true
end end
function FileChooser:rotationMode()
--[[
return code for four kinds of rotation mode:
0 for no rotation,
1 for landscape with bottom on the right side of screen, etc.
2
---------
| |
| |
| |
3 | | 1
| |
| |
| |
---------
0
--]]
if KEY_FW_DOWN == 116 then
return 0
end
orie_fd = assert(io.open("/sys/module/eink_fb_hal_broads/parameters/bs_orientation", "r"))
updown_fd = assert(io.open("/sys/module/eink_fb_hal_broads/parameters/bs_upside_down", "r"))
mode = orie_fd:read() + (updown_fd:read() * 2)
return mode
end
function FileChooser:choose(ypos, height) function FileChooser:choose(ypos, height)
local perpage = math.floor(height / self.spacing) - 1 local perpage = math.floor(height / self.spacing) - 1
@ -154,32 +127,13 @@ function FileChooser:choose(ypos, height)
end end
local ev = input.waitForEvent() local ev = input.waitForEvent()
if ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_PRESS then if ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_PRESS then
print("key code:"..ev.code) --print("key code:"..ev.code)
ev.code = adjustFWKey(ev.code)
if ev.code == KEY_FW_UP then if ev.code == KEY_FW_UP then
if self:rotationMode() == 0 then prevItem()
prevItem()
elseif self:rotationMode() == 2 then
nextItem()
end
elseif ev.code == KEY_FW_DOWN then elseif ev.code == KEY_FW_DOWN then
if self:rotationMode() == 0 then nextItem()
nextItem() elseif ev.code == KEY_F then -- invoke fontchooser menu
elseif self:rotationMode() == 2 then
prevItem()
end
elseif ev.code == KEY_FW_LEFT then
if self:rotationMode() == 1 then
prevItem()
elseif self:rotationMode() == 3 then
nextItem()
end
elseif ev.code == KEY_FW_RIGHT then
if self:rotationMode() == 1 then
nextItem()
elseif self:rotationMode() == 3 then
prevItem()
end
elseif ev.code == KEY_F then
FontChooser:init() FontChooser:init()
newfont = FontChooser:choose(0, height) newfont = FontChooser:choose(0, height)
if newfont ~= nil then if newfont ~= nil then
@ -187,8 +141,7 @@ function FileChooser:choose(ypos, height)
clearglyphcache() clearglyphcache()
end end
pagedirty = true pagedirty = true
elseif ev.code == KEY_S then elseif ev.code == KEY_S then -- invoke search input
-- invoke search input
keywords = InputBox:input(height-100, 100, "Search:") keywords = InputBox:input(height-100, 100, "Search:")
if keywords then -- display search result according to keywords if keywords then -- display search result according to keywords
--[[ --[[

@ -188,6 +188,7 @@ function FileSearcher:choose(ypos, height, keywords)
local ev = input.waitForEvent() local ev = input.waitForEvent()
if ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_PRESS then if ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_PRESS then
ev.code = adjustFWKey(ev.code)
if ev.code == KEY_FW_UP then if ev.code == KEY_FW_UP then
prevItem() prevItem()
elseif ev.code == KEY_FW_DOWN then elseif ev.code == KEY_FW_DOWN then

@ -31,8 +31,8 @@ FontChooser = {
} }
function FontChooser:init() function FontChooser:init()
clearglyphcache()
self.items = #self.fonts self.items = #self.fonts
table.sort(self.fonts)
end end
@ -80,6 +80,7 @@ function FontChooser:choose(ypos, height)
renderUtf8Text(fb.bb, x, y, self.tface, self.tfhash, renderUtf8Text(fb.bb, x, y, self.tface, self.tfhash,
"Fonts Menu", true) "Fonts Menu", true)
-- draw font items
fb.bb:paintRect(0, ypos + self.title_H + 10, fb.bb:getWidth(), height - self.title_H, 0) fb.bb:paintRect(0, ypos + self.title_H + 10, fb.bb:getWidth(), height - self.title_H, 0)
local c local c
for c = 1, perpage do for c = 1, perpage do
@ -89,6 +90,7 @@ function FontChooser:choose(ypos, height)
renderUtf8Text(fb.bb, 50, y, self.face, self.fhash, self.fonts[i], true) renderUtf8Text(fb.bb, 50, y, self.face, self.fhash, self.fonts[i], true)
end end
end end
-- draw footer -- draw footer
y = ypos + self.title_H + (self.spacing * perpage) + self.foot_H y = ypos + self.title_H + (self.spacing * perpage) + self.foot_H
x = (fb.bb:getWidth() / 2) - 50 x = (fb.bb:getWidth() / 2) - 50
@ -122,6 +124,7 @@ function FontChooser:choose(ypos, height)
local ev = input.waitForEvent() local ev = input.waitForEvent()
if ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_PRESS then if ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_PRESS then
ev.code = adjustFWKey(ev.code)
if ev.code == KEY_FW_UP then if ev.code == KEY_FW_UP then
prevItem() prevItem()
elseif ev.code == KEY_FW_DOWN then elseif ev.code == KEY_FW_DOWN then

@ -96,8 +96,8 @@ function InputBox:input(ypos, height, title, d_text)
local ev = input.waitForEvent() local ev = input.waitForEvent()
if ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_PRESS then if ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_PRESS then
print("key code:"..ev.code) --print("key code:"..ev.code)
--ev.code = adjustFWKey(ev.code) ev.code = adjustFWKey(ev.code)
if ev.code == KEY_FW_UP then if ev.code == KEY_FW_UP then
elseif ev.code == KEY_FW_DOWN then elseif ev.code == KEY_FW_DOWN then
elseif ev.code == KEY_A then elseif ev.code == KEY_A then

@ -154,3 +154,75 @@ function set_emu_keycodes()
KEY_VPLUS = 95 -- F11 KEY_VPLUS = 95 -- F11
KEY_VMINUS = 96 -- F12 KEY_VMINUS = 96 -- F12
end end
function getRotationMode()
--[[
return code for four kinds of rotation mode:
0 for no rotation,
1 for landscape with bottom on the right side of screen, etc.
2
-----------
| ------- |
| | | |
| | | |
| | | |
3 | | | | 1
| | | |
| | | |
| ------- |
| |
-----------
0
--]]
if KEY_FW_DOWN == 116 then -- in EMU mode always return 0
return 0
end
orie_fd = assert(io.open("/sys/module/eink_fb_hal_broads/parameters/bs_orientation", "r"))
updown_fd = assert(io.open("/sys/module/eink_fb_hal_broads/parameters/bs_upside_down", "r"))
mode = orie_fd:read() + (updown_fd:read() * 2)
return mode
end
function adjustFWKey(code)
if getRotationMode() == 0 then
return code
elseif getRotationMode() == 1 then
if code == KEY_FW_UP then
return KEY_FW_RIGHT
elseif code == KEY_FW_RIGHT then
return KEY_FW_DOWN
elseif code == KEY_FW_DOWN then
return KEY_FW_LEFT
elseif code == KEY_FW_LEFT then
return KEY_FW_UP
else
return code
end
elseif getRotationMode() == 2 then
if code == KEY_FW_UP then
return KEY_FW_DOWN
elseif code == KEY_FW_RIGHT then
return KEY_FW_LEFT
elseif code == KEY_FW_DOWN then
return KEY_FW_UP
elseif code == KEY_FW_LEFT then
return KEY_FW_RIGHT
else
return code
end
elseif getRotationMode() == 3 then
if code == KEY_FW_UP then
return KEY_FW_LEFT
elseif code == KEY_FW_RIGHT then
return KEY_FW_UP
elseif code == KEY_FW_DOWN then
return KEY_FW_RIGHT
elseif code == KEY_FW_LEFT then
return KEY_FW_DOWN
else
return code
end
end
end

Loading…
Cancel
Save