Tercio@11: Tercio@11: local DF = _G ["DetailsFramework"] Tercio@20: if (not DF or not DetailsFrameworkCanLoad) then Tercio@20: return Tercio@20: end Tercio@20: Tercio@11: local _ Tercio@11: local _rawset = rawset --> lua local Tercio@11: local _rawget = rawget --> lua local Tercio@11: local _setmetatable = setmetatable --> lua local Tercio@11: local _unpack = unpack --> lua local Tercio@11: local _type = type --> lua local Tercio@11: local _math_floor = math.floor --> lua local Tercio@11: local loadstring = loadstring --> lua local Tercio@11: Tercio@11: local cleanfunction = function() end Tercio@11: local APIImageFunctions = false Tercio@39: Tercio@39: do Tercio@39: local metaPrototype = { Tercio@39: WidgetType = "image", Tercio@39: SetHook = DF.SetHook, Tercio@39: RunHooksForWidget = DF.RunHooksForWidget, Tercio@39: } Tercio@39: Tercio@39: _G [DF.GlobalWidgetControlNames ["image"]] = _G [DF.GlobalWidgetControlNames ["image"]] or metaPrototype Tercio@39: end Tercio@39: Tercio@39: local ImageMetaFunctions = _G [DF.GlobalWidgetControlNames ["image"]] Tercio@11: Tercio@11: ------------------------------------------------------------------------------------------------------------ Tercio@11: --> metatables Tercio@11: Tercio@11: ImageMetaFunctions.__call = function (_table, value) Tercio@11: return self.image:SetTexture (value) Tercio@11: end Tercio@11: Tercio@11: ------------------------------------------------------------------------------------------------------------ Tercio@11: --> members Tercio@11: Tercio@11: --> shown Tercio@11: local gmember_shown = function (_object) Tercio@11: return _object:IsShown() Tercio@11: end Tercio@11: --> frame width Tercio@11: local gmember_width = function (_object) Tercio@11: return _object.image:GetWidth() Tercio@11: end Tercio@11: --> frame height Tercio@11: local gmember_height = function (_object) Tercio@11: return _object.image:GetHeight() Tercio@11: end Tercio@11: --> texture Tercio@11: local gmember_texture = function (_object) Tercio@11: return _object.image:GetTexture() Tercio@11: end Tercio@11: --> alpha Tercio@11: local gmember_alpha = function (_object) Tercio@11: return _object.image:GetAlpha() Tercio@11: end Tercio@11: Tercio@39: ImageMetaFunctions.GetMembers = ImageMetaFunctions.GetMembers or {} Tercio@39: ImageMetaFunctions.GetMembers ["shown"] = gmember_shown Tercio@39: ImageMetaFunctions.GetMembers ["alpha"] = gmember_alpha Tercio@39: ImageMetaFunctions.GetMembers ["width"] = gmember_width Tercio@39: ImageMetaFunctions.GetMembers ["height"] = gmember_height Tercio@39: ImageMetaFunctions.GetMembers ["texture"] = gmember_texture Tercio@39: Tercio@11: ImageMetaFunctions.__index = function (_table, _member_requested) Tercio@11: Tercio@39: local func = ImageMetaFunctions.GetMembers [_member_requested] Tercio@11: if (func) then Tercio@11: return func (_table, _member_requested) Tercio@11: end Tercio@11: Tercio@11: local fromMe = _rawget (_table, _member_requested) Tercio@11: if (fromMe) then Tercio@11: return fromMe Tercio@11: end Tercio@11: Tercio@11: return ImageMetaFunctions [_member_requested] Tercio@11: end Tercio@11: Tercio@11: ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Tercio@11: Tercio@11: --> show Tercio@11: local smember_show = function (_object, _value) Tercio@11: if (_value) then Tercio@11: return _object:Show() Tercio@11: else Tercio@11: return _object:Hide() Tercio@11: end Tercio@11: end Tercio@11: --> hide Tercio@11: local smember_hide = function (_object, _value) Tercio@11: if (not _value) then Tercio@11: return _object:Show() Tercio@11: else Tercio@11: return _object:Hide() Tercio@11: end Tercio@11: end Tercio@11: --> texture Tercio@11: local smember_texture = function (_object, _value) Tercio@11: if (type (_value) == "table") then Tercio@11: local r, g, b, a = DF:ParseColors (_value) Tercio@11: _object.image:SetTexture (r, g, b, a or 1) Tercio@11: else Tercio@11: if (DF:IsHtmlColor (_value)) then Tercio@11: local r, g, b, a = DF:ParseColors (_value) Tercio@11: _object.image:SetTexture (r, g, b, a or 1) Tercio@11: else Tercio@11: _object.image:SetTexture (_value) Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: --> width Tercio@11: local smember_width = function (_object, _value) Tercio@11: return _object.image:SetWidth (_value) Tercio@11: end Tercio@11: --> height Tercio@11: local smember_height = function (_object, _value) Tercio@11: return _object.image:SetHeight (_value) Tercio@11: end Tercio@11: --> alpha Tercio@11: local smember_alpha = function (_object, _value) Tercio@11: return _object.image:SetAlpha (_value) Tercio@11: end Tercio@11: --> color Tercio@11: local smember_color = function (_object, _value) Tercio@11: if (type (_value) == "table") then Tercio@11: local r, g, b, a = DF:ParseColors (_value) Tercio@11: _object.image:SetTexture (r,g,b, a or 1) Tercio@11: else Tercio@11: if (DF:IsHtmlColor (_value)) then Tercio@11: local r, g, b, a = DF:ParseColors (_value) Tercio@11: _object.image:SetTexture (r, g, b, a or 1) Tercio@11: else Tercio@11: _object.image:SetTexture (_value) Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: --> desaturated Tercio@11: local smember_desaturated = function (_object, _value) Tercio@11: if (_value) then Tercio@11: _object:SetDesaturated (true) Tercio@11: else Tercio@11: _object:SetDesaturated (false) Tercio@11: end Tercio@11: end Tercio@11: --> texcoords Tercio@11: local smember_texcoord = function (_object, _value) Tercio@11: if (_value) then Tercio@11: _object:SetTexCoord (unpack (_value)) Tercio@11: else Tercio@11: _object:SetTexCoord (0, 1, 0, 1) Tercio@11: end Tercio@11: end Tercio@11: Tercio@39: ImageMetaFunctions.SetMembers = ImageMetaFunctions.SetMembers or {} Tercio@39: ImageMetaFunctions.SetMembers ["show"] = smember_show Tercio@39: ImageMetaFunctions.SetMembers ["hide"] = smember_hide Tercio@39: ImageMetaFunctions.SetMembers ["alpha"] = smember_alpha Tercio@39: ImageMetaFunctions.SetMembers ["width"] = smember_width Tercio@39: ImageMetaFunctions.SetMembers ["height"] = smember_height Tercio@39: ImageMetaFunctions.SetMembers ["texture"] = smember_texture Tercio@39: ImageMetaFunctions.SetMembers ["texcoord"] = smember_texcoord Tercio@39: ImageMetaFunctions.SetMembers ["color"] = smember_color Tercio@39: ImageMetaFunctions.SetMembers ["blackwhite"] = smember_desaturated Tercio@39: Tercio@11: ImageMetaFunctions.__newindex = function (_table, _key, _value) Tercio@39: local func = ImageMetaFunctions.SetMembers [_key] Tercio@11: if (func) then Tercio@11: return func (_table, _value) Tercio@11: else Tercio@11: return _rawset (_table, _key, _value) Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: ------------------------------------------------------------------------------------------------------------ Tercio@11: --> methods Tercio@11: --> show & hide Tercio@11: function ImageMetaFunctions:IsShown() Tercio@11: return self.image:IsShown() Tercio@11: end Tercio@11: function ImageMetaFunctions:Show() Tercio@11: return self.image:Show() Tercio@11: end Tercio@11: function ImageMetaFunctions:Hide() Tercio@11: return self.image:Hide() Tercio@11: end Tercio@11: Tercio@11: -- setpoint Tercio@11: function ImageMetaFunctions:SetPoint (v1, v2, v3, v4, v5) Tercio@11: v1, v2, v3, v4, v5 = DF:CheckPoints (v1, v2, v3, v4, v5, self) Tercio@11: if (not v1) then Tercio@11: print ("Invalid parameter for SetPoint") Tercio@11: return Tercio@11: end Tercio@11: return self.widget:SetPoint (v1, v2, v3, v4, v5) Tercio@11: end Tercio@11: Tercio@11: -- sizes Tercio@11: function ImageMetaFunctions:SetSize (w, h) Tercio@11: if (w) then Tercio@11: self.image:SetWidth (w) Tercio@11: end Tercio@11: if (h) then Tercio@11: return self.image:SetHeight (h) Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: ------------------------------------------------------------------------------------------------------------ Tercio@11: --> scripts Tercio@11: Tercio@11: ------------------------------------------------------------------------------------------------------------ Tercio@11: --> object constructor Tercio@11: Tercio@11: function DF:CreateImage (parent, texture, w, h, layer, coords, member, name) Tercio@11: return DF:NewImage (parent, texture, w, h, layer, coords, member, name) Tercio@11: end Tercio@11: Tercio@11: function DF:NewImage (parent, texture, w, h, layer, coords, member, name) Tercio@11: Tercio@11: if (not parent) then Tercioo@29: return error ("Details! FrameWork: parent not found.", 2) Tercio@11: end Tercio@11: Tercio@11: if (not name) then Tercio@11: name = "DetailsFrameworkPictureNumber" .. DF.PictureNameCounter Tercio@11: DF.PictureNameCounter = DF.PictureNameCounter + 1 Tercio@11: end Tercio@11: Tercio@11: if (name:find ("$parent")) then Tercioo@29: local parentName = DF.GetParentName (parent) Tercioo@29: name = name:gsub ("$parent", parentName) Tercio@11: end Tercio@11: Tercio@11: local ImageObject = {type = "image", dframework = true} Tercio@11: Tercio@11: if (member) then Tercio@11: parent [member] = ImageObject Tercio@11: end Tercio@11: Tercio@11: if (parent.dframework) then Tercio@11: parent = parent.widget Tercio@11: end Tercio@11: Tercio@11: texture = texture or "" Tercio@11: Tercio@11: ImageObject.image = parent:CreateTexture (name, layer or "OVERLAY") Tercio@11: ImageObject.widget = ImageObject.image Tercio@11: Tercio@11: if (not APIImageFunctions) then Tercio@11: APIImageFunctions = true Tercio@11: local idx = getmetatable (ImageObject.image).__index Tercio@11: for funcName, funcAddress in pairs (idx) do Tercio@11: if (not ImageMetaFunctions [funcName]) then Tercio@11: ImageMetaFunctions [funcName] = function (object, ...) Tercio@20: local x = loadstring ( "return _G['"..object.image:GetName().."']:"..funcName.."(...)") Tercio@11: return x (...) Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: ImageObject.image.MyObject = ImageObject Tercio@11: Tercio@11: if (w) then Tercio@11: ImageObject.image:SetWidth (w) Tercio@11: end Tercio@11: if (h) then Tercio@11: ImageObject.image:SetHeight (h) Tercio@11: end Tercio@11: if (texture) then Tercio@11: if (type (texture) == "table") then Tercio@11: local r, g, b = DF:ParseColors (texture) Tercio@11: ImageObject.image:SetTexture (r,g,b) Tercio@11: else Tercio@11: if (DF:IsHtmlColor (texture)) then Tercio@11: local r, g, b = DF:ParseColors (texture) Tercio@11: ImageObject.image:SetTexture (r, g, b) Tercio@11: else Tercio@11: ImageObject.image:SetTexture (texture) Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: if (coords and type (coords) == "table" and coords [4]) then Tercio@11: ImageObject.image:SetTexCoord (unpack (coords)) Tercio@11: end Tercio@11: Tercio@39: ImageObject.HookList = { Tercio@39: } Tercio@39: Tercio@11: setmetatable (ImageObject, ImageMetaFunctions) Tercio@11: Tercio@11: return ImageObject Tercio@58: end