Gradient implementation
This commit is contained in:
@@ -19,6 +19,9 @@ local default = {
|
||||
orientation = "HORIZONTAL",
|
||||
inverse = false,
|
||||
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},
|
||||
spark = false,
|
||||
sparkWidth = 10,
|
||||
@@ -68,10 +71,26 @@ local properties = {
|
||||
type = "textureLSM",
|
||||
},
|
||||
barColor = {
|
||||
display = L["Bar Color"],
|
||||
display = L["Bar Color/Gradient Start"],
|
||||
setter = "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 = {
|
||||
display = {L["Icon"], L["Visibility"]},
|
||||
setter = "SetIconVisible",
|
||||
@@ -265,17 +284,15 @@ local barPrototype = {
|
||||
self.directionInverse = (self.orientation == "HORIZONTAL_INVERSE") or (self.orientation == "VERTICAL")
|
||||
|
||||
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
|
||||
self.fg:ClearAllPoints();
|
||||
self.fg:SetPoint(self.align1);
|
||||
self.fg:SetPoint(self.align2);
|
||||
self.fgFrame:ClearAllPoints()
|
||||
self.fgFrame:SetPoint(self.align1);
|
||||
self.fgFrame:SetPoint(self.align2);
|
||||
self.fgMask:ClearAllPoints()
|
||||
self.fgMask:SetPoint(self.align1, self, self.align1)
|
||||
self.fgMask:SetPoint(self.align2, self, 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 sparkRotationMode = self.spark.sparkRotationMode;
|
||||
@@ -301,18 +318,24 @@ local barPrototype = {
|
||||
-- Create statusbar illusion
|
||||
if (self.horizontal) then
|
||||
local xProgress = self:GetRealSize() * progress;
|
||||
self.fg:SetWidth(xProgress > 0.0001 and xProgress or 0.0001);
|
||||
self.fgFrame:SetWidth(xProgress > 0.0001 and xProgress or 0.0001);
|
||||
local show = xProgress > 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
|
||||
local yProgress = select(2, self:GetRealSize()) * progress;
|
||||
self.fg:SetHeight(yProgress > 0.0001 and yProgress or 0.0001);
|
||||
self.fgFrame:SetHeight(yProgress > 0.0001 and yProgress or 0.0001);
|
||||
local show = yProgress > 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
|
||||
|
||||
-- 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 sparkVisible = sparkHidden == "NEVER"
|
||||
or (sparkHidden == "FULL" and progress < 1)
|
||||
@@ -562,8 +585,8 @@ local barPrototype = {
|
||||
self.fg:SetVertexColor(r, g, b, a);
|
||||
end,
|
||||
|
||||
["GetForegroundColor"] = function(self)
|
||||
return self.fg:GetVertexColor();
|
||||
["SetForegroundGradient"] = function(self, orientation, r1, g1, b1, a1, r2, g2, b2, a2)
|
||||
self.fg:SetGradientAlpha(orientation, r1, g1, b1, a1, r2, g2, b2, a2)
|
||||
end,
|
||||
|
||||
-- Set background color
|
||||
@@ -571,10 +594,6 @@ local barPrototype = {
|
||||
self.bg:SetVertexColor(r, g, b, a);
|
||||
end,
|
||||
|
||||
["GetBackgroundColor"] = function(self)
|
||||
return self.bg:GetVertexColor();
|
||||
end,
|
||||
|
||||
-- Convenience methods
|
||||
["SetTexture"] = function(self, texture)
|
||||
self:SetStatusBarTexture(texture);
|
||||
@@ -588,10 +607,6 @@ local barPrototype = {
|
||||
self:SetForegroundColor(r, g, b, a);
|
||||
end,
|
||||
|
||||
["GetVertexColor"] = function(self)
|
||||
return self.fg:GetVertexColor();
|
||||
end,
|
||||
|
||||
["GetRealSize"] = function(self)
|
||||
return 0, 0
|
||||
end,
|
||||
@@ -774,7 +789,7 @@ local funcs = {
|
||||
elseif anchorPoint == "icon" then
|
||||
anchor = self.icon
|
||||
elseif anchorPoint == "fg" then
|
||||
anchor = self.bar.fgFrame
|
||||
anchor = self.bar.fgMask
|
||||
elseif anchorPoint == "bg" then
|
||||
anchor = self.bar.bg
|
||||
end
|
||||
@@ -1066,6 +1081,53 @@ local funcs = {
|
||||
end
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -1091,16 +1153,26 @@ local function create(parent)
|
||||
region:SetResizable(true);
|
||||
region:SetMinResize(1, 1);
|
||||
|
||||
-- Create statusbar (inherit prototype)
|
||||
local bar = CreateFrame("Frame", nil, region);
|
||||
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);
|
||||
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");
|
||||
fg:SetDrawLayer("ARTWORK", -1);
|
||||
bg:SetDrawLayer("ARTWORK", -2);
|
||||
spark:SetDrawLayer("ARTWORK", 7);
|
||||
bar.fg = fg;
|
||||
bar.fgFrame = fgFrame
|
||||
bar.fgMask = fgMask
|
||||
bar.bg = bg;
|
||||
bar.spark = spark;
|
||||
for key, value in pairs(barPrototype) do
|
||||
@@ -1170,6 +1242,10 @@ local function modify(parent, region, data)
|
||||
region.orientation = data.orientation
|
||||
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.iconVisible = data.icon
|
||||
region.icon_side = data.icon_side
|
||||
@@ -1209,26 +1285,6 @@ local function modify(parent, region, data)
|
||||
bar.spark.sparkRotation = data.sparkRotation;
|
||||
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]);
|
||||
|
||||
-- Update icon visibility
|
||||
|
||||
Reference in New Issue
Block a user