-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtextureButton.lua
38 lines (33 loc) · 1.14 KB
/
textureButton.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
local TextureButton = {}
TextureButton.__index = TextureButton
function newTextureButton(imageName)
local tb = {}
tb.imageName = imageName:sub(1, #imageName - 4)
tb.textureImage = love.graphics.newImage(TEXTURE_DIRECTORY..imageName)
tb.x = 0
tb.y = 0
tb.imageWidth= tb.textureImage:getWidth()
tb.scaleFactor = TEXTURE_BUTTON_WIDTH/tb.imageWidth
return setmetatable(tb, TextureButton)
end
function TextureButton:update()
if mouseDown
and mouseX > self.x
and mouseX < self.x + TEXTURE_BUTTON_WIDTH
and mouseY > self.y
and mouseY < self.y + TEXTURE_BUTTON_WIDTH
then
pSystem:setTexture(self.textureImage)
end
end
function TextureButton:draw()
love.graphics.setColor(.25,.25,.25,1)
love.graphics.rectangle('line', self.x, self.y, TEXTURE_BUTTON_WIDTH, TEXTURE_BUTTON_WIDTH)
love.graphics.draw(self.textureImage, self.x, self.y, 0, self.scaleFactor, self.scaleFactor)
love.graphics.setColor(WHITE)
love.graphics.printf(self.imageName, self.x, self.y, TEXTURE_BUTTON_WIDTH, 'center')
end
function TextureButton:setXY(x, y)
self.x = x
self.y = y
end