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