Advertisement
Dramiel

RIFT Button

Oct 29th, 2011
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.19 KB | None | 0 0
  1. Rowdy.Setup(...);
  2.  
  3. import "core";
  4. import "string";
  5. import "event";
  6. import "class";
  7.  
  8. package "ui";
  9.  
  10. local base, metatable, methods = nil, nil, { };
  11.  
  12. -- private members
  13. local function OnLeftDown(self)
  14.     local protected = self[UI.Button];
  15.  
  16.     protected.textColor = { protected.text:GetFontColor() };
  17.     protected.text:SetFontColor(.2, .5, .3, 1);
  18.  
  19.     protected.borderColor = { self:GetBorderColor() };
  20.     self:SetBorderColor(.2, .5, .3, 1);
  21. end
  22.  
  23. local function OnLeftUpOutside(self)
  24.     local protected = self[UI.Button];
  25.  
  26.     if (not protected.textColor or not protected.borderColor) then
  27.         return;
  28.     end
  29.  
  30.     protected.text:SetFontColor(unpack(protected.textColor));
  31.     self:SetBorderColor(unpack(protected.borderColor));
  32. end
  33.  
  34. local function OnLeftUp(self)
  35.     OnLeftUpOutside(self);
  36.  
  37.     self.Event.Click(self);
  38. end
  39.  
  40. local function UpdateSize(self)
  41.     local protected = self[UI.Button];
  42.     local textFrame = protected.text;
  43.  
  44.     self:SetWidth(textFrame:GetWidth() + 20);
  45.     self:SetHeight(textFrame:GetHeight() + 10);
  46. end
  47.  
  48. -- public members
  49. methods.SetText = function(self, text)
  50.     local protected = self[UI.Button];
  51.     local textFrame = protected.text;
  52.  
  53.     textFrame:SetText(text);
  54.  
  55.     if (protected.autosize) then
  56.         UpdateSize(self);
  57.     end
  58. end
  59.  
  60. methods.SetAutoSize = function(self, value)
  61.     self[UI.Button].autosize = value;
  62.  
  63.     if (value) then
  64.         UpdateSize(self);
  65.     end
  66. end
  67.  
  68. methods.GetAutoSize = function(self, value)
  69.     return self[UI.Button].autosize;
  70. end
  71.  
  72. -- constructor
  73. UI.Button = function(parent)
  74.     assert(isInstanceOf(parent, UI.Context) or isInstanceOf(parent, UI.FrameBase),
  75.         "UI.Button requires 'parent' (UI.Context) parameter");
  76.  
  77.     local name = parent:GetName() .. "Button";
  78.  
  79.     local self = UI.FramedFrame(name, parent);
  80.     self:SetWidth(20);
  81.     self:SetHeight(20);
  82.  
  83.     local text = UI.Text(name .. "Text", self);
  84.     text:SetPoint("CENTER", self, "CENTER", -0.5, -1);
  85.     text:SetAutoSize(true);
  86.  
  87.     self.Event.LeftDown = OnLeftDown;
  88.     self.Event.LeftUp = OnLeftUp;
  89.     self.Event.LeftUpoutside = OnLeftUpOutside;
  90.  
  91.     self[UI.Button] = {
  92.         text = text,
  93.     };
  94.  
  95.     self.Event:add("Click");
  96.  
  97.     base, metatable = class(base, metatable, methods, self, UI.Button);
  98.  
  99.     self:SetAutoSize(true);
  100.  
  101.     return self;
  102. end
  103.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement