annotate Libs/DF/picture.lua @ 11:2f09fe4be15c

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