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 -- '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 -- '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 -- 'blacklist' [table] A list of frames that should be deactivated for mouse usage
local function MoveMouseDown() this:StartMoving() end local function OnDragStart() this:StartMoving() end
local function MoveMouseUp() this:StopMovingOrSizing() end local function OnDragStop() this:StopMovingOrSizing() end
function pfUI.api.EnableMovable(name, addon, blacklist) function pfUI.api.EnableMovable(name, addon, blacklist)
if addon then if addon then
local scan = CreateFrame("Frame") local scan = CreateFrame("Frame")
@@ -544,8 +544,9 @@ function pfUI.api.EnableMovable(name, addon, blacklist)
frame:SetMovable(true) frame:SetMovable(true)
frame:EnableMouse(true) frame:EnableMouse(true)
frame:SetScript("OnMouseDown", MoveMouseDown) frame:RegisterForDrag("LeftButton")
frame:SetScript("OnMouseUp", MoveMouseUp) frame:SetScript("OnDragStart", OnDragStart)
frame:SetScript("OnDragStop", OnDragStop)
this:UnregisterAllEvents() this:UnregisterAllEvents()
end end
@@ -561,8 +562,9 @@ function pfUI.api.EnableMovable(name, addon, blacklist)
if type(name) == "string" then frame = _G[name] end if type(name) == "string" then frame = _G[name] end
frame:SetMovable(true) frame:SetMovable(true)
frame:EnableMouse(true) frame:EnableMouse(true)
frame:SetScript("OnMouseDown", MoveMouseDown) frame:RegisterForDrag("LeftButton")
frame:SetScript("OnMouseUp", MoveMouseUp) frame:SetScript("OnDragStart", OnDragStart)
frame:SetScript("OnDragStop", OnDragStop)
end end
end end
+3 -2
View File
@@ -1042,11 +1042,12 @@ function pfUI.api.CreateQuestionDialog(text, yes, no, editbox, onclose)
question:SetFrameStrata("TOOLTIP") question:SetFrameStrata("TOOLTIP")
question:SetMovable(true) question:SetMovable(true)
question:EnableMouse(true) question:EnableMouse(true)
question:SetScript("OnMouseDown",function() question:RegisterForDrag("LeftButton")
question:SetScript("OnDragStart",function()
this:StartMoving() this:StartMoving()
end) end)
question:SetScript("OnMouseUp",function() question:SetScript("OnDragStop",function()
this:StopMovingOrSizing() this:StopMovingOrSizing()
end) end)
+3 -2
View File
@@ -24,8 +24,9 @@ pfUI:RegisterModule("addons", "vanilla:tbc", function ()
pfUI.addons:EnableMouseWheel(1) pfUI.addons:EnableMouseWheel(1)
pfUI.addons:SetMovable(true) pfUI.addons:SetMovable(true)
pfUI.addons:EnableMouse(true) pfUI.addons:EnableMouse(true)
pfUI.addons:SetScript("OnMouseDown", function() this:StartMoving() end) pfUI.addons:RegisterForDrag("LeftButton")
pfUI.addons:SetScript("OnMouseUp", function() this:StopMovingOrSizing() end) pfUI.addons:SetScript("OnDragStart", function() this:StartMoving() end)
pfUI.addons:SetScript("OnDragStop", function() this:StopMovingOrSizing() end)
pfUI.addons:Hide() pfUI.addons:Hide()
CreateBackdrop(pfUI.addons, nil, true, .75) CreateBackdrop(pfUI.addons, nil, true, .75)
+4 -1
View File
@@ -225,7 +225,10 @@ pfUI:RegisterModule("bags", "vanilla:tbc", function ()
frame:EnableMouse(1) frame:EnableMouse(1)
frame:SetMovable(1) frame:SetMovable(1)
frame:RegisterForDrag("LeftButton") frame:RegisterForDrag("LeftButton")
frame:SetScript("OnDragStart", function() this:StartMoving() end) frame:SetScript("OnDragStart", function()
this:StartMoving()
end)
frame:SetScript("OnDragStop", function() frame:SetScript("OnDragStop", function()
this:StopMovingOrSizing() this:StopMovingOrSizing()
SaveMovable(this) SaveMovable(this)
+3 -2
View File
@@ -175,11 +175,12 @@ pfUI:RegisterModule("chat", "vanilla:tbc", function ()
pfUI.chat.urlcopy:SetMovable(true) pfUI.chat.urlcopy:SetMovable(true)
pfUI.chat.urlcopy:EnableMouse(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() this:StartMoving()
end) end)
pfUI.chat.urlcopy:SetScript("OnMouseUp",function() pfUI.chat.urlcopy:SetScript("OnDragStop",function()
this:StopMovingOrSizing() this:StopMovingOrSizing()
end) end)
+3 -2
View File
@@ -55,13 +55,14 @@ pfUI:RegisterModule("firstrun", "vanilla:tbc", function ()
f:SetFrameStrata("TOOLTIP") f:SetFrameStrata("TOOLTIP")
f:SetMovable(true) f:SetMovable(true)
f:EnableMouse(true) f:EnableMouse(true)
f:RegisterForDrag("LeftButton")
f:SetWidth(380) f:SetWidth(380)
f:SetHeight(180) f:SetHeight(180)
f:SetScript("OnMouseDown",function() f:SetScript("OnDragStart",function()
this:StartMoving() this:StartMoving()
end) end)
f:SetScript("OnMouseUp",function() f:SetScript("OnDragStop",function()
this:StopMovingOrSizing() this:StopMovingOrSizing()
end) end)
+3 -2
View File
@@ -543,6 +543,7 @@ pfUI:RegisterModule("gui", "vanilla:tbc", function ()
pfUI.gui = CreateFrame("Frame", "pfConfigGUI", UIParent) pfUI.gui = CreateFrame("Frame", "pfConfigGUI", UIParent)
pfUI.gui:SetMovable(true) pfUI.gui:SetMovable(true)
pfUI.gui:EnableMouse(true) pfUI.gui:EnableMouse(true)
pfUI.gui:RegisterForDrag("LeftButton")
pfUI.gui:SetWidth(720) pfUI.gui:SetWidth(720)
pfUI.gui:SetHeight(480) pfUI.gui:SetHeight(480)
pfUI.gui:SetFrameStrata("DIALOG") pfUI.gui:SetFrameStrata("DIALOG")
@@ -575,11 +576,11 @@ pfUI:RegisterModule("gui", "vanilla:tbc", function ()
pfUI.gui:Hide() pfUI.gui:Hide()
end) end)
pfUI.gui:SetScript("OnMouseDown",function() pfUI.gui:SetScript("OnDragStart",function()
this:StartMoving() this:StartMoving()
end) end)
pfUI.gui:SetScript("OnMouseUp",function() pfUI.gui:SetScript("OnDragStop",function()
this:StopMovingOrSizing() this:StopMovingOrSizing()
end) end)
+6 -5
View File
@@ -39,6 +39,10 @@ pfUI:RegisterModule("map", "vanilla:tbc", function ()
UIPanelWindows["WorldMapFrame"] = { area = "center" } UIPanelWindows["WorldMapFrame"] = { area = "center" }
WorldMapFrame:SetMovable(true)
WorldMapFrame:EnableMouse(true)
WorldMapFrame:RegisterForDrag("LeftButton")
WorldMapFrame:SetScript("OnShow", function() WorldMapFrame:SetScript("OnShow", function()
-- default events -- default events
UpdateMicroButtons() UpdateMicroButtons()
@@ -67,18 +71,15 @@ pfUI:RegisterModule("map", "vanilla:tbc", function ()
SaveMovable(this, true) SaveMovable(this, true)
end) end)
WorldMapFrame:SetScript("OnMouseDown",function() WorldMapFrame:SetScript("OnDragStart",function()
WorldMapFrame:StartMoving() WorldMapFrame:StartMoving()
end) end)
WorldMapFrame:SetScript("OnMouseUp",function() WorldMapFrame:SetScript("OnDragStop",function()
WorldMapFrame:StopMovingOrSizing() WorldMapFrame:StopMovingOrSizing()
SaveMovable(this, true) SaveMovable(this, true)
end) end)
WorldMapFrame:SetMovable(true)
WorldMapFrame:EnableMouse(true)
WorldMapFrame:SetAlpha(alpha) WorldMapFrame:SetAlpha(alpha)
WorldMapFrame:SetScale(scale) WorldMapFrame:SetScale(scale)
UpdateTooltipScale() UpdateTooltipScale()
+3 -2
View File
@@ -253,8 +253,9 @@ pfUI:RegisterModule("share", "vanilla:tbc", function ()
f:SetHeight(420) f:SetHeight(420)
f:SetMovable(true) f:SetMovable(true)
f:EnableMouse(true) f:EnableMouse(true)
f:SetScript("OnMouseDown", function() f:StartMoving() end) f:RegisterForDrag("LeftButton")
f:SetScript("OnMouseUp", function() f:StopMovingOrSizing() end) f:SetScript("OnDragStart", function() f:StartMoving() end)
f:SetScript("OnDragStop", function() f:StopMovingOrSizing() end)
f:SetScript("OnShow", function() f:SetScript("OnShow", function()
if pfUI.gui and pfUI.gui:IsShown() then if pfUI.gui and pfUI.gui:IsShown() then
+23 -23
View File
@@ -322,16 +322,7 @@ pfUI:RegisterModule("unlock", "vanilla:tbc", function ()
QueueFunction(UpdateDockValues) QueueFunction(UpdateDockValues)
end end
local function DraggerOnMouseDown() local function DraggerOnDragStart()
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 frame = this.frame local frame = this.frame
pfUI.unlock.selection = GetFrames() pfUI.unlock.selection = GetFrames()
@@ -349,10 +340,7 @@ pfUI:RegisterModule("unlock", "vanilla:tbc", function ()
if frame.OnMove then frame:OnMove() end if frame.OnMove then frame:OnMove() end
end end
local function DraggerOnMouseUp() local function DraggerOnDragStop()
if arg1 == "MiddleButton" then return end
if arg1 == "RightButton" then return end
local frame = this.frame local frame = this.frame
local name = this.fname local name = this.fname
@@ -410,14 +398,25 @@ pfUI:RegisterModule("unlock", "vanilla:tbc", function ()
end end
local function DraggerOnClick() local function DraggerOnClick()
pfUI.unlock.selection = GetFrames() if arg1 == "RightButton" then
for id, frame in pairs(pfUI.unlock.selection) do -- add dockframe to the dragger to show advanced options
pfUI_config["position"][frame:GetName()] = nil if pfUI.unlock.dock.parent == this and pfUI.unlock.dock:IsShown() then
UpdateMovable(frame) 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 end
UpdateDockValues()
end end
local function DraggerOnEnter() 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 label = string.sub(fname, 1, 2) == "pf" and strsub(fname,3) or fname
local d = CreateFrame("Button", fname .. "Drag", f) local d = CreateFrame("Button", fname .. "Drag", f)
d:RegisterForClicks("MiddleButtonUp") d:RegisterForClicks("MiddleButtonUp", "RightButtonUp")
d:RegisterForDrag("LeftButton")
d:SetAllPoints(f) d:SetAllPoints(f)
d:SetFrameStrata("DIALOG") d:SetFrameStrata("DIALOG")
d:SetAlpha(1) d:SetAlpha(1)
@@ -461,8 +461,8 @@ pfUI:RegisterModule("unlock", "vanilla:tbc", function ()
d.text:SetText(label) d.text:SetText(label)
d:SetScript("OnMouseWheel", DraggerOnMouseWheel) d:SetScript("OnMouseWheel", DraggerOnMouseWheel)
d:SetScript("OnMouseDown", DraggerOnMouseDown) d:SetScript("OnDragStart", DraggerOnDragStart)
d:SetScript("OnMouseUp", DraggerOnMouseUp) d:SetScript("OnDragStop", DraggerOnDragStop)
d:SetScript("OnClick", DraggerOnClick) d:SetScript("OnClick", DraggerOnClick)
d:SetScript("OnEnter", DraggerOnEnter) d:SetScript("OnEnter", DraggerOnEnter)
d:SetScript("OnLeave", DraggerOnLeave) d:SetScript("OnLeave", DraggerOnLeave)