tekkub / controlfreak

WoW Addon - Crowd control assistance

This URL has Read+Write access

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