annotate Libs/AceGUI-3.0/widgets/AceGUIWidget-Icon.lua @ 0:c6ff7ba0e8f6

Reasonably functional now. Cleaning up some stuff which might have to be reverted.
author Zerotorescue
date Thu, 07 Oct 2010 17:17:43 +0200
parents
children
rev   line source
Zerotorescue@0 1 --[[-----------------------------------------------------------------------------
Zerotorescue@0 2 Icon Widget
Zerotorescue@0 3 -------------------------------------------------------------------------------]]
Zerotorescue@0 4 local Type, Version = "Icon", 20
Zerotorescue@0 5 local AceGUI = LibStub and LibStub("AceGUI-3.0", true)
Zerotorescue@0 6 if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
Zerotorescue@0 7
Zerotorescue@0 8 -- Lua APIs
Zerotorescue@0 9 local select, pairs, print = select, pairs, print
Zerotorescue@0 10
Zerotorescue@0 11 -- WoW APIs
Zerotorescue@0 12 local CreateFrame, UIParent, GetBuildInfo = CreateFrame, UIParent, GetBuildInfo
Zerotorescue@0 13
Zerotorescue@0 14 --[[-----------------------------------------------------------------------------
Zerotorescue@0 15 Scripts
Zerotorescue@0 16 -------------------------------------------------------------------------------]]
Zerotorescue@0 17 local function Control_OnEnter(frame)
Zerotorescue@0 18 frame.obj:Fire("OnEnter")
Zerotorescue@0 19 end
Zerotorescue@0 20
Zerotorescue@0 21 local function Control_OnLeave(frame)
Zerotorescue@0 22 frame.obj:Fire("OnLeave")
Zerotorescue@0 23 end
Zerotorescue@0 24
Zerotorescue@0 25 local function Button_OnClick(frame, button)
Zerotorescue@0 26 frame.obj:Fire("OnClick", button)
Zerotorescue@0 27 AceGUI:ClearFocus()
Zerotorescue@0 28 end
Zerotorescue@0 29
Zerotorescue@0 30 --[[-----------------------------------------------------------------------------
Zerotorescue@0 31 Methods
Zerotorescue@0 32 -------------------------------------------------------------------------------]]
Zerotorescue@0 33 local methods = {
Zerotorescue@0 34 ["OnAcquire"] = function(self)
Zerotorescue@0 35 self:SetHeight(110)
Zerotorescue@0 36 self:SetWidth(110)
Zerotorescue@0 37 self:SetLabel()
Zerotorescue@0 38 self:SetImage(nil)
Zerotorescue@0 39 self:SetImageSize(64, 64)
Zerotorescue@0 40 self:SetDisabled(false)
Zerotorescue@0 41 end,
Zerotorescue@0 42
Zerotorescue@0 43 -- ["OnRelease"] = nil,
Zerotorescue@0 44
Zerotorescue@0 45 ["SetLabel"] = function(self, text)
Zerotorescue@0 46 if text and text ~= "" then
Zerotorescue@0 47 self.label:Show()
Zerotorescue@0 48 self.label:SetText(text)
Zerotorescue@0 49 self:SetHeight(self.image:GetHeight() + 25)
Zerotorescue@0 50 else
Zerotorescue@0 51 self.label:Hide()
Zerotorescue@0 52 self:SetHeight(self.image:GetHeight() + 10)
Zerotorescue@0 53 end
Zerotorescue@0 54 end,
Zerotorescue@0 55
Zerotorescue@0 56 ["SetImage"] = function(self, path, ...)
Zerotorescue@0 57 local image = self.image
Zerotorescue@0 58 image:SetTexture(path)
Zerotorescue@0 59
Zerotorescue@0 60 if image:GetTexture() then
Zerotorescue@0 61 local n = select("#", ...)
Zerotorescue@0 62 if n == 4 or n == 8 then
Zerotorescue@0 63 image:SetTexCoord(...)
Zerotorescue@0 64 else
Zerotorescue@0 65 image:SetTexCoord(0, 1, 0, 1)
Zerotorescue@0 66 end
Zerotorescue@0 67 end
Zerotorescue@0 68 end,
Zerotorescue@0 69
Zerotorescue@0 70 ["SetImageSize"] = function(self, width, height)
Zerotorescue@0 71 self.image:SetWidth(width)
Zerotorescue@0 72 self.image:SetHeight(height)
Zerotorescue@0 73 --self.frame:SetWidth(width + 30)
Zerotorescue@0 74 if self.label:IsShown() then
Zerotorescue@0 75 self:SetHeight(height + 25)
Zerotorescue@0 76 else
Zerotorescue@0 77 self:SetHeight(height + 10)
Zerotorescue@0 78 end
Zerotorescue@0 79 end,
Zerotorescue@0 80
Zerotorescue@0 81 ["SetDisabled"] = function(self, disabled)
Zerotorescue@0 82 self.disabled = disabled
Zerotorescue@0 83 if disabled then
Zerotorescue@0 84 self.frame:Disable()
Zerotorescue@0 85 self.label:SetTextColor(0.5, 0.5, 0.5)
Zerotorescue@0 86 self.image:SetVertexColor(0.5, 0.5, 0.5, 0.5)
Zerotorescue@0 87 else
Zerotorescue@0 88 self.frame:Enable()
Zerotorescue@0 89 self.label:SetTextColor(1, 1, 1)
Zerotorescue@0 90 self.image:SetVertexColor(1, 1, 1)
Zerotorescue@0 91 end
Zerotorescue@0 92 end
Zerotorescue@0 93 }
Zerotorescue@0 94
Zerotorescue@0 95 --[[-----------------------------------------------------------------------------
Zerotorescue@0 96 Constructor
Zerotorescue@0 97 -------------------------------------------------------------------------------]]
Zerotorescue@0 98 local function Constructor()
Zerotorescue@0 99 local frame = CreateFrame("Button", nil, UIParent)
Zerotorescue@0 100 frame:Hide()
Zerotorescue@0 101
Zerotorescue@0 102 frame:EnableMouse(true)
Zerotorescue@0 103 frame:SetScript("OnEnter", Control_OnEnter)
Zerotorescue@0 104 frame:SetScript("OnLeave", Control_OnLeave)
Zerotorescue@0 105 frame:SetScript("OnClick", Button_OnClick)
Zerotorescue@0 106
Zerotorescue@0 107 local label = frame:CreateFontString(nil, "BACKGROUND", "GameFontHighlight")
Zerotorescue@0 108 label:SetPoint("BOTTOMLEFT")
Zerotorescue@0 109 label:SetPoint("BOTTOMRIGHT")
Zerotorescue@0 110 label:SetJustifyH("CENTER")
Zerotorescue@0 111 label:SetJustifyV("TOP")
Zerotorescue@0 112 label:SetHeight(18)
Zerotorescue@0 113
Zerotorescue@0 114 local image = frame:CreateTexture(nil, "BACKGROUND")
Zerotorescue@0 115 image:SetWidth(64)
Zerotorescue@0 116 image:SetHeight(64)
Zerotorescue@0 117 image:SetPoint("TOP", 0, -5)
Zerotorescue@0 118
Zerotorescue@0 119 local highlight = frame:CreateTexture(nil, "HIGHLIGHT")
Zerotorescue@0 120 highlight:SetAllPoints(image)
Zerotorescue@0 121 highlight:SetTexture("Interface\\PaperDollInfoFrame\\UI-Character-Tab-Highlight")
Zerotorescue@0 122 highlight:SetTexCoord(0, 1, 0.23, 0.77)
Zerotorescue@0 123 highlight:SetBlendMode("ADD")
Zerotorescue@0 124
Zerotorescue@0 125 local widget = {
Zerotorescue@0 126 label = label,
Zerotorescue@0 127 image = image,
Zerotorescue@0 128 frame = frame,
Zerotorescue@0 129 type = Type
Zerotorescue@0 130 }
Zerotorescue@0 131 for method, func in pairs(methods) do
Zerotorescue@0 132 widget[method] = func
Zerotorescue@0 133 end
Zerotorescue@0 134 -- SetText is deprecated, but keep it around for a while. (say, to WoW 4.0)
Zerotorescue@0 135 if (select(4, GetBuildInfo()) < 40000) then
Zerotorescue@0 136 widget.SetText = widget.SetLabel
Zerotorescue@0 137 else
Zerotorescue@0 138 widget.SetText = function(self, ...) print("AceGUI-3.0-Icon: SetText is deprecated! Use SetLabel instead!"); self:SetLabel(...) end
Zerotorescue@0 139 end
Zerotorescue@0 140
Zerotorescue@0 141 return AceGUI:RegisterAsWidget(widget)
Zerotorescue@0 142 end
Zerotorescue@0 143
Zerotorescue@0 144 AceGUI:RegisterWidgetType(Type, Constructor, Version)