annotate Libs/AceGUI-3.0/widgets/AceGUIWidget-Label.lua @ 3:c6f0976069c7

Default value for the welcome / bye notification is now set to false The mailframe checkbox now primarily toggles the mail opening, however if you hold shift you can still disable the entire addon Now properly removes QuickAuction?s mail count Now tracks when a mail lost all attachments rather than it being deleted in order to continue processing the next item (mail sent by players containing text should now work properly). This should also be good for a nice speed increase. Added a variable called ?busy? to the MailOpener object indicating whether or not Mail Opener is currently working. Other addons (or macros) can retrieve it with ?LibStub("AceAddon-3.0"):GetAddon("MailOpener").busy? A mail refresh from the Postal service should no longer occur while mail is being opened but will happen instantly afterwards. Postal?s module toggling will now be handled by Postal itself. Added a short summary to the top of all modules for other developers. The time remaining until next mail box refresh should be displayed for as long as Mail Opener can be sure.
author Zerotorescue
date Tue, 07 Sep 2010 17:46:27 +0200
parents 823e33465b6e
children
rev   line source
Zerotorescue@0 1 --[[-----------------------------------------------------------------------------
Zerotorescue@0 2 Label Widget
Zerotorescue@0 3 Displays text and optionally an icon.
Zerotorescue@0 4 -------------------------------------------------------------------------------]]
Zerotorescue@0 5 local Type, Version = "Label", 21
Zerotorescue@0 6 local AceGUI = LibStub and LibStub("AceGUI-3.0", true)
Zerotorescue@0 7 if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
Zerotorescue@0 8
Zerotorescue@0 9 -- Lua APIs
Zerotorescue@0 10 local max, select, pairs = math.max, select, pairs
Zerotorescue@0 11
Zerotorescue@0 12 -- WoW APIs
Zerotorescue@0 13 local CreateFrame, UIParent = CreateFrame, UIParent
Zerotorescue@0 14
Zerotorescue@0 15 -- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
Zerotorescue@0 16 -- List them here for Mikk's FindGlobals script
Zerotorescue@0 17 -- GLOBALS: GameFontHighlightSmall
Zerotorescue@0 18
Zerotorescue@0 19 --[[-----------------------------------------------------------------------------
Zerotorescue@0 20 Support functions
Zerotorescue@0 21 -------------------------------------------------------------------------------]]
Zerotorescue@0 22
Zerotorescue@0 23 local function UpdateImageAnchor(self)
Zerotorescue@0 24 if self.resizing then return end
Zerotorescue@0 25 local frame = self.frame
Zerotorescue@0 26 local width = frame.width or frame:GetWidth() or 0
Zerotorescue@0 27 local image = self.image
Zerotorescue@0 28 local label = self.label
Zerotorescue@0 29 local height
Zerotorescue@0 30
Zerotorescue@0 31 label:ClearAllPoints()
Zerotorescue@0 32 image:ClearAllPoints()
Zerotorescue@0 33
Zerotorescue@0 34 if self.imageshown then
Zerotorescue@0 35 local imagewidth = image:GetWidth()
Zerotorescue@0 36 if (width - imagewidth) < 200 or (label:GetText() or "") == "" then
Zerotorescue@0 37 -- image goes on top centered when less than 200 width for the text, or if there is no text
Zerotorescue@0 38 image:SetPoint("TOP")
Zerotorescue@0 39 label:SetPoint("TOP", image, "BOTTOM")
Zerotorescue@0 40 label:SetPoint("LEFT")
Zerotorescue@0 41 label:SetWidth(width)
Zerotorescue@0 42 height = image:GetHeight() + label:GetHeight()
Zerotorescue@0 43 else
Zerotorescue@0 44 -- image on the left
Zerotorescue@0 45 image:SetPoint("TOPLEFT")
Zerotorescue@0 46 label:SetPoint("TOPLEFT", image, "TOPRIGHT", 4, 0)
Zerotorescue@0 47 label:SetWidth(width - imagewidth - 4)
Zerotorescue@0 48 height = max(image:GetHeight(), label:GetHeight())
Zerotorescue@0 49 end
Zerotorescue@0 50 else
Zerotorescue@0 51 -- no image shown
Zerotorescue@0 52 label:SetPoint("TOPLEFT")
Zerotorescue@0 53 label:SetWidth(width)
Zerotorescue@0 54 height = label:GetHeight()
Zerotorescue@0 55 end
Zerotorescue@0 56
Zerotorescue@0 57 self.resizing = true
Zerotorescue@0 58 frame:SetHeight(height)
Zerotorescue@0 59 frame.height = height
Zerotorescue@0 60 self.resizing = nil
Zerotorescue@0 61 end
Zerotorescue@0 62
Zerotorescue@0 63 --[[-----------------------------------------------------------------------------
Zerotorescue@0 64 Methods
Zerotorescue@0 65 -------------------------------------------------------------------------------]]
Zerotorescue@0 66 local methods = {
Zerotorescue@0 67 ["OnAcquire"] = function(self)
Zerotorescue@0 68 -- set the flag to stop constant size updates
Zerotorescue@0 69 self.resizing = true
Zerotorescue@0 70 -- height is set dynamically by the text and image size
Zerotorescue@0 71 self:SetWidth(200)
Zerotorescue@0 72 self:SetText()
Zerotorescue@0 73 self:SetImage(nil)
Zerotorescue@0 74 self:SetImageSize(16, 16)
Zerotorescue@0 75 self:SetColor()
Zerotorescue@0 76 self:SetFontObject()
Zerotorescue@0 77
Zerotorescue@0 78 -- reset the flag
Zerotorescue@0 79 self.resizing = nil
Zerotorescue@0 80 -- run the update explicitly
Zerotorescue@0 81 UpdateImageAnchor(self)
Zerotorescue@0 82 end,
Zerotorescue@0 83
Zerotorescue@0 84 -- ["OnRelease"] = nil,
Zerotorescue@0 85
Zerotorescue@0 86 ["OnWidthSet"] = function(self, width)
Zerotorescue@0 87 UpdateImageAnchor(self)
Zerotorescue@0 88 end,
Zerotorescue@0 89
Zerotorescue@0 90 ["SetText"] = function(self, text)
Zerotorescue@0 91 self.label:SetText(text)
Zerotorescue@0 92 UpdateImageAnchor(self)
Zerotorescue@0 93 end,
Zerotorescue@0 94
Zerotorescue@0 95 ["SetColor"] = function(self, r, g, b)
Zerotorescue@0 96 if not (r and g and b) then
Zerotorescue@0 97 r, g, b = 1, 1, 1
Zerotorescue@0 98 end
Zerotorescue@0 99 self.label:SetVertexColor(r, g, b)
Zerotorescue@0 100 end,
Zerotorescue@0 101
Zerotorescue@0 102 ["SetImage"] = function(self, path, ...)
Zerotorescue@0 103 local image = self.image
Zerotorescue@0 104 image:SetTexture(path)
Zerotorescue@0 105
Zerotorescue@0 106 if image:GetTexture() then
Zerotorescue@0 107 self.imageshown = true
Zerotorescue@0 108 local n = select("#", ...)
Zerotorescue@0 109 if n == 4 or n == 8 then
Zerotorescue@0 110 image:SetTexCoord(...)
Zerotorescue@0 111 else
Zerotorescue@0 112 image:SetTexCoord(0, 1, 0, 1)
Zerotorescue@0 113 end
Zerotorescue@0 114 else
Zerotorescue@0 115 self.imageshown = nil
Zerotorescue@0 116 end
Zerotorescue@0 117 UpdateImageAnchor(self)
Zerotorescue@0 118 end,
Zerotorescue@0 119
Zerotorescue@0 120 ["SetFont"] = function(self, font, height, flags)
Zerotorescue@0 121 self.label:SetFont(font, height, flags)
Zerotorescue@0 122 end,
Zerotorescue@0 123
Zerotorescue@0 124 ["SetFontObject"] = function(self, font)
Zerotorescue@0 125 self:SetFont((font or GameFontHighlightSmall):GetFont())
Zerotorescue@0 126 end,
Zerotorescue@0 127
Zerotorescue@0 128 ["SetImageSize"] = function(self, width, height)
Zerotorescue@0 129 self.image:SetWidth(width)
Zerotorescue@0 130 self.image:SetHeight(height)
Zerotorescue@0 131 UpdateImageAnchor(self)
Zerotorescue@0 132 end,
Zerotorescue@0 133 }
Zerotorescue@0 134
Zerotorescue@0 135 --[[-----------------------------------------------------------------------------
Zerotorescue@0 136 Constructor
Zerotorescue@0 137 -------------------------------------------------------------------------------]]
Zerotorescue@0 138 local function Constructor()
Zerotorescue@0 139 local frame = CreateFrame("Frame", nil, UIParent)
Zerotorescue@0 140 frame:Hide()
Zerotorescue@0 141
Zerotorescue@0 142 local label = frame:CreateFontString(nil, "BACKGROUND", "GameFontHighlightSmall")
Zerotorescue@0 143 label:SetJustifyH("LEFT")
Zerotorescue@0 144 label:SetJustifyV("TOP")
Zerotorescue@0 145
Zerotorescue@0 146 local image = frame:CreateTexture(nil, "BACKGROUND")
Zerotorescue@0 147
Zerotorescue@0 148 -- create widget
Zerotorescue@0 149 local widget = {
Zerotorescue@0 150 label = label,
Zerotorescue@0 151 image = image,
Zerotorescue@0 152 frame = frame,
Zerotorescue@0 153 type = Type
Zerotorescue@0 154 }
Zerotorescue@0 155 for method, func in pairs(methods) do
Zerotorescue@0 156 widget[method] = func
Zerotorescue@0 157 end
Zerotorescue@0 158
Zerotorescue@0 159 return AceGUI:RegisterAsWidget(widget)
Zerotorescue@0 160 end
Zerotorescue@0 161
Zerotorescue@0 162 AceGUI:RegisterWidgetType(Type, Constructor, Version)