----------------------------- -- Levak ©2011 -------------- -- http://levak.free.fr/ ---- -- levak92@gmail.com -------- ----------------------------- ------ Request Request = class(Screen) function Request:init(title, text, var, limit, gtype, callback) self.title = title self.text = text self.limit = limit self.gtype = gtype self.var = var self.callback = callback platform.gc():setFont("sansserif", "r", fnormal) self.strWidth = math.max(platform.gc():getStringWidth(title), platform.gc():getStringWidth(text)) if self.var then self.strHeight = 2*(platform.gc():getStringHeight(title) + platform.gc():getStringHeight(text)) else self.strHeight = platform.gc():getStringHeight(title) + platform.gc():getStringHeight(text) end navPos = {x = (platform.window:width() + self.strWidth)/2, y = platform.window:height()/2} self.items = {Button(0, 0, 1, 3, normal, function() self:enterKey() end, nil, nextButton)} initVKB((platform.window:height() + self.strHeight)/2 , gtype) 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 if self.var then 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) end -- 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") if self.var then gc:drawString(self.var, (sX - self.strWidth + margin)/2, sY/2, "top") end for i,button in ipairs(self.items) do button:paint(gc) end if isWideScreen and self.var 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