[longomatch] Use the new Color class to represent colors
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch] Use the new Color class to represent colors
- Date: Mon, 7 Jul 2014 11:21:20 +0000 (UTC)
commit 908e14fdff2583e2bc6a407cee5d3e678fb420b3
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date: Wed May 14 19:18:40 2014 +0200
Use the new Color class to represent colors
LongoMatch.Core/Handlers/Handlers.cs | 2 +-
LongoMatch.Core/Store/Category.cs | 16 +++++-------
.../Store/Templates/CategoriesTemplate.cs | 4 +--
LongoMatch.GUI.Helpers/Misc.cs | 26 ++++++++++++++-----
LongoMatch.GUI/Gui/Cairo.cs | 13 +++++----
LongoMatch.GUI/Gui/Component/CategoryProperties.cs | 2 +-
LongoMatch.GUI/Gui/Component/DrawingToolBox.cs | 2 +-
LongoMatch.GUI/Gui/Dialog/DrawingTool.cs | 4 +-
Tests/Core/TestCategory.cs | 10 +++----
9 files changed, 43 insertions(+), 36 deletions(-)
---
diff --git a/LongoMatch.Core/Handlers/Handlers.cs b/LongoMatch.Core/Handlers/Handlers.cs
index 00cc880..27bb775 100644
--- a/LongoMatch.Core/Handlers/Handlers.cs
+++ b/LongoMatch.Core/Handlers/Handlers.cs
@@ -91,7 +91,7 @@ namespace LongoMatch.Handlers
/* Draw tool changed */
public delegate void DrawToolChangedHandler(DrawTool drawTool);
/* Paint color changed */
- public delegate void ColorChangedHandler(System.Drawing.Color color);
+ public delegate void ColorChangedHandler(Color color);
/* Paint line width changed */
public delegate void LineWidthChangedHandler(int width);
/* Toggle widget visibility */
diff --git a/LongoMatch.Core/Store/Category.cs b/LongoMatch.Core/Store/Category.cs
index 138b3c6..a2564bb 100644
--- a/LongoMatch.Core/Store/Category.cs
+++ b/LongoMatch.Core/Store/Category.cs
@@ -19,7 +19,6 @@
//
using System;
-using System.Drawing;
using System.Collections.Generic;
using System.Runtime.Serialization;
using Mono.Unix;
@@ -75,7 +74,7 @@ namespace LongoMatch.Store
/// <summary>
/// A color to identify plays in this category
/// </summary>
- public System.Drawing.Color Color {
+ public Color Color {
get;
set;
}
@@ -167,10 +166,9 @@ namespace LongoMatch.Store
SubCategories = (List<ISubCategory>)info.GetValue("subcategories",
typeof(List<ISubCategory>));
Position = (Int32) info.GetValue("position", typeof (Int32));
SortMethod = (SortMethodType)info.GetValue("sort_method", typeof(SortMethodType));
- Color = Color.FromArgb(
- ColorHelper.ShortToByte((ushort)info.GetValue("red", typeof(ushort))),
- ColorHelper.ShortToByte((ushort)info.GetValue("green", typeof(ushort))),
- ColorHelper.ShortToByte((ushort)info.GetValue("blue", typeof(ushort))));
+ Color = new Color ((ushort)info.GetValue("red", typeof(ushort)),
+ (ushort)info.GetValue("green", typeof(ushort)),
+ (ushort)info.GetValue("blue", typeof(ushort)));
try {
TagFieldPosition = (bool) info.GetValue("tagfieldpos", typeof (bool));
} catch {
@@ -208,9 +206,9 @@ namespace LongoMatch.Store
info.AddValue("position", Position);
info.AddValue("subcategories", SubCategories);
/* Convert to ushort for backward compatibility */
- info.AddValue("red", ColorHelper.ByteToShort(Color.R));
- info.AddValue("green", ColorHelper.ByteToShort(Color.G));
- info.AddValue("blue", ColorHelper.ByteToShort(Color.B));
+ info.AddValue("red", Color.R);
+ info.AddValue("green", Color.G);
+ info.AddValue("blue", Color.B);
info.AddValue("sort_method", SortMethod);
info.AddValue("tagfieldpos", TagFieldPosition);
info.AddValue("taghalffieldpos", TagHalfFieldPosition);
diff --git a/LongoMatch.Core/Store/Templates/CategoriesTemplate.cs
b/LongoMatch.Core/Store/Templates/CategoriesTemplate.cs
index dd2e545..1f078cd 100644
--- a/LongoMatch.Core/Store/Templates/CategoriesTemplate.cs
+++ b/LongoMatch.Core/Store/Templates/CategoriesTemplate.cs
@@ -19,7 +19,6 @@
//
using System;
using System.Collections.Generic;
-using System.Drawing;
using System.Linq;
using Newtonsoft.Json;
@@ -28,7 +27,6 @@ using LongoMatch.Common;
using LongoMatch.Interfaces;
using Image = LongoMatch.Common.Image;
-using Color = System.Drawing.Color;
namespace LongoMatch.Store.Templates
{
@@ -179,7 +177,7 @@ namespace LongoMatch.Store.Templates
}
public Category AddDefaultItem (int index) {
- Color c = Color.FromArgb(255, 0, 0);
+ Color c = new Color (255, 0, 0);
HotKey h = new HotKey();
diff --git a/LongoMatch.GUI.Helpers/Misc.cs b/LongoMatch.GUI.Helpers/Misc.cs
index bd96e0a..f34c240 100644
--- a/LongoMatch.GUI.Helpers/Misc.cs
+++ b/LongoMatch.GUI.Helpers/Misc.cs
@@ -22,6 +22,8 @@ using Gdk;
using Mono.Unix;
using LongoMatch.Common;
+using LColor = LongoMatch.Common.Color;
+using Color = Gdk.Color;
namespace LongoMatch.Gui.Helpers
{
@@ -84,15 +86,25 @@ namespace LongoMatch.Gui.Helpers
}
}
- public static Gdk.Color ToGdkColor(System.Drawing.Color color) {
- return new Gdk.Color(color.R, color.G, color.B);
+ static public byte ShortToByte (ushort val) {
+ return (byte) (((float)val) / ushort.MaxValue * byte.MaxValue);
}
- public static System.Drawing.Color ToDrawingColor(Gdk.Color color) {
- return System.Drawing.Color.FromArgb(
- ColorHelper.ShortToByte(color.Red),
- ColorHelper.ShortToByte(color.Green),
- ColorHelper.ShortToByte(color.Blue));
+ static public double ShortToDouble (ushort val) {
+ return (double) (val) / ushort.MaxValue;
+ }
+
+ static public double ByteToDouble (byte val) {
+ return (double) (val) / byte.MaxValue;
+ }
+
+ public static Color ToGdkColor(LColor color) {
+ return new Color (ShortToByte (color.R), ShortToByte (color.G),
+ ShortToByte (color.G));
+ }
+
+ public static LColor ToLgmColor(Color color) {
+ return new LColor (color.Red, color.Green, color.Blue);
}
public static ListStore FillImageFormat (ComboBox formatBox, VideoStandard def) {
diff --git a/LongoMatch.GUI/Gui/Cairo.cs b/LongoMatch.GUI/Gui/Cairo.cs
index a1b6016..7766e97 100644
--- a/LongoMatch.GUI/Gui/Cairo.cs
+++ b/LongoMatch.GUI/Gui/Cairo.cs
@@ -17,6 +17,7 @@
//
using System;
using Cairo;
+using LongoMatch.Gui.Helpers;
namespace LongoMatch.Common
@@ -73,15 +74,15 @@ namespace LongoMatch.Common
}
public static Cairo.Color RGBToCairoColor(Gdk.Color gdkColor) {
- return new Cairo.Color (ColorHelper.ShortToDouble (gdkColor.Red),
- ColorHelper.ShortToDouble (gdkColor.Green),
- ColorHelper.ShortToDouble (gdkColor.Blue));
+ return new Cairo.Color (Misc.ShortToDouble (gdkColor.Red),
+ Misc.ShortToDouble (gdkColor.Green),
+ Misc.ShortToDouble (gdkColor.Blue));
}
public static Cairo.Color ColorFromRGB (byte r, byte g, byte b) {
- return new Cairo.Color (ColorHelper.ByteToDouble (r),
- ColorHelper.ByteToDouble (g),
- ColorHelper.ByteToDouble (b));
+ return new Cairo.Color (Misc.ByteToDouble (r),
+ Misc.ByteToDouble (g),
+ Misc.ByteToDouble (b));
}
}
}
diff --git a/LongoMatch.GUI/Gui/Component/CategoryProperties.cs
b/LongoMatch.GUI/Gui/Component/CategoryProperties.cs
index b23f86d..01fe86c 100644
--- a/LongoMatch.GUI/Gui/Component/CategoryProperties.cs
+++ b/LongoMatch.GUI/Gui/Component/CategoryProperties.cs
@@ -221,7 +221,7 @@ namespace LongoMatch.Gui.Component
protected virtual void OnColorbutton1ColorSet(object sender, System.EventArgs e)
{
if(cat != null)
- cat.Color= Helpers.Misc.ToDrawingColor(colorbutton1.Color);
+ cat.Color= Helpers.Misc.ToLgmColor(colorbutton1.Color);
}
protected virtual void OnLeadTimeChanged(object sender, System.EventArgs e)
diff --git a/LongoMatch.GUI/Gui/Component/DrawingToolBox.cs b/LongoMatch.GUI/Gui/Component/DrawingToolBox.cs
index 4d6a590..5eeca65 100644
--- a/LongoMatch.GUI/Gui/Component/DrawingToolBox.cs
+++ b/LongoMatch.GUI/Gui/Component/DrawingToolBox.cs
@@ -124,7 +124,7 @@ namespace LongoMatch.Gui.Component
protected virtual void OnColorbuttonColorSet(object sender, System.EventArgs e)
{
if(ColorChanged != null)
- ColorChanged(Helpers.Misc.ToDrawingColor(colorbutton.Color));
+ ColorChanged(Helpers.Misc.ToLgmColor(colorbutton.Color));
}
}
}
diff --git a/LongoMatch.GUI/Gui/Dialog/DrawingTool.cs b/LongoMatch.GUI/Gui/Dialog/DrawingTool.cs
index f59428a..c70aef7 100644
--- a/LongoMatch.GUI/Gui/Dialog/DrawingTool.cs
+++ b/LongoMatch.GUI/Gui/Dialog/DrawingTool.cs
@@ -70,7 +70,7 @@ namespace LongoMatch.Gui.Dialog
drawingwidget1.LineWidth = width;
}
- protected virtual void OnDrawingtoolbox1ColorChanged(System.Drawing.Color color)
+ protected virtual void OnDrawingtoolbox1ColorChanged (LongoMatch.Common.Color color)
{
drawingwidget1.LineColor = Helpers.Misc.ToGdkColor(color);
}
@@ -113,7 +113,7 @@ namespace LongoMatch.Gui.Dialog
string tempFile = System.IO.Path.GetTempFileName();
drawingwidget1.SaveDrawings(tempFile);
Pixbuf frame = new Pixbuf(tempFile);
- play.KeyFrameDrawing = new Drawing { Pixbuf= new Image(frame), Render = stopTime};
+ play.KeyFrameDrawing = new LongoMatch.Store.Drawing { Pixbuf= new Image(frame),
Render = stopTime};
drawingwidget1.SaveAll(tempFile);
frame.Dispose();
play.Miniature = new Image(new Pixbuf(tempFile));
diff --git a/Tests/Core/TestCategory.cs b/Tests/Core/TestCategory.cs
index 5a5514d..3e4dda1 100644
--- a/Tests/Core/TestCategory.cs
+++ b/Tests/Core/TestCategory.cs
@@ -16,14 +16,12 @@
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
//
using System;
-using System.Drawing;
using NUnit.Framework;
using Newtonsoft.Json;
using LongoMatch.Common;
using LongoMatch.Store;
using System.IO;
-using Color = System.Drawing.Color;
namespace Tests.Core
{
@@ -39,7 +37,7 @@ namespace Tests.Core
StreamReader reader;
cat = new Category();
- cat.Color = Color.AliceBlue;
+ cat.Color = new Color (255, 0, 0);
cat.HotKey = new HotKey {Key=2, Modifier=4};
cat.Name = "test";
cat.Position = 2;
@@ -78,9 +76,9 @@ namespace Tests.Core
Assert.AreEqual (cat.FieldPositionIsDistance, newcat.FieldPositionIsDistance);
Assert.AreEqual (cat.HalfFieldPositionIsDistance, newcat.HalfFieldPositionIsDistance);
Assert.AreEqual (cat.HotKey, newcat.HotKey);
- Assert.AreEqual (newcat.Color.R, Color.AliceBlue.R);
- Assert.AreEqual (newcat.Color.G, Color.AliceBlue.G);
- Assert.AreEqual (newcat.Color.B, Color.AliceBlue.B);
+ Assert.AreEqual (255, newcat.Color.R);
+ Assert.AreEqual (0, newcat.Color.G);
+ Assert.AreEqual (0, newcat.Color.B);
Assert.AreEqual (newcat.SubCategories.Count, 1);
Assert.AreEqual (newcat.SubCategories[0].Name, "TestSubcat");
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]