[longomatch/gameunits] Make widget for categories more generic



commit ad04ca7bd64eb1d65b91216b92eef0f37c3902e1
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Thu Nov 24 23:27:22 2011 +0100

    Make widget for categories more generic

 LongoMatch.GUI/Gui/Base/TimelineWidgetBase.cs      |    4 +-
 LongoMatch.GUI/Gui/Component/TimeLineWidget.cs     |    3 +-
 ...{CategoriesScale.cs => TimelineLabelsWidget.cs} |   33 ++++++++++++++------
 LongoMatch.GUI/LongoMatch.GUI.mdp                  |    2 +-
 4 files changed, 28 insertions(+), 14 deletions(-)
---
diff --git a/LongoMatch.GUI/Gui/Base/TimelineWidgetBase.cs b/LongoMatch.GUI/Gui/Base/TimelineWidgetBase.cs
index 0c5a20b..569d0aa 100644
--- a/LongoMatch.GUI/Gui/Base/TimelineWidgetBase.cs
+++ b/LongoMatch.GUI/Gui/Base/TimelineWidgetBase.cs
@@ -29,7 +29,7 @@ namespace LongoMatch.Gui.Base
 	public partial class TimelineWidgetBase : Gtk.Bin
 	{
 		protected TimeReferenceWidget tr;
-		protected CategoriesScale cs;
+		protected TimelineLabelsWidget cs;
 		protected uint currentFrame, pixelRatio, frames;
 		protected bool loaded;
 		
@@ -38,7 +38,7 @@ namespace LongoMatch.Gui.Base
 			this.Build ();
 			
 			tr = new TimeReferenceWidget();
-			cs = new CategoriesScale();
+			cs = new TimelineLabelsWidget();
 			
 			cs.WidthRequest = 100;
 			toolsbox.HeightRequest = 50 - leftbox.Spacing;
diff --git a/LongoMatch.GUI/Gui/Component/TimeLineWidget.cs b/LongoMatch.GUI/Gui/Component/TimeLineWidget.cs
index aec0c2a..cdfd28b 100644
--- a/LongoMatch.GUI/Gui/Component/TimeLineWidget.cs
+++ b/LongoMatch.GUI/Gui/Component/TimeLineWidget.cs
@@ -19,6 +19,7 @@
 //
 using System;
 using System.Collections.Generic;
+using System.Linq;
 using Gtk;
 
 using LongoMatch.Gui.Base;
@@ -60,7 +61,7 @@ namespace LongoMatch.Gui.Component {
 				tsList.Clear(); 
 				frames = value.Description.File.GetFrames();
 
-				cs.Categories = categories;
+				cs.Labels = categories.Select(c => c.Name).ToList();
 				cs.Show();
 
 				tr.Frames = frames;
diff --git a/LongoMatch.GUI/Gui/Component/CategoriesScale.cs b/LongoMatch.GUI/Gui/Component/TimelineLabelsWidget.cs
similarity index 78%
rename from LongoMatch.GUI/Gui/Component/CategoriesScale.cs
rename to LongoMatch.GUI/Gui/Component/TimelineLabelsWidget.cs
index e406a7d..43ed277 100644
--- a/LongoMatch.GUI/Gui/Component/CategoriesScale.cs
+++ b/LongoMatch.GUI/Gui/Component/TimelineLabelsWidget.cs
@@ -16,6 +16,7 @@
 //  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 //
 using System;
+using System.Collections.Generic;
 using Cairo;
 using Gtk;
 using Gdk;
@@ -26,26 +27,39 @@ using LongoMatch.Store.Templates;
 
 namespace LongoMatch.Gui.Component
 {
-	public class CategoriesScale: Gtk.DrawingArea
+	public class TimelineLabelsWidget: Gtk.DrawingArea
 	{
 		private const int SECTION_HEIGHT = 30;
 		private const int SECTION_WIDTH = 100;
 		private const int LINE_WIDTH = 2;
 		private double scroll;
 		Pango.Layout layout;
+		Dictionary<string, Gdk.Color> labelsDict;
 
 		[System.ComponentModel.Category("LongoMatch")]
 		[System.ComponentModel.ToolboxItem(true)]
-		public CategoriesScale()
+		public TimelineLabelsWidget()
 		{
 			layout =  new Pango.Layout(PangoContext);
 			layout.Wrap = Pango.WrapMode.Char;
 			layout.Alignment = Pango.Alignment.Left;
+			labelsDict = new Dictionary<string, Gdk.Color> ();
 		}
 
+		public List<string> Labels {
+			set {
+				labelsDict.Clear();
+				foreach (String label in value)
+					labelsDict.Add(label, Gdk.Color.Zero);
+			}
+		}
+		
 		public Categories Categories {
-			get;
-			set;
+			set {
+				labelsDict.Clear();
+				foreach (Category cat in value)
+					labelsDict.Add(cat.Name, cat.Color);
+			}
 		}
 
 		public double Scroll {
@@ -69,17 +83,17 @@ namespace LongoMatch.Gui.Component
 		private void DrawCategories(Gdk.Window win) {
 			int i = 0;
 
-			if(Categories == null)
+			if(labelsDict.Count == 0)
 				return;
 
 			using(Cairo.Context g = Gdk.CairoHelper.Create(win)) {
-				foreach(Category cat in Categories) {
+				foreach(String label in labelsDict.Keys) {
 					int y = LINE_WIDTH/2 + i * SECTION_HEIGHT - (int)Scroll;
 					CairoUtils.DrawRoundedRectangle(g, 2, y + 3 , Allocation.Width - 3,
 					                                SECTION_HEIGHT - 3, SECTION_HEIGHT/7,
-					                                CairoUtils.RGBToCairoColor(cat.Color),
-					                                CairoUtils.RGBToCairoColor(cat.Color));
-					DrawCairoText(cat.Name, 0 + 3, y + SECTION_HEIGHT / 2 - 5);
+					                                CairoUtils.RGBToCairoColor(labelsDict[label]),
+					                                CairoUtils.RGBToCairoColor(labelsDict[label]));
+					DrawCairoText(label, 0 + 3, y + SECTION_HEIGHT / 2 - 5);
 					i++;
 				}
 			}
@@ -92,4 +106,3 @@ namespace LongoMatch.Gui.Component
 		}
 	}
 }
-
diff --git a/LongoMatch.GUI/LongoMatch.GUI.mdp b/LongoMatch.GUI/LongoMatch.GUI.mdp
index 31ad85c..743a897 100644
--- a/LongoMatch.GUI/LongoMatch.GUI.mdp
+++ b/LongoMatch.GUI/LongoMatch.GUI.mdp
@@ -103,7 +103,7 @@
     <File subtype="Code" buildaction="Compile" name="gtk-gui/LongoMatch.Gui.Dialog.EndCaptureDialog.cs" />
     <File subtype="Code" buildaction="Compile" name="gtk-gui/LongoMatch.Gui.Dialog.BusyDialog.cs" />
     <File subtype="Code" buildaction="Compile" name="Gui/TreeView/ListTreeViewBase.cs" />
-    <File subtype="Code" buildaction="Compile" name="Gui/Component/CategoriesScale.cs" />
+    <File subtype="Code" buildaction="Compile" name="Gui/Component/TimelineLabelsWidget.cs" />
     <File subtype="Code" buildaction="Compile" name="gtk-gui/LongoMatch.Gui.Dialog.TemplateEditorDialog.cs" />
     <File subtype="Code" buildaction="Compile" name="Gui/TreeView/SubCategoriesTreeView.cs" />
     <File subtype="Code" buildaction="Compile" name="Gui/Dialog/SubCategoryTagsEditor.cs" />



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