mirror of
https://github.com/linux-man/LoveFrames.git
synced 2024-10-11 22:34:17 +00:00
112 lines
2.6 KiB
Lua
112 lines
2.6 KiB
Lua
--[[------------------------------------------------
|
|
-- LÖVE Frames --
|
|
-- By Nikolai Resokav --
|
|
--]]------------------------------------------------
|
|
|
|
-- progress bar class
|
|
image = class("image", base)
|
|
image:include(loveframes.templates.default)
|
|
|
|
--[[---------------------------------------------------------
|
|
- func: initialize()
|
|
- desc: initializes the object
|
|
--]]---------------------------------------------------------
|
|
function image:initialize()
|
|
|
|
self.type = "image"
|
|
self.width = 0
|
|
self.height = 0
|
|
self.internal = false
|
|
self.image = nil
|
|
self.imagecolor = nil
|
|
|
|
end
|
|
|
|
--[[---------------------------------------------------------
|
|
- func: update(deltatime)
|
|
- desc: updates the object
|
|
--]]---------------------------------------------------------
|
|
function image:update(dt)
|
|
|
|
if self.visible == false then
|
|
if self.alwaysupdate == false then
|
|
return
|
|
end
|
|
end
|
|
|
|
-- move to parent if there is a parent
|
|
if self.parent ~= nil then
|
|
self.x = self.parent.x + self.staticx
|
|
self.y = self.parent.y + self.staticy
|
|
end
|
|
|
|
if self.Update then
|
|
self.Update(self, dt)
|
|
end
|
|
|
|
end
|
|
|
|
--[[---------------------------------------------------------
|
|
- func: draw()
|
|
- desc: draws the object
|
|
--]]---------------------------------------------------------
|
|
function image:draw()
|
|
|
|
if self.visible == false then
|
|
return
|
|
end
|
|
|
|
-- skin variables
|
|
local index = loveframes.config["ACTIVESKIN"]
|
|
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
|
local selfskin = self.skin
|
|
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
|
|
|
|
loveframes.drawcount = loveframes.drawcount + 1
|
|
self.draworder = loveframes.drawcount
|
|
|
|
if self.Draw ~= nil then
|
|
self.Draw(self)
|
|
else
|
|
skin.DrawImage(self)
|
|
end
|
|
|
|
local image = self.image
|
|
local color = self.imagecolor
|
|
|
|
if color then
|
|
love.graphics.setColor(unpack(color))
|
|
love.graphics.draw(image)
|
|
else
|
|
love.graphics.setColor(255, 255, 255, 255)
|
|
love.graphics.draw(image, self.x, self.y)
|
|
end
|
|
|
|
end
|
|
|
|
--[[---------------------------------------------------------
|
|
- func: SetImage(image)
|
|
- desc: sets the object's image
|
|
--]]---------------------------------------------------------
|
|
function image:SetImage(image)
|
|
|
|
if type(image) == "string" then
|
|
self.image = love.graphics.newImage(image)
|
|
else
|
|
self.image = image
|
|
end
|
|
|
|
self.width = self.image:getWidth()
|
|
self.height = self.image:getHeight()
|
|
|
|
end
|
|
|
|
--[[---------------------------------------------------------
|
|
- func: SetColor(table)
|
|
- desc: sets the object's color
|
|
--]]---------------------------------------------------------
|
|
function image:SetColor(t)
|
|
|
|
self.imagecolor = t
|
|
|
|
end |