comparison Libs/AceGUI-3.0/widgets/AceGUIWidget-InteractiveLabel.lua @ 0:169f5211fc7f

First public revision. At this point ItemAuditor watches mail for auctions sold or purchased, watches for buy/sell (money and 1 item type change) and conversions/tradeskills. Milling isn't working yet because there is too much time between the first event and the last event.
author Asa Ayers <Asa.Ayers@Gmail.com>
date Thu, 20 May 2010 19:22:19 -0700
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:169f5211fc7f
1 local AceGUI = LibStub("AceGUI-3.0")
2
3 -- Lua APIs
4 local select, max = select, math.max
5
6 -- WoW APIs
7 local CreateFrame, UIParent = CreateFrame, UIParent
8
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
12
13 --------------------------
14 -- Label --
15 --------------------------
16 do
17 local Type = "InteractiveLabel"
18 local Version = 6
19
20 local function OnAcquire(self)
21 self:SetHeight(18)
22 self:SetWidth(200)
23 self:SetText("")
24 self:SetImage(nil)
25 self:SetColor()
26 self:SetFontObject()
27 self:SetHighlight()
28 self:SetHighlightTexCoord()
29 end
30
31 local function OnRelease(self)
32 self:SetDisabled(false)
33 self.frame:ClearAllPoints()
34 self.frame:Hide()
35 end
36
37 local function UpdateImageAnchor(self)
38 local width = self.frame.width or self.frame:GetWidth() or 0
39 local image = self.image
40 local label = self.label
41 local frame = self.frame
42 local height
43
44 label:ClearAllPoints()
45 image:ClearAllPoints()
46
47 if self.imageshown then
48 local imagewidth = image:GetWidth()
49 if (width - imagewidth) < 200 or (label:GetText() or "") == "" then
50 --image goes on top centered when less than 200 width for the text, or if there is no text
51 image:SetPoint("TOP",frame,"TOP",0,0)
52 label:SetPoint("TOP",image,"BOTTOM",0,0)
53 label:SetPoint("LEFT",frame,"LEFT",0,0)
54 label:SetWidth(width)
55 height = image:GetHeight() + label:GetHeight()
56 else
57 --image on the left
58 local imageheight = image:GetHeight()
59 local labelheight = label:GetHeight()
60 --center image with label
61 if imageheight > labelheight then
62 image:SetPoint("TOPLEFT",frame,"TOPLEFT",0,0)
63 label:SetPoint("LEFT",image,"RIGHT",0,0)
64 else
65 label:SetPoint("TOPLEFT",frame,"TOPLEFT",imagewidth,0)
66 image:SetPoint("RIGHT",label,"LEFT",0,0)
67 end
68 label:SetWidth(width - imagewidth)
69 height = max(imageheight, labelheight)
70 end
71 else
72 --no image shown
73 label:SetPoint("TOPLEFT",frame,"TOPLEFT",0,0)
74 label:SetWidth(width)
75 height = self.label:GetHeight()
76 end
77
78 self.resizing = true
79 self.frame:SetHeight(height)
80 self.frame.height = height
81 self.resizing = nil
82 end
83
84 local function SetText(self, text)
85 self.label:SetText(text or "")
86 UpdateImageAnchor(self)
87 end
88
89 local function SetColor(self, r, g, b)
90 if not (r and g and b) then
91 r, g, b = 1, 1, 1
92 end
93 self.label:SetVertexColor(r, g, b)
94 end
95
96 local function OnWidthSet(self, width)
97 if self.resizing then return end
98 UpdateImageAnchor(self)
99 end
100
101 local function SetImage(self, path, ...)
102 local image = self.image
103 image:SetTexture(path)
104
105 if image:GetTexture() then
106 self.imageshown = true
107 local n = select('#', ...)
108 if n == 4 or n == 8 then
109 image:SetTexCoord(...)
110 end
111 else
112 self.imageshown = nil
113 end
114 UpdateImageAnchor(self)
115 end
116
117 local function SetFont(self, font, height, flags)
118 self.label:SetFont(font, height, flags)
119 end
120
121 local function SetFontObject(self, font)
122 self.label:SetFontObject(font or GameFontHighlightSmall)
123 end
124
125 local function SetImageSize(self, width, height)
126 self.image:SetWidth(width)
127 self.image:SetHeight(height)
128 UpdateImageAnchor(self)
129 end
130
131 local function SetHighlight(self, ...)
132 self.highlight:SetTexture(...)
133 end
134
135 local function SetHighlightTexCoord(self, ...)
136 if select('#', ...) >= 1 then
137 self.highlight:SetTexCoord(...)
138 else
139 self.highlight:SetTexCoord(0, 1, 0, 1)
140 end
141 end
142
143 local function SetDisabled(self,disabled)
144 self.disabled = disabled
145 if disabled then
146 self.frame:EnableMouse(false)
147 self.label:SetTextColor(0.5, 0.5, 0.5)
148 else
149 self.frame:EnableMouse(true)
150 self.label:SetTextColor(1, 1, 1)
151 end
152 end
153
154 local function OnEnter(this)
155 this.obj.highlight:Show()
156 this.obj:Fire("OnEnter")
157 end
158
159 local function OnLeave(this)
160 this.obj.highlight:Hide()
161 this.obj:Fire("OnLeave")
162 end
163
164 local function OnClick(this, ...)
165 this.obj:Fire("OnClick", ...)
166 AceGUI:ClearFocus()
167 end
168
169 local function Constructor()
170 local frame = CreateFrame("Frame",nil,UIParent)
171 local self = {}
172 self.type = Type
173
174 frame:EnableMouse(true)
175 frame:SetScript("OnEnter", OnEnter)
176 frame:SetScript("OnLeave", OnLeave)
177 frame:SetScript("OnMouseDown", OnClick)
178
179 self.OnRelease = OnRelease
180 self.OnAcquire = OnAcquire
181 self.SetText = SetText
182 self.SetColor = SetColor
183 self.frame = frame
184 self.OnWidthSet = OnWidthSet
185 self.SetImage = SetImage
186 self.SetImageSize = SetImageSize
187 self.SetFont = SetFont
188 self.SetFontObject = SetFontObject
189 self.SetHighlight = SetHighlight
190 self.SetHighlightTexCoord = SetHighlightTexCoord
191 self.SetDisabled = SetDisabled
192 frame.obj = self
193
194 frame:SetHeight(18)
195 frame:SetWidth(200)
196 local label = frame:CreateFontString(nil,"BACKGROUND","GameFontHighlightSmall")
197 label:SetPoint("TOPLEFT",frame,"TOPLEFT",0,0)
198 label:SetWidth(200)
199 label:SetJustifyH("LEFT")
200 label:SetJustifyV("TOP")
201 self.label = label
202
203 local highlight = frame:CreateTexture(nil, "OVERLAY")
204 highlight:SetTexture(nil)
205 highlight:SetAllPoints()
206 highlight:SetBlendMode("ADD")
207 highlight:Hide()
208 self.highlight = highlight
209
210 local image = frame:CreateTexture(nil,"BACKGROUND")
211 self.image = image
212
213 AceGUI:RegisterAsWidget(self)
214 return self
215 end
216
217 AceGUI:RegisterWidgetType(Type,Constructor,Version)
218 end
219