feat: add some special guiElements
This commit is contained in:
parent
dd0fcf2547
commit
39d11596f0
4 changed files with 87 additions and 0 deletions
16
sonic-radiance.love/birb/modules/gui/elements/assets.lua
Normal file
16
sonic-radiance.love/birb/modules/gui/elements/assets.lua
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
local Parent = require "birb.modules.gui.elements.drawable"
|
||||||
|
local AssetElement = Parent:extend()
|
||||||
|
|
||||||
|
function AssetElement:new(name, assetType, assetName, x, y,r,sx,sy,ox,oy, opacity, depth)
|
||||||
|
local gui = self:getGui()
|
||||||
|
local asset = gui.scene.assets[assetType][assetName]
|
||||||
|
assert(asset ~= nil, assetName .. ' (' .. assetType .. ") doesn't exist")
|
||||||
|
|
||||||
|
AssetElement.super.new(self, name, asset, x, y,r,sx,sy,ox,oy, opacity, depth)
|
||||||
|
end
|
||||||
|
|
||||||
|
function AssetElement:draw()
|
||||||
|
self.drawable:draw(self.x,self.y,self.r,self.sx,self.sy,self.ox,self.oy)
|
||||||
|
end
|
||||||
|
|
||||||
|
return AssetElement
|
19
sonic-radiance.love/birb/modules/gui/elements/color.lua
Normal file
19
sonic-radiance.love/birb/modules/gui/elements/color.lua
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
local Parent = require "birb.modules.gui.elements.parent"
|
||||||
|
local ColorElement = Parent:extend()
|
||||||
|
|
||||||
|
function ColorElement:new(name, r, g, b, opacity)
|
||||||
|
local w, h = core.screen:getDimensions()
|
||||||
|
ColorElement.super.new(self, name, self.x, self.y, w, h)
|
||||||
|
self.r = r or 1
|
||||||
|
self.g = g or 1
|
||||||
|
self.b = b or 1
|
||||||
|
self.opacity = opacity or 1
|
||||||
|
end
|
||||||
|
|
||||||
|
function ColorElement:draw()
|
||||||
|
love.graphics.setColor(self.r, self.g, self.b, self.opacity)
|
||||||
|
love.graphics.rectangle("fill", 0, 0, self.w, self.h)
|
||||||
|
utils.graphics.resetColor()
|
||||||
|
end
|
||||||
|
|
||||||
|
return ColorElement
|
30
sonic-radiance.love/birb/modules/gui/elements/drawable.lua
Normal file
30
sonic-radiance.love/birb/modules/gui/elements/drawable.lua
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
local Parent = require "birb.modules.gui.elements.parent"
|
||||||
|
local DrawableElement = Parent:extend()
|
||||||
|
|
||||||
|
function DrawableElement:new(name, drawable, x, y,r,sx,sy,ox,oy, opacity, depth)
|
||||||
|
self.drawable = drawable
|
||||||
|
|
||||||
|
local w, h = self.drawable:getDimensions()
|
||||||
|
DrawableElement.super.new(self, name, x, y, w, h)
|
||||||
|
self.r = r or 0
|
||||||
|
self.sx, self.sy = sx or 1, sy or 1
|
||||||
|
self.ox, self.oy = self:parseOrigin(ox, w), self:parseOrigin(oy, h)
|
||||||
|
self.opacity = opacity or 1
|
||||||
|
self.depth = depth or 0
|
||||||
|
end
|
||||||
|
|
||||||
|
function DrawableElement:parseOrigin(origin, size)
|
||||||
|
if (origin == "center") then
|
||||||
|
return size/2
|
||||||
|
elseif (origin == "end") then
|
||||||
|
return size
|
||||||
|
else
|
||||||
|
return origin or 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function DrawableElement:draw()
|
||||||
|
love.graphics.draw(self.drawable, self.x,self.y,self.r,self.sx,self.sy,self.ox,self.oy)
|
||||||
|
end
|
||||||
|
|
||||||
|
return DrawableElement
|
22
sonic-radiance.love/birb/modules/gui/elements/text.lua
Normal file
22
sonic-radiance.love/birb/modules/gui/elements/text.lua
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
local Parent = require "birb.modules.gui.elements.parent"
|
||||||
|
local TextElement = Parent:extend()
|
||||||
|
|
||||||
|
function TextElement:new(name, fontName, text, x, y, align, depth)
|
||||||
|
self.text = text
|
||||||
|
local gui = self:getGui()
|
||||||
|
self.font = gui.scene.assets.fonts[fontName]
|
||||||
|
|
||||||
|
TextElement.super.new(self, name, x, y, 1, 1)
|
||||||
|
self.align = align
|
||||||
|
self.depth = depth or 0
|
||||||
|
end
|
||||||
|
|
||||||
|
function TextElement:getText()
|
||||||
|
return self.text
|
||||||
|
end
|
||||||
|
|
||||||
|
function TextElement:draw()
|
||||||
|
self.font:draw(self:getText(), self.x, self.y, -1, self.align)
|
||||||
|
end
|
||||||
|
|
||||||
|
return TextElement
|
Loading…
Reference in a new issue