Add events that can be hooked to track the changing of colours.

Mere [07-13-13 - 13:25]
Add events that can be hooked to track the changing of colours.

Update HealingBar to track the colour changes for the bar, IE mana and health colours.
Filename
Colours.lua
HealingBar.lua
MereHealingFrames.lua
diff --git a/Colours.lua b/Colours.lua
index 3d516bb..bce7aee 100644
--- a/Colours.lua
+++ b/Colours.lua
@@ -4,6 +4,9 @@

 local MereHealingFrames, privateVars = ...

+local colourChangeFuncs = {}
+local colourChangeEvents = {}
+
 MereHealingFrames.CurrentColours = {}

 MereHealingFrames.DefaultColours = {
@@ -181,18 +184,37 @@ end
 function MereHealingFrames.Colours.Clear(name)
 	if MereHealingFrames.CurrentColours[name] then
 		MereHealingFrames.CurrentColours[name] = nil
+
+        local defaultColour = MereHealingFrames.DefaultColours[name]
+        colourChangeFuncs[name](defaultColour.r, defaultColour.g, defaultColour.b, defaultColour.a or 1.0)
 	end
 end

 function MereHealingFrames.Colours.Update(name, r, g, b, a)
-	if  not MereHealingFrames.DefaultColours[name] then
+	if not MereHealingFrames.DefaultColours[name] then
 		return false
 	end

 	MereHealingFrames.CurrentColours[name] = { r = r, g = g, b = b, a = a or 1.0 }
+    colourChangeFuncs[name](r, g, b, a or 1.0)
+
 	return true
 end

 function MereHealingFrames.Colours.ResetAll()
+    for colourName, colourDetail in pairs(MereHealingFrames.CurrentColours) do
+        local defaultColour = MereHealingFrames.DefaultColours[colourName]
+        colourChangeFuncs[colourName](defaultColour.r, defaultColour.g, defaultColour.b, defaultColour.a or 1.0)
+    end
+
 	MereHealingFrames.CurrentColours = {}
+end
+
+function MereHealingFrames.Colours.RegisterEventHooks()
+    for colourName, colourDetails in pairs(MereHealingFrames.DefaultColours) do
+        local EventPath =  'Colours.' .. colourName
+        local caller, handle = Utility.Event.Create("MereHealingFrames", EventPath)
+        colourChangeFuncs[colourName] = caller
+        colourChangeEvents[colourName] = handle
+    end
 end
\ No newline at end of file
diff --git a/HealingBar.lua b/HealingBar.lua
index 014d51f..2dc1a83 100644
--- a/HealingBar.lua
+++ b/HealingBar.lua
@@ -28,7 +28,10 @@ MereHealingFrames.HealingBar = {
     valueChangeEvent = nil,
     maxValueChangeEvent = nil,
     updateValueFunction = nil,
-    updateMaxValueFunction = nil
+    updateMaxValueFunction = nil,
+
+    colourChangeEvent = nil,
+    colourChangeFunction = nil
 	}

 local healingBarId = 1
@@ -44,6 +47,7 @@ function MereHealingFrames.HealingBar:new (settings)
     this.updateValueFunction = function(handle, value) MereHealingFrames.HealingBar.UpdateValue(this, value) end
     this.updateMaxValueFunction = function(handle, value) MereHealingFrames.HealingBar.UpdateMax(this, value) end

+    this.colourChangeFunction = function (handle, r, g, b, a) MereHealingFrames.HealingBar.ChangeColourRGBA(this, r, g, b, a) end
     return this
 end

@@ -317,6 +321,16 @@ function MereHealingFrames.HealingBar:ChangeColour(colour)
 	self.Bar:SetBackgroundColor(colour.r, colour.g, colour.b, colour.a)
 end

+function MereHealingFrames.HealingBar:ChangeColourRGBA(r, g, b, a)
+    if not self.framesLoaded then return end
+    self.Bar:SetBackgroundColor(r, g, b, a)
+end
+
+function MereHealingFrames.HealingBar:ChangeColourSource(colourName)
+    self:ChangeColour(MereHealingFrames.Colours.FetchColour(colourName))
+    self:ReplaceEventHandler("colourChangeEvent", Event.MereHealingFrames.Colours[colourName], self.colourChangeFunction)
+end
+
 function MereHealingFrames.HealingBar:SetBarMode(barMode)
 	self.barMode = barMode

@@ -325,16 +339,16 @@ function MereHealingFrames.HealingBar:SetBarMode(barMode)
     end

     if barMode == "rogue" then
-		self:ChangeColour(MereHealingFrames.Colours.FetchColour("BarRogue"))
+		self:ChangeColourSource("BarRogue")
         self.Text:SetFontColor(MereHealingFrames.Colours.FetchRGB("EnergyBarText"))
         self.Text:SetShadowColor(MereHealingFrames.Colours.FetchRGB("EnergyBarTextShadow"))
 	elseif barMode == "warrior" then
-		self:ChangeColour(MereHealingFrames.Colours.FetchColour("BarWarrior"))
-        self.Text:SetFontColor(MereHealingFrames.Colours.FetchRGB("PowerBarText"))
+        self:ChangeColourSource("BarWarrior")
+		self.Text:SetFontColor(MereHealingFrames.Colours.FetchRGB("PowerBarText"))
         self.Text:SetShadowColor(MereHealingFrames.Colours.FetchRGB("PowerBarTextShadow"))
 	elseif barMode == "mana" then
-		self:ChangeColour(MereHealingFrames.Colours.FetchColour("BarMana"))
-        self.Text:SetFontColor(MereHealingFrames.Colours.FetchRGB("ManaBarText"))
+        self:ChangeColourSource("BarMana")
+		self.Text:SetFontColor(MereHealingFrames.Colours.FetchRGB("ManaBarText"))
         self.Text:SetShadowColor(MereHealingFrames.Colours.FetchRGB("ManaBarTextShadow"))
 	elseif barMode == "health" then
 		self:UpdateHealthBarColour()
@@ -382,8 +396,8 @@ function MereHealingFrames.HealingBar:UpdateHealthBarColour()
 			elseif callingName == "rogue" then
 				barColour = "RogueColour"
 			end
-		end
-		self:ChangeColour(MereHealingFrames.Colours.FetchColour(barColour))
+        end
+        self:ChangeColourSource(barColour)
 	end
 end

diff --git a/MereHealingFrames.lua b/MereHealingFrames.lua
index 3014e0b..6adbc38 100644
--- a/MereHealingFrames.lua
+++ b/MereHealingFrames.lua
@@ -14,6 +14,8 @@ MereHealingFrames.ToolTip.Initialize(MereHealingFrames.context)
 MereHealingFrames.PlayerId = Inspect.Unit.Lookup("player")
 MereHealingFrames.SpellRange = 35

+MereHealingFrames.Colours.RegisterEventHooks()
+
 MereHealingFrames.Config.window = MereHealingFrames.Config.UI:new()

 function MereHealingFrames.fetchVersion()