comparison ui/AmrUiIcon.lua @ 57:01b63b8ed811 v21

total rewrite to version 21
author yellowfive
date Fri, 05 Jun 2015 11:05:15 -0700
parents
children 0515882856f1
comparison
equal deleted inserted replaced
56:75431c084aa0 57:01b63b8ed811
1 --[[-----------------------------------------------------------------------------
2 Icon Container
3 Simple container widget that is an icon, and can optionally contain children.
4 -------------------------------------------------------------------------------]]
5 local Type, Version = "AmrUiIcon", 1
6 local AceGUI = LibStub and LibStub("AceGUI-3.0", true)
7 if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
8
9 local Amr = LibStub("AceAddon-3.0"):GetAddon("AskMrRobot")
10
11 -- Lua APIs
12 local pairs = pairs
13
14 -- WoW APIs
15 local CreateFrame, UIParent = CreateFrame, UIParent
16
17 --[[-----------------------------------------------------------------------------
18 Support Functions
19 -------------------------------------------------------------------------------]]
20 local function setIconBorderWidth(frame, icon, width)
21 icon:ClearAllPoints()
22 icon:SetPoint("TOPLEFT", frame, "TOPLEFT", width, -width)
23 icon:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -width, width)
24 end
25
26 --[[-----------------------------------------------------------------------------
27 Scripts
28 -------------------------------------------------------------------------------]]
29
30 local function frameOnEnter(frame)
31 frame.obj:Fire("OnEnter")
32 end
33
34 local function frameOnLeave(frame)
35 frame.obj:Fire("OnLeave")
36 end
37
38 --[[-----------------------------------------------------------------------------
39 Methods
40 -------------------------------------------------------------------------------]]
41 local methods = {
42 ["OnAcquire"] = function(self)
43 self:SetAutoAdjustHeight(false)
44 self:SetWidth(64)
45 self:SetHeight(64)
46 self:SetBorderWidth(2)
47 self:HideIconBorder()
48 self:SetIcon(nil)
49 self:SetStrata("FULLSCREEN_DIALOG")
50 self:SetLevel(0)
51 self:SetVisible(true)
52 self.frame:ClearAllPoints()
53 self.icon:SetDesaturated(false)
54 end,
55
56 ["SetIcon"] = function(self, icon)
57 if not icon then
58 self.icon:SetTexture(0, 0, 0, 0)
59 else
60 self.icon:SetTexture(icon)
61 end
62 end,
63
64 ["SetBorderWidth"] = function(self, width)
65 setIconBorderWidth(self.frame, self.icon, width)
66 end,
67
68 ["SetIconBorderColor"] = function(self, color, a)
69 self.bg:SetTexture(color.R, color.G, color.B, a or 1)
70 end,
71
72 ["HideIconBorder"] = function(self)
73 self.bg:SetTexture(0, 0, 0, 0)
74 end,
75
76 ["SetStrata"] = function(self, strata)
77 self.frame:SetFrameStrata(strata)
78 end,
79
80 ["SetLevel"] = function(self, level)
81 self.frame:SetFrameLevel(level)
82 end,
83
84
85 ["SetVisible"] = function(self, visible)
86 if visible then
87 self.frame:Show()
88 else
89 self.frame:Hide()
90 end
91 end
92 }
93
94 --[[-----------------------------------------------------------------------------
95 Constructor
96 -------------------------------------------------------------------------------]]
97 local function Constructor()
98 local frame = CreateFrame("Frame", nil, UIParent)
99 frame:SetFrameStrata("FULLSCREEN_DIALOG")
100
101 frame:SetScript("OnEnter", frameOnEnter)
102 frame:SetScript("OnLeave", frameOnLeave)
103
104 local bg = frame:CreateTexture(nil, "BORDER")
105 bg:SetAllPoints()
106
107 local icon = frame:CreateTexture(nil, "ARTWORK", nil, 1)
108 icon:SetTexCoord(0.05, 0.95, 0.05, 0.95)
109
110 local borderTop = frame:CreateTexture(nil, "ARTWORK", nil, 2)
111 borderTop:SetTexture(0, 0, 0, 1)
112 borderTop:SetHeight(1)
113 borderTop:SetPoint("TOPLEFT", icon, "TOPLEFT")
114 borderTop:SetPoint("TOPRIGHT", icon, "TOPRIGHT")
115
116 local borderRight = frame:CreateTexture(nil, "ARTWORK", nil, 2)
117 borderRight:SetTexture(0, 0, 0, 1)
118 borderRight:SetWidth(1)
119 borderRight:SetPoint("TOPRIGHT", icon, "TOPRIGHT")
120 borderRight:SetPoint("BOTTOMRIGHT", icon, "BOTTOMRIGHT")
121
122 local borderBottom = frame:CreateTexture(nil, "ARTWORK", nil, 2)
123 borderBottom:SetTexture(0, 0, 0, 1)
124 borderBottom:SetHeight(1)
125 borderBottom:SetPoint("BOTTOMLEFT", icon, "BOTTOMLEFT")
126 borderBottom:SetPoint("BOTTOMRIGHT", icon, "BOTTOMRIGHT")
127
128 local borderLeft = frame:CreateTexture(nil, "ARTWORK", nil, 2)
129 borderLeft:SetTexture(0, 0, 0, 1)
130 borderLeft:SetWidth(1)
131 borderLeft:SetPoint("TOPLEFT", icon, "TOPLEFT")
132 borderLeft:SetPoint("BOTTOMLEFT", icon, "BOTTOMLEFT")
133
134 local widget = {
135 bg = bg,
136 icon = icon,
137 frame = frame,
138 content = frame,
139 type = Type
140 }
141 for method, func in pairs(methods) do
142 widget[method] = func
143 end
144
145 return AceGUI:RegisterAsContainer(widget)
146 end
147
148 AceGUI:RegisterWidgetType(Type, Constructor, Version)