diff --git a/code/ui.lua b/code/ui.lua index b39f115..94b4056 100644 --- a/code/ui.lua +++ b/code/ui.lua @@ -5,6 +5,30 @@ function addElement(self) self.id = #UIElement end +function drawTextBox(text,x,y,color,background_color) + local c1, c2, c3, a = love.graphics.getColor() + local width = locale_font:getWidth(text) + local height = locale_font:getHeight(text) + local margin = 5 + love.graphics.setColor(unpack(color)) + love.graphics.rectangle("fill", + x-1, + y-1, + width+margin*2+2, + height+margin*2+2 + ) + love.graphics.setColor(unpack(background_color)) + love.graphics.rectangle("fill", + x, + y, + width+margin*2, + height+margin*2 + ) + love.graphics.setColor(unpack(color)) + love.graphics.print(text, x+margin, y+margin) + love.graphics.setColor(c1,c2,c3,a) +end + require "code/ui/button" require "code/ui/dialog" require "code/ui/prompt" diff --git a/code/ui/prompt.lua b/code/ui/prompt.lua index 5937524..fc0bf7d 100644 --- a/code/ui/prompt.lua +++ b/code/ui/prompt.lua @@ -53,28 +53,13 @@ function Prompt:textinput(text) end function Prompt:draw() - local c1, c2, c3, a = love.graphics.getColor() - local text = self.name .. ": " .. self.input - local width = locale_font:getWidth(text) - local height = locale_font:getHeight(text) - local margin = 10 - love.graphics.setColor(unpack(self.color)) - love.graphics.rectangle("fill", - self.pos.x-margin-1, - self.pos.y-1, - width+margin*2+2, - height+margin+2 - ) - love.graphics.setColor(unpack(self.background_color)) - love.graphics.rectangle("fill", - self.pos.x-margin, + drawTextBox( + self.name .. ": " .. self.input, + self.pos.x, self.pos.y, - width+margin*2, - height+margin + self.color, + self.background_color ) - love.graphics.setColor(unpack(self.color)) - love.graphics.print(text, self.pos.x, self.pos.y) - love.graphics.setColor(c1,c2,c3,a) end function Prompt:activate()