Files
OmicronFrames/src/types/statusbar.lua
2023-03-15 17:13:01 +01:00

72 lines
2.5 KiB
Lua

-- Copyright 2023 <omicron.me@protonmail.com>
--
-- This file is part of Omicron Frames
--
-- Omicron Frames is free software: you can redistribute it and/or modify it
-- under the terms of the GNU General Public License as published by the Free
-- Software Foundation, either version 3 of the License, or (at your option)
-- any later version.
--
-- Omicron Frames is distributed in the hope that it will be useful, but
-- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
-- more details.
--
-- You should have received a copy of the GNU General Public License along with
-- Omicron Frames. If not, see <https://www.gnu.org/licenses/>.
local omi = select(2, ...)
local types = omi.GetModule("types")
types.StatusBar = types.CreateClass("StatusBar")
local StatusBar = types.StatusBar
function StatusBar:Init(parent, width, height)
-- parent: the parent frame
-- pct: nil if no percent value is shown, otherwise "left", "right" or "center"
-- value: nil if no value is shown, otherwise "left", "right" or "center"
-- text: nil if no text is shown, otherwise "left", "right" or "center"
-- stack: another StatusBar we will stack under
self.parent = parent
local parentFrame = parent.secureFrame
local bar = CreateFrame("StatusBar", nil, parentFrame)
bar:SetFrameStrata("MEDIUM")
bar:SetFrameLevel(10)
bar:SetPoint("TOPLEFT", parentFrame, "TOPLEFT", 0, 0)
bar:SetSize(width, height)
bar:SetStatusBarTexture("Interface\\Addons\\OmicronFrames\\media\\textures\\bar_subtle_diagonal")
bar:GetStatusBarTexture():SetHorizTile(false)
bar:GetStatusBarTexture():SetVertTile(false)
self.bar = bar
local bg = bar:CreateTexture(nil, "BACKGROUND")
bg:SetTexture("Interface\\Addons\\OmicronFrames\\media\\textures\\bar_subtle_diagonal")
bg:SetAllPoints(true)
self.bg = bg
self:SetRange(0, 1)
self:SetValue(1)
bar:Show()
end
function StatusBar:SetRange(min, max)
self.bar:SetMinMaxValues(min, max)
end
function StatusBar:SetValue(value)
self.bar:SetValue(value)
end
function StatusBar:SetInterpolatedColor(start, stop, progress)
local r = start[1] + (stop[1] - start[1])*progress
local g = start[2] + (stop[2] - start[2])*progress
local b = start[3] + (stop[3] - start[3])*progress
self:SetColor(r, g, b)
end
function StatusBar:SetColor(r, g, b)
self.bar:SetStatusBarColor(r, g, b)
self.bg:SetVertexColor(0.2*r, 0.2*g, 0.2*b)
end