----------------------------- -- Levak ©2011 -------------- -- http://levak.free.fr/ ---- -- levak92@gmail.com -------- ----------------------------- ------ Request Request = class(Screen) Request.__index = Request function Request.create(title, text, var, limit, gtype, callback) local request = class(Screen) setmetatable(request, Request) request.title = title request.text = text request.limit = limit request.gtype = gtype request.var = var request.callback = callback platform.gc():setFont("sansserif", "r", fnormal) request.strWidth = math.max(platform.gc():getStringWidth(title), platform.gc():getStringWidth(text)) request.strHeight = 2*(platform.gc():getStringHeight(title) + platform.gc():getStringHeight(text)) navPos = {x = (platform.window:width() + request.strWidth)/2, y = platform.window:height()/2} request.items = {Button.create(0, 0, 1, 3, normal, function() request:enterKey() end, nil, nextButton)} initVKB((platform.window:height() + request.strHeight)/2 , gtype) return request end function Request:paint(gc) local margin = normal local sX, sY = platform.window:width(), platform.window:height() gc:setFont("sansserif", "r", fnormal) gc:setPen("medium", "smooth") -- background gc:setColorRGB(220, 220, 220) gc:fillRect( (sX - self.strWidth - margin)/2, (sY - self.strHeight - margin)/2, self.strWidth + margin, self.strHeight + margin) -- titleBar & border gc:setColorRGB(0, 0, 0) gc:fillRect( (sX - self.strWidth - margin)/2, (sY - self.strHeight - margin)/2, self.strWidth + margin, 2*margin) gc:drawRect( (sX - self.strWidth - margin)/2, (sY - self.strHeight - margin)/2, self.strWidth + margin, self.strHeight + margin) -- textBox gc:setColorRGB(255, 255, 255) gc:fillRect( (sX - self.strWidth)/2, sY/2, self.strWidth - margin, 2*normal) gc:setColorRGB(0, 0, 0) gc:drawRect( (sX - self.strWidth)/2, sY/2, self.strWidth - margin, 2*normal) -- title text gc:setColorRGB(255, 255, 255) gc:drawString(self.title, (sX - self.strWidth - margin)/2, (sY - self.strHeight - margin)/2, "top") -- content text gc:setColorRGB(0, 0, 0) gc:drawString(self.text, (sX - self.strWidth)/2, (sY - self.strHeight)/2 + 2*margin, "top") gc:drawString(self.var, (sX - self.strWidth + margin)/2, sY/2, "top") for i,button in ipairs(self.items) do button:paint(gc) end if isWideScreen then for i,button in ipairs(VKB) do button:paint(gc) end end end function Request:charIn(ch) if self.gtype == "" and ((ch >= "a" and ch <= "z") or (ch >= "0" and ch <="9")) or self.gtype ~= "" and ((self.gtype == "alpha" and ch >= "a" and ch <= "z" ) or (self.gtype == "num" and ch >= "0" and ch <= "9" )) then if string.len(self.var) < self.limit then self.var = self.var..ch end end platform.window:invalidate() end function Request:backspaceKey() if string.len(self.var) > 0 then self.var = string.sub(self.var, 1, string.len(self.var)-1) end platform.window:invalidate() end function Request:clearKey() self.var = "" platform.window:invalidate() end function Request:enterKey() PullScreen() return self.callback(self.var) end function Request:escapeKey() PullScreen() end function Request:arrowKey(key) if key == "up" then elseif key == "down" then elseif key == "left" then elseif key == "right" then end platform.window:invalidate() end function Request:mouseDown(x, y) for i, button in ipairs(self.items) do if button:isActive(x, y) then self:enterKey() end end for i, button in ipairs(VKB) do if button:isActive(x, y) then button.fun(self) end end platform.window:invalidate() end -- non used events function Request:tabKey() end function Request:backtabKey() end function Request:contextMenu() end function Request:help() end function Request:mouseUp() end