Mercurial > wow > hansgar_and_franzok_assist
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 38:219f04e5ba55 | 39:7944c081e5b4 |
|---|---|
| 13 local _math_floor = math.floor --> lua locals | 13 local _math_floor = math.floor --> lua locals |
| 14 | 14 |
| 15 local SharedMedia = LibStub:GetLibrary ("LibSharedMedia-3.0") | 15 local SharedMedia = LibStub:GetLibrary ("LibSharedMedia-3.0") |
| 16 | 16 |
| 17 local cleanfunction = function() end | 17 local cleanfunction = function() end |
| 18 local BarMetaFunctions = {} | |
| 19 local APIBarFunctions | 18 local APIBarFunctions |
| 19 | |
| 20 do | |
| 21 local metaPrototype = { | |
| 22 WidgetType = "normal_bar", | |
| 23 SetHook = DF.SetHook, | |
| 24 RunHooksForWidget = DF.RunHooksForWidget, | |
| 25 } | |
| 26 | |
| 27 _G [DF.GlobalWidgetControlNames ["normal_bar"]] = _G [DF.GlobalWidgetControlNames ["normal_bar"]] or metaPrototype | |
| 28 end | |
| 29 | |
| 30 local BarMetaFunctions = _G [DF.GlobalWidgetControlNames ["normal_bar"]] | |
| 20 | 31 |
| 21 ------------------------------------------------------------------------------------------------------------ | 32 ------------------------------------------------------------------------------------------------------------ |
| 22 --> metatables | 33 --> metatables |
| 23 | 34 |
| 24 BarMetaFunctions.__call = function (_table, value) | 35 BarMetaFunctions.__call = function (_table, value) |
| 109 --> font color | 120 --> font color |
| 110 local gmember_textcolor = function (_object) | 121 local gmember_textcolor = function (_object) |
| 111 return _object.textleft:GetTextColor() | 122 return _object.textleft:GetTextColor() |
| 112 end | 123 end |
| 113 | 124 |
| 114 local get_members_function_index = { | 125 BarMetaFunctions.GetMembers = BarMetaFunctions.GetMembers or {} |
| 115 ["tooltip"] = gmember_tooltip, | 126 BarMetaFunctions.GetMembers ["tooltip"] = gmember_tooltip |
| 116 ["shown"] = gmember_shown, | 127 BarMetaFunctions.GetMembers ["shown"] = gmember_shown |
| 117 ["width"] = gmember_width, | 128 BarMetaFunctions.GetMembers ["width"] = gmember_width |
| 118 ["height"] = gmember_height, | 129 BarMetaFunctions.GetMembers ["height"] = gmember_height |
| 119 ["value"] = gmember_value, | 130 BarMetaFunctions.GetMembers ["value"] = gmember_value |
| 120 ["lefttext"] = gmember_ltext, | 131 BarMetaFunctions.GetMembers ["lefttext"] = gmember_ltext |
| 121 ["righttext"] = gmember_rtext, | 132 BarMetaFunctions.GetMembers ["righttext"] = gmember_rtext |
| 122 ["color"] = gmember_color, | 133 BarMetaFunctions.GetMembers ["color"] = gmember_color |
| 123 ["icon"] = gmember_icon, | 134 BarMetaFunctions.GetMembers ["icon"] = gmember_icon |
| 124 ["texture"] = gmember_texture, | 135 BarMetaFunctions.GetMembers ["texture"] = gmember_texture |
| 125 ["fontsize"] = gmember_textsize, | 136 BarMetaFunctions.GetMembers ["fontsize"] = gmember_textsize |
| 126 ["fontface"] = gmember_textfont, | 137 BarMetaFunctions.GetMembers ["fontface"] = gmember_textfont |
| 127 ["fontcolor"] = gmember_textcolor, | 138 BarMetaFunctions.GetMembers ["fontcolor"] = gmember_textcolor |
| 128 ["textsize"] = gmember_textsize, --alias | 139 BarMetaFunctions.GetMembers ["textsize"] = gmember_textsize --alias |
| 129 ["textfont"] = gmember_textfont, --alias | 140 BarMetaFunctions.GetMembers ["textfont"] = gmember_textfont --alias |
| 130 ["textcolor"] = gmember_textcolor --alias | 141 BarMetaFunctions.GetMembers ["textcolor"] = gmember_textcolor --alias |
| 131 } | |
| 132 | 142 |
| 133 BarMetaFunctions.__index = function (_table, _member_requested) | 143 BarMetaFunctions.__index = function (_table, _member_requested) |
| 134 | 144 |
| 135 local func = get_members_function_index [_member_requested] | 145 local func = BarMetaFunctions.GetMembers [_member_requested] |
| 136 if (func) then | 146 if (func) then |
| 137 return func (_table, _member_requested) | 147 return func (_table, _member_requested) |
| 138 end | 148 end |
| 139 | 149 |
| 140 local fromMe = _rawget (_table, _member_requested) | 150 local fromMe = _rawget (_table, _member_requested) |
| 265 local smember_outline = function (_object, _value) | 275 local smember_outline = function (_object, _value) |
| 266 DF:SetFontOutline (_object.textleft, _value) | 276 DF:SetFontOutline (_object.textleft, _value) |
| 267 return DF:SetFontOutline (_object.textright, _value) | 277 return DF:SetFontOutline (_object.textright, _value) |
| 268 end | 278 end |
| 269 | 279 |
| 270 local set_members_function_index = { | 280 BarMetaFunctions.SetMembers = BarMetaFunctions.SetMembers or {} |
| 271 ["tooltip"] = smember_tooltip, | 281 BarMetaFunctions.SetMembers["tooltip"] = smember_tooltip |
| 272 ["shown"] = smember_shown, | 282 BarMetaFunctions.SetMembers["shown"] = smember_shown |
| 273 ["width"] = smember_width, | 283 BarMetaFunctions.SetMembers["width"] = smember_width |
| 274 ["height"] = smember_height, | 284 BarMetaFunctions.SetMembers["height"] = smember_height |
| 275 ["value"] = smember_value, | 285 BarMetaFunctions.SetMembers["value"] = smember_value |
| 276 ["righttext"] = smember_rtext, | 286 BarMetaFunctions.SetMembers["righttext"] = smember_rtext |
| 277 ["lefttext"] = smember_ltext, | 287 BarMetaFunctions.SetMembers["lefttext"] = smember_ltext |
| 278 ["color"] = smember_color, | 288 BarMetaFunctions.SetMembers["color"] = smember_color |
| 279 ["icon"] = smember_icon, | 289 BarMetaFunctions.SetMembers["icon"] = smember_icon |
| 280 ["texture"] = smember_texture, | 290 BarMetaFunctions.SetMembers["texture"] = smember_texture |
| 281 ["fontsize"] = smember_textsize, | 291 BarMetaFunctions.SetMembers["fontsize"] = smember_textsize |
| 282 ["fontface"] = smember_textfont, | 292 BarMetaFunctions.SetMembers["fontface"] = smember_textfont |
| 283 ["fontcolor"] = smember_textcolor, | 293 BarMetaFunctions.SetMembers["fontcolor"] = smember_textcolor |
| 284 ["textsize"] = smember_textsize, --alias | 294 BarMetaFunctions.SetMembers["textsize"] = smember_textsize --alias |
| 285 ["textfont"] = smember_textfont, --alias | 295 BarMetaFunctions.SetMembers["textfont"] = smember_textfont --alias |
| 286 ["textcolor"] = smember_textcolor, --alias | 296 BarMetaFunctions.SetMembers["textcolor"] = smember_textcolor --alias |
| 287 ["shadow"] = smember_outline, | 297 BarMetaFunctions.SetMembers["shadow"] = smember_outline |
| 288 ["outline"] = smember_outline, --alias | 298 BarMetaFunctions.SetMembers["outline"] = smember_outline --alias |
| 289 } | |
| 290 | 299 |
| 291 BarMetaFunctions.__newindex = function (_table, _key, _value) | 300 BarMetaFunctions.__newindex = function (_table, _key, _value) |
| 292 | 301 |
| 293 local func = set_members_function_index [_key] | 302 local func = BarMetaFunctions.SetMembers [_key] |
| 294 if (func) then | 303 if (func) then |
| 295 return func (_table, _value) | 304 return func (_table, _value) |
| 296 else | 305 else |
| 297 return _rawset (_table, _key, _value) | 306 return _rawset (_table, _key, _value) |
| 298 end | 307 end |
| 418 --> container | 427 --> container |
| 419 function BarMetaFunctions:SetContainer (container) | 428 function BarMetaFunctions:SetContainer (container) |
| 420 self.container = container | 429 self.container = container |
| 421 end | 430 end |
| 422 | 431 |
| 423 --> hooks | |
| 424 function BarMetaFunctions:SetHook (hookType, func) | |
| 425 if (func) then | |
| 426 _rawset (self, hookType.."Hook", func) | |
| 427 else | |
| 428 _rawset (self, hookType.."Hook", nil) | |
| 429 end | |
| 430 end | |
| 431 | |
| 432 ------------------------------------------------------------------------------------------------------------ | 432 ------------------------------------------------------------------------------------------------------------ |
| 433 --> scripts | 433 --> scripts |
| 434 | 434 |
| 435 local OnEnter = function (frame) | 435 local OnEnter = function (frame) |
| 436 if (frame.MyObject.OnEnterHook) then | 436 local capsule = frame.MyObject |
| 437 local interrupt = frame.MyObject.OnEnterHook (frame, frame.MyObject) | 437 local kill = capsule:RunHooksForWidget ("OnEnter", frame, capsule) |
| 438 if (interrupt) then | 438 if (kill) then |
| 439 return | 439 return |
| 440 end | |
| 441 end | 440 end |
| 442 | 441 |
| 443 frame.MyObject.background:Show() | 442 frame.MyObject.background:Show() |
| 444 | 443 |
| 445 if (frame.MyObject.have_tooltip) then | 444 if (frame.MyObject.have_tooltip) then |
| 449 end | 448 end |
| 450 | 449 |
| 451 end | 450 end |
| 452 | 451 |
| 453 local OnLeave = function (frame) | 452 local OnLeave = function (frame) |
| 454 if (frame.MyObject.OnLeaveHook) then | 453 local capsule = frame.MyObject |
| 455 local interrupt = frame.MyObject.OnLeaveHook (frame) | 454 local kill = capsule:RunHooksForWidget ("OnLeave", frame, capsule) |
| 456 if (interrupt) then | 455 if (kill) then |
| 457 return | 456 return |
| 458 end | |
| 459 end | 457 end |
| 460 | 458 |
| 461 if (frame.MyObject.have_tooltip) then | 459 if (frame.MyObject.have_tooltip) then |
| 462 GameCooltip2:ShowMe (false) | 460 GameCooltip2:ShowMe (false) |
| 463 end | 461 end |
| 464 end | 462 end |
| 465 | 463 |
| 466 local OnHide = function (frame) | 464 local OnHide = function (frame) |
| 467 if (frame.MyObject.OnHideHook) then | 465 local capsule = frame.MyObject |
| 468 local interrupt = frame.MyObject.OnHideHook (frame) | 466 local kill = capsule:RunHooksForWidget ("OnHide", frame, capsule) |
| 469 if (interrupt) then | 467 if (kill) then |
| 470 return | 468 return |
| 471 end | |
| 472 end | 469 end |
| 473 end | 470 end |
| 474 | 471 |
| 475 local OnShow = function (frame) | 472 local OnShow = function (frame) |
| 476 if (frame.MyObject.OnShowHook) then | 473 local capsule = frame.MyObject |
| 477 local interrupt = frame.MyObject.OnShowHook (frame) | 474 local kill = capsule:RunHooksForWidget ("OnShow", frame, capsule) |
| 478 if (interrupt) then | 475 if (kill) then |
| 479 return | 476 return |
| 480 end | |
| 481 end | 477 end |
| 482 end | 478 end |
| 483 | 479 |
| 484 local OnMouseDown = function (frame, button) | 480 local OnMouseDown = function (frame, button) |
| 485 if (frame.MyObject.OnMouseDownHook) then | 481 local capsule = frame.MyObject |
| 486 local interrupt = frame.MyObject.OnMouseDownHook (frame, button) | 482 local kill = capsule:RunHooksForWidget ("OnMouseDown", frame, button, capsule) |
| 487 if (interrupt) then | 483 if (kill) then |
| 488 return | 484 return |
| 489 end | |
| 490 end | 485 end |
| 491 | 486 |
| 492 if (not frame.MyObject.container.isLocked and frame.MyObject.container:IsMovable()) then | 487 if (not frame.MyObject.container.isLocked and frame.MyObject.container:IsMovable()) then |
| 493 if (not frame.isLocked and frame:IsMovable()) then | 488 if (not frame.isLocked and frame:IsMovable()) then |
| 494 frame.MyObject.container.isMoving = true | 489 frame.MyObject.container.isMoving = true |
| 496 end | 491 end |
| 497 end | 492 end |
| 498 end | 493 end |
| 499 | 494 |
| 500 local OnMouseUp = function (frame, button) | 495 local OnMouseUp = function (frame, button) |
| 501 if (frame.MyObject.OnMouseUpHook) then | 496 local capsule = frame.MyObject |
| 502 local interrupt = frame.MyObject.OnMouseUpHook (frame, button) | 497 local kill = capsule:RunHooksForWidget ("OnMouseUp", frame, button, capsule) |
| 503 if (interrupt) then | 498 if (kill) then |
| 504 return | 499 return |
| 505 end | |
| 506 end | 500 end |
| 507 | 501 |
| 508 if (frame.MyObject.container.isMoving) then | 502 if (frame.MyObject.container.isMoving) then |
| 509 frame.MyObject.container:StopMovingOrSizing() | 503 frame.MyObject.container:StopMovingOrSizing() |
| 510 frame.MyObject.container.isMoving = false | 504 frame.MyObject.container.isMoving = false |
| 672 value = value or 0 | 666 value = value or 0 |
| 673 w = w or 150 | 667 w = w or 150 |
| 674 h = h or 14 | 668 h = h or 14 |
| 675 | 669 |
| 676 --> default members: | 670 --> default members: |
| 677 --> hooks | |
| 678 BarObject.OnEnterHook = nil | |
| 679 BarObject.OnLeaveHook = nil | |
| 680 BarObject.OnHideHook = nil | |
| 681 BarObject.OnShowHook = nil | |
| 682 BarObject.OnMouseDownHook = nil | |
| 683 BarObject.OnMouseUpHook = nil | |
| 684 BarObject.OnTimerEndHook = nil | |
| 685 --> misc | 671 --> misc |
| 686 BarObject.tooltip = nil | |
| 687 BarObject.locked = false | 672 BarObject.locked = false |
| 688 BarObject.have_tooltip = nil | |
| 689 | 673 |
| 690 BarObject.container = container | 674 BarObject.container = container |
| 691 | 675 |
| 692 --> create widgets | 676 --> create widgets |
| 693 BarObject.statusbar = CreateFrame ("statusbar", name, parent, "DetailsFrameworkNormalBarTemplate") | 677 BarObject.statusbar = CreateFrame ("statusbar", name, parent, "DetailsFrameworkNormalBarTemplate") |
| 727 BarObject.textright = _G [name .. "_TextRight"] | 711 BarObject.textright = _G [name .. "_TextRight"] |
| 728 BarObject.div = _G [name .. "_sparkMouseover"] | 712 BarObject.div = _G [name .. "_sparkMouseover"] |
| 729 BarObject.div_timer = _G [name .. "_sparkTimer"] | 713 BarObject.div_timer = _G [name .. "_sparkTimer"] |
| 730 | 714 |
| 731 --> hooks | 715 --> hooks |
| 716 BarObject.HookList = { | |
| 717 OnEnter = {}, | |
| 718 OnLeave = {}, | |
| 719 OnHide = {}, | |
| 720 OnShow = {}, | |
| 721 OnMouseDown = {}, | |
| 722 OnMouseUp = {}, | |
| 723 } | |
| 724 | |
| 732 BarObject.statusbar:SetScript ("OnEnter", OnEnter) | 725 BarObject.statusbar:SetScript ("OnEnter", OnEnter) |
| 733 BarObject.statusbar:SetScript ("OnLeave", OnLeave) | 726 BarObject.statusbar:SetScript ("OnLeave", OnLeave) |
| 734 BarObject.statusbar:SetScript ("OnHide", OnHide) | 727 BarObject.statusbar:SetScript ("OnHide", OnHide) |
| 735 BarObject.statusbar:SetScript ("OnShow", OnShow) | 728 BarObject.statusbar:SetScript ("OnShow", OnShow) |
| 736 BarObject.statusbar:SetScript ("OnMouseDown", OnMouseDown) | 729 BarObject.statusbar:SetScript ("OnMouseDown", OnMouseDown) |
