Mercurial > wow > hansgar_and_franzok_assist
comparison Libs/DF/split_bar.lua @ 39:7944c081e5b4
- framework update.
- ToC Update.
| author | Tercio |
|---|---|
| date | Tue, 19 Jul 2016 13:23:40 -0300 |
| parents | 5da06cb420d4 |
| children | 0682d738499b |
comparison
equal
deleted
inserted
replaced
| 38:219f04e5ba55 | 39:7944c081e5b4 |
|---|---|
| 11 local _unpack = unpack --> lua local | 11 local _unpack = unpack --> lua local |
| 12 local _type = type --> lua local | 12 local _type = type --> lua local |
| 13 local _math_floor = math.floor --> lua local | 13 local _math_floor = math.floor --> lua local |
| 14 | 14 |
| 15 local cleanfunction = function() end | 15 local cleanfunction = function() end |
| 16 local SplitBarMetaFunctions = {} | |
| 17 local APISplitBarFunctions | 16 local APISplitBarFunctions |
| 17 | |
| 18 do | |
| 19 local metaPrototype = { | |
| 20 WidgetType = "split_bar", | |
| 21 SetHook = DF.SetHook, | |
| 22 RunHooksForWidget = DF.RunHooksForWidget, | |
| 23 } | |
| 24 | |
| 25 _G [DF.GlobalWidgetControlNames ["split_bar"]] = _G [DF.GlobalWidgetControlNames ["split_bar"]] or metaPrototype | |
| 26 end | |
| 27 | |
| 28 local SplitBarMetaFunctions = _G [DF.GlobalWidgetControlNames ["split_bar"]] | |
| 18 | 29 |
| 19 ------------------------------------------------------------------------------------------------------------ | 30 ------------------------------------------------------------------------------------------------------------ |
| 20 --> metatables | 31 --> metatables |
| 21 | 32 |
| 22 SplitBarMetaFunctions.__call = function (_table, value) | 33 SplitBarMetaFunctions.__call = function (_table, value) |
| 120 --> font color | 131 --> font color |
| 121 local gmember_textcolor = function (_object) | 132 local gmember_textcolor = function (_object) |
| 122 return _object.textleft:GetTextColor() | 133 return _object.textleft:GetTextColor() |
| 123 end | 134 end |
| 124 | 135 |
| 125 local get_members_function_index = { | 136 SplitBarMetaFunctions.GetMembers = SplitBarMetaFunctions.GetMembers or {} |
| 126 ["tooltip"] = gmember_tooltip, | 137 SplitBarMetaFunctions.GetMembers ["tooltip"] = gmember_tooltip |
| 127 ["shown"] = gmember_shown, | 138 SplitBarMetaFunctions.GetMembers ["shown"] = gmember_shown |
| 128 ["width"] = gmember_width, | 139 SplitBarMetaFunctions.GetMembers ["width"] = gmember_width |
| 129 ["height"] = gmember_height, | 140 SplitBarMetaFunctions.GetMembers ["height"] = gmember_height |
| 130 ["value"] = gmember_value, | 141 SplitBarMetaFunctions.GetMembers ["value"] = gmember_value |
| 131 ["righttext"] = gmember_rtext, | 142 SplitBarMetaFunctions.GetMembers ["righttext"] = gmember_rtext |
| 132 ["lefttext"] = gmember_ltext, | 143 SplitBarMetaFunctions.GetMembers ["lefttext"] = gmember_ltext |
| 133 ["rightcolor"] = gmember_rcolor, | 144 SplitBarMetaFunctions.GetMembers ["rightcolor"] = gmember_rcolor |
| 134 ["leftcolor"] = gmember_lcolor, | 145 SplitBarMetaFunctions.GetMembers ["leftcolor"] = gmember_lcolor |
| 135 ["righticon"] = gmember_ricon, | 146 SplitBarMetaFunctions.GetMembers ["righticon"] = gmember_ricon |
| 136 ["lefticon"] = gmember_licon, | 147 SplitBarMetaFunctions.GetMembers ["lefticon"] = gmember_licon |
| 137 ["texture"] = gmember_texture, | 148 SplitBarMetaFunctions.GetMembers ["texture"] = gmember_texture |
| 138 ["fontsize"] = gmember_textsize, | 149 SplitBarMetaFunctions.GetMembers ["fontsize"] = gmember_textsize |
| 139 ["fontface"] = gmember_textfont, | 150 SplitBarMetaFunctions.GetMembers ["fontface"] = gmember_textfont |
| 140 ["fontcolor"] = gmember_textcolor, | 151 SplitBarMetaFunctions.GetMembers ["fontcolor"] = gmember_textcolor |
| 141 ["textsize"] = gmember_textsize, --alias | 152 SplitBarMetaFunctions.GetMembers ["textsize"] = gmember_textsize --alias |
| 142 ["textfont"] = gmember_textfont, --alias | 153 SplitBarMetaFunctions.GetMembers ["textfont"] = gmember_textfont --alias |
| 143 ["textcolor"] = gmember_textcolor --alias | 154 SplitBarMetaFunctions.GetMembers ["textcolor"] = gmember_textcolor --alias |
| 144 } | |
| 145 | 155 |
| 146 SplitBarMetaFunctions.__index = function (_table, _member_requested) | 156 SplitBarMetaFunctions.__index = function (_table, _member_requested) |
| 147 | 157 |
| 148 local func = get_members_function_index [_member_requested] | 158 local func = SplitBarMetaFunctions.GetMembers [_member_requested] |
| 149 if (func) then | 159 if (func) then |
| 150 return func (_table, _member_requested) | 160 return func (_table, _member_requested) |
| 151 end | 161 end |
| 152 | 162 |
| 153 local fromMe = _rawget (_table, _member_requested) | 163 local fromMe = _rawget (_table, _member_requested) |
| 272 local _value1, _value2, _value3, _value4 = DF:ParseColors (_value) | 282 local _value1, _value2, _value3, _value4 = DF:ParseColors (_value) |
| 273 _object.textleft:SetTextColor (_value1, _value2, _value3, _value4) | 283 _object.textleft:SetTextColor (_value1, _value2, _value3, _value4) |
| 274 return _object.textright:SetTextColor (_value1, _value2, _value3, _value4) | 284 return _object.textright:SetTextColor (_value1, _value2, _value3, _value4) |
| 275 end | 285 end |
| 276 | 286 |
| 277 local set_members_function_index = { | 287 SplitBarMetaFunctions.SetMembers = SplitBarMetaFunctions.SetMembers or {} |
| 278 ["tooltip"] = smember_tooltip, | 288 SplitBarMetaFunctions.SetMembers ["tooltip"] = smember_tooltip |
| 279 ["shown"] = smember_shown, | 289 SplitBarMetaFunctions.SetMembers ["shown"] = smember_shown |
| 280 ["width"] = smember_width, | 290 SplitBarMetaFunctions.SetMembers ["width"] = smember_width |
| 281 ["height"] = smember_height, | 291 SplitBarMetaFunctions.SetMembers ["height"] = smember_height |
| 282 ["value"] = smember_value, | 292 SplitBarMetaFunctions.SetMembers ["value"] = smember_value |
| 283 ["righttext"] = smember_rtext, | 293 SplitBarMetaFunctions.SetMembers ["righttext"] = smember_rtext |
| 284 ["lefttext"] = smember_ltext, | 294 SplitBarMetaFunctions.SetMembers ["lefttext"] = smember_ltext |
| 285 ["rightcolor"] = smember_rcolor, | 295 SplitBarMetaFunctions.SetMembers ["rightcolor"] = smember_rcolor |
| 286 ["leftcolor"] = smember_lcolor, | 296 SplitBarMetaFunctions.SetMembers ["leftcolor"] = smember_lcolor |
| 287 ["righticon"] = smember_ricon, | 297 SplitBarMetaFunctions.SetMembers ["righticon"] = smember_ricon |
| 288 ["lefticon"] = smember_licon, | 298 SplitBarMetaFunctions.SetMembers ["lefticon"] = smember_licon |
| 289 ["texture"] = smember_texture, | 299 SplitBarMetaFunctions.SetMembers ["texture"] = smember_texture |
| 290 ["fontsize"] = smember_textsize, | 300 SplitBarMetaFunctions.SetMembers ["fontsize"] = smember_textsize |
| 291 ["fontface"] = smember_textfont, | 301 SplitBarMetaFunctions.SetMembers ["fontface"] = smember_textfont |
| 292 ["fontcolor"] = smember_textcolor, | 302 SplitBarMetaFunctions.SetMembers ["fontcolor"] = smember_textcolor |
| 293 ["textsize"] = smember_textsize, --alias | 303 SplitBarMetaFunctions.SetMembers ["textsize"] = smember_textsize --alias |
| 294 ["textfont"] = smember_textfont, --alias | 304 SplitBarMetaFunctions.SetMembers ["textfont"] = smember_textfont --alias |
| 295 ["textcolor"] = smember_textcolor --alias | 305 SplitBarMetaFunctions.SetMembers ["textcolor"] = smember_textcolor --alias |
| 296 } | |
| 297 | 306 |
| 298 SplitBarMetaFunctions.__newindex = function (_table, _key, _value) | 307 SplitBarMetaFunctions.__newindex = function (_table, _key, _value) |
| 299 local func = set_members_function_index [_key] | 308 local func = SplitBarMetaFunctions.SetMembers [_key] |
| 300 if (func) then | 309 if (func) then |
| 301 return func (_table, _value) | 310 return func (_table, _value) |
| 302 else | 311 else |
| 303 return _rawset (_table, _key, _value) | 312 return _rawset (_table, _key, _value) |
| 304 end | 313 end |
| 423 else | 432 else |
| 424 self.statusbar:SetFrameStrata (strata) | 433 self.statusbar:SetFrameStrata (strata) |
| 425 end | 434 end |
| 426 end | 435 end |
| 427 | 436 |
| 428 --> hooks | |
| 429 function SplitBarMetaFunctions:SetHook (hookType, func) | |
| 430 if (func) then | |
| 431 _rawset (self, hookType.."Hook", func) | |
| 432 else | |
| 433 _rawset (self, hookType.."Hook", nil) | |
| 434 end | |
| 435 end | |
| 436 | |
| 437 ------------------------------------------------------------------------------------------------------------ | 437 ------------------------------------------------------------------------------------------------------------ |
| 438 --> scripts | 438 --> scripts |
| 439 local OnEnter = function (frame) | 439 local OnEnter = function (frame) |
| 440 if (frame.MyObject.OnEnterHook) then | 440 local capsule = frame.MyObject |
| 441 local interrupt = frame.MyObject.OnEnterHook (frame) | 441 local kill = capsule:RunHooksForWidget ("OnEnter", frame, capsule) |
| 442 if (interrupt) then | 442 if (kill) then |
| 443 return | 443 return |
| 444 end | |
| 445 end | 444 end |
| 446 | 445 |
| 447 frame.MyObject.div:SetPoint ("left", frame, "left", frame:GetValue() * (frame:GetWidth()/100) - 18, 0) | 446 frame.MyObject.div:SetPoint ("left", frame, "left", frame:GetValue() * (frame:GetWidth()/100) - 18, 0) |
| 448 | 447 |
| 449 if (frame.MyObject.have_tooltip) then | 448 if (frame.MyObject.have_tooltip) then |
| 452 GameCooltip2:ShowCooltip (frame, "tooltip") | 451 GameCooltip2:ShowCooltip (frame, "tooltip") |
| 453 end | 452 end |
| 454 end | 453 end |
| 455 | 454 |
| 456 local OnLeave = function (frame) | 455 local OnLeave = function (frame) |
| 457 if (frame.MyObject.OnLeaveHook) then | 456 local capsule = frame.MyObject |
| 458 local interrupt = frame.MyObject.OnLeaveHook (frame) | 457 local kill = capsule:RunHooksForWidget ("OnLeave", frame, capsule) |
| 459 if (interrupt) then | 458 if (kill) then |
| 460 return | 459 return |
| 461 end | |
| 462 end | 460 end |
| 463 | 461 |
| 464 if (frame.MyObject.have_tooltip) then | 462 if (frame.MyObject.have_tooltip) then |
| 465 DF.popup:ShowMe (false) | 463 DF.popup:ShowMe (false) |
| 466 end | 464 end |
| 467 end | 465 end |
| 468 | 466 |
| 469 local OnHide = function (frame) | 467 local OnHide = function (frame) |
| 470 if (frame.MyObject.OnHideHook) then | 468 local capsule = frame.MyObject |
| 471 local interrupt = frame.MyObject.OnHideHook (frame) | 469 local kill = capsule:RunHooksForWidget ("OnHide", frame, capsule) |
| 472 if (interrupt) then | 470 if (kill) then |
| 473 return | 471 return |
| 474 end | |
| 475 end | 472 end |
| 476 end | 473 end |
| 477 | 474 |
| 478 local OnShow = function (frame) | 475 local OnShow = function (frame) |
| 479 if (frame.MyObject.OnShowHook) then | 476 local capsule = frame.MyObject |
| 480 local interrupt = frame.MyObject.OnShowHook (frame) | 477 local kill = capsule:RunHooksForWidget ("OnShow", frame, capsule) |
| 481 if (interrupt) then | 478 if (kill) then |
| 482 return | 479 return |
| 483 end | |
| 484 end | 480 end |
| 485 end | 481 end |
| 486 | 482 |
| 487 local OnMouseDown = function (frame, button) | 483 local OnMouseDown = function (frame, button) |
| 488 if (frame.MyObject.OnMouseDownHook) then | 484 local capsule = frame.MyObject |
| 489 local interrupt = frame.MyObject.OnMouseDownHook (frame, button) | 485 local kill = capsule:RunHooksForWidget ("OnMouseDown", frame, button, capsule) |
| 490 if (interrupt) then | 486 if (kill) then |
| 491 return | 487 return |
| 492 end | |
| 493 end | 488 end |
| 494 | 489 |
| 495 if (not frame.MyObject.container.isLocked and frame.MyObject.container:IsMovable()) then | 490 if (not frame.MyObject.container.isLocked and frame.MyObject.container:IsMovable()) then |
| 496 if (not frame.isLocked and frame:IsMovable()) then | 491 if (not frame.isLocked and frame:IsMovable()) then |
| 497 frame.MyObject.container.isMoving = true | 492 frame.MyObject.container.isMoving = true |
| 499 end | 494 end |
| 500 end | 495 end |
| 501 end | 496 end |
| 502 | 497 |
| 503 local OnMouseUp = function (frame, button) | 498 local OnMouseUp = function (frame, button) |
| 504 if (frame.MyObject.OnMouseUpHook) then | 499 local capsule = frame.MyObject |
| 505 local interrupt = frame.MyObject.OnMouseUpHook (frame, button) | 500 local kill = capsule:RunHooksForWidget ("OnMouseUp", frame, button, capsule) |
| 506 if (interrupt) then | 501 if (kill) then |
| 507 return | 502 return |
| 508 end | |
| 509 end | 503 end |
| 510 | 504 |
| 511 if (frame.MyObject.container.isMoving) then | 505 if (frame.MyObject.container.isMoving) then |
| 512 frame.MyObject.container:StopMovingOrSizing() | 506 frame.MyObject.container:StopMovingOrSizing() |
| 513 frame.MyObject.container.isMoving = false | 507 frame.MyObject.container.isMoving = false |
| 562 if (container.dframework) then | 556 if (container.dframework) then |
| 563 container = container.widget | 557 container = container.widget |
| 564 end | 558 end |
| 565 | 559 |
| 566 --> default members: | 560 --> default members: |
| 567 --> hooks | |
| 568 SplitBarObject.OnEnterHook = nil | |
| 569 SplitBarObject.OnLeaveHook = nil | |
| 570 SplitBarObject.OnHideHook = nil | |
| 571 SplitBarObject.OnShowHook = nil | |
| 572 SplitBarObject.OnMouseDownHook = nil | |
| 573 SplitBarObject.OnMouseUpHook = nil | |
| 574 --> misc | 561 --> misc |
| 575 SplitBarObject.tooltip = nil | |
| 576 SplitBarObject.locked = false | 562 SplitBarObject.locked = false |
| 577 SplitBarObject.have_tooltip = nil | |
| 578 SplitBarObject.container = container | 563 SplitBarObject.container = container |
| 579 | 564 |
| 580 --> create widgets | 565 --> create widgets |
| 581 SplitBarObject.statusbar = CreateFrame ("statusbar", name, parent, "DetailsFrameworkSplitBarTemplate") | 566 SplitBarObject.statusbar = CreateFrame ("statusbar", name, parent, "DetailsFrameworkSplitBarTemplate") |
| 582 SplitBarObject.widget = SplitBarObject.statusbar | 567 SplitBarObject.widget = SplitBarObject.statusbar |
| 608 SplitBarObject.background = _G [name .. "_StatusBarBackground"] | 593 SplitBarObject.background = _G [name .. "_StatusBarBackground"] |
| 609 SplitBarObject.texture = _G [name .. "_StatusBarTexture"] | 594 SplitBarObject.texture = _G [name .. "_StatusBarTexture"] |
| 610 | 595 |
| 611 SplitBarObject.div = _G [name .. "_Spark"] | 596 SplitBarObject.div = _G [name .. "_Spark"] |
| 612 | 597 |
| 613 | 598 |
| 614 --> hooks | 599 --> hooks |
| 615 SplitBarObject.statusbar:SetScript ("OnEnter", OnEnter) | 600 SplitBarObject.HookList = { |
| 616 SplitBarObject.statusbar:SetScript ("OnLeave", OnLeave) | 601 OnEnter = {}, |
| 617 SplitBarObject.statusbar:SetScript ("OnHide", OnHide) | 602 OnLeave = {}, |
| 618 SplitBarObject.statusbar:SetScript ("OnShow", OnShow) | 603 OnHide = {}, |
| 619 SplitBarObject.statusbar:SetScript ("OnMouseDown", OnMouseDown) | 604 OnShow = {}, |
| 620 SplitBarObject.statusbar:SetScript ("OnMouseUp", OnMouseUp) | 605 OnMouseDown = {}, |
| 621 SplitBarObject.statusbar:SetScript ("OnSizeChanged", OnSizeChanged) | 606 OnMouseUp = {}, |
| 607 OnSizeChanged = {}, | |
| 608 } | |
| 609 | |
| 610 SplitBarObject.statusbar:SetScript ("OnEnter", OnEnter) | |
| 611 SplitBarObject.statusbar:SetScript ("OnLeave", OnLeave) | |
| 612 SplitBarObject.statusbar:SetScript ("OnHide", OnHide) | |
| 613 SplitBarObject.statusbar:SetScript ("OnShow", OnShow) | |
| 614 SplitBarObject.statusbar:SetScript ("OnMouseDown", OnMouseDown) | |
| 615 SplitBarObject.statusbar:SetScript ("OnMouseUp", OnMouseUp) | |
| 616 SplitBarObject.statusbar:SetScript ("OnSizeChanged", OnSizeChanged) | |
| 622 | 617 |
| 623 _setmetatable (SplitBarObject, SplitBarMetaFunctions) | 618 _setmetatable (SplitBarObject, SplitBarMetaFunctions) |
| 624 | 619 |
| 625 return SplitBarObject | 620 return SplitBarObject |
| 626 end | 621 end |
