WoWInterface SVN zzcommon

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /
    from Rev 108 to Rev 109
    Reverse comparison

Rev 108 → Rev 109

trunk/LibCommon/frames.lua
1,6 → 1,6
local name, addon = ...
 
local embed = addon:LibInit("zzCommon-Frames", 13, {'AddDrag','LoadFrame','GetFrameCoords','CreateSecureFrame'})
local embed = addon:LibInit("zzCommon-Frames", 14, {'AddDrag','LoadFrame','GetFrameCoords','CreateSecureFrame'})
if(type(embed) ~= 'function') then return end
local base = LibStub('zzCommon-Frames')
base['frames'] = base['frames'] or {}
9,7 → 9,7
return math.floor(num * (10^(idp or 0)) + 0.5) / (10^(idp or 0))
end
 
local function dragAble(self)
local function dragAble()
return true
end
 
27,38 → 27,36
['db'] = {},
}
 
local function setDefaultValues(self)
if(not self['db'] and self['name'] and addon['db']) then
addon['db']['profile'][self['name']] = addon['db']['profile'][self['name']] or {}
addon['db']['profile'][self['name']]['points'] = addon['db']['profile'][self['name']]['points'] or {}
self['db'] = addon['db']['profile'][self['name']]['points']
local function setDefaultValues(frame)
if(not frame['db'] and frame['name'] and addon['db']) then
addon['db']['profile'][frame['name']] = addon['db']['profile'][frame['name']] or {}
addon['db']['profile'][frame['name']]['points'] = addon['db']['profile'][frame['name']]['points'] or {}
frame['db'] = addon['db']['profile'][frame['name']]['points']
end
for k, v in pairs(defaults) do
if(self[k] == nil) then
self[k] = v
if(frame[k] == nil) then
frame[k] = v
end
end
return self
return frame
end
 
local function saveFrame(self)
local db = self['db']
local fn = self:GetName()
local function saveFrame(frame)
local db = frame['db']
local fn = frame:GetName()
db[fn] = db[fn] or {
['xpos'] = 0,
['ypos'] = 0,
}
local x, y = self:GetCenter()
local s = self:GetEffectiveScale()
local x, y = frame:GetCenter()
local s = frame:GetEffectiveScale()
local uis = UIParent:GetScale()
x = x*s - GetScreenWidth()*uis/2
y = y*s - GetScreenHeight()*uis/2
db[fn]['xpos'] = addon['round'](x/uis,0)
db[fn]['ypos'] = addon['round'](y/uis,0)
db[fn]['xpos'] = addon:round(x/uis,0)
db[fn]['ypos'] = addon:round(y/uis,0)
end
 
local function loadFrame() end -- dummy
 
local schedules = {}
local scheduleframe = CreateFrame("Frame")
scheduleframe:SetScript("OnEvent", function(self, event)
69,9 → 67,9
self:UnregisterEvent(event)
end)
 
local function addSchedule(self, func)
local function addSchedule(frame, func)
schedules[#schedules + 1] = {
['frame'] = self,
['frame'] = frame,
['func'] = func,
}
if(#schedules == 1) then
79,137 → 77,136
end
end
 
local function getCoords(self)
local s = self:GetEffectiveScale()
local function getCoords(frame)
local s = frame:GetEffectiveScale()
local uis = UIParent:GetScale()
local fn = self:GetName()
return self['db'][fn]['xpos']*uis/s, self['db'][fn]['ypos']*uis/s
local fn = frame:GetName()
return frame['db'][fn]['xpos']*uis/s, frame['db'][fn]['ypos']*uis/s
end
 
loadFrame = function(self) -- local because of previous dummy
if not self then return end
local function loadFrame(frame)
if not frame then return end
if( InCombatLockdown() ) then
addSchedule(self, loadFrame)
addSchedule(frame, loadFrame)
return
end
self:SetMovable(true)
local db = self['db']
local fn = self:GetName()
frame:SetMovable(true)
local db = frame['db']
local fn = frame:GetName()
db[fn] = db[fn] or {
['xpos'] = 0,
['ypos'] = 0,
}
local x, y = getCoords(self)
self:ClearAllPoints()
self:SetPoint("CENTER", UIParent, "CENTER", x, y)
self:SetUserPlaced(true)
local x, y = getCoords(frame)
frame:ClearAllPoints()
frame:SetPoint("CENTER", UIParent, "CENTER", x, y)
frame:SetUserPlaced(true)
end
 
local function dragView2(self)
if(IsAltKeyDown() and self['dragAble']()) then
self['tex']:SetTexture(0, .5, 0, .5)
local function dragView2(frame)
if(IsAltKeyDown() and frame['dragAble']()) then
frame['tex']:SetTexture(0, .5, 0, .5)
else
self['tex']:SetTexture(0, 0, 0 , 0)
frame['tex']:SetTexture(0, 0, 0 , 0)
end
end
 
local function storePoints(self)
wipe(self['db'])
for i = 1, self:GetNumPoints() do
 
self['db'][#self['db'] + 1] = {self:GetPoint(i)}
self['db'][#self['db']][2] = self['db'][#self['db']][2] and self['db'][#self['db']][2]:GetName() or "UIParent"
self['db'][#self['db']][4] = round(self['db'][#self['db']][4])
self['db'][#self['db']][5] = round(self['db'][#self['db']][5])
-- print("save", self:GetName(),self:GetPoint(i),self['db'][#self['db']][4],self['db'][#self['db']][5])
local function storePoints(frame)
wipe(frame['db'])
for i = 1, frame:GetNumPoints() do
frame['db'][#frame['db'] + 1] = {frame:GetPoint(i)}
frame['db'][#frame['db']][2] = frame['db'][#frame['db']][2] and frame['db'][#frame['db']][2]:GetName() or "UIParent"
frame['db'][#frame['db']][4] = round(frame['db'][#frame['db']][4])
frame['db'][#frame['db']][5] = round(frame['db'][#frame['db']][5])
print("save", frame:GetName(),frame:GetPoint(i),frame['db'][#frame['db']][4],frame['db'][#frame['db']][5])
end
end
 
local function restorePoints(self)
if(#self['db']<1) then
storePoints(self)
local function restorePoints(frame)
if(#frame['db']<1) then
storePoints(frame)
end
self:ClearAllPoints()
for i = 1, #self['db'] do
if(self['db'][i][2] == "UIParent") then
self['db'][i][2] = UIParent
frame:ClearAllPoints()
for i = 1, #frame['db'] do
if(frame['db'][i][2] == "UIParent") then
frame['db'][i][2] = UIParent
end
-- print("load", self:GetName(),self['db'][i][1],_G[self['db'][i][2]],self['db'][i][3],self['db'][i][4],self['db'][i][5])
self:SetPoint(self['db'][i][1],self['db'][i][2] == "UIParent" and UIParent or _G[self['db'][i][2]],self['db'][i][3],self['db'][i][4],self['db'][i][5])
print("load", frame:GetName(),frame['db'][i][1],_G[frame['db'][i][2]],frame['db'][i][3],frame['db'][i][4],frame['db'][i][5])
frame:SetPoint(frame['db'][i][1],frame['db'][i][2] == "UIParent" and UIParent or _G[frame['db'][i][2]],frame['db'][i][3],frame['db'][i][4],frame['db'][i][5])
end
 
end
local function toggle(self)
if(self:IsVisible()) then
self:Hide()
local function toggle(frame)
if(frame:IsVisible()) then
frame:Hide()
else
self:Show()
frame:Show()
end
end
 
local function center(self)
self:ClearAllPoints()
self:SetPoint("Center", UIParent,"Center",0,0)
saveFrame(self)
local function center(frame)
frame:ClearAllPoints()
frame:SetPoint("Center", UIParent,"Center",0,0)
saveFrame(frame)
end
 
local function center2(self)
self:ClearAllPoints()
self:SetPoint("Center", UIParent,"Center",0,0)
storePoints(self)
local function center2(frame)
frame:ClearAllPoints()
frame:SetPoint("Center", UIParent,"Center",0,0)
storePoints(frame)
end
 
local function startMove(self)
local function startMove(frame)
if InCombatLockdown() then return end
if(self['locked']) then return end
if(self['moveparent']) then
self:GetParent():StartMoving()
self:GetParent():SetUserPlaced(false)
if(frame['locked']) then return end
if(frame['moveparent']) then
frame:GetParent():StartMoving()
frame:GetParent():SetUserPlaced(false)
else
self:StartMoving()
self:SetUserPlaced(false)
frame:StartMoving()
frame:SetUserPlaced(false)
end
 
end
 
local function stopMove(self)
if(self['moveparent']) then
self:GetParent():StopMovingOrSizing()
saveFrame(self:GetParent())
local function stopMove(frame)
if(frame['moveparent']) then
frame:GetParent():StopMovingOrSizing()
saveFrame(frame:GetParent())
else
self:StopMovingOrSizing()
saveFrame(self)
frame:StopMovingOrSizing()
saveFrame(frame)
end
end
 
local function startMove2(self)
if(not self:dragAble()) then return end
self:StartMoving()
self:SetUserPlaced(false)
local function startMove2(frame)
if(not frame:dragAble()) then return end
frame:StartMoving()
frame:SetUserPlaced(false)
end
 
local function stopMove2(self)
self:StopMovingOrSizing()
storePoints(self)
local function stopMove2(frame)
frame:StopMovingOrSizing()
storePoints(frame)
end
 
local function dragView(self)
if(IsAltKeyDown() and self:GetParent()['dragAble']() and not InCombatLockdown()) then
self['tex']:SetTexture(0, .5, 0, .5)
self:Show()
local function dragView(frame)
if(IsAltKeyDown() and frame:GetParent()['dragAble']() and not InCombatLockdown()) then
frame['tex']:SetTexture(0, .5, 0, .5)
frame:Show()
else
if(self:IsVisible()) then
self['tex']:SetTexture(0, 1, 0 , 0)
stopMove(self)
self:Hide()
if(frame:IsVisible()) then
frame['tex']:SetTexture(0, 1, 0 , 0)
stopMove(frame)
frame:Hide()
end
end
end
local function checkShow(self, elapsed)
self['elapsed'] = self['elapsed'] + elapsed
if(self['elapsed']>1) then
dragView(self)
self['elapsed'] = 0
local function checkShow(frame, elapsed)
frame['elapsed'] = frame['elapsed'] + elapsed
if(frame['elapsed']>1) then
dragView(frame)
frame['elapsed'] = 0
end
end
local lib = {}