diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/ElvUIDev/.gitattributes b/ElvUIDev/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/ElvUIDev/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/ElvUIDev/ElvUIDev.lua b/ElvUIDev/ElvUIDev.lua new file mode 100644 index 0000000..dada133 --- /dev/null +++ b/ElvUIDev/ElvUIDev.lua @@ -0,0 +1,1106 @@ +local AddonName, Addon = ... + +local ElvUI = LibStub("AceAddon-3.0"):GetAddon("ElvUI") +Addon.ElvUI = ElvUI + +local Distributor = ElvUI:GetModule("Distributor") +local PluginInstaller = ElvUI:GetModule("PluginInstaller") +local Layout = ElvUI:GetModule("Layout") +local ActionBars = ElvUI:GetModule("ActionBars") +local Auras = ElvUI:GetModule("Auras") +local Bags = ElvUI:GetModule("Bags") +local Blizzard = ElvUI:GetModule("Blizzard") +local Chat = ElvUI:GetModule("Chat") +local DataBars = ElvUI:GetModule("DataBars") +local DataTexts = ElvUI:GetModule("DataTexts") +local Minimap = ElvUI:GetModule("Minimap") +local WorldMap = ElvUI:GetModule("WorldMap") +local AFK = ElvUI:GetModule("AFK") +local ChatILvL = ElvUI:GetModule("ChatILvL") +local DebugTools = ElvUI:GetModule("DebugTools") +local Misc = ElvUI:GetModule("Misc") +local RaidUtility = ElvUI:GetModule("RaidUtility") +local Threat = ElvUI:GetModule("Threat") +local Totems = ElvUI:GetModule("Totems") +local NamePlates = ElvUI:GetModule("NamePlates") +local Skins = ElvUI:GetModule("Skins") +local Tooltip = ElvUI:GetModule("Tooltip") +local UnitFrames = ElvUI:GetModule("UnitFrames") + +local ElvUIDev = { } +Addon.ElvUIDev = ElvUIDev + +_G["ElvUIDev"] = ElvUIDev + +math.round = function(num, decimals) + local mult = 10^(decimals or 0) + + return math.floor(num * mult + 0.5) / mult +end + +local L = Addon.L + +ElvUIDev.events = CreateFrame("Frame") +ElvUIDev.events:RegisterEvent("ADDON_LOADED") + +ElvUIDev.events:SetScript("OnEvent", function(self, event, ...) + ElvUIDev[event](ElvUIDev, ...) +end) + +ElvUIDev.widgets = { } + +function ElvUIDev:Print(msg, ...) + print("|cFF50C0FFElvUIDev|r: "..msg, ...) +end + +-- Widgets +function ElvUIDev:RegisterWidget(name) + if self.widgets[name] then + ElvUIDev:Print("Widget is already registered with this name:", name) + end + + local class = { } + class["name"] = name + + self.widgets[name] = class + + return class +end + +function ElvUIDev:CreateWidget(name, ...) + local class = self.widgets[name] + + if not class then + ElvUIDev:Print("Widget is not registered:", name) + + return + end + + local frame = class:Create(...) + + local mt = getmetatable(frame) + + if type(mt.__index) == "table" then + setmetatable(frame, { + __index = function(self, key) + return (key == "Class" and class or key == "name" and class.name or key:sub(1, 2) == "__" and mt.__index[key:sub(3)] or class["__index"] and class.__index(self, key, mt) or key ~= "Create" and class[key] or mt.__index[key]) + end + }) + end + + return frame +end + +function ElvUIDev:GetWidget(name) + return self.widgets[name] +end + +function ElvUIDev:HasWidget(name) + return not not self.widgets[name] +end + +function ElvUIDev:ADDON_LOADED(addon) + if addon == AddonName then + ElvUIDev.loadedtime = GetTime() + + self:CreateOptions() + + if not self.frame.main.devtools.table.loaded then + self:AddFunctions() + self:UpdateFunctions() + + self.frame.main.devtools.table.loaded = true + end + + ElvUIDev:Print("Addon loaded into the memory.") + end +end + +function ElvUIDev:CreateOptions() + self.frame = self:CreateWidget("Window", "ElvUIDevOptions", UIParent) + self.frame:SetFrameStrata("High") + self.frame:SetSize(800, 600) + self.frame:SetPoint("TopLeft", UIParent, "TopLeft", (UIParent:GetWidth() / 2) - 400, (-UIParent:GetHeight() / 2) + 300) + self.frame:EnableMouse(true) + --self.frame:SetMovable(true) + + --[[if not InterfaceOptionsFrame:IsShown() then + tinsert(UISpecialFrames, self.frame:GetName()) + end + + if InterfaceOptionsFrame then + InterfaceOptionsFrame:HookScript("OnShow", function(self) + for i, v in pairs(UISpecialFrames) do + if v == "ElvUIDevOptions" then + tremove(UISpecialFrames, i) + end + end + end) + InterfaceOptionsFrame:HookScript("OnHide", function(self) + tinsert(UISpecialFrames, "ElvUIDevOptions") + end) + end]] + + self.frame:SetScript("OnMouseDown", function(self, button) + if button == "LeftButton" then + self:SetMovable(true) + self:StartMoving() + end + end) + self.frame:SetScript("OnMouseUp", function(self, button) + if button == "LeftButton" then + self:StopMovingOrSizing() + self:SetMovable(false) + + local left, bottom = self:GetLeft(), self:GetBottom() + + --local x = math.round((left + (self:GetWidth() / 2)) - (UIParent:GetWidth() / 2)) + --local y = math.round((bottom + (self:GetHeight() / 2)) - (UIParent:GetHeight() / 2)) + + local x = math.round(left) + local y = math.round(-UIParent:GetHeight() + bottom + self:GetHeight()) + + self:ClearAllPoints() + self:SetPoint("TopLeft", UIParent, "TopLeft", x, y) + end + end) + + --[[self.frame:SetScript("OnMouseWheel", function(self, delta) + self.overlay.texture:SetAlpha(self.overlay.texture:GetAlpha() - (delta / 50)) + self.Bg:SetAlpha(self.Bg:GetAlpha() - (delta / 200)) + end)]] + + self.frame.title:SetText("ElvUI Dev") + + self.frame.version = self.frame:CreateFontString(nil, "Overlay") + self.frame.version:SetFontObject(GameFontNormal) + self.frame.version:SetVertexColor(0.8, 0.8, 0.8, 0.3) + self.frame.version:SetPoint("BottomRight", self.frame, "BottomRight", -15, 3) + self.frame.version:SetWidth(120) + self.frame.version:SetHeight(20) + self.frame.version:SetJustifyV("Middle") + self.frame.version:SetJustifyH("Right") + self.frame.version:SetText(GetAddOnMetadata("ElvUIDev", "Version")) + self.frame.version:SetWordWrap(false) + + self.frame.main = { } + self.frame.main.devtools = { } + + self.frame.main.devtools.table = self:CreateWidget("Table", self.frame) + self.frame.main.devtools.table:SetPoint("TopLeft", self.frame, "TopLeft", 2 + 20, -84) + self.frame.main.devtools.table:SetPoint("BottomRight", self.frame, "BottomRight", -5 - 20, 75) + --self.frame.main.devtools.table:Hide() + + self.frame.main.devtools.table:AddColumn("Function", 0.3) + self.frame.main.devtools.table:AddColumn("Calls", 0.125) + self.frame.main.devtools.table:AddColumn("Calls/sec", 0.125, "%.3f") + self.frame.main.devtools.table:AddColumn("Time/call", 0.15, "%.3f ms") + self.frame.main.devtools.table:AddColumn("Total time", 0.15, "%.3f ms") + self.frame.main.devtools.table:AddColumn("Overall usage", 0.15, "%.2f%%", true) + + self.frame.main.devtools.table:SetScript("OnShow", function(frame) + ElvUIDev:UpdateFunctions() + end) + + --[[self.frame.main.devtools.table.refresh = self:CreateWidget("CheckButtonIcon", self.frame.main.devtools.table) + self.frame.main.devtools.table.refresh:SetPoint("TopRight", self.frame.main.devtools.table, "BottomRight", 0, 0) + self.frame.main.devtools.table.refresh.text:SetText("Refresh") + self.frame.main.devtools.table.refresh.text:SetWordWrap(false) + self.frame.main.devtools.table.refresh:SetScript("OnClick", function(self, button) + ElvUIDev:UpdateFunctions() + end)]] + + self.frame.main.devtools.table.toggle = self:CreateWidget("CheckButtonSquare", self.frame.main.devtools.table) + self.frame.main.devtools.table.toggle:SetPoint("TopLeft", self.frame.main.devtools.table, "BottomLeft", -2, 0) + + self.frame.main.devtools.table.toggle.texture:SetSize(7, 13) + self.frame.main.devtools.table.toggle.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\Play") + self.frame.main.devtools.table.toggle.texture:SetTexCoord(0.3125, 0.75, 0.0625, 0.875) + + self.frame.main.devtools.table.toggle:SetScript("OnClick", function(self, button) + if self:GetChecked() then + self:GetParent():SetScript("OnUpdate", ElvUIDev.FunctionsOnUpdate) + + self.texture:SetSize(9, 13) + self.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\Stop") + self.texture:SetTexCoord(0.1875, 0.75, 0.0625, 0.875) + else + self:GetParent():SetScript("OnUpdate", nil) + + self.texture:SetSize(7, 13) + self.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\Play") + self.texture:SetTexCoord(0.3125, 0.75, 0.0625, 0.875) + end + end) + + self.frame.main.devtools.table.refresh = self:CreateWidget("ButtonSquare", self.frame.main.devtools.table) + self.frame.main.devtools.table.refresh:SetPoint("TopLeft", self.frame.main.devtools.table.toggle, "TopRight", 0, 0) + + self.frame.main.devtools.table.refresh.texture:SetTexture("Interface\\Buttons\\UI-RefreshButton") + + self.frame.main.devtools.table.refresh:SetScript("OnClick", function(self, button) + ElvUIDev:UpdateFunctions() + end) + + self.frame.main.devtools.table.edit = self:CreateWidget("EditBox", self.frame.main.devtools.table) + self.frame.main.devtools.table.edit:SetSize(300, 26) + self.frame.main.devtools.table.edit:SetPoint("Left", self.frame.main.devtools.table.refresh, "Right", 3, 0) + + self.frame.main.devtools.table.edit.clear = CreateFrame("Button", nil, self.frame.main.devtools.table.edit) + self.frame.main.devtools.table.edit.clear:SetSize(12, 12) + self.frame.main.devtools.table.edit.clear:SetPoint("Center", self.frame.main.devtools.table.edit, "Right", -6 - 7, 0) + self.frame.main.devtools.table.edit.clear:SetAlpha(0.3) + self.frame.main.devtools.table.edit.clear:Hide() + + self.frame.main.devtools.table.edit.clear:SetScript("OnEnter", function(self) + if self.pushed then + return + end + + self:SetAlpha(0.6) + end) + self.frame.main.devtools.table.edit.clear:SetScript("OnLeave", function(self) + if self.pushed then + return + end + + self:SetAlpha(0.3) + end) + + self.frame.main.devtools.table.edit.clear:SetScript("OnMouseDown", function(self, button) + if button ~= "LeftButton" then + return + end + + self.pushed = true + + self:SetAlpha(0.2) + + self:SetSize(10, 10) + end) + self.frame.main.devtools.table.edit.clear:SetScript("OnMouseUp", function(self, button) + if button ~= "LeftButton" then + return + end + + self.pushed = nil + + self:SetAlpha(0.3) + + self:SetSize(12, 12) + end) + + self.frame.main.devtools.table.edit.clear:SetScript("OnClick", function(self, button) + if button ~= "LeftButton" then + return + end + + self.pushed = nil + + self:SetSize(12, 12) + + ElvUIDev.frame.main.devtools.table.edit:SetText("") + ElvUIDev.frame.main.devtools.table.edit:ClearFocus() + end) + + self.frame.main.devtools.table.edit.clear.texture = self.frame.main.devtools.table.edit.clear:CreateTexture(nil, "Overlay") + self.frame.main.devtools.table.edit.clear.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\Close") + self.frame.main.devtools.table.edit.clear.texture:SetAllPoints(self.frame.main.devtools.table.edit.clear) + + self.frame.main.devtools.table.edit.number = self.frame.main.devtools.table:CreateFontString(nil, "Background") + self.frame.main.devtools.table.edit.number:SetFontObject(GameFontHighlightSmall) + self.frame.main.devtools.table.edit.number:SetSize(200, 26) + self.frame.main.devtools.table.edit.number:SetJustifyV("Middle") + self.frame.main.devtools.table.edit.number:SetJustifyH("Left") + self.frame.main.devtools.table.edit.number:SetWordWrap(false) + self.frame.main.devtools.table.edit.number:SetPoint("Left", self.frame.main.devtools.table.edit, "Right", 3, 0) + + --self.frame.main.devtools.table.edit.number:SetText("0 functions.") + + self.frame.main.devtools.table.edit:SetScript("OnTextChanged", function(self, userInput) + local text = self:GetText() + if text == "" then + self.clear:Hide() + else + self.clear:Show() + end + + ElvUIDev.frame.main.devtools.table:SetFilter(text) + + if text == "" then + ElvUIDev.frame.main.devtools.table.edit.number:SetFormattedText("%d functions: %0.3f ms", #ElvUIDev.frame.main.devtools.table.sorted, ElvUIDev:GetTotal(5)) + else + ElvUIDev.frame.main.devtools.table.edit.number:SetFormattedText("%d functions: %0.3f ms", #ElvUIDev.frame.main.devtools.table.filtered, ElvUIDev:GetFiltered(5)) + end + end) + + self.frame.childrens = {self.frame:GetChildren()} + + self:MakeScaleable(self.frame) + + self.frame:Hide() + + PlaySound(841) +end + +function ElvUIDev:ToggleFrame() + if not self.frame:IsShown() then + self.frame:Show() + else + self.frame:Hide() + end +end + +function ElvUIDev:AddFunction(key, func) + local subs = false + local usage, calls = GetFunctionCPUUsage(func, subs) + usage, calls = math.max(0, usage), calls + self.frame.main.devtools.table:AddRow(key, calls, (calls / math.floor(GetTime() - (ElvUI.loadedtime or ElvUIDev.loadedtime))), (usage / math.max(1, calls)), usage, (usage / math.max(1, GetAddOnCPUUsage("ElvUI"))) * 100) +end + +function ElvUIDev:AddFunctions() + for key, func in pairs(ElvUI) do + if type(func) == "function" then + self:AddFunction("ElvUI:"..key, func) + end + end + + for key, func in pairs(Distributor) do + if type(func) == "function" then + self:AddFunction("Distributor:"..key, func) + end + end + + for key, func in pairs(PluginInstaller) do + if type(func) == "function" then + self:AddFunction("PluginInstaller:"..key, func) + end + end + + for key, func in pairs(Layout) do + if type(func) == "function" then + self:AddFunction("Layout:"..key, func) + end + end + + for key, func in pairs(ActionBars) do + if type(func) == "function" then + self:AddFunction("ActionBars:"..key, func) + end + end + + for key, func in pairs(Auras) do + if type(func) == "function" then + self:AddFunction("Auras:"..key, func) + end + end + + for key, func in pairs(Bags) do + if type(func) == "function" then + self:AddFunction("Bags:"..key, func) + end + end + + for key, func in pairs(Blizzard) do + if type(func) == "function" then + self:AddFunction("Blizzard:"..key, func) + end + end + + for key, func in pairs(Chat) do + if type(func) == "function" then + self:AddFunction("Chat:"..key, func) + end + end + + for key, func in pairs(DataBars) do + if type(func) == "function" then + self:AddFunction("DataBars:"..key, func) + end + end + + for key, func in pairs(DataTexts) do + if type(func) == "function" then + self:AddFunction("DataTexts:"..key, func) + end + end + + for key, func in pairs(Minimap) do + if type(func) == "function" then + self:AddFunction("Minimap:"..key, func) + end + end + + for key, func in pairs(WorldMap) do + if type(func) == "function" then + self:AddFunction("WorldMap:"..key, func) + end + end + + for key, func in pairs(AFK) do + if type(func) == "function" then + self:AddFunction("AFK:"..key, func) + end + end + + for key, func in pairs(ChatILvL) do + if type(func) == "function" then + self:AddFunction("ChatILvL:"..key, func) + end + end + + for key, func in pairs(DebugTools) do + if type(func) == "function" then + self:AddFunction("DebugTools:"..key, func) + end + end + + for key, func in pairs(Misc) do + if type(func) == "function" then + self:AddFunction("Misc:"..key, func) + end + end + + for key, func in pairs(RaidUtility) do + if type(func) == "function" then + self:AddFunction("RaidUtility:"..key, func) + end + end + + for key, func in pairs(Threat) do + if type(func) == "function" then + self:AddFunction("Threat:"..key, func) + end + end + + for key, func in pairs(Totems) do + if type(func) == "function" then + self:AddFunction("Totems:"..key, func) + end + end + + for key, func in pairs(NamePlates) do + if type(func) == "function" then + self:AddFunction("NamePlates:"..key, func) + end + end + + for key, func in pairs(Skins) do + if type(func) == "function" then + self:AddFunction("Skins:"..key, func) + end + end + + for key, func in pairs(Tooltip) do + if type(func) == "function" then + self:AddFunction("Tooltip:"..key, func) + end + end + + for key, func in pairs(UnitFrames) do + if type(func) == "function" then + self:AddFunction("UnitFrames:"..key, func) + end + end + + self.frame.main.devtools.table:ApplyFilter() +end + +function ElvUIDev:UpdateFunction(key, func) + local subs = false + local usage, calls = GetFunctionCPUUsage(func, subs) + usage, calls = math.max(0, usage), calls + + local callspersec = (calls / math.floor(GetTime() - (ElvUI.loadedtime or ElvUIDev.loadedtime))) + local timepercall = (usage / math.max(1, calls)) + local overallusage = (usage / math.max(1, GetAddOnCPUUsage("ElvUI"))) * 100 + + if calls == 0 and callspersec == 0 and timepercall == 0 and usage == 0 and overallusage == 0 then + return + end + + self.frame.main.devtools.table:UpdateRow(key, calls, callspersec, timepercall, usage, overallusage) +end + +function ElvUIDev:FunctionsOnUpdate(elapsed) + self.time = (self.time or 0) + elapsed + if self.time < 1 then + return + end + self.time = 0 + + ElvUIDev:UpdateFunctions() +end + +function ElvUIDev:UpdateFunctions() + UpdateAddOnCPUUsage("ElvUI") + + for key, func in pairs(ElvUI) do + if type(func) == "function" then + self:UpdateFunction("ElvUI:"..key, func) + end + end + + for key, func in pairs(Distributor) do + if type(func) == "function" then + self:UpdateFunction("Distributor:"..key, func) + end + end + + for key, func in pairs(PluginInstaller) do + if type(func) == "function" then + self:UpdateFunction("PluginInstaller:"..key, func) + end + end + + for key, func in pairs(Layout) do + if type(func) == "function" then + self:UpdateFunction("Layout:"..key, func) + end + end + + for key, func in pairs(ActionBars) do + if type(func) == "function" then + self:UpdateFunction("ActionBars:"..key, func) + end + end + + for key, func in pairs(Auras) do + if type(func) == "function" then + self:UpdateFunction("Auras:"..key, func) + end + end + + for key, func in pairs(Bags) do + if type(func) == "function" then + self:UpdateFunction("Bags:"..key, func) + end + end + + for key, func in pairs(Blizzard) do + if type(func) == "function" then + self:UpdateFunction("Blizzard:"..key, func) + end + end + + for key, func in pairs(Chat) do + if type(func) == "function" then + self:UpdateFunction("Chat:"..key, func) + end + end + + for key, func in pairs(DataBars) do + if type(func) == "function" then + self:UpdateFunction("DataBars:"..key, func) + end + end + + for key, func in pairs(DataTexts) do + if type(func) == "function" then + self:UpdateFunction("DataTexts:"..key, func) + end + end + + for key, func in pairs(Minimap) do + if type(func) == "function" then + self:UpdateFunction("Minimap:"..key, func) + end + end + + for key, func in pairs(WorldMap) do + if type(func) == "function" then + self:UpdateFunction("WorldMap:"..key, func) + end + end + + for key, func in pairs(AFK) do + if type(func) == "function" then + self:UpdateFunction("AFK:"..key, func) + end + end + + for key, func in pairs(ChatILvL) do + if type(func) == "function" then + self:UpdateFunction("ChatILvL:"..key, func) + end + end + + for key, func in pairs(DebugTools) do + if type(func) == "function" then + self:UpdateFunction("DebugTools:"..key, func) + end + end + + for key, func in pairs(Misc) do + if type(func) == "function" then + self:UpdateFunction("Misc:"..key, func) + end + end + + for key, func in pairs(RaidUtility) do + if type(func) == "function" then + self:UpdateFunction("RaidUtility:"..key, func) + end + end + + for key, func in pairs(Threat) do + if type(func) == "function" then + self:UpdateFunction("Threat:"..key, func) + end + end + + for key, func in pairs(Totems) do + if type(func) == "function" then + self:UpdateFunction("Totems:"..key, func) + end + end + + for key, func in pairs(NamePlates) do + if type(func) == "function" then + self:UpdateFunction("NamePlates:"..key, func) + end + end + + for key, func in pairs(Skins) do + if type(func) == "function" then + self:UpdateFunction("Skins:"..key, func) + end + end + + for key, func in pairs(Tooltip) do + if type(func) == "function" then + self:UpdateFunction("Tooltip:"..key, func) + end + end + + for key, func in pairs(UnitFrames) do + if type(func) == "function" then + self:UpdateFunction("UnitFrames:"..key, func) + end + end + + self.frame.main.devtools.table:Update() + + if ElvUIDev.frame.main.devtools.table.edit:GetText() == "" then + ElvUIDev.frame.main.devtools.table.edit.number:SetFormattedText("%d functions: %0.3f ms", #ElvUIDev.frame.main.devtools.table.sorted, ElvUIDev:GetTotal(5)) + else + ElvUIDev.frame.main.devtools.table.edit.number:SetFormattedText("%d functions: %0.3f ms", #ElvUIDev.frame.main.devtools.table.filtered, ElvUIDev:GetFiltered(5)) + end +end + +function ElvUIDev:GetTotal(row) + local x = 0 + + for i = 1, #self.frame.main.devtools.table.sorted do + x = x + tonumber(self.frame.main.devtools.table.sorted[i][row].text) + end + + return x +end + +function ElvUIDev:GetFiltered(row) + local x = 0 + + for i = 1, #self.frame.main.devtools.table.filtered do + x = x + tonumber(self.frame.main.devtools.table.filtered[i][row].text) + end + + return x +end + +function ElvUIDev:MakeScaleable(frame) + if not frame then + return + end + + if frame.resizable then + return + end + + frame.resizable = true + + frame.width = frame:GetWidth() + frame.height = frame:GetHeight() + frame.scale = frame:GetScale() + + frame.frameLevel = frame:GetFrameLevel() + if frame.frameLevel > 13 then + frame.frameLevel = 13 + end + + frame:SetMovable(true) + frame:SetMaxResize(math.round(frame.width * 1.50375), math.round(frame.height * 1.50375)) + frame:SetMinResize(math.round(frame.width * 0.66125), math.round(frame.height * 0.66125)) + frame:SetUserPlaced(true) + + frame.br = CreateFrame("Frame", nil, frame) + frame.br:SetFrameStrata(frame:GetFrameStrata()) + frame.br:SetPoint("BottomRight", frame, "BottomRight", -2, 1) + frame.br:SetWidth(16) + frame.br:SetHeight(16) + frame.br:SetFrameLevel(frame.frameLevel + 7) + frame.br:EnableMouse(true) + + frame.br.texture = frame.br:CreateTexture(nil, "Overlay") + frame.br.texture:SetPoint("TopLeft", frame.br, "TopLeft", 0, 0) + frame.br.texture:SetWidth(16) + frame.br.texture:SetHeight(16) + frame.br.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberUp") + + frame.br:SetScript("OnEnter", function(self) + frame.br.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberHighlight") + frame.bl.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberHighlight") + frame.tr.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberHighlight") + end) + frame.br:SetScript("OnLeave", function(self) + frame.br.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberUp") + frame.bl.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberUp") + frame.tr.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberUp") + end) + frame.br:SetScript("OnMouseDown", function(self, button) + if button == "LeftButton" then + frame:SetResizable(true) + frame.resizing = true + frame:StartSizing("Right") + end + + frame.br.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberDown") + frame.bl.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberDown") + frame.tr.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberDown") + + frame.version:SetFormattedText("%.3f", frame.scale) + end) + frame.br:SetScript("OnMouseUp", function(self, button) + if button == "MiddleButton" then + frame.br.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberUp") + frame.bl.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberUp") + frame.tr.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberUp") + end + + local x, y = GetCursorPosition() + local fx = self:GetLeft() * self:GetEffectiveScale() + local fy = self:GetBottom() * self:GetEffectiveScale() + if x >= fx and x <= (fx + self:GetWidth()) and y >= fy and y <= (fy + self:GetHeight()) then + frame.br.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberHighlight") + frame.bl.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberHighlight") + frame.tr.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberHighlight") + else + frame.br.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberUp") + frame.bl.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberUp") + frame.tr.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberUp") + end + + frame.resizing = nil + frame.direction = nil + frame:StopMovingOrSizing() + frame:SetResizable(false) + + frame.version:SetText(GetAddOnMetadata("ElvUIDev", "Version")) + end) + + frame.bl = CreateFrame("Frame", nil, frame) + frame.bl:SetFrameStrata(frame:GetFrameStrata()) + frame.bl:SetPoint("BottomLeft", frame, "BottomLeft", 0, 1) + frame.bl:SetWidth(16) + frame.bl:SetHeight(16) + frame.bl:SetFrameLevel(frame.frameLevel + 7) + frame.bl:EnableMouse(true) + + frame.bl.texture = frame.bl:CreateTexture(nil, "Overlay") + local ULx, ULy, LLx, LLy, URx, URy, LRx, LRy = frame.bl.texture:GetTexCoord() + frame.bl.texture:SetTexCoord(URx, URy, LRx, LRy, ULx, ULy, LLx, LLy) + frame.bl.texture:SetPoint("TopLeft", frame.bl, "TopLeft", 0, 0) + frame.bl.texture:SetWidth(16) + frame.bl.texture:SetHeight(16) + frame.bl.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberUp") + + frame.bl:SetScript("OnEnter", function(self) + frame.bl.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberHighlight") + frame.tl.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberHighlight") + frame.br.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberHighlight") + end) + frame.bl:SetScript("OnLeave", function(self) + frame.bl.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberUp") + frame.tl.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberUp") + frame.br.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberUp") + end) + frame.bl:SetScript("OnMouseDown", function(self, button) + if button == "LeftButton" then + frame:SetResizable(true) + frame.resizing = true + frame:StartSizing("Left") + end + + frame.bl.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberDown") + frame.tl.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberDown") + frame.br.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberDown") + + frame.version:SetFormattedText("%.3f", frame.scale) + end) + frame.bl:SetScript("OnMouseUp", function(self, button) + if button == "MiddleButton" then + frame.bl.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberUp") + frame.tl.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberUp") + frame.br.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberUp") + end + + local x, y = GetCursorPosition() + local fx = self:GetLeft() * self:GetEffectiveScale() + local fy = self:GetBottom() * self:GetEffectiveScale() + if x >= fx and x <= (fx + self:GetWidth()) and y >= fy and y <= (fy + self:GetHeight()) then + frame.bl.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberHighlight") + frame.tl.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberHighlight") + frame.br.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberHighlight") + else + frame.bl.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberUp") + frame.tl.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberUp") + frame.br.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberUp") + end + + frame.resizing = nil + frame.direction = nil + frame:StopMovingOrSizing() + frame:SetResizable(false) + + frame.version:SetText(GetAddOnMetadata("ElvUIDev", "Version")) + end) + + frame.tl = CreateFrame("Frame", nil, frame) + frame.tl:SetFrameStrata(frame:GetFrameStrata()) + frame.tl:SetPoint("TopLeft", frame, "TopLeft", 0, -20) + frame.tl:SetWidth(16) + frame.tl:SetHeight(16) + frame.tl:SetFrameLevel(frame.frameLevel + 7) + frame.tl:EnableMouse(true) + + frame.tl.texture = frame.tl:CreateTexture(nil, "Overlay") + local ULx, ULy, LLx, LLy, URx, URy, LRx, LRy = frame.tl.texture:GetTexCoord() + frame.tl.texture:SetTexCoord(LRx, LRy, URx, URy, LLx, LLy, ULx, ULy) + frame.tl.texture:SetPoint("TopLeft", frame.tl, "TopLeft", 0, 0) + frame.tl.texture:SetWidth(16) + frame.tl.texture:SetHeight(16) + frame.tl.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberUp") + + frame.tl:SetScript("OnEnter", function(self) + frame.tl.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberHighlight") + frame.tr.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberHighlight") + frame.bl.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberHighlight") + end) + frame.tl:SetScript("OnLeave", function(self) + frame.tl.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberUp") + frame.tr.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberUp") + frame.bl.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberUp") + end) + frame.tl:SetScript("OnMouseDown", function(self, button) + if button == "LeftButton" then + frame:SetResizable(true) + frame.resizing = true + frame.direction = "TopLeft" + frame:StartSizing("Top") + end + + frame.tl.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberDown") + frame.tr.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberDown") + frame.bl.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberDown") + + frame.version:SetFormattedText("%.3f", frame.scale) + end) + frame.tl:SetScript("OnMouseUp", function(self, button) + if button == "MiddleButton" then + frame.tl.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberUp") + frame.tr.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberUp") + frame.bl.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberUp") + end + + local x, y = GetCursorPosition() + local fx = self:GetLeft() * self:GetEffectiveScale() + local fy = self:GetBottom() * self:GetEffectiveScale() + if x >= fx and x <= (fx + self:GetWidth()) and y >= fy and y <= (fy + self:GetHeight()) then + frame.tl.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberHighlight") + frame.tr.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberHighlight") + frame.bl.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberHighlight") + else + frame.tl.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberUp") + frame.tr.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberUp") + frame.bl.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberUp") + end + + frame.resizing = nil + frame.direction = nil + frame:StopMovingOrSizing() + frame:SetResizable(false) + + frame.version:SetText(GetAddOnMetadata("ElvUIDev", "Version")) + end) + + frame.tr = CreateFrame("Frame", nil, frame) + frame.tr:SetFrameStrata(frame:GetFrameStrata()) + frame.tr:SetPoint("TopRight", frame, "TopRight", -2, -20) + frame.tr:SetWidth(16) + frame.tr:SetHeight(16) + frame.tr:SetFrameLevel(frame.frameLevel + 7) + frame.tr:EnableMouse(true) + + frame.tr.texture = frame.tr:CreateTexture(nil, "Overlay") + local ULx, ULy, LLx, LLy, URx, URy, LRx, LRy = frame.tr.texture:GetTexCoord() + frame.tr.texture:SetTexCoord(LLx, LLy, ULx, ULy, LRx, LRy, URx, URy) + frame.tr.texture:SetPoint("TopLeft", frame.tr, "TopLeft", 0, 0) + frame.tr.texture:SetWidth(16) + frame.tr.texture:SetHeight(16) + frame.tr.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberUp") + + frame.tr:SetScript("OnEnter", function(self) + frame.tr.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberHighlight") + frame.tl.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberHighlight") + frame.br.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberHighlight") + end) + frame.tr:SetScript("OnLeave", function(self) + frame.tr.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberUp") + frame.tl.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberUp") + frame.br.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberUp") + end) + frame.tr:SetScript("OnMouseDown", function(self, button) + if button == "LeftButton" then + frame:SetResizable(true) + frame.resizing = true + frame.direction = "TopRight" + frame:StartSizing("Top") + end + + frame.tr.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberDown") + frame.tl.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberDown") + frame.br.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberDown") + + frame.version:SetFormattedText("%.3f", frame.scale) + end) + frame.tr:SetScript("OnMouseUp", function(self, button) + if button == "MiddleButton" then + frame.tr.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberUp") + frame.tl.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberUp") + frame.br.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberUp") + end + + local x, y = GetCursorPosition() + local fx = self:GetLeft() * self:GetEffectiveScale() + local fy = self:GetBottom() * self:GetEffectiveScale() + if x >= fx and x <= (fx + self:GetWidth()) and y >= fy and y <= (fy + self:GetHeight()) then + frame.tr.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberHighlight") + frame.tl.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberHighlight") + frame.br.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberHighlight") + else + frame.tr.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberUp") + frame.tl.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberUp") + frame.br.texture:SetTexture("Interface\\AddOns\\ElvUIDev\\Textures\\SizeGrabberUp") + end + + frame.resizing = nil + frame.direction = nil + frame:StopMovingOrSizing() + frame:SetResizable(false) + + frame.version:SetText(GetAddOnMetadata("ElvUIDev", "Version")) + end) + + frame:SetScript("OnSizeChanged", function(self) + if not self.resizing then + return + end + + local left, bottom = self:GetLeft(), self:GetBottom() + + if self.direction == "TopLeft" or self.direction == "TopRight" then + self:ClearAllPoints() + if self.direction == "TopLeft" then + local x = math.round(-UIParent:GetWidth() + self:GetRight()) + local y = math.round(bottom) + + self:SetPoint("BottomRight", UIParent, "BottomRight", x, y) + else + local x = math.round(left) + local y = math.round(bottom) + + self:SetPoint("BottomLeft", UIParent, "BottomLeft", x, y) + end + + local scale = self:GetHeight() / frame.height + self.scale = scale + --local modifier = ((1 - scale) / 1.8) -- Figure out why the hell do we need this. + --local xy = modifier / (scale + 1.5) + self:SetWidth(math.round(frame.width * scale)) + --frame.overlay:SetScale(scale) + self.overlay:SetScale(scale) + --self.main.menu:SetPoint("TopLeft", self.main, "TopLeft", 50, math.round(-43 / scale)) + + self.shadow.upper:SetPoint("TopLeft", 0, math.round(-21 / self.scale)) + self.shadow.upper:SetPoint("TopRight", math.round(-2 / self.scale), math.round(-21 / self.scale)) + self.shadow.upper:SetScale(scale) + + for i = 1, #self.main.devtools.table.frame.columns do + if self.main.devtools.table.frame:GetWidth() == 800 then + return + end + + local column = self.main.devtools.table.frame.columns[i][1] + + column:SetWidth(math.round(self.main.devtools.table.frame:GetWidth() * self.main.devtools.table.frame.columns[i][6])) + column:SetMaxResize(math.round(column:GetWidth() * 2), math.round(column:GetHeight() * 2)) + column:SetMinResize(math.round(column:GetWidth() / 1.4), math.round(column:GetHeight() / 1.4)) + end + + local y = math.round(self:GetHeight() - (self.overlay:GetHeight() * scale) + 5) + self.main.devtools.table:SetPoint("TopLeft", self, "TopLeft", 2 + 20, -y) + + self.version:SetFormattedText("%.3f", self.scale) + + --ElvUIDev:ScaleChildrens(self, scale) + else + self:ClearAllPoints() + local x = math.round(left) + local y = math.round(-UIParent:GetHeight() + bottom + self:GetHeight()) + self:SetPoint("TopLeft", UIParent, "TopLeft", x, y) + + local scale = self:GetWidth() / frame.width + self.scale = scale + --local modifier = ((1 - scale) / 1.8) -- Figure out why the hell do we need this. + --local xy = modifier / (scale + 1.5) + self:SetHeight(math.round(frame.height * scale)) + --frame.overlay:SetScale(scale) + self.overlay:SetScale(scale) + --self.main.menu:SetPoint("TopLeft", self.main, "TopLeft", 50, math.round(-43 / scale)) + + self.shadow.upper:SetPoint("TopLeft", 0, math.round(-21 / self.scale)) + self.shadow.upper:SetPoint("TopRight", math.round(-2 / self.scale), math.round(-21 / self.scale)) + self.shadow.upper:SetScale(scale) + + for i = 1, #self.main.devtools.table.frame.columns do + if self.main.devtools.table.frame:GetWidth() == 800 then + return + end + + local column = self.main.devtools.table.frame.columns[i][1] + + column:SetWidth(math.round(self.main.devtools.table.frame:GetWidth() * self.main.devtools.table.frame.columns[i][6])) + column:SetMaxResize(math.round(column:GetWidth() * 2), math.round(column:GetHeight() * 2)) + column:SetMinResize(math.round(column:GetWidth() / 1.4), math.round(column:GetHeight() / 1.4)) + end + + local y = math.round(self:GetHeight() - (self.overlay:GetHeight() * scale) + 5) + self.main.devtools.table:SetPoint("TopLeft", self, "TopLeft", 2 + 20, -y) + + self.version:SetFormattedText("%.3f", self.scale) + + --ElvUIDev:ScaleChildrens(self, scale) + end + end) +end + +function ElvUIDev:ScaleChildrens(frame, scale) + --local childrens = {frame:GetChildren()} + --for _, child in ipairs(childrens) do + for i = 1, #self.frame.childrens do + local child = self.frame.childrens[i] + if child ~= frame.bl and child ~= frame.b and child ~= frame.br and child ~= frame.tr and child ~= frame.t and child ~= frame.tl and child ~= frame.l and child ~= frame.r then + child:SetScale(scale) + end + end +end diff --git a/ElvUIDev/ElvUIDev.toc b/ElvUIDev/ElvUIDev.toc new file mode 100644 index 0000000..82c8df0 --- /dev/null +++ b/ElvUIDev/ElvUIDev.toc @@ -0,0 +1,16 @@ +## Interface: 80000 +## Title: ElvUI Dev +## Version: 0.1.2 +## Author: Resike +## Notes: Development tools for ElvUI. +## DefaultState: Enabled +## Dependencies: ElvUI +## LoadOnDemand: 1 + +ElvUIDev.lua + +Widgets\Button.lua +Widgets\CheckButton.lua +Widgets\EditBox.lua +Widgets\Table.lua +Widgets\Window.lua \ No newline at end of file diff --git a/ElvUIDev/Textures/Close.tga b/ElvUIDev/Textures/Close.tga new file mode 100644 index 0000000..e1d06bb Binary files /dev/null and b/ElvUIDev/Textures/Close.tga differ diff --git a/ElvUIDev/Textures/Play.tga b/ElvUIDev/Textures/Play.tga new file mode 100644 index 0000000..c0ca707 Binary files /dev/null and b/ElvUIDev/Textures/Play.tga differ diff --git a/ElvUIDev/Textures/SizeGrabberDown.tga b/ElvUIDev/Textures/SizeGrabberDown.tga new file mode 100644 index 0000000..88ca5f2 Binary files /dev/null and b/ElvUIDev/Textures/SizeGrabberDown.tga differ diff --git a/ElvUIDev/Textures/SizeGrabberHighlight.tga b/ElvUIDev/Textures/SizeGrabberHighlight.tga new file mode 100644 index 0000000..12678e6 Binary files /dev/null and b/ElvUIDev/Textures/SizeGrabberHighlight.tga differ diff --git a/ElvUIDev/Textures/SizeGrabberUp.tga b/ElvUIDev/Textures/SizeGrabberUp.tga new file mode 100644 index 0000000..150df82 Binary files /dev/null and b/ElvUIDev/Textures/SizeGrabberUp.tga differ diff --git a/ElvUIDev/Textures/Stop.tga b/ElvUIDev/Textures/Stop.tga new file mode 100644 index 0000000..4c66b5a Binary files /dev/null and b/ElvUIDev/Textures/Stop.tga differ diff --git a/ElvUIDev/Widgets/Button.lua b/ElvUIDev/Widgets/Button.lua new file mode 100644 index 0000000..26e3c5a --- /dev/null +++ b/ElvUIDev/Widgets/Button.lua @@ -0,0 +1,69 @@ +local AddonName, Addon = ... + +local ElvUIDev = Addon.ElvUIDev + +local CreateFrame = CreateFrame +local GameFontDisableSmall = GameFontDisableSmall +local GameFontHighlightSmall = GameFontHighlightSmall + +local Button = ElvUIDev:RegisterWidget("Button") + +function Button:Create(parent) + local frame = CreateFrame("Button", nil, parent) + frame:SetSize(150, 22) + frame:SetNormalFontObject(GameFontHighlightSmall) + frame:SetDisabledFontObject(GameFontDisableSmall) + frame:SetHighlightFontObject(GameFontHighlightSmall) + + frame.text = frame:CreateFontString(nil, "Overlay") + frame.text:SetFontObject(GameFontHighlightSmall) + frame.text:SetJustifyH("Left") + frame.text:SetJustifyV("Middle") + frame.text:SetWordWrap(false) + frame.text:SetPoint("Left", frame, "Right", 5, 0) + frame.text:SetText("Button") + + frame:SetFontString(frame.text) + + return frame +end + +local ButtonSquare = ElvUIDev:RegisterWidget("ButtonSquare") + +function ButtonSquare:Create(parent) + local frame = CreateFrame("Button", nil, parent) + frame:SetSize(32, 32) + + frame:SetNormalTexture("Interface\\Buttons\\UI-SquareButton-Up") + frame:GetNormalTexture():SetDesaturated(true) + frame:GetNormalTexture():SetVertexColor(0.8, 0.8, 0.8) + frame:GetNormalTexture():SetDrawLayer("Overlay", 3) + + frame:SetPushedTexture("Interface\\Buttons\\UI-SquareButton-Down") + frame:GetPushedTexture():SetDesaturated(true) + frame:GetPushedTexture():SetVertexColor(0.8, 0.8, 0.8) + frame:GetPushedTexture():SetDrawLayer("Overlay", 3) + + frame:SetHighlightTexture("Interface\\Buttons\\UI-Common-MouseHilight") + + frame:GetHighlightTexture():SetBlendMode("Add") + frame:GetHighlightTexture():SetAlpha(0.75) + frame:GetHighlightTexture():SetPoint("TopLeft", frame, "TopLeft", 0, -2) + frame:GetHighlightTexture():SetPoint("BottomRight", frame, "BottomRight", -2, 1) + + frame.texture = frame:CreateTexture("Overlay") + frame.texture:SetDrawLayer("Overlay", 5) + frame.texture:SetSize(14, 14) + frame.texture:SetPoint("Center", frame, "Center", -1, -1) + + frame:SetScript("OnMouseDown", function(self, button) + self.texture:SetVertexColor(0.5, 0.5, 0.5) + self.texture:SetPoint("Center", self, "Center", -2, -3) + end) + frame:SetScript("OnMouseUp", function(self, button) + self.texture:SetVertexColor(1, 1, 1) + self.texture:SetPoint("Center", self, "Center", -1, -1) + end) + + return frame +end diff --git a/ElvUIDev/Widgets/CheckButton.lua b/ElvUIDev/Widgets/CheckButton.lua new file mode 100644 index 0000000..a863b88 --- /dev/null +++ b/ElvUIDev/Widgets/CheckButton.lua @@ -0,0 +1,125 @@ +local AddonName, Addon = ... + +local ElvUIDev = Addon.ElvUIDev + +local hooksecurefunc = hooksecurefunc + +local CreateFrame = CreateFrame + +local GameFontNomal = GameFontNomal +local GameFontHighlightl = GameFontHighlight +local GameFontDisable = GameFontDisable + +local CheckButton = ElvUIDev:RegisterWidget("CheckButton") + +function CheckButton:Create(parent) + local frame = CreateFrame("CheckButton", nil, parent) + frame:SetSize(20, 20) + frame:SetNormalFontObject(GameFontNomal) + local normalFont = frame:GetNormalFontObject() + normalFont:SetTextColor(1, 1, 1) + frame:SetHighlightFontObject(GameFontHighlight) + local highlightFont = frame:GetHighlightFontObject() + highlightFont:SetTextColor(1, 0.82, 0) + frame:SetDisabledFontObject(GameFontDisable) + local disableFont = frame:GetDisabledFontObject() + disableFont:SetTextColor(0.5, 0.5, 0.5) + frame:SetNormalTexture("Interface\\Buttons\\UI-CheckBox-Up") + frame:SetCheckedTexture("Interface\\Buttons\\UI-Common-MouseHilight") + frame:SetHighlightTexture("Interface\\Buttons\\UI-CheckBox-Highlight") + + frame.text = frame:CreateFontString(nil, "Overlay") + frame.text:SetFontObject(GameFontNomal) + frame.text:SetJustifyH("Left") + frame.text:SetJustifyV("Middle") + frame.text:SetWordWrap(false) + frame.text:SetPoint("Left", frame, "Right", 1, 1) + frame.text:SetText("CheckButton") + + frame:SetFontString(frame.text) + frame:SetHitRectInsets(0, -frame:GetWidth() + 10 - frame.text:GetStringWidth(), 0, 4) + + -- Only for non-static text + --[[hooksecurefunc(frame.text, "SetText", function(self) + frame:SetHitRectInsets(0, -frame:GetWidth() + 10 - frame.text:GetStringWidth(), 0, 0) + end)]] + + return frame +end + +local CheckButtonIcon = ElvUIDev:RegisterWidget("CheckButtonIcon") + +function CheckButtonIcon:Create(parent) + local frame = CreateFrame("CheckButton", nil, parent) + frame:SetSize(100, 32) + frame:SetNormalFontObject(GameFontNomal) + local normalFont = frame:GetNormalFontObject() + normalFont:SetTextColor(1, 1, 1) + frame:SetHighlightFontObject(GameFontHighlight) + local highlightFont = frame:GetHighlightFontObject() + highlightFont:SetTextColor(1, 0.82, 0) + frame:SetDisabledFontObject(GameFontDisable) + local disableFont = frame:GetDisabledFontObject() + disableFont:SetTextColor(0.5, 0.5, 0.5) + + frame.icon = frame:CreateTexture(nil, "Artwork") + frame.icon:SetSize(24, 24) + frame.icon:SetPoint("TopLeft", 4, -4) + + frame.text = frame:CreateFontString(nil, "Overlay") + frame.text:SetFontObject(GameFontNomal) + frame.text:SetPoint("TopLeft", 36, -4) + frame.text:SetPoint("BottomRight", -4, 4) + frame.text:SetJustifyV("Middle") + frame.text:SetJustifyH("Left") + frame.text:SetText("CheckButton") + + frame:SetFontString(frame.text) + + -- Only for non-static text + --[[hooksecurefunc(frame.text, "SetText", function(self) + frame:SetHitRectInsets(0, -frame:GetWidth() + 10 - frame.text:GetStringWidth(), 0, 0) + end)]] + + return frame +end + +local CheckButtonSquare = ElvUIDev:RegisterWidget("CheckButtonSquare") + +function CheckButtonSquare:Create(parent) + local frame = CreateFrame("CheckButton", nil, parent) + frame:SetSize(32, 32) + + frame:SetNormalTexture("Interface\\Buttons\\UI-SquareButton-Up") + frame:GetNormalTexture():SetDesaturated(true) + frame:GetNormalTexture():SetVertexColor(0.8, 0.8, 0.8, 1.0) + frame:GetNormalTexture():SetDrawLayer("Overlay", 3) + + frame:SetPushedTexture("Interface\\Buttons\\UI-SquareButton-Down") + frame:GetPushedTexture():SetDesaturated(true) + frame:GetPushedTexture():SetVertexColor(0.8, 0.8, 0.8, 1.0) + frame:GetPushedTexture():SetDrawLayer("Overlay", 3) + + frame:SetHighlightTexture("Interface\\Buttons\\UI-Common-MouseHilight") + + frame:GetHighlightTexture():SetBlendMode("Add") + frame:GetHighlightTexture():SetAlpha(0.75) + frame:GetHighlightTexture():SetPoint("TopLeft", frame, "TopLeft", 0, -2) + frame:GetHighlightTexture():SetPoint("BottomRight", frame, "BottomRight", -2, 1) + + frame.texture = frame:CreateTexture("Overlay") + frame.texture:SetDrawLayer("Overlay", 5) + frame.texture:SetSize(14, 14) + frame.texture:SetPoint("Center", frame, "Center", 0, 0) + + frame:SetScript("OnMouseDown", function(self, button) + self.texture:SetVertexColor(0.5, 0.5, 0.5, 1.0) + self.texture:SetPoint("Center", self, "Center", -1, -2) + end) + frame:SetScript("OnMouseUp", function(self, button) + self.texture:SetVertexColor(0.8, 0.8, 0.8, 1.0) + self.texture:SetPoint("Center", self, "Center", 0, 0) + end) + + return frame +end diff --git a/ElvUIDev/Widgets/EditBox.lua b/ElvUIDev/Widgets/EditBox.lua new file mode 100644 index 0000000..40b468a --- /dev/null +++ b/ElvUIDev/Widgets/EditBox.lua @@ -0,0 +1,62 @@ +local AddonName, Addon = ... + +local ElvUIDev = Addon.ElvUIDev + +local CreateFrame = CreateFrame +local GameFontHighlight = GameFontHighlight +local GameFontNormal = GameFontNormal + +local EditBox = ElvUIDev:RegisterWidget("EditBox") + +function EditBox:Create(parent) + local frame = CreateFrame("EditBox", nil, parent) + frame:SetSize(200, 26) + frame:SetJustifyH("Left") + frame:SetAutoFocus(false) + frame:SetFontObject(GameFontHighlight) + frame:SetTextInsets(4, 4, 2, 2) + frame:SetHitRectInsets(0, 0, 0, 0) + frame:SetBackdrop({ + bgFile = "Interface\\Buttons\\White8X8", + edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", + tile = true, + tileSize = 16, + edgeSize = 13, + insets = {left = 3, right = 3, top = 2, bottom = 2} + }) + frame:SetBackdropColor(0, 0, 0, 0.5) + frame:SetBackdropBorderColor(0.3, 0.3, 0.3, 1.0) + + frame.title = frame:CreateFontString(nil, "Overlay") + frame.title:SetFontObject(GameFontNormal) + frame.title:SetJustifyH("Left") + frame.title:SetJustifyV("Middle") + frame.title:SetWordWrap(false) + frame.title:SetSize(194, 20) + frame.title:SetPoint("BottomLeft", frame, "TopLeft", 3, 0) + frame.title:SetPoint("BottomRight", frame, "TopRight", -3, 0) + --frame.title:SetText("EditBox") + + frame:SetScript("OnEnter", function(self) + self:SetBackdropBorderColor(0.45, 0.45, 0.45, 1.0) + end) + frame:SetScript("OnLeave", function(self) + self:SetBackdropBorderColor(0.3, 0.3, 0.3, 1.0) + end) + + frame:SetScript("OnEscapePressed", function(self) + self:ClearFocus() + end) + frame:SetScript("OnEnterPressed", function(self) + self:ClearFocus() + end) + + frame:SetScript("OnEditFocusLost", function(self) + self:HighlightText(0, 0) + end) + --[[frame:SetScript("OnEditFocusGained", function(self) + self:HighlightText(0, -1) + end)]] + + return frame +end diff --git a/ElvUIDev/Widgets/Table.lua b/ElvUIDev/Widgets/Table.lua new file mode 100644 index 0000000..5ee6943 --- /dev/null +++ b/ElvUIDev/Widgets/Table.lua @@ -0,0 +1,777 @@ +local AddonName, Addon = ... + +local ElvUIDev = Addon.ElvUIDev + +local CreateFrame = CreateFrame + +local Table = ElvUIDev:RegisterWidget("Table") + +function Table:Create(parent) + self.frame = CreateFrame("Frame", nil, parent or UIParent) + self.frame:SetPoint("TopLeft", parent, "TopLeft", 0, 0) + self.frame:SetPoint("BottomRight", parent, "BottomRight", 0, 0) + self.frame:SetSize(800, 600) + + self.frame.backdrop = { + bgFile = "Interface\\Buttons\\WHITE8X8", + edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", + tile = true, + tileSize = 16, + edgeSize = 14, + insets = {left = 2, right = 2, top = 2, bottom = 2}, + } + + self.frame:SetBackdrop(self.frame.backdrop) + self.frame:SetBackdropColor(0.0, 0.0, 0.0, 0.5) + self.frame:SetBackdropBorderColor(0.3, 0.3, 0.3, 1.0) + + self.frame.columns = { } + --self.frame.rows = { } + + --self.frame.rowstext = { } + + self.frame.sorted = { } + + self.frame.sortedheader = 1 + self.frame.descending = false + + self.frame.filtered = { } + + self.frame.filter = "" + + self.frame.scrollframe = CreateFrame("ScrollFrame", nil, self.frame) + self.frame.scrollframe:SetPoint("TopLeft", self.frame, "TopLeft", 2, -2 - 19) + self.frame.scrollframe:SetPoint("BottomRight", self.frame, "BottomRight", -2, 2 + 1) + self.frame.scrollframe:SetClipsChildren(true) + + self.frame.header = CreateFrame("ScrollFrame", nil, self.frame) + self.frame.header:SetPoint("TopLeft", self.frame, "TopLeft", 0, 0) + self.frame.header:SetPoint("BottomRight", self.frame, "TopRight", 0, -24) + + self.frame.headerscrolling = CreateFrame("Frame", nil, self.frame.header) + self.frame.headerscrolling:SetSize(11, 19) + self.frame.headerscrolling:SetAllPoints(self.frame.header) + + self.frame.header:SetScrollChild(self.frame.headerscrolling) + + self.frame.scrollbar = CreateFrame("Slider", nil, self.frame, "UIPanelScrollBarTemplate") + self.frame.scrollbar:SetScript("OnValueChanged", nil) -- :GetParent() visibility bug with :SetClipsChildren(true) + self.frame.scrollbar:SetPoint("TopRight", self.frame, "TopRight", -4 + 21, -18) + self.frame.scrollbar:SetPoint("BottomRight", self.frame, "BottomRight", -4 + 21, 17) + self.frame.scrollbar:SetMinMaxValues(0, 0) + self.frame.scrollbar:SetValueStep(22) + self.frame.scrollbar:SetObeyStepOnDrag(true) + self.frame.scrollbar.scrollStep = 1 + self.frame.scrollbar:SetValue(1) + self.frame.scrollbar.ScrollUpButton:Disable() + self.frame.scrollbar:SetWidth(16) + + self.frame.scrollbar:SetScript("OnValueChanged", function(self, value) + if not self:IsShown() then + return + end + + local min, max = self:GetMinMaxValues() + if value == min then + self.ScrollUpButton:Disable() + else + self.ScrollUpButton:Enable() + end + + if value == max then + self.ScrollDownButton:Disable() + else + self.ScrollDownButton:Enable() + end + + self:GetParent().scrollframe:SetVerticalScroll(value) + + -- Too expensive + local offset = (self:GetValue() / self:GetValueStep()) + + if offset % 2 == 0 then + for i = 1, #Table.frame.rowframes do + for j = 1, #Table.frame.rowframes[i] do + if i % 2 == 0 then + Table.frame.rowframes[i][j].bg:SetColorTexture(0.4, 0.4, 0.4) + else + Table.frame.rowframes[i][j].bg:SetColorTexture(0.9, 0.9, 1) + end + end + end + else + for i = 1, #Table.frame.rowframes do + for j = 1, #Table.frame.rowframes[i] do + if i % 2 == 0 then + Table.frame.rowframes[i][j].bg:SetColorTexture(0.9, 0.9, 1) + else + Table.frame.rowframes[i][j].bg:SetColorTexture(0.4, 0.4, 0.4) + end + end + end + end + + Table:UpdateItems() + + --[[local startline = (self:GetValue() / 22) + 1 + local endline = startline + 18 + + if endline > #Table.frame.rows then + endline = #Table.frame.rows + end + + for i = 1, #Table.frame.rows do + for j = 1, #Table.frame.rows[i] do + if i >= startline and i <= endline then + Table.frame.rows[i][j]:Show() + else + Table.frame.rows[i][j]:Hide() + end + end + end]] + end) + + self.frame:SetScript("OnMouseWheel", function (self, delta) + self.scrollbar:SetValue(self.scrollbar:GetValue() - (delta * 27 * self.scrollbar.scrollStep)) + end) + + self.frame.scrollbar.bg = self.frame.scrollbar:CreateTexture(nil, "Background") + self.frame.scrollbar.bg:SetAllPoints(self.frame.scrollbar) + self.frame.scrollbar.bg:SetColorTexture(0, 0, 0, 0.4) + + self.frame.scrolling = CreateFrame("Frame", nil, self.frame.scrollframe) + --self.frame.scrolling:SetPoint("TopLeft", self.frame.scrollframe, "TopLeft", 0, 0) + --self.frame.scrolling:SetPoint("BottomRight", self.frame.scrollframe, "BottomRight", 0, 0) + self.frame.scrolling:SetAllPoints(self.frame.scrollframe) + self.frame.scrolling:SetSize(800, 0) + + self.frame.scrollframe:SetScrollChild(self.frame.scrolling) + + function self.frame.sorter(a, b) + local col, desc = self.frame.sortedheader, self.frame.descending + --print(a[col].text, b[col].text) + return (desc and a[col].text > b[col].text) or + (not desc and a[col].text < b[col].text) or + (a[col].text == b[col].text and a[1].text < b[1].text) + end + + return self.frame +end + +function Table:GetSortedColumn() + return self.frame.sortedheader, self.frame.descending +end + +function Table:SetSortedColumn(id, desc) + self.frame.sortedheader = math.max(1, math.min(#(self.frame.columns), id)) + self.frame.descending = not not desc + self:SortColumn() +end + +function Table:SortColumn() + local items + if self.frame.filter and self.frame.filter ~= "" then + items = self.frame.filtered + else + items = self.frame.sorted + end + + table.sort(items, self.frame.columns[self.frame.sortedheader][5]) + + self:UpdateItems() +end + +function Table:AddColumn(text, width, format, last) + local frame = self:CreateColumn(self.frame.headerscrolling, text, width, format, last) + --frame:SetID(#self.frame.columns + 1) + + --tinsert(self.frame.columns, {frame, text, width, format}) + + self.frame.columns[#self.frame.columns + 1] = {frame, text, width, format, self.sorter, width} + + --self:Sort() + + return #self.frame.columns +end + +function Table:CreateColumn(parent, text, width, format, last) + local frame = CreateFrame("Button", nil, parent) + frame:SetID(#self.frame.columns + 1) + + if last then + frame.last = last + end + + if self.frame.lastcolumn then + if frame.last then + frame:SetPoint("TopLeft", self.frame.lastcolumn, "TopRight", -2, 0) + frame:SetPoint("TopRight", self.frame, "TopRight", -2, 0) + else + frame:SetPoint("TopLeft", self.frame.lastcolumn, "TopRight", -2, 0) + end + else + frame:SetPoint("TopLeft", parent, "TopLeft", 1, -2) + end + + --[[local x = 0 + if self.frame.scrollbar:IsShown() then + x = 12 + end]] + + --frame:SetSize((self.frame:GetWidth() - x) * width, 24) + frame:SetSize(math.round(self.frame:GetWidth() * width), 24) + frame:SetMaxResize(math.round(frame:GetWidth() * 2), math.round(frame:GetHeight() * 2)) + frame:SetMinResize(math.round(frame:GetWidth() / 1.4), math.round(frame:GetHeight() / 1.4)) + + frame.text = frame:CreateFontString(nil, "Overlay") + if frame:GetID() == 1 then + frame.text:SetPoint("TopLeft", frame, "TopLeft", 6.5, -2.5) + else + frame.text:SetPoint("TopLeft", frame, "TopLeft", 4.5, -2.5) + end + frame.text:SetPoint("BottomRight", frame, "BottomRight", -4 - 20, 6) + frame.text:SetFontObject(GameFontHighlightSmall) + --frame.text:SetVertexColor(0.4, 0.7, 1, 1) + frame.text:SetJustifyH("Left") + frame.text:SetWordWrap(false) + + frame:SetFontString(frame.text) + frame:SetText(text) + + --frame:SetNormalFontObject(GameFontHighlightSmall) + frame:SetHighlightTexture([[Interface\HelpFrame\KnowledgeBaseButtton]]) + frame:GetHighlightTexture():SetTexCoord(0.13085938, 0.63085938, 0.0078125, 0.203125) + frame:GetHighlightTexture():ClearAllPoints() + frame:GetHighlightTexture():SetPoint("TopLeft", 2, -1) + frame:GetHighlightTexture():SetPoint("BottomRight", -1, 5) + + --[=[frame.highlight = CreateFrame("Frame", nil, frame) + frame.highlight:SetAllPoints(frame) + + frame.highlight.l = frame.highlight:CreateTexture(nil, "Highlight") + frame.highlight.l:SetTexture([[Interface\ChatFrame\ChatFrameTab-HighlightLeft]]) + frame.highlight.l:SetPoint("TopLeft", frame.highlight, "TopLeft", 1, 0) + frame.highlight.l:SetBlendMode("Add") + frame.highlight.l:SetVertexColor(0.2, 0.5, 1, 0.75) + frame.highlight.l:SetSize(12, 19) + frame.highlight.l:SetTexCoord(0.25, 1, 0.375, 1) + + frame.highlight.r = frame.highlight:CreateTexture(nil, "Highlight") + frame.highlight.r:SetTexture([[Interface\ChatFrame\ChatFrameTab-HighlightRight]]) + frame.highlight.r:SetPoint("TopRight", frame.highlight, "TopRight", 0, 0) + frame.highlight.r:SetBlendMode("Add") + frame.highlight.r:SetVertexColor(0.2, 0.5, 1, 0.75) + frame.highlight.r:SetSize(12, 19) + frame.highlight.r:SetTexCoord(0, 0.75, 0.375, 1) + + frame.highlight.m = frame.highlight:CreateTexture(nil, "Highlight") + frame.highlight.m:SetTexture([[Interface\ChatFrame\ChatFrameTab-HighlightMid]]) + frame.highlight.m:SetPoint("TopLeft", frame.highlight.l, "TopRight", 0, 0) + frame.highlight.m:SetPoint("BottomRight", frame.highlight.r, "BottomLeft", 0, 0) + frame.highlight.m:SetBlendMode("Add") + frame.highlight.m:SetVertexColor(0.2, 0.5, 1, 0.75) + frame.highlight.m:SetTexCoord(0, 1, 0.375, 1) + + frame.highlight:SetScript("OnEnter", function(self) + frame.highlight.l:Show() + frame.highlight.r:Show() + frame.highlight.m:Show() + end) + + frame.highlight:SetScript("OnLeave", function(self) + frame.highlight.l:Hide() + frame.highlight.r:Hide() + frame.highlight.m:Hide() + end)]=] + + if not frame.last then + frame.resize = CreateFrame("Frame", nil, frame) + frame.resize:EnableMouse(true) + frame.resize:SetSize(7, 17) + frame.resize:SetPoint("Center", frame, "Right", 0, 0) + --frame.resize.bg = frame.resize:CreateTexture(nil, "Background") + --frame.resize.bg:SetAllPoints(frame.resize) + --frame.resize.bg:SetColorTexture(0.9, 0.9, 1) + --frame.resize.bg:SetAlpha(0.1) + + frame.resize:SetScript("OnMouseDown", function(resize, button) + --frame:SetParent(self.frame) + frame:SetResizable(true) + frame:StartSizing("Right") + end) + frame.resize:SetScript("OnMouseUp", function(resize, button) + frame:SetResizable(false) + frame:StopMovingOrSizing() + + for i = 1, #self.frame.columns do + if i ~= 1 then + if self.frame.columns[i][1].last then + self.frame.columns[i][1]:SetPoint("TopLeft", self.frame.columns[i - 1][1], "TopRight", -2, 0) + self.frame.columns[i][1]:SetPoint("TopRight", self.frame, "TopRight", -2, 0) + else + self.frame.columns[i][1]:SetPoint("TopLeft", self.frame.columns[i - 1][1], "TopRight", -2, 0) + end + else + self.frame.columns[i][1]:SetPoint("TopLeft", parent, "TopLeft", 1, -2) + end + + self.frame.columns[i][6] = self.frame.columns[i][1]:GetWidth() / self.frame:GetWidth() + --self.frame.columns[i][1]:SetParent(self.frame.headerscrolling) + end + end) + + frame.resize:SetScript("OnEnter", function(resize, button) + frame.right:SetAlpha(1) + self.frame.columns[frame:GetID() + 1][1].left:SetAlpha(1) + end) + frame.resize:SetScript("OnLeave", function(resize, button) + frame.right:SetAlpha(0.4) + self.frame.columns[frame:GetID() + 1][1].left:SetAlpha(0.5) + end) + + frame:SetScript("OnSizeChanged", function(self, button) + if self.noSizing then + return + end + + self:SetWidth(math.round(self:GetWidth())) + + -- This should be recursive + --for i = #Table.frame.columns, self:GetID() + 1, -1 do + local i = 6 + if Table.frame.columns[i][1]:GetWidth() < (Table.frame:GetWidth() * Table.frame.columns[i][3] / 1.4) then + local diff = Table.frame:GetWidth() * Table.frame.columns[i][3] / 1.4 - Table.frame.columns[i][1]:GetWidth() + + if (Table.frame.columns[i - 1][1]:GetWidth() - diff) > (Table.frame:GetWidth() * Table.frame.columns[i - 1][3] / 1.4) then + Table.frame.columns[i - 1][1].noSizing = true + Table.frame.columns[i - 1][1]:SetWidth(math.round(Table.frame.columns[i - 1][1]:GetWidth() - diff)) + Table.frame.columns[i - 1][1].noSizing = nil + else + if (Table.frame.columns[i - 2][1]:GetWidth() - diff) > (Table.frame:GetWidth() * Table.frame.columns[i - 2][3] / 1.4) then + Table.frame.columns[i - 2][1].noSizing = true + Table.frame.columns[i - 2][1]:SetWidth(math.round(Table.frame.columns[i - 2][1]:GetWidth() - diff)) + Table.frame.columns[i - 2][1].noSizing = nil + else + if (Table.frame.columns[i - 3][1]:GetWidth() - diff) > (Table.frame:GetWidth() * Table.frame.columns[i - 3][3] / 1.4) then + Table.frame.columns[i - 3][1].noSizing = true + Table.frame.columns[i - 3][1]:SetWidth(math.round(Table.frame.columns[i - 3][1]:GetWidth() - diff)) + Table.frame.columns[i - 3][1].noSizing = nil + else + if (Table.frame.columns[i - 4][1]:GetWidth() - diff) > (Table.frame:GetWidth() * Table.frame.columns[i - 4][3] / 1.4) then + Table.frame.columns[i - 4][1].noSizing = true + Table.frame.columns[i - 4][1]:SetWidth(math.round(Table.frame.columns[i - 4][1]:GetWidth() - diff)) + Table.frame.columns[i - 4][1].noSizing = nil + else + if (Table.frame.columns[i - 5][1]:GetWidth() - diff) > (Table.frame:GetWidth() * Table.frame.columns[i - 5][3] / 1.4) then + Table.frame.columns[i - 5][1].noSizing = true + Table.frame.columns[i - 5][1]:SetWidth(math.round(Table.frame.columns[i - 5][1]:GetWidth() - diff)) + Table.frame.columns[i - 5][1].noSizing = nil + end + end + end + end + end + end + --end + end) + end + + --if self.frame.lastcolumn then + frame.left = frame:CreateTexture(nil, "Background") + frame.left:SetTexture([[Interface\FriendsFrame\WhoFrame-ColumnTabs]]) + frame.left:SetTexCoord(0, 0.078125, 0, 0.59375) + frame.left:SetVertexColor(0.65, 0.65, 0.65, 1) + frame.left:SetPoint("TopLeft") + frame.left:SetSize(5, 19) + frame.left:SetAlpha(0.4) + --end + + --if not frame.last then + frame.right = frame:CreateTexture(nil, "Background") + frame.right:SetTexture([[Interface\FriendsFrame\WhoFrame-ColumnTabs]]) + frame.right:SetTexCoord(0.90625, 0.96875, 0, 0.59375) + frame.right:SetVertexColor(0.65, 0.65, 0.65, 1) + frame.right:SetPoint("TopRight") + frame.right:SetSize(4, 19) + frame.right:SetAlpha(0.4) + --end + + frame.middle = frame:CreateTexture(nil, "Background") + frame.middle:SetTexture([[Interface\FriendsFrame\WhoFrame-ColumnTabs]]) + frame.middle:SetTexCoord(0.078125, 0.90625, 0, 0.59375) + frame.middle:SetVertexColor(0.65, 0.65, 0.65, 1) + frame.middle:SetPoint("Left", frame.left, "Right") + frame.middle:SetPoint("Right", frame.right, "Left") + frame.middle:SetSize(10, 19) + + frame.arrow = frame:CreateTexture(nil, "Overlay") + frame.arrow:SetTexture([[Interface\Minimap\MiniMap-PositionArrows]]) + frame.arrow:SetTexCoord(0, 1, 0, 0.5) + frame.arrow:SetSize(16, 16) + frame.arrow:SetPoint("TopRight", -6, -3) + frame.arrow:Hide() + + frame:SetScript("OnClick", function(self, button) + local old, dir = Table:GetSortedColumn() + Table:SetSortedColumn(self:GetID(), (old == self:GetID() and not dir)) + + for i = 1, #Table.frame.columns do + local frame = Table.frame.columns[i][1] + if frame:GetID() ~= Table.frame.sortedheader then + frame.arrow:Hide() + Table.frame.columns[i][1].text:SetFontObject(GameFontHighlightSmall) + else + frame.arrow:Show() + frame.text:SetFontObject(GameFontNormalSmall) + if Table.frame.descending then + frame.arrow:SetTexCoord(0, 1, 0.5, 1) + else + frame.arrow:SetTexCoord(0, 1, 0, 0.5) + end + end + end + + PlaySound(1115) + end) + + frame:SetScript("OnMouseUp", function(frame, button) + if button == "RightButton" then + frame:SetWidth(self.frame.columns[frame:GetID()][3] * self.frame:GetWidth()) + + self.frame.columns[frame:GetID()][6] = self.frame.columns[frame:GetID()][3] + + PlaySound(1115) + end + end) + + self.frame.lastcolumn = frame + + return frame +end + +function Table:AddRow(...) + assert(select("#", ...) == #self.frame.columns, "Number of arguments does not match number of columns.") + + if not self.frame.rowframes then + self.frame.rowframes = { } + + self:CreateRow(self.frame.scrolling, ...) + end + + --tinsert(self.frame.rows, {#self.frame.rows + 1, ...}) + + --self.frame.rows[#self.frame.rows + 1] = { } + self.frame.sorted[#self.frame.sorted + 1] = { } + for i = 1, (select("#", ...)) do + local text = (select(i, ...)) + --self.frame.rows[#self.frame.rows][i] = { } + --self.frame.rows[#self.frame.rows][i].text = text + self.frame.sorted[#self.frame.sorted][i] = { } + self.frame.sorted[#self.frame.sorted][i].text = text + end + + --self:ApplyFilter() + + --[[self.frame.filtered[#self.frame.filtered + 1] = { } + for i = 1, (select("#", ...)) do + local text = (select(i, ...)) + if i == 1 and string.find(text, self.frame.filter) then + --self.frame.rows[#self.frame.rows][i] = { } + --self.frame.rows[#self.frame.rows][i].text = text + self.frame.filtered[#self.frame.filtered][i] = { } + self.frame.filtered[#self.frame.filtered][i].text = text + else + break + end + end]] + + --[=[self.frame.scrolling:SetSize(800, #self.frame.filtered * 22) + + if (#self.frame.filtered * 22) > (self.frame:GetHeight() - 22) then + if (#self.frame.filtered - 19) < 0 then + self.frame.scrollbar:SetMinMaxValues(0, ((#self.frame.filtered) * 22)--[[ + (22 * 3)]]) + else + self.frame.scrollbar:SetMinMaxValues(0, ((#self.frame.filtered - 19) * 22)--[[ + (22 * 3)]]) + end + + --self.frame.scrollbar:SetMinMaxValues(0, ((#self.frame.filtered - 19) * 22)--[[ + (22 * 3)]]) + self.frame.scrollbar.ScrollDownButton:Enable() + self.frame.scrollbar:Show() + else + self.frame.scrollbar:SetMinMaxValues(0, 0) + self.frame.scrollbar.ScrollDownButton:Disable() + self.frame.scrollbar:Hide() + end]=] + + --[[for i = 1, #self.frame.rows do + for j = 1, #self.frame.rows[i] do + if i % 2 == 0 then + self.frame.rows[i][j].bg:SetColorTexture(0.5, 0.5, 0.5) + else + self.frame.rows[i][j].bg:SetColorTexture(0.9, 0.9, 1) + end + end + end]] + + return #self.frame.sorted +end + +-- Update everything +function Table:Update() + self:ApplyFilter() + + self:SortColumn() + + --self:UpdateItems() + + self:UpdateScrollBar() +end + +function Table:UpdateScrollBar() + local items + if self.frame.filter and self.frame.filter ~= "" then + items = self.frame.filtered + else + items = self.frame.sorted + end + + self.frame.scrolling:SetSize(800, #items * 22) + + if (#items * 22) > (self.frame:GetHeight() - 22) then + if (#items - 19) < 0 then + self.frame.scrollbar:SetMinMaxValues(0, ((#items) * 22)--[[ + (22 * 3)]]) + else + self.frame.scrollbar:SetMinMaxValues(0, ((#items - 19) * 22)--[[ + (22 * 3)]]) + end + + --self.frame.scrollbar:SetMinMaxValues(0, ((#items - 19) * 22)--[[ + (22 * 3)]]) + self.frame.scrollbar.ScrollDownButton:Enable() + self.frame.scrollbar:Show() + else + self.frame.scrollbar:SetMinMaxValues(0, 0) + self.frame.scrollbar.ScrollDownButton:Disable() + self.frame.scrollbar:Hide() + end +end + +function Table:SetFilter(filter) + self.frame.filter = filter + + self:Update() +end + +function Table:ApplyFilter() + if not self.frame.filter or self.frame.filter == "" then + return + end + + self.frame.filtered = { } + + for i = 1, #self.frame.sorted do + if string.find(self.frame.sorted[i][1].text, self.frame.filter) then + self.frame.filtered[#self.frame.filtered + 1] = { } + for j = 1, #self.frame.sorted[i] do + self.frame.filtered[#self.frame.filtered][j] = self.frame.sorted[i][j] + end + end + end + + return #self.frame.filtered +end + +function Table:UpdateRow(...) + local name = ... + + -- Only update visible rows + --[[local startline = (self.frame.scrollbar:GetValue() / 22) + 1 + local endline = startline + 18 + + if endline > #self.frame.rows then + endline = #self.frame.rows + end]] + + --[=[for j = 1, #self.frame.rows[self.frame.rowstext[name]] do + local text = (select(j, ...)) + if self.frame.rows[self.frame.rowstext[name]][j].text ~= text then + self.frame.rows[self.frame.rowstext[name]][j].text = text + end + end]=] + + local items + if self.frame.filter and self.frame.filter ~= "" then + items = self.frame.filtered + else + items = self.frame.sorted + end + + for i = 1, #items do + if items[i][1].text == name then + for j = 2, #items[i] do + local text = (select(j, ...)) + if items[i][j].text ~= text then + items[i][j].text = text + end + end + break + end + end +end + +function Table:CreateRow(parent, ...) + local rows = (select("#", ...)) + for i = 1, 32 do + self.frame.rowframes[i] = { } + for j = 1, rows do + self.frame.rowframes[i][j] = CreateFrame("Frame", nil, parent) + self.frame.rowframes[i][j]:SetHeight(22) + --self.frame.rowframes[i][j]:SetSize(self.frame.columns[j][1]:GetWidth() - 1, 22) + + if self.frame.newrow then + self.frame.rowframes[i][j]:SetPoint("TopLeft", self.frame.rowframes[i - 1][j], "BottomLeft", 0, 0) + self.frame.rowframes[i][j]:SetPoint("TopRight", self.frame.rowframes[i - 1][j], "BottomRight", 0, 0) + self.frame.newrow = nil + elseif self.frame.lastrow then + if i == 1 then + self.frame.rowframes[i][j]:SetPoint("TopLeft", self.frame.lastrow, "TopRight", -1, 0) + if j == rows then + self.frame.rowframes[i][j]:SetPoint("TopRight", self.frame.columns[j][1], "BottomRight", -1, 0) + else + self.frame.rowframes[i][j]:SetPoint("TopRight", self.frame.columns[j][1], "BottomRight", 0, 0) + end + else + self.frame.rowframes[i][j]:SetPoint("TopLeft", self.frame.rowframes[i - 1][j], "BottomLeft", 0, 0) + self.frame.rowframes[i][j]:SetPoint("TopRight", self.frame.rowframes[i - 1][j], "BottomRight", 0, 0) + end + else + self.frame.rowframes[i][j]:SetPoint("TopLeft", self.frame.columns[j][1], "BottomLeft", 2, 5) + self.frame.rowframes[i][j]:SetPoint("TopRight", self.frame.columns[j][1], "BottomRight", 0, 0) + end + + self.frame.lastrow = self.frame.rowframes[i][j] + + if j == rows then + self.frame.newrow = true + end + + self.frame.rowframes[i][j].text = self.frame.rowframes[i][j]:CreateFontString(nil, "Overlay") + self.frame.rowframes[i][j].text:SetPoint("TopLeft", self.frame.rowframes[i][j], "TopLeft", 4.5, -4.5) + self.frame.rowframes[i][j].text:SetPoint("BottomRight", self.frame.rowframes[i][j], "BottomRight", -4, 4) + self.frame.rowframes[i][j].text:SetFontObject(GameFontHighlightSmall) + self.frame.rowframes[i][j].text:SetJustifyH("Left") + self.frame.rowframes[i][j].text:SetHeight(24) + self.frame.rowframes[i][j].text:SetWordWrap(false) + self.frame.rowframes[i][j].text:SetText(self.frame.rowframes[i][j].text) + + self.frame.rowframes[i][j].bg = self.frame.rowframes[i][j]:CreateTexture(nil, "Background") + self.frame.rowframes[i][j].bg:SetAllPoints(self.frame.rowframes[i][j]) + if i % 2 == 0 then + self.frame.rowframes[i][j].bg:SetColorTexture(0.4, 0.4, 0.4) + else + self.frame.rowframes[i][j].bg:SetColorTexture(0.9, 0.9, 1) + end + self.frame.rowframes[i][j].bg:SetAlpha(0.1) + + self.frame.rowframes[i][j]:SetScript("OnEnter", function(self) + self.bg:SetAlpha(0.3) + end) + self.frame.rowframes[i][j]:SetScript("OnLeave", function(self) + self.bg:SetAlpha(0.1) + end) + end + end +end + +function Table:UpdateItems() + --[[self.frame.scrolling:SetSize(800, #self.frame.rows * 22) + + if (#self.frame.rows * 22) > (self.frame:GetHeight() - 22) then + self.frame.scrollbar:SetMinMaxValues(0, ((#self.frame.rows - 19) * 22) + (22 * 3)) + self.frame.scrollbar.ScrollDownButton:Enable() + self.frame.scrollbar:Show() + else + self.frame.scrollbar:SetMinMaxValues(0, 0) + self.frame.scrollbar.ScrollDownButton:Disable() + self.frame.scrollbar:Hide() + end]] + + --[[local x = 0 + if self.frame.scrollbar:IsShown() then + x = 12 + + for i = 1, #self.frame.columns do + self.frame.columns[i][1]:SetSize(((self.frame:GetWidth() - x) * self.frame.columns[i][3]), 24) + --self.frame.columns[i][1]:SetID(i) + end + else + for i = 1, #self.frame.columns do + if i == #self.frame.columns then + self.frame.columns[i][1]:SetSize(math.round(((self.frame:GetWidth() - x) * self.frame.columns[i][3])) + 2, 24) + else + self.frame.columns[i][1]:SetSize(math.round(((self.frame:GetWidth() - x) * self.frame.columns[i][3])) + 1, 24) + end + --self.frame.columns[i][1]:SetID(i) + end + end]] + + --[[for i = 1, #self.frame.columns do + if i ~= 1 then + if self.frame.columns[i][1].last then + self.frame.columns[i][1]:SetPoint("TopLeft", self.frame.columns[i - 1][1], "TopRight", -2, 0) + self.frame.columns[i][1]:SetPoint("TopRight", self.frame, "TopRight", -2, 0) + else + self.frame.columns[i][1]:SetPoint("TopLeft", self.frame.columns[i - 1][1], "TopRight", -2, 0) + end + else + self.frame.columns[i][1]:SetPoint("TopLeft", self.frame, "TopLeft", 1, -2) + end + end]] + + if not self.frame.rowframes then + return + end + + local items + if self.frame.filter and self.frame.filter ~= "" then + items = self.frame.filtered + else + items = self.frame.sorted + end + + local k + if #self.frame.rowframes > #items then + k = #items + + if k < 32 then + k = 32 + end + else + k = #self.frame.rowframes + end + + local offset = (self.frame.scrollbar:GetValue() / self.frame.scrollbar:GetValueStep()) + + for i = 1, k do + for j = 1, #self.frame.rowframes[i] do + local format = self.frame.columns[j][4] + local frame = self.frame.rowframes[i][j] + + if type(format) == "string" then + if items[i + offset] then + frame:Show() + frame.text:SetText(format:format(items[i + offset][j].text)) + else + frame:Hide() + frame.text:SetText("") + end + else + if items[i + offset] then + frame:Show() + frame.text:SetText(tostring(items[i + offset][j].text)) + else + frame:Hide() + frame.text:SetText("") + end + end + end + end +end diff --git a/ElvUIDev/Widgets/Window.lua b/ElvUIDev/Widgets/Window.lua new file mode 100644 index 0000000..d13540a --- /dev/null +++ b/ElvUIDev/Widgets/Window.lua @@ -0,0 +1,133 @@ +local AddonName, Addon = ... + +local ElvUIDev = Addon.ElvUIDev + +local CreateFrame = CreateFrame +local PlaySound = PlaySound + +local UIParent = UIParent +local GameFontHighlight = GameFontHighlight + +local Window = ElvUIDev:RegisterWidget("Window") + +function Window:Create(name, parent) + local frame = CreateFrame("Frame", name, parent or UIParent, "BasicFrameTemplate") + frame:SetClampedToScreen(true) + + frame.Bg:SetTexture("Interface\\FrameGeneral\\UI-Background-Marble", true, true) + frame.Bg:SetHorizTile(true) + frame.Bg:SetVertTile(true) + frame.Bg:SetAlpha(1) + + frame.TitleBg:SetTexture("Interface\\HelpFrame\\DarkSandstone-Tile", true, false) + frame.TitleBg:SetHorizTile(true) + frame.TitleBg:SetVertTile(false) + + --[[frame.gradient = frame:CreateTexture(nil, "Background") + frame.gradient:SetTexture("Interface\\Tooltips\\UI-Tooltip-Background") + --frame.gradient:SetMask("Interface\\CharacterFrame\\Button_BloodPresence_DeathKnight") + frame.gradient:SetBlendMode("Add") + frame.gradient:SetGradientAlpha("Vertical", 1, 1, 1, 1, 0.1, 0.1, 0.1, 0) + --frame.gradient:SetPoint("TopLeft", frame, "TopLeft", 1, -1) + --frame.gradient:SetPoint("BottomRight", frame, "BottomRight", -1, 1) + frame.gradient:SetAllPoints(frame.Bg)]] + + frame.overlay = CreateFrame("Frame", nil, frame) + frame.overlay:SetPoint("TopLeft", 2, -76) + frame.overlay:SetPoint("BottomRight", -2, 2) + + frame.overlay.texture = frame:CreateTexture(nil, "Background") + frame.overlay.texture:SetDrawLayer("Background", 3) + frame.overlay.texture:SetAllPoints(frame.overlay) + frame.overlay.texture:SetTexture("Interface\\HelpFrame\\DarkSandstone-Tile", true, true) + frame.overlay.texture:SetDrawLayer("Background", 2) + frame.overlay.texture:SetHorizTile(true) + frame.overlay.texture:SetVertTile(true) + + frame.line = frame.overlay:CreateTexture(nil, "Border") + frame.line:SetDrawLayer("Background", 5) + frame.line:SetTexture("Interface\\LevelUp\\LevelUpTex") + frame.line:SetTexCoord(0.00195313, 0.81835938, 0.035, 0.018625) + --frame.line:SetTexCoord(0, 0.8203125, 0.03125, 0.03515625) -- SetHeight(2) + frame.line:SetPoint("TopLeft", 0, 0) + frame.line:SetPoint("TopRight", 0, 0) + frame.line:SetHeight(7) + + frame.shadow = { } + + frame.shadow.upper = CreateFrame("Frame", nil, frame) + frame.shadow.upper:SetHeight(43) + frame.shadow.upper:SetPoint("TopLeft", 0, -21) + frame.shadow.upper:SetPoint("TopRight", -2, -21) + frame.shadow.upper:SetFrameLevel(1) + frame.shadow.upper:Hide() + + frame.shadow.upper.texture = frame.shadow.upper:CreateTexture(nil, "Background") + frame.shadow.upper.texture:SetDrawLayer("Background", 4) + frame.shadow.upper.texture:SetTexture("Interface\\Common\\bluemenu-goldborder-horiz", true, true) + frame.shadow.upper.texture:SetTexCoord(0, 1, 0.015625, 0.3515625) + frame.shadow.upper.texture:SetHorizTile(true) + frame.shadow.upper.texture:SetHeight(43) + frame.shadow.upper.texture:SetAllPoints(frame.shadow.upper) + + frame.shadow.top = frame.overlay:CreateTexture(nil, "Background") + frame.shadow.top:SetDrawLayer("Background", 4) + frame.shadow.top:SetTexture("Interface\\Common\\bluemenu-goldborder-horiz", true, true) + frame.shadow.top:SetTexCoord(0, 1, 0.015625, 0.3515625) + frame.shadow.top:SetHorizTile(true) + frame.shadow.top:SetHeight(43) + frame.shadow.top:SetPoint("TopLeft", 0, 0) + frame.shadow.top:SetPoint("TopRight", -2, 0) + + frame.shadow.bottom = frame.overlay:CreateTexture(nil, "Background") + frame.shadow.bottom:SetDrawLayer("Background", 4) + frame.shadow.bottom:SetTexture("Interface\\Common\\bluemenu-goldborder-horiz", true, true) + frame.shadow.bottom:SetTexCoord(0, 1, 0.3515625, 0.6875) + frame.shadow.bottom:SetHorizTile(true) + frame.shadow.bottom:SetHeight(43) + frame.shadow.bottom:SetPoint("BottomLeft", 0, 0) + frame.shadow.bottom:SetPoint("BottomRight", 0, 0) + + frame.title = frame:CreateFontString(nil, "Overlay") + frame.title:SetPoint("Top", 0, 1.5) + frame.title:SetHeight(24) + frame.title:SetFontObject(GameFontHighlight) + frame.title:SetTextColor(1, 0.82, 0) + frame.title:SetShadowOffset(1, -1) + frame.title:SetJustifyH("Center") + frame.title:SetJustifyV("Middle") + frame.title:SetText("") + + --[[if collapse then + frame.collapse = CreateFrame("Button", nil, frame) + frame.collapse:SetHitRectInsets(7, 7, 7, 7) + frame.collapse:SetPoint("Right", frame.CloseButton, "Left", 10, 0) + frame.collapse:SetWidth(32) + frame.collapse:SetHeight(32) + frame.collapse:SetNormalTexture("Interface\\Buttons\\UI-Panel-CollapseButton-Up") + frame.collapse:SetPushedTexture("Interface\\Buttons\\UI-Panel-CollapseButton-Down") + frame.collapse:SetHighlightTexture("Interface\\Buttons\\UI-Panel-MinimizeButton-Highlight", "Add") + end]] + + frame.CloseButton:SetHitRectInsets(6, 6, 6, 6) + + frame:SetScript("OnMouseDown", function(self, button) + if button == "LeftButton" then + self:StartMoving() + end + end) + frame:SetScript("OnMouseUp", function(self, button) + if button == "LeftButton" then + self:StopMovingOrSizing() + end + end) + + frame:SetScript("OnShow", function(self, button) + PlaySound(841) + end) + frame:SetScript("OnHide", function(self, button) + PlaySound(851) + end) + + return frame +end