PageRenderTime 62ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/WidgetWarlock/Summons.lua

http://github.com/tekkub/controlfreak
Lua | 130 lines | 82 code | 34 blank | 14 comment | 13 complexity | 2101f3fab88915817b15b257ed4b20ee MD5 | raw file
  1. local lib, oldminor = LibStub:NewLibrary("WidgetWarlock-Alpha1", 3)
  2. if not lib then return end
  3. lib.upgrading = oldminor or 0
  4. if lib.upgrading >= 3 then return end
  5. -- Creates a text edit box.
  6. -- All args optional, parent highly recommended
  7. function lib:SummonEditBox(parent, w, ...)
  8. local f = CreateFrame('EditBox', nil, parent)
  9. f:SetAutoFocus(false)
  10. local left = self:SummonTextureWithCoords(f, "BACKGROUND", 8, 20, "Interface\\Common\\Common-Input-Border", 0, 0.0625, 0, 0.625)
  11. local right = self:SummonTextureWithCoords(f, "BACKGROUND", 8, 20, "Interface\\Common\\Common-Input-Border", 0.9375, 1, 0, 0.625)
  12. local center = self:SummonTextureWithCoords(f, "BACKGROUND", 10, 20, "Interface\\Common\\Common-Input-Border", 0.0625, 0.9375, 0, 0.625)
  13. left:SetPoint("LEFT", f, "LEFT", -5, 0)
  14. right:SetPoint("RIGHT", f, "RIGHT", 0, 0)
  15. center:SetPoint("RIGHT", right, "LEFT", 0, 0)
  16. center:SetPoint("LEFT", left, "RIGHT", 0, 0)
  17. f:SetScript("OnEscapePressed", f.ClearFocus)
  18. f:SetScript("OnEditFocusLost", lib.ClearHighlight)
  19. f:SetScript("OnEditFocusGained", f.HighlightText)
  20. f:SetFontObject('ChatFontNormal')
  21. if select('#', ...) > 0 then f:SetPoint(...) end
  22. f:SetWidth(w or 100)
  23. f:SetHeight(32)
  24. return f
  25. end
  26. if lib.upgrading >= 1 then return end
  27. -- Creates a background box to place behind widgets for visual grouping.
  28. -- All args optional, parent highly recommended
  29. function lib:SummonGroupBox(parent, w, h, ...)
  30. local box = CreateFrame('Frame', nil, parent)
  31. box:SetBackdrop(self.GroupBoxBG)
  32. box:SetBackdropBorderColor(0.4, 0.4, 0.4)
  33. box:SetBackdropColor(0.1, 0.1, 0.1)
  34. if select('#',...) > 0 then box:SetPoint(...) end
  35. if w then box:SetWidth(w) end
  36. if h then box:SetHeight(h) end
  37. return box
  38. end
  39. function lib.ClearHighlight(f) f:HighlightText(0,0) end
  40. -- Creates a button
  41. -- All args optional, parent highly recommended
  42. function lib:SummonButton(parent, text, w, h, ...)
  43. local b = CreateFrame("Button", nil, parent)
  44. if select(1, ...) then b:SetPoint(...) end
  45. b:SetWidth(w or 90)
  46. b:SetHeight(h or 21)
  47. -- Fonts --
  48. b:SetDisabledFontObject(GameFontDisable)
  49. b:SetHighlightFontObject(GameFontHighlight)
  50. b:SetTextFontObject(GameFontNormal)
  51. -- Textures --
  52. b:SetNormalTexture("Interface\\Buttons\\UI-Panel-Button-Up")
  53. b:SetPushedTexture("Interface\\Buttons\\UI-Panel-Button-Down")
  54. b:SetHighlightTexture("Interface\\Buttons\\UI-Panel-Button-Highlight")
  55. b:SetDisabledTexture("Interface\\Buttons\\UI-Panel-Button-Disabled")
  56. b:GetNormalTexture():SetTexCoord(0, 0.625, 0, 0.6875)
  57. b:GetPushedTexture():SetTexCoord(0, 0.625, 0, 0.6875)
  58. b:GetHighlightTexture():SetTexCoord(0, 0.625, 0, 0.6875)
  59. b:GetDisabledTexture():SetTexCoord(0, 0.625, 0, 0.6875)
  60. b:GetHighlightTexture():SetBlendMode("ADD")
  61. b:SetText(text)
  62. return b
  63. end
  64. -- Create a checkbox.
  65. -- All args optional but parent is highly recommended
  66. function lib:SummonCheckBox(parent, size, ...)
  67. local check = CreateFrame("CheckButton", nil, parent)
  68. check:SetWidth(size or 32)
  69. check:SetHeight(size or 32)
  70. if select(1, ...) then check:SetPoint(...) end
  71. check:SetNormalTexture("Interface\\Buttons\\UI-CheckBox-Up")
  72. check:SetPushedTexture("Interface\\Buttons\\UI-CheckBox-Down")
  73. check:SetHighlightTexture("Interface\\Buttons\\UI-CheckBox-Highlight")
  74. check:SetDisabledCheckedTexture("Interface\\Buttons\\UI-CheckBox-Check-Disabled")
  75. check:SetCheckedTexture("Interface\\Buttons\\UI-CheckBox-Check")
  76. return check
  77. end
  78. -- Create a slider.
  79. -- All args optional, parent recommended
  80. -- If lowvalue and highvalue are strings it is assumed they are % values
  81. -- and the % is parsed and set as decimal values for min/max
  82. function lib:SummonSlider(parent, label, lowvalue, highvalue, ...)
  83. local slider = CreateFrame("Slider", nil, parent)
  84. slider:SetWidth(128)
  85. slider:SetHeight(17)
  86. if select(1, ...) then slider:SetPoint(...) end
  87. slider:SetOrientation("HORIZONTAL")
  88. slider:SetThumbTexture("Interface\\Buttons\\UI-SliderBar-Button-Horizontal")
  89. slider:SetBackdrop(self.HorizontalSliderBG)
  90. local text = self:SummonFontString(slider, "ARTWORK", "GameFontNormalSmall", label, "BOTTOM", slider, "TOP")
  91. local low = self:SummonFontString(slider, "ARTWORK", "GameFontHighlightSmall", lowvalue, "TOPLEFT", slider, "BOTTOMLEFT", 2, 3)
  92. local high = self:SummonFontString(slider, "ARTWORK", "GameFontHighlightSmall", highvalue, "TOPRIGHT", slider, "BOTTOMRIGHT", -2, 3)
  93. if type(lowvalue) == "string" then slider:SetMinMaxValues(tonumber((lowvalue:gsub("%%", "")))/100, tonumber((highvalue:gsub("%%", "")))/100)
  94. else slider:SetMinMaxValues(lowvalue, highvalue) end
  95. return slider, text, low, high
  96. end