Gradient implementation

This commit is contained in:
NoM0Re
2025-03-01 17:14:36 +01:00
parent 46dac486c7
commit 2aea3b7a0d
4 changed files with 133 additions and 57 deletions
+109 -53
View File
@@ -19,6 +19,9 @@ local default = {
orientation = "HORIZONTAL", orientation = "HORIZONTAL",
inverse = false, inverse = false,
barColor = {1.0, 0.0, 0.0, 1.0}, barColor = {1.0, 0.0, 0.0, 1.0},
barColor2 = {1.0, 1.0, 0.0, 1.0},
enableGradient = false,
gradientOrientation = "HORIZONTAL",
backgroundColor = {0.0, 0.0, 0.0, 0.5}, backgroundColor = {0.0, 0.0, 0.0, 0.5},
spark = false, spark = false,
sparkWidth = 10, sparkWidth = 10,
@@ -68,10 +71,26 @@ local properties = {
type = "textureLSM", type = "textureLSM",
}, },
barColor = { barColor = {
display = L["Bar Color"], display = L["Bar Color/Gradient Start"],
setter = "Color", setter = "Color",
type = "color", type = "color",
}, },
barColor2 = {
display = L["Gradient End"],
setter = "SetBarColor2",
type = "color",
},
gradientOrientation = {
display = L["Gradient Orientation"],
setter = "SetGradientOrientation",
type = "list",
values = Private.gradient_orientations
},
enableGradient = {
display = L["Gradient Enabled"],
setter = "SetGradientEnabled",
type = "bool",
},
icon_visible = { icon_visible = {
display = {L["Icon"], L["Visibility"]}, display = {L["Icon"], L["Visibility"]},
setter = "SetIconVisible", setter = "SetIconVisible",
@@ -265,17 +284,15 @@ local barPrototype = {
self.directionInverse = (self.orientation == "HORIZONTAL_INVERSE") or (self.orientation == "VERTICAL") self.directionInverse = (self.orientation == "HORIZONTAL_INVERSE") or (self.orientation == "VERTICAL")
local TLx, TLy, BLx, BLy, TRx, TRy, BRx, BRy = self.GetTexCoord(0, 1); local TLx, TLy, BLx, BLy, TRx, TRy, BRx, BRy = self.GetTexCoord(0, 1);
self.bg:SetTexCoord(TLx , TLy , BLx , BLy , TRx , TRy , BRx , BRy ); self.bg:SetTexCoord(TLx, TLy, BLx, BLy, TRx, TRy, BRx, BRy)
self.fg:SetTexCoord(TLx, TLy, BLx, BLy, TRx, TRy, BRx, BRy)
-- Set alignment -- Set alignment
self.fg:ClearAllPoints(); self.fgMask:ClearAllPoints()
self.fg:SetPoint(self.align1); self.fgMask:SetPoint(self.align1, self, self.align1)
self.fg:SetPoint(self.align2); self.fgMask:SetPoint(self.align2, self, self.align2)
self.fgFrame:ClearAllPoints()
self.fgFrame:SetPoint(self.align1);
self.fgFrame:SetPoint(self.align2);
self.spark:SetPoint("CENTER", self.fg, self.alignSpark, self.spark.sparkOffsetX or 0, self.spark.sparkOffsetY or 0); self.spark:SetPoint("CENTER", self.fgMask, self.alignSpark, self.spark.sparkOffsetX or 0, self.spark.sparkOffsetY or 0);
local sparkMirror = self.spark.sparkMirror; local sparkMirror = self.spark.sparkMirror;
local sparkRotationMode = self.spark.sparkRotationMode; local sparkRotationMode = self.spark.sparkRotationMode;
@@ -301,18 +318,24 @@ local barPrototype = {
-- Create statusbar illusion -- Create statusbar illusion
if (self.horizontal) then if (self.horizontal) then
local xProgress = self:GetRealSize() * progress; local xProgress = self:GetRealSize() * progress;
self.fg:SetWidth(xProgress > 0.0001 and xProgress or 0.0001); local show = xProgress > 0.0001
self.fgFrame:SetWidth(xProgress > 0.0001 and xProgress or 0.0001); self.fgMask:SetWidth(show and (xProgress + 0.1) or 0.1);
if show then
self.fg:Show()
else
self.fg:Hide()
end
else else
local yProgress = select(2, self:GetRealSize()) * progress; local yProgress = select(2, self:GetRealSize()) * progress;
self.fg:SetHeight(yProgress > 0.0001 and yProgress or 0.0001); local show = yProgress > 0.0001
self.fgFrame:SetHeight(yProgress > 0.0001 and yProgress or 0.0001); self.fgMask:SetHeight(show and (yProgress + 0.1) or 0.1);
if show then
self.fg:Show()
else
self.fg:Hide()
end
end end
-- Stretch texture
local TLx_, TLy_, BLx_, BLy_, TRx_, TRy_, BRx_, BRy_ = self.GetTexCoord(0, progress);
self.fg:SetTexCoord(TLx_, TLy_, BLx_, BLy_, TRx_, TRy_, BRx_, BRy_);
local sparkHidden = self.spark.sparkHidden; local sparkHidden = self.spark.sparkHidden;
local sparkVisible = sparkHidden == "NEVER" local sparkVisible = sparkHidden == "NEVER"
or (sparkHidden == "FULL" and progress < 1) or (sparkHidden == "FULL" and progress < 1)
@@ -562,8 +585,8 @@ local barPrototype = {
self.fg:SetVertexColor(r, g, b, a); self.fg:SetVertexColor(r, g, b, a);
end, end,
["GetForegroundColor"] = function(self) ["SetForegroundGradient"] = function(self, orientation, r1, g1, b1, a1, r2, g2, b2, a2)
return self.fg:GetVertexColor(); self.fg:SetGradientAlpha(orientation, r1, g1, b1, a1, r2, g2, b2, a2)
end, end,
-- Set background color -- Set background color
@@ -571,10 +594,6 @@ local barPrototype = {
self.bg:SetVertexColor(r, g, b, a); self.bg:SetVertexColor(r, g, b, a);
end, end,
["GetBackgroundColor"] = function(self)
return self.bg:GetVertexColor();
end,
-- Convenience methods -- Convenience methods
["SetTexture"] = function(self, texture) ["SetTexture"] = function(self, texture)
self:SetStatusBarTexture(texture); self:SetStatusBarTexture(texture);
@@ -588,10 +607,6 @@ local barPrototype = {
self:SetForegroundColor(r, g, b, a); self:SetForegroundColor(r, g, b, a);
end, end,
["GetVertexColor"] = function(self)
return self.fg:GetVertexColor();
end,
["GetRealSize"] = function(self) ["GetRealSize"] = function(self)
return 0, 0 return 0, 0
end, end,
@@ -774,7 +789,7 @@ local funcs = {
elseif anchorPoint == "icon" then elseif anchorPoint == "icon" then
anchor = self.icon anchor = self.icon
elseif anchorPoint == "fg" then elseif anchorPoint == "fg" then
anchor = self.bar.fgFrame anchor = self.bar.fgMask
elseif anchorPoint == "bg" then elseif anchorPoint == "bg" then
anchor = self.bar.bg anchor = self.bar.bg
end end
@@ -1066,6 +1081,53 @@ local funcs = {
end end
self.subRegionEvents:Notify("OrientationChanged") self.subRegionEvents:Notify("OrientationChanged")
end,
UpdateForegroundColor = function(self)
if self.enableGradient then
self.bar:SetForegroundGradient(self.gradientOrientation,
self.color_anim_r or self.color_r,
self.color_anim_g or self.color_g,
self.color_anim_b or self.color_b,
self.color_anim_a or self.color_a,
self.barColor2[1],
self.barColor2[2],
self.barColor2[3],
self.barColor2[4])
else
self.bar:SetForegroundColor(self.color_anim_r or self.color_r,
self.color_anim_g or self.color_g,
self.color_anim_b or self.color_b,
self.color_anim_a or self.color_a);
end
end,
SetBarColor2 = function(self, r, g, b, a)
self.barColor2 = { r, g, b, a}
self:UpdateForegroundColor()
end,
SetGradientOrientation = function(self, orientation)
self.gradientOrientation = orientation
self:UpdateForegroundColor()
end,
SetGradientEnabled = function(self, enable)
self.enableGradient = enable
self:UpdateForegroundColor()
end,
Color = function(self, r, g, b, a)
self.color_r = r;
self.color_g = g;
self.color_b = b;
self.color_a = a;
self:UpdateForegroundColor()
end,
ColorAnim = function(self, r, g, b, a)
self.color_anim_r = r;
self.color_anim_g = g;
self.color_anim_b = b;
self.color_anim_a = a;
self:UpdateForegroundColor()
end,
GetColor = function(self)
return self.color_r, self.color_g, self.color_b, self.color_a
end end
} }
@@ -1091,16 +1153,26 @@ local function create(parent)
region:SetResizable(true); region:SetResizable(true);
region:SetMinResize(1, 1); region:SetMinResize(1, 1);
-- Create statusbar (inherit prototype)
local bar = CreateFrame("Frame", nil, region); local bar = CreateFrame("Frame", nil, region);
WeakAuras.Mixin(bar, Private.SmoothStatusBarMixin); WeakAuras.Mixin(bar, Private.SmoothStatusBarMixin);
local fg = bar:CreateTexture(nil, "BORDER");
local bg = region:CreateTexture(nil, "BACKGROUND"); -- Now create a bunch of textures
local bg = region:CreateTexture(nil, "ARTWORK");
bg:SetAllPoints(bar); bg:SetAllPoints(bar);
local fgFrame = CreateFrame("Frame", nil, bar)
-- Workaround für Masking mit einer zusätzlichen Alpha-Textur
local fgMask = CreateFrame("Frame", nil, bar)
fgMask:SetAllPoints(bar)
local fg = fgMask:CreateTexture(nil, "ARTWORK");
fg:SetAllPoints(fgMask)
local spark = bar:CreateTexture(nil, "ARTWORK"); local spark = bar:CreateTexture(nil, "ARTWORK");
fg:SetDrawLayer("ARTWORK", -1);
bg:SetDrawLayer("ARTWORK", -2);
spark:SetDrawLayer("ARTWORK", 7);
bar.fg = fg; bar.fg = fg;
bar.fgFrame = fgFrame bar.fgMask = fgMask
bar.bg = bg; bar.bg = bg;
bar.spark = spark; bar.spark = spark;
for key, value in pairs(barPrototype) do for key, value in pairs(barPrototype) do
@@ -1170,6 +1242,10 @@ local function modify(parent, region, data)
region.orientation = data.orientation region.orientation = data.orientation
region.effectiveOrientation = nil region.effectiveOrientation = nil
-- region.barColor is special because of animations
region.barColor2 = CopyTable(data.barColor2)
region.enableGradient = data.enableGradient
region.gradientOrientation = data.gradientOrientation
region.overlayclip = data.overlayclip; region.overlayclip = data.overlayclip;
region.iconVisible = data.icon region.iconVisible = data.icon
region.icon_side = data.icon_side region.icon_side = data.icon_side
@@ -1209,26 +1285,6 @@ local function modify(parent, region, data)
bar.spark.sparkRotation = data.sparkRotation; bar.spark.sparkRotation = data.sparkRotation;
bar.spark.sparkMirror = data.sparkMirror; bar.spark.sparkMirror = data.sparkMirror;
-- Color update function
region.Color = region.Color or function(self, r, g, b, a)
self.color_r = r;
self.color_g = g;
self.color_b = b;
self.color_a = a;
self.bar:SetForegroundColor(self.color_anim_r or r, self.color_anim_g or g, self.color_anim_b or b, self.color_anim_a or a);
end
region.ColorAnim = function(self, r, g, b, a)
self.color_anim_r = r;
self.color_anim_g = g;
self.color_anim_b = b;
self.color_anim_a = a;
self.bar:SetForegroundColor(r or self.color_r, g or self.color_g, b or self.color_b, a or self.color_a);
end
region.GetColor = region.GetColor or function(self)
return self.color_r, self.color_g, self.color_b, self.color_a
end
region:Color(data.barColor[1], data.barColor[2], data.barColor[3], data.barColor[4]); region:Color(data.barColor[1], data.barColor[2], data.barColor[3], data.barColor[4]);
-- Update icon visibility -- Update icon visibility
+1 -1
View File
@@ -188,7 +188,7 @@ local function modify(parent, region, parentData, data, first)
local anchor local anchor
if parentData.regionType == "aurabar" then if parentData.regionType == "aurabar" then
if data.bar_model_clip then if data.bar_model_clip then
anchor = parent.bar.fgFrame anchor = parent.bar.fgMask
else else
anchor = parent.bar anchor = parent.bar
end end
+1 -1
View File
@@ -195,7 +195,7 @@ local function modify(parent, region, parentData, data, first)
-- Special anchoring for clipping ! -- Special anchoring for clipping !
region:SetScript("OnSizeChanged", nil) region:SetScript("OnSizeChanged", nil)
region:ClearAllPoints() region:ClearAllPoints()
region:SetAllPoints(parent.bar.fgFrame) region:SetAllPoints(parent.bar.fgMask)
region.stopMotion:ClearAllPoints() region.stopMotion:ClearAllPoints()
region.stopMotion:SetAllPoints(region.parent.bar) region.stopMotion:SetAllPoints(region.parent.bar)
else else
+22 -2
View File
@@ -138,13 +138,33 @@ local function createOptions(id, data)
name = L["Bar Color Settings"], name = L["Bar Color Settings"],
order = 39 order = 39
}, },
enableGradient = {
type = "toggle",
width = WeakAuras.normalWidth,
name = L["Enable Gradient"],
order = 39.1
},
gradientOrientation = {
type = "select",
width = WeakAuras.normalWidth,
values = OptionsPrivate.Private.gradient_orientations,
name = L["Gradient Orientation"],
order = 39.2
},
barColor = { barColor = {
type = "color", type = "color",
width = WeakAuras.normalWidth, width = WeakAuras.normalWidth,
name = L["Bar Color"], name = L["Bar Color/Gradient Start"],
hasAlpha = true, hasAlpha = true,
order = 39.3 order = 39.3
}, },
barColor2 = {
type = "color",
width = WeakAuras.normalWidth,
name = L["Gradient End"],
hasAlpha = true,
order = 39.4
},
backgroundColor = { backgroundColor = {
type = "color", type = "color",
width = WeakAuras.normalWidth, width = WeakAuras.normalWidth,
@@ -870,4 +890,4 @@ end
OptionsPrivate.registerRegions = OptionsPrivate.registerRegions or {} OptionsPrivate.registerRegions = OptionsPrivate.registerRegions or {}
table.insert(OptionsPrivate.registerRegions, function() table.insert(OptionsPrivate.registerRegions, function()
OptionsPrivate.Private.RegisterRegionOptions("aurabar", createOptions, createIcon, L["Progress Bar"], createThumbnail, modifyThumbnail, L["Shows a progress bar with name, timer, and icon"], templates, GetAnchors); OptionsPrivate.Private.RegisterRegionOptions("aurabar", createOptions, createIcon, L["Progress Bar"], createThumbnail, modifyThumbnail, L["Shows a progress bar with name, timer, and icon"], templates, GetAnchors);
end) end)