[gbrainy] PlayerHistory view logic is moved to its own view as part of Core



commit 822320f7e4a37cc719aacd9d32d3fb8698d5fa90
Author: Jordi Mas <jmas softcatala org>
Date:   Sat Nov 28 19:14:41 2009 +0100

    PlayerHistory view logic is moved to its own view as part of Core

 po/POTFILES.in                                     |    7 +-
 .../Classical/Dialogs/PlayerHistoryDialog.cs       |  211 +----------------
 src/Core/Makefile.am                               |    1 +
 src/Core/Views/PlayerHistoryView.cs                |  253 ++++++++++++++++++++
 4 files changed, 266 insertions(+), 206 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 1343f01..6d36adc 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -2,14 +2,10 @@ data/verbal_analogies.xml
 gbrainy.desktop.in
 src/Core/Views/CountDownView.cs
 src/Core/Views/FinishView.cs
-src/Core/Views/IDrawable.cs
-src/Core/Views/IDrawRequest.cs
+src/Core/Views/PlayerHistoryView.cs
 src/Core/Views/ViewsControler.cs
 src/Core/Views/WelcomeView.cs
 src/Core/Libraries/SVGImage.cs
-src/Core/Libraries/CairoContextEx.cs
-src/Core/Platform/Unix.cs
-src/Core/Main/ArrayListIndicesRandom.cs
 src/Core/Main/ColorPalette.cs
 src/Core/Main/Game.cs
 src/Core/Main/GameManager.cs
@@ -92,6 +88,5 @@ src/Games/Calculation/CalculationPrimes.cs
 src/Games/Calculation/CalculationProportions.cs
 src/Games/Calculation/CalculationRatio.cs
 src/Games/Calculation/CalculationTwoNumbers.cs
-src/Games/GameList.cs
 src/Clients/Classical/gbrainy.glade
 src/Clients/Classical/mono-addins-strings.xml
diff --git a/src/Clients/Classical/Dialogs/PlayerHistoryDialog.cs b/src/Clients/Classical/Dialogs/PlayerHistoryDialog.cs
index fa6e5e3..3f906dd 100644
--- a/src/Clients/Classical/Dialogs/PlayerHistoryDialog.cs
+++ b/src/Clients/Classical/Dialogs/PlayerHistoryDialog.cs
@@ -24,6 +24,7 @@ using System.Collections;
 
 using gbrainy.Core.Main;
 using gbrainy.Core.Libraries;
+using gbrainy.Core.Views;
 
 namespace gbrainy.Clients.Classical
 {
@@ -71,223 +72,48 @@ namespace gbrainy.Clients.Classical
 
 		void OnTotalToggled (object sender, EventArgs args)
 		{
+			drawing_area.View.ShowTotal = checkbutton_total.Active;
 			drawing_area.QueueDraw ();
 		}
 
 		void OnLogicToggled (object sender, EventArgs args)
 		{
+			drawing_area.View.ShowLogic = checkbutton_logic.Active;
 			drawing_area.QueueDraw ();
 		}
 
 		void OnMemoryToggled (object sender, EventArgs args)
 		{
+			drawing_area.View.ShowMemory = checkbutton_memory.Active;
 			drawing_area.QueueDraw ();
 		}
 
 		void OnCalculationToggled (object sender, EventArgs args)
 		{
+			drawing_area.View.ShowCalculation = checkbutton_calculation.Active;
 			drawing_area.QueueDraw ();
 		}
 
 		void OnVerbalToggled (object sender, EventArgs args)
 		{
+			drawing_area.View.ShowVerbal = checkbutton_verbal.Active;
 			drawing_area.QueueDraw ();
 		}
 
 		public class CairoPreview : DrawingArea 
 		{
-			const double area_h = 0.8, area_w = 0.9, point_size = 0.005 * 1.25;
-			Cairo.Color math_color = new Cairo.Color (0.56, 0.71, 0.20);    // 8fb735
-			Cairo.Color logic_color = new Cairo.Color (0.81, 0.54, 0.23);   // d18c3b
-			Cairo.Color memory_color = new Cairo.Color (0.73, 0.22, 0.51);  // bb3a84
-			Cairo.Color verbal_color = new Cairo.Color (0.68, 0.16, 0.17);  // af2b2c
-			Cairo.Color total_color = new Cairo.Color (0, 0, 0.6);
-			Cairo.Color text_color = new Cairo.Color (0, 0, 0);
-			Cairo.Color axis_color = new Cairo.Color (0.15, 0.15, 0.15);
 			PlayerHistoryDialog dlg;
+			PlayerHistoryView view;
 
 			public CairoPreview (PlayerHistoryDialog dlg)
 			{
 				this.dlg = dlg;
+				view = new PlayerHistoryView (dlg.PlayerHistory);
 			}
 
-			private void DrawLegend (CairoContextEx cr, double x, double y)
-			{
-				const double line_size = 0.05, offset_x = 0.01, second_row = 0.05, space_hor = 0.4;
-				double old_width;
-
-				old_width = cr.LineWidth;
-				cr.LineWidth = 0.01;
-		
-				cr.Color = total_color;
-				cr.MoveTo (x, y);
-				cr.LineTo (x + line_size, y);
-				cr.Stroke ();
-				cr.Color = text_color;
-				cr.MoveTo (x + line_size + offset_x, y - 0.01);
-				cr.ShowPangoText (Catalog.GetString ("Total"));
-				cr.Stroke ();
-
-				cr.Color = logic_color;
-				cr.MoveTo (x, y + second_row);
-				cr.LineTo (x + line_size, y + second_row);
-				cr.Stroke ();
-				cr.Color = text_color;
-				cr.MoveTo (x + line_size + offset_x, y - 0.01 + second_row);
-				cr.ShowPangoText (Game.GetGameTypeDescription (Game.Types.LogicPuzzle));
-				cr.Stroke ();
-
-				x += space_hor;
-				cr.Color = memory_color;
-				cr.MoveTo (x, y);
-				cr.LineTo (x + line_size, y);
-				cr.Stroke ();
-				cr.Color = text_color;
-				cr.MoveTo (x + line_size + offset_x, y - 0.01);
-				cr.ShowPangoText (Game.GetGameTypeDescription (Game.Types.MemoryTrainer));
-				cr.Stroke ();
-
-				cr.Color = math_color;
-				cr.MoveTo (x, y + second_row);
-				cr.LineTo (x + line_size, y + second_row);
-				cr.Stroke ();
-				cr.Color = text_color;
-				cr.MoveTo (x + line_size + offset_x, y - 0.01 + second_row);
-				cr.ShowPangoText (Game.GetGameTypeDescription (Game.Types.MathTrainer));
-				cr.Stroke ();
-
-				x += space_hor;
-				cr.Color = verbal_color;
-				cr.MoveTo (x, y);
-				cr.LineTo (x + line_size, y);
-				cr.Stroke ();
-				cr.Color = text_color;
-				cr.MoveTo (x + line_size + offset_x, y - 0.01);
-				cr.ShowPangoText (Game.GetGameTypeDescription (Game.Types.VerbalAnalogy));
-				cr.Stroke ();
-
-				cr.LineWidth = old_width;
+			public PlayerHistoryView View {
+				get { return view; }
 			}
-
-			private void DrawLines (CairoContextEx cr, double x, double y)
-			{
-				double px, py;
-				PlayerHistory history = dlg.PlayerHistory;
-				double ratio;
-				int pos;
-
-				if (history.Games.Count == 0)
-					return;
-
-				ratio = area_w / (history.Games.Count - 1);
-		
-				if (dlg.checkbutton_logic.Active) { // Logic
-					cr.Color = logic_color;
-					cr.MoveTo (x, area_h - (area_h * history.Games[0].logic_score / 100));
-
-					pos = 1;
-					for (int i = 1; i < history.Games.Count; i++)
-					{
-						if (history.Games[i].logic_score < 0)
-							continue;
-
-						px = x + (ratio * pos);
-						py = y + area_h - (area_h * history.Games[i].logic_score / 100);
-						cr.LineTo (px, py);
-						pos++;
-					}
-					cr.Stroke ();
-				}
-
-				if (dlg.checkbutton_calculation.Active) { // Math
-					cr.Color = math_color;
-					cr.MoveTo (x, area_h - (area_h * history.Games[0].math_score / 100));
-
-					pos = 1;
-					for (int i = 1; i < history.Games.Count; i++)
-					{
-						if (history.Games[i].math_score < 0)
-							continue;
-
-						px = x + (ratio * pos);
-						py = y + area_h - (area_h * history.Games[i].math_score / 100);
-						cr.LineTo (px, py);
-						pos++;
-					}
-					cr.Stroke ();
-				}
-
-				if (dlg.checkbutton_memory.Active) { // Memory
-					cr.Color = memory_color;
-					cr.MoveTo (x, area_h - (area_h * history.Games[0].memory_score / 100));
-
-					pos = 1;
-					for (int i = 1; i < history.Games.Count; i++)
-					{
-						if (history.Games[i].memory_score < 0)
-							continue;
-
-						px = x + (ratio * pos);
-						py = y + area_h - (area_h * history.Games[i].memory_score / 100);
-						cr.LineTo (px, py);
-						pos++;
-					}
-					cr.Stroke ();
-				}
-
-				if (dlg.checkbutton_verbal.Active) { // Verbal
-					cr.Color = verbal_color;
-					cr.MoveTo (x, area_h - (area_h * history.Games[0].verbal_score / 100));
-
-					pos = 1;
-					for (int i = 1; i < history.Games.Count; i++)
-					{
-						if (history.Games[i].verbal_score < 0)
-							continue;
-
-						px = x + (ratio * pos);
-						py = y + area_h - (area_h * history.Games[i].verbal_score / 100);
-						cr.LineTo (px, py);
-						pos++;
-					}
-					cr.Stroke ();
-				}
-
-				if (dlg.checkbutton_total.Active) { // Total			
-					cr.Color = total_color;
-					cr.MoveTo (x, area_h - (area_h * history.Games[0].total_score / 100));
-
-					pos = 1;
-					for (int i = 1; i < history.Games.Count; i++)
-					{
-						if (history.Games[pos].total_score < 0)
-							continue;
-
-						px = x + (ratio * pos);
-						py = y + area_h - (area_h * history.Games[i].total_score / 100);
-						cr.LineTo (px, py);
-						pos++;
-					}
-					cr.Stroke ();
-				}
-			}
-
-			private void DrawGrid (CairoContextEx cr, double x, double y)
-			{
-				// Draw Axis
-				cr.MoveTo (x, y);
-				cr.LineTo (x, y + area_h);
-				cr.LineTo (x + area_w, y + area_h);
-				cr.Stroke ();
-
-				cr.Color = new Cairo.Color (0.8, 0.8, 0.8);
-				cr.LineWidth = 0.001;
-				for (double line_y = y; line_y < area_h + y; line_y += area_h / 10) {
-					cr.MoveTo (x, line_y);
-					cr.LineTo (x + area_w, line_y);
-					cr.Stroke ();
-				}
-			}		
 	
 			protected override bool OnExposeEvent (Gdk.EventExpose args)
 			{
@@ -314,22 +140,7 @@ namespace gbrainy.Clients.Classical
 				cr.Translate (x, y);
 				cr.Scale (nw, nh);
 
-				// Background
-				cr.Color = new Cairo.Color (1, 1, 1);
-				cr.Paint ();
-				cr.Stroke ();
-
-				x = 0.05; 
-				y = 0.05;
-				cr.LineWidth = point_size;
-				cr.Color = axis_color;
-
-				cr.Rectangle (x, y, area_w, area_h);
-				cr.Clip ();
-				DrawLines (cr, x, y);
-				cr.ResetClip ();
-				DrawLegend (cr, x, y + area_h + 0.05);
-				DrawGrid (cr, x, y);
+				view.Draw (cr, nw, nh, Direction == Gtk.TextDirection.Rtl);
 
 				((IDisposable)cc).Dispose();
 				((IDisposable)cr).Dispose();
diff --git a/src/Core/Makefile.am b/src/Core/Makefile.am
index 334129f..ee546f0 100644
--- a/src/Core/Makefile.am
+++ b/src/Core/Makefile.am
@@ -26,6 +26,7 @@ CSFILES =  \
 		Views/FinishView.cs		\
 		Views/IDrawable.cs		\
 		Views/IDrawRequest.cs		\
+		Views/PlayerHistoryView.cs	\
 		Views/ViewsControler.cs		\
 		Views/WelcomeView.cs		\
 		Platform/Unix.cs		\
diff --git a/src/Core/Views/PlayerHistoryView.cs b/src/Core/Views/PlayerHistoryView.cs
new file mode 100644
index 0000000..a5e1d83
--- /dev/null
+++ b/src/Core/Views/PlayerHistoryView.cs
@@ -0,0 +1,253 @@
+/*
+ * Copyright (C) 2007-2009 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
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+
+using System;
+using Cairo;
+using Mono.Unix;
+
+using gbrainy.Core.Main;
+using gbrainy.Core.Libraries;
+
+namespace gbrainy.Core.Views
+{
+	public class PlayerHistoryView : IDrawable
+	{
+		const double area_h = 0.8, area_w = 0.9, point_size = 0.005 * 1.25;
+		Cairo.Color math_color = new Cairo.Color (0.56, 0.71, 0.20);    // 8fb735
+		Cairo.Color logic_color = new Cairo.Color (0.81, 0.54, 0.23);   // d18c3b
+		Cairo.Color memory_color = new Cairo.Color (0.73, 0.22, 0.51);  // bb3a84
+		Cairo.Color verbal_color = new Cairo.Color (0.68, 0.16, 0.17);  // af2b2c
+		Cairo.Color total_color = new Cairo.Color (0, 0, 0.6);
+		Cairo.Color text_color = new Cairo.Color (0, 0, 0);
+		Cairo.Color axis_color = new Cairo.Color (0.15, 0.15, 0.15);
+		PlayerHistory history;
+
+		public PlayerHistoryView (PlayerHistory history)
+		{
+			this.history = history;
+			ShowLogic = ShowMemory = ShowCalculation = ShowVerbal = true;
+		}
+
+		public bool ShowTotal { get; set; }
+		public bool ShowLogic { get; set; }
+		public bool ShowMemory { get; set; }
+		public bool ShowCalculation { get; set; }
+		public bool ShowVerbal { get; set; }
+		
+		void DrawLegend (CairoContextEx cr, double x, double y)
+		{
+			const double line_size = 0.05, offset_x = 0.01, second_row = 0.05, space_hor = 0.4;
+			double old_width;
+
+			old_width = cr.LineWidth;
+			cr.LineWidth = 0.01;
+	
+			cr.Color = total_color;
+			cr.MoveTo (x, y);
+			cr.LineTo (x + line_size, y);
+			cr.Stroke ();
+			cr.Color = text_color;
+			cr.MoveTo (x + line_size + offset_x, y - 0.01);
+			cr.ShowPangoText (Catalog.GetString ("Total"));
+			cr.Stroke ();
+
+			cr.Color = logic_color;
+			cr.MoveTo (x, y + second_row);
+			cr.LineTo (x + line_size, y + second_row);
+			cr.Stroke ();
+			cr.Color = text_color;
+			cr.MoveTo (x + line_size + offset_x, y - 0.01 + second_row);
+			cr.ShowPangoText (Game.GetGameTypeDescription (Game.Types.LogicPuzzle));
+			cr.Stroke ();
+
+			x += space_hor;
+			cr.Color = memory_color;
+			cr.MoveTo (x, y);
+			cr.LineTo (x + line_size, y);
+			cr.Stroke ();
+			cr.Color = text_color;
+			cr.MoveTo (x + line_size + offset_x, y - 0.01);
+			cr.ShowPangoText (Game.GetGameTypeDescription (Game.Types.MemoryTrainer));
+			cr.Stroke ();
+
+			cr.Color = math_color;
+			cr.MoveTo (x, y + second_row);
+			cr.LineTo (x + line_size, y + second_row);
+			cr.Stroke ();
+			cr.Color = text_color;
+			cr.MoveTo (x + line_size + offset_x, y - 0.01 + second_row);
+			cr.ShowPangoText (Game.GetGameTypeDescription (Game.Types.MathTrainer));
+			cr.Stroke ();
+
+			x += space_hor;
+			cr.Color = verbal_color;
+			cr.MoveTo (x, y);
+			cr.LineTo (x + line_size, y);
+			cr.Stroke ();
+			cr.Color = text_color;
+			cr.MoveTo (x + line_size + offset_x, y - 0.01);
+			cr.ShowPangoText (Game.GetGameTypeDescription (Game.Types.VerbalAnalogy));
+			cr.Stroke ();
+
+			cr.LineWidth = old_width;
+		}
+
+		void DrawLines (CairoContextEx cr, double x, double y)
+		{
+			double px, py;
+			double ratio;
+			int pos;
+
+			if (history.Games.Count == 0)
+				return;
+
+			ratio = area_w / (history.Games.Count - 1);
+	
+			if (ShowLogic) {
+				cr.Color = logic_color;
+				cr.MoveTo (x, area_h - (area_h * history.Games[0].logic_score / 100));
+
+				pos = 1;
+				for (int i = 1; i < history.Games.Count; i++)
+				{
+					if (history.Games[i].logic_score < 0)
+						continue;
+
+					px = x + (ratio * pos);
+					py = y + area_h - (area_h * history.Games[i].logic_score / 100);
+					cr.LineTo (px, py);
+					pos++;
+				}
+				cr.Stroke ();
+			}
+
+			if (ShowCalculation) {
+				cr.Color = math_color;
+				cr.MoveTo (x, area_h - (area_h * history.Games[0].math_score / 100));
+
+				pos = 1;
+				for (int i = 1; i < history.Games.Count; i++)
+				{
+					if (history.Games[i].math_score < 0)
+						continue;
+
+					px = x + (ratio * pos);
+					py = y + area_h - (area_h * history.Games[i].math_score / 100);
+					cr.LineTo (px, py);
+					pos++;
+				}
+				cr.Stroke ();
+			}
+
+			if (ShowMemory) {
+				cr.Color = memory_color;
+				cr.MoveTo (x, area_h - (area_h * history.Games[0].memory_score / 100));
+
+				pos = 1;
+				for (int i = 1; i < history.Games.Count; i++)
+				{
+					if (history.Games[i].memory_score < 0)
+						continue;
+
+					px = x + (ratio * pos);
+					py = y + area_h - (area_h * history.Games[i].memory_score / 100);
+					cr.LineTo (px, py);
+					pos++;
+				}
+				cr.Stroke ();
+			}
+
+			if (ShowVerbal) {
+				cr.Color = verbal_color;
+				cr.MoveTo (x, area_h - (area_h * history.Games[0].verbal_score / 100));
+
+				pos = 1;
+				for (int i = 1; i < history.Games.Count; i++)
+				{
+					if (history.Games[i].verbal_score < 0)
+						continue;
+
+					px = x + (ratio * i);
+					py = y + area_h - (area_h * history.Games[i].verbal_score / 100);
+					cr.LineTo (px, py);
+					pos++;
+				}
+				cr.Stroke ();
+			}
+
+			if (ShowTotal) {
+				cr.Color = total_color;
+				cr.MoveTo (x, area_h - (area_h * history.Games[0].total_score / 100));
+
+				pos = 1;
+				for (int i = 1; i < history.Games.Count; i++)
+				{
+					if (history.Games[pos].total_score < 0)
+						continue;
+
+					px = x + (ratio * pos);
+					py = y + area_h - (area_h * history.Games[i].total_score / 100);
+					cr.LineTo (px, py);
+					pos++;
+				}
+				cr.Stroke ();
+			}
+		}
+
+		void DrawGrid (CairoContextEx cr, double x, double y)
+		{
+			// Draw Axis
+			cr.MoveTo (x, y);
+			cr.LineTo (x, y + area_h);
+			cr.LineTo (x + area_w, y + area_h);
+			cr.Stroke ();
+
+			cr.Color = new Cairo.Color (0.8, 0.8, 0.8);
+			cr.LineWidth = 0.001;
+			for (double line_y = y; line_y < area_h + y; line_y += area_h / 10) {
+				cr.MoveTo (x, line_y);
+				cr.LineTo (x + area_w, line_y);
+				cr.Stroke ();
+			}
+		}		
+
+		public void Draw (CairoContextEx cr, int width, int height, bool rtl)
+		{
+			double x, y;
+
+			// Background
+			cr.Color = new Cairo.Color (1, 1, 1);
+			cr.Paint ();
+			cr.Stroke ();
+
+			x = 0.05; 
+			y = 0.05;
+			cr.LineWidth = point_size;
+			cr.Color = axis_color;
+
+			cr.Rectangle (x, y, area_w, area_h);
+			cr.Clip ();
+			DrawLines (cr, x, y);
+			cr.ResetClip ();
+			DrawLegend (cr, x, y + area_h + 0.05);
+			DrawGrid (cr, x, y);
+		}
+	}
+}



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