From 019695255d04ed385e639e6a7d57268068cc326e Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Fri, 17 Feb 2012 13:46:40 +0800 Subject: [PATCH 1/8] add: a demo for text input --- filechooser.lua | 7 +++ fileseacher.lua | 161 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 168 insertions(+) create mode 100644 fileseacher.lua diff --git a/filechooser.lua b/filechooser.lua index ae5104c82..cfd8ef47c 100644 --- a/filechooser.lua +++ b/filechooser.lua @@ -2,6 +2,7 @@ require "rendertext" require "keys" require "graphics" require "fontchooser" +require "fileseacher" FileChooser = { -- Class vars: @@ -35,6 +36,7 @@ function FileChooser:readdir() table.insert(self.files, f) end end + --@TODO make sure .. is sortted to the first item 16.02 2012 table.sort(self.dirs) table.sort(self.files) end @@ -151,6 +153,7 @@ function FileChooser:choose(ypos, height) end local ev = input.waitForEvent() if ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_PRESS then + print("key code:"..ev.code) if ev.code == KEY_FW_UP then if self:rotationMode() == 0 then prevItem() @@ -183,6 +186,10 @@ function FileChooser:choose(ypos, height) clearglyphcache() end pagedirty = true + elseif ev.code == KEY_S then + FileSeacher:init() + FileSeacher:choose(0, height) + pagedirty = true elseif ev.code == KEY_PGFWD then if self.page < (self.items / perpage) then if self.current + self.page*perpage > self.items then diff --git a/fileseacher.lua b/fileseacher.lua new file mode 100644 index 000000000..137ce4621 --- /dev/null +++ b/fileseacher.lua @@ -0,0 +1,161 @@ +require "rendertext" +require "keys" +require "graphics" + +FileSeacher = { + -- font for displaying file/dir names + face = freetype.newBuiltinFace("sans", 25), + fhash = "s25", + -- font for page title + tface = freetype.newBuiltinFace("Helvetica-BoldOblique", 32), + tfhash = "hbo32", + -- font for paging display + sface = freetype.newBuiltinFace("sans", 16), + sfhash = "s16", + -- title height + title_H = 45, + -- spacing between lines + spacing = 40, + -- foot height + foot_H = 27, + + x_input = 50, + -- state buffer + fonts = {"sans", "cjk", "mono", + "Courier", "Courier-Bold", "Courier-Oblique", "Courier-BoldOblique", + "Helvetica", "Helvetica-Oblique", "Helvetica-BoldOblique", + "Times-Roman", "Times-Bold", "Times-Italic", "Times-BoldItalic",}, + items = 14, + page = 1, + current = 2, + oldcurrent = 1, +} + +function FileSeacher:init() + self.items = #self.fonts + --@TODO check this 17.02 2012 + self.face = freetype.newBuiltinFace("sans", 25), + table.sort(self.fonts) +end + + +function FileSeacher:choose(ypos, height) + local perpage = math.floor(height / self.spacing) - 2 + local pagedirty = true + local markerdirty = false + + local prevItem = function () + if self.current == 1 then + if self.page > 1 then + self.current = perpage + self.page = self.page - 1 + pagedirty = true + end + else + self.current = self.current - 1 + markerdirty = true + end + end + + local nextItem = function () + if self.current == perpage then + if self.page < (self.items / perpage) then + self.current = 1 + self.page = self.page + 1 + pagedirty = true + end + else + if self.page ~= math.floor(self.items / perpage) + 1 + or self.current + (self.page-1)*perpage < self.items then + self.current = self.current + 1 + markerdirty = true + end + end + end + + + while true do + if pagedirty then + fb.bb:paintRect(0, ypos, fb.bb:getWidth(), height, 0) + + -- draw menu title + renderUtf8Text(fb.bb, 30, ypos + self.title_H, self.tface, self.tfhash, + "[ Fonts Menu ]", true) + + local c + for c = 1, perpage do + local i = (self.page - 1) * perpage + c + if i <= self.items then + y = ypos + self.title_H + (self.spacing * c) + renderUtf8Text(fb.bb, 50, y, self.face, self.fhash, self.fonts[i], true) + end + end + y = ypos + self.title_H + (self.spacing * perpage) + self.foot_H + x = (fb.bb:getWidth() / 2) - 50 + renderUtf8Text(fb.bb, x, y, self.sface, self.sfhash, + "Page "..self.page.." of "..(math.floor(self.items / perpage)+1), true) + markerdirty = true + end + + if markerdirty then + if not pagedirty then + if self.oldcurrent > 0 then + y = ypos + self.title_H + (self.spacing * self.oldcurrent) + 10 + fb.bb:paintRect(30, y, fb.bb:getWidth() - 60, 3, 0) + fb:refresh(1, 30, y, fb.bb:getWidth() - 60, 3) + end + end + -- draw new marker line + y = ypos + self.title_H + (self.spacing * self.current) + 10 + fb.bb:paintRect(30, y, fb.bb:getWidth() - 60, 3, 15) + if not pagedirty then + fb:refresh(1, 30, y, fb.bb:getWidth() - 60, 3) + end + self.oldcurrent = self.current + markerdirty = false + 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 + if ev.code == KEY_FW_UP then + prevItem() + elseif ev.code == KEY_FW_DOWN then + nextItem() + elseif ev.code == KEY_PGFWD then + if self.page < (self.items / perpage) then + if self.current + self.page*perpage > self.items then + self.current = self.items - self.page*perpage + end + self.page = self.page + 1 + pagedirty = true + else + self.current = self.items - (self.page-1)*perpage + markerdirty = true + end + elseif ev.code == KEY_PGBCK then + if self.page > 1 then + self.page = self.page - 1 + pagedirty = true + else + self.current = 1 + markerdirty = true + end + elseif ev.code == KEY_F then + self.x_input = self.x_input + 10 + y = ypos + self.title_H + (self.spacing) + renderUtf8Text(fb.bb, self.x_input, y, self.face, self.fhash, "f", true) + fb:refresh(1, x_input, ypos, fb.bb:getWidth(), height) + elseif ev.code == KEY_ENTER or ev.code == KEY_FW_PRESS then + local newface = self.fonts[perpage*(self.page-1)+self.current] + return newface + elseif ev.code == KEY_BACK then + return nil + end + end + end +end From 8fdb0a4c3edcfb20ae6d5fb0e86c96e802347f7d Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Sat, 18 Feb 2012 18:21:03 +0800 Subject: [PATCH 2/8] add: demo for inputbox --- filechooser.lua | 6 +- inputbox.lua | 153 ++++++++++++++++++++++++++++++++++++++++++++++++ keys.lua | 23 +++++++- 3 files changed, 179 insertions(+), 3 deletions(-) create mode 100644 inputbox.lua diff --git a/filechooser.lua b/filechooser.lua index cfd8ef47c..084af48b0 100644 --- a/filechooser.lua +++ b/filechooser.lua @@ -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 diff --git a/inputbox.lua b/inputbox.lua new file mode 100644 index 000000000..d86fad050 --- /dev/null +++ b/inputbox.lua @@ -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 diff --git a/keys.lua b/keys.lua index b757dd5b0..ee43be603 100644 --- a/keys.lua +++ b/keys.lua @@ -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 From 3bc71354ed9b5ff33e72407a4de9b2c9bc21da35 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Sat, 18 Feb 2012 20:07:28 +0800 Subject: [PATCH 3/8] mod: add KEY_DEL for EMU mode --- keys.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/keys.lua b/keys.lua index ee43be603..8b93d90f8 100644 --- a/keys.lua +++ b/keys.lua @@ -109,6 +109,7 @@ function set_emu_keycodes() KEY_PGFWD = 117 KEY_PGBCK = 112 KEY_BACK = 22 -- backspace + KEY_DEL = 119 -- Delete KEY_MENU = 67 -- F1 KEY_FW_UP = 111 KEY_FW_DOWN = 116 From 29a9996fb226525498cd1261115d5d9aebe64844 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Sat, 18 Feb 2012 20:32:38 +0800 Subject: [PATCH 4/8] mod: inputbox finished --- filechooser.lua | 5 +++-- inputbox.lua | 13 ++++++++++--- keys.lua | 1 + 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/filechooser.lua b/filechooser.lua index 084af48b0..6137863b4 100644 --- a/filechooser.lua +++ b/filechooser.lua @@ -2,7 +2,7 @@ require "rendertext" require "keys" require "graphics" require "fontchooser" -require "fileseacher" +require "filesearcher" require "inputbox" FileChooser = { @@ -188,7 +188,8 @@ function FileChooser:choose(ypos, height) end pagedirty = true elseif ev.code == KEY_S then - InputBox:input(height-100, 100) + input = InputBox:input(height-100, 100) + print(input) --FileSeacher:init() --FileSeacher:choose(0, height) pagedirty = true diff --git a/inputbox.lua b/inputbox.lua index d86fad050..a8647adc9 100644 --- a/inputbox.lua +++ b/inputbox.lua @@ -21,6 +21,7 @@ InputBox = { input_bg = 1, + input_string = "", -- state buffer dirs = nil, files = nil, @@ -48,6 +49,7 @@ function InputBox:addChar(text) 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 + self.input_string = self.input_string .. text end function InputBox:delChar() @@ -58,6 +60,7 @@ function InputBox:delChar() --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) + self.input_string = self.input_string:sub(0,-2) end function InputBox:input(ypos, height) @@ -79,7 +82,7 @@ function InputBox:input(ypos, height) end if pagedirty then - fb:refresh(0, 0, ypos, fb.bb:getWidth(), height) + fb:refresh(1, 20, ypos, w, h) pagedirty = false end @@ -141,12 +144,16 @@ function InputBox:input(ypos, height) self:addChar("y") elseif ev.code == KEY_Z then self:addChar("z") + elseif ev.code == KEY_SPACE then + self:addChar(" ") 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 + return self.input_string + elseif ev.code == KEY_DEL then self:delChar() + elseif ev.code == KEY_BACK then + return "" end end end diff --git a/keys.lua b/keys.lua index 8b93d90f8..eb932176a 100644 --- a/keys.lua +++ b/keys.lua @@ -116,6 +116,7 @@ function set_emu_keycodes() KEY_FW_LEFT = 113 KEY_FW_RIGHT = 114 KEY_FW_PRESS = 36 -- enter for now + KEY_SPACE = 65 KEY_ENTER = 36 From 85fedef7a4968bd6212340fd1ee9b05cd6a0b35b Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Sat, 18 Feb 2012 20:35:03 +0800 Subject: [PATCH 5/8] add: filesearcher --- filesearcher.lua | 179 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 179 insertions(+) create mode 100644 filesearcher.lua diff --git a/filesearcher.lua b/filesearcher.lua new file mode 100644 index 000000000..3f819e941 --- /dev/null +++ b/filesearcher.lua @@ -0,0 +1,179 @@ +require "rendertext" +require "keys" +require "graphics" +require "fontchooser" +require "inputbox" + +FileSearcher = { + -- Class vars: + + -- font for displaying file/dir names + face = freetype.newBuiltinFace("sans", 25), + fhash = "s25", + -- font for paging display + sface = freetype.newBuiltinFace("sans", 16), + sfhash = "s16", + -- spacing between lines + spacing = 40, + + -- state buffer + dirs = nil, + files = nil, + items = 0, + path = "", + page = 1, + current = 1, + oldcurrent = 0, +} + +function FileSearcher:readdir() + self.dirs = {} + self.files = {} + for f in lfs.dir(self.path) do + if lfs.attributes(self.path.."/"..f, "mode") == "directory" and f ~= "." and not string.match(f, "^%.[^.]") then + table.insert(self.dirs, f) + elseif string.match(f, ".+%.[pP][dD][fF]$") then + table.insert(self.files, f) + end + end + table.sort(self.dirs) + table.sort(self.files) +end + +function FileSearcher: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 FileSearcher:choose(ypos, height) + local perpage = math.floor(height / self.spacing) - 1 + local pagedirty = true + local markerdirty = false + + local prevItem = function () + if self.current == 1 then + if self.page > 1 then + self.current = perpage + self.page = self.page - 1 + pagedirty = true + end + else + self.current = self.current - 1 + markerdirty = true + end + end + + local nextItem = function () + if self.current == perpage then + if self.page < (self.items / perpage) then + self.current = 1 + self.page = self.page + 1 + pagedirty = true + end + else + if self.page ~= math.floor(self.items / perpage) + 1 + or self.current + (self.page-1)*perpage < self.items then + self.current = self.current + 1 + markerdirty = true + end + end + end + + while true do + if pagedirty then + fb.bb:paintRect(0, ypos, fb.bb:getWidth(), height, 0) + local c + for c = 1, perpage do + local i = (self.page - 1) * perpage + c + if i <= #self.dirs then + -- resembles display in midnight commander: adds "/" prefix for directories + renderUtf8Text(fb.bb, 39, ypos + self.spacing*c, self.face, self.fhash, "/", true) + renderUtf8Text(fb.bb, 50, ypos + self.spacing*c, self.face, self.fhash, self.dirs[i], true) + elseif i <= self.items then + renderUtf8Text(fb.bb, 50, ypos + self.spacing*c, self.face, self.fhash, self.files[i-#self.dirs], true) + end + end + renderUtf8Text(fb.bb, 39, ypos + self.spacing * perpage + 32, self.sface, self.sfhash, + "Page "..self.page.." of "..(math.floor(self.items / perpage)+1), true) + markerdirty = true + end + if markerdirty then + if not pagedirty then + if self.oldcurrent > 0 then + fb.bb:paintRect(30, ypos + self.spacing*self.oldcurrent + 10, fb.bb:getWidth() - 60, 3, 0) + fb:refresh(1, 30, ypos + self.spacing*self.oldcurrent + 10, fb.bb:getWidth() - 60, 3) + end + end + fb.bb:paintRect(30, ypos + self.spacing*self.current + 10, fb.bb:getWidth() - 60, 3, 15) + if not pagedirty then + fb:refresh(1, 30, ypos + self.spacing*self.current + 10, fb.bb:getWidth() - 60, 3) + end + self.oldcurrent = self.current + markerdirty = false + 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 + ev.code = adjustFWKey(ev.code) + if ev.code == KEY_FW_UP then + prevItem() + elseif ev.code == KEY_FW_DOWN then + nextItem() + elseif ev.code == KEY_F then + FontChooser:init() + newfont = FontChooser:choose(0, height) + if newfont ~= nil then + self.face = freetype.newBuiltinFace(newfont, 25) + clearglyphcache() + end + pagedirty = true + elseif ev.code == KEY_S then + InputBox:input() + elseif ev.code == KEY_PGFWD then + if self.page < (self.items / perpage) then + if self.current + self.page*perpage > self.items then + self.current = self.items - self.page*perpage + end + self.page = self.page + 1 + pagedirty = true + else + self.current = self.items - (self.page-1)*perpage + markerdirty = true + end + elseif ev.code == KEY_PGBCK then + if self.page > 1 then + self.page = self.page - 1 + pagedirty = true + else + self.current = 1 + markerdirty = true + end + elseif ev.code == KEY_ENTER or ev.code == KEY_FW_PRESS then + local newdir = self.dirs[perpage*(self.page-1)+self.current] + if newdir == ".." then + local path = string.gsub(self.path, "(.*)/[^/]+/?$", "%1") + self:setPath(path) + elseif newdir then + local path = self.path.."/"..newdir + self:setPath(path) + else + return self.path.."/"..self.files[perpage*(self.page-1)+self.current - #self.dirs] + end + pagedirty = true + elseif ev.code == KEY_BACK then + return nil + end + end + end +end From 32d1bede8c6b0de974f81e333ba50163be101723 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Sun, 19 Feb 2012 07:21:50 +0800 Subject: [PATCH 6/8] start working on filesearcher --- filechooser.lua | 13 ++-- fileseacher.lua | 161 ----------------------------------------------- filesearcher.lua | 114 +++++++++++++-------------------- inputbox.lua | 12 ++-- 4 files changed, 61 insertions(+), 239 deletions(-) delete mode 100644 fileseacher.lua diff --git a/filechooser.lua b/filechooser.lua index 6137863b4..ecec641a3 100644 --- a/filechooser.lua +++ b/filechooser.lua @@ -188,10 +188,15 @@ function FileChooser:choose(ypos, height) end pagedirty = true elseif ev.code == KEY_S then - input = InputBox:input(height-100, 100) - print(input) - --FileSeacher:init() - --FileSeacher:choose(0, height) + keywords = InputBox:input(height-100, 100, "Search:") + if keywords then + -- display search result according to keywords + FileSearcher:init() + file = FileSearcher:choose(ypos, height, keywords) + if file then + return file + end + end pagedirty = true elseif ev.code == KEY_PGFWD then if self.page < (self.items / perpage) then diff --git a/fileseacher.lua b/fileseacher.lua deleted file mode 100644 index 137ce4621..000000000 --- a/fileseacher.lua +++ /dev/null @@ -1,161 +0,0 @@ -require "rendertext" -require "keys" -require "graphics" - -FileSeacher = { - -- font for displaying file/dir names - face = freetype.newBuiltinFace("sans", 25), - fhash = "s25", - -- font for page title - tface = freetype.newBuiltinFace("Helvetica-BoldOblique", 32), - tfhash = "hbo32", - -- font for paging display - sface = freetype.newBuiltinFace("sans", 16), - sfhash = "s16", - -- title height - title_H = 45, - -- spacing between lines - spacing = 40, - -- foot height - foot_H = 27, - - x_input = 50, - -- state buffer - fonts = {"sans", "cjk", "mono", - "Courier", "Courier-Bold", "Courier-Oblique", "Courier-BoldOblique", - "Helvetica", "Helvetica-Oblique", "Helvetica-BoldOblique", - "Times-Roman", "Times-Bold", "Times-Italic", "Times-BoldItalic",}, - items = 14, - page = 1, - current = 2, - oldcurrent = 1, -} - -function FileSeacher:init() - self.items = #self.fonts - --@TODO check this 17.02 2012 - self.face = freetype.newBuiltinFace("sans", 25), - table.sort(self.fonts) -end - - -function FileSeacher:choose(ypos, height) - local perpage = math.floor(height / self.spacing) - 2 - local pagedirty = true - local markerdirty = false - - local prevItem = function () - if self.current == 1 then - if self.page > 1 then - self.current = perpage - self.page = self.page - 1 - pagedirty = true - end - else - self.current = self.current - 1 - markerdirty = true - end - end - - local nextItem = function () - if self.current == perpage then - if self.page < (self.items / perpage) then - self.current = 1 - self.page = self.page + 1 - pagedirty = true - end - else - if self.page ~= math.floor(self.items / perpage) + 1 - or self.current + (self.page-1)*perpage < self.items then - self.current = self.current + 1 - markerdirty = true - end - end - end - - - while true do - if pagedirty then - fb.bb:paintRect(0, ypos, fb.bb:getWidth(), height, 0) - - -- draw menu title - renderUtf8Text(fb.bb, 30, ypos + self.title_H, self.tface, self.tfhash, - "[ Fonts Menu ]", true) - - local c - for c = 1, perpage do - local i = (self.page - 1) * perpage + c - if i <= self.items then - y = ypos + self.title_H + (self.spacing * c) - renderUtf8Text(fb.bb, 50, y, self.face, self.fhash, self.fonts[i], true) - end - end - y = ypos + self.title_H + (self.spacing * perpage) + self.foot_H - x = (fb.bb:getWidth() / 2) - 50 - renderUtf8Text(fb.bb, x, y, self.sface, self.sfhash, - "Page "..self.page.." of "..(math.floor(self.items / perpage)+1), true) - markerdirty = true - end - - if markerdirty then - if not pagedirty then - if self.oldcurrent > 0 then - y = ypos + self.title_H + (self.spacing * self.oldcurrent) + 10 - fb.bb:paintRect(30, y, fb.bb:getWidth() - 60, 3, 0) - fb:refresh(1, 30, y, fb.bb:getWidth() - 60, 3) - end - end - -- draw new marker line - y = ypos + self.title_H + (self.spacing * self.current) + 10 - fb.bb:paintRect(30, y, fb.bb:getWidth() - 60, 3, 15) - if not pagedirty then - fb:refresh(1, 30, y, fb.bb:getWidth() - 60, 3) - end - self.oldcurrent = self.current - markerdirty = false - 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 - if ev.code == KEY_FW_UP then - prevItem() - elseif ev.code == KEY_FW_DOWN then - nextItem() - elseif ev.code == KEY_PGFWD then - if self.page < (self.items / perpage) then - if self.current + self.page*perpage > self.items then - self.current = self.items - self.page*perpage - end - self.page = self.page + 1 - pagedirty = true - else - self.current = self.items - (self.page-1)*perpage - markerdirty = true - end - elseif ev.code == KEY_PGBCK then - if self.page > 1 then - self.page = self.page - 1 - pagedirty = true - else - self.current = 1 - markerdirty = true - end - elseif ev.code == KEY_F then - self.x_input = self.x_input + 10 - y = ypos + self.title_H + (self.spacing) - renderUtf8Text(fb.bb, self.x_input, y, self.face, self.fhash, "f", true) - fb:refresh(1, x_input, ypos, fb.bb:getWidth(), height) - elseif ev.code == KEY_ENTER or ev.code == KEY_FW_PRESS then - local newface = self.fonts[perpage*(self.page-1)+self.current] - return newface - elseif ev.code == KEY_BACK then - return nil - end - end - end -end diff --git a/filesearcher.lua b/filesearcher.lua index 3f819e941..ac37e5dfe 100644 --- a/filesearcher.lua +++ b/filesearcher.lua @@ -1,60 +1,43 @@ require "rendertext" require "keys" require "graphics" -require "fontchooser" -require "inputbox" FileSearcher = { - -- Class vars: - -- font for displaying file/dir names face = freetype.newBuiltinFace("sans", 25), fhash = "s25", + -- font for page title + tface = freetype.newBuiltinFace("Helvetica-BoldOblique", 32), + tfhash = "hbo32", -- font for paging display sface = freetype.newBuiltinFace("sans", 16), sfhash = "s16", + -- title height + title_H = 45, -- spacing between lines spacing = 40, + -- foot height + foot_H = 27, -- state buffer - dirs = nil, - files = nil, - items = 0, - path = "", + fonts = {"sans", "cjk", "mono", + "Courier", "Courier-Bold", "Courier-Oblique", "Courier-BoldOblique", + "Helvetica", "Helvetica-Oblique", "Helvetica-BoldOblique", + "Times-Roman", "Times-Bold", "Times-Italic", "Times-BoldItalic",}, + items = 14, page = 1, - current = 1, - oldcurrent = 0, + current = 2, + oldcurrent = 1, } -function FileSearcher:readdir() - self.dirs = {} - self.files = {} - for f in lfs.dir(self.path) do - if lfs.attributes(self.path.."/"..f, "mode") == "directory" and f ~= "." and not string.match(f, "^%.[^.]") then - table.insert(self.dirs, f) - elseif string.match(f, ".+%.[pP][dD][fF]$") then - table.insert(self.files, f) - end - end - table.sort(self.dirs) - table.sort(self.files) -end - -function FileSearcher: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 +function FileSearcher:init() + self.items = #self.fonts + table.sort(self.fonts) end -function FileSearcher:choose(ypos, height) - local perpage = math.floor(height / self.spacing) - 1 +function FileSearcher:choose(ypos, height, keywords) + local perpage = math.floor(height / self.spacing) - 2 local pagedirty = true local markerdirty = false @@ -87,59 +70,59 @@ function FileSearcher:choose(ypos, height) end end + while true do if pagedirty then fb.bb:paintRect(0, ypos, fb.bb:getWidth(), height, 0) + + -- draw menu title + renderUtf8Text(fb.bb, 30, ypos + self.title_H, self.tface, self.tfhash, + "Search Result for "..keywords, true) + local c for c = 1, perpage do - local i = (self.page - 1) * perpage + c - if i <= #self.dirs then - -- resembles display in midnight commander: adds "/" prefix for directories - renderUtf8Text(fb.bb, 39, ypos + self.spacing*c, self.face, self.fhash, "/", true) - renderUtf8Text(fb.bb, 50, ypos + self.spacing*c, self.face, self.fhash, self.dirs[i], true) - elseif i <= self.items then - renderUtf8Text(fb.bb, 50, ypos + self.spacing*c, self.face, self.fhash, self.files[i-#self.dirs], true) + local i = (self.page - 1) * perpage + c + if i <= self.items then + y = ypos + self.title_H + (self.spacing * c) + renderUtf8Text(fb.bb, 50, y, self.face, self.fhash, self.fonts[i], true) end end - renderUtf8Text(fb.bb, 39, ypos + self.spacing * perpage + 32, self.sface, self.sfhash, + y = ypos + self.title_H + (self.spacing * perpage) + self.foot_H + x = (fb.bb:getWidth() / 2) - 50 + renderUtf8Text(fb.bb, x, y, self.sface, self.sfhash, "Page "..self.page.." of "..(math.floor(self.items / perpage)+1), true) markerdirty = true end + if markerdirty then if not pagedirty then if self.oldcurrent > 0 then - fb.bb:paintRect(30, ypos + self.spacing*self.oldcurrent + 10, fb.bb:getWidth() - 60, 3, 0) - fb:refresh(1, 30, ypos + self.spacing*self.oldcurrent + 10, fb.bb:getWidth() - 60, 3) + y = ypos + self.title_H + (self.spacing * self.oldcurrent) + 10 + fb.bb:paintRect(30, y, fb.bb:getWidth() - 60, 3, 0) + fb:refresh(1, 30, y, fb.bb:getWidth() - 60, 3) end end - fb.bb:paintRect(30, ypos + self.spacing*self.current + 10, fb.bb:getWidth() - 60, 3, 15) + -- draw new marker line + y = ypos + self.title_H + (self.spacing * self.current) + 10 + fb.bb:paintRect(30, y, fb.bb:getWidth() - 60, 3, 15) if not pagedirty then - fb:refresh(1, 30, ypos + self.spacing*self.current + 10, fb.bb:getWidth() - 60, 3) + fb:refresh(1, 30, y, fb.bb:getWidth() - 60, 3) end self.oldcurrent = self.current markerdirty = false 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 - ev.code = adjustFWKey(ev.code) if ev.code == KEY_FW_UP then prevItem() elseif ev.code == KEY_FW_DOWN then nextItem() - elseif ev.code == KEY_F then - FontChooser:init() - newfont = FontChooser:choose(0, height) - if newfont ~= nil then - self.face = freetype.newBuiltinFace(newfont, 25) - clearglyphcache() - end - pagedirty = true - elseif ev.code == KEY_S then - InputBox:input() elseif ev.code == KEY_PGFWD then if self.page < (self.items / perpage) then if self.current + self.page*perpage > self.items then @@ -160,17 +143,8 @@ function FileSearcher:choose(ypos, height) markerdirty = true end elseif ev.code == KEY_ENTER or ev.code == KEY_FW_PRESS then - local newdir = self.dirs[perpage*(self.page-1)+self.current] - if newdir == ".." then - local path = string.gsub(self.path, "(.*)/[^/]+/?$", "%1") - self:setPath(path) - elseif newdir then - local path = self.path.."/"..newdir - self:setPath(path) - else - return self.path.."/"..self.files[perpage*(self.page-1)+self.current - #self.dirs] - end - pagedirty = true + local newface = self.fonts[perpage*(self.page-1)+self.current] + return newface elseif ev.code == KEY_BACK then return nil end diff --git a/inputbox.lua b/inputbox.lua index a8647adc9..aaf2a5f9c 100644 --- a/inputbox.lua +++ b/inputbox.lua @@ -63,7 +63,7 @@ function InputBox:delChar() self.input_string = self.input_string:sub(0,-2) end -function InputBox:input(ypos, height) +function InputBox:input(ypos, height, title) local pagedirty = true self.input_start_y = ypos + 35 self.input_cur_x = self.input_start_x @@ -77,7 +77,7 @@ function InputBox:input(ypos, height) -- 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) + title, true) markerdirty = true end @@ -149,11 +149,15 @@ function InputBox:input(ypos, height) elseif ev.code == KEY_PGFWD then elseif ev.code == KEY_PGBCK then elseif ev.code == KEY_ENTER or ev.code == KEY_FW_PRESS then - return self.input_string + if self.input_string == "" then + return nil + else + return self.input_string + end elseif ev.code == KEY_DEL then self:delChar() elseif ev.code == KEY_BACK then - return "" + return nil end end end From f9804a1c9258857f83c2c09aa6370b20ea261cab Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Sun, 19 Feb 2012 09:54:52 +0800 Subject: [PATCH 7/8] searcher demo finished! waiting for refractory. --- filechooser.lua | 1 + filesearcher.lua | 72 ++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 65 insertions(+), 8 deletions(-) diff --git a/filechooser.lua b/filechooser.lua index ecec641a3..19ca9d382 100644 --- a/filechooser.lua +++ b/filechooser.lua @@ -188,6 +188,7 @@ function FileChooser:choose(ypos, height) end pagedirty = true elseif ev.code == KEY_S then + -- invoke search input keywords = InputBox:input(height-100, 100, "Search:") if keywords then -- display search result according to keywords diff --git a/filesearcher.lua b/filesearcher.lua index ac37e5dfe..59fffb5e9 100644 --- a/filesearcher.lua +++ b/filesearcher.lua @@ -19,7 +19,11 @@ FileSearcher = { -- foot height foot_H = 27, + x_input = 50, -- state buffer + dirs = {}, + files = {}, + result = {}, fonts = {"sans", "cjk", "mono", "Courier", "Courier-Bold", "Courier-Oblique", "Courier-BoldOblique", "Helvetica", "Helvetica-Oblique", "Helvetica-BoldOblique", @@ -30,9 +34,53 @@ FileSearcher = { oldcurrent = 1, } -function FileSearcher:init() - self.items = #self.fonts - table.sort(self.fonts) +function FileSearcher:readdir() + self.dirs = {self.path} + self.files = {} + while #self.dirs ~= 0 do + new_dirs = {} + -- handle each dir + for __, d in pairs(self.dirs) do + -- handle files in d + for f in lfs.dir(d) do + if lfs.attributes(self.path.."/"..f, "mode") == "directory" + and f ~= "." and f~= ".." and not string.match(f, "^%.[^.]") then + table.insert(new_dirs, d.."/"..f) + elseif string.match(f, ".+%.[pP][dD][fF]$") then + file_entry = {dir=d, name=f,} + table.insert(self.files, file_entry) + --print("file:"..d.."/"..f) + end + end + end + self.dirs = new_dirs + end +end + +function FileSearcher:setPath(newPath) + self.path = newPath + self:readdir() + self.items = #self.files + --@TODO check none found 19.02 2012 + if self.items == 0 then + return nil + end + self.page = 1 + self.current = 1 + return true +end + +function FileSearcher:setSearchResult(keywords) + self.result = self.files + self.items = #self.result + self.page = 1 + self.current = 1 +end + +function FileSearcher:init(keywords) + self:setPath("/home/dave/documents/kindle/backup/documents") + self:setSearchResult(keywords) + --@TODO check this 17.02 2012 end @@ -77,20 +125,25 @@ function FileSearcher:choose(ypos, height, keywords) -- draw menu title renderUtf8Text(fb.bb, 30, ypos + self.title_H, self.tface, self.tfhash, - "Search Result for "..keywords, true) + "Search Result for"..keywords, true) + -- draw results local c for c = 1, perpage do local i = (self.page - 1) * perpage + c if i <= self.items then y = ypos + self.title_H + (self.spacing * c) - renderUtf8Text(fb.bb, 50, y, self.face, self.fhash, self.fonts[i], true) + renderUtf8Text(fb.bb, 50, y, self.face, self.fhash, + self.result[i].name, true) end end + + -- draw footer y = ypos + self.title_H + (self.spacing * perpage) + self.foot_H x = (fb.bb:getWidth() / 2) - 50 + all_page = (math.floor(self.items / perpage)+1) renderUtf8Text(fb.bb, x, y, self.sface, self.sfhash, - "Page "..self.page.." of "..(math.floor(self.items / perpage)+1), true) + "Page "..self.page.." of "..all_page, true) markerdirty = true end @@ -142,9 +195,12 @@ function FileSearcher:choose(ypos, height, keywords) self.current = 1 markerdirty = true end + elseif ev.code == KEY_S then + input = InputBox:input(height-100, 100) elseif ev.code == KEY_ENTER or ev.code == KEY_FW_PRESS then - local newface = self.fonts[perpage*(self.page-1)+self.current] - return newface + -- return full file path + file_entry = self.files[perpage*(self.page-1)+self.current] + return file_entry.dir .. "/" .. file_entry.name elseif ev.code == KEY_BACK then return nil end From 060ad5cb01a88966ee57d331e448ef6b2016c71a Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Sun, 19 Feb 2012 14:41:44 +0800 Subject: [PATCH 8/8] finished search feature! --- filechooser.lua | 10 ++++- filesearcher.lua | 67 ++++++++++++++++++++---------- inputbox.lua | 106 +++++++++++++++++++++++++---------------------- 3 files changed, 110 insertions(+), 73 deletions(-) diff --git a/filechooser.lua b/filechooser.lua index 19ca9d382..bd2fedbbc 100644 --- a/filechooser.lua +++ b/filechooser.lua @@ -190,8 +190,14 @@ function FileChooser:choose(ypos, height) elseif ev.code == KEY_S then -- invoke search input 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 + --[[ + ---------------------------------------------------------------- + || uncomment following line and set the correct path if you want + || to test search feature in EMU mode + ---------------------------------------------------------------- + --]] + --FileSearcher:init("/home/dave/documents/kindle/backup/documents") FileSearcher:init() file = FileSearcher:choose(ypos, height, keywords) if file then diff --git a/filesearcher.lua b/filesearcher.lua index 59fffb5e9..d59e0cd49 100644 --- a/filesearcher.lua +++ b/filesearcher.lua @@ -19,18 +19,13 @@ FileSearcher = { -- foot height foot_H = 27, - x_input = 50, -- state buffer dirs = {}, files = {}, result = {}, - fonts = {"sans", "cjk", "mono", - "Courier", "Courier-Bold", "Courier-Oblique", "Courier-BoldOblique", - "Helvetica", "Helvetica-Oblique", "Helvetica-BoldOblique", - "Times-Roman", "Times-Bold", "Times-Italic", "Times-BoldItalic",}, - items = 14, - page = 1, - current = 2, + items = 0, + page = 0, + current = 1, oldcurrent = 1, } @@ -71,16 +66,27 @@ function FileSearcher:setPath(newPath) end function FileSearcher:setSearchResult(keywords) - self.result = self.files + self.result = {} + if keywords == " " then -- one space to show all files + self.result = self.files + else + for __,f in pairs(self.files) do + if string.find(string.lower(f.name), keywords) then + table.insert(self.result, f) + end + end + end self.items = #self.result self.page = 1 self.current = 1 end -function FileSearcher:init(keywords) - self:setPath("/home/dave/documents/kindle/backup/documents") - self:setSearchResult(keywords) - --@TODO check this 17.02 2012 +function FileSearcher:init(search_path) + if search_path then + self:setPath(search_path) + else + self:setPath("/mnt/us/documents") + end end @@ -118,23 +124,34 @@ function FileSearcher:choose(ypos, height, keywords) end end + self:setSearchResult(keywords) while true do if pagedirty then + markerdirty = true fb.bb:paintRect(0, ypos, fb.bb:getWidth(), height, 0) -- draw menu title renderUtf8Text(fb.bb, 30, ypos + self.title_H, self.tface, self.tfhash, - "Search Result for"..keywords, true) + "Search Result for: "..keywords, true) -- draw results local c - for c = 1, perpage do - local i = (self.page - 1) * perpage + c - if i <= self.items then - y = ypos + self.title_H + (self.spacing * c) - renderUtf8Text(fb.bb, 50, y, self.face, self.fhash, - self.result[i].name, true) + if self.items == 0 then -- nothing found + y = ypos + self.title_H + self.spacing * 2 + renderUtf8Text(fb.bb, 20, y, self.face, self.fhash, + "Sorry, your keyword did not match any documents.", true) + renderUtf8Text(fb.bb, 20, y + self.spacing, self.face, self.fhash, + "Please try a different keyword.", true) + markerdirty = false + else -- found something, draw it + for c = 1, perpage do + local i = (self.page - 1) * perpage + c + if i <= self.items then + y = ypos + self.title_H + (self.spacing * c) + renderUtf8Text(fb.bb, 50, y, self.face, self.fhash, + self.result[i].name, true) + end end end @@ -144,7 +161,6 @@ function FileSearcher:choose(ypos, height, keywords) all_page = (math.floor(self.items / perpage)+1) renderUtf8Text(fb.bb, x, y, self.sface, self.sfhash, "Page "..self.page.." of "..all_page, true) - markerdirty = true end if markerdirty then @@ -196,7 +212,14 @@ function FileSearcher:choose(ypos, height, keywords) markerdirty = true end elseif ev.code == KEY_S then - input = InputBox:input(height-100, 100) + old_keywords = keywords + keywords = InputBox:input(height-100, 100, "Search:", old_keywords) + if keywords then + self:setSearchResult(keywords) + else + keywords = old_keywords + end + pagedirty = true elseif ev.code == KEY_ENTER or ev.code == KEY_FW_PRESS then -- return full file path file_entry = self.files[perpage*(self.page-1)+self.current] diff --git a/inputbox.lua b/inputbox.lua index aaf2a5f9c..2c50d6882 100644 --- a/inputbox.lua +++ b/inputbox.lua @@ -4,84 +4,92 @@ 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_cur_x = nil, -- points to the start of next input pos input_bg = 1, input_string = "", - -- state buffer - dirs = nil, - files = nil, - items = 0, - path = "", - page = 1, - current = 1, - oldcurrent = 0, + + -- font for displaying input content + face = freetype.newBuiltinFace("mono", 25), + fhash = "m25", + fheight = 25, + fwidth = 16, } -function InputBox:setPath(newPath) - self.path = newPath - self:readdir() - self.items = #self.dirs + #self.files - if self.items == 0 then - return nil +function InputBox:setDefaultInput(text) + self.input_string = "" + self:addString(text) + --renderUtf8Text(fb.bb, self.input_start_x, self.input_start_y, + --self.face, self.fhash, text, true) + --self.input_cur_x = self.input_start_x + (string.len(text) * self.fwidth) + --self.input_string = text +end + +function InputBox:addString(str) + for i = 1, #str do + self:addChar(str:sub(i,i)) 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 - self.input_string = self.input_string .. text +function InputBox:addChar(char) + renderUtf8Text(fb.bb, self.input_cur_x, self.input_start_y, self.face, self.fhash, + char, true) + fb:refresh(1, self.input_cur_x, self.input_start_y-19, self.fwidth, self.fheight) + self.input_cur_x = self.input_cur_x + self.fwidth + self.input_string = self.input_string .. char 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 + self.input_cur_x = self.input_cur_x - self.fwidth --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) + fb.bb:paintRect(self.input_cur_x, self.input_start_y-19, + self.fwidth, self.fheight, self.input_bg) + fb:refresh(1, self.input_cur_x, self.input_start_y-19, self.fwidth, self.fheight) self.input_string = self.input_string:sub(0,-2) end -function InputBox:input(ypos, height, title) +function InputBox:drawBox(ypos, w, h, title) + -- 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) + -- draw input title + renderUtf8Text(fb.bb, 35, self.input_start_y, self.face, self.fhash, + title, true) +end + + +--[[ + || d_text default to nil (used to set default text in input slot) +--]] +function InputBox:input(ypos, height, title, d_text) local pagedirty = true + -- do some initilization self.input_start_y = ypos + 35 self.input_cur_x = self.input_start_x + if d_text then -- if specified default text, draw it + w = fb.bb:getWidth() - 40 + h = height - 45 + self:drawBox(ypos, w, h, title) + self:setDefaultInput(d_text) + fb:refresh(1, 20, ypos, w, h) + pagedirty = false + else -- otherwise, leave the draw task to the main loop + self.input_string = "" + end + 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, - title, true) - markerdirty = true - end - - if pagedirty then + self:drawBox(ypos, w, h, title) fb:refresh(1, 20, ypos, w, h) pagedirty = false end