[gbrainy] Fixes timer sync for Countdown view



commit 31f9fb8bda3eacec8e6664aa233238af7985c09c
Author: Jordi Mas <jmas softcatala org>
Date:   Sat Nov 21 13:41:50 2009 +0100

    Fixes timer sync for Countdown view

 src/Core/Main/Memory.cs         |   19 +++++++++++++++----
 src/Core/Views/CountDownView.cs |   19 +++++++++++++++----
 2 files changed, 30 insertions(+), 8 deletions(-)
---
diff --git a/src/Core/Main/Memory.cs b/src/Core/Main/Memory.cs
index fc149e0..8efae47 100644
--- a/src/Core/Main/Memory.cs
+++ b/src/Core/Main/Memory.cs
@@ -77,7 +77,7 @@ namespace gbrainy.Core.Main
 			}
 
 			downview = new CountDownView (OnCountDownFinish);
-			downview.RequestRedraw += OnCountDownRedraw;
+			downview.DrawRequest += OnCountDownRedraw;
 		}
 
 		public void OnCountDownRedraw (object o, EventArgs args)
@@ -85,11 +85,20 @@ namespace gbrainy.Core.Main
 			OnDrawRequest ();
 		}
 
+		void FinishCountDown ()
+		{
+			downview.EndDrawCountDown ();
+			downview.DrawRequest -= OnCountDownRedraw;
+			downview = null;
+		}
+
 		void OnCountDownFinish (object source, EventArgs e)
 		{
 			downview.EndDrawCountDown ();
-			InitializeGame ();
+			downview.DrawRequest -= OnCountDownRedraw;
 			downview = null;
+
+			InitializeGame ();
 		}
 
 		void InitializeGame ()
@@ -110,7 +119,6 @@ namespace gbrainy.Core.Main
 
 		public void StartTimer ()
 		{
-			Console.WriteLine ("Memory.StartTimer {0}", SynchronizingObject);
 			timer.Enabled = true;
 			draw_timer = true;
 		}
@@ -150,7 +158,10 @@ namespace gbrainy.Core.Main
 
 		public override void Finish ()
 		{
-			timer.Enabled = false;
+			if (downview != null)
+				FinishCountDown ();
+			else 
+				timer.Enabled = false;
 		}		
 
 		public override void Draw (CairoContextEx gr, int area_width, int area_height, bool rtl)
diff --git a/src/Core/Views/CountDownView.cs b/src/Core/Views/CountDownView.cs
index c1bdb2f..d49d44e 100644
--- a/src/Core/Views/CountDownView.cs
+++ b/src/Core/Views/CountDownView.cs
@@ -22,27 +22,38 @@ using System;
 using Cairo;
 using Mono.Unix;
 using System.Timers;
+using System.ComponentModel;
 
 using gbrainy.Core.Libraries;
 
 namespace gbrainy.Core.Views
 {
-	public class CountDownView : IDrawable
+	public class CountDownView : IDrawable, IDrawRequest
 	{
 		static int countdown_time;
 		System.Timers.Timer timer;
 		EventHandler finish;
-		public event EventHandler RequestRedraw; // Not used in this view
+		ISynchronizeInvoke synchronize;
+
+		public event EventHandler DrawRequest; // Not used in this view
 
 		public CountDownView (EventHandler OnFinish)
 		{
 			timer = new System.Timers.Timer ();
 			timer.Elapsed += TimerUpdater;
+			timer.SynchronizingObject = SynchronizingObject;
 			timer.Interval = (1 * 1000); // 1 second
 			finish = OnFinish;
 			Start ();
 		}
 
+		public ISynchronizeInvoke SynchronizingObject { 
+			set { 
+				synchronize = value;
+			}
+			get { return synchronize; }
+		}
+
 		public void Start ()
 		{
 			countdown_time = 3;
@@ -95,8 +106,8 @@ namespace gbrainy.Core.Views
 				
 				}
 				countdown_time--;
-				if (RequestRedraw != null)
-					RequestRedraw (this, EventArgs.Empty);
+				if (DrawRequest != null)
+					DrawRequest (this, EventArgs.Empty);
 			}
 		}
 	}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]