[gbrainy/gbrainy-17x] Visual support for Pause + refactor



commit c46cce5945fccd360215a2e6430f20a19b31bf68
Author: Jordi Mas <jmas softcatala org>
Date:   Fri Jan 7 21:16:41 2011 +0100

    Visual support for Pause + refactor

 src/Clients/Classical/Widgets/GameDrawingArea.cs |  102 ++++++++++++++--------
 src/Clients/Classical/gbrainy.cs                 |    2 +
 2 files changed, 68 insertions(+), 36 deletions(-)
---
diff --git a/src/Clients/Classical/Widgets/GameDrawingArea.cs b/src/Clients/Classical/Widgets/GameDrawingArea.cs
index 4cf04ac..2692918 100644
--- a/src/Clients/Classical/Widgets/GameDrawingArea.cs
+++ b/src/Clients/Classical/Widgets/GameDrawingArea.cs
@@ -20,6 +20,7 @@
 using System;
 using Gtk;
 using Cairo;
+using Mono.Unix;
 
 using gbrainy.Core.Main;
 
@@ -30,6 +31,8 @@ namespace gbrainy.Clients.Classical.Widgets
 	// question or answer, etc.
 	public class GameDrawingArea : DrawingArea
 	{
+		bool paused;
+
 		public IDrawable Drawable { get; set; }
 		public string Question { get; set; }
 		public string Solution { get; set; }
@@ -38,6 +41,20 @@ namespace gbrainy.Clients.Classical.Widgets
 		public int OffsetY { get; private set; }
 		public bool UseSolutionArea { get; set; }
 
+		public bool Paused { 
+			get { return paused; }
+			set {
+				paused = value;
+				QueueDraw ();
+			}
+		}
+
+		// Constants
+		const int question_high = 55;
+		const int solution_high = 55;
+		const int total_margin = 0; // Margin applied as in-box for themes
+		const double text_margin = 0.015;
+
 		public GameDrawingArea ()
 		{
 			UseSolutionArea = true;
@@ -49,9 +66,6 @@ namespace gbrainy.Clients.Classical.Widgets
 				return false;
 
 			int w, h, total_w, total_h;
-			const int question_high = 55;
-			const int solution_high = 55;
-			const int total_margin = 0; // Margin applied as in-box for themes
 
 			Cairo.Context cc = Gdk.CairoHelper.Create (args.Window);
 			CairoContextEx cr = new CairoContextEx (cc.Handle, this);
@@ -80,48 +94,64 @@ namespace gbrainy.Clients.Classical.Widgets
 
 			OffsetY += question_high + total_margin;
 
-			// Draw a background taking all the area
-			double line_space = cr.FontLineSpace;
 			cr.Save ();
-			{
-				const double text_margin = 0.015;
-				double scaled_margin;
-				double max_width;
-
-				cr.Scale (total_w, total_h);
-				cr.DrawBackground ();
-				cr.FontLineSpace = 0.004;
-				cr.SetPangoFontSize (0.018);
-
-				scaled_margin = (double) total_margin / (double) total_w;
-				max_width = 1 - (scaled_margin * 2) - (text_margin * 2);
-				cr.UseMarkup = true;
-
-				if (String.IsNullOrEmpty (Question) == false)
-				{
-					// Question drawing
-					cr.DrawStringWithWrapping (scaled_margin + text_margin, scaled_margin + text_margin, Question, max_width);
-				}
-
-				if (UseSolutionArea && String.IsNullOrEmpty (Solution) == false)
-				{
-					// Solution drawing
-					cr.DrawStringWithWrapping (scaled_margin + text_margin, 1 - 0.12 - scaled_margin - text_margin, Solution, max_width);
-				}
+
+			// Draw a background taking all the window area
+			cr.Scale (total_w, total_h);
+			cr.DrawBackground ();
+			
+			if (Paused == false) {
+				DrawQuestionAndAnswer (cr, total_w, total_h);
+			} else {
+				cr.SetPangoFontSize (0.08);
+				cr.DrawTextCentered (0.5, 0.5, Catalog.GetString ("Paused"));
 				cr.Stroke ();
 			}
-
-			cr.FontLineSpace = line_space;
 			cr.Restore ();
 
-			// Draw the game area
-			cr.Translate (OffsetX, OffsetY);
-			cr.SetPangoNormalFontSize ();
-			Drawable.Draw (cr, DrawingSquare, DrawingSquare, Direction == Gtk.TextDirection.Rtl);
+			if (Paused == false)
+			{
+				// Draw the game area
+				cr.Translate (OffsetX, OffsetY);
+				cr.SetPangoNormalFontSize ();
+				cr.Color = new Color (1, 1, 1, 0.5);
+				Drawable.Draw (cr, DrawingSquare, DrawingSquare, Direction == Gtk.TextDirection.Rtl);
+				cr.Stroke ();
+			}
 
 			((IDisposable)cc).Dispose();
 			((IDisposable)cr).Dispose();
 			return true;
 		}
+
+		void DrawQuestionAndAnswer (CairoContextEx cr, int width, int height)
+		{
+			double scaled_margin;
+			double max_width;
+			double line_space;
+
+			line_space = cr.FontLineSpace;
+			cr.FontLineSpace = 0.004;
+			cr.SetPangoFontSize (0.018);
+
+			scaled_margin = (double) total_margin / (double) width;
+			max_width = 1 - (scaled_margin * 2) - (text_margin * 2);
+			cr.UseMarkup = true;
+
+			if (String.IsNullOrEmpty (Question) == false)
+			{
+				// Question drawing
+				cr.DrawStringWithWrapping (scaled_margin + text_margin, scaled_margin + text_margin, Question, max_width);
+			}
+
+			if (UseSolutionArea && String.IsNullOrEmpty (Solution) == false)
+			{
+				// Solution drawing
+				cr.DrawStringWithWrapping (scaled_margin + text_margin, 1 - 0.12 - scaled_margin - text_margin, Solution, max_width);
+			}
+			cr.UseMarkup = false;
+			cr.Stroke ();
+			cr.FontLineSpace = line_space;
+		}
 	}
 }
diff --git a/src/Clients/Classical/gbrainy.cs b/src/Clients/Classical/gbrainy.cs
index 6b73b33..86a4db3 100755
--- a/src/Clients/Classical/gbrainy.cs
+++ b/src/Clients/Classical/gbrainy.cs
@@ -663,10 +663,12 @@ namespace gbrainy.Clients.Classical
 		void SetPauseResumeButtonUI (bool pause)
 		{
 			if (pause) {
+				drawing_area.Paused = false;
 				pause_tbbutton.StockId = "pause";
 				pause_tbbutton.Label = Catalog.GetString ("Pause");
 				ActiveInputControls (true);
 			} else {
+				drawing_area.Paused = true;	
 				pause_tbbutton.StockId = "resume";
 				pause_tbbutton.Label = Catalog.GetString ("Resume");
 				ActiveInputControls (false);



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