Asa@0
|
1 local AceGUI = LibStub("AceGUI-3.0")
|
Asa@0
|
2
|
Asa@0
|
3 -- Lua APIs
|
Asa@0
|
4 local max, select = math.max, select
|
Asa@0
|
5
|
Asa@0
|
6 -- WoW APIs
|
Asa@0
|
7 local CreateFrame, UIParent = CreateFrame, UIParent
|
Asa@0
|
8
|
Asa@0
|
9 -- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
|
Asa@0
|
10 -- List them here for Mikk's FindGlobals script
|
Asa@0
|
11 -- GLOBALS: GameFontHighlightSmall
|
Asa@0
|
12
|
Asa@0
|
13 --------------------------
|
Asa@0
|
14 -- Label --
|
Asa@0
|
15 --------------------------
|
Asa@0
|
16 do
|
Asa@0
|
17 local Type = "Label"
|
Asa@0
|
18 local Version = 11
|
Asa@0
|
19
|
Asa@0
|
20 local function OnAcquire(self)
|
Asa@0
|
21 self:SetHeight(18)
|
Asa@0
|
22 self:SetWidth(200)
|
Asa@0
|
23 self:SetText("")
|
Asa@0
|
24 self:SetImage(nil)
|
Asa@0
|
25 self:SetColor()
|
Asa@0
|
26 self:SetFontObject()
|
Asa@0
|
27 end
|
Asa@0
|
28
|
Asa@0
|
29 local function OnRelease(self)
|
Asa@0
|
30 self.frame:ClearAllPoints()
|
Asa@0
|
31 self.frame:Hide()
|
Asa@0
|
32 end
|
Asa@0
|
33
|
Asa@0
|
34 local function UpdateImageAnchor(self)
|
Asa@0
|
35 local width = self.frame.width or self.frame:GetWidth() or 0
|
Asa@0
|
36 local image = self.image
|
Asa@0
|
37 local label = self.label
|
Asa@0
|
38 local frame = self.frame
|
Asa@0
|
39 local height
|
Asa@0
|
40
|
Asa@0
|
41 label:ClearAllPoints()
|
Asa@0
|
42 image:ClearAllPoints()
|
Asa@0
|
43
|
Asa@0
|
44 if self.imageshown then
|
Asa@0
|
45 local imagewidth = image:GetWidth()
|
Asa@0
|
46 if (width - imagewidth) < 200 or (label:GetText() or "") == "" then
|
Asa@0
|
47 --image goes on top centered when less than 200 width for the text, or if there is no text
|
Asa@0
|
48 image:SetPoint("TOP",frame,"TOP",0,0)
|
Asa@0
|
49 label:SetPoint("TOP",image,"BOTTOM",0,0)
|
Asa@0
|
50 label:SetPoint("LEFT",frame,"LEFT",0,0)
|
Asa@0
|
51 label:SetWidth(width)
|
Asa@0
|
52 height = image:GetHeight() + label:GetHeight()
|
Asa@0
|
53 else
|
Asa@0
|
54 --image on the left
|
Asa@0
|
55 image:SetPoint("TOPLEFT",frame,"TOPLEFT",0,0)
|
Asa@0
|
56 label:SetPoint("TOPLEFT",image,"TOPRIGHT",4,0)
|
Asa@0
|
57 label:SetWidth(width - imagewidth)
|
Asa@0
|
58 height = max(image:GetHeight(), label:GetHeight())
|
Asa@0
|
59 end
|
Asa@0
|
60 else
|
Asa@0
|
61 --no image shown
|
Asa@0
|
62 label:SetPoint("TOPLEFT",frame,"TOPLEFT",0,0)
|
Asa@0
|
63 label:SetWidth(width)
|
Asa@0
|
64 height = self.label:GetHeight()
|
Asa@0
|
65 end
|
Asa@0
|
66
|
Asa@0
|
67 self.resizing = true
|
Asa@0
|
68 self.frame:SetHeight(height)
|
Asa@0
|
69 self.frame.height = height
|
Asa@0
|
70 self.resizing = nil
|
Asa@0
|
71 end
|
Asa@0
|
72
|
Asa@0
|
73 local function SetText(self, text)
|
Asa@0
|
74 self.label:SetText(text or "")
|
Asa@0
|
75 UpdateImageAnchor(self)
|
Asa@0
|
76 end
|
Asa@0
|
77
|
Asa@0
|
78 local function SetColor(self, r, g, b)
|
Asa@0
|
79 if not (r and g and b) then
|
Asa@0
|
80 r, g, b = 1, 1, 1
|
Asa@0
|
81 end
|
Asa@0
|
82 self.label:SetVertexColor(r, g, b)
|
Asa@0
|
83 end
|
Asa@0
|
84
|
Asa@0
|
85 local function OnWidthSet(self, width)
|
Asa@0
|
86 if self.resizing then return end
|
Asa@0
|
87 UpdateImageAnchor(self)
|
Asa@0
|
88 end
|
Asa@0
|
89
|
Asa@0
|
90 local function SetImage(self, path, ...)
|
Asa@0
|
91 local image = self.image
|
Asa@0
|
92 image:SetTexture(path)
|
Asa@0
|
93
|
Asa@0
|
94 if image:GetTexture() then
|
Asa@0
|
95 self.imageshown = true
|
Asa@0
|
96 local n = select('#', ...)
|
Asa@0
|
97 if n == 4 or n == 8 then
|
Asa@0
|
98 image:SetTexCoord(...)
|
Asa@0
|
99 end
|
Asa@0
|
100 else
|
Asa@0
|
101 self.imageshown = nil
|
Asa@0
|
102 end
|
Asa@0
|
103 UpdateImageAnchor(self)
|
Asa@0
|
104 end
|
Asa@0
|
105
|
Asa@0
|
106 local function SetFont(self, font, height, flags)
|
Asa@0
|
107 self.label:SetFont(font, height, flags)
|
Asa@0
|
108 end
|
Asa@0
|
109
|
Asa@0
|
110 local function SetFontObject(self, font)
|
Asa@0
|
111 self.label:SetFontObject(font or GameFontHighlightSmall)
|
Asa@0
|
112 end
|
Asa@0
|
113
|
Asa@0
|
114 local function SetImageSize(self, width, height)
|
Asa@0
|
115 self.image:SetWidth(width)
|
Asa@0
|
116 self.image:SetHeight(height)
|
Asa@0
|
117 UpdateImageAnchor(self)
|
Asa@0
|
118 end
|
Asa@0
|
119
|
Asa@0
|
120 local function Constructor()
|
Asa@0
|
121 local frame = CreateFrame("Frame",nil,UIParent)
|
Asa@0
|
122 local self = {}
|
Asa@0
|
123 self.type = Type
|
Asa@0
|
124
|
Asa@0
|
125 self.OnRelease = OnRelease
|
Asa@0
|
126 self.OnAcquire = OnAcquire
|
Asa@0
|
127 self.SetText = SetText
|
Asa@0
|
128 self.SetColor = SetColor
|
Asa@0
|
129 self.frame = frame
|
Asa@0
|
130 self.OnWidthSet = OnWidthSet
|
Asa@0
|
131 self.SetImage = SetImage
|
Asa@0
|
132 self.SetImageSize = SetImageSize
|
Asa@0
|
133 self.SetFont = SetFont
|
Asa@0
|
134 self.SetFontObject = SetFontObject
|
Asa@0
|
135 frame.obj = self
|
Asa@0
|
136
|
Asa@0
|
137 frame:SetHeight(18)
|
Asa@0
|
138 frame:SetWidth(200)
|
Asa@0
|
139 local label = frame:CreateFontString(nil,"BACKGROUND","GameFontHighlightSmall")
|
Asa@0
|
140 label:SetPoint("TOPLEFT",frame,"TOPLEFT",0,0)
|
Asa@0
|
141 label:SetWidth(200)
|
Asa@0
|
142 label:SetJustifyH("LEFT")
|
Asa@0
|
143 label:SetJustifyV("TOP")
|
Asa@0
|
144 self.label = label
|
Asa@0
|
145
|
Asa@0
|
146 local image = frame:CreateTexture(nil,"BACKGROUND")
|
Asa@0
|
147 self.image = image
|
Asa@0
|
148
|
Asa@0
|
149 AceGUI:RegisterAsWidget(self)
|
Asa@0
|
150 return self
|
Asa@0
|
151 end
|
Asa@0
|
152
|
Asa@0
|
153 AceGUI:RegisterWidgetType(Type,Constructor,Version)
|
Asa@0
|
154 end
|
Asa@0
|
155
|