From 39d11596f09231706e757e8f0a8a91e6c6f0e132 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 22 Aug 2021 16:45:43 +0200 Subject: [PATCH] feat: add some special guiElements --- .../birb/modules/gui/elements/assets.lua | 16 ++++++++++ .../birb/modules/gui/elements/color.lua | 19 ++++++++++++ .../birb/modules/gui/elements/drawable.lua | 30 +++++++++++++++++++ .../birb/modules/gui/elements/text.lua | 22 ++++++++++++++ 4 files changed, 87 insertions(+) create mode 100644 sonic-radiance.love/birb/modules/gui/elements/assets.lua create mode 100644 sonic-radiance.love/birb/modules/gui/elements/color.lua create mode 100644 sonic-radiance.love/birb/modules/gui/elements/drawable.lua create mode 100644 sonic-radiance.love/birb/modules/gui/elements/text.lua diff --git a/sonic-radiance.love/birb/modules/gui/elements/assets.lua b/sonic-radiance.love/birb/modules/gui/elements/assets.lua new file mode 100644 index 0000000..2e05410 --- /dev/null +++ b/sonic-radiance.love/birb/modules/gui/elements/assets.lua @@ -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 \ No newline at end of file diff --git a/sonic-radiance.love/birb/modules/gui/elements/color.lua b/sonic-radiance.love/birb/modules/gui/elements/color.lua new file mode 100644 index 0000000..f1aa94f --- /dev/null +++ b/sonic-radiance.love/birb/modules/gui/elements/color.lua @@ -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 \ No newline at end of file diff --git a/sonic-radiance.love/birb/modules/gui/elements/drawable.lua b/sonic-radiance.love/birb/modules/gui/elements/drawable.lua new file mode 100644 index 0000000..76c1031 --- /dev/null +++ b/sonic-radiance.love/birb/modules/gui/elements/drawable.lua @@ -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 \ No newline at end of file diff --git a/sonic-radiance.love/birb/modules/gui/elements/text.lua b/sonic-radiance.love/birb/modules/gui/elements/text.lua new file mode 100644 index 0000000..ebd4ffa --- /dev/null +++ b/sonic-radiance.love/birb/modules/gui/elements/text.lua @@ -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 \ No newline at end of file