[gbrainy] Mouse support for memory and calculation games



commit 545c2dd2590c476c91dd76502d7654e575718ebf
Author: Jordi Mas <jmas softcatala org>
Date:   Sat Feb 6 13:30:55 2010 +0100

    Mouse support for memory and calculation games

 sample_extensions/Memory/MemorySample.cs           |    2 +-
 src/Core/Libraries/CairoContextEx.cs               |    2 +-
 src/Core/Main/Game.cs                              |   17 +++-
 src/Core/Main/Memory.cs                            |   20 +++--
 src/Games/Calculation/CalculationAverage.cs        |   33 +++++---
 src/Games/Calculation/CalculationCloserFraction.cs |   39 ++++++----
 src/Games/Calculation/CalculationProportions.cs    |   35 +++++----
 src/Games/Logic/PuzzleMatrixNumbers.cs             |   11 ++-
 src/Games/Memory/MemoryColouredFigures.cs          |   57 +++++++++-----
 src/Games/Memory/MemoryColouredText.cs             |    4 +-
 src/Games/Memory/MemoryCountDots.cs                |    4 +-
 src/Games/Memory/MemoryFacts.cs                    |    6 +-
 src/Games/Memory/MemoryFigures.cs                  |    6 +-
 src/Games/Memory/MemoryFiguresAndText.cs           |    6 +-
 src/Games/Memory/MemoryFiguresNumbers.cs           |   60 +++++++++-----
 src/Games/Memory/MemoryIndications.cs              |   82 ++++++++++++--------
 src/Games/Memory/MemoryNumbers.cs                  |    4 +-
 src/Games/Memory/MemoryWords.cs                    |    6 +-
 18 files changed, 237 insertions(+), 157 deletions(-)
---
diff --git a/sample_extensions/Memory/MemorySample.cs b/sample_extensions/Memory/MemorySample.cs
index 0e1c6b1..da49c05 100644
--- a/sample_extensions/Memory/MemorySample.cs
+++ b/sample_extensions/Memory/MemorySample.cs
@@ -77,7 +77,7 @@ public class MemorySample : Memory
 		base.Initialize ();
 	}
 	
-	public override void DrawPossibleAnswers (CairoContextEx gr, int area_width, int area_height)
+	public override void DrawPossibleAnswers (CairoContextEx gr, int area_width, int area_height, bool rtl)
 	{
 		double x= DrawAreaX + 0.125, y = DrawAreaY + 0.1;
 		int cnt = 0;
diff --git a/src/Core/Libraries/CairoContextEx.cs b/src/Core/Libraries/CairoContextEx.cs
index 94a6db0..e667abd 100644
--- a/src/Core/Libraries/CairoContextEx.cs
+++ b/src/Core/Libraries/CairoContextEx.cs
@@ -172,7 +172,7 @@ namespace gbrainy.Core.Libraries
 			layout.SingleParagraphMode = true;
 			layout.Width = -1;
 			layout.GetPixelSize (out w, out h);
-			MoveTo ((old.X0 + x * old.Xx) - w / 2, (old.Y0 + y * old.Yy) - font_size / 2);
+			MoveTo ((old.X0 + x * old.Xx) - w / 2, old.Y0 + (y * old.Yy) - h / 2);
 			Pango.CairoHelper.ShowLayout (this, layout);
 			Matrix = old;
 		}
diff --git a/src/Core/Main/Game.cs b/src/Core/Main/Game.cs
index 0cd7b10..0c13bd1 100644
--- a/src/Core/Main/Game.cs
+++ b/src/Core/Main/Game.cs
@@ -235,6 +235,10 @@ namespace gbrainy.Core.Main
 			}
 		}
 
+		protected Widget [] Widgets {
+			get { return containers.ToArray (); }
+		}
+
 		//
 		// Score algorithm returns a value between 0 and 10
 		//
@@ -322,13 +326,18 @@ namespace gbrainy.Core.Main
 			return String.Format (Catalog.GetString ("Figure {0}"), GetPossibleAnswer (answer));
 		}
 
-		public virtual void Draw (CairoContextEx gr, int width, int height, bool rtl)
+		protected void InitDraw (CairoContextEx gr, int width, int height, bool rtl)
 		{
 			gr.Scale (width, height);
 			gr.DrawBackground ();
-			gr.Color = new Cairo.Color (0, 0, 0);
-			gr.LineWidth = LineWidth;
-	
+			gr.Color = default_color;
+			gr.LineWidth = LineWidth;		
+		}
+
+		public virtual void Draw (CairoContextEx gr, int width, int height, bool rtl)
+		{
+			InitDraw (gr, width, height, rtl);
+
 			foreach (Toolkit.Container container in containers)
 				container.Draw (gr, width, height, rtl);
 		}
diff --git a/src/Core/Main/Memory.cs b/src/Core/Main/Memory.cs
index 949b4ad..4b1f650 100644
--- a/src/Core/Main/Memory.cs
+++ b/src/Core/Main/Memory.cs
@@ -162,24 +162,24 @@ namespace gbrainy.Core.Main
 				downview.Draw (gr, area_width, area_height, rtl);
 				return;
 			}
-
-			base.Draw (gr, area_width, area_height, rtl);
+			
+			InitDraw (gr, area_width, area_height, rtl);
 
 			if (shade) {
 				if (alpha > 0)
 					alpha -= (1 / (double) shading_time);
 
 				gr.Color = new Color (DefaultDrawingColor.R, DefaultDrawingColor.G, DefaultDrawingColor.B, alpha);
-				DrawObjectToMemorize (gr, area_width, area_height);
+				DrawObjectToMemorize (gr, area_width, area_height, rtl);
 				return;
 			}
 		
 			alpha = 1;
 			gr.Color = new Color (DefaultDrawingColor.R, DefaultDrawingColor.G, DefaultDrawingColor.B, alpha);
 			if (request_answer && DrawAnswer == false) {
-				DrawPossibleAnswers (gr, area_width, area_height);
+				DrawPossibleAnswers (gr, area_width, area_height, rtl);
 			} else {
-				DrawObjectToMemorize (gr, area_width, area_height);			
+				DrawObjectToMemorize (gr, area_width, area_height, rtl);
 			}		
 		}
 
@@ -189,12 +189,16 @@ namespace gbrainy.Core.Main
 			gr.DrawBackground ();
 			gr.Color = new Cairo.Color (0, 0, 0);
 			gr.LineWidth = LineWidth;
-			DrawObjectToMemorize (gr, width, height);
+			DrawObjectToMemorize (gr, width, height, rtl);
 		}
 
-		public virtual void DrawPossibleAnswers (CairoContextEx gr, int area_width, int area_height) {}
+		public virtual void DrawPossibleAnswers (CairoContextEx gr, int area_width, int area_height, bool rtl)
+		{
+			foreach (Toolkit.Container container in Widgets)
+				container.Draw (gr, area_width, area_height, rtl);
+		}
 
-		public virtual void DrawObjectToMemorize (CairoContextEx gr, int area_width, int area_height)
+		public virtual void DrawObjectToMemorize (CairoContextEx gr, int area_width, int area_height, bool rtl)
 		{
 			double percentage;
 
diff --git a/src/Games/Calculation/CalculationAverage.cs b/src/Games/Calculation/CalculationAverage.cs
index fa3c3c7..892475e 100644
--- a/src/Games/Calculation/CalculationAverage.cs
+++ b/src/Games/Calculation/CalculationAverage.cs
@@ -23,6 +23,7 @@ using Mono.Unix;
 
 using gbrainy.Core.Main;
 using gbrainy.Core.Libraries;
+using gbrainy.Core.Toolkit;
 
 namespace gbrainy.Games.Calculation
 {
@@ -142,24 +143,30 @@ namespace gbrainy.Games.Calculation
 			}
 
 			right_answer += GetPossibleAnswer (which);
-		}
 
-		public override void Draw (CairoContextEx gr, int area_width, int area_height, bool rtl)
-		{	
+			// Options
 			double x = DrawAreaX + 0.25, y = DrawAreaY + 0.16;
-			int indx;
-
-			base.Draw (gr, area_width, area_height, rtl);
-
-			gr.SetPangoLargeFontSize ();
-
+			Container container = new Container (x, y,  1 - (x * 2), 0.6);
+			AddWidget (container);
+	
 			for (int i = 0; i < options_cnt; i++)
 			{
-				gr.MoveTo (x, y);
-				indx = random_indices[i];
-				gr.ShowPangoText (String.Format ("{0}) {1:##0.###}", GetPossibleAnswer (i) , options [indx]));
+				DrawableArea drawable_area = new DrawableArea (0.3, 0.1);
+				drawable_area.X = x;
+				drawable_area.Y = y + i * 0.15;
+				container.AddChild (drawable_area);
+				drawable_area.Data = i;
+				drawable_area.DataEx = GetPossibleAnswer (i);
+
+				drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
+				{
+					int n = (int) e.Data;
+					int indx = random_indices[n];
 
-				y = y + 0.15;
+					e.Context.SetPangoLargeFontSize ();
+					e.Context.MoveTo (0.02, 0.02);
+					e.Context.ShowPangoText (String.Format ("{0}) {1:##0.###}", GetPossibleAnswer (n) , options [indx]));
+				};
 			}
 		}
 	}
diff --git a/src/Games/Calculation/CalculationCloserFraction.cs b/src/Games/Calculation/CalculationCloserFraction.cs
index 2fb9fa8..765ec69 100644
--- a/src/Games/Calculation/CalculationCloserFraction.cs
+++ b/src/Games/Calculation/CalculationCloserFraction.cs
@@ -23,6 +23,7 @@ using Mono.Unix;
 
 using gbrainy.Core.Main;
 using gbrainy.Core.Libraries;
+using gbrainy.Core.Toolkit;
 
 namespace gbrainy.Games.Calculation
 {
@@ -82,7 +83,6 @@ namespace gbrainy.Games.Calculation
 				break;
 			}
 
-
 			while (done == false) {
 				duplicated = false;
 				options[0 + 0] = basenum + random.Next (randnum);
@@ -140,24 +140,31 @@ namespace gbrainy.Games.Calculation
 			ans_idx = random_indices[which];
 			question_num = options[ans_idx * 2] / options[(ans_idx * 2) + 1];
 			right_answer += GetPossibleAnswer (which);
-		}
 
-		public override void Draw (CairoContextEx gr, int area_width, int area_height, bool rtl)
-		{	
+			// Options
 			double x = DrawAreaX + 0.25, y = DrawAreaY + 0.16;
-			int indx;
-
-			base.Draw (gr, area_width, area_height, rtl);
-
-			gr.SetPangoLargeFontSize ();
-
-			for (int i = 0; i < options_cnt; i++)
+			Container container = new Container (x, y,  1 - (x * 2), 0.6);
+			AddWidget (container);
+	
+			for (i = 0; i < options_cnt; i++)
 			{
-				gr.MoveTo (x, y);
-				indx = random_indices[i];
-				gr.ShowPangoText (String.Format (Catalog.GetString ("{0}) {1}"), GetPossibleAnswer (i) , options [indx * 2] +  " / " + options [(indx  * 2) +1]));
-			
-				y = y + 0.15;
+				DrawableArea drawable_area = new DrawableArea (0.3, 0.1);
+				drawable_area.X = x;
+				drawable_area.Y = y + i * 0.15;
+				container.AddChild (drawable_area);
+				drawable_area.Data = i;
+				drawable_area.DataEx = GetPossibleAnswer (i);
+
+				drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
+				{
+					int n = (int) e.Data;
+					int indx = random_indices[n];
+
+					e.Context.SetPangoLargeFontSize ();
+					e.Context.MoveTo (0.02, 0.02);
+					e.Context.ShowPangoText (String.Format (Catalog.GetString ("{0}) {1}"), GetPossibleAnswer (n) , 
+						options [indx * 2] +  " / " + options [(indx  * 2) +1]));
+				};
 			}
 		}
 	}
diff --git a/src/Games/Calculation/CalculationProportions.cs b/src/Games/Calculation/CalculationProportions.cs
index 0da4c58..41fbf84 100644
--- a/src/Games/Calculation/CalculationProportions.cs
+++ b/src/Games/Calculation/CalculationProportions.cs
@@ -23,6 +23,7 @@ using Mono.Unix;
 
 using gbrainy.Core.Main;
 using gbrainy.Core.Libraries;
+using gbrainy.Core.Toolkit;
 
 namespace gbrainy.Games.Calculation
 {
@@ -94,24 +95,30 @@ namespace gbrainy.Games.Calculation
 			}
 
 			right_answer += GetPossibleAnswer (which);
-		}
 
-		public override void Draw (CairoContextEx gr, int area_width, int area_height, bool rtl)
-		{	
+			// Options
 			double x = DrawAreaX + 0.25, y = DrawAreaY + 0.16;
-			int indx;
-
-			base.Draw (gr, area_width, area_height, rtl);
-
-			gr.SetPangoLargeFontSize ();
-
+			Container container = new Container (x, y,  1 - (x * 2), 0.6);
+			AddWidget (container);
+	
 			for (int i = 0; i < options_cnt; i++)
 			{
-				gr.MoveTo (x, y);
-				indx = random_indices[i];
-				gr.ShowPangoText (String.Format ("{0}) {1:##0.##}", GetPossibleAnswer (i) , options [indx]));
-
-				y = y + 0.15;
+				DrawableArea drawable_area = new DrawableArea (0.3, 0.1);
+				drawable_area.X = x;
+				drawable_area.Y = y + i * 0.15;
+				container.AddChild (drawable_area);
+				drawable_area.Data = i;
+				drawable_area.DataEx = GetPossibleAnswer (i);
+
+				drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
+				{
+					int n = (int) e.Data;
+					int indx = random_indices[n];
+
+					e.Context.SetPangoLargeFontSize ();
+					e.Context.MoveTo (0.02, 0.02);
+					e.Context.ShowPangoText (String.Format ("{0}) {1:##0.##}", GetPossibleAnswer (n), options [indx]));
+				};
 			}
 		}
 	}
diff --git a/src/Games/Logic/PuzzleMatrixNumbers.cs b/src/Games/Logic/PuzzleMatrixNumbers.cs
index 84faa1a..247b510 100644
--- a/src/Games/Logic/PuzzleMatrixNumbers.cs
+++ b/src/Games/Logic/PuzzleMatrixNumbers.cs
@@ -143,16 +143,17 @@ namespace gbrainy.Games.Logic
 					gr.Rectangle (DrawAreaX + row * rect_w, DrawAreaY + column * rect_h, rect_w, rect_h);
 
 					if (row != 3  || column != 3) {
-						gr.MoveTo (0.04 + DrawAreaX + column * rect_w, (rect_h / 2) + DrawAreaY + row * rect_h);
-						gr.ShowPangoText ( (numbers[column + (row * 4)]).ToString() );
+						gr.DrawTextCentered (DrawAreaX + column * rect_w + rect_w / 2, 
+							DrawAreaY + row * rect_h + rect_h / 2,
+							(numbers[column + (row * 4)]).ToString());
 					}
 				}
 			}
 
-			gr.MoveTo (0.04 + DrawAreaX + 3 * rect_w, (rect_h / 2) + DrawAreaY + 3 * rect_h);
-			gr.ShowPangoText ("?");
+			gr.DrawTextCentered (DrawAreaX + 3 * rect_w + rect_w / 2,
+				DrawAreaY + 3 * rect_h + rect_h / 2,
+				"?");
 			gr.Stroke ();
 		}
-
 	}
 }
diff --git a/src/Games/Memory/MemoryColouredFigures.cs b/src/Games/Memory/MemoryColouredFigures.cs
index ef1beb7..b400591 100644
--- a/src/Games/Memory/MemoryColouredFigures.cs
+++ b/src/Games/Memory/MemoryColouredFigures.cs
@@ -23,6 +23,7 @@ using Mono.Unix;
 
 using gbrainy.Core.Main;
 using gbrainy.Core.Libraries;
+using gbrainy.Core.Toolkit;
 
 namespace gbrainy.Games.Memory
 {
@@ -101,6 +102,39 @@ namespace gbrainy.Games.Memory
 			}
 
 			base.Initialize ();
+
+			HorizontalContainer container = new HorizontalContainer (DrawAreaX, DrawAreaY, 0.8, 0.4);
+			AddWidget (container);
+
+			double x = DrawAreaX, y = DrawAreaY;
+
+			for (int i = 0; i < answers_order.Count; i++) 
+			{
+				if (i == 2) {
+					y += 0.5;
+					x = DrawAreaX;
+
+					container = new HorizontalContainer (DrawAreaX, DrawAreaY + 0.45, 0.8, 0.4);
+					AddWidget (container);
+				}
+
+				DrawableArea drawable_area = new DrawableArea (0.4, 0.4);
+				container.AddChild (drawable_area);
+				drawable_area.SelectedArea = new Rectangle (0.05, 0, 0.3, 0.3);
+				drawable_area.Data = i;
+				drawable_area.DataEx = GetPossibleAnswer (i);
+
+				drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
+				{
+					int n = (int) e.Data;
+
+					palette.Alpha = alpha;
+					DrawSquare (e.Context, 0.05, 0, squares_colours, squares * answers_order[n]);
+					e.Context.MoveTo (0.05, 0 + block_space - 0.02);
+					e.Context.ShowPangoText (GetPossibleFigureAnswer (n));
+					e.Context.Stroke ();
+				};
+			}
 		}
 
 		private void Randomize (SquareColor []colours, int source, int target)
@@ -140,28 +174,9 @@ namespace gbrainy.Games.Memory
 			}
 		}
 
-		public override void DrawPossibleAnswers (CairoContextEx gr, int area_width, int area_height)
-		{
-			double x = DrawAreaX, y = DrawAreaY;
-	
-			palette.Alpha = alpha;
-		
-			for (int i = 0; i < answers_order.Count; i++) {
-				if (i == 2) {
-					y += 0.45;
-					x = DrawAreaX;
-				}
-				DrawSquare (gr, x, y, squares_colours, squares * answers_order[i]);
-				gr.MoveTo (x, y + block_space - 0.02);
-				gr.ShowPangoText (GetPossibleFigureAnswer (i));
-				gr.Stroke ();
-				x += block_space + 0.08;
-			}
-		}
-
-		public override void DrawObjectToMemorize (CairoContextEx gr, int area_width, int area_height)
+		public override void DrawObjectToMemorize (CairoContextEx gr, int area_width, int area_height, bool rtl)
 		{
-			base.DrawObjectToMemorize (gr, area_width, area_height);
+			base.DrawObjectToMemorize (gr, area_width, area_height, rtl);
 			palette.Alpha = alpha; 
 			DrawSquare (gr, DrawAreaX + 0.3, DrawAreaY + 0.1, squares_colours, 0);
 		}
diff --git a/src/Games/Memory/MemoryColouredText.cs b/src/Games/Memory/MemoryColouredText.cs
index af7efcf..b4a40cf 100644
--- a/src/Games/Memory/MemoryColouredText.cs
+++ b/src/Games/Memory/MemoryColouredText.cs
@@ -69,9 +69,9 @@ namespace gbrainy.Games.Memory
 			base.Initialize ();
 		}
 	
-		public override void DrawObjectToMemorize (CairoContextEx gr, int area_width, int area_height)
+		public override void DrawObjectToMemorize (CairoContextEx gr, int area_width, int area_height, bool rtl)
 		{
-			base.DrawObjectToMemorize (gr, area_width, area_height);
+			base.DrawObjectToMemorize (gr, area_width, area_height, rtl);
 			DrawObject (gr);
 		}
 
diff --git a/src/Games/Memory/MemoryCountDots.cs b/src/Games/Memory/MemoryCountDots.cs
index 4602053..41babfb 100644
--- a/src/Games/Memory/MemoryCountDots.cs
+++ b/src/Games/Memory/MemoryCountDots.cs
@@ -88,9 +88,9 @@ namespace gbrainy.Games.Memory
 			base.Initialize ();
 		}
 
-		public override void DrawObjectToMemorize (CairoContextEx gr, int area_width, int area_height)
+		public override void DrawObjectToMemorize (CairoContextEx gr, int area_width, int area_height, bool rtl)
 		{
-			base.DrawObjectToMemorize (gr, area_width, area_height);
+			base.DrawObjectToMemorize (gr, area_width, area_height, rtl);
 			DrawObject (gr, area_width, area_height);
 		}
 
diff --git a/src/Games/Memory/MemoryFacts.cs b/src/Games/Memory/MemoryFacts.cs
index 00d39b0..9359335 100644
--- a/src/Games/Memory/MemoryFacts.cs
+++ b/src/Games/Memory/MemoryFacts.cs
@@ -143,16 +143,16 @@ namespace gbrainy.Games.Memory
 			return fact;
 		}
 
-		public override void DrawPossibleAnswers (CairoContextEx gr, int area_width, int area_height)
+		public override void DrawPossibleAnswers (CairoContextEx gr, int area_width, int area_height, bool rtl)
 		{
 
 		}
 	
-		public override void DrawObjectToMemorize (CairoContextEx gr, int area_width, int area_height)
+		public override void DrawObjectToMemorize (CairoContextEx gr, int area_width, int area_height, bool rtl)
 		{
 			string text = string.Empty;
 
-			base.DrawObjectToMemorize (gr, area_width, area_height);
+			base.DrawObjectToMemorize (gr, area_width, area_height, rtl);
 	
 			for (int i = 0; i < facts.Length; i++)
 			{
diff --git a/src/Games/Memory/MemoryFigures.cs b/src/Games/Memory/MemoryFigures.cs
index 3313608..c6d2e03 100644
--- a/src/Games/Memory/MemoryFigures.cs
+++ b/src/Games/Memory/MemoryFigures.cs
@@ -106,7 +106,7 @@ namespace gbrainy.Games.Memory
 			base.Initialize ();
 		}
 
-		public override void DrawPossibleAnswers (CairoContextEx gr, int area_width, int area_height)
+		public override void DrawPossibleAnswers (CairoContextEx gr, int area_width, int area_height, bool rtl)
 		{
 			int col = 1, fig;
 			double x = start_x_ans, y = start_y;
@@ -141,9 +141,9 @@ namespace gbrainy.Games.Memory
 			}
 		}
 
-		public override void DrawObjectToMemorize (CairoContextEx gr, int area_width, int area_height)
+		public override void DrawObjectToMemorize (CairoContextEx gr, int area_width, int area_height, bool rtl)
 		{
-			base.DrawObjectToMemorize (gr, area_width, area_height);
+			base.DrawObjectToMemorize (gr, area_width, area_height, rtl);
 			DrawAllFigures (gr, start_x_ques, start_y, area_width, area_height);
 		}
 
diff --git a/src/Games/Memory/MemoryFiguresAndText.cs b/src/Games/Memory/MemoryFiguresAndText.cs
index b9f4bfa..3a9048e 100644
--- a/src/Games/Memory/MemoryFiguresAndText.cs
+++ b/src/Games/Memory/MemoryFiguresAndText.cs
@@ -114,7 +114,7 @@ namespace gbrainy.Games.Memory
 			base.Initialize ();
 		}
 
-		public override void DrawPossibleAnswers (CairoContextEx gr, int area_width, int area_height)
+		public override void DrawPossibleAnswers (CairoContextEx gr, int area_width, int area_height, bool rtl)
 		{
 			double x= DrawAreaX, y = DrawAreaY + 0.1;
 			int pos = 0;
@@ -144,9 +144,9 @@ namespace gbrainy.Games.Memory
 			}
 		}
 
-		public override void DrawObjectToMemorize (CairoContextEx gr, int area_width, int area_height)
+		public override void DrawObjectToMemorize (CairoContextEx gr, int area_width, int area_height, bool rtl)
 		{
-			base.DrawObjectToMemorize (gr, area_width, area_height);
+			base.DrawObjectToMemorize (gr, area_width, area_height, rtl);
 			DrawAllFigures (gr, start_x_ques, start_y, area_width, area_height);
 		}
 
diff --git a/src/Games/Memory/MemoryFiguresNumbers.cs b/src/Games/Memory/MemoryFiguresNumbers.cs
index 05b10de..e51746f 100644
--- a/src/Games/Memory/MemoryFiguresNumbers.cs
+++ b/src/Games/Memory/MemoryFiguresNumbers.cs
@@ -23,6 +23,7 @@ using Mono.Unix;
 
 using gbrainy.Core.Main;
 using gbrainy.Core.Libraries;
+using gbrainy.Core.Toolkit;
 
 namespace gbrainy.Games.Memory
 {
@@ -83,6 +84,38 @@ namespace gbrainy.Games.Memory
 			}
 
 			base.Initialize ();
+
+			HorizontalContainer container = new HorizontalContainer (DrawAreaX, DrawAreaY, 0.8, 0.4);
+			AddWidget (container);
+
+			double x = DrawAreaX, y = DrawAreaY;
+
+			for (int i = 0; i < answers_order.Count; i++) 
+			{
+				if (i == 2) {
+					y += 0.5;
+					x = DrawAreaX;
+
+					container = new HorizontalContainer (DrawAreaX, DrawAreaY + 0.45, 0.8, 0.4);
+					AddWidget (container);
+				}
+
+				DrawableArea drawable_area = new DrawableArea (0.4, 0.4);
+				container.AddChild (drawable_area);
+				drawable_area.SelectedArea = new Rectangle (0.05, 0, 0.3, 0.3);
+				drawable_area.Data = i;
+				drawable_area.DataEx = GetPossibleAnswer (i);
+
+				drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
+				{
+					int n = (int) e.Data;
+
+					DrawSquare (e.Context, 0.05, 0, numbers, squares * answers_order[n]);
+					e.Context.MoveTo (0.05, block_space - 0.02);
+					e.Context.ShowPangoText (GetPossibleFigureAnswer (n));
+					e.Context.Stroke ();
+				};
+			}
 		}
 
 		private void Randomize (int []nums, int source, int target)
@@ -121,28 +154,10 @@ namespace gbrainy.Games.Memory
 					done = true;
 			}
 		}
-	
-
-		public override void DrawPossibleAnswers (CairoContextEx gr, int area_width, int area_height)
-		{
-			double x = DrawAreaX , y = DrawAreaY;
-			gr.Color = DefaultDrawingColor;
-			for (int i = 0; i < answers_order.Count; i++) {
-				if (i == 2) {
-					y += 0.45;
-					x = DrawAreaX;
-				}
-				DrawSquare (gr, x, y, numbers, squares * (int) answers_order[i]);
-				gr.MoveTo (x, y + block_space);
-				gr.ShowPangoText (GetPossibleFigureAnswer (i));
-				gr.Stroke ();
-				x += block_space + 0.08;
-			}
-		}
 
-		public override void DrawObjectToMemorize (CairoContextEx gr, int area_width, int area_height)
+		public override void DrawObjectToMemorize (CairoContextEx gr, int area_width, int area_height, bool rtl)
 		{
-			base.DrawObjectToMemorize (gr, area_width, area_height);
+			base.DrawObjectToMemorize (gr, area_width, area_height, rtl);
 			DrawSquare (gr, 0.3 + DrawAreaX, DrawAreaY + 0.1, numbers, 0);
 		}
 
@@ -151,11 +166,12 @@ namespace gbrainy.Games.Memory
 			for (int column = 0; column < columns; column++) {
 				for (int row = 0; row < rows; row++) {
 					gr.Rectangle (x + row * rect_w, y + column * rect_h, rect_w, rect_h);
-					gr.DrawTextCentered (x + (rect_w / 2) + column * rect_w, y + (rect_h / 2) + row * rect_h, 
+					gr.Stroke ();
+					gr.DrawTextCentered (x + (rect_w / 2) + column * rect_w, y + (rect_h / 2) + row * rect_h,
 						(nums[index + column + (row * columns)]).ToString ());
+					gr.Stroke ();
 				}
 			}
-			gr.Stroke ();
 		}
 	}
 }
diff --git a/src/Games/Memory/MemoryIndications.cs b/src/Games/Memory/MemoryIndications.cs
index 46b979e..d01868d 100644
--- a/src/Games/Memory/MemoryIndications.cs
+++ b/src/Games/Memory/MemoryIndications.cs
@@ -23,6 +23,7 @@ using Mono.Unix;
 
 using gbrainy.Core.Main;
 using gbrainy.Core.Libraries;
+using gbrainy.Core.Toolkit;
 
 namespace gbrainy.Games.Memory
 {
@@ -56,12 +57,14 @@ namespace gbrainy.Games.Memory
 
 			public void Draw (CairoContextEx gr, ref double x, ref double y, Indication next_prev)
 			{
-				const double line_length = 0.050;
-				const double points = 0.050;
+				const double line_length = 0.045;
+				const double points = 0.045;
 
 				if (type == Type.Start) {
 					gr.Rectangle (x, y, points, points);
 					gr.DrawTextCentered (x + points /2 , y + points /2, ((int)obj).ToString ());
+					gr.Stroke ();
+
 					switch ((TurnDirection) next_prev.obj) {
 					case TurnDirection.Right:
 						x += points;
@@ -78,8 +81,6 @@ namespace gbrainy.Games.Memory
 						x += points / 2;
 						break;
 					}
-
-					gr.Stroke ();
 			
 				} else if (type == Type.Turn) {
 					gr.MoveTo (x, y);
@@ -235,8 +236,47 @@ namespace gbrainy.Games.Memory
 				}
 			}
 
-			//for (int i = 0; i < indications.Length; i++)
-			//	Console.WriteLine ("{0}",  indications[i].ToString ());
+			// Draw row 1
+			HorizontalContainer container = new HorizontalContainer (0.05, 0.1, 0.9, 0.4);
+			AddWidget (container);
+
+			for (int i = 0; i  < 2; i++)
+			{
+				DrawableArea drawable_area = new DrawableArea (0.45, 0.4);
+				container.AddChild (drawable_area);
+				drawable_area.SelectedArea = new Rectangle (0, 0, 0.45, 0.3);
+				drawable_area.Data = i;
+				drawable_area.DataEx = GetPossibleAnswer (i);
+				drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
+				{
+					int n = (int) e.Data;
+
+					DrawPossibleAnswers (e.Context, 0.2, 0.1, WhichAnswer (answers[n]));
+					e.Context.MoveTo (0.2, 0.12 + 0.2);
+					e.Context.ShowPangoText (GetPossibleFigureAnswer (n));
+				};
+			}
+
+			// Draw row 2
+			container = new HorizontalContainer (0.05, 0.5, 0.9, 0.4);
+			AddWidget (container);
+
+			for (int i = 2; i  < 4; i++)
+			{
+				DrawableArea drawable_area = new DrawableArea (0.45, 0.4);
+				container.AddChild (drawable_area);
+				drawable_area.SelectedArea = new Rectangle (0, 0, 0.45, 0.3);
+				drawable_area.Data = i;
+				drawable_area.DataEx = GetPossibleAnswer (i);
+				drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
+				{
+					int n = (int) e.Data;
+
+					DrawPossibleAnswers (e.Context, 0.2, 0.1, WhichAnswer (answers[n]));
+					e.Context.MoveTo (0.2, 0.12 + 0.2);
+					e.Context.ShowPangoText (GetPossibleFigureAnswer (n));
+				};
+			}
 		}
 
 		private Indication[] CopyAnswer ()
@@ -268,38 +308,12 @@ namespace gbrainy.Games.Memory
 			case 3:
 				return indications_wrongC;
 			}
-
 			return null;
 		}
-
-		public override void DrawPossibleAnswers (CairoContextEx gr, int area_width, int area_height)
-		{
-			double x, y;
-
-			x = 0.22; y = 0.3;
-			DrawPossibleAnswers (gr, x, y, WhichAnswer (answers[0]));
-			gr.MoveTo (x, y + 0.2);
-			gr.ShowPangoText (GetPossibleFigureAnswer (0));
-
-			x = 0.7; y = 0.3;
-			DrawPossibleAnswers (gr, x, y, WhichAnswer (answers[1]));
-			gr.MoveTo (x, y + 0.2);
-			gr.ShowPangoText (GetPossibleFigureAnswer (1));
-
-			x = 0.22; y = 0.7;
-			DrawPossibleAnswers (gr, x, y, WhichAnswer (answers[2]));
-			gr.MoveTo (x, y + 0.2);
-			gr.ShowPangoText (GetPossibleFigureAnswer (2));
-
-			x = 0.7; y = 0.7;
-			DrawPossibleAnswers (gr, x, y, WhichAnswer (answers[3]));
-			gr.MoveTo (x, y + 0.2);
-			gr.ShowPangoText (GetPossibleFigureAnswer (3));
-		}
 	
-		public override void DrawObjectToMemorize (CairoContextEx gr, int area_width, int area_height)
+		public override void DrawObjectToMemorize (CairoContextEx gr, int area_width, int area_height, bool rtl)
 		{
-			base.DrawObjectToMemorize (gr, area_width, area_height);
+			base.DrawObjectToMemorize (gr, area_width, area_height, rtl);
 
 			if (DrawAnswer == false) {
 				for (int i = 0; i < indications.Length; i++)
diff --git a/src/Games/Memory/MemoryNumbers.cs b/src/Games/Memory/MemoryNumbers.cs
index 5682919..df5d0af 100644
--- a/src/Games/Memory/MemoryNumbers.cs
+++ b/src/Games/Memory/MemoryNumbers.cs
@@ -159,12 +159,12 @@ namespace gbrainy.Games.Memory
 			right_answer = current_game.Answer;
 		}
 
-		public override void DrawObjectToMemorize (CairoContextEx gr, int area_width, int area_height)
+		public override void DrawObjectToMemorize (CairoContextEx gr, int area_width, int area_height, bool rtl)
 		{
 
 			StringBuilder sequence = new StringBuilder (64);
 
-			base.DrawObjectToMemorize (gr, area_width, area_height);
+			base.DrawObjectToMemorize (gr, area_width, area_height, rtl);
 			gr.SetPangoLargeFontSize ();
 
 			for (int num = 0; num < Challenge.Numbers.Length - 1; num++)
diff --git a/src/Games/Memory/MemoryWords.cs b/src/Games/Memory/MemoryWords.cs
index 5165be0..069fcbe 100644
--- a/src/Games/Memory/MemoryWords.cs
+++ b/src/Games/Memory/MemoryWords.cs
@@ -118,7 +118,7 @@ namespace gbrainy.Games.Memory
 			base.Initialize ();
 		}
 	
-		public override void DrawPossibleAnswers (CairoContextEx gr, int area_width, int area_height)
+		public override void DrawPossibleAnswers (CairoContextEx gr, int area_width, int area_height, bool rtl)
 		{
 			double x= DrawAreaX + 0.125, y = DrawAreaY + 0.1;
 			int cnt = 0;
@@ -142,9 +142,9 @@ namespace gbrainy.Games.Memory
 			}
 		}
 	
-		public override void DrawObjectToMemorize (CairoContextEx gr, int area_width, int area_height)
+		public override void DrawObjectToMemorize (CairoContextEx gr, int area_width, int area_height, bool rtl)
 		{
-			base.DrawObjectToMemorize (gr, area_width, area_height);
+			base.DrawObjectToMemorize (gr, area_width, area_height, rtl);
 			DrawObject (gr, area_width, area_height);
 		}
 	



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