annotate Libs/DF/normal_bar.lua @ 39:7944c081e5b4

- framework update. - ToC Update.
author Tercio
date Tue, 19 Jul 2016 13:23:40 -0300
parents 5da06cb420d4
children a960d5372b0c
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 locals
Tercio@11 9 local _rawget = rawget --> lua locals
Tercio@11 10 local _setmetatable = setmetatable --> lua locals
Tercio@11 11 local _unpack = unpack --> lua locals
Tercio@11 12 local _type = type --> lua locals
Tercio@11 13 local _math_floor = math.floor --> lua locals
Tercio@11 14
Tercio@11 15 local SharedMedia = LibStub:GetLibrary ("LibSharedMedia-3.0")
Tercio@11 16
Tercio@11 17 local cleanfunction = function() end
Tercio@11 18 local APIBarFunctions
Tercio@11 19
Tercio@39 20 do
Tercio@39 21 local metaPrototype = {
Tercio@39 22 WidgetType = "normal_bar",
Tercio@39 23 SetHook = DF.SetHook,
Tercio@39 24 RunHooksForWidget = DF.RunHooksForWidget,
Tercio@39 25 }
Tercio@39 26
Tercio@39 27 _G [DF.GlobalWidgetControlNames ["normal_bar"]] = _G [DF.GlobalWidgetControlNames ["normal_bar"]] or metaPrototype
Tercio@39 28 end
Tercio@39 29
Tercio@39 30 local BarMetaFunctions = _G [DF.GlobalWidgetControlNames ["normal_bar"]]
Tercio@39 31
Tercio@11 32 ------------------------------------------------------------------------------------------------------------
Tercio@11 33 --> metatables
Tercio@11 34
Tercio@11 35 BarMetaFunctions.__call = function (_table, value)
Tercio@11 36 if (not value) then
Tercio@11 37 return _table.statusbar:GetValue()
Tercio@11 38 else
Tercio@11 39 return _table.statusbar:SetValue (value)
Tercio@11 40 end
Tercio@11 41 end
Tercio@11 42
Tercio@11 43 BarMetaFunctions.__add = function (v1, v2)
Tercio@11 44 if (_type (v1) == "table") then
Tercio@11 45 local v = v1.statusbar:GetValue()
Tercio@11 46 v = v + v2
Tercio@11 47 v1.statusbar:SetValue (v)
Tercio@11 48 else
Tercio@11 49 local v = v2.statusbar:GetValue()
Tercio@11 50 v = v + v1
Tercio@11 51 v2.statusbar:SetValue (v)
Tercio@11 52 end
Tercio@11 53 end
Tercio@11 54
Tercio@11 55 BarMetaFunctions.__sub = function (v1, v2)
Tercio@11 56 if (_type (v1) == "table") then
Tercio@11 57 local v = v1.statusbar:GetValue()
Tercio@11 58 v = v - v2
Tercio@11 59 v1.statusbar:SetValue (v)
Tercio@11 60 else
Tercio@11 61 local v = v2.statusbar:GetValue()
Tercio@11 62 v = v - v1
Tercio@11 63 v2.statusbar:SetValue (v)
Tercio@11 64 end
Tercio@11 65 end
Tercio@11 66
Tercio@11 67 ------------------------------------------------------------------------------------------------------------
Tercio@11 68 --> members
Tercio@11 69
Tercio@11 70 --> tooltip
Tercio@11 71 local function gmember_tooltip (_object)
Tercio@11 72 return _object:GetTooltip()
Tercio@11 73 end
Tercio@11 74 --> shown
Tercio@11 75 local gmember_shown = function (_object)
Tercio@11 76 return _object.statusbar:IsShown()
Tercio@11 77 end
Tercio@11 78 --> frame width
Tercio@11 79 local gmember_width = function (_object)
Tercio@11 80 return _object.statusbar:GetWidth()
Tercio@11 81 end
Tercio@11 82 --> frame height
Tercio@11 83 local gmember_height = function (_object)
Tercio@11 84 return _object.statusbar:GetHeight()
Tercio@11 85 end
Tercio@11 86 --> value
Tercio@11 87 local gmember_value = function (_object)
Tercio@11 88 return _object.statusbar:GetValue()
Tercio@11 89 end
Tercio@11 90 --> right text
Tercio@11 91 local gmember_rtext = function (_object)
Tercio@11 92 return _object.textright:GetText()
Tercio@11 93 end
Tercio@11 94 --> left text
Tercio@11 95 local gmember_ltext = function (_object)
Tercio@11 96 return _object.textleft:GetText()
Tercio@11 97 end
Tercio@11 98 --> left color
Tercio@11 99 local gmember_color = function (_object)
Tercio@11 100 return _object._texture.original_colors
Tercio@11 101 end
Tercio@11 102 --> icon
Tercio@11 103 local gmember_icon = function (_object)
Tercio@11 104 return _object._icon:GetTexture()
Tercio@11 105 end
Tercio@11 106 --> texture
Tercio@11 107 local gmember_texture = function (_object)
Tercio@11 108 return _object._texture:GetTexture()
Tercio@11 109 end
Tercio@11 110 --> font size
Tercio@11 111 local gmember_textsize = function (_object)
Tercio@11 112 local _, fontsize = _object.textleft:GetFont()
Tercio@11 113 return fontsize
Tercio@11 114 end
Tercio@11 115 --> font face
Tercio@11 116 local gmember_textfont = function (_object)
Tercio@11 117 local fontface = _object.textleft:GetFont()
Tercio@11 118 return fontface
Tercio@11 119 end
Tercio@11 120 --> font color
Tercio@11 121 local gmember_textcolor = function (_object)
Tercio@11 122 return _object.textleft:GetTextColor()
Tercio@11 123 end
Tercio@11 124
Tercio@39 125 BarMetaFunctions.GetMembers = BarMetaFunctions.GetMembers or {}
Tercio@39 126 BarMetaFunctions.GetMembers ["tooltip"] = gmember_tooltip
Tercio@39 127 BarMetaFunctions.GetMembers ["shown"] = gmember_shown
Tercio@39 128 BarMetaFunctions.GetMembers ["width"] = gmember_width
Tercio@39 129 BarMetaFunctions.GetMembers ["height"] = gmember_height
Tercio@39 130 BarMetaFunctions.GetMembers ["value"] = gmember_value
Tercio@39 131 BarMetaFunctions.GetMembers ["lefttext"] = gmember_ltext
Tercio@39 132 BarMetaFunctions.GetMembers ["righttext"] = gmember_rtext
Tercio@39 133 BarMetaFunctions.GetMembers ["color"] = gmember_color
Tercio@39 134 BarMetaFunctions.GetMembers ["icon"] = gmember_icon
Tercio@39 135 BarMetaFunctions.GetMembers ["texture"] = gmember_texture
Tercio@39 136 BarMetaFunctions.GetMembers ["fontsize"] = gmember_textsize
Tercio@39 137 BarMetaFunctions.GetMembers ["fontface"] = gmember_textfont
Tercio@39 138 BarMetaFunctions.GetMembers ["fontcolor"] = gmember_textcolor
Tercio@39 139 BarMetaFunctions.GetMembers ["textsize"] = gmember_textsize --alias
Tercio@39 140 BarMetaFunctions.GetMembers ["textfont"] = gmember_textfont --alias
Tercio@39 141 BarMetaFunctions.GetMembers ["textcolor"] = gmember_textcolor --alias
Tercio@11 142
Tercio@11 143 BarMetaFunctions.__index = function (_table, _member_requested)
Tercio@11 144
Tercio@39 145 local func = BarMetaFunctions.GetMembers [_member_requested]
Tercio@11 146 if (func) then
Tercio@11 147 return func (_table, _member_requested)
Tercio@11 148 end
Tercio@11 149
Tercio@11 150 local fromMe = _rawget (_table, _member_requested)
Tercio@11 151 if (fromMe) then
Tercio@11 152 return fromMe
Tercio@11 153 end
Tercio@11 154
Tercio@11 155 return BarMetaFunctions [_member_requested]
Tercio@11 156 end
Tercio@11 157
Tercio@11 158
Tercio@11 159 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Tercio@11 160
Tercio@11 161
Tercio@11 162 --> tooltip
Tercio@11 163 local smember_tooltip = function (_object, _value)
Tercio@11 164 return _object:SetTooltip (_value)
Tercio@11 165 end
Tercio@11 166 --> show
Tercio@11 167 local smember_shown = function (_object, _value)
Tercio@11 168 if (_value) then
Tercio@11 169 return _object:Show()
Tercio@11 170 else
Tercio@11 171 return _object:Hide()
Tercio@11 172 end
Tercio@11 173 end
Tercio@11 174 --> hide
Tercio@11 175 local smember_hide = function (_object, _value)
Tercio@11 176 if (_value) then
Tercio@11 177 return _object:Hide()
Tercio@11 178 else
Tercio@11 179 return _object:Show()
Tercio@11 180 end
Tercio@11 181 end
Tercio@11 182 --> width
Tercio@11 183 local smember_width = function (_object, _value)
Tercio@11 184 return _object.statusbar:SetWidth (_value)
Tercio@11 185 end
Tercio@11 186 --> height
Tercio@11 187 local smember_height = function (_object, _value)
Tercio@11 188 return _object.statusbar:SetHeight (_value)
Tercio@11 189 end
Tercio@11 190 --> statusbar value
Tercio@11 191 local smember_value = function (_object, _value)
Tercio@11 192 _object.statusbar:SetValue (_value)
Tercio@11 193 return _object.div:SetPoint ("left", _object.statusbar, "left", _value * (_object.statusbar:GetWidth()/100) - 16, 0)
Tercio@11 194 end
Tercio@11 195 --> right text
Tercio@11 196 local smember_rtext = function (_object, _value)
Tercio@11 197 return _object.textright:SetText (_value)
Tercio@11 198 end
Tercio@11 199 --> left text
Tercio@11 200 local smember_ltext = function (_object, _value)
Tercio@11 201 return _object.textleft:SetText (_value)
Tercio@11 202 end
Tercio@11 203 --> color
Tercio@11 204 local smember_color = function (_object, _value)
Tercio@11 205 local _value1, _value2, _value3, _value4 = DF:ParseColors (_value)
Tercio@11 206
Tercio@11 207 _object.statusbar:SetStatusBarColor (_value1, _value2, _value3, _value4)
Tercio@11 208 _object._texture.original_colors = {_value1, _value2, _value3, _value4}
Tercio@22 209 _object.timer_texture:SetVertexColor (_value1, _value2, _value3, _value4)
Tercio@25 210
Tercio@25 211 _object.timer_textureR:SetVertexColor (_value1, _value2, _value3, _value4)
Tercio@25 212
Tercio@11 213 return _object._texture:SetVertexColor (_value1, _value2, _value3, _value4)
Tercio@11 214 end
Tercio@11 215 --> icon
Tercio@11 216 local smember_icon = function (_object, _value)
Tercio@11 217 if (type (_value) == "table") then
Tercio@11 218 local _value1, _value2 = _unpack (_value)
Tercio@11 219 _object._icon:SetTexture (_value1)
Tercio@11 220 if (_value2) then
Tercio@11 221 _object._icon:SetTexCoord (_unpack (_value2))
Tercio@11 222 end
Tercio@11 223 else
Tercio@11 224 _object._icon:SetTexture (_value)
Tercio@11 225 end
Tercio@11 226 return
Tercio@11 227 end
Tercio@11 228 --> texture
Tercio@11 229 local smember_texture = function (_object, _value)
Tercio@11 230 if (type (_value) == "table") then
Tercio@11 231 local _value1, _value2 = _unpack (_value)
Tercio@11 232 _object._texture:SetTexture (_value1)
Tercio@22 233 _object.timer_texture:SetTexture (_value1)
Tercio@25 234 _object.timer_textureR:SetTexture (_value1)
Tercio@11 235 if (_value2) then
Tercio@11 236 _object._texture:SetTexCoord (_unpack (_value2))
Tercio@22 237 _object.timer_texture:SetTexCoord (_unpack (_value2))
Tercio@25 238 _object.timer_textureR:SetTexCoord (_unpack (_value2))
Tercio@11 239 end
Tercio@11 240 else
Tercio@11 241 if (_value:find ("\\")) then
Tercio@11 242 _object._texture:SetTexture (_value)
Tercio@11 243 else
Tercio@11 244 local file = SharedMedia:Fetch ("statusbar", _value)
Tercio@11 245 if (file) then
Tercio@11 246 _object._texture:SetTexture (file)
Tercio@22 247 _object.timer_texture:SetTexture (file)
Tercio@25 248 _object.timer_textureR:SetTexture (file)
Tercio@11 249 else
Tercio@11 250 _object._texture:SetTexture (_value)
Tercio@22 251 _object.timer_texture:SetTexture (_value)
Tercio@25 252 _object.timer_textureR:SetTexture (_value)
Tercio@11 253 end
Tercio@11 254 end
Tercio@11 255 end
Tercio@11 256 return
Tercio@11 257 end
Tercio@11 258 --> font face
Tercio@11 259 local smember_textfont = function (_object, _value)
Tercio@11 260 DF:SetFontFace (_object.textleft, _value)
Tercio@11 261 return DF:SetFontFace (_object.textright, _value)
Tercio@11 262 end
Tercio@11 263 --> font size
Tercio@11 264 local smember_textsize = function (_object, _value)
Tercio@11 265 DF:SetFontSize (_object.textleft, _value)
Tercio@11 266 return DF:SetFontSize (_object.textright, _value)
Tercio@11 267 end
Tercio@11 268 --> font color
Tercio@11 269 local smember_textcolor = function (_object, _value)
Tercio@11 270 local _value1, _value2, _value3, _value4 = DF:ParseColors (_value)
Tercio@11 271 _object.textleft:SetTextColor (_value1, _value2, _value3, _value4)
Tercio@11 272 return _object.textright:SetTextColor (_value1, _value2, _value3, _value4)
Tercio@11 273 end
Tercio@11 274 --> outline (shadow)
Tercio@11 275 local smember_outline = function (_object, _value)
Tercio@11 276 DF:SetFontOutline (_object.textleft, _value)
Tercio@11 277 return DF:SetFontOutline (_object.textright, _value)
Tercio@11 278 end
Tercio@11 279
Tercio@39 280 BarMetaFunctions.SetMembers = BarMetaFunctions.SetMembers or {}
Tercio@39 281 BarMetaFunctions.SetMembers["tooltip"] = smember_tooltip
Tercio@39 282 BarMetaFunctions.SetMembers["shown"] = smember_shown
Tercio@39 283 BarMetaFunctions.SetMembers["width"] = smember_width
Tercio@39 284 BarMetaFunctions.SetMembers["height"] = smember_height
Tercio@39 285 BarMetaFunctions.SetMembers["value"] = smember_value
Tercio@39 286 BarMetaFunctions.SetMembers["righttext"] = smember_rtext
Tercio@39 287 BarMetaFunctions.SetMembers["lefttext"] = smember_ltext
Tercio@39 288 BarMetaFunctions.SetMembers["color"] = smember_color
Tercio@39 289 BarMetaFunctions.SetMembers["icon"] = smember_icon
Tercio@39 290 BarMetaFunctions.SetMembers["texture"] = smember_texture
Tercio@39 291 BarMetaFunctions.SetMembers["fontsize"] = smember_textsize
Tercio@39 292 BarMetaFunctions.SetMembers["fontface"] = smember_textfont
Tercio@39 293 BarMetaFunctions.SetMembers["fontcolor"] = smember_textcolor
Tercio@39 294 BarMetaFunctions.SetMembers["textsize"] = smember_textsize --alias
Tercio@39 295 BarMetaFunctions.SetMembers["textfont"] = smember_textfont --alias
Tercio@39 296 BarMetaFunctions.SetMembers["textcolor"] = smember_textcolor --alias
Tercio@39 297 BarMetaFunctions.SetMembers["shadow"] = smember_outline
Tercio@39 298 BarMetaFunctions.SetMembers["outline"] = smember_outline --alias
Tercio@11 299
Tercio@11 300 BarMetaFunctions.__newindex = function (_table, _key, _value)
Tercio@11 301
Tercio@39 302 local func = BarMetaFunctions.SetMembers [_key]
Tercio@11 303 if (func) then
Tercio@11 304 return func (_table, _value)
Tercio@11 305 else
Tercio@11 306 return _rawset (_table, _key, _value)
Tercio@11 307 end
Tercio@11 308 end
Tercio@11 309
Tercio@11 310 ------------------------------------------------------------------------------------------------------------
Tercio@11 311 --> methods
Tercio@11 312
Tercio@11 313 --> show & hide
Tercio@11 314 function BarMetaFunctions:Show()
Tercio@11 315 self.statusbar:Show()
Tercio@11 316 end
Tercio@11 317 function BarMetaFunctions:Hide()
Tercio@11 318 self.statusbar:Hide()
Tercio@11 319 end
Tercio@11 320
Tercio@11 321 --> set value (status bar)
Tercio@11 322 function BarMetaFunctions:SetValue (value)
Tercio@11 323 if (not value) then
Tercio@11 324 value = 0
Tercio@11 325 end
Tercio@11 326 self.statusbar:SetValue (value)
Tercio@11 327 self.div:SetPoint ("left", self.statusbar, "left", value * (self.statusbar:GetWidth()/100) - 16, 0)
Tercio@11 328 end
Tercio@11 329
Tercio@11 330 --> set point
Tercio@11 331 function BarMetaFunctions:SetPoint (v1, v2, v3, v4, v5)
Tercio@11 332 v1, v2, v3, v4, v5 = DF:CheckPoints (v1, v2, v3, v4, v5, self)
Tercio@11 333 if (not v1) then
Tercio@11 334 print ("Invalid parameter for SetPoint")
Tercio@11 335 return
Tercio@11 336 end
Tercio@11 337 return self.widget:SetPoint (v1, v2, v3, v4, v5)
Tercio@11 338 end
Tercio@11 339
Tercio@11 340 --> set sizes
Tercio@11 341 function BarMetaFunctions:SetSize (w, h)
Tercio@11 342 if (w) then
Tercio@11 343 self.statusbar:SetWidth (w)
Tercio@11 344 end
Tercio@11 345 if (h) then
Tercio@11 346 self.statusbar:SetHeight (h)
Tercio@11 347 end
Tercio@11 348 end
Tercio@11 349
Tercio@11 350 --> set texture
Tercio@11 351 function BarMetaFunctions:SetTexture (texture)
Tercio@11 352 self._texture:SetTexture (texture)
Tercio@11 353 end
Tercio@11 354
Tercio@11 355 --> set texts
Tercio@11 356 function BarMetaFunctions:SetLeftText (text)
Tercio@11 357 self.textleft:SetText (text)
Tercio@11 358 end
Tercio@11 359 function BarMetaFunctions:SetRightText (text)
Tercio@11 360 self.textright:SetText (text)
Tercio@11 361 end
Tercio@11 362
Tercio@11 363 --> set color
Tercio@11 364 function BarMetaFunctions:SetColor (r, g, b, a)
Tercio@11 365 r, g, b, a = DF:ParseColors (r, g, b, a)
Tercio@11 366
Tercio@11 367 self._texture:SetVertexColor (r, g, b, a)
Tercio@11 368 self.statusbar:SetStatusBarColor (r, g, b, a)
Tercio@11 369 self._texture.original_colors = {r, g, b, a}
Tercio@11 370 end
Tercio@11 371
Tercio@11 372 --> set icons
Tercio@11 373 function BarMetaFunctions:SetIcon (texture, ...)
Tercio@11 374 self._icon:SetTexture (texture)
Tercio@11 375 if (...) then
Tercio@11 376 local L, R, U, D = _unpack (...)
Tercio@11 377 self._icon:SetTexCoord (L, R, U, D)
Tercio@11 378 end
Tercio@11 379 end
Tercio@11 380
Tercio@11 381 --> show div
Tercio@11 382 function BarMetaFunctions:ShowDiv (bool)
Tercio@11 383 if (bool) then
Tercio@11 384 self.div:Show()
Tercio@11 385 else
Tercio@11 386 self.div:Hide()
Tercio@11 387 end
Tercio@11 388 end
Tercio@11 389
Tercio@11 390 -- tooltip
Tercio@11 391 function BarMetaFunctions:SetTooltip (tooltip)
Tercio@11 392 if (tooltip) then
Tercio@11 393 return _rawset (self, "have_tooltip", tooltip)
Tercio@11 394 else
Tercio@11 395 return _rawset (self, "have_tooltip", nil)
Tercio@11 396 end
Tercio@11 397 end
Tercio@11 398 function BarMetaFunctions:GetTooltip()
Tercio@11 399 return _rawget (self, "have_tooltip")
Tercio@11 400 end
Tercio@11 401
Tercio@11 402 -- frame levels
Tercio@11 403 function BarMetaFunctions:GetFrameLevel()
Tercio@11 404 return self.statusbar:GetFrameLevel()
Tercio@11 405 end
Tercio@11 406 function BarMetaFunctions:SetFrameLevel (level, frame)
Tercio@11 407 if (not frame) then
Tercio@11 408 return self.statusbar:SetFrameLevel (level)
Tercio@11 409 else
Tercio@11 410 local framelevel = frame:GetFrameLevel (frame) + level
Tercio@11 411 return self.statusbar:SetFrameLevel (framelevel)
Tercio@11 412 end
Tercio@11 413 end
Tercio@11 414
Tercio@11 415 -- frame stratas
Tercio@11 416 function BarMetaFunctions:SetFrameStrata()
Tercio@11 417 return self.statusbar:GetFrameStrata()
Tercio@11 418 end
Tercio@11 419 function BarMetaFunctions:SetFrameStrata (strata)
Tercio@11 420 if (_type (strata) == "table") then
Tercio@11 421 self.statusbar:SetFrameStrata (strata:GetFrameStrata())
Tercio@11 422 else
Tercio@11 423 self.statusbar:SetFrameStrata (strata)
Tercio@11 424 end
Tercio@11 425 end
Tercio@11 426
Tercio@11 427 --> container
Tercio@11 428 function BarMetaFunctions:SetContainer (container)
Tercio@11 429 self.container = container
Tercio@11 430 end
Tercio@11 431
Tercio@11 432 ------------------------------------------------------------------------------------------------------------
Tercio@11 433 --> scripts
Tercio@11 434
Tercio@11 435 local OnEnter = function (frame)
Tercio@39 436 local capsule = frame.MyObject
Tercio@39 437 local kill = capsule:RunHooksForWidget ("OnEnter", frame, capsule)
Tercio@39 438 if (kill) then
Tercio@39 439 return
Tercio@11 440 end
Tercio@11 441
Tercio@11 442 frame.MyObject.background:Show()
Tercio@11 443
Tercio@11 444 if (frame.MyObject.have_tooltip) then
Tercio@11 445 GameCooltip2:Reset()
Tercio@11 446 GameCooltip2:AddLine (frame.MyObject.have_tooltip)
Tercio@11 447 GameCooltip2:ShowCooltip (frame, "tooltip")
Tercio@11 448 end
Tercio@11 449
Tercio@11 450 end
Tercio@11 451
Tercio@11 452 local OnLeave = function (frame)
Tercio@39 453 local capsule = frame.MyObject
Tercio@39 454 local kill = capsule:RunHooksForWidget ("OnLeave", frame, capsule)
Tercio@39 455 if (kill) then
Tercio@39 456 return
Tercio@11 457 end
Tercio@11 458
Tercio@11 459 if (frame.MyObject.have_tooltip) then
Tercio@11 460 GameCooltip2:ShowMe (false)
Tercio@11 461 end
Tercio@11 462 end
Tercio@11 463
Tercio@11 464 local OnHide = function (frame)
Tercio@39 465 local capsule = frame.MyObject
Tercio@39 466 local kill = capsule:RunHooksForWidget ("OnHide", frame, capsule)
Tercio@39 467 if (kill) then
Tercio@39 468 return
Tercio@11 469 end
Tercio@11 470 end
Tercio@11 471
Tercio@11 472 local OnShow = function (frame)
Tercio@39 473 local capsule = frame.MyObject
Tercio@39 474 local kill = capsule:RunHooksForWidget ("OnShow", frame, capsule)
Tercio@39 475 if (kill) then
Tercio@39 476 return
Tercio@11 477 end
Tercio@11 478 end
Tercio@11 479
Tercio@11 480 local OnMouseDown = function (frame, button)
Tercio@39 481 local capsule = frame.MyObject
Tercio@39 482 local kill = capsule:RunHooksForWidget ("OnMouseDown", frame, button, capsule)
Tercio@39 483 if (kill) then
Tercio@39 484 return
Tercio@11 485 end
Tercio@11 486
Tercio@11 487 if (not frame.MyObject.container.isLocked and frame.MyObject.container:IsMovable()) then
Tercio@11 488 if (not frame.isLocked and frame:IsMovable()) then
Tercio@11 489 frame.MyObject.container.isMoving = true
Tercio@11 490 frame.MyObject.container:StartMoving()
Tercio@11 491 end
Tercio@11 492 end
Tercio@11 493 end
Tercio@11 494
Tercio@11 495 local OnMouseUp = function (frame, button)
Tercio@39 496 local capsule = frame.MyObject
Tercio@39 497 local kill = capsule:RunHooksForWidget ("OnMouseUp", frame, button, capsule)
Tercio@39 498 if (kill) then
Tercio@39 499 return
Tercio@11 500 end
Tercio@11 501
Tercio@11 502 if (frame.MyObject.container.isMoving) then
Tercio@11 503 frame.MyObject.container:StopMovingOrSizing()
Tercio@11 504 frame.MyObject.container.isMoving = false
Tercio@11 505 end
Tercio@11 506 end
Tercio@11 507
Tercio@11 508 ------------------------------------------------------------------------------------------------------------
Tercio@11 509 --> timer
Tercio@11 510
Tercio@11 511 function BarMetaFunctions:OnTimerEnd()
Tercio@11 512 if (self.OnTimerEndHook) then
Tercio@24 513 local interrupt = self.OnTimerEndHook (self)
Tercio@11 514 if (interrupt) then
Tercio@11 515 return
Tercio@11 516 end
Tercio@11 517 end
Tercio@11 518 self.timer_texture:Hide()
Tercio@24 519 self.timer_textureR:Hide()
Tercio@11 520 self.div_timer:Hide()
Tercio@11 521 self:Hide()
Tercio@11 522 self.timer = false
Tercio@11 523 end
Tercio@11 524
Tercio@25 525 function BarMetaFunctions:CancelTimerBar (no_timer_end)
Tercio@25 526 if (not self.HasTimer) then
Tercio@25 527 return
Tercio@25 528 end
Tercio@25 529 if (self.TimerScheduled) then
Tercio@25 530 DF:CancelTimer (self.TimerScheduled)
Tercio@25 531 self.TimerScheduled = nil
Tercio@25 532 else
Tercio@25 533 if (self.statusbar:GetScript ("OnUpdate")) then
Tercio@25 534 self.statusbar:SetScript ("OnUpdate", nil)
Tercio@25 535 end
Tercio@25 536 end
Tercio@25 537 self.righttext = ""
Tercio@25 538 if (not no_timer_end) then
Tercio@25 539 self:OnTimerEnd()
Tercio@25 540 end
Tercio@25 541 end
Tercio@25 542
Tercio@11 543 local OnUpdate = function (self, elapsed)
Tercio@24 544 --> percent of elapsed
Tercio@24 545 local pct = abs (self.end_timer - GetTime() - self.tempo) / self.tempo
Tercio@24 546 if (self.inverse) then
Tercio@24 547 self.t:SetWidth (self.total_size * pct)
Tercio@24 548 else
Tercio@24 549 self.t:SetWidth (self.total_size * abs (pct-1))
Tercio@24 550 end
Tercio@24 551
Tercio@24 552 --> right text
Tercio@11 553 self.remaining = self.remaining - elapsed
Tercio@24 554 if (self.MyObject.RightTextIsTimer) then
Tercio@24 555 self.righttext:SetText (DF:IntegerToTimer (self.remaining))
Tercio@24 556 else
Tercio@24 557 self.righttext:SetText (_math_floor (self.remaining))
Tercio@24 558 end
Tercio@24 559
Tercio@24 560 if (pct >= 1) then
Tercio@24 561 self.righttext:SetText ("")
Tercio@11 562 self:SetScript ("OnUpdate", nil)
Tercio@25 563 self.MyObject.HasTimer = nil
Tercio@11 564 self.MyObject:OnTimerEnd()
Tercio@11 565 end
Tercio@11 566 end
Tercio@11 567
Tercio@25 568 function BarMetaFunctions:SetTimer (tempo, end_at)
Tercio@25 569
Tercio@25 570 if (end_at) then
Tercio@25 571 self.statusbar.tempo = end_at - tempo
Tercio@25 572 self.statusbar.remaining = end_at - GetTime()
Tercio@25 573 self.statusbar.end_timer = end_at
Tercio@25 574 else
Tercio@25 575 self.statusbar.tempo = tempo
Tercio@25 576 self.statusbar.remaining = tempo
Tercio@25 577 self.statusbar.end_timer = GetTime() + tempo
Tercio@25 578 end
Tercio@25 579
Tercio@24 580 self.statusbar.total_size = self.statusbar:GetWidth()
Tercio@24 581 self.statusbar.inverse = self.BarIsInverse
Tercio@11 582
Tercio@24 583 self (0)
Tercio@11 584
Tercio@11 585 self.div_timer:Show()
Tercio@11 586 self.background:Show()
Tercio@22 587 self:Show()
Tercio@11 588
Tercio@24 589 if (self.LeftToRight) then
Tercio@24 590 self.timer_texture:Hide()
Tercio@24 591 self.timer_textureR:Show()
Tercio@24 592 self.statusbar.t = self.timer_textureR
Tercio@24 593 self.timer_textureR:ClearAllPoints()
Tercio@24 594 self.timer_textureR:SetPoint ("right", self.statusbar, "right")
Tercio@24 595 self.div_timer:SetPoint ("left", self.timer_textureR, "left", -14, -1)
Tercio@24 596 else
Tercio@24 597 self.timer_texture:Show()
Tercio@24 598 self.timer_textureR:Hide()
Tercio@24 599 self.statusbar.t = self.timer_texture
Tercio@24 600 self.timer_texture:ClearAllPoints()
Tercio@24 601 self.timer_texture:SetPoint ("left", self.statusbar, "left")
Tercio@24 602 self.div_timer:SetPoint ("left", self.timer_texture, "right", -16, -1)
Tercio@24 603 end
Tercio@24 604
Tercio@24 605 if (self.BarIsInverse) then
Tercio@24 606 self.statusbar.t:SetWidth (1)
Tercio@24 607 else
Tercio@24 608 self.statusbar.t:SetWidth (self.statusbar.total_size)
Tercio@24 609 end
Tercio@24 610
Tercio@11 611 self.timer = true
Tercio@11 612
Tercio@25 613 self.HasTimer = true
Tercio@25 614 self.TimerScheduled = DF:ScheduleTimer ("StartTimeBarAnimation", 0.1, self)
Tercio@24 615 end
Tercio@24 616
Tercio@24 617 function DF:StartTimeBarAnimation (timebar)
Tercio@25 618 timebar.TimerScheduled = nil
Tercio@24 619 timebar.statusbar:SetScript ("OnUpdate", OnUpdate)
Tercio@11 620 end
Tercio@11 621
Tercio@11 622 ------------------------------------------------------------------------------------------------------------
Tercio@11 623 --> object constructor
Tercio@11 624
Tercio@11 625 function DetailsFrameworkNormalBar_OnCreate (self)
Tercio@11 626 self.texture.original_colors = {1, 1, 1, 1}
Tercio@11 627 self.background.original_colors = {.3, .3, .3, .3}
Tercio@11 628 self.timertexture.original_colors = {.3, .3, .3, .3}
Tercio@11 629 return true
Tercio@11 630 end
Tercio@11 631
Tercio@11 632 function DF:CreateBar (parent, texture, w, h, value, member, name)
Tercio@11 633 return DF:NewBar (parent, parent, name, member, w, h, value, texture)
Tercio@11 634 end
Tercio@11 635
Tercio@11 636 function DF:NewBar (parent, container, name, member, w, h, value, texture_name)
Tercio@11 637
Tercio@11 638 if (not name) then
Tercio@11 639 name = "DetailsFrameworkBarNumber" .. DF.BarNameCounter
Tercio@11 640 DF.BarNameCounter = DF.BarNameCounter + 1
Tercio@11 641
Tercio@11 642 elseif (not parent) then
Tercioo@29 643 return error ("Details! FrameWork: parent not found.", 2)
Tercio@11 644 elseif (not container) then
Tercio@11 645 container = parent
Tercio@11 646 end
Tercio@11 647
Tercio@11 648 if (name:find ("$parent")) then
Tercioo@29 649 local parentName = DF.GetParentName (parent)
Tercioo@29 650 name = name:gsub ("$parent", parentName)
Tercio@11 651 end
Tercio@11 652
Tercio@11 653 local BarObject = {type = "bar", dframework = true}
Tercio@11 654
Tercio@11 655 if (member) then
Tercio@11 656 parent [member] = BarObject
Tercio@11 657 end
Tercio@11 658
Tercio@11 659 if (parent.dframework) then
Tercio@11 660 parent = parent.widget
Tercio@11 661 end
Tercio@11 662 if (container.dframework) then
Tercio@11 663 container = container.widget
Tercio@11 664 end
Tercio@11 665
Tercio@11 666 value = value or 0
Tercio@11 667 w = w or 150
Tercio@11 668 h = h or 14
Tercio@11 669
Tercio@11 670 --> default members:
Tercio@11 671 --> misc
Tercio@11 672 BarObject.locked = false
Tercio@11 673
Tercio@11 674 BarObject.container = container
Tercio@11 675
Tercio@11 676 --> create widgets
Tercio@11 677 BarObject.statusbar = CreateFrame ("statusbar", name, parent, "DetailsFrameworkNormalBarTemplate")
Tercio@11 678 BarObject.widget = BarObject.statusbar
Tercio@11 679
Tercio@11 680 if (not APIBarFunctions) then
Tercio@11 681 APIBarFunctions = true
Tercio@11 682 local idx = getmetatable (BarObject.statusbar).__index
Tercio@11 683 for funcName, funcAddress in pairs (idx) do
Tercio@11 684 if (not BarMetaFunctions [funcName]) then
Tercio@11 685 BarMetaFunctions [funcName] = function (object, ...)
Tercio@20 686 local x = loadstring ( "return _G['"..object.statusbar:GetName().."']:"..funcName.."(...)")
Tercio@11 687 return x (...)
Tercio@11 688 end
Tercio@11 689 end
Tercio@11 690 end
Tercio@11 691 end
Tercio@11 692
Tercio@11 693 BarObject.statusbar:SetHeight (h)
Tercio@11 694 BarObject.statusbar:SetWidth (w)
Tercio@11 695 BarObject.statusbar:SetFrameLevel (parent:GetFrameLevel()+1)
Tercio@11 696 BarObject.statusbar:SetMinMaxValues (0, 100)
Tercio@11 697 BarObject.statusbar:SetValue (value or 50)
Tercio@11 698 BarObject.statusbar.MyObject = BarObject
Tercio@11 699
Tercio@11 700 BarObject.timer_texture = _G [name .. "_timerTexture"]
Tercio@11 701 BarObject.timer_texture:SetWidth (w)
Tercio@11 702 BarObject.timer_texture:SetHeight (h)
Tercio@11 703
Tercio@24 704 BarObject.timer_textureR = _G [name .. "_timerTextureR"]
Tercio@24 705 BarObject.timer_textureR:Hide()
Tercio@24 706
Tercio@11 707 BarObject._texture = _G [name .. "_statusbarTexture"]
Tercio@11 708 BarObject.background = _G [name .. "_background"]
Tercio@11 709 BarObject._icon = _G [name .. "_icon"]
Tercio@11 710 BarObject.textleft = _G [name .. "_TextLeft"]
Tercio@11 711 BarObject.textright = _G [name .. "_TextRight"]
Tercio@11 712 BarObject.div = _G [name .. "_sparkMouseover"]
Tercio@11 713 BarObject.div_timer = _G [name .. "_sparkTimer"]
Tercio@11 714
Tercio@11 715 --> hooks
Tercio@39 716 BarObject.HookList = {
Tercio@39 717 OnEnter = {},
Tercio@39 718 OnLeave = {},
Tercio@39 719 OnHide = {},
Tercio@39 720 OnShow = {},
Tercio@39 721 OnMouseDown = {},
Tercio@39 722 OnMouseUp = {},
Tercio@39 723 }
Tercio@39 724
Tercio@11 725 BarObject.statusbar:SetScript ("OnEnter", OnEnter)
Tercio@11 726 BarObject.statusbar:SetScript ("OnLeave", OnLeave)
Tercio@11 727 BarObject.statusbar:SetScript ("OnHide", OnHide)
Tercio@11 728 BarObject.statusbar:SetScript ("OnShow", OnShow)
Tercio@11 729 BarObject.statusbar:SetScript ("OnMouseDown", OnMouseDown)
Tercio@11 730 BarObject.statusbar:SetScript ("OnMouseUp", OnMouseUp)
Tercio@11 731
Tercio@11 732 --> set class
Tercio@11 733 _setmetatable (BarObject, BarMetaFunctions)
Tercio@11 734
Tercio@11 735 --> set texture
Tercio@11 736 if (texture_name) then
Tercio@11 737 smember_texture (BarObject, texture_name)
Tercio@11 738 end
Tercio@11 739
Tercio@11 740 return BarObject
Tercio@25 741 end --endd