Refonte pour utiliser le systeme de GUI #112

Merged
kazhnuz merged 102 commits from feat/gui into master 2022-01-06 19:15:16 +01:00
4 changed files with 87 additions and 0 deletions
Showing only changes of commit 39d11596f0 - Show all commits

View 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

View 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

View 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

View 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