Hmm... After thinking through the code for a while, I think I found the flaw inherit to the original design. The fact it is incapable of flipping on an axis unrelated to its fill direction. Example, you want to flip horizontally while the bar is set to fill vertically.
It was written from the view that you'd be doing a horizontal fill with a horizontal flip, which honestly, isn't seen in any HUD addon other than my current in-house one.
Here's a new version using the old fill direction code with a separate flip processing section.
lua Code:
local function SetBarValue(bar,val1,val2,flipH,flipV)-- Accepts 5 values, bar texture, start value, end value, and flip flags (horizontal and vertical)
-- Keep the values within a 0-1 range
val1=math.min(math.max(val1,0),1);
val2=math.min(math.max(val2,0),1);
-- Sometimes textures glitch when trying to set a width or height of 0, so handle it here
if val1==val2 then
bar:Hide();
return;
else
bar:Show();
end
-- Set our low and high values
local low,high=math.min(val1,val2),math.max(val1,val2);
-- Find our parent width and height
local parent=bar:GetParent();
local w,h=parent:GetWidth(),parent:GetHeight();
-- Get our point set, we'll use this to get our bar orientation
local point=bar:GetPoint(1);
if not point then return; end-- Handle if point isn't set, perhaps cleared?
-- These are our temp origin variables (note one of these pairs can have both vars nil, just use default texcoords for those)
local origL=point:find("LEFT$");
local origR=point:find("RIGHT$");
local origT=point:find("^TOP");
local origB=point:find("^BOTTOM");
-- Reset point
bar:SetPoint(point
,(origL or origR) and (origL and low*w or -low*w) or 0-- X offset
,(origT or origB) and (origB and low*h or -low*h) or 0-- Y offset
);
-- Texcoord calc
local l,r,t,b=0,1,0,1;-- Texcoords are in the range of 0-1 with their origin at top left
if origL then
l,r=low,high;
elseif origR then
l,r=1-high,1-low;
end
if origT then
t,b=low,high;
elseif origB then
t,b=1-high,1-low;
end
-- Process flip (affects which side the bar piece is drawn from too)
if flipH then l,r=1-l,1-r; end
if flipV then t,b=1-t,1-b; end
-- Apply texcord/size
bar:SetTexCoord(l,r,t,b);
bar:SetWidth(w*math.abs(r-l));
bar:SetHeight(h*math.abs(b-t));
end