[longomatch] Use byte for colors



commit db09a81b863acb46c58a48ad30373bde44c1d997
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Wed May 28 16:36:59 2014 +0200

    Use byte for colors

 LongoMatch.Core/Common/Color.cs                    |   41 ++++++++++----------
 .../Store/Templates/CategoriesTemplate.cs          |    2 +-
 LongoMatch.Drawing/CanvasObject/PlayObject.cs      |    2 +-
 LongoMatch.GUI.Helpers/Misc.cs                     |    9 +---
 4 files changed, 24 insertions(+), 30 deletions(-)
---
diff --git a/LongoMatch.Core/Common/Color.cs b/LongoMatch.Core/Common/Color.cs
index a2e99e2..d616103 100644
--- a/LongoMatch.Core/Common/Color.cs
+++ b/LongoMatch.Core/Common/Color.cs
@@ -21,7 +21,7 @@ namespace LongoMatch.Common
 {
        public class Color
        {
-               public Color (ushort r, ushort g, ushort b, ushort a=ushort.MaxValue)
+               public Color (byte r, byte g, byte b, byte a=byte.MaxValue)
                {
                        R = r;
                        G = g;
@@ -29,22 +29,22 @@ namespace LongoMatch.Common
                        A = a;
                }
                
-               public ushort R {
+               public byte R {
                        get;
                        set;
                }
                
-               public ushort G {
+               public byte G {
                        get;
                        set;
                }
                
-               public ushort B {
+               public byte B {
                        get;
                        set;
                }
                
-               public ushort A {
+               public byte A {
                        get;
                        set;
                }
@@ -63,26 +63,25 @@ namespace LongoMatch.Common
                        return (Int32)R<<24 | (Int32)G<<16 | (Int32)B<<8 | (Int32)A;
                }
                
-               static public ushort ByteToUShort (Byte val) {
-                       var ret = (ushort) (((float)val) / byte.MaxValue * ushort.MaxValue);
-                       return ret;
-               }
-
-               static Color ColorFromRGB (byte r, byte g, byte b) {
-                       return new Color (ByteToUShort (r), ByteToUShort (g), ByteToUShort (b));
+               static public byte UShortToByte (ushort val) {
+                       return (byte) (((float)val) / ushort.MaxValue * byte.MaxValue);
                }
                
+               static public Color ColorFromUShort (ushort r, ushort g, ushort b, ushort a = 
ushort.MaxValue) {
+                       return new Color (UShortToByte (r), UShortToByte (g),
+                                         UShortToByte (b), UShortToByte (a));
+               }
                
                static public Color Black = new Color (0, 0, 0);
-               static public Color White = new Color (ushort.MaxValue, ushort.MaxValue, ushort.MaxValue);
-               static public Color Red = new Color (ushort.MaxValue, 0, 0);
-               static public Color Green = new Color (0, ushort.MaxValue, 0);
-               static public Color Blue = new Color (0, 0, ushort.MaxValue);
-               static public Color Grey1 = ColorFromRGB (190, 190, 190);
-               static public Color Grey2 = ColorFromRGB (32, 32, 32);
-               static public Color Green1 = ColorFromRGB (99,192,56);
-               static public Color Red1 = ColorFromRGB (255, 51, 0);
-               static public Color Blue1 = ColorFromRGB (0, 153, 255);
+               static public Color White = new Color (255, 255, 255);
+               static public Color Red = new Color (255, 0, 0);
+               static public Color Green = new Color (0, 255, 0);
+               static public Color Blue = new Color (0, 0, 255);
+               static public Color Grey1 = new Color (190, 190, 190);
+               static public Color Grey2 = new Color (32, 32, 32);
+               static public Color Green1 = new Color (99,192,56);
+               static public Color Red1 = new Color (255, 51, 0);
+               static public Color Blue1 = new Color (0, 153, 255);
        }
 }
 
diff --git a/LongoMatch.Core/Store/Templates/CategoriesTemplate.cs 
b/LongoMatch.Core/Store/Templates/CategoriesTemplate.cs
index 1f078cd..0148908 100644
--- a/LongoMatch.Core/Store/Templates/CategoriesTemplate.cs
+++ b/LongoMatch.Core/Store/Templates/CategoriesTemplate.cs
@@ -177,7 +177,7 @@ namespace LongoMatch.Store.Templates
                }       
                
                public Category AddDefaultItem (int index) {
-                       Color c = new Color (255, 0, 0);
+                       Color c = Color.Red;
                        HotKey h = new HotKey();
                        
                        
diff --git a/LongoMatch.Drawing/CanvasObject/PlayObject.cs b/LongoMatch.Drawing/CanvasObject/PlayObject.cs
index 549b74a..0ff7d00 100644
--- a/LongoMatch.Drawing/CanvasObject/PlayObject.cs
+++ b/LongoMatch.Drawing/CanvasObject/PlayObject.cs
@@ -75,7 +75,7 @@ namespace LongoMatch.Drawing.CanvasObject
                public override void Draw (IDrawingToolkit tk, Area area) {
                        Color c = Play.Category.Color;
                        tk.Begin ();
-                       tk.FillColor = new Color (c.R, c.G, c.B, (ushort) (0.8 * ushort.MaxValue));
+                       tk.FillColor = new Color (c.R, c.G, c.B, (byte) (0.8 * byte.MaxValue));
                        if (Selected) {
                                tk.StrokeColor = Common.PLAY_OBJECT_SELECTED_COLOR;
                        } else {
diff --git a/LongoMatch.GUI.Helpers/Misc.cs b/LongoMatch.GUI.Helpers/Misc.cs
index f34c240..e0fb908 100644
--- a/LongoMatch.GUI.Helpers/Misc.cs
+++ b/LongoMatch.GUI.Helpers/Misc.cs
@@ -86,10 +86,6 @@ namespace LongoMatch.Gui.Helpers
                        }
                }
                
-               static public byte ShortToByte (ushort val) {
-                       return (byte) (((float)val) / ushort.MaxValue * byte.MaxValue);
-               }
-               
                static public double ShortToDouble (ushort val) {
                        return (double) (val) / ushort.MaxValue;
                }
@@ -99,12 +95,11 @@ namespace LongoMatch.Gui.Helpers
                }
 
                public static Color ToGdkColor(LColor color) {
-                       return new Color (ShortToByte (color.R), ShortToByte (color.G),
-                                         ShortToByte (color.G));
+                       return new Color (color.R, color.G, color.G);
                }
                
                public static LColor ToLgmColor(Color color) {
-                       return new LColor (color.Red, color.Green, color.Blue);
+                       return LColor.ColorFromUShort (color.Red, color.Green, color.Red);
                }
                
                public static ListStore FillImageFormat (ComboBox formatBox, VideoStandard def) {


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