[gbrainy] Make history dialog box bigger plus add description to the axis



commit ee16dcc73009d8af5cd5e720316c851225f825ae
Author: Jordi Mas <jmas softcatala org>
Date:   Fri Nov 26 22:59:28 2010 +0100

    Make history dialog box bigger plus add description to the axis

 .../Classical/Dialogs/ui/PlayerHistoryDialog.ui    |    6 +-
 src/Core/Views/PlayerHistoryView.cs                |   96 ++++++++++++--------
 2 files changed, 59 insertions(+), 43 deletions(-)
---
diff --git a/src/Clients/Classical/Dialogs/ui/PlayerHistoryDialog.ui b/src/Clients/Classical/Dialogs/ui/PlayerHistoryDialog.ui
index e590dd9..54c17eb 100644
--- a/src/Clients/Classical/Dialogs/ui/PlayerHistoryDialog.ui
+++ b/src/Clients/Classical/Dialogs/ui/PlayerHistoryDialog.ui
@@ -6,8 +6,8 @@
     <property name="visible">True</property>
     <property name="border_width">7</property>
     <property name="title" translatable="yes">Player's Game Session History</property>
-    <property name="default_width">450</property>
-    <property name="default_height">450</property>
+    <property name="default_width">550</property>
+    <property name="default_height">550</property>
     <property name="type_hint">dialog</property>
     <property name="has_separator">False</property>
     <child internal-child="vbox">
@@ -21,7 +21,7 @@
             <property name="orientation">vertical</property>
             <child>
               <object class="GtkLabel" id="label_playerhistory">
-                <property name="width_request">400</property>
+                <property name="width_request">500</property>
                 <property name="visible">True</property>
                 <property name="xalign">0</property>
                 <property name="yalign">0</property>
diff --git a/src/Core/Views/PlayerHistoryView.cs b/src/Core/Views/PlayerHistoryView.cs
index eb767c6..0a249d4 100644
--- a/src/Core/Views/PlayerHistoryView.cs
+++ b/src/Core/Views/PlayerHistoryView.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
@@ -28,14 +28,20 @@ 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);
+		const double area_h = 0.80, area_w = 0.9, point_size = 0.005 * 1.25;
+		const double grid_offsetx = 0.1, grid_offsety = 0.1;
+		const double grid_x = grid_offsetx;
+		const double grid_y = grid_offsety;
+		const double grid_width = area_w -grid_offsetx;
+		const double grid_height = area_h - grid_offsety;
+		readonly Cairo.Color math_color = new Cairo.Color (0.56, 0.71, 0.20);    // 8fb735
+		readonly Cairo.Color logic_color = new Cairo.Color (0.81, 0.54, 0.23);   // d18c3b
+		readonly Cairo.Color memory_color = new Cairo.Color (0.73, 0.22, 0.51);  // bb3a84
+		readonly Cairo.Color verbal_color = new Cairo.Color (0.68, 0.16, 0.17);  // af2b2c
+		readonly Cairo.Color total_color = new Cairo.Color (0, 0, 0.6);
+		readonly Cairo.Color text_color = new Cairo.Color (0, 0, 0);
+		readonly Cairo.Color axis_color = new Cairo.Color (0.8, 0.8, 0.8);
+		readonly Cairo.Color desc_color = new Color (0.3, 0.3, 0.3);
 		PlayerHistory history;
 
 		public PlayerHistoryView (PlayerHistory history)
@@ -49,15 +55,25 @@ namespace gbrainy.Core.Views
 		public bool ShowMemory { get; set; }
 		public bool ShowCalculation { get; set; }
 		public bool ShowVerbal { get; set; }
-		
+
+		void DrawAxisDescription (CairoContextEx cr, double x, double y, string description)
+		{
+			cr.Save ();
+			cr.Color = desc_color;
+			cr.MoveTo (x, y);
+			cr.ShowPangoText (description);
+			cr.Stroke ();
+			cr.Restore ();
+		}
+
 		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;
+			const double line_size = 0.05, offset_x = 0.01, second_row = 0.05, space_hor = 0.35;
 			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);
@@ -117,11 +133,11 @@ namespace gbrainy.Core.Views
 			if (history.Games.Count == 0)
 				return;
 
-			ratio = area_w / (history.Games.Count - 1);
-	
+			ratio = grid_width / (history.Games.Count - 1);
+
 			if (ShowLogic) {
 				cr.Color = logic_color;
-				cr.MoveTo (x, area_h - (area_h * history.Games[0].LogicScore / 100));
+				cr.MoveTo (x, grid_height - (grid_height * history.Games[0].LogicScore / 100));
 
 				pos = 1;
 				for (int i = 1; i < history.Games.Count; i++)
@@ -130,7 +146,7 @@ namespace gbrainy.Core.Views
 						continue;
 
 					px = x + (ratio * pos);
-					py = y + area_h - (area_h * history.Games[i].LogicScore / 100);
+					py = y + grid_height - (grid_height * history.Games[i].LogicScore / 100);
 					cr.LineTo (px, py);
 					pos++;
 				}
@@ -139,7 +155,7 @@ namespace gbrainy.Core.Views
 
 			if (ShowCalculation) {
 				cr.Color = math_color;
-				cr.MoveTo (x, area_h - (area_h * history.Games[0].MathScore / 100));
+				cr.MoveTo (x, grid_height - (grid_height * history.Games[0].MathScore / 100));
 
 				pos = 1;
 				for (int i = 1; i < history.Games.Count; i++)
@@ -148,7 +164,7 @@ namespace gbrainy.Core.Views
 						continue;
 
 					px = x + (ratio * pos);
-					py = y + area_h - (area_h * history.Games[i].MathScore / 100);
+					py = y + grid_height - (grid_height * history.Games[i].MathScore / 100);
 					cr.LineTo (px, py);
 					pos++;
 				}
@@ -157,7 +173,7 @@ namespace gbrainy.Core.Views
 
 			if (ShowMemory) {
 				cr.Color = memory_color;
-				cr.MoveTo (x, area_h - (area_h * history.Games[0].MemoryScore / 100));
+				cr.MoveTo (x, grid_height - (grid_height * history.Games[0].MemoryScore / 100));
 
 				pos = 1;
 				for (int i = 1; i < history.Games.Count; i++)
@@ -166,7 +182,7 @@ namespace gbrainy.Core.Views
 						continue;
 
 					px = x + (ratio * pos);
-					py = y + area_h - (area_h * history.Games[i].MemoryScore / 100);
+					py = y + grid_height - (grid_height * history.Games[i].MemoryScore / 100);
 					cr.LineTo (px, py);
 					pos++;
 				}
@@ -175,7 +191,7 @@ namespace gbrainy.Core.Views
 
 			if (ShowVerbal) {
 				cr.Color = verbal_color;
-				cr.MoveTo (x, area_h - (area_h * history.Games[0].VerbalScore / 100));
+				cr.MoveTo (x, grid_height - (grid_height * history.Games[0].VerbalScore / 100));
 
 				pos = 1;
 				for (int i = 1; i < history.Games.Count; i++)
@@ -184,7 +200,7 @@ namespace gbrainy.Core.Views
 						continue;
 
 					px = x + (ratio * i);
-					py = y + area_h - (area_h * history.Games[i].VerbalScore / 100);
+					py = y + grid_height - (grid_height * history.Games[i].VerbalScore / 100);
 					cr.LineTo (px, py);
 					pos++;
 				}
@@ -193,7 +209,7 @@ namespace gbrainy.Core.Views
 
 			if (ShowTotal) {
 				cr.Color = total_color;
-				cr.MoveTo (x, area_h - (area_h * history.Games[0].TotalScore / 100));
+				cr.MoveTo (x, grid_height - (grid_height * history.Games[0].TotalScore / 100));
 
 				pos = 1;
 				for (int i = 1; i < history.Games.Count; i++)
@@ -202,7 +218,7 @@ namespace gbrainy.Core.Views
 						continue;
 
 					px = x + (ratio * pos);
-					py = y + area_h - (area_h * history.Games[i].TotalScore / 100);
+					py = y + grid_height - (grid_height * history.Games[i].TotalScore / 100);
 					cr.LineTo (px, py);
 					pos++;
 				}
@@ -214,49 +230,49 @@ namespace gbrainy.Core.Views
 		{
 			// Draw Axis
 			cr.MoveTo (x, y);
-			cr.LineTo (x, y + area_h);
-			cr.LineTo (x + area_w, y + area_h);
+			cr.LineTo (x, y + grid_height);
+			cr.LineTo (x + grid_width, y + grid_height);
 			cr.Stroke ();
 
 			cr.Save ();
-			cr.Color = new Cairo.Color (0.8, 0.8, 0.8);
+			cr.Color = axis_color;
 			cr.LineWidth = 0.001;
 
-			for (double line_y = y; line_y < area_h + y; line_y += area_h / 10) {
+			for (double line_y = y; line_y < grid_height + y; line_y += grid_height / 10) {
 				cr.MoveTo (x, line_y);
-				cr.LineTo (x + area_w, line_y);
+				cr.LineTo (x + grid_width, line_y);
 				cr.Stroke ();
 			}
 
 			cr.Restore ();
 
+			// Draw score scale
 			int pos = 100;
-			for (double line_y = y; line_y < area_h + y; line_y += area_h / 10) {
-				cr.DrawTextAlignedRight (x - 0.02, line_y - 0.02, String.Format ("{0}", pos));
+			for (double line_y = y; line_y < grid_height + y; line_y += grid_height / 10) {
+				cr.DrawTextAlignedRight (x- 0.01, line_y, String.Format ("{0}", pos));
 				pos -= 10;
 			}
-		}		
+		}
 
 		public void Draw (CairoContextEx cr, int width, int height, bool rtl)
 		{
-			double x, y;
+			double x = 0, y = 0;
 
 			// 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);
+			DrawLines (cr, grid_x, grid_y);
 			cr.ResetClip ();
-			DrawLegend (cr, x, y + area_h + 0.05);
-			DrawGrid (cr, x, y);
+			DrawLegend (cr, x + grid_offsetx, y + area_h + 0.06);
+			DrawGrid (cr, grid_x, grid_y);
+
+			DrawAxisDescription (cr, x + area_w + 0.01, 0.78, Catalog.GetString ("Time"));
+			DrawAxisDescription (cr, 0, 0.03, Catalog.GetString ("Score"));
 		}
 	}
 }



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