From 748693115ecc7619b277a589f79a61bf5f563259 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20B=C3=BCchner?= Date: Fri, 12 May 2023 19:18:10 +0200 Subject: [PATCH] chore: begin migration to new `ScrollFrame` API - TODO: `IconBrowser` migration --- .vscode/settings.json | 21 ++- MegaMacro.toc | 7 +- src/windows/mega-macro.input-scrollframe.lua | 164 ++++++++++++++++ src/windows/mega-macro.input-scrollframe.xml | 32 ++++ src/windows/mega-macro.scrollframe.xml | 22 +++ src/windows/mega-macro.window.lua | 52 +++++- src/windows/mega-macro.window.xml | 187 ++++++++----------- 7 files changed, 365 insertions(+), 120 deletions(-) create mode 100644 src/windows/mega-macro.input-scrollframe.lua create mode 100644 src/windows/mega-macro.input-scrollframe.xml create mode 100644 src/windows/mega-macro.scrollframe.xml diff --git a/.vscode/settings.json b/.vscode/settings.json index bd7e616..982794c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -231,6 +231,25 @@ "WorldFrame", "class", "QueryCastSequence", - "message" + "message", + "hooksecurefunc", + "tremove", + "SetMacroSpell", + "GetMacroItem", + "SetMacroItem", + "GetLooseMacroIcons", + "GetLooseMacroItemIcons", + "GetMacroIcons", + "GetMacroItemIcons", + "GetNumSpellTabs", + "GetSpellTabInfo", + "GetSpellBookItemInfo", + "GetSpellBookItemTexture", + "GetFlyoutInfo", + "GetFlyoutSlotInfo", + "UnitName", + "ceil", + "GetSpellBookItemName", + "IsPassiveSpell" ] } diff --git a/MegaMacro.toc b/MegaMacro.toc index f39e017..6beb3bb 100644 --- a/MegaMacro.toc +++ b/MegaMacro.toc @@ -1,7 +1,7 @@ -## Interface: 100007 +## Interface: 100100 ## Title: Mega Macro ## Author: Sellorio -## Version: 1.1.1 +## Version: 1.2.1 ## OptionalDeps: ElvUI ## SavedVariables: MegaMacroConfig, MegaMacroGlobalData @@ -27,4 +27,7 @@ src/engine/parsing/conditions.lua src/engine/mega-macro-parser.lua src/main.xml +src/windows/mega-macro.input-scrollframe.lua +src/windows/mega-macro.input-scrollframe.xml +src/windows/mega-macro.scrollframe.xml src/windows/mega-macro.window.xml diff --git a/src/windows/mega-macro.input-scrollframe.lua b/src/windows/mega-macro.input-scrollframe.lua new file mode 100644 index 0000000..8a805bc --- /dev/null +++ b/src/windows/mega-macro.input-scrollframe.lua @@ -0,0 +1,164 @@ +function MegaMacro_EditBox_OnTabPressed(self) + if (self.previousEditBox and IsShiftKeyDown()) then + self.previousEditBox:SetFocus(); + elseif (self.nextEditBox) then + self.nextEditBox:SetFocus(); + end +end + +function MegaMacro_EditBox_ClearFocus(self) + self:ClearFocus(); +end + +function MegaMacro_EditBox_HighlightText(self) + self:HighlightText(); +end + +function MegaMacro_EditBox_ClearHighlight(self) + self:HighlightText(0, 0); +end + +function MegaMacro_ScrollFrame_OnLoad(self) + if not self.noScrollBar then + local scrollBarTemplate = self.scrollBarTemplate or SCROLL_FRAME_SCROLL_BAR_TEMPLATE; + if not scrollBarTemplate then + error("SCROLL_FRAME_SCROLL_BAR_TEMPLATE undefined. Check ScrollDefine.lua") + end + + local left = self.scrollBarX or SCROLL_FRAME_SCROLL_BAR_OFFSET_LEFT; + if not left then + error("SCROLL_FRAME_SCROLL_BAR_OFFSET_LEFT undefined. Check ScrollDefine.lua") + end + + local top = self.scrollBarTopY or SCROLL_FRAME_SCROLL_BAR_OFFSET_TOP; + if not top then + error("SCROLL_FRAME_SCROLL_BAR_OFFSET_TOP undefined. Check ScrollDefine.lua") + end + + local bottom = self.scrollBarBottomY or SCROLL_FRAME_SCROLL_BAR_OFFSET_BOTTOM; + if not bottom then + error("SCROLL_FRAME_SCROLL_BAR_OFFSET_BOTTOM undefined. Check ScrollDefine.lua") + end + + self.ScrollBar = CreateFrame("EventFrame", nil, self, scrollBarTemplate); + self.ScrollBar:SetHideIfUnscrollable(self.scrollBarHideIfUnscrollable); + self.ScrollBar:SetHideTrackIfThumbExceedsTrack(self.scrollBarHideTrackIfThumbExceedsTrack); + self.ScrollBar:SetPoint("TOPLEFT", self, "TOPRIGHT", left, top); + self.ScrollBar:SetPoint("BOTTOMLEFT", self, "BOTTOMRIGHT", left, bottom); + self.ScrollBar:Show(); + + ScrollUtil.InitScrollFrameWithScrollBar(self, self.ScrollBar); + + self.ScrollBar:Update(); + end +end + +function MegaMacro_ScrollingEdit_OnTextChanged(self, scrollFrame) + -- force an update when the text changes + self.handleCursorChange = true; + MegaMacro_ScrollingEdit_OnUpdate(self, 0, scrollFrame); +end + +function MegaMacro_ScrollingEdit_OnLoad(self) + MegaMacro_ScrollingEdit_SetCursorOffsets(self, 0, 0); +end + +function MegaMacro_ScrollingEdit_SetCursorOffsets(self, offset, height) + self.cursorOffset = offset; + self.cursorHeight = height; +end + +function MegaMacro_ScrollingEdit_OnCursorChanged(self, x, y, w, h) + MegaMacro_ScrollingEdit_SetCursorOffsets(self, y, h); + self.handleCursorChange = true; +end + +-- NOTE: If your edit box never shows partial lines of text, then this function will not work when you use +-- your mouse to move the edit cursor. You need the edit box to cut lines of text so that you can use your +-- mouse to highlight those partially-seen lines; otherwise you won't be able to use the mouse to move the +-- cursor above or below the current scroll area of the edit box. +function MegaMacro_ScrollingEdit_OnUpdate(self, elapsed, scrollFrame) + if (not scrollFrame) then + scrollFrame = self:GetParent(); + end + + local hasScrollableExtent = scrollFrame.ScrollBar:HasScrollableExtent(); + if (not hasScrollableExtent) then + -- Return if the scroll frame has no scroll bar or if the scroll bar has no scrollable extent. + return; + end + + local formattedScrollFrame = _G["MegaMacro_FormattedFrameScrollFrame"]; + if not formattedScrollFrame then + error("MegaMacro_FormattedFrameScrollFrame undefined. Check ScrollDefine.lua") + end + + local scroll = scrollFrame:GetVerticalScroll(); + local formattedScroll = formattedScrollFrame:GetVerticalScroll(); + + if (scroll ~= formattedScroll) then + formattedScrollFrame:SetVerticalScroll(scroll); + end + + if (self.handleCursorChange) then + local height, range, size, cursorOffset; + + height = scrollFrame:GetHeight(); + range = scrollFrame:GetVerticalScrollRange(); + size = height + range; + cursorOffset = -self.cursorOffset; + + if (math.floor(height) <= 0 or math.floor(range) <= 0) then + --Frame has no area, nothing to calculate. + return; + end + + while (cursorOffset < scroll) do + scroll = (scroll - (height / 2)); + if (scroll < 0) then + scroll = 0; + end + scrollFrame:SetVerticalScroll(scroll); + formattedScrollFrame:SetVerticalScroll(scroll); + end + + -- If the cursor is below the scroll area, scroll down until it's at the bottom of the scroll area. + while ((cursorOffset + self.cursorHeight) > (scroll + height) and scroll < range) do + scroll = (scroll + (height / 2)); + -- Don't scroll past the end of the text + if (scroll > range) then + scroll = range; + end + scrollFrame:SetVerticalScroll(scroll); + formattedScrollFrame:SetVerticalScroll(scroll); + end + + self.handleCursorChange = false; + end +end + +function MegaMacro_InputScrollFrame_OnLoad(self) + -- self.scrollBarX = -10; + -- self.scrollBarTopY = -1; + -- self.scrollBarBottomY = -3; + -- self.scrollBarHideIfUnscrollable = true; + + MegaMacro_ScrollFrame_OnLoad(self); + + self.EditBox:SetWidth(self:GetWidth() - 18); + self.EditBox:SetMaxLetters(self.maxLetters); +end + +function MegaMacro_InputScrollFrame_OnMouseDown(self) + self.EditBox:SetFocus(); +end + +MegaMacro_InputScrollFrame_OnTabPressed = MegaMacro_EditBox_OnTabPressed; + +function MegaMacro_InputScrollFrame_OnUpdate(self, elapsed) + MegaMacro_ScrollingEdit_OnUpdate(self, elapsed, self:GetParent()); +end + +function MegaMacro_InputScrollFrame_OnEscapePressed(self) + self:ClearFocus(); +end diff --git a/src/windows/mega-macro.input-scrollframe.xml b/src/windows/mega-macro.input-scrollframe.xml new file mode 100644 index 0000000..93a23a1 --- /dev/null +++ b/src/windows/mega-macro.input-scrollframe.xml @@ -0,0 +1,32 @@ + +