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