View Single Post
11-28-10, 12:06 AM   #23
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,327
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:
  1. local function SetBarValue(bar,val1,val2,flipH,flipV)-- Accepts 5 values, bar texture, start value, end value, and flip flags (horizontal and vertical)
  2. --  Keep the values within a 0-1 range
  3.     val1=math.min(math.max(val1,0),1);
  4.     val2=math.min(math.max(val2,0),1);
  5.  
  6. --  Sometimes textures glitch when trying to set a width or height of 0, so handle it here
  7.     if val1==val2 then
  8.         bar:Hide();
  9.         return;
  10.     else
  11.         bar:Show();
  12.     end
  13.  
  14. --  Set our low and high values
  15.     local low,high=math.min(val1,val2),math.max(val1,val2);
  16.  
  17. --  Find our parent width and height
  18.     local parent=bar:GetParent();
  19.     local w,h=parent:GetWidth(),parent:GetHeight();
  20.  
  21. --  Get our point set, we'll use this to get our bar orientation
  22.     local point=bar:GetPoint(1);
  23.     if not point then return; end-- Handle if point isn't set, perhaps cleared?
  24.  
  25. --  These are our temp origin variables (note one of these pairs can have both vars nil, just use default texcoords for those)
  26.     local origL=point:find("LEFT$");
  27.     local origR=point:find("RIGHT$");
  28.     local origT=point:find("^TOP");
  29.     local origB=point:find("^BOTTOM");
  30.  
  31. --  Reset point
  32.     bar:SetPoint(point
  33.         ,(origL or origR) and (origL and low*w or -low*w) or 0--    X offset
  34.         ,(origT or origB) and (origB and low*h or -low*h) or 0--    Y offset
  35.     );
  36.  
  37. --  Texcoord calc
  38.     local l,r,t,b=0,1,0,1;--    Texcoords are in the range of 0-1 with their origin at top left
  39.     if origL then
  40.         l,r=low,high;
  41.     elseif origR then
  42.         l,r=1-high,1-low;
  43.     end
  44.     if origT then
  45.         t,b=low,high;
  46.     elseif origB then
  47.         t,b=1-high,1-low;
  48.     end
  49.  
  50. --  Process flip (affects which side the bar piece is drawn from too)
  51.     if flipH then l,r=1-l,1-r; end
  52.     if flipV then t,b=1-t,1-b; end
  53.  
  54. --  Apply texcord/size
  55.     bar:SetTexCoord(l,r,t,b);
  56.     bar:SetWidth(w*math.abs(r-l));
  57.     bar:SetHeight(h*math.abs(b-t));
  58. end
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote