summaryrefslogtreecommitdiffhomepage
path: root/button.lua
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2016-08-22 02:24:32 +0200
committerAki <nthirtyone@gmail.com>2016-08-22 02:24:32 +0200
commit6e9aa28e70ec842db643a06609454fff54b5d86a (patch)
tree75aac8a30267f33f33fc808eda358f5b56af140c /button.lua
parent43fa5953e4c9f226c2579097b3f42bd97bc587c4 (diff)
downloadroflnauts-6e9aa28e70ec842db643a06609454fff54b5d86a.zip
roflnauts-6e9aa28e70ec842db643a06609454fff54b5d86a.tar.gz
roflnauts-6e9aa28e70ec842db643a06609454fff54b5d86a.tar.bz2
Werking!
Diffstat (limited to 'button.lua')
-rw-r--r--button.lua54
1 files changed, 54 insertions, 0 deletions
diff --git a/button.lua b/button.lua
new file mode 100644
index 0000000..925baf3
--- /dev/null
+++ b/button.lua
@@ -0,0 +1,54 @@
+-- `Button`
+-- Button used in `Menu`
+
+Button = {
+ text = "button",
+ focused = false,
+ x = 0,
+ y = 0
+}
+
+function Button:new(text)
+ local o = {}
+ setmetatable(o, self)
+ self.__index = self
+ o.text = text or self.text
+ return o
+end
+function Button:setPosition(x, y)
+ self.x = x or 0
+ self.y = y or 0
+ return self
+end
+function Button:getPosition() return self.x,self.y end
+function Button:focus()
+ self.focused = true
+end
+function Button:blur()
+ self.focused = false
+end
+function Button:active() end
+function Button:set(name, func)
+ if type(name) == "string" and type(func) == "function" then
+ self[name] = func
+ end
+ return self
+end
+function Button:draw(scale)
+ local x,y = self:getPosition()
+ if self.focused then
+ love.graphics.setColor(255, 128, 0, 255)
+ else
+ love.graphics.setColor(255, 255, 255, 255)
+ end
+ love.graphics.print(self.text, x*scale, y*scale, 0, scale, scale)
+end
+function Button:update(dt) end
+function Button:controlpressed(set, action, key)
+ if action == "attack" and self.focused then
+ self:active()
+ end
+end
+function Button:controlreleased(set, action, key) end
+
+return Button \ No newline at end of file