Mercurial > wow > hansgar_and_franzok_assist
comparison Libs/DF/button.lua @ 22:dbd417f413a8
- framework update.
| author | Tercio |
|---|---|
| date | Tue, 08 Sep 2015 13:16:49 -0300 |
| parents | dc1c77254f80 |
| children | 7523376ecaa3 |
comparison
equal
deleted
inserted
replaced
| 21:7fef991992f6 | 22:dbd417f413a8 |
|---|---|
| 614 else | 614 else |
| 615 button.texture:SetTexCoord (0, 1, 0.24609375, 0.49609375) | 615 button.texture:SetTexCoord (0, 1, 0.24609375, 0.49609375) |
| 616 end | 616 end |
| 617 end | 617 end |
| 618 | 618 |
| 619 if (button.MyObject.onenter_backdrop_border_color) then | |
| 620 button:SetBackdropBorderColor (unpack (button.MyObject.onenter_backdrop_border_color)) | |
| 621 end | |
| 622 | |
| 623 if (button.MyObject.onenter_backdrop) then | |
| 624 button:SetBackdropColor (unpack (button.MyObject.onenter_backdrop)) | |
| 625 end | |
| 626 | |
| 619 if (button.MyObject.have_tooltip) then | 627 if (button.MyObject.have_tooltip) then |
| 620 GameCooltip2:Preset (2) | 628 GameCooltip2:Preset (2) |
| 621 if (type (button.MyObject.have_tooltip) == "function") then | 629 if (type (button.MyObject.have_tooltip) == "function") then |
| 622 GameCooltip2:AddLine (button.MyObject.have_tooltip() or "") | 630 GameCooltip2:AddLine (button.MyObject.have_tooltip() or "") |
| 623 else | 631 else |
| 624 GameCooltip2:AddLine (button.MyObject.have_tooltip) | 632 GameCooltip2:AddLine (button.MyObject.have_tooltip) |
| 625 end | 633 end |
| 626 GameCooltip2:ShowCooltip (button, "tooltip") | 634 GameCooltip2:ShowCooltip (button, "tooltip") |
| 627 end | 635 end |
| 628 | |
| 629 local parent = button:GetParent().MyObject | |
| 630 if (parent and parent.type == "panel") then | |
| 631 if (parent.GradientEnabled) then | |
| 632 parent:RunGradient() | |
| 633 end | |
| 634 end | |
| 635 end | 636 end |
| 636 | 637 |
| 637 local OnLeave = function (button) | 638 local OnLeave = function (button) |
| 638 | 639 |
| 639 if (button.textureLeft and not button.MyObject.is_mouse_down) then | 640 if (button.textureLeft and not button.MyObject.is_mouse_down) then |
| 663 else | 664 else |
| 664 button.texture:SetTexCoord (0, 1, 0, 0.24609375) | 665 button.texture:SetTexCoord (0, 1, 0, 0.24609375) |
| 665 end | 666 end |
| 666 end | 667 end |
| 667 | 668 |
| 669 if (button.MyObject.onleave_backdrop_border_color) then | |
| 670 button:SetBackdropBorderColor (unpack (button.MyObject.onleave_backdrop_border_color)) | |
| 671 end | |
| 672 | |
| 673 if (button.MyObject.onleave_backdrop) then | |
| 674 button:SetBackdropColor (unpack (button.MyObject.onleave_backdrop)) | |
| 675 end | |
| 676 | |
| 668 if (button.MyObject.have_tooltip) then | 677 if (button.MyObject.have_tooltip) then |
| 669 if (GameCooltip2:GetText (1) == button.MyObject.have_tooltip or type (button.MyObject.have_tooltip) == "function") then | 678 if (GameCooltip2:GetText (1) == button.MyObject.have_tooltip or type (button.MyObject.have_tooltip) == "function") then |
| 670 GameCooltip2:Hide() | 679 GameCooltip2:Hide() |
| 671 end | |
| 672 end | |
| 673 | |
| 674 local parent = button:GetParent().MyObject | |
| 675 if (parent and parent.type == "panel") then | |
| 676 if (parent.GradientEnabled) then | |
| 677 parent:RunGradient (false) | |
| 678 end | 680 end |
| 679 end | 681 end |
| 680 end | 682 end |
| 681 | 683 |
| 682 local OnHide = function (button) | 684 local OnHide = function (button) |
| 860 end | 862 end |
| 861 end | 863 end |
| 862 end | 864 end |
| 863 | 865 |
| 864 ------------------------------------------------------------------------------------------------------------ | 866 ------------------------------------------------------------------------------------------------------------ |
| 867 | |
| 868 function ButtonMetaFunctions:SetTemplate (template) | |
| 869 | |
| 870 if (template.width) then | |
| 871 self:SetWidth (template.width) | |
| 872 end | |
| 873 if (template.height) then | |
| 874 self:SetHeight (template.height) | |
| 875 end | |
| 876 | |
| 877 if (template.backdrop) then | |
| 878 self:SetBackdrop (template.backdrop) | |
| 879 end | |
| 880 if (template.backdropcolor) then | |
| 881 local r, g, b, a = DF:ParseColors (template.backdropcolor) | |
| 882 self:SetBackdropColor (r, g, b, a) | |
| 883 self.onleave_backdrop = {r, g, b, a} | |
| 884 end | |
| 885 if (template.backdropbordercolor) then | |
| 886 local r, g, b, a = DF:ParseColors (template.backdropbordercolor) | |
| 887 self:SetBackdropBorderColor (r, g, b, a) | |
| 888 self.onleave_backdrop_border_color = {r, g, b, a} | |
| 889 end | |
| 890 | |
| 891 if (template.onentercolor) then | |
| 892 local r, g, b, a = DF:ParseColors (template.onentercolor) | |
| 893 self.onenter_backdrop = {r, g, b, a} | |
| 894 end | |
| 895 | |
| 896 if (template.onleavecolor) then | |
| 897 local r, g, b, a = DF:ParseColors (template.onleavecolor) | |
| 898 self.onleave_backdrop = {r, g, b, a} | |
| 899 end | |
| 900 | |
| 901 if (template.onenterbordercolor) then | |
| 902 local r, g, b, a = DF:ParseColors (template.onenterbordercolor) | |
| 903 self.onenter_backdrop_border_color = {r, g, b, a} | |
| 904 end | |
| 905 | |
| 906 if (template.onleavebordercolor) then | |
| 907 local r, g, b, a = DF:ParseColors (template.onleavebordercolor) | |
| 908 self.onleave_backdrop_border_color = {r, g, b, a} | |
| 909 end | |
| 910 | |
| 911 if (template.icon) then | |
| 912 local i = template.icon | |
| 913 self:SetIcon (i.texture, i.width, i.height, i.layout, i.texcoord, i.color, i.textdistance, i.leftpadding) | |
| 914 end | |
| 915 | |
| 916 end | |
| 917 | |
| 918 ------------------------------------------------------------------------------------------------------------ | |
| 865 --> object constructor | 919 --> object constructor |
| 866 | 920 |
| 867 function DF:CreateButton (parent, func, w, h, text, param1, param2, texture, member, name, short_method, text_template) | 921 function DF:CreateButton (parent, func, w, h, text, param1, param2, texture, member, name, short_method, button_template, text_template) |
| 868 return DF:NewButton (parent, parent, name, member, w, h, func, param1, param2, texture, text, short_method, text_template) | 922 return DF:NewButton (parent, parent, name, member, w, h, func, param1, param2, texture, text, short_method, button_template, text_template) |
| 869 end | 923 end |
| 870 | 924 |
| 871 function DF:NewButton (parent, container, name, member, w, h, func, param1, param2, texture, text, short_method, template) | 925 function DF:NewButton (parent, container, name, member, w, h, func, param1, param2, texture, text, short_method, button_template, text_template) |
| 872 | 926 |
| 873 if (not name) then | 927 if (not name) then |
| 874 name = "DetailsFrameworkButtonNumber" .. DF.ButtonCounter | 928 name = "DetailsFrameworkButtonNumber" .. DF.ButtonCounter |
| 875 DF.ButtonCounter = DF.ButtonCounter + 1 | 929 DF.ButtonCounter = DF.ButtonCounter + 1 |
| 876 | 930 |
| 882 end | 936 end |
| 883 | 937 |
| 884 if (name:find ("$parent")) then | 938 if (name:find ("$parent")) then |
| 885 name = name:gsub ("$parent", parent:GetName()) | 939 name = name:gsub ("$parent", parent:GetName()) |
| 886 end | 940 end |
| 887 | 941 |
| 888 | |
| 889 local ButtonObject = {type = "button", dframework = true} | 942 local ButtonObject = {type = "button", dframework = true} |
| 890 | 943 |
| 891 if (member) then | 944 if (member) then |
| 892 parent [member] = ButtonObject | 945 parent [member] = ButtonObject |
| 893 end | 946 end |
| 915 | 968 |
| 916 | 969 |
| 917 ButtonObject.button = CreateFrame ("button", name, parent, "DetailsFrameworkButtonTemplate") | 970 ButtonObject.button = CreateFrame ("button", name, parent, "DetailsFrameworkButtonTemplate") |
| 918 ButtonObject.widget = ButtonObject.button | 971 ButtonObject.widget = ButtonObject.button |
| 919 | 972 |
| 920 ButtonObject.button:SetBackdrop ({bgFile = DF.folder .. "background", tileSize = 64, edgeFile = DF.folder .. "border_2", edgeSize = 10, insets = {left = 1, right = 1, top = 1, bottom = 1}}) | 973 --ButtonObject.button:SetBackdrop ({bgFile = DF.folder .. "background", tileSize = 64, edgeFile = DF.folder .. "border_2", edgeSize = 10, insets = {left = 1, right = 1, top = 1, bottom = 1}}) |
| 921 ButtonObject.button:SetBackdropColor (0, 0, 0, 0.4) | 974 ButtonObject.button:SetBackdropColor (0, 0, 0, 0.4) |
| 922 ButtonObject.button:SetBackdropBorderColor (1, 1, 1, 1) | 975 ButtonObject.button:SetBackdropBorderColor (1, 1, 1, 1) |
| 923 | 976 |
| 924 if (not APIButtonFunctions) then | 977 if (not APIButtonFunctions) then |
| 925 APIButtonFunctions = true | 978 APIButtonFunctions = true |
| 932 end | 985 end |
| 933 end | 986 end |
| 934 end | 987 end |
| 935 end | 988 end |
| 936 | 989 |
| 990 | |
| 937 ButtonObject.button:SetWidth (w or 100) | 991 ButtonObject.button:SetWidth (w or 100) |
| 938 ButtonObject.button:SetHeight (h or 20) | 992 ButtonObject.button:SetHeight (h or 20) |
| 939 ButtonObject.button.MyObject = ButtonObject | 993 ButtonObject.button.MyObject = ButtonObject |
| 940 | 994 |
| 941 ButtonObject.text_overlay = _G [name .. "_Text"] | 995 ButtonObject.text_overlay = _G [name .. "_Text"] |
| 975 ButtonObject.param1 = param1 | 1029 ButtonObject.param1 = param1 |
| 976 ButtonObject.param2 = param2 | 1030 ButtonObject.param2 = param2 |
| 977 | 1031 |
| 978 ButtonObject.short_method = short_method | 1032 ButtonObject.short_method = short_method |
| 979 | 1033 |
| 980 if (template) then | 1034 if (text_template) then |
| 981 if (template.size) then | 1035 if (text_template.size) then |
| 982 DF:SetFontSize (ButtonObject.button.text, template.size) | 1036 DF:SetFontSize (ButtonObject.button.text, text_template.size) |
| 983 end | 1037 end |
| 984 if (template.color) then | 1038 if (text_template.color) then |
| 985 local r, g, b, a = DF:ParseColors (template.color) | 1039 local r, g, b, a = DF:ParseColors (text_template.color) |
| 986 ButtonObject.button.text:SetTextColor (r, g, b, a) | 1040 ButtonObject.button.text:SetTextColor (r, g, b, a) |
| 987 end | 1041 end |
| 988 if (template.font) then | 1042 if (text_template.font) then |
| 989 local SharedMedia = LibStub:GetLibrary ("LibSharedMedia-3.0") | 1043 local SharedMedia = LibStub:GetLibrary ("LibSharedMedia-3.0") |
| 990 local font = SharedMedia:Fetch ("font", template.font) | 1044 local font = SharedMedia:Fetch ("font", text_template.font) |
| 991 DF:SetFontFace (ButtonObject.button.text, font) | 1045 DF:SetFontFace (ButtonObject.button.text, font) |
| 992 end | 1046 end |
| 993 end | 1047 end |
| 994 | 1048 |
| 995 --> hooks | 1049 --> hooks |
| 999 ButtonObject.button:SetScript ("OnShow", OnShow) | 1053 ButtonObject.button:SetScript ("OnShow", OnShow) |
| 1000 ButtonObject.button:SetScript ("OnMouseDown", OnMouseDown) | 1054 ButtonObject.button:SetScript ("OnMouseDown", OnMouseDown) |
| 1001 ButtonObject.button:SetScript ("OnMouseUp", OnMouseUp) | 1055 ButtonObject.button:SetScript ("OnMouseUp", OnMouseUp) |
| 1002 | 1056 |
| 1003 _setmetatable (ButtonObject, ButtonMetaFunctions) | 1057 _setmetatable (ButtonObject, ButtonMetaFunctions) |
| 1058 | |
| 1059 if (button_template) then | |
| 1060 ButtonObject:SetTemplate (button_template) | |
| 1061 end | |
| 1004 | 1062 |
| 1005 return ButtonObject | 1063 return ButtonObject |
| 1006 | 1064 |
| 1007 end | 1065 end |
| 1008 | 1066 |
| 1027 | 1085 |
| 1028 local colorpick_cancel = function (self) | 1086 local colorpick_cancel = function (self) |
| 1029 ColorPickerFrame:Hide() | 1087 ColorPickerFrame:Hide() |
| 1030 end | 1088 end |
| 1031 | 1089 |
| 1032 function DF:CreateColorPickButton (parent, name, member, callback, alpha) | 1090 function DF:CreateColorPickButton (parent, name, member, callback, alpha, button_template) |
| 1033 return DF:NewColorPickButton (parent, name, member, callback, alpha) | 1091 return DF:NewColorPickButton (parent, name, member, callback, alpha, button_template) |
| 1034 end | 1092 end |
| 1035 | 1093 |
| 1036 function DF:NewColorPickButton (parent, name, member, callback, alpha) | 1094 function DF:NewColorPickButton (parent, name, member, callback, alpha, button_template) |
| 1037 | 1095 |
| 1038 --button | 1096 --button |
| 1039 local button = DF:NewButton (parent, _, name, member, color_button_width, color_button_height, pickcolor, alpha, "param2") | 1097 local button = DF:NewButton (parent, _, name, member, color_button_width, color_button_height, pickcolor, alpha, "param2", nil, nil, nil, button_template) |
| 1040 button:InstallCustomTexture() | |
| 1041 button.color_callback = callback | 1098 button.color_callback = callback |
| 1042 button.Cancel = colorpick_cancel | 1099 button.Cancel = colorpick_cancel |
| 1043 button.SetColor = set_colorpick_color | 1100 button.SetColor = set_colorpick_color |
| 1044 | 1101 |
| 1045 button:SetBackdrop ({edgeFile = [[Interface\Tooltips\UI-Tooltip-Border]], edgeSize = 6, | 1102 if (not button_template) then |
| 1046 bgFile = [[Interface\DialogFrame\UI-DialogBox-Background]], insets = {left = 0, right = 0, top = 0, bottom = 0}}) | 1103 button:InstallCustomTexture() |
| 1104 button:SetBackdrop ({edgeFile = [[Interface\Tooltips\UI-Tooltip-Border]], edgeSize = 6, | |
| 1105 bgFile = [[Interface\DialogFrame\UI-DialogBox-Background]], insets = {left = 0, right = 0, top = 0, bottom = 0}}) | |
| 1106 end | |
| 1047 | 1107 |
| 1048 --textura do fundo | 1108 --textura do fundo |
| 1049 local background = DF:NewImage (button, nil, color_button_width, color_button_height, nil, nil, nil, "$parentBck") | 1109 local background = DF:NewImage (button, nil, color_button_width, color_button_height, nil, nil, nil, "$parentBck") |
| 1050 --background:SetTexture ([[Interface\AddOns\Details\images\icons]]) | 1110 --background:SetTexture ([[Interface\AddOns\Details\images\icons]]) |
| 1051 background:SetPoint ("topleft", button.widget, "topleft", 1, -2) | 1111 background:SetPoint ("topleft", button.widget, "topleft", 1, -2) |
