From 9ae142aa9669a3d744e197a44950b04e05fa1514 Mon Sep 17 00:00:00 2001
From: jsiegle <joshs@alleninstitute.org>
Date: Tue, 23 Sep 2014 14:05:43 -0700
Subject: [PATCH] Simplify MessageCenter animation code

---
 .../Editors/MessageCenterEditor.cpp           | 81 ++++---------------
 1 file changed, 14 insertions(+), 67 deletions(-)

diff --git a/Source/Processors/Editors/MessageCenterEditor.cpp b/Source/Processors/Editors/MessageCenterEditor.cpp
index 92972ce10..e98395203 100644
--- a/Source/Processors/Editors/MessageCenterEditor.cpp
+++ b/Source/Processors/Editors/MessageCenterEditor.cpp
@@ -59,85 +59,27 @@ void MessageCenterEditor::buttonClicked(Button* button)
 void MessageCenterEditor::labelTextChanged(Label* label)
 {
 
-	if (label == incomingMessageDisplayArea)
-	{
-		incomingBackground = Colours::orange;
-		startTimer(20);
-	}
 }
 
 void MessageCenterEditor::timerCallback()
 {
 
-	uint8 defaultValue = 100;
-
-	uint8 inRed = incomingBackground.getRed();
-	uint8 inGreen = incomingBackground.getGreen();
-	uint8 inBlue = incomingBackground.getBlue();
-
-	uint8 outRed = outgoingBackground.getRed();
-	uint8 outGreen = outgoingBackground.getGreen();
-	uint8 outBlue = outgoingBackground.getBlue();
-
 	bool shouldRepaint = false;
 
-	if (inGreen > defaultValue)
-	{
-		inGreen -= 1; shouldRepaint = true;
-	}
-	else if (inGreen < defaultValue)
-	{
-		inGreen += 1; shouldRepaint = true;
-	}
+	float incomingAlpha = incomingBackground.getFloatAlpha();
 
-	if (inRed > defaultValue)
+	if (incomingAlpha > 0)
 	{
-		inRed -= 1; shouldRepaint = true;
-	}
-	else if (inRed < defaultValue)
-	{
-		inRed += 1; shouldRepaint = true;
-	}
+		incomingAlpha -= 0.05;
 
-	if (inBlue > defaultValue)
-	{
-		inBlue -= 1; shouldRepaint = true;
-	}
-	else if (inBlue < defaultValue)
-	{
-		inBlue += 1; shouldRepaint = true;
-	}
+		if (incomingAlpha < 0)
+			incomingAlpha = 0;
 
-	if (outGreen > defaultValue)
-	{
-		outGreen -= 1; shouldRepaint = true;
-	}
-	else if (outGreen < defaultValue)
-	{
-		outGreen += 1; shouldRepaint = true;
-	}
-
-	if (outRed > defaultValue)
-	{
-		outRed -= 1; shouldRepaint = true;
-	}
-	else if (outRed < defaultValue)
-	{
-		outRed += 1; shouldRepaint = true;
-	}
+		incomingBackground = incomingBackground.withAlpha(incomingAlpha);
 
-	if (outBlue > defaultValue)
-	{
-		outBlue -= 1; shouldRepaint = true;
-	}
-	else if (outBlue < defaultValue)
-	{
-		outBlue += 1; shouldRepaint = true;
+		shouldRepaint = true;
 	}
 
-	incomingBackground = Colour(inRed, inGreen, inBlue);
-	outgoingBackground = Colour(outRed, outGreen, outBlue);
-
 	if (shouldRepaint)
 		repaint();
 	else
@@ -177,7 +119,7 @@ void MessageCenterEditor::messageReceived(bool state)
 		incomingBackground = Colours::green;
 	}
 
-	startTimer(20);
+	startTimer(75);
 }
 
 void MessageCenterEditor::paint(Graphics& g)
@@ -187,6 +129,11 @@ void MessageCenterEditor::paint(Graphics& g)
 
     g.fillRect(0, 0, getWidth(), getHeight());
 
+    g.setColour(Colour(100,100,100));
+
+    g.fillRect(5, 5, getWidth()/2-5, getHeight()-10);
+    g.fillRect(getWidth()/2+5, 5, getWidth()/2-60, getHeight()-10);
+
     g.setColour(incomingBackground);
 
     g.fillRect(5, 5, getWidth()/2-5, getHeight()-10);
@@ -215,7 +162,7 @@ void MessageCenterEditor::actionListenerCallback(const String& message)
     incomingMessageDisplayArea->setText(message, sendNotification);
 
     incomingBackground = Colours::orange;
-    startTimer(20);
+    startTimer(75);
 
 }
 
-- 
GitLab