1 local AceGUI
= LibStub("AceGUI-3.0")
4 local max, select
= math
.max, select
7 local CreateFrame
, UIParent
= CreateFrame
, UIParent
9 -- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
10 -- List them here for Mikk's FindGlobals script
11 -- GLOBALS: GameFontHighlightSmall
13 --------------------------
15 --------------------------
20 local function OnAcquire(self
)
25 self
:SetImageSize(16, 16)
30 local function OnRelease(self
)
31 self
.frame
:ClearAllPoints()
35 local function UpdateImageAnchor(self
)
36 local width
= self
.frame
.width
or self
.frame
:GetWidth() or 0
37 local image
= self
.image
38 local label
= self
.label
39 local frame
= self
.frame
42 label
:ClearAllPoints()
43 image
:ClearAllPoints()
45 if self
.imageshown
then
46 local imagewidth
= image
:GetWidth()
47 if (width
- imagewidth
) < 200 or (label
:GetText() or "") == "" then
48 --image goes on top centered when less than 200 width for the text, or if there is no text
49 image
:SetPoint("TOP",frame
,"TOP",0,0)
50 label
:SetPoint("TOP",image
,"BOTTOM",0,0)
51 label
:SetPoint("LEFT",frame
,"LEFT",0,0)
53 height
= image
:GetHeight() + label
:GetHeight()
56 image
:SetPoint("TOPLEFT",frame
,"TOPLEFT",0,0)
57 label
:SetPoint("TOPLEFT",image
,"TOPRIGHT",4,0)
58 label
:SetWidth(width
- imagewidth
)
59 height
= max(image
:GetHeight(), label
:GetHeight())
63 label
:SetPoint("TOPLEFT",frame
,"TOPLEFT",0,0)
65 height
= self
.label
:GetHeight()
69 self
.frame
:SetHeight(height
)
70 self
.frame
.height
= height
74 local function SetText(self
, text
)
75 self
.label
:SetText(text
or "")
76 UpdateImageAnchor(self
)
79 local function SetColor(self
, r
, g
, b
)
80 if not (r
and g
and b
) then
83 self
.label
:SetVertexColor(r
, g
, b
)
86 local function OnWidthSet(self
, width
)
87 if self
.resizing
then return end
88 UpdateImageAnchor(self
)
91 local function SetImage(self
, path
, ...)
92 local image
= self
.image
93 image
:SetTexture(path
)
95 if image
:GetTexture() then
96 self
.imageshown
= true
97 local n
= select('#', ...)
98 if n
== 4 or n
== 8 then
99 image
:SetTexCoord(...)
101 image
:SetTexCoord(0, 1, 0, 1)
104 self
.imageshown
= nil
106 UpdateImageAnchor(self
)
109 local function SetFont(self
, font
, height
, flags
)
110 self
.label
:SetFont(font
, height
, flags
)
113 local function SetFontObject(self
, font
)
114 self
.label
:SetFontObject(font
or GameFontHighlightSmall
)
117 local function SetImageSize(self
, width
, height
)
118 self
.image
:SetWidth(width
)
119 self
.image
:SetHeight(height
)
120 UpdateImageAnchor(self
)
123 local function Constructor()
124 local frame
= CreateFrame("Frame",nil,UIParent
)
128 self
.OnRelease
= OnRelease
129 self
.OnAcquire
= OnAcquire
130 self
.SetText
= SetText
131 self
.SetColor
= SetColor
133 self
.OnWidthSet
= OnWidthSet
134 self
.SetImage
= SetImage
135 self
.SetImageSize
= SetImageSize
136 self
.SetFont
= SetFont
137 self
.SetFontObject
= SetFontObject
142 local label
= frame
:CreateFontString(nil,"BACKGROUND","GameFontHighlightSmall")
143 label
:SetPoint("TOPLEFT",frame
,"TOPLEFT",0,0)
145 label
:SetJustifyH("LEFT")
146 label
:SetJustifyV("TOP")
149 local image
= frame
:CreateTexture(nil,"BACKGROUND")
152 AceGUI
:RegisterAsWidget(self
)
156 AceGUI
:RegisterWidgetType(Type
,Constructor
,Version
)