core: switch from mousedown to drag functions

Due to crashes/freezes while moving some frames, one possible
reason could be that pfUI was using OnMouseDown and OnMouseUp
to run its frame-moving code. I have noticed better performance
when using the intended functions, OnDragStart and OnDragStop
to move frames.

This commit changes every occurrence of such functions and splits
drag and click into seperate functions where required.
This commit is contained in:
shagu
2022-05-07 21:35:52 +02:00
parent c72c61c133
commit 0214eebf36
10 changed files with 59 additions and 47 deletions
+8 -6
View File
@@ -526,8 +526,8 @@ end
-- 'name' [frame/string] Name of the Frame that should be movable
-- 'addon' [string] Addon that must be loaded before being able to access the frame
-- 'blacklist' [table] A list of frames that should be deactivated for mouse usage
local function MoveMouseDown() this:StartMoving() end
local function MoveMouseUp() this:StopMovingOrSizing() end
local function OnDragStart() this:StartMoving() end
local function OnDragStop() this:StopMovingOrSizing() end
function pfUI.api.EnableMovable(name, addon, blacklist)
if addon then
local scan = CreateFrame("Frame")
@@ -544,8 +544,9 @@ function pfUI.api.EnableMovable(name, addon, blacklist)
frame:SetMovable(true)
frame:EnableMouse(true)
frame:SetScript("OnMouseDown", MoveMouseDown)
frame:SetScript("OnMouseUp", MoveMouseUp)
frame:RegisterForDrag("LeftButton")
frame:SetScript("OnDragStart", OnDragStart)
frame:SetScript("OnDragStop", OnDragStop)
this:UnregisterAllEvents()
end
@@ -561,8 +562,9 @@ function pfUI.api.EnableMovable(name, addon, blacklist)
if type(name) == "string" then frame = _G[name] end
frame:SetMovable(true)
frame:EnableMouse(true)
frame:SetScript("OnMouseDown", MoveMouseDown)
frame:SetScript("OnMouseUp", MoveMouseUp)
frame:RegisterForDrag("LeftButton")
frame:SetScript("OnDragStart", OnDragStart)
frame:SetScript("OnDragStop", OnDragStop)
end
end
+3 -2
View File
@@ -1042,11 +1042,12 @@ function pfUI.api.CreateQuestionDialog(text, yes, no, editbox, onclose)
question:SetFrameStrata("TOOLTIP")
question:SetMovable(true)
question:EnableMouse(true)
question:SetScript("OnMouseDown",function()
question:RegisterForDrag("LeftButton")
question:SetScript("OnDragStart",function()
this:StartMoving()
end)
question:SetScript("OnMouseUp",function()
question:SetScript("OnDragStop",function()
this:StopMovingOrSizing()
end)
+3 -2
View File
@@ -24,8 +24,9 @@ pfUI:RegisterModule("addons", "vanilla:tbc", function ()
pfUI.addons:EnableMouseWheel(1)
pfUI.addons:SetMovable(true)
pfUI.addons:EnableMouse(true)
pfUI.addons:SetScript("OnMouseDown", function() this:StartMoving() end)
pfUI.addons:SetScript("OnMouseUp", function() this:StopMovingOrSizing() end)
pfUI.addons:RegisterForDrag("LeftButton")
pfUI.addons:SetScript("OnDragStart", function() this:StartMoving() end)
pfUI.addons:SetScript("OnDragStop", function() this:StopMovingOrSizing() end)
pfUI.addons:Hide()
CreateBackdrop(pfUI.addons, nil, true, .75)
+4 -1
View File
@@ -225,7 +225,10 @@ pfUI:RegisterModule("bags", "vanilla:tbc", function ()
frame:EnableMouse(1)
frame:SetMovable(1)
frame:RegisterForDrag("LeftButton")
frame:SetScript("OnDragStart", function() this:StartMoving() end)
frame:SetScript("OnDragStart", function()
this:StartMoving()
end)
frame:SetScript("OnDragStop", function()
this:StopMovingOrSizing()
SaveMovable(this)
+3 -2
View File
@@ -175,11 +175,12 @@ pfUI:RegisterModule("chat", "vanilla:tbc", function ()
pfUI.chat.urlcopy:SetMovable(true)
pfUI.chat.urlcopy:EnableMouse(true)
pfUI.chat.urlcopy:SetScript("OnMouseDown",function()
pfUI.chat.urlcopy:RegisterForDrag("LeftButton")
pfUI.chat.urlcopy:SetScript("OnDragStart",function()
this:StartMoving()
end)
pfUI.chat.urlcopy:SetScript("OnMouseUp",function()
pfUI.chat.urlcopy:SetScript("OnDragStop",function()
this:StopMovingOrSizing()
end)
+3 -2
View File
@@ -55,13 +55,14 @@ pfUI:RegisterModule("firstrun", "vanilla:tbc", function ()
f:SetFrameStrata("TOOLTIP")
f:SetMovable(true)
f:EnableMouse(true)
f:RegisterForDrag("LeftButton")
f:SetWidth(380)
f:SetHeight(180)
f:SetScript("OnMouseDown",function()
f:SetScript("OnDragStart",function()
this:StartMoving()
end)
f:SetScript("OnMouseUp",function()
f:SetScript("OnDragStop",function()
this:StopMovingOrSizing()
end)
+3 -2
View File
@@ -543,6 +543,7 @@ pfUI:RegisterModule("gui", "vanilla:tbc", function ()
pfUI.gui = CreateFrame("Frame", "pfConfigGUI", UIParent)
pfUI.gui:SetMovable(true)
pfUI.gui:EnableMouse(true)
pfUI.gui:RegisterForDrag("LeftButton")
pfUI.gui:SetWidth(720)
pfUI.gui:SetHeight(480)
pfUI.gui:SetFrameStrata("DIALOG")
@@ -575,11 +576,11 @@ pfUI:RegisterModule("gui", "vanilla:tbc", function ()
pfUI.gui:Hide()
end)
pfUI.gui:SetScript("OnMouseDown",function()
pfUI.gui:SetScript("OnDragStart",function()
this:StartMoving()
end)
pfUI.gui:SetScript("OnMouseUp",function()
pfUI.gui:SetScript("OnDragStop",function()
this:StopMovingOrSizing()
end)
+6 -5
View File
@@ -39,6 +39,10 @@ pfUI:RegisterModule("map", "vanilla:tbc", function ()
UIPanelWindows["WorldMapFrame"] = { area = "center" }
WorldMapFrame:SetMovable(true)
WorldMapFrame:EnableMouse(true)
WorldMapFrame:RegisterForDrag("LeftButton")
WorldMapFrame:SetScript("OnShow", function()
-- default events
UpdateMicroButtons()
@@ -67,18 +71,15 @@ pfUI:RegisterModule("map", "vanilla:tbc", function ()
SaveMovable(this, true)
end)
WorldMapFrame:SetScript("OnMouseDown",function()
WorldMapFrame:SetScript("OnDragStart",function()
WorldMapFrame:StartMoving()
end)
WorldMapFrame:SetScript("OnMouseUp",function()
WorldMapFrame:SetScript("OnDragStop",function()
WorldMapFrame:StopMovingOrSizing()
SaveMovable(this, true)
end)
WorldMapFrame:SetMovable(true)
WorldMapFrame:EnableMouse(true)
WorldMapFrame:SetAlpha(alpha)
WorldMapFrame:SetScale(scale)
UpdateTooltipScale()
+3 -2
View File
@@ -253,8 +253,9 @@ pfUI:RegisterModule("share", "vanilla:tbc", function ()
f:SetHeight(420)
f:SetMovable(true)
f:EnableMouse(true)
f:SetScript("OnMouseDown", function() f:StartMoving() end)
f:SetScript("OnMouseUp", function() f:StopMovingOrSizing() end)
f:RegisterForDrag("LeftButton")
f:SetScript("OnDragStart", function() f:StartMoving() end)
f:SetScript("OnDragStop", function() f:StopMovingOrSizing() end)
f:SetScript("OnShow", function()
if pfUI.gui and pfUI.gui:IsShown() then
+23 -23
View File
@@ -322,16 +322,7 @@ pfUI:RegisterModule("unlock", "vanilla:tbc", function ()
QueueFunction(UpdateDockValues)
end
local function DraggerOnMouseDown()
if arg1 == "MiddleButton" then return end
if arg1 == "RightButton" then
if pfUI.unlock.dock.parent == this and pfUI.unlock.dock:IsShown() then
SetDockToFrame(nil)
else
SetDockToFrame(this)
end
return
end
local function DraggerOnDragStart()
local frame = this.frame
pfUI.unlock.selection = GetFrames()
@@ -349,10 +340,7 @@ pfUI:RegisterModule("unlock", "vanilla:tbc", function ()
if frame.OnMove then frame:OnMove() end
end
local function DraggerOnMouseUp()
if arg1 == "MiddleButton" then return end
if arg1 == "RightButton" then return end
local function DraggerOnDragStop()
local frame = this.frame
local name = this.fname
@@ -410,14 +398,25 @@ pfUI:RegisterModule("unlock", "vanilla:tbc", function ()
end
local function DraggerOnClick()
pfUI.unlock.selection = GetFrames()
for id, frame in pairs(pfUI.unlock.selection) do
pfUI_config["position"][frame:GetName()] = nil
UpdateMovable(frame)
if arg1 == "RightButton" then
-- add dockframe to the dragger to show advanced options
if pfUI.unlock.dock.parent == this and pfUI.unlock.dock:IsShown() then
SetDockToFrame(nil)
else
SetDockToFrame(this)
end
return
elseif arg1 == "MiddleButton" then
-- reset positions of dragger and all connected frames
pfUI.unlock.selection = GetFrames()
for id, frame in pairs(pfUI.unlock.selection) do
pfUI_config["position"][frame:GetName()] = nil
UpdateMovable(frame)
if frame.OnMove then frame:OnMove() end
if frame.OnMove then frame:OnMove() end
end
UpdateDockValues()
end
UpdateDockValues()
end
local function DraggerOnEnter()
@@ -437,7 +436,8 @@ pfUI:RegisterModule("unlock", "vanilla:tbc", function ()
local label = string.sub(fname, 1, 2) == "pf" and strsub(fname,3) or fname
local d = CreateFrame("Button", fname .. "Drag", f)
d:RegisterForClicks("MiddleButtonUp")
d:RegisterForClicks("MiddleButtonUp", "RightButtonUp")
d:RegisterForDrag("LeftButton")
d:SetAllPoints(f)
d:SetFrameStrata("DIALOG")
d:SetAlpha(1)
@@ -461,8 +461,8 @@ pfUI:RegisterModule("unlock", "vanilla:tbc", function ()
d.text:SetText(label)
d:SetScript("OnMouseWheel", DraggerOnMouseWheel)
d:SetScript("OnMouseDown", DraggerOnMouseDown)
d:SetScript("OnMouseUp", DraggerOnMouseUp)
d:SetScript("OnDragStart", DraggerOnDragStart)
d:SetScript("OnDragStop", DraggerOnDragStop)
d:SetScript("OnClick", DraggerOnClick)
d:SetScript("OnEnter", DraggerOnEnter)
d:SetScript("OnLeave", DraggerOnLeave)