add: demo for inputbox

pull/2/merge
Qingping Hou 12 years ago
parent 019695255d
commit 8fdb0a4c3e

@ -3,6 +3,7 @@ require "keys"
require "graphics"
require "fontchooser"
require "fileseacher"
require "inputbox"
FileChooser = {
-- Class vars:
@ -187,8 +188,9 @@ function FileChooser:choose(ypos, height)
end
pagedirty = true
elseif ev.code == KEY_S then
FileSeacher:init()
FileSeacher:choose(0, height)
InputBox:input(height-100, 100)
--FileSeacher:init()
--FileSeacher:choose(0, height)
pagedirty = true
elseif ev.code == KEY_PGFWD then
if self.page < (self.items / perpage) then

@ -0,0 +1,153 @@
require "rendertext"
require "keys"
require "graphics"
InputBox = {
-- Class vars:
-- font for displaying input content
face = freetype.newBuiltinFace("mono", 25),
fhash = "m25",
fheight = 25,
-- font for input title display
tface = freetype.newBuiltinFace("sans", 28),
tfhash = "s28",
-- spacing between lines
spacing = 40,
input_start_x = 145,
input_start_y = nil,
input_cur_x = nil,
input_bg = 1,
-- state buffer
dirs = nil,
files = nil,
items = 0,
path = "",
page = 1,
current = 1,
oldcurrent = 0,
}
function InputBox:setPath(newPath)
self.path = newPath
self:readdir()
self.items = #self.dirs + #self.files
if self.items == 0 then
return nil
end
self.page = 1
self.current = 1
return true
end
function InputBox:addChar(text)
renderUtf8Text(fb.bb, self.input_cur_x, self.input_start_y,
self.face, self.fhash, text, true)
fb:refresh(1, self.input_cur_x, self.input_start_y-19, 16, self.fheight)
self.input_cur_x = self.input_cur_x + 16
end
function InputBox:delChar()
if self.input_start_x == self.input_cur_x then
return
end
self.input_cur_x = self.input_cur_x - 16
--fill last character with blank rectangle
fb.bb:paintRect(self.input_cur_x, self.input_start_y-19, 16, self.fheight, self.input_bg)
fb:refresh(1, self.input_cur_x, self.input_start_y-19, 16, self.fheight)
end
function InputBox:input(ypos, height)
local pagedirty = true
self.input_start_y = ypos + 35
self.input_cur_x = self.input_start_x
while true do
if pagedirty then
w = fb.bb:getWidth() - 40
h = height - 45
-- draw input border
fb.bb:paintRect(20, ypos, w, h, 5)
-- draw input slot
fb.bb:paintRect(140, ypos + 10, w - 130, h - 20, self.input_bg)
renderUtf8Text(fb.bb, 35, self.input_start_y, self.face, self.fhash,
"Search:", true)
markerdirty = true
end
if pagedirty then
fb:refresh(0, 0, ypos, fb.bb:getWidth(), height)
pagedirty = false
end
local ev = input.waitForEvent()
if ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_PRESS then
print("key code:"..ev.code)
--ev.code = adjustFWKey(ev.code)
if ev.code == KEY_FW_UP then
elseif ev.code == KEY_FW_DOWN then
elseif ev.code == KEY_A then
self:addChar("a")
elseif ev.code == KEY_B then
self:addChar("b")
elseif ev.code == KEY_C then
self:addChar("c")
elseif ev.code == KEY_D then
self:addChar("d")
elseif ev.code == KEY_E then
self:addChar("e")
elseif ev.code == KEY_F then
self:addChar("f")
elseif ev.code == KEY_G then
self:addChar("g")
elseif ev.code == KEY_H then
self:addChar("h")
elseif ev.code == KEY_I then
self:addChar("i")
elseif ev.code == KEY_J then
self:addChar("j")
elseif ev.code == KEY_K then
self:addChar("k")
elseif ev.code == KEY_L then
self:addChar("l")
elseif ev.code == KEY_M then
self:addChar("m")
elseif ev.code == KEY_N then
self:addChar("n")
elseif ev.code == KEY_O then
self:addChar("o")
elseif ev.code == KEY_P then
self:addChar("p")
elseif ev.code == KEY_Q then
self:addChar("q")
elseif ev.code == KEY_R then
self:addChar("r")
elseif ev.code == KEY_S then
self:addChar("s")
elseif ev.code == KEY_T then
self:addChar("t")
elseif ev.code == KEY_U then
self:addChar("u")
elseif ev.code == KEY_V then
self:addChar("v")
elseif ev.code == KEY_W then
self:addChar("w")
elseif ev.code == KEY_X then
self:addChar("x")
elseif ev.code == KEY_Y then
self:addChar("y")
elseif ev.code == KEY_Z then
self:addChar("z")
elseif ev.code == KEY_PGFWD then
elseif ev.code == KEY_PGBCK then
elseif ev.code == KEY_ENTER or ev.code == KEY_FW_PRESS then
pagedirty = true
elseif ev.code == KEY_BACK then
self:delChar()
end
end
end
end

@ -118,13 +118,34 @@ function set_emu_keycodes()
KEY_ENTER = 36
KEY_Q = 24
KEY_W = 25
KEY_E = 26
KEY_R = 27
KEY_T = 28
KEY_Y = 29
KEY_U = 30
KEY_I = 31
KEY_O = 32
KEY_P = 33
KEY_A = 38
KEY_S = 39
KEY_D = 40
KEY_F = 41
KEY_G = 42
KEY_H = 43
KEY_J = 44
KEY_K = 45
KEY_L = 46
KEY_Z = 52
KEY_X = 53
KEY_C = 54
KEY_V = 55
KEY_B = 56
KEY_N = 57
KEY_M = 58
KEY_SHIFT = 50 -- left shift
KEY_ALT = 64 -- left alt

Loading…
Cancel
Save