-------------------------------------------------------------------------- |
-- FluidFrames.lua |
-------------------------------------------------------------------------- |
--[[ |
FluidFrames |
|
By: AnduinLothar <KarlKFI@cosmosui.org> |
|
$Id: FluidFrames.lua 5241 2008-04-06 00:13:33Z karlkfi $ |
$Rev: 5241 $ |
$LastChangedBy: karlkfi $ |
$Date: 2008-04-05 19:13:33 -0500 (Sat, 05 Apr 2008) $ |
|
|
]]-- |
|
FluidFrames = {} |
|
FluidFrames.version = tonumber(GetAddOnMetadata("FluidFrames", "Version")) |
|
FluidFrames.debug = false |
|
FluidFrames.NEW_PARENT = "UIParent" |
|
local function Print(text) |
-- Grey |
DEFAULT_CHAT_FRAME:AddMessage(text, .5,.5,.5) |
end |
|
local function DebugPrint(text) |
if (FluidFrames.debug) then |
-- Grey |
DEFAULT_CHAT_FRAME:AddMessage(text, .5,.5,.5) |
end |
end |
|
local function OrNil(text) |
return text or FLUIDFRAMES_NIL |
end |
|
function FluidFrames.Round(x, place) |
if not place then place = 1 end |
return floor(x*place+0.5)/place |
end |
|
function FluidFrames.Compare(x, y) |
local delta = 0.001 |
return x <= y + delta and x >= y - delta |
end |
|
FluidFrames.UninitializedFrames = {} |
|
FluidFrames.FramesToDragByParent = { |
"PaperDollFrame", |
"ReputationFrame", |
"SkillFrame", |
"PVPFrameHonor", |
"PetPaperDollFrame", |
"PVPFrame", |
} |
|
FluidFrames.FramesToInitLater = { |
["QuestWatchFrame"] = true, |
} |
|
function FluidFrames.InitMovedFrames(frameList) |
local framesToHide = {}; |
|
for k,v in pairs(frameList) do |
-- remove parents that used to be unnamed frames |
if (type(v.parent) ~= "string") then |
v.parent = nil |
end |
-- remove relativeTo points that used to be unnamed frames |
for kk,vv in ipairs(v.point) do |
if (type(vv[2]) ~= "string") then |
v.point[kk] = nil |
end |
end |
|
local frame = getglobal(k) |
if (not frame) then |
DebugPrint(format(FLUIDFRAMES_CANT_FIND_STORED, k)) |
-- Add to the Uninitialized list and check on subsequent ADDON_LOADED and PLAYER_REGEN_ENABLED events |
if (frameList ~= FluidFrames.UninitializedFrames) then |
FluidFrames.UninitializedFrames[k] = frameList[k] |
end |
|
elseif (frame:IsProtected() and InCombatLockdown()) then |
DebugPrint(format(FLUIDFRAMES_CANT_MOVE_IN_COMBAT, k)) |
-- Add to the Uninitialized list and check on subsequent ADDON_LOADED and PLAYER_REGEN_ENABLED events |
if (frameList ~= FluidFrames.UninitializedFrames) then |
FluidFrames.UninitializedFrames[k] = frameList[k] |
end |
|
elseif (FluidFrames.FramesToInitLater[k] and frameList ~= FluidFrames.UninitializedFrames) then |
DebugPrint(format(FLUIDFRAMES_DELAYING_EXCEPTION_FRAME, k)) |
-- Exception frames load on PLAYER_REGEN_ENABLED or QUEST_LOG_UPDATE after PLAYER_ENTERING_WORLD |
FluidFrames.UninitializedFrames[k] = frameList[k] |
|
else |
-- SetPoint to stored location, immobilize and establish SetPointHook |
if (v.immobilized) then |
local data = v.immobilized |
if (data.point) then |
if (data.scale and not FluidFrames.Compare(data.scale, frame:GetScale())) then |
frame:SetScale(data.scale) |
end |
if (data.width and data.height) then |
local widthScale = data.width/frame:GetWidth() |
local heightScale = data.height/frame:GetHeight() |
if (FluidFrames.debug) then |
Print("Dimension Restore: "..(frame.GetName and frame:GetName() or "(nil)")) |
Print("Saved Width: "..FluidFrames.Round(data.width, 100).." Curr Width: "..FluidFrames.Round(frame:GetWidth(), 100)) |
Print("Saved Height: "..FluidFrames.Round(data.height, 100).." Curr Height: "..FluidFrames.Round(frame:GetHeight(), 100)) |
Print("WidthScale: "..FluidFrames.Round(widthScale, 100).." HeightScale: "..FluidFrames.Round(heightScale, 100)) |
end |
FluidFrames.RescaleFrame(frame, widthScale, heightScale, true) |
end |
else |
-- update v1.01 sv |
data.point = { data[1], data[2], data[3], data[4], data[5] } |
data[1] = nil |
data[2] = nil |
data[3] = nil |
data[4] = nil |
data[5] = nil |
end |
|
FluidFrames.FreeFrameFromParent(frame) |
|
frame:ClearAllPoints() |
frame:SetPoint(unpack(data.point)) |
frame:SetMovable(1) |
frame:SetUserPlaced(1) |
frame.FFImmobilized = true |
hooksecurefunc(frame, "SetPoint", FluidFrames.SetPointHook) |
hooksecurefunc(frame, "SetWidth", FluidFrames.SetWidthHook) |
hooksecurefunc(frame, "SetHeight", FluidFrames.SetHeightHook) |
frame.FFSetXHooked = true |
end |
|
-- Store frame to hide later (so that it doesn't hide moved child frames before they are reparented) |
if (v.hidden) then |
tinsert(framesToHide, k) |
end |
|
-- Remove from the Uninitialized list |
if (frameList == FluidFrames.UninitializedFrames) then |
frameList[k] = nil |
end |
|
end |
|
end |
|
-- Hide frames and establish ShowHook |
for i,frameName in pairs(framesToHide) do |
local frame = getglobal(frameName) |
FluidFrames.LockHiddenFrame(frame) |
end |
end |
|
function FluidFrames.InitTempDraggableFrames() |
-- Make UIPanels temporarily draggable (position not saved) |
for frameName,info in pairs(UIPanelWindows) do |
local frame = getglobal(frameName) |
if (frame and frame.GetTitleRegion) then |
local titleRegion = frame:GetTitleRegion() |
if (not titleRegion) then |
titleRegion = frame:CreateTitleRegion() |
end |
--titleRegion:SetAllPoints(frame) |
frame:EnableMouse(1) |
end |
end |
|
for frameName,info in pairs(UIChildWindows) do |
local frame = getglobal(frameName) |
if (frame and frame.GetTitleRegion) then |
local titleRegion = frame:GetTitleRegion() |
if (not titleRegion) then |
titleRegion = frame:CreateTitleRegion() |
end |
--titleRegion:SetAllPoints(frame) |
frame:EnableMouse(1) |
end |
end |
|
-- Disable the mouse on a few child frames so that the parent is draggable |
for i,frameName in ipairs(FluidFrames.FramesToDragByParent) do |
local frame = getglobal(frameName) |
if (frame) then |
frame:EnableMouse(nil) |
end |
end |
|
--Exceptions |
if (not MinimapCluster:GetTitleRegion()) then |
MinimapCluster:SetScript("OnEnter", function() |
local tempthis = this |
this = MinimapZoneTextButton |
MinimapZoneTextButton:GetScript("OnEnter")(MinimapZoneTextButton) |
this = tempthis |
end) |
MinimapCluster:SetScript("OnLeave", function() |
local tempthis = this |
this = MinimapZoneTextButton |
MinimapZoneTextButton:GetScript("OnLeave")(MinimapZoneTextButton) |
this = tempthis |
end) |
MinimapCluster:CreateTitleRegion():SetAllPoints(MinimapCluster) |
MinimapZoneTextButton:EnableMouse(nil) |
end |
|
-- Update Enabled (mostly for LoD) |
if (FluidFrames_SavedVars) then |
FluidFrames.ToggleTempDraggableFrames(FluidFrames_SavedVars.TempDraggable == "1") |
end |
end |
|
function FluidFrames.ToggleTempDraggableFrames(value) |
for frameName,info in pairs(UIPanelWindows) do |
local frame = getglobal(frameName) |
if (frame and frame.GetTitleRegion) then |
local titleRegion = frame:GetTitleRegion() |
if (titleRegion) then |
if (value) then |
titleRegion:SetAllPoints(frame) |
else |
titleRegion:ClearAllPoints() |
titleRegion:SetHeight(0) |
titleRegion:SetWidth(0) |
end |
end |
end |
end |
|
for frameName,info in pairs(UIChildWindows) do |
local frame = getglobal(frameName) |
if (frame and frame.GetTitleRegion) then |
local titleRegion = frame:GetTitleRegion() |
if (titleRegion) then |
if (value) then |
titleRegion:SetAllPoints(frame) |
else |
titleRegion:ClearAllPoints() |
titleRegion:SetHeight(0) |
titleRegion:SetWidth(0) |
end |
end |
end |
end |
|
--Exceptions |
local titleRegion = MinimapCluster:GetTitleRegion() |
if (titleRegion) then |
if (value) then |
titleRegion:SetAllPoints(MinimapCluster) |
else |
titleRegion:ClearAllPoints() |
titleRegion:SetHeight(0) |
titleRegion:SetWidth(0) |
end |
end |
|
if (value and AchievementFrame) then |
AchievementFrameHeader:EnableMouse(false) |
end |
end |
|
function FluidFrames.OnEvent(self, event, arg1) |
if (event == "ADDON_LOADED") then |
-- Catch Load on Demand Addon frames |
-- Use OnUpdate to load after their LoadWith's |
self.nextFrameInit = true |
|
elseif (event == "VARIABLES_LOADED") then |
FluidFrames.InitTempDraggableFrames() |
if (Portfolio) then |
FluidFrames.RegisterPortfolio() |
end |
self:RegisterEvent("PLAYER_ENTERING_WORLD") |
|
elseif (event == "PLAYER_ENTERING_WORLD") then |
self:UnregisterEvent("PLAYER_ENTERING_WORLD") |
self:RegisterEvent("QUEST_LOG_UPDATE") |
self:RegisterEvent("PLAYER_REGEN_ENABLED") |
self:RegisterEvent("ADDON_LOADED") |
|
if (not FluidFramesModifiedFrames) then |
FluidFramesModifiedFrames = {} |
else |
FluidFrames.InitMovedFrames(FluidFramesModifiedFrames) |
hooksecurefunc("CreateFrame", FluidFrames.CreateFrameHook) |
end |
--FluidFrames.InitTempDraggableFrames() |
|
-- QUEST_LOG_UPDATE should fire when you log in or reloadui, regardless of whether you have any quests |
--This makes sure QuestWatchFrame has been resized |
elseif (event == "QUEST_LOG_UPDATE") then |
self:UnregisterEvent("QUEST_LOG_UPDATE") |
FluidFrames.InitMovedFrames(FluidFrames.UninitializedFrames) |
|
elseif (event == "PLAYER_REGEN_ENABLED") then |
self:UnregisterEvent("PLAYER_REGEN_ENABLED") |
FluidFrames.InitMovedFrames(FluidFrames.UninitializedFrames) |
|
end |
end |
|
function FluidFrames.CreateFrameHook(frameType, frameName, parent) |
if (frameName and FluidFrames.UninitializedFrames[frameName]) then |
FluidFrames.EventFrame.nextFrameInit = true |
end |
end |
|
function FluidFrames.EventOnUpdate(self, delay) |
if (self.nextFrameInit) then |
FluidFrames.InitMovedFrames(FluidFrames.UninitializedFrames) |
FluidFrames.InitTempDraggableFrames() |
self.nextFrameInit = false |
end |
end |
|
function FluidFrames.OnUpdate(self, delay) |
if (self.frame and (self.isResizing or self.isMoving or self.isRescaling)) then |
if (not this.count) then |
self.count = delay |
elseif (this.count < .02) then |
self.count = self.count + delay |
|
elseif (this.isRescaling) then |
this.count = 0 |
local frame = self.frame |
|
local x, y = GetCursorPosition() |
local UIScale = UIParent:GetEffectiveScale() |
local currScale = self:GetEffectiveScale() |
x = x / currScale - 10 / currScale |
y = y / currScale + 10 / currScale |
local left = self:GetLeft() |
local top = self:GetTop() |
local wScale = (x-left)/self:GetWidth() |
local hScale = (top-y)/self:GetHeight() |
local scale = max(min(max(wScale, hScale), 1.2), 0.8) |
|
if (scale < 1 and currScale < 0.1) then |
return |
end |
|
FluidFrames.RelativelyScaleFrame(this, scale) |
FluidFrames.RelativelyScaleFrame(frame, scale) |
|
local xOffset = left/scale |
local yOffset = top/scale - this:GetHeight() |
|
frame:SetUserPlaced(nil) |
frame:ClearAllPoints() |
frame:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", xOffset, yOffset) |
frame:SetUserPlaced(1) |
|
self:ClearAllPoints() |
self:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", xOffset, yOffset) |
|
else |
self.count = 0 |
local frame = self.frame |
|
if (this.isResizing) then |
local wScale = self:GetWidth()/frame:GetWidth() |
if (frame.MFwScale) then |
frame.MFwScale = frame.MFwScale * wScale |
else |
frame.MFwScale = wScale |
end |
local hScale = self:GetHeight()/frame:GetHeight() |
if (frame.MFhScale) then |
frame.MFhScale = frame.MFhScale * hScale |
else |
frame.MFhScale = hScale |
end |
|
FluidFrames.RescaleFrame(frame, wScale, hScale, not IsAltKeyDown()) |
end |
|
frame:SetUserPlaced(nil) |
frame:ClearAllPoints() |
frame:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", self:GetLeft(), self:GetBottom()) |
frame:SetUserPlaced(1) |
|
end |
end |
end |
|
function FluidFrames.InitEventFrame() |
if (FluidFrames.EventFrame) then |
return |
end |
local eventFrame = CreateFrame("Frame", "FluidEventFrame", UIParent) |
eventFrame:RegisterEvent("VARIABLES_LOADED") |
eventFrame:SetScript("OnEvent", FluidFrames.OnEvent) |
eventFrame:SetScript("OnUpdate", FluidFrames.EventOnUpdate) |
FluidFrames.EventFrame = eventFrame |
end |
|
function FluidFrames.InitDraggableFrame() |
if (FluidFrames.DragFrame) then |
return |
end |
|
local dragFrame = CreateFrame("Frame", "FluidFrame", UIParent) |
dragFrame:Hide() |
dragFrame:SetToplevel(1) |
dragFrame:SetFrameStrata("TOOLTIP") |
dragFrame:SetResizable(1) |
dragFrame:SetMovable(1) |
dragFrame:EnableMouse("LeftButton") |
dragFrame:SetAlpha(0.25) |
|
dragFrame:SetScript("OnMouseDown", FluidFrames.StartMoving) |
dragFrame:SetScript("OnMouseUp", FluidFrames.StopDragFrameMovingOrSizing) |
dragFrame:SetScript("OnUpdate", FluidFrames.OnUpdate) |
|
local minsize = 10 |
|
FluidFrames.DragFrame = dragFrame |
|
--dragFrame:CreateTitleRegion():SetAllPoints(dragFrame) |
--Frame:GetTitleRegion() |
|
local red = 0 |
local green = 0.2 |
local blue = 0.7 |
-- Don't make bigger than the UIParent? |
dragFrame:SetMinResize(minsize, minsize) |
--dragFrame:SetMaxResize() |
|
local background = dragFrame:CreateTexture("FluidFrameBackground", "BACKGROUND") |
background:SetTexture("Interface\\ChatFrame\\ChatFrameBackground") |
background:SetVertexColor(red, green, blue) |
background:SetPoint("TOP", 0, -2) |
background:SetPoint("BOTTOM", 0, 1) |
background:SetPoint("LEFT", 1, 0) |
background:SetPoint("RIGHT", -1, 0) |
|
local ResizeTopLeft = CreateFrame("Button", "FluidFrameResizeTopLeft", dragFrame) |
--ResizeTopLeft:SetFrameLevel(ResizeTopLeft:GetFrameLevel()-1) |
ResizeTopLeft:SetHeight(16) |
ResizeTopLeft:SetWidth(16) |
ResizeTopLeft:SetPoint("TOPLEFT", -2, 2) |
local rtlTexture = ResizeTopLeft:CreateTexture("FluidFramertlTexture", "BACKGROUND") |
rtlTexture:SetVertexColor(red, green, blue) |
rtlTexture:SetTexture("Interface\\ChatFrame\\ChatFrameBorder") |
rtlTexture:SetAllPoints(ResizeTopLeft) --TOPLEFT 16/16? |
rtlTexture:SetTexCoord(0, 0.25, 0, 0.125) |
ResizeTopLeft:SetScript("OnMouseDown", function(self, button) FluidFrames.StartParentResizing(self, button, "TOPLEFT") end) |
ResizeTopLeft:SetScript("OnMouseUp", FluidFrames.StopParentMovingOrSizing) |
ResizeTopLeft:SetScript("OnEnter", function() FluidFrames.SetColorHighlight(rtlTexture) end) |
ResizeTopLeft:SetScript("OnLeave", function() rtlTexture:SetVertexColor(red, green, blue) end) |
|
local ResizeTopRight = CreateFrame("Button", "FluidFrameResizeTopRight", dragFrame) |
--ResizeTopRight:SetFrameLevel(ResizeTopRight:GetFrameLevel()-1) |
ResizeTopRight:SetHeight(16) |
ResizeTopRight:SetWidth(16) |
ResizeTopRight:SetPoint("TOPRIGHT", 2, 2) |
local rtrTexture = ResizeTopRight:CreateTexture("FluidFramertrTexture", "BACKGROUND") |
rtrTexture:SetVertexColor(red, green, blue) |
rtrTexture:SetTexture("Interface\\ChatFrame\\ChatFrameBorder") |
rtrTexture:SetAllPoints(ResizeTopRight) --TOPRIGHT 16/16? |
rtrTexture:SetTexCoord(0.75, 1.0, 0, 0.125) |
ResizeTopRight:SetScript("OnMouseDown", function(self, button) FluidFrames.StartParentResizing(self, button, "TOPRIGHT") end) |
ResizeTopRight:SetScript("OnMouseUp", FluidFrames.StopParentMovingOrSizing) |
ResizeTopRight:SetScript("OnEnter", function() FluidFrames.SetColorHighlight(rtrTexture) end) |
ResizeTopRight:SetScript("OnLeave", function() rtrTexture:SetVertexColor(red, green, blue) end) |
|
local ResizeBottomLeft = CreateFrame("Button", "FluidFrameResizeBottomLeft", dragFrame) |
--ResizeBottomLeft:SetFrameLevel(ResizeBottomLeft:GetFrameLevel()-1) |
ResizeBottomLeft:SetHeight(16) |
ResizeBottomLeft:SetWidth(16) |
ResizeBottomLeft:SetPoint("BOTTOMLEFT", -2, -3) |
local rblTexture = ResizeBottomLeft:CreateTexture("FluidFramerblTexture", "BACKGROUND") |
rblTexture:SetVertexColor(red, green, blue) |
rblTexture:SetTexture("Interface\\ChatFrame\\ChatFrameBorder") |
rblTexture:SetAllPoints(ResizeBottomLeft) --TOPLEFT 16/16? |
rblTexture:SetTexCoord(0, 0.25, 0.7265625, 0.8515625) |
ResizeBottomLeft:SetScript("OnMouseDown", function(self, button) FluidFrames.StartParentResizing(self, button, "BOTTOMLEFT") end) |
ResizeBottomLeft:SetScript("OnMouseUp", FluidFrames.StopParentMovingOrSizing) |
ResizeBottomLeft:SetScript("OnEnter", function() FluidFrames.SetColorHighlight(rblTexture) end) |
ResizeBottomLeft:SetScript("OnLeave", function() rblTexture:SetVertexColor(red, green, blue) end) |
|
local ResizeBottomRight = CreateFrame("Button", "FluidFrameResizeBottomRight", dragFrame) |
--ResizeBottomRight:SetFrameLevel(ResizeBottomRight:GetFrameLevel()-1) |
ResizeBottomRight:SetHeight(16) |
ResizeBottomRight:SetWidth(16) |
ResizeBottomRight:SetPoint("BOTTOMRIGHT", 2, -3) |
local rbrTexture = ResizeBottomRight:CreateTexture("FluidFramerbrTexture", "BACKGROUND") |
rbrTexture:SetVertexColor(red, green, blue) |
rbrTexture:SetTexture("Interface\\ChatFrame\\ChatFrameBorder") |
rbrTexture:SetAllPoints(ResizeBottomRight) --BOTTOMRIGHT 16/16? |
rbrTexture:SetTexCoord(0.75, 1.0, 0.7265625, 0.8515625) |
ResizeBottomRight:SetScript("OnMouseDown", function(self, button) FluidFrames.StartParentResizing(self, button, "BOTTOMRIGHT") end) |
ResizeBottomRight:SetScript("OnMouseUp", FluidFrames.StopParentMovingOrSizing) |
ResizeBottomRight:SetScript("OnEnter", function() FluidFrames.SetColorHighlight(rbrTexture) end) |
ResizeBottomRight:SetScript("OnLeave", function() rbrTexture:SetVertexColor(red, green, blue) end) |
|
local ResizeTop = CreateFrame("Button", "FluidFrameResizeTop", dragFrame) |
--ResizeTop:SetFrameLevel(ResizeTop:GetFrameLevel()-1) |
ResizeTop:SetHeight(16) |
ResizeTop:SetWidth(16) |
ResizeTop:SetPoint("LEFT", ResizeTopLeft, "RIGHT", 0, 0) |
ResizeTop:SetPoint("RIGHT", ResizeTopRight, "LEFT", 0, 0) |
local rtTexture = ResizeTop:CreateTexture("FluidFramertTexture", "BACKGROUND") |
rtTexture:SetVertexColor(red, green, blue) |
rtTexture:SetTexture("Interface\\ChatFrame\\ChatFrameBorder") |
rtTexture:SetAllPoints(ResizeTop) |
rtTexture:SetTexCoord(0.25, 0.75, 0, 0.125) |
ResizeTop:SetScript("OnMouseDown", function(self, button) FluidFrames.StartParentResizing(self, button, "TOP") end) |
ResizeTop:SetScript("OnMouseUp", FluidFrames.StopParentMovingOrSizing) |
ResizeTop:SetScript("OnEnter", function() FluidFrames.SetColorHighlight(rtTexture) end) |
ResizeTop:SetScript("OnLeave", function() rtTexture:SetVertexColor(red, green, blue) end) |
|
local ResizeBottom = CreateFrame("Button", "FluidFrameResizeBottom", dragFrame) |
--ResizeBottom:SetFrameLevel(ResizeBottom:GetFrameLevel()-1) |
ResizeBottom:SetHeight(16) |
ResizeBottom:SetWidth(16) |
ResizeBottom:SetPoint("LEFT", ResizeBottomLeft, "RIGHT", 0, 0) |
ResizeBottom:SetPoint("RIGHT", ResizeBottomRight, "LEFT", 0, 0) |
local rbTexture = ResizeBottom:CreateTexture("FluidFramerbTexture", "BACKGROUND") |
rbTexture:SetVertexColor(red, green, blue) |
rbTexture:SetTexture("Interface\\ChatFrame\\ChatFrameBorder") |
rbTexture:SetAllPoints(ResizeBottom) --TOPLEFT 16/16? |
rbTexture:SetTexCoord(0.25, 0.75, 0.7265625, 0.8515625) |
ResizeBottom:SetScript("OnMouseDown", function(self, button) FluidFrames.StartParentResizing(self, button, "BOTTOM") end) |
ResizeBottom:SetScript("OnMouseUp", FluidFrames.StopParentMovingOrSizing) |
ResizeBottom:SetScript("OnEnter", function() FluidFrames.SetColorHighlight(rbTexture) end) |
ResizeBottom:SetScript("OnLeave", function() rbTexture:SetVertexColor(red, green, blue) end) |
|
local ResizeLeft = CreateFrame("Button", "FluidFrameResizeLeft", dragFrame) |
--ResizeLeft:SetFrameLevel(ResizeLeft:GetFrameLevel()-1) |
ResizeLeft:SetHeight(16) |
ResizeLeft:SetWidth(16) |
ResizeLeft:SetPoint("TOP", ResizeTopLeft, "BOTTOM", 0, 0) |
ResizeLeft:SetPoint("BOTTOM", ResizeBottomLeft, "TOP", 0, 0) |
local rbTexture = ResizeLeft:CreateTexture("FluidFramerbTexture", "BACKGROUND") |
rbTexture:SetVertexColor(red, green, blue) |
rbTexture:SetTexture("Interface\\ChatFrame\\ChatFrameBorder") |
rbTexture:SetAllPoints(ResizeLeft) |
rbTexture:SetTexCoord(0, 0.25, 0.125, 0.7265625) |
ResizeLeft:SetScript("OnMouseDown", function(self, button) FluidFrames.StartParentResizing(self, button, "LEFT") end) |
ResizeLeft:SetScript("OnMouseUp", FluidFrames.StopParentMovingOrSizing) |
ResizeLeft:SetScript("OnEnter", function() FluidFrames.SetColorHighlight(rbTexture) end) |
ResizeLeft:SetScript("OnLeave", function() rbTexture:SetVertexColor(red, green, blue) end) |
|
local ResizeRight = CreateFrame("Button", "FluidFrameResizeRight", dragFrame) |
--ResizeRight:SetFrameLevel(ResizeRight:GetFrameLevel()-1) |
ResizeRight:SetHeight(16) |
ResizeRight:SetWidth(16) |
ResizeRight:SetPoint("TOP", ResizeTopRight, "BOTTOM", 0, 0) |
ResizeRight:SetPoint("BOTTOM", ResizeBottomRight, "TOP", 0, 0) |
local rrTexture = ResizeRight:CreateTexture("FluidFramerrTexture", "BACKGROUND") |
rrTexture:SetVertexColor(red, green, blue) |
rrTexture:SetTexture("Interface\\ChatFrame\\ChatFrameBorder") |
rrTexture:SetAllPoints(ResizeRight) |
rrTexture:SetTexCoord(0.75, 1.0, 0.125, 0.7265625) |
ResizeRight:SetScript("OnMouseDown", function(self, button) FluidFrames.StartParentResizing(self, button, "RIGHT") end) |
ResizeRight:SetScript("OnMouseUp", FluidFrames.StopParentMovingOrSizing) |
ResizeRight:SetScript("OnEnter", function() FluidFrames.SetColorHighlight(rrTexture) end) |
ResizeRight:SetScript("OnLeave", function() rrTexture:SetVertexColor(red, green, blue) end) |
|
local Scale = CreateFrame("Button", "FluidFrameRescale", dragFrame) |
Scale:SetFrameLevel(Scale:GetFrameLevel()+1) |
Scale:SetHeight(20) |
Scale:SetWidth(20) |
Scale:SetPoint("BOTTOMRIGHT", 20, -20) |
local sTexture = Scale:CreateTexture("FluidFrameRescaleTexture", "BACKGROUND") |
sTexture:SetVertexColor(red, green, blue) |
sTexture:SetTexture("Interface\\AddOns\\FluidFrames\\Skin\\Rescale") |
sTexture:SetAllPoints(Scale) |
Scale:SetScript("OnMouseDown", FluidFrames.StartParentRescaling) |
Scale:SetScript("OnMouseUp", FluidFrames.StopParentMovingOrSizing) |
Scale:SetScript("OnEnter", function() FluidFrames.SetColorHighlight(sTexture) end) |
Scale:SetScript("OnLeave", function() sTexture:SetVertexColor(red, green, blue) end) |
|
local HideButton = CreateFrame("Button", "FluidFrameHideButton", dragFrame, "UIPanelButtonTemplate2") |
HideButton:SetText(HIDE) |
HideButton:SetPoint("BOTTOM", dragFrame, "TOP", 10, 0) |
HideButton:SetScript("OnClick", FluidFrames.HideButton_OnClick) |
HideButton:SetClampedToScreen(1) |
end |
|
function FluidFrames.SetColorHighlight(frame) |
if (IsShiftKeyDown()) then |
frame:SetVertexColor(1, 0.82, 0) |
end |
end |
|
function FluidFrames.HideButton_OnClick(self) |
if (FluidFrames.DragFrame.frame.FFHidden) then |
FluidFrames.UnlockHiddenFrame(FluidFrames.DragFrame.frame) |
self:SetText(HIDE) |
else |
FluidFrames.StoreFrameDefault(FluidFrames.DragFrame.frame) |
FluidFrames.LockHiddenFrame(FluidFrames.DragFrame.frame) |
self:SetText(SHOW) |
end |
end |
|
function FluidFrames.StartParentResizing(self, button, anchorPoint) |
local frame = self:GetParent() |
if (frame.isLocked) then |
return |
end |
if (frame:IsProtected() and InCombatLockdown()) then |
Print(format(FLUIDFRAMES_CANT_RESIZE_IN_COMBAT, frame:GetName())) |
return |
elseif (button == "RightButton") then |
FluidFrames.ResetFrame(frame.frame) |
elseif (IsShiftKeyDown()) then |
FluidFrames.StoreFrameDefault(frame.frame, true, true) |
FluidFrames.Mobilize(frame.frame) |
FluidFrames.FreeFrameFromParent(frame.frame) |
frame.isResizing = true |
frame:StartSizing(anchorPoint) |
else |
FluidFrames.StoreFrameDefault(frame.frame) |
FluidFrames.Mobilize(frame.frame) |
FluidFrames.FreeFrameFromParent(frame.frame) |
frame:StartMoving() |
frame.isMoving = true |
end |
end |
|
function FluidFrames.StartMoving(self, button) |
if (self.frame:IsProtected() and InCombatLockdown()) then |
Print(format(FLUIDFRAMES_CANT_MOVE_IN_COMBAT, self.frame:GetName())) |
return |
elseif (button == "RightButton") then |
FluidFrames.ResetFrame(self.frame) |
elseif (not self.isLocked) then |
FluidFrames.StoreFrameDefault(self.frame) |
FluidFrames.Mobilize(self.frame) |
FluidFrames.FreeFrameFromParent(self.frame) |
self:StartMoving() |
self.isMoving = true |
end |
end |
|
function FluidFrames.StartParentRescaling(self, button) |
local frame = self:GetParent() |
if (frame:IsProtected() and InCombatLockdown()) then |
Print(format(FLUIDFRAMES_CANT_RESCALE_IN_COMBAT, frame:GetName())) |
return |
elseif (button == "RightButton") then |
FluidFrames.ResetFrame(frame.frame) |
elseif (IsShiftKeyDown()) then |
if (not frame.isLocked) then |
FluidFrames.StoreFrameDefault(frame.frame, true) |
FluidFrames.Mobilize(frame.frame) |
FluidFrames.FreeFrameFromParent(frame.frame) |
frame.isRescaling = true |
end |
else |
FluidFrames.StoreFrameDefault(frame.frame) |
FluidFrames.Mobilize(frame.frame) |
FluidFrames.FreeFrameFromParent(frame.frame) |
frame:StartMoving() |
frame.isMoving = true |
end |
end |
|
function FluidFrames.StopParentMovingOrSizing(self) |
if (button ~= "RightButton") then |
local frame = self:GetParent() |
frame:StopMovingOrSizing() |
if (frame.isRescaling or frame.isResizing or frame.isMoving) then |
local storeScale = frame.isRescaling or frame.isResizing |
local storeDimentions = frame.isResizing |
frame.isMoving = nil |
frame.isResizing = nil |
frame.isRescaling = nil |
FluidFrames.ImmobilizeAndStoreDimentions(frame.frame, storeScale, storeDimentions) |
end |
end |
end |
|
function FluidFrames.StopDragFrameMovingOrSizing(self) |
if (button ~= "RightButton") then |
self:StopMovingOrSizing() |
local storeScale = self.isRescaling or self.isResizing |
local storeDimentions = self.isResizing |
self.isMoving = nil |
self.isResizing = nil |
self.isRescaling = nil |
FluidFrames.ImmobilizeAndStoreDimentions(self.frame, storeScale, storeDimentions) |
end |
end |
|
--/z FluidFrames.StartFrameResize(FriendsFrame) |
function FluidFrames.StartFrameResize(frame) |
if (not frame) then |
return |
elseif (frame:IsProtected() and InCombatLockdown()) then |
Print(format(FLUIDFRAMES_CANT_RESIZE_IN_COMBAT, frame:GetName())) |
return |
end |
FluidFrames.InitDraggableFrame() |
local dragFrame = FluidFrames.DragFrame |
|
Print(format(FLUIDFRAMES_START_RESIZE, OrNil(frame:GetName()))) |
|
dragFrame:SetWidth(frame:GetWidth()) |
dragFrame:SetHeight(frame:GetHeight()) |
local left = frame:GetLeft() |
local bottom = frame:GetBottom() |
dragFrame:ClearAllPoints() |
dragFrame:SetPoint("BOTTOMLEFT", left, bottom) |
frame:SetUserPlaced(nil) |
frame:ClearAllPoints() |
frame:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", left, bottom) |
frame:SetUserPlaced(1) |
dragFrame.frame = frame |
dragFrame:Show() |
end |
|
function FluidFrames.EndResizeFrame(frame) |
if (not frame) then |
return |
end |
local dragFrame = FluidFrames.DragFrame |
|
Print(format(FLUIDFRAMES_STOP_RESIZE, OrNil(frame:GetName()))) |
|
dragFrame.frame = nil |
dragFrame:Hide() |
end |
|
function FluidFrames.RescaleChildren(widthScale, heightScale, resizeFontStrings, ...) |
for i=1, select("#", ...) do |
local child = select(i, ...) |
if (child) then |
if (child:IsObjectType("FontString")) then |
local fontName, fontHeight, fontFlags = child:GetFont() |
if (fontName and fontHeight > 0 and heightScale ~= child:GetParent():GetScale()) then |
child:SetFont(fontName, fontHeight*heightScale, fontFlags) |
--Print("Resizing FontString: "..(child:GetName() or "<Unnamed>").." Scale: "..FluidFrames.Round(heightScale, 100).." FontSize: "..FluidFrames.Round(fontHeight*heightScale, 100)) |
end |
if ( resizeFontStrings and child:GetStringWidth() > 0 and not FluidFrames.Compare(child:GetStringWidth(), child:GetWidth()) ) then |
--Use height for now, untill there's a way to check if the FontString has been absoolutely sized or not |
if (child.GetName and child:GetName()) then |
--Print(child:GetName()..": resizeFontStrings - "..floor(child:GetStringWidth()).." "..floor(child:GetWidth()).." "..floor(child:GetHeight()).." "..FluidFrames.Round(heightScale, 100)) |
child:SetWidth(child:GetWidth()*heightScale) |
child:SetHeight(child:GetHeight()*heightScale) |
--Print("SetWidth: "..FluidFrames.Round(child:GetWidth()*heightScale, 100).." SetHeight: "..FluidFrames.Round(child:GetHeight()*heightScale, 100)) |
end |
end |
else |
child:SetWidth(child:GetWidth()*widthScale) |
child:SetHeight(child:GetHeight()*heightScale) |
end |
if (child.GetChildren) then |
FluidFrames.RescaleChildren(widthScale, heightScale, resizeFontStrings, child:GetChildren()) |
end |
if (child.GetRegions) then |
FluidFrames.RescaleChildren(widthScale, heightScale, resizeFontStrings, child:GetRegions()) |
end |
|
if (child.GetNumPoints) then |
for p=1, child:GetNumPoints() do |
local point, relativeTo, relativePoint, xOffset, yOffset = child:GetPoint(p) |
child:SetPoint(point, relativeTo, relativePoint, xOffset*widthScale, yOffset*heightScale) |
end |
end |
end |
end |
end |
|
--/z FluidFrames.RescaleFrame(ShapeshiftBarFrame, 1.5, 1) |
--/z FluidFrames.RescaleFrame(PlayerFrame, 1.5, 1) |
function FluidFrames.RescaleFrame(frame, widthScale, heightScale, resizeFontStrings) |
if (not frame) then |
return |
elseif (frame:IsProtected() and InCombatLockdown()) then |
return |
end |
|
frame:SetWidth(frame:GetWidth()*widthScale) |
frame:SetHeight(frame:GetHeight()*heightScale) |
|
if (frame.GetChildren) then |
FluidFrames.RescaleChildren(widthScale, heightScale, resizeFontStrings, frame:GetChildren()) |
end |
if (frame.GetRegions) then |
FluidFrames.RescaleChildren(widthScale, heightScale, resizeFontStrings, frame:GetRegions()) |
end |
end |
|
function FluidFrames.RelativelyScaleFrame(frame, scale) |
if (not frame) then |
return |
end |
frame:SetScale(frame:GetScale()*scale) |
end |
|
---------------------------- |
-- Frame Stack Code |
---------------------------- |
|
FluidFrames.FrameStack = {} |
FluidFrames.ExcludedFrames = { |
WorldFrame = true, |
UIParent = true, |
|
MainMenuBarArtFrame = true, |
MainMenuBarOverlayFrame = true, |
TargetFrameTextureFrame = true, |
LFGWizardFrame = true, |
FriendsListFrame = true, |
} |
for i=1, NUM_CONTAINER_FRAMES do |
FluidFrames.ExcludedFrames["ContainerFrame"..i] = true |
end |
|
function FluidFrames.IsChildFrame(frame, child) |
if (not frame or not child) then |
return |
end |
while (child ~= frame) do |
child = child:GetParent() |
if (not child) then |
return false |
end |
end |
return true |
end |
|
function FluidFrames.BuildCursorFrameStack() |
local stack = FluidFrames.FrameStack |
|
--Empty Stack |
local stackSize = #stack |
while (stackSize > 0) do |
tremove(stack, #stack) |
stackSize = #stack |
end |
|
local frame = EnumerateFrames() |
while (frame) do |
local frameName = frame.GetName and frame:GetName() |
if (frame:IsVisible() |
and (not frameName or not FluidFrames.ExcludedFrames[frameName]) |
and MouseIsOver(frame) |
and not FluidFrames.IsChildFrame(FluidFrames.DragFrame, frame) |
) then |
tinsert(stack, frame) |
end |
frame = EnumerateFrames(frame) |
end |
end |
|
function FluidFrames.GetNextStackFrame(frame, showAll) |
local stack = FluidFrames.FrameStack |
|
local returnNext |
|
if (not frame) then |
if (#stack > 0) then |
returnNext = true |
else |
return |
end |
end |
|
for i, sFrame in ipairs(stack) do |
if (showAll or sFrame:GetName()) then |
if (returnNext) then |
return sFrame |
elseif (frame == sFrame) then |
returnNext = true |
end |
end |
end |
end |
|
|
function FluidFrames.GetPreviousStackFrame(frame) |
local stack = FluidFrames.FrameStack |
|
if (not frame) then |
if (#stack > 0) then |
return stack[#stack] |
else |
return |
end |
end |
|
local prevFrame |
for i, sFrame in ipairs(stack) do |
if (frame == sFrame) then |
return prevFrame |
end |
prevFrame = sFrame |
end |
end |
|
---------------------------- |
-- Highlight a Frame |
---------------------------- |
|
function FluidFrames.HighlightMouseFrame(showAll) |
|
local dragFrame = FluidFrames.DragFrame |
|
if (dragFrame.isResizing) then |
dragFrame:StopMovingOrSizing() |
dragFrame.isResizing = nil |
end |
|
FluidFrames.BuildCursorFrameStack() |
|
local newFrame |
if (not dragFrame:IsVisible()) then |
if (IsShiftKeyDown()) then |
newFrame = FluidFrames.GetPreviousStackFrame() |
else |
newFrame = FluidFrames.GetNextStackFrame() |
end |
else |
if (#FluidFrames.FrameStack > 0) then |
if (IsShiftKeyDown()) then |
newFrame = FluidFrames.GetPreviousStackFrame(dragFrame.frame) |
else |
newFrame = FluidFrames.GetNextStackFrame(dragFrame.frame) |
end |
if (not newFrame) then |
dragFrame.frame = nil |
dragFrame:Hide() |
return |
end |
end |
end |
|
if (not newFrame) then |
Print(FLUIDFRAMES_NO_MOVABLE_FRAMES) |
dragFrame.frame = nil |
dragFrame:Hide() |
return |
end |
|
|
local parent = newFrame:GetParent() |
Print(format(FLUIDFRAMES_HIGHLIGHT, OrNil(newFrame:GetName()), OrNil(parent and parent:GetName()))) |
|
dragFrame:SetWidth(newFrame:GetWidth()) |
dragFrame:SetHeight(newFrame:GetHeight()) |
local scale = newFrame:GetEffectiveScale()/UIParent:GetEffectiveScale() |
dragFrame:SetScale(scale) |
local left = newFrame:GetLeft() |
local bottom = newFrame:GetBottom() |
dragFrame:ClearAllPoints() |
dragFrame:SetPoint("BOTTOMLEFT", left, bottom) |
|
newFrame:SetMovable(1) |
|
if (parent == UIParent or parent == nil) then |
--[[ |
newFrame:SetUserPlaced(nil) |
newFrame:ClearAllPoints() |
newFrame:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", left, bottom) |
newFrame:SetUserPlaced(1) |
]]-- |
end |
|
dragFrame.frame = newFrame |
dragFrame:Show() |
end |
|
---------------------------- |
-- Immobilization Code |
---------------------------- |
|
function FluidFrames.SetPointHook(self, ...) |
if (self.FFImmobilized) then |
DebugPrint(format("%s:SetPoint intercepted - Immobilized.", self:GetName())) |
local data = FluidFramesModifiedFrames[self:GetName()] |
if (data and data.immobilized) then |
if (self:IsProtected() and InCombatLockdown()) then |
DebugPrint(format("%s:SetPoint intercepted - Can't move in combat.", self:GetName())) |
else |
self.FFImmobilized = nil |
self:ClearAllPoints() |
self:SetPoint(unpack(data.immobilized.point)) |
self.FFImmobilized = true |
DebugPrint(format("%s:SetPoint intercepted - Moved to saved location.", self:GetName())) |
end |
end |
else |
DebugPrint(format("%s:SetPoint intercepted - Mobile: %s.", self:GetName(), (this and this.GetName and this:GetName() or "Unknown"))) |
end |
end |
|
function FluidFrames.SetWidthHook(self, width) |
if (self.FFImmobilized) then |
DebugPrint(format("%s:SetWidth intercepted - %s.", self:GetName(), width)) |
-- Allow SetWidth when immobilized, update saved data |
local data = FluidFramesModifiedFrames[self:GetName()] |
if (data and data.immobilized and data.immobilized.width and data.width) then |
-- Update Reset Width by scaling by difference between the previous immobilized width and the new width |
data.width = data.width * (width / data.immobilized.width) |
-- Update Immobilized Width |
data.immobilized.width = width |
end |
end |
end |
|
function FluidFrames.SetHeightHook(self, height) |
if (self.FFImmobilized) then |
DebugPrint(format("%s:SetHeight intercepted - %s.", self:GetName(), height)) |
-- Allow SetHeight when immobilized, update saved data |
local data = FluidFramesModifiedFrames[self:GetName()] |
if (data and data.immobilized and data.immobilized.height and data.height) then |
-- Update Reset Height by scaling by difference between the previous immobilized height and the new height |
data.height = data.height * (height / data.immobilized.height) |
-- Update Immobilized Height |
data.immobilized.height = height |
--[[ Update position (since it's will be set from the bottom left) |
self.FFImmobilized = nil |
self:ClearAllPoints() |
self:SetPoint(unpack(data.immobilized.point)) |
self.FFImmobilized = true |
]]-- |
end |
end |
end |
|
|
function FluidFrames.Immobilize(frame) |
if (frame.GetName and frame:GetName()) then |
if (not frame.FFSetXHooked) then |
hooksecurefunc(frame, "SetPoint", FluidFrames.SetPointHook) |
hooksecurefunc(frame, "SetWidth", FluidFrames.SetWidthHook) |
hooksecurefunc(frame, "SetHeight", FluidFrames.SetHeightHook) |
frame.FFSetXHooked = true |
end |
-- Should be just a single point relative to UIParent. Maybe store in SV? Set relativeTo = "UIParent"? |
local data = FluidFramesModifiedFrames[frame:GetName()] |
if (data) then |
local point = { frame:GetPoint(1) } |
if (point[2] == UIParent) then |
point[2] = "UIParent" |
frame.FFImmobilized = true |
|
if (not data.immobilized) then |
data.immobilized = {} |
end |
data.immobilized.point = point |
else |
if (data.immobilized) then |
if (not data.immobilized.scale) then |
data.immobilized = nil |
else |
data.immobilized.point = nil |
end |
end |
frame.FFImmobilized = nil |
Print(format(FLUIDFRAMES_CANT_IMMOBILIZE_NOT_UIPARENT, frame:GetName())) |
end |
else |
Print(format(FLUIDFRAMES_CANT_IMMOBILIZE_NO_DEFAULT, frame:GetName())) |
end |
else |
Print(FLUIDFRAMES_CANT_IMMOBILIZE_UNNAMED) |
end |
end |
|
function FluidFrames.ImmobilizeAndStoreDimentions(frame, storeScale, storeDimentions) |
if (frame.GetName and frame:GetName()) then |
if (not frame.FFSetXHooked) then |
hooksecurefunc(frame, "SetPoint", FluidFrames.SetPointHook) |
hooksecurefunc(frame, "SetWidth", FluidFrames.SetWidthHook) |
hooksecurefunc(frame, "SetHeight", FluidFrames.SetHeightHook) |
frame.FFSetXHooked = true |
end |
-- Should be just a single point relative to UIParent. Maybe store in SV? Set relativeTo = "UIParent"? |
local data = FluidFramesModifiedFrames[frame:GetName()] |
if (data) then |
local point = { frame:GetPoint(1) } |
if (point[2] == UIParent) then |
point[2] = "UIParent" |
frame.FFImmobilized = true |
|
if (not data.immobilized) then |
data.immobilized = {} |
end |
data.immobilized.point = point |
if (storeScale) then |
data.immobilized.scale = frame:GetScale() |
end |
if (storeDimentions) then |
data.immobilized.height = frame:GetHeight() |
data.immobilized.width = frame:GetWidth() |
end |
else |
data.immobilized = nil |
frame.FFImmobilized = nil |
Print(format(FLUIDFRAMES_CANT_IMMOBILIZE_NOT_UIPARENT, frame:GetName())) |
end |
else |
Print(format(FLUIDFRAMES_CANT_IMMOBILIZE_NO_DEFAULT, frame:GetName())) |
end |
else |
Print(FLUIDFRAMES_CANT_IMMOBILIZE_UNNAMED) |
end |
end |
|
function FluidFrames.Mobilize(frame) |
frame.FFImmobilized = nil |
if (frame.GetName and frame:GetName()) then |
local data = FluidFramesModifiedFrames[frame:GetName()] |
if (data and data.immobilized) then |
data.immobilized.point = nil |
--data.immobilized = nil |
end |
end |
end |
|
|
---------------------------- |
-- Accociative Reparent Code (Fixes things like dragging ActionBar1 |
---------------------------- |
|
function FluidFrames.FreeFrameSiblingsFromParent(frame, oldParent, newParent, reShow, ...) |
for i=1, select("#", ...) do |
local sibling = select(i, ...) |
if (sibling and sibling:GetParent() == oldParent) then |
if (sibling:GetNumPoints() == 1) then |
local pdata = { sibling:GetPoint(1) } |
if (pdata[2] == frame) then |
if (sibling.GetName) then |
DebugPrint(format(FLUIDFRAMES_REPARENTING_SIBLING, sibling:GetName(), OrNil(oldParent:GetName()), OrNil(newParent:GetName()))) |
end |
sibling:SetParent(newParent) |
--if (reShow and sibling:IsShown()) then |
-- sibling:Show() |
--end |
FluidFrames.FreeFrameSiblingsFromParent(sibling, oldParent, newParent, reShow, ...) |
FluidFrames.FreeFrameSiblingsFromParent(sibling, oldParent, newParent, reShow, ...) |
end |
end |
end |
end |
end |
--/z FluidFrames.FreeFrameSiblingsFromParent(ActionButton1, MainMenuBarArtFrame, UIParent, MainMenuBarArtFrame:GetChildren()) |
--/z FluidFrames.FreeFrameSiblingsFromParent(CharacterMicroButton, MainMenuBarArtFrame, UIParent, MainMenuBarArtFrame:GetChildren()) |
|
--[[ |
function FluidFrames.HasHiddenAncestorFrame(frame) |
local parent = frame:GetParent() |
if (not parent or FluidFrames.ExcludedFrames[parent]) then |
return false |
elseif (parent.FFHidden) then |
return true |
else |
return FluidFrames.HasHiddenAncestorFrame(parent) |
end |
end |
]]-- |
|
function FluidFrames.ReparentAssociatedFrames(frame, oldParent, newParent) |
if (oldParent and oldParent ~= newParent) then |
frame:SetParent(newParent) |
--local reShow = FluidFrames.HasHiddenAncestorFrame(oldParent) |
--if (reShow and frame:IsShown()) then |
-- frame:Show() |
--end |
DebugPrint(format(FLUIDFRAMES_REPARENTING, frame:GetName(), OrNil(oldParent:GetName()), OrNil(newParent:GetName()))) |
FluidFrames.FreeFrameSiblingsFromParent(frame, oldParent, newParent, reShow, oldParent:GetChildren()) |
FluidFrames.FreeFrameSiblingsFromParent(frame, oldParent, newParent, reShow, oldParent:GetRegions()) |
end |
end |
|
function FluidFrames.FreeFrameFromParent(frame) |
local oldParent = frame:GetParent() |
if (oldParent) then |
local newParent = getglobal(FluidFrames.NEW_PARENT) |
FluidFrames.ReparentAssociatedFrames(frame, oldParent, newParent) |
end |
end |
|
function FluidFrames.ResetFrameParent(frame, origParent) |
--local parent = getglobal(FluidFrames.NEW_PARENT) |
local parent = frame:GetParent() |
FluidFrames.ReparentAssociatedFrames(frame, parent, origParent) |
end |
|
---------------------------- |
-- Hide Code |
---------------------------- |
|
function FluidFrames.ShowHook(self) |
if (self.FFHidden) then |
self:Hide() |
end |
end |
|
--/z FluidFrames.LockHiddenFrame(MainMenuBar) |
function FluidFrames.LockHiddenFrame(frame) |
if (frame.GetName and frame:GetName()) then |
if (not frame.FFShowHooked) then |
hooksecurefunc(frame, "Show", FluidFrames.ShowHook) |
frame.FFShowHooked = true |
end |
local data = FluidFramesModifiedFrames[frame:GetName()] |
if (data) then |
DebugPrint(format("Hiding: %s", frame:GetName())) |
frame.FFHidden = true |
data.hidden = true |
data.unitAttr = frame:GetAttribute("unit") |
if (data.unitAttr) then |
frame:SetAttribute("unit", nil) |
end |
frame:Hide() |
FluidFrames.UpdateGUI() |
else |
DebugPrint(format(FLUIDFRAMES_CANT_HIDE, frame:GetName())) |
end |
end |
end |
|
--/z FluidFrames.UnlockHiddenFrame(MainMenuBar) |
--MainMenuBarBackpackButton:Show() |
function FluidFrames.UnlockHiddenFrame(frame) |
if (frame.GetName and frame:GetName()) then |
local data = FluidFramesModifiedFrames[frame:GetName()] |
if (data) then |
DebugPrint(format("Un-hiding: %s", frame:GetName())) |
frame.FFHidden = nil |
data.hidden = nil |
if (data.unitAttr) then |
frame:SetAttribute("unit", data.unitAttr) |
data.unitAttr = nil |
end |
frame:Show() |
FluidFrames.UpdateGUI() |
else |
DebugPrint(format(FLUIDFRAMES_CANT_HIDE, frame:GetName())) |
end |
end |
end |
|
---------------------------- |
-- Reset Code |
---------------------------- |
|
FluidFramesModifiedFrames = {} |
|
function FluidFrames.StoreFrameDefault(frame, storeScale, storeDimentions) |
local name = frame:GetName() |
if (not name) then |
return |
end |
local data = FluidFramesModifiedFrames[name] |
if (not data) then |
data = {} |
end |
if (storeScale and not data.scale) then |
data.scale = frame:GetScale() |
end |
if (storeDimentions and (not data.height or not data.width)) then |
data.height = frame:GetHeight() |
data.width = frame:GetWidth() |
end |
if (not data.parent) then |
local parent = frame:GetParent() |
data.parent = parent and parent:GetName() or parent |
end |
if (not data.point) then |
data.point = {} |
for i=1, frame:GetNumPoints() do |
local pdata = { frame:GetPoint(i) } |
--{ point, relativeTo, relativePoint, xofs, yofs } |
if (pdata[2] and pdata[2].GetName and pdata[2]:GetName()) then |
pdata[2] = pdata[2]:GetName() |
tinsert(data.point, pdata) |
else |
--No anchor name.... won't save accross sessions (deleted on VARIABLES_LOADED). |
Print(format(FLUIDFRAMES_UNNAMED_ANCHOR, name)) |
tinsert(data.point, pdata) |
end |
end |
end |
if (not FluidFramesModifiedFrames[name]) then |
FluidFramesModifiedFrames[name] = data |
FluidFrames.UpdateGUI() |
end |
end |
|
function FluidFrames.ResetFrame(frame) |
-- Remove saved position regardless. |
frame:SetUserPlaced(nil) |
|
local name = frame:GetName() |
if (not name) then |
Print(FLUIDFRAMES_CANT_RESET_UNNAMED) |
return |
elseif (not FluidFramesModifiedFrames[name]) then |
Print(format(FLUIDFRAMES_CANT_RESET_NO_DEFAULT, name)) |
return |
end |
local data = FluidFramesModifiedFrames[name] |
--WOW Crash!!! uncomment this and reset a frame. FluidFrames.RescaleFrame(frame, data.width/frame:GetWidth(), data.height/frame:GetHeight()) |
|
FluidFrames.Mobilize(frame) |
|
if (type(data.parent) == "string") then |
local parent = getglobal(data.parent) |
if (parent) then |
FluidFrames.ResetFrameParent(frame, parent) |
end |
elseif (type(data.parent) == "table") then |
FluidFrames.ResetFrameParent(frame, data.parent) |
end |
|
if (data.scale) then |
frame:SetScale(data.scale) |
end |
|
if (data.width and data.height) then |
local widthScale = data.width/frame:GetWidth() |
local heightScale = data.height/frame:GetHeight() |
FluidFrames.RescaleFrame(frame, widthScale, heightScale, true) |
end |
|
frame:ClearAllPoints() |
for i=1, #data.point do |
frame:SetPoint(data.point[i][1], data.point[i][2], data.point[i][3], data.point[i][4], data.point[i][5]) |
end |
|
FluidFrames.UnlockHiddenFrame(frame) |
|
FluidFramesModifiedFrames[name] = nil |
|
-- Refresh frame with it's OnShow updates |
frame:Hide() |
frame:Show() |
|
FluidFrames.DragFrame.frame = nil |
FluidFrames.DragFrame:Hide() |
|
FluidFrames.UpdateGUI() |
Print(format(FLUIDFRAMES_RESET, name)) |
end |
|
function FluidFrames.ResetAll() |
FluidFrames.DoNotUpdateGUI = true |
for k,v in pairs(FluidFramesModifiedFrames) do |
local frame = getglobal(k) |
if (frame) then |
FluidFrames.ResetFrame(frame) |
else |
Print(format(FLUIDFRAMES_CANT_RESET_NOT_FOUND, k)) |
end |
end |
FluidFrames.DoNotUpdateGUI = nil |
FluidFrames.UpdateGUI() |
Print(FLUIDFRAMES_RESET_ALL_FINISHED) |
end |
|
SlashCmdList["FLUIDFRAMESSLASH"] = FluidFrames.ResetAll; |
|
function FluidFrames.ReshowAll() |
FluidFrames.DoNotUpdateGUI = true |
for k,v in pairs(FluidFramesModifiedFrames) do |
local frame = getglobal(k) |
if (frame and frame.FFHidden) then |
FluidFrames.UnlockHiddenFrame(frame) |
end |
end |
FluidFrames.DoNotUpdateGUI = nil |
FluidFrames.UpdateGUI() |
Print(FLUIDFRAMES_RESHOW_ALL_FINISHED) |
end |
|
|
---------------------------- |
-- Portfolio Registration |
---------------------------- |
|
function FluidFrames.UpdateGUI() |
if (Portfolio) then |
if (not FluidFrames.DoNotUpdateGUI) then |
--TODO: add update options to show hidden and moved frames |
--FluidFrames.RegisterPortfolio(true) |
end |
end |
end |
|
function FluidFrames.RegisterPortfolio() |
local optionTable = { |
id="FluidFrames"; |
subText=FLUIDFRAMES_DESC_FULL; |
options={ |
-- Pulls the first header and helptext from the addon toc data |
{ |
id = "TempDraggable"; |
tvar = "TempDraggable", |
text = FLUIDFRAMES_TEMP_DRAGGABLE; |
type = CONTROLTYPE_CHECKBOX; |
callback = function(value) |
FluidFrames.ToggleTempDraggableFrames(value == "1") |
end; |
defaultValue = "1", |
}; |
{ |
id = "Reset"; |
text = FLUIDFRAMES_RESET_ALL; |
type = CONTROLTYPE_BUTTON; |
callback = FluidFrames.ResetAll; |
point = {nil, nil, nil, 0, -30}; |
}; |
{ |
id = "Reshow"; |
text = FLUIDFRAMES_RESHOW_ALL; |
type = CONTROLTYPE_BUTTON; |
callback = FluidFrames.ReshowAll; |
point = {"TOPLEFT", "Reset", "TOPRIGHT", 40, 0}; |
}; |
{ |
id = "Help"; |
text = FLUIDFRAMES_HELP_HEADER; |
subText = FLUIDFRAMES_HELP1..FLUIDFRAMES_NEWLINE..FLUIDFRAMES_NEWLINE |
..FLUIDFRAMES_HELP2..FLUIDFRAMES_NEWLINE |
..FLUIDFRAMES_HELP3..FLUIDFRAMES_NEWLINE |
..FLUIDFRAMES_HELP4..FLUIDFRAMES_NEWLINE |
..FLUIDFRAMES_HELP5..FLUIDFRAMES_NEWLINE..FLUIDFRAMES_NEWLINE |
..FLUIDFRAMES_HELP6..FLUIDFRAMES_NEWLINE..FLUIDFRAMES_NEWLINE |
..FLUIDFRAMES_HELP7..FLUIDFRAMES_NEWLINE..FLUIDFRAMES_NEWLINE |
..FLUIDFRAMES_HELP8; |
type = CONTROLTYPE_HEADER; |
point = {nil, "Reset", nil, nil, -40}; |
init = function(header, subtext) |
subtext:SetHeight(140) |
end; |
}; |
}; |
savedVarTable = "FluidFrames_SavedVars"; |
loadVars = true; |
} |
|
Portfolio.RegisterOptionSet(optionTable) |
end |
|
|
---------------------------- |
-- OnLoad Inits |
---------------------------- |
FluidFrames.InitDraggableFrame() |
FluidFrames.InitEventFrame() |
|