From aceff7ba6ca23d202a2a559999036c7ba972e3e7 Mon Sep 17 00:00:00 2001 From: gered Date: Fri, 29 Mar 2013 19:00:48 -0400 Subject: [PATCH] add very basic copies of System.Drawing classes to Gwen namespace minimal implementation only, just enough to satisfy Gwen's usage of the original System.Drawing classes --- Gwen/Color.cs | 65 +++++++++++++++++++++++++++++++++++++++++++++++ Gwen/Point.cs | 20 +++++++++++++++ Gwen/Rectangle.cs | 56 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 141 insertions(+) create mode 100644 Gwen/Color.cs create mode 100644 Gwen/Point.cs create mode 100644 Gwen/Rectangle.cs diff --git a/Gwen/Color.cs b/Gwen/Color.cs new file mode 100644 index 0000000..615aa8a --- /dev/null +++ b/Gwen/Color.cs @@ -0,0 +1,65 @@ +using System; + +namespace Gwen +{ + [Serializable] + public struct Color + { + public byte A; + public byte R; + public byte G; + public byte B; + + public static readonly Color White = FromArgb(255, 255, 255); + public static readonly Color Black = FromArgb(0, 0, 0); + public static readonly Color Red = FromArgb(255, 0, 0); + public static readonly Color Green = FromArgb(0, 255, 0); + public static readonly Color Blue = FromArgb(0, 0, 255); + public static readonly Color Yellow = FromArgb(255, 255, 0); + + public static Color FromArgb(int red, int green, int blue) + { + return FromArgb(255, red, green, blue); + } + + public static Color FromArgb(int alpha, int red, int green, int blue) + { + Color result; + result.A = (byte)alpha; + result.R = (byte)red; + result.G = (byte)green; + result.B = (byte)blue; + return result; + } + + public float GetHue() + { + int r = R; + int g = G; + int b = B; + byte minval = (byte) Math.Min (r, Math.Min (g, b)); + byte maxval = (byte) Math.Max (r, Math.Max (g, b)); + + if (maxval == minval) + return 0.0f; + + float diff = (float)(maxval - minval); + float rnorm = (maxval - r) / diff; + float gnorm = (maxval - g) / diff; + float bnorm = (maxval - b) / diff; + + float hue = 0.0f; + if (r == maxval) + hue = 60.0f * (6.0f + bnorm - gnorm); + if (g == maxval) + hue = 60.0f * (2.0f + rnorm - bnorm); + if (b == maxval) + hue = 60.0f * (4.0f + gnorm - rnorm); + if (hue > 360.0f) + hue = hue - 360.0f; + + return hue; + } + } +} + diff --git a/Gwen/Point.cs b/Gwen/Point.cs new file mode 100644 index 0000000..ead9241 --- /dev/null +++ b/Gwen/Point.cs @@ -0,0 +1,20 @@ +using System; + +namespace Gwen +{ + [Serializable] + public struct Point + { + public int X; + public int Y; + + public static readonly Point Empty; + + public Point(int x, int y) + { + X = x; + Y = y; + } + } +} + diff --git a/Gwen/Rectangle.cs b/Gwen/Rectangle.cs new file mode 100644 index 0000000..6936ff6 --- /dev/null +++ b/Gwen/Rectangle.cs @@ -0,0 +1,56 @@ +using System; + +namespace Gwen +{ + [Serializable] + public struct Rectangle + { + public int X; + public int Y; + public int Width; + public int Height; + + public static readonly Rectangle Empty; + + public Rectangle(int x, int y, int width, int height) + { + X = x; + Y = y; + Width = width; + Height = height; + } + + public int Left + { + get + { + return X; + } + } + + public int Top + { + get + { + return Y; + } + } + + public int Right + { + get + { + return X + Width; + } + } + + public int Bottom + { + get + { + return Y + Height; + } + } + } +} +