2012-03-13 21:51:25 +00:00
|
|
|
require "rendertext"
|
|
|
|
require "keys"
|
|
|
|
require "graphics"
|
|
|
|
require "font"
|
|
|
|
require "inputbox"
|
|
|
|
require "selectmenu"
|
|
|
|
require "commands"
|
|
|
|
|
|
|
|
HelpPage = {
|
2012-03-20 19:15:24 +00:00
|
|
|
-- Other Class vars:
|
2012-09-06 18:19:57 +00:00
|
|
|
title_H = 40, -- title height
|
|
|
|
margin_H = 10, -- horisontal margin
|
|
|
|
foot_H = 28, -- foot height
|
|
|
|
bg_color = 3, -- background color
|
|
|
|
spacing = 25, -- spacing between lines
|
2012-03-13 21:51:25 +00:00
|
|
|
|
|
|
|
-- state buffer
|
|
|
|
commands = nil,
|
|
|
|
items = 0,
|
2012-04-09 17:04:26 +00:00
|
|
|
page = 1,
|
2012-03-13 21:51:25 +00:00
|
|
|
}
|
|
|
|
|
2012-08-28 19:36:45 +00:00
|
|
|
function HelpPage:show(ypos, height, commands, title)
|
2012-09-06 18:19:57 +00:00
|
|
|
local face = Font:getFace("hpkfont", 20)
|
|
|
|
local hface = Font:getFace("hfont", 20)
|
|
|
|
local fface = Font:getFace("ffont", 16)
|
|
|
|
local tface = Font:getFace("tfont", 25)
|
|
|
|
|
2012-11-18 11:32:23 +00:00
|
|
|
self.commands = Commands:new()
|
2012-03-13 21:51:25 +00:00
|
|
|
self.items = 0
|
|
|
|
local keys = {}
|
|
|
|
for k,v in pairs(commands.map) do
|
|
|
|
local key = v.keygroup or v.keydef:display()
|
2012-06-03 22:49:23 +00:00
|
|
|
--Debug("order: "..v.order.." command: "..tostring(v.keydef).." - keygroup:"..(v.keygroup or "nil").." -keys[key]:"..(keys[key] or "nil"))
|
2012-03-13 21:51:25 +00:00
|
|
|
if keys[key] == nil then
|
|
|
|
keys[key] = 1
|
|
|
|
table.insert(self.commands,{shortcut=key,help=v.help,order=v.order})
|
|
|
|
self.items = self.items + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
table.sort(self.commands,function(w1,w2) return w1.order<w2.order end)
|
2012-03-20 22:28:49 +00:00
|
|
|
|
2012-09-06 18:19:57 +00:00
|
|
|
local face_height, face_ascender = face.ftface:getHeightAndAscender()
|
|
|
|
--local hface_height, hface_ascender = hface.ftface:getHeightAndAscender()
|
|
|
|
local fface_height, fface_ascender = fface.ftface:getHeightAndAscender()
|
2012-06-03 22:49:23 +00:00
|
|
|
--Debug(face_height.."-"..face_ascender)
|
|
|
|
--Debug(fface_height.."-"..fface_ascender)
|
2012-04-16 18:16:31 +00:00
|
|
|
face_height = math.ceil(face_height)
|
|
|
|
face_ascender = math.ceil(face_ascender)
|
|
|
|
fface_height = math.ceil(fface_height)
|
|
|
|
fface_ascender = math.ceil(fface_ascender)
|
|
|
|
local spacing = face_height + 5
|
2012-08-28 19:36:45 +00:00
|
|
|
local vert_S = self.title_H + 3
|
2012-03-20 22:28:49 +00:00
|
|
|
|
2012-05-19 10:59:38 +00:00
|
|
|
local perpage = math.floor( (height - ypos - 1 * (fface_height + 5) - vert_S) / spacing )
|
2012-06-03 13:03:55 +00:00
|
|
|
self.page = 1
|
2012-04-16 18:16:31 +00:00
|
|
|
local is_pagedirty = true
|
2012-03-13 21:51:25 +00:00
|
|
|
|
|
|
|
while true do
|
2012-04-16 18:16:31 +00:00
|
|
|
if is_pagedirty then
|
2012-04-15 14:07:39 +00:00
|
|
|
fb.bb:paintRect(0, ypos, fb.bb:getWidth(), height, 0)
|
2012-09-07 09:46:46 +00:00
|
|
|
DrawTitle(title or "Active Hotkeys",self.margin_H,0,self.title_H,self.bg_color,tface)
|
2012-03-13 21:51:25 +00:00
|
|
|
local c
|
|
|
|
local max_x = 0
|
|
|
|
for c = 1, perpage do
|
2012-05-19 10:59:38 +00:00
|
|
|
local x = self.margin_H
|
2012-03-13 21:51:25 +00:00
|
|
|
local i = (self.page - 1) * perpage + c
|
|
|
|
if i <= self.items then
|
2012-04-15 14:07:39 +00:00
|
|
|
local key = self.commands[i].shortcut
|
|
|
|
for _k,aMod in pairs(MOD_TABLE) do
|
|
|
|
local modStart, modEnd = key:find(aMod.v)
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("key:"..key.." v:"..aMod.v.." d:"..aMod.d.." modstart:"..(modStart or "nil"))
|
2012-04-15 14:07:39 +00:00
|
|
|
if(modStart ~= nil) then
|
|
|
|
key = key:sub(1,modStart-1)..key:sub(modEnd+1)
|
2012-09-06 18:19:57 +00:00
|
|
|
local box = sizeUtf8Text( x, fb.bb:getWidth(), face, aMod.d, true)
|
2012-05-19 10:59:38 +00:00
|
|
|
fb.bb:paintRect(x, ypos + spacing*c - box.y_top + vert_S, box.x + self.title_H, box.y_top + box.y_bottom, self.bg_color)
|
2012-09-06 18:19:57 +00:00
|
|
|
local pen_x = renderUtf8Text(fb.bb, x, ypos + spacing*c + vert_S, face, aMod.d.." + ", true)
|
2012-04-15 14:07:39 +00:00
|
|
|
x = x + pen_x
|
|
|
|
max_x = math.max(max_x, pen_x)
|
|
|
|
end
|
|
|
|
end
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("key:"..key)
|
2012-09-06 18:19:57 +00:00
|
|
|
local box = sizeUtf8Text( x, fb.bb:getWidth(), face, key , true)
|
2012-05-19 10:59:38 +00:00
|
|
|
fb.bb:paintRect(x, ypos + spacing*c - box.y_top + vert_S, box.x, box.y_top + box.y_bottom, self.bg_color)
|
2012-09-06 18:19:57 +00:00
|
|
|
local pen_x = renderUtf8Text(fb.bb, x, ypos + spacing*c + vert_S, face, key, true)
|
2012-04-15 14:07:39 +00:00
|
|
|
x = x + pen_x
|
|
|
|
max_x = math.max(max_x, x)
|
2012-03-13 21:51:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
for c = 1, perpage do
|
|
|
|
local i = (self.page - 1) * perpage + c
|
|
|
|
if i <= self.items then
|
2012-09-06 18:19:57 +00:00
|
|
|
renderUtf8Text(fb.bb, max_x + 20, ypos + spacing*c + vert_S, hface, self.commands[i].help, true)
|
2012-03-13 21:51:25 +00:00
|
|
|
end
|
2012-03-20 19:15:24 +00:00
|
|
|
end
|
2012-05-19 10:59:38 +00:00
|
|
|
-- draw footer
|
|
|
|
local footer = "Page "..self.page.." of "..math.ceil(self.items / perpage).." - Back to close this page"
|
2012-09-06 18:19:57 +00:00
|
|
|
renderUtf8Text(fb.bb, self.margin_H, height-7, fface, footer, true)
|
2012-03-13 21:51:25 +00:00
|
|
|
end
|
2012-04-16 18:16:31 +00:00
|
|
|
if is_pagedirty then
|
2012-03-13 21:51:25 +00:00
|
|
|
fb:refresh(0, 0, ypos, fb.bb:getWidth(), height)
|
2012-04-16 18:16:31 +00:00
|
|
|
is_pagedirty = false
|
2012-03-13 21:51:25 +00:00
|
|
|
end
|
|
|
|
|
2012-04-12 19:00:44 +00:00
|
|
|
local ev = input.saveWaitForEvent()
|
2012-06-03 22:49:23 +00:00
|
|
|
--Debug("key code:"..ev.code)
|
2012-03-13 21:51:25 +00:00
|
|
|
ev.code = adjustKeyEvents(ev)
|
|
|
|
if ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_PRESS then
|
2012-04-20 02:04:31 +00:00
|
|
|
if ev.code == KEY_PGFWD or ev.code == KEY_LPGFWD then
|
2012-03-13 21:51:25 +00:00
|
|
|
if self.page < (self.items / perpage) then
|
|
|
|
self.page = self.page + 1
|
2012-04-16 18:16:31 +00:00
|
|
|
is_pagedirty = true
|
2012-03-13 21:51:25 +00:00
|
|
|
end
|
2012-04-20 02:04:31 +00:00
|
|
|
elseif ev.code == KEY_PGBCK or ev.code == KEY_LPGBCK then
|
2012-03-13 21:51:25 +00:00
|
|
|
if self.page > 1 then
|
|
|
|
self.page = self.page - 1
|
2012-04-16 18:16:31 +00:00
|
|
|
is_pagedirty = true
|
2012-03-13 21:51:25 +00:00
|
|
|
end
|
2012-10-05 16:36:43 +00:00
|
|
|
elseif ev.code == KEY_BACK then
|
2012-03-13 21:51:25 +00:00
|
|
|
return nil
|
2012-11-18 11:32:23 +00:00
|
|
|
elseif ev.code == KEY_INTO_SCREEN_SAVER or ev.code == KEY_OUTOF_SCREEN_SAVER then
|
|
|
|
command = self.commands:get(ev.code, nil)
|
|
|
|
ret_code = command.func(self)
|
|
|
|
if ret_code == "break" then
|
|
|
|
break;
|
|
|
|
end
|
2012-03-13 21:51:25 +00:00
|
|
|
end
|
2012-11-18 11:32:23 +00:00
|
|
|
end -- ev.type == EV_KEY...
|
|
|
|
end -- while
|
2012-03-13 21:51:25 +00:00
|
|
|
end
|