|
Tercio@11
|
1
|
|
Tercio@11
|
2 local DF = _G ["DetailsFramework"]
|
|
Tercio@20
|
3 if (not DF or not DetailsFrameworkCanLoad) then
|
|
Tercio@20
|
4 return
|
|
Tercio@20
|
5 end
|
|
Tercio@20
|
6
|
|
Tercio@11
|
7 local _
|
|
Tercio@11
|
8 local _rawset = rawset --> lua local
|
|
Tercio@11
|
9 local _rawget = rawget --> lua local
|
|
Tercio@11
|
10 local _setmetatable = setmetatable --> lua local
|
|
Tercio@11
|
11 local _unpack = unpack --> lua local
|
|
Tercio@11
|
12 local _type = type --> lua local
|
|
Tercio@11
|
13 local _math_floor = math.floor --> lua local
|
|
Tercio@11
|
14 local loadstring = loadstring --> lua local
|
|
Tercio@11
|
15
|
|
Tercio@11
|
16 local cleanfunction = function() end
|
|
Tercio@11
|
17 local APIImageFunctions = false
|
|
Tercio@11
|
18 local ImageMetaFunctions = {}
|
|
Tercio@11
|
19
|
|
Tercio@11
|
20 ------------------------------------------------------------------------------------------------------------
|
|
Tercio@11
|
21 --> metatables
|
|
Tercio@11
|
22
|
|
Tercio@11
|
23 ImageMetaFunctions.__call = function (_table, value)
|
|
Tercio@11
|
24 return self.image:SetTexture (value)
|
|
Tercio@11
|
25 end
|
|
Tercio@11
|
26
|
|
Tercio@11
|
27 ------------------------------------------------------------------------------------------------------------
|
|
Tercio@11
|
28 --> members
|
|
Tercio@11
|
29
|
|
Tercio@11
|
30 --> shown
|
|
Tercio@11
|
31 local gmember_shown = function (_object)
|
|
Tercio@11
|
32 return _object:IsShown()
|
|
Tercio@11
|
33 end
|
|
Tercio@11
|
34 --> frame width
|
|
Tercio@11
|
35 local gmember_width = function (_object)
|
|
Tercio@11
|
36 return _object.image:GetWidth()
|
|
Tercio@11
|
37 end
|
|
Tercio@11
|
38 --> frame height
|
|
Tercio@11
|
39 local gmember_height = function (_object)
|
|
Tercio@11
|
40 return _object.image:GetHeight()
|
|
Tercio@11
|
41 end
|
|
Tercio@11
|
42 --> texture
|
|
Tercio@11
|
43 local gmember_texture = function (_object)
|
|
Tercio@11
|
44 return _object.image:GetTexture()
|
|
Tercio@11
|
45 end
|
|
Tercio@11
|
46 --> alpha
|
|
Tercio@11
|
47 local gmember_alpha = function (_object)
|
|
Tercio@11
|
48 return _object.image:GetAlpha()
|
|
Tercio@11
|
49 end
|
|
Tercio@11
|
50
|
|
Tercio@11
|
51 local get_members_function_index = {
|
|
Tercio@11
|
52 ["shown"] = gmember_shown,
|
|
Tercio@11
|
53 ["alpha"] = gmember_alpha,
|
|
Tercio@11
|
54 ["width"] = gmember_width,
|
|
Tercio@11
|
55 ["height"] = gmember_height,
|
|
Tercio@11
|
56 ["texture"] = gmember_texture,
|
|
Tercio@11
|
57 }
|
|
Tercio@11
|
58
|
|
Tercio@11
|
59 ImageMetaFunctions.__index = function (_table, _member_requested)
|
|
Tercio@11
|
60
|
|
Tercio@11
|
61 local func = get_members_function_index [_member_requested]
|
|
Tercio@11
|
62 if (func) then
|
|
Tercio@11
|
63 return func (_table, _member_requested)
|
|
Tercio@11
|
64 end
|
|
Tercio@11
|
65
|
|
Tercio@11
|
66 local fromMe = _rawget (_table, _member_requested)
|
|
Tercio@11
|
67 if (fromMe) then
|
|
Tercio@11
|
68 return fromMe
|
|
Tercio@11
|
69 end
|
|
Tercio@11
|
70
|
|
Tercio@11
|
71 return ImageMetaFunctions [_member_requested]
|
|
Tercio@11
|
72 end
|
|
Tercio@11
|
73
|
|
Tercio@11
|
74 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
Tercio@11
|
75
|
|
Tercio@11
|
76 --> show
|
|
Tercio@11
|
77 local smember_show = function (_object, _value)
|
|
Tercio@11
|
78 if (_value) then
|
|
Tercio@11
|
79 return _object:Show()
|
|
Tercio@11
|
80 else
|
|
Tercio@11
|
81 return _object:Hide()
|
|
Tercio@11
|
82 end
|
|
Tercio@11
|
83 end
|
|
Tercio@11
|
84 --> hide
|
|
Tercio@11
|
85 local smember_hide = function (_object, _value)
|
|
Tercio@11
|
86 if (not _value) then
|
|
Tercio@11
|
87 return _object:Show()
|
|
Tercio@11
|
88 else
|
|
Tercio@11
|
89 return _object:Hide()
|
|
Tercio@11
|
90 end
|
|
Tercio@11
|
91 end
|
|
Tercio@11
|
92 --> texture
|
|
Tercio@11
|
93 local smember_texture = function (_object, _value)
|
|
Tercio@11
|
94 if (type (_value) == "table") then
|
|
Tercio@11
|
95 local r, g, b, a = DF:ParseColors (_value)
|
|
Tercio@11
|
96 _object.image:SetTexture (r, g, b, a or 1)
|
|
Tercio@11
|
97 else
|
|
Tercio@11
|
98 if (DF:IsHtmlColor (_value)) then
|
|
Tercio@11
|
99 local r, g, b, a = DF:ParseColors (_value)
|
|
Tercio@11
|
100 _object.image:SetTexture (r, g, b, a or 1)
|
|
Tercio@11
|
101 else
|
|
Tercio@11
|
102 _object.image:SetTexture (_value)
|
|
Tercio@11
|
103 end
|
|
Tercio@11
|
104 end
|
|
Tercio@11
|
105 end
|
|
Tercio@11
|
106 --> width
|
|
Tercio@11
|
107 local smember_width = function (_object, _value)
|
|
Tercio@11
|
108 return _object.image:SetWidth (_value)
|
|
Tercio@11
|
109 end
|
|
Tercio@11
|
110 --> height
|
|
Tercio@11
|
111 local smember_height = function (_object, _value)
|
|
Tercio@11
|
112 return _object.image:SetHeight (_value)
|
|
Tercio@11
|
113 end
|
|
Tercio@11
|
114 --> alpha
|
|
Tercio@11
|
115 local smember_alpha = function (_object, _value)
|
|
Tercio@11
|
116 return _object.image:SetAlpha (_value)
|
|
Tercio@11
|
117 end
|
|
Tercio@11
|
118 --> color
|
|
Tercio@11
|
119 local smember_color = function (_object, _value)
|
|
Tercio@11
|
120 if (type (_value) == "table") then
|
|
Tercio@11
|
121 local r, g, b, a = DF:ParseColors (_value)
|
|
Tercio@11
|
122 _object.image:SetTexture (r,g,b, a or 1)
|
|
Tercio@11
|
123 else
|
|
Tercio@11
|
124 if (DF:IsHtmlColor (_value)) then
|
|
Tercio@11
|
125 local r, g, b, a = DF:ParseColors (_value)
|
|
Tercio@11
|
126 _object.image:SetTexture (r, g, b, a or 1)
|
|
Tercio@11
|
127 else
|
|
Tercio@11
|
128 _object.image:SetTexture (_value)
|
|
Tercio@11
|
129 end
|
|
Tercio@11
|
130 end
|
|
Tercio@11
|
131 end
|
|
Tercio@11
|
132 --> desaturated
|
|
Tercio@11
|
133 local smember_desaturated = function (_object, _value)
|
|
Tercio@11
|
134 if (_value) then
|
|
Tercio@11
|
135 _object:SetDesaturated (true)
|
|
Tercio@11
|
136 else
|
|
Tercio@11
|
137 _object:SetDesaturated (false)
|
|
Tercio@11
|
138 end
|
|
Tercio@11
|
139 end
|
|
Tercio@11
|
140 --> texcoords
|
|
Tercio@11
|
141 local smember_texcoord = function (_object, _value)
|
|
Tercio@11
|
142 if (_value) then
|
|
Tercio@11
|
143 _object:SetTexCoord (unpack (_value))
|
|
Tercio@11
|
144 else
|
|
Tercio@11
|
145 _object:SetTexCoord (0, 1, 0, 1)
|
|
Tercio@11
|
146 end
|
|
Tercio@11
|
147 end
|
|
Tercio@11
|
148
|
|
Tercio@11
|
149 local set_members_function_index = {
|
|
Tercio@11
|
150 ["show"] = smember_show,
|
|
Tercio@11
|
151 ["hide"] = smember_hide,
|
|
Tercio@11
|
152 ["alpha"] = smember_alpha,
|
|
Tercio@11
|
153 ["width"] = smember_width,
|
|
Tercio@11
|
154 ["height"] = smember_height,
|
|
Tercio@11
|
155 ["texture"] = smember_texture,
|
|
Tercio@11
|
156 ["texcoord"] = smember_texcoord,
|
|
Tercio@11
|
157 ["color"] = smember_color,
|
|
Tercio@11
|
158 ["blackwhite"] = smember_desaturated,
|
|
Tercio@11
|
159 }
|
|
Tercio@11
|
160
|
|
Tercio@11
|
161 ImageMetaFunctions.__newindex = function (_table, _key, _value)
|
|
Tercio@11
|
162 local func = set_members_function_index [_key]
|
|
Tercio@11
|
163 if (func) then
|
|
Tercio@11
|
164 return func (_table, _value)
|
|
Tercio@11
|
165 else
|
|
Tercio@11
|
166 return _rawset (_table, _key, _value)
|
|
Tercio@11
|
167 end
|
|
Tercio@11
|
168 end
|
|
Tercio@11
|
169
|
|
Tercio@11
|
170 ------------------------------------------------------------------------------------------------------------
|
|
Tercio@11
|
171 --> methods
|
|
Tercio@11
|
172 --> show & hide
|
|
Tercio@11
|
173 function ImageMetaFunctions:IsShown()
|
|
Tercio@11
|
174 return self.image:IsShown()
|
|
Tercio@11
|
175 end
|
|
Tercio@11
|
176 function ImageMetaFunctions:Show()
|
|
Tercio@11
|
177 return self.image:Show()
|
|
Tercio@11
|
178 end
|
|
Tercio@11
|
179 function ImageMetaFunctions:Hide()
|
|
Tercio@11
|
180 return self.image:Hide()
|
|
Tercio@11
|
181 end
|
|
Tercio@11
|
182
|
|
Tercio@11
|
183 -- setpoint
|
|
Tercio@11
|
184 function ImageMetaFunctions:SetPoint (v1, v2, v3, v4, v5)
|
|
Tercio@11
|
185 v1, v2, v3, v4, v5 = DF:CheckPoints (v1, v2, v3, v4, v5, self)
|
|
Tercio@11
|
186 if (not v1) then
|
|
Tercio@11
|
187 print ("Invalid parameter for SetPoint")
|
|
Tercio@11
|
188 return
|
|
Tercio@11
|
189 end
|
|
Tercio@11
|
190 return self.widget:SetPoint (v1, v2, v3, v4, v5)
|
|
Tercio@11
|
191 end
|
|
Tercio@11
|
192
|
|
Tercio@11
|
193 -- sizes
|
|
Tercio@11
|
194 function ImageMetaFunctions:SetSize (w, h)
|
|
Tercio@11
|
195 if (w) then
|
|
Tercio@11
|
196 self.image:SetWidth (w)
|
|
Tercio@11
|
197 end
|
|
Tercio@11
|
198 if (h) then
|
|
Tercio@11
|
199 return self.image:SetHeight (h)
|
|
Tercio@11
|
200 end
|
|
Tercio@11
|
201 end
|
|
Tercio@11
|
202
|
|
Tercio@11
|
203 ------------------------------------------------------------------------------------------------------------
|
|
Tercio@11
|
204 --> scripts
|
|
Tercio@11
|
205
|
|
Tercio@11
|
206 ------------------------------------------------------------------------------------------------------------
|
|
Tercio@11
|
207 --> object constructor
|
|
Tercio@11
|
208
|
|
Tercio@11
|
209 function DF:CreateImage (parent, texture, w, h, layer, coords, member, name)
|
|
Tercio@11
|
210 return DF:NewImage (parent, texture, w, h, layer, coords, member, name)
|
|
Tercio@11
|
211 end
|
|
Tercio@11
|
212
|
|
Tercio@11
|
213 function DF:NewImage (parent, texture, w, h, layer, coords, member, name)
|
|
Tercio@11
|
214
|
|
Tercio@11
|
215 if (not parent) then
|
|
Tercio@11
|
216 return nil
|
|
Tercio@11
|
217 end
|
|
Tercio@11
|
218
|
|
Tercio@11
|
219 if (not name) then
|
|
Tercio@11
|
220 name = "DetailsFrameworkPictureNumber" .. DF.PictureNameCounter
|
|
Tercio@11
|
221 DF.PictureNameCounter = DF.PictureNameCounter + 1
|
|
Tercio@11
|
222 end
|
|
Tercio@11
|
223
|
|
Tercio@11
|
224 if (name:find ("$parent")) then
|
|
Tercio@11
|
225 name = name:gsub ("$parent", parent:GetName())
|
|
Tercio@11
|
226 end
|
|
Tercio@11
|
227
|
|
Tercio@11
|
228 local ImageObject = {type = "image", dframework = true}
|
|
Tercio@11
|
229
|
|
Tercio@11
|
230 if (member) then
|
|
Tercio@11
|
231 parent [member] = ImageObject
|
|
Tercio@11
|
232 end
|
|
Tercio@11
|
233
|
|
Tercio@11
|
234 if (parent.dframework) then
|
|
Tercio@11
|
235 parent = parent.widget
|
|
Tercio@11
|
236 end
|
|
Tercio@11
|
237
|
|
Tercio@11
|
238 texture = texture or ""
|
|
Tercio@11
|
239
|
|
Tercio@11
|
240 ImageObject.image = parent:CreateTexture (name, layer or "OVERLAY")
|
|
Tercio@11
|
241 ImageObject.widget = ImageObject.image
|
|
Tercio@11
|
242
|
|
Tercio@11
|
243 if (not APIImageFunctions) then
|
|
Tercio@11
|
244 APIImageFunctions = true
|
|
Tercio@11
|
245 local idx = getmetatable (ImageObject.image).__index
|
|
Tercio@11
|
246 for funcName, funcAddress in pairs (idx) do
|
|
Tercio@11
|
247 if (not ImageMetaFunctions [funcName]) then
|
|
Tercio@11
|
248 ImageMetaFunctions [funcName] = function (object, ...)
|
|
Tercio@20
|
249 local x = loadstring ( "return _G['"..object.image:GetName().."']:"..funcName.."(...)")
|
|
Tercio@11
|
250 return x (...)
|
|
Tercio@11
|
251 end
|
|
Tercio@11
|
252 end
|
|
Tercio@11
|
253 end
|
|
Tercio@11
|
254 end
|
|
Tercio@11
|
255
|
|
Tercio@11
|
256 ImageObject.image.MyObject = ImageObject
|
|
Tercio@11
|
257
|
|
Tercio@11
|
258 if (w) then
|
|
Tercio@11
|
259 ImageObject.image:SetWidth (w)
|
|
Tercio@11
|
260 end
|
|
Tercio@11
|
261 if (h) then
|
|
Tercio@11
|
262 ImageObject.image:SetHeight (h)
|
|
Tercio@11
|
263 end
|
|
Tercio@11
|
264 if (texture) then
|
|
Tercio@11
|
265 if (type (texture) == "table") then
|
|
Tercio@11
|
266 local r, g, b = DF:ParseColors (texture)
|
|
Tercio@11
|
267 ImageObject.image:SetTexture (r,g,b)
|
|
Tercio@11
|
268 else
|
|
Tercio@11
|
269 if (DF:IsHtmlColor (texture)) then
|
|
Tercio@11
|
270 local r, g, b = DF:ParseColors (texture)
|
|
Tercio@11
|
271 ImageObject.image:SetTexture (r, g, b)
|
|
Tercio@11
|
272 else
|
|
Tercio@11
|
273 ImageObject.image:SetTexture (texture)
|
|
Tercio@11
|
274 end
|
|
Tercio@11
|
275 end
|
|
Tercio@11
|
276 end
|
|
Tercio@11
|
277
|
|
Tercio@11
|
278 if (coords and type (coords) == "table" and coords [4]) then
|
|
Tercio@11
|
279 ImageObject.image:SetTexCoord (unpack (coords))
|
|
Tercio@11
|
280 end
|
|
Tercio@11
|
281
|
|
Tercio@11
|
282 setmetatable (ImageObject, ImageMetaFunctions)
|
|
Tercio@11
|
283
|
|
Tercio@11
|
284 return ImageObject
|
|
Tercio@11
|
285 end |