annotate Libs/DF/picture.lua @ 63:3552946c0b9a tip

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