Skip to content

Commit

Permalink
[caelUI - modules] We can now create a backdrop on modules via :Creat…
Browse files Browse the repository at this point in the history
…eBackdrop(). Use locals over globals. Change the way :GetMedia() is referenced.
  • Loading branch information
memborsky committed Dec 10, 2011
1 parent 6ec2bdb commit ff485ff
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
44 changes: 38 additions & 6 deletions caelUI/core/modules.lua
Expand Up @@ -2,6 +2,7 @@ local private = unpack(select(2, ...))

-- Localized variables
local PixelScale = private.PixelScale
local media = private.media

-- We use this to reference a blank frame for calling frame related functions when we modify them.
local reference_frame = CreateFrame("Frame")
Expand Down Expand Up @@ -34,10 +35,6 @@ module_metatable.__index.IsEventRegistered = private.events.IsEventRegistered
-- Format money output
module_metatable.__index.FormatMoney = private.format_money

function module_metatable.__index:GetMedia()
return private.media
end

-- Rewrite the SetPoint on our frame so we can use PixelScale here instead of in the actual module.
function module_metatable.__index:SetPoint(...)
local argument_count = #(...)
Expand All @@ -54,16 +51,48 @@ function module_metatable.__index:SetPoint(...)
reference_frame.SetPoint(self, ...)
end
end

self:Print("Hello from SetPoint.")
end

function module_metatable.__index:CreateBackdrop()
local name

if self.name then
name = self.name .. "Backdrop"
elseif self.GetParent and self:GetParent():GetName() then
name = self:GetParent():GetName() .. "Backdrop"
else
name = nil
end

self.backdrop = CreateFrame("Frame", name, self)
self.SetPoint(self.backdrop, "TOPLEFT", self, "TOPLEFT", -2, 2)
self.SetPoint(self.backdrop, "BOTTOMRIGHT", self, "BOTTOMRIGHT", 2, -2)
self.backdrop:SetFrameLevel(self:GetFrameLevel() - 1 > 0 and self:GetFrameLevel() - 1 or 0)
self.backdrop:SetBackdrop(media.backdrop_table)
self.backdrop:SetBackdropColor(0, 0, 0, 0.4)
self.backdrop:SetBackdropBorderColor(0, 0, 0, 1)
self.backdrop:SetFrameStrata("BACKGROUND")
end

-- If the module doesn't pass in a name and we are creating a frame, we need to assign it a name so we can
-- have better global management of it.
local system_count = 0

function CreateModule(name, create_frame)
-- Make a black table if we aren't to be create a frame
local self = {}

-- If we are creating this module as a frame, we need to create the frame and overwrite some of the
-- frame functions to be managed our way and to make the code a in the module look a lot cleaner.
if create_frame then
self = CreateFrame("Frame", "caelUI_" .. name, UIParent)
self = CreateFrame("Frame", "caelUI_" .. name and name or "SystemGenerated" .. system_count, UIParent)

-- Increase the system counter if we had no named passed in.
if not name then
system_count = system_count + 1
end
end

-- Set our modules metatable to our returned self.
Expand All @@ -74,7 +103,10 @@ function CreateModule(name, create_frame)

-- We pass the PixelScale function with the table/frame we create because we occasionally still need
-- it on frame modifications that are not created with this function.
self.PixelScale = private.PixelScale
self.PixelScale = PixelScale

-- Return the media table so we don't have to include private in our modules.
self.GetMedia = function() return media end

-- Return the data.
return self
Expand Down
8 changes: 1 addition & 7 deletions caelUI/modules/blizzard/skin/timer_bars.lua
Expand Up @@ -51,13 +51,7 @@ do
statusbar:SetAllPoints(bar)
end

bar.backdrop = CreateFrame("Frame", nil, bar)
bar.backdrop:SetFrameLevel(bar:GetFrameLevel() - 1)
bar.backdrop:SetPoint("TOPLEFT", bar, "TOPLEFT", PixelScale(-2), PixelScale(2))
bar.backdrop:SetPoint("BOTTOMRIGHT", bar, "BOTTOMRIGHT", PixelScale(2), PixelScale(-2))
bar.backdrop:SetBackdrop(media.backdrop_table)
bar.backdrop:SetBackdropBorderColor(0, 0, 0)
bar.backdrop:SetBackdropColor(0, 0, 0, 0.4)
TimerBars.CreateBackdrop(bar)

bar.skinned = true
end
Expand Down

0 comments on commit ff485ff

Please sign in to comment.