[gbrainy] Disable mouse after answer, fixes, and add support for mouse and rtl to 6 more puzzles



commit 5f237c63328ab4f812a25db82840a1036b126dbb
Author: Jordi Mas <jmas softcatala org>
Date:   Sat Jan 30 13:58:09 2010 +0100

    Disable mouse after answer, fixes, and add support for mouse and rtl to 6 more puzzles

 src/Clients/Classical/gbrainy.cs                   |    1 -
 src/Core/Main/Game.cs                              |    7 ++
 src/Core/Main/GameSession.cs                       |    9 +-
 src/Core/Main/Verbal/AnalogiesMultipleOptions.cs   |   40 ++++++----
 .../Main/Verbal/AnalogiesPairOfWordsOptions.cs     |    2 +-
 src/Core/Makefile.am                               |    5 +-
 src/Core/Toolkit/Container.cs                      |   16 +++-
 src/Core/Toolkit/DrawableArea.cs                   |   20 ++++-
 src/Core/Toolkit/HorizontalContainer.cs            |   18 ++++-
 src/Core/Toolkit/Widget.cs                         |   24 +++++-
 src/Core/Views/WelcomeView.cs                      |    8 +-
 src/Games/Calculation/CalculationCloserFraction.cs |    2 +-
 src/Games/Logic/PuzzleFigures.cs                   |   78 +++++++++++---------
 src/Games/Logic/PuzzleMostInCommon.cs              |   36 +++++++--
 src/Games/Logic/PuzzleOstracism.cs                 |   31 +++++---
 src/Games/Logic/PuzzlePredicateLogic.cs            |   45 +++++++-----
 16 files changed, 230 insertions(+), 112 deletions(-)
---
diff --git a/src/Clients/Classical/gbrainy.cs b/src/Clients/Classical/gbrainy.cs
index 32acaa2..1738e45 100644
--- a/src/Clients/Classical/gbrainy.cs
+++ b/src/Clients/Classical/gbrainy.cs
@@ -401,7 +401,6 @@ namespace gbrainy.Clients.Classical
 			UpdateSolution (answer + " " + session.CurrentGame.Answer);
 
 			session.CurrentGame.DrawAnswer = true;
-			session.Status = GameSession.SessionStatus.Answered;
 			ActiveInputControls (true);
 			next_button.GrabFocus ();
 			drawing_area.QueueDraw ();
diff --git a/src/Core/Main/Game.cs b/src/Core/Main/Game.cs
index 383380e..0cd7b10 100644
--- a/src/Core/Main/Game.cs
+++ b/src/Core/Main/Game.cs
@@ -385,6 +385,13 @@ namespace gbrainy.Core.Main
 			return str;
 		}
 
+		public void DisableMouseEvents ()
+		{
+			foreach (Toolkit.Container container in containers) 
+				foreach (Widget widget in container.Children)
+					widget.Sensitive = false;
+		}
+
 		public void MouseEvent (object obj, MouseEventArgs args)
 		{
 			foreach (Toolkit.Container container in containers)
diff --git a/src/Core/Main/GameSession.cs b/src/Core/Main/GameSession.cs
index 1a131b8..42601d5 100644
--- a/src/Core/Main/GameSession.cs
+++ b/src/Core/Main/GameSession.cs
@@ -78,7 +78,6 @@ namespace gbrainy.Core.Main
 		private string current_time;
 		private TimeSpan one_sec = TimeSpan.FromSeconds (1);
 		private int total_score;
-		private bool scored_game;
 		private SessionStatus status;
 		private ViewsControler controler;
 		private ISynchronizeInvoke synchronize;
@@ -171,6 +170,9 @@ namespace gbrainy.Core.Main
 			set {
 				status = value;
 				controler.Status = value;
+
+				if (status == SessionStatus.Answered && CurrentGame != null)
+					CurrentGame.DisableMouseEvents ();
 			}
 		}
 
@@ -297,7 +299,6 @@ namespace gbrainy.Core.Main
 			CurrentGame.Initialize ();
 
 			CurrentGame.GameTime = TimeSpan.Zero;
-			scored_game = false;
 			Status = SessionStatus.Playing;
 		}
 
@@ -333,7 +334,7 @@ namespace gbrainy.Core.Main
 			bool won;
 			int components = 0;
 
-			if (CurrentGame == null || scored_game == true)
+			if (CurrentGame == null ||Status == SessionStatus.Answered)
 				return false;
 
 			score = CurrentGame.Score (answer);
@@ -393,7 +394,7 @@ namespace gbrainy.Core.Main
 
 			total_score = total_score / components;
 
-			scored_game = true;
+			Status = SessionStatus.Answered;
 			return won;
 		}
 
diff --git a/src/Core/Main/Verbal/AnalogiesMultipleOptions.cs b/src/Core/Main/Verbal/AnalogiesMultipleOptions.cs
index 87d3a4d..6bceef4 100644
--- a/src/Core/Main/Verbal/AnalogiesMultipleOptions.cs
+++ b/src/Core/Main/Verbal/AnalogiesMultipleOptions.cs
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 Jordi Mas i Hernàndez <jmas softcatala org>
+ * Copyright (C) 2009-2010 Jordi Mas i Hernàndez <jmas softcatala org>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -25,6 +25,7 @@ using Cairo;
 using Mono.Unix;
 
 using gbrainy.Core.Libraries;
+using gbrainy.Core.Toolkit;
 
 namespace gbrainy.Core.Main.Verbal
 {
@@ -95,32 +96,39 @@ namespace gbrainy.Core.Main.Verbal
 				return;
 
 			right_answer = GetPossibleAnswer (current.right);
+
+			Container container = new Container (DrawAreaX + 0.1, 0.50, 0.5, current.answers.Length * 0.15);
+			AddWidget (container);
+	
+			for (int i = 0; i <  current.answers.Length; i++)
+			{
+				DrawableArea drawable_area = new DrawableArea (0.8, 0.1);
+				drawable_area.X = DrawAreaX;
+				drawable_area.Y = DrawAreaY + 0.2 + 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;
+
+					e.Context.MoveTo (0.05, 0.02);
+					e.Context.ShowPangoText (String.Format (Catalog.GetString ("{0}) {1}"), GetPossibleAnswer (n), current.answers[n].ToString ()));
+				};
+			}
 		}
 	
 		public override void Draw (CairoContextEx gr, int area_width, int area_height, bool rtl)
 		{
-			double x = DrawAreaX, y = DrawAreaY + 0.1;
-
 			base.Draw (gr, area_width, area_height, rtl);
 
 			if (current == null || current.answers == null)
 				return;
 
 			gr.SetPangoLargeFontSize ();
-			gr.MoveTo (0.1, y);
+			gr.MoveTo (0.1, DrawAreaY + 0.05);
 			gr.ShowPangoText (Catalog.GetString ("Possible answers are:"));
-
-			gr.SetPangoNormalFontSize ();
-
-			y += 0.15;
-			x += 0.05;
-			for (int n = 0; n < current.answers.Length; n++)
-			{
-				gr.MoveTo (x, y);
-				gr.ShowPangoText (String.Format ("{0}) {1}", GetPossibleAnswer (n), current.answers[n].ToString ()));
-				gr.Stroke ();
-				y += 0.15;
-			}
 		}
 	}
 }
diff --git a/src/Core/Main/Verbal/AnalogiesPairOfWordsOptions.cs b/src/Core/Main/Verbal/AnalogiesPairOfWordsOptions.cs
index 9a6f9a9..2d27207 100644
--- a/src/Core/Main/Verbal/AnalogiesPairOfWordsOptions.cs
+++ b/src/Core/Main/Verbal/AnalogiesPairOfWordsOptions.cs
@@ -113,7 +113,7 @@ namespace gbrainy.Core.Main.Verbal
 			for (int n = 0; n < current.answers.Length; n++)
 			{
 				gr.MoveTo (x, y);
-				gr.ShowPangoText (String.Format ("{0}) {1}", GetPossibleAnswer (n), current.answers[n].ToString ()));
+				gr.ShowPangoText (String.Format (Catalog.GetString ("{0}) {1}"), GetPossibleAnswer (n), current.answers[n].ToString ()));
 				gr.Stroke ();
 				y += 0.15;
 			}
diff --git a/src/Core/Makefile.am b/src/Core/Makefile.am
index 18d9d45..2299821 100644
--- a/src/Core/Makefile.am
+++ b/src/Core/Makefile.am
@@ -1,4 +1,7 @@
-CSFLAGS = -unsafe -target:library $(CSC_DEFINES)
+CSFLAGS = -unsafe -target:library $(CSC_DEFINES) 
+
+#Active when designing games
+#CSFLAGS += -D:DESIGN_MODE
 
 TARGET = ../gbrainy.Core.dll
 TARGET_CFG = ../gbrainy.Core.dll.config
diff --git a/src/Core/Toolkit/Container.cs b/src/Core/Toolkit/Container.cs
index b4fcd38..1ab2956 100644
--- a/src/Core/Toolkit/Container.cs
+++ b/src/Core/Toolkit/Container.cs
@@ -27,7 +27,7 @@ namespace gbrainy.Core.Toolkit
 {
 	//
 	// Base Container class
-	// Does not support rtl and all the coordinates are relative to the child (not the container)
+	// Does not support rtl and all the coordinates are drawable context (not to the container)
 	// 
 	public class Container : Widget
 	{
@@ -40,6 +40,12 @@ namespace gbrainy.Core.Toolkit
 		
 		public Container (double x, double y, double width, double height) : base (width, height)
 		{
+			if (x < 0 || x > 1)
+				throw new ArgumentOutOfRangeException ("x");
+
+			if (y < 0 || y > 1)
+				throw new ArgumentOutOfRangeException ("y");
+
 			X = x;
 			Y = y;
 		}
@@ -71,12 +77,13 @@ namespace gbrainy.Core.Toolkit
 
 		public override void Draw (CairoContextEx gr, int area_width, int area_height, bool rtl)
 		{
-			/*gr.Save ();
+#if DESIGN_MODE
+			gr.Save ();
 			gr.Color = new Cairo.Color (0, 0, 1);
 			gr.Rectangle (X, Y, Width, Height);
 			gr.Stroke ();
-			gr.Restore ();*/
-
+			gr.Restore ();
+#endif
 			foreach (Widget child in children)
 			{
 				gr.Save ();						
@@ -84,6 +91,7 @@ namespace gbrainy.Core.Toolkit
 				child.Draw (gr, area_width, area_height, rtl);
 				gr.Restore ();
 			}
+
 		}
 
 		public override void MouseEvent (object obj, MouseEventArgs args)
diff --git a/src/Core/Toolkit/DrawableArea.cs b/src/Core/Toolkit/DrawableArea.cs
index b387f1b..1c3594b 100644
--- a/src/Core/Toolkit/DrawableArea.cs
+++ b/src/Core/Toolkit/DrawableArea.cs
@@ -28,7 +28,6 @@ namespace gbrainy.Core.Toolkit
 	public class DrawableArea : Widget
 	{
 		public virtual event WidgetDrawEventHandler DrawEventHandler;
-		public virtual event WidgetSelectedEventHandler SelectedRequestEvent;
 		bool hoover;
 
 		public DrawableArea (double x, double y, double width, double height) : base (width, height)
@@ -39,18 +38,28 @@ namespace gbrainy.Core.Toolkit
 
 	    	public DrawableArea (double width, double height) : base (width, height)
 		{
-
+			Sensitive = true;
 		}
 
 		public Rectangle SelectedArea { get; set; }
 
+		public override bool Sensitive { 
+			set { 
+				hoover = false;
+				base.Sensitive = value;
+			}
+			get {return base.Sensitive; }
+		}
+
 		public override void Draw (CairoContextEx gr, int area_width, int area_height, bool rtl) 
 		{
-			/*gr.Save ();
+#if DESIGN_MODE
+			gr.Save ();
 			gr.Color = new Cairo.Color (1, 0, 0);
 			gr.Rectangle (0, 0, Width, Height);
 			gr.Stroke ();
-			gr.Restore ();*/
+			gr.Restore ();
+#endif
 
 			if (hoover == true)
   			{
@@ -80,6 +89,9 @@ namespace gbrainy.Core.Toolkit
 
 		public override void MouseEvent (object obj, MouseEventArgs args)
 		{
+			if (Sensitive == false)
+				return;
+
 			if (args.X == -1 || args.Y == -1) {
 				if (hoover == true) {
 					hoover = false;
diff --git a/src/Core/Toolkit/HorizontalContainer.cs b/src/Core/Toolkit/HorizontalContainer.cs
index a091abd..b12b3cd 100644
--- a/src/Core/Toolkit/HorizontalContainer.cs
+++ b/src/Core/Toolkit/HorizontalContainer.cs
@@ -42,12 +42,26 @@ namespace gbrainy.Core.Toolkit
 	
 			this.rtl = rtl;
 
-			/*gr.Save ();
+#if DESIGN_MODE
+			gr.Save ();
 			gr.Color = new Cairo.Color (0, 0, 1);
 			gr.Rectangle (X, Y, Width, Height);
 			gr.Stroke ();
-			gr.Restore ();*/
+			gr.Restore ();
 
+			double width = 0;
+
+			foreach (Widget child in children)
+			{
+				width += child.Width;
+				
+				if (Height < child.Height)
+					throw new InvalidOperationException (String.Format ("Container height too small {0} < {1}", Height, child.Height));
+			}
+
+			if (Width < width)
+				throw new InvalidOperationException (String.Format ("Container witdh too small {0} < {1}", Width, width));
+#endif
 			//
 			// Coordinates are stored right to left
 			//
diff --git a/src/Core/Toolkit/Widget.cs b/src/Core/Toolkit/Widget.cs
index c6a4112..77006a7 100644
--- a/src/Core/Toolkit/Widget.cs
+++ b/src/Core/Toolkit/Widget.cs
@@ -25,22 +25,40 @@ using gbrainy.Core.Libraries;
 
 namespace gbrainy.Core.Toolkit
 {
+	/*
+		This is a set of classes that help to model a minimal widget library over
+		Cairo that handles RTL and mouse events
+	*/
+
 	public abstract class Widget : IDrawable, IDrawRequest, IMouseEvent
 	{
 		public delegate void WidgetDrawEventHandler (object sender, DrawEventArgs e);
-		public delegate void WidgetSelectedEventHandler (object sender, SeletectedEventArgs e);
 
 		public event EventHandler DrawRequest;
-		public event WidgetSelectedEventHandler SelectedEvent;
+		public event EventHandler <SeletectedEventArgs> SelectedEvent;
 		ISynchronizeInvoke synchronize;
+		bool sensitive;
 
 	    	public Widget (double width, double height)
 		{
+			if (width < 0 || width > 1)
+				throw new ArgumentOutOfRangeException ("width");
+
+			if (height < 0 || height > 1)
+				throw new ArgumentOutOfRangeException ("height");
+
 			Width = width;
 			Height = height;
 		}
 
-		public bool Sensitive { get; set; }
+		public virtual bool Sensitive { 
+			set {
+				sensitive = value;
+				OnDrawRequest ();
+			}
+			get {return sensitive; }
+		}
+
 		public object Data { get; set; }
 		public object DataEx { get; set; }
 
diff --git a/src/Core/Views/WelcomeView.cs b/src/Core/Views/WelcomeView.cs
index 381ac8e..51d7497 100644
--- a/src/Core/Views/WelcomeView.cs
+++ b/src/Core/Views/WelcomeView.cs
@@ -54,7 +54,7 @@ namespace gbrainy.Core.Views
 				e.Context.DrawImageFromAssembly ("logic-games.svg", 0, 0, image_size, image_size);
 			};
 
-			drawable_area = new DrawableArea (0.75, 0.25);
+			drawable_area = new DrawableArea (0.75, space);
 			container.AddChild (drawable_area);
 			drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
 			{
@@ -75,7 +75,7 @@ namespace gbrainy.Core.Views
 				e.Context.DrawImageFromAssembly ("math-games.svg", 0, 0, image_size, image_size);
 			};
 
-			drawable_area = new DrawableArea (0.75, 0.25);
+			drawable_area = new DrawableArea (0.75, space);
 			container.AddChild (drawable_area);
 			drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
 			{
@@ -96,7 +96,7 @@ namespace gbrainy.Core.Views
 				e.Context.DrawImageFromAssembly ("memory-games.svg", 0, 0, image_size, image_size);
 			};
 
-			drawable_area = new DrawableArea (0.75, 0.25);
+			drawable_area = new DrawableArea (0.75, space);
 			container.AddChild (drawable_area);
 			drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
 			{
@@ -117,7 +117,7 @@ namespace gbrainy.Core.Views
 				e.Context.DrawImageFromAssembly ("verbal-games.svg", 0, 0, image_size, image_size);
 			};
 
-			drawable_area = new DrawableArea (0.75, 0.25);
+			drawable_area = new DrawableArea (0.75, space);
 			container.AddChild (drawable_area);
 			drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
 			{
diff --git a/src/Games/Calculation/CalculationCloserFraction.cs b/src/Games/Calculation/CalculationCloserFraction.cs
index 1de7577..2fb9fa8 100644
--- a/src/Games/Calculation/CalculationCloserFraction.cs
+++ b/src/Games/Calculation/CalculationCloserFraction.cs
@@ -155,7 +155,7 @@ namespace gbrainy.Games.Calculation
 			{
 				gr.MoveTo (x, y);
 				indx = random_indices[i];
-				gr.ShowPangoText (String.Format ("{0}) {1}", GetPossibleAnswer (i) , options [indx * 2] +  " / " + options [(indx  * 2) +1]));
+				gr.ShowPangoText (String.Format (Catalog.GetString ("{0}) {1}"), GetPossibleAnswer (i) , options [indx * 2] +  " / " + options [(indx  * 2) +1]));
 			
 				y = y + 0.15;
 			}
diff --git a/src/Games/Logic/PuzzleFigures.cs b/src/Games/Logic/PuzzleFigures.cs
index 4405399..a771249 100644
--- a/src/Games/Logic/PuzzleFigures.cs
+++ b/src/Games/Logic/PuzzleFigures.cs
@@ -24,6 +24,7 @@ using Mono.Unix;
 
 using gbrainy.Core.Main;
 using gbrainy.Core.Libraries;
+using gbrainy.Core.Toolkit;
 
 namespace gbrainy.Games.Logic
 {
@@ -47,7 +48,6 @@ namespace gbrainy.Games.Logic
 			get {return Catalog.GetString ("What is the next logical sequence of objects in the last column? See below the convention when giving the answer.");} 
 		}
 
-
 		public override string Answer {
 			get { 
 				string answer = base.Answer + " ";
@@ -70,43 +70,45 @@ namespace gbrainy.Games.Logic
 			sb.Append (GetPossibleAnswer (figures[(2 * 6) + random_indices [5]]));
 
 			right_answer = sb.ToString ();
-		}
 
-		private void AnswerCoding (CairoContextEx gr, double x, double y)
-		{
-			double pos_x = x;
+			HorizontalContainer container = new HorizontalContainer (DrawAreaX, 0.75, 0.8, 0.1);
+			AddWidget (container);
 
-			gr.MoveTo (pos_x, y - 0.01);
-			y += 0.05;
-			gr.ShowPangoText (Catalog.GetString ("Convention when giving the answer is:"));
+			DrawableArea drawable_area = new DrawableArea (0.8 / 3, 0.1);
+			drawable_area.Sensitive = false;
+			container.AddChild (drawable_area);
 
-			gr.MoveTo (pos_x, y + 0.05);
-			gr.ShowPangoText (String.Format (Catalog.GetString ("{0} ->"), GetPossibleAnswer (0)));
-			gr.Stroke ();
-			gr.DrawDiamond (x + 0.1, y, 0.1);
-			gr.Stroke ();
-	
-			pos_x += 0.3;
-			gr.MoveTo (pos_x, y + 0.05);
-			gr.ShowPangoText (String.Format (Catalog.GetString ("{0} ->"), GetPossibleAnswer (1)));
-			gr.Stroke ();
-			pos_x += 0.1;
-			gr.Arc (pos_x + 0.05, y + 0.05, 0.05, 0, 2 * Math.PI);	
-			gr.Stroke ();
-
-			pos_x += 0.2;
-			gr.MoveTo (pos_x, y + 0.05);
-			gr.ShowPangoText (String.Format (Catalog.GetString ("{0} ->"), GetPossibleAnswer (2)));
-			gr.Stroke ();
-			pos_x += 0.1;
-			gr.DrawEquilateralTriangle (pos_x, y, 0.1);
-			gr.Stroke ();
+			drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
+			{
+				e.Context.MoveTo (0, 0.05);
+				e.Context.ShowPangoText (String.Format (Catalog.GetString ("{0} ->"), GetPossibleAnswer (0)));
+				e.Context.DrawDiamond (0.1, 0, 0.1);
+				e.Context.Stroke ();
+			};
 
-			y += 0.16;
-			gr.MoveTo (x, y);		
-			gr.ShowPangoText (String.Format (Catalog.GetString ("E.g: {0}{1}{2} (diamond, triangle, circle)"),
-				GetPossibleAnswer (0), GetPossibleAnswer (2), GetPossibleAnswer (1)));
+			drawable_area = new DrawableArea (0.8 / 3, 0.1);
+			drawable_area.Sensitive = false;
+			container.AddChild (drawable_area);
 
+			drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
+			{
+				e.Context.MoveTo (0, 0.05);
+				e.Context.ShowPangoText (String.Format (Catalog.GetString ("{0} ->"), GetPossibleAnswer (1)));
+				e.Context.Stroke ();
+				e.Context.Arc (0.15, 0.05, 0.05, 0, 2 * Math.PI);
+				e.Context.Stroke ();
+			};
+
+			drawable_area = new DrawableArea (0.8 / 3, 0.1);
+			drawable_area.Sensitive = false;
+			container.AddChild (drawable_area);
+
+			drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
+			{
+				e.Context.MoveTo (0, 0.05);
+				e.Context.ShowPangoText (String.Format (Catalog.GetString ("{0} ->"), GetPossibleAnswer (2)));
+				e.Context.DrawEquilateralTriangle (0.1, 0, 0.1);
+			};
 		}
 
 		public override void Draw (CairoContextEx gr, int area_width, int area_height, bool rtl)
@@ -157,7 +159,15 @@ namespace gbrainy.Games.Logic
 				gr.Restore ();	
 			}
 
-			AnswerCoding (gr, DrawAreaX, y);
+			x = DrawAreaX;
+			gr.MoveTo (x, y - 0.01);
+			y += 0.05;
+			gr.ShowPangoText (Catalog.GetString ("Convention when giving the answer is:"));
+
+			y += 0.16;
+			gr.MoveTo (x, y);		
+			gr.ShowPangoText (String.Format (Catalog.GetString ("E.g: {0}{1}{2} (diamond, triangle, circle)"),
+				GetPossibleAnswer (0), GetPossibleAnswer (2), GetPossibleAnswer (1)));
 		}
 
 		public override bool CheckAnswer (string answer)
diff --git a/src/Games/Logic/PuzzleMostInCommon.cs b/src/Games/Logic/PuzzleMostInCommon.cs
index b4e4846..a2ad804 100644
--- a/src/Games/Logic/PuzzleMostInCommon.cs
+++ b/src/Games/Logic/PuzzleMostInCommon.cs
@@ -25,6 +25,7 @@ using System.Collections;
 
 using gbrainy.Core.Main;
 using gbrainy.Core.Libraries;
+using gbrainy.Core.Toolkit;
 
 namespace gbrainy.Games.Logic
 {
@@ -174,6 +175,33 @@ namespace gbrainy.Games.Logic
 			array.AddRange (new Element [] {Element.MediumCircle, Element.MediumCircleWithChild, Element.MediumCircleWithChild, 
 				Element.MediumCircle,Element.MediumCircle, Element.MediumCircleWithChild, Element.MediumCircleWithChild});
 			answers.Add (BuildFigure (array, answers));
+
+			double figure_size = 0.22;
+			double x = DrawAreaX - 0.05, y = DrawAreaY + 0.45;
+
+			HorizontalContainer container = new HorizontalContainer (x, y, random_indices_answers.Count * figure_size, 0.3);
+			DrawableArea drawable_area;
+		
+			AddWidget (container);
+
+			for (int i = 0; i < random_indices_answers.Count; i++)
+			{
+				drawable_area = new DrawableArea (figure_size, figure_size + 0.05);
+				drawable_area.SelectedArea = new Rectangle (0.05, 0.05, 0.15, 0.15);
+				drawable_area.Data = i;
+				drawable_area.DataEx = GetPossibleAnswer (i);
+
+				drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
+				{
+					int n = (int) e.Data;
+
+					DrawFigure (e.Context, 0.05, 0.05, (FigureElement []) answers[random_indices_answers[n]]);
+					e.Context.MoveTo (0.05, 0.22);
+					e.Context.ShowPangoText (GetPossibleFigureAnswer (n));
+				};
+			
+				container.AddChild (drawable_area);
+			}
 		}
 
 		private ArrayListIndicesRandom RandomizeFromArray (ArrayList ar)
@@ -288,14 +316,6 @@ namespace gbrainy.Games.Logic
 			gr.MoveTo (x - 0.06, y);
 			gr.ShowPangoText (Catalog.GetString ("Possible answers are:"));
 			gr.Stroke ();
-	
-			y += 0.08;
-			for (int i = 0; i < random_indices_answers.Count; i++) {
-				DrawFigure (gr, x, y, (FigureElement []) answers[(int)random_indices_answers[i]]);
-				gr.MoveTo (x, y + 0.2);
-				x+= 0.22;
-				gr.ShowPangoText (GetPossibleFigureAnswer (i));
-			}
 		}
 	}
 }
diff --git a/src/Games/Logic/PuzzleOstracism.cs b/src/Games/Logic/PuzzleOstracism.cs
index cf7be55..9d74022 100644
--- a/src/Games/Logic/PuzzleOstracism.cs
+++ b/src/Games/Logic/PuzzleOstracism.cs
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007-2009 Jordi Mas i Hernàndez <jmas softcatala org>
+ * Copyright (C) 2007-2010 Jordi Mas i Hernàndez <jmas softcatala org>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -23,6 +23,7 @@ using Mono.Unix;
 
 using gbrainy.Core.Main;
 using gbrainy.Core.Libraries;
+using gbrainy.Core.Toolkit;
 
 namespace gbrainy.Games.Logic
 {
@@ -133,20 +134,28 @@ namespace gbrainy.Games.Logic
 					break;
 				}
 			}
-		}
-
-		public override void Draw (CairoContextEx gr, int area_width, int area_height, bool rtl)
-		{
-			double x = DrawAreaX + 0.20, y = DrawAreaY + 0.2;
 
-			base.Draw (gr, area_width, area_height, rtl);
+			Container container = new Container (DrawAreaX + 0.1, DrawAreaY + 0.2, 0.5, random_indices.Count * 0.1);
+			AddWidget (container);
 
-			gr.SetPangoLargeFontSize ();		
 			for (int i = 0; i < random_indices.Count; i++)
 			{
-				gr.MoveTo (x, y);
-				gr.ShowPangoText (String.Format ("{0}) {1}", GetPossibleAnswer (i), equations [random_indices[i]]));
-				y += 0.1;
+				DrawableArea drawable_area = new DrawableArea (0.5, 0.1);
+				drawable_area.X = DrawAreaX + 0.1;
+				drawable_area.Y = DrawAreaY + 0.2 + i * 0.1;
+				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;
+
+					e.Context.SetPangoLargeFontSize ();
+					e.Context.MoveTo (0.05, 0.02);
+					// Translators: this "option) answer" for example "a) "21 x 60 = 1260". This should not be changed for most of the languages
+					e.Context.ShowPangoText (String.Format (Catalog.GetString ("{0}) {1}"), GetPossibleAnswer (n), equations [random_indices[n]]));
+				};
 			}
 		}
 	}
diff --git a/src/Games/Logic/PuzzlePredicateLogic.cs b/src/Games/Logic/PuzzlePredicateLogic.cs
index be74812..819bed3 100644
--- a/src/Games/Logic/PuzzlePredicateLogic.cs
+++ b/src/Games/Logic/PuzzlePredicateLogic.cs
@@ -24,6 +24,7 @@ using Mono.Unix;
 
 using gbrainy.Core.Main;
 using gbrainy.Core.Libraries;
+using gbrainy.Core.Toolkit;
 
 namespace gbrainy.Games.Logic
 {
@@ -127,32 +128,40 @@ namespace gbrainy.Games.Logic
 				}
 			}
 
+			Container container = new Container (DrawAreaX, DrawAreaX + 0.2, 0.8, 0.6);
+			AddWidget (container);
+	
+			for (int i = 0; i <  predicates[question].options.Length; i++)
+			{
+				int opt = random_indices [i];
+
+				DrawableArea drawable_area = new DrawableArea (0.8, 0.1);
+				drawable_area.X = DrawAreaX;
+				drawable_area.Y = DrawAreaY + 0.2 + i * 0.15;
+				container.AddChild (drawable_area);
+				drawable_area.Data = opt;
+				drawable_area.DataEx = GetPossibleAnswer (opt);
+
+				drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
+				{
+					int option = (int) e.Data;
+					
+					e.Context.SetPangoNormalFontSize ();
+					e.Context.MoveTo (0.05, 0.02);
+					e.Context.ShowPangoText (String.Format (Catalog.GetString ("{0}) {1}"), GetPossibleAnswer (option),
+						predicates[question].options[option].ToString ()));
+					e.Context.Stroke ();
+				};
+			}
 		}
 
 		public override void Draw (CairoContextEx gr, int area_width, int area_height, bool rtl)
 		{
-			double x = DrawAreaX, y = DrawAreaY + 0.1;
-			int option;
-
 			base.Draw (gr, area_width, area_height, rtl);
 
 			gr.SetPangoLargeFontSize ();
-			gr.MoveTo (0.1, y);
+			gr.MoveTo (0.1, DrawAreaY + 0.1);
 			gr.ShowPangoText (Catalog.GetString ("Possible answers are:"));
-
-			gr.SetPangoNormalFontSize ();
-
-			y += 0.15;
-			x += 0.05;
-			for (int n = 0; n < predicates[question].options.Length; n++)
-			{
-				option = random_indices [n];
-				gr.MoveTo (x, y);
-				gr.ShowPangoText (String.Format ("{0}) {1}", GetPossibleAnswer (n),
-					predicates[question].options[option].ToString ()));
-				gr.Stroke ();
-				y += 0.15;
-			}
 		}
 	}
 }



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