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