From 600aabd976a77e4367b03a382ff704a525df64eb Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Tue, 17 Sep 2019 01:38:38 -0400 Subject: [PATCH] Initial commit --- MBS.Framework.CLI/Application.cs | 58 +++ MBS.Framework.CLI/CommandLineSwitch.cs | 81 +++ MBS.Framework.CLI/MBS.Framework.CLI.csproj | 45 ++ MBS.Framework.CLI/Properties/AssemblyInfo.cs | 26 + MBS.Framework.sln | 25 + .../Collections/Generic/AutoDictionary.cs | 49 ++ .../Generic/BidirectionalDictionary.cs | 123 +++++ MBS.Framework/Drawing/Color.cs | 481 ++++++++++++++++++ MBS.Framework/Drawing/Colors.cs | 307 +++++++++++ MBS.Framework/Drawing/Dimension.cs | 6 + MBS.Framework/Drawing/Dimension2D.cs | 35 ++ MBS.Framework/Drawing/Dimension3D.cs | 25 + MBS.Framework/Drawing/Padding.cs | 50 ++ MBS.Framework/Drawing/Rectangle.cs | 133 +++++ MBS.Framework/Drawing/Vector.cs | 27 + MBS.Framework/MBS.Framework.csproj | 47 ++ MBS.Framework/Properties/AssemblyInfo.cs | 46 ++ 17 files changed, 1564 insertions(+) create mode 100644 MBS.Framework.CLI/Application.cs create mode 100644 MBS.Framework.CLI/CommandLineSwitch.cs create mode 100644 MBS.Framework.CLI/MBS.Framework.CLI.csproj create mode 100644 MBS.Framework.CLI/Properties/AssemblyInfo.cs create mode 100644 MBS.Framework.sln create mode 100644 MBS.Framework/Collections/Generic/AutoDictionary.cs create mode 100644 MBS.Framework/Collections/Generic/BidirectionalDictionary.cs create mode 100644 MBS.Framework/Drawing/Color.cs create mode 100644 MBS.Framework/Drawing/Colors.cs create mode 100644 MBS.Framework/Drawing/Dimension.cs create mode 100644 MBS.Framework/Drawing/Dimension2D.cs create mode 100644 MBS.Framework/Drawing/Dimension3D.cs create mode 100644 MBS.Framework/Drawing/Padding.cs create mode 100644 MBS.Framework/Drawing/Rectangle.cs create mode 100644 MBS.Framework/Drawing/Vector.cs create mode 100644 MBS.Framework/MBS.Framework.csproj create mode 100644 MBS.Framework/Properties/AssemblyInfo.cs diff --git a/MBS.Framework.CLI/Application.cs b/MBS.Framework.CLI/Application.cs new file mode 100644 index 0000000..58ebfdf --- /dev/null +++ b/MBS.Framework.CLI/Application.cs @@ -0,0 +1,58 @@ +using System; +using System.Text; + +namespace MBS.Framework.CLI +{ + public static class Application + { + private static CommandLineSwitch.CommandLineSwitchCollection _switchs = new CommandLineSwitch.CommandLineSwitchCollection(); + public static CommandLineSwitch.CommandLineSwitchCollection Switches + { + get + { + _switchs.Update(); + return _switchs; + } + } + + public static string ExecutableFileName + { + get { return System.Reflection.Assembly.GetEntryAssembly().Location; } + } + public static string ExecutableFileTitle + { + get { return System.IO.Path.GetFileName(ExecutableFileName); } + } + + public static void Start() + { + } + + public static void PrintUsage() + { + StringBuilder sbSwitches = new StringBuilder(); + foreach (CommandLineSwitch sw in Switches) + { + if (sw.IsOptional) + sbSwitches.Append('['); + + sbSwitches.Append(String.Format("/{0}", sw.Name)); + + if (sw.CanHaveValue) + { + sbSwitches.Append(':'); + sbSwitches.Append(sw.ExampleValue == null ? "value": sw.ExampleValue); + } + + if (sw.IsOptional) + sbSwitches.Append(']'); + + if (Switches.IndexOf(sw) < Switches.Count - 1) + { + sbSwitches.Append(' '); + } + } + Console.WriteLine(String.Format("usage: {0} {1}", System.IO.Path.GetFileNameWithoutExtension(ExecutableFileTitle), sbSwitches.ToString())); + } + } +} \ No newline at end of file diff --git a/MBS.Framework.CLI/CommandLineSwitch.cs b/MBS.Framework.CLI/CommandLineSwitch.cs new file mode 100644 index 0000000..461741a --- /dev/null +++ b/MBS.Framework.CLI/CommandLineSwitch.cs @@ -0,0 +1,81 @@ +using System; + +namespace MBS.Framework.CLI +{ + public class CommandLineSwitch + { + public class CommandLineSwitchCollection + : System.Collections.ObjectModel.Collection + { + private bool updated = false; + public void Update() + { + if (updated) return; + + string[] args = Environment.GetCommandLineArgs(); + for (int i = 1; i < args.Length; i++) + { + string arg = args[i]; + + + if (arg.StartsWith("/")) + { + CommandLineSwitch sw = this[arg]; + if (sw == null) + sw = new CommandLineSwitch(); + + if (arg.Contains(":")) + { + string[] values = arg.Split(new char[] { ':' }, 2); + sw.Name = values[0]; + sw.Value = values[1]; + } + else + { + sw.Name = arg; + } + } + } + updated = true; + } + + public CommandLineSwitch this[string name] + { + get + { + foreach (CommandLineSwitch sw in this) + { + if (sw.Name == name) return sw; + } + return null; + } + } + + public CommandLineSwitch Add(string name, string defaultValue = null, bool optional = false, bool canHaveValue = false, string exampleValue = null) + { + CommandLineSwitch sw = new CommandLineSwitch(); + sw.Name = name; + sw.CanHaveValue = canHaveValue; + sw.DefaultValue = defaultValue; + sw.ExampleValue = exampleValue; + sw.IsOptional = optional; + Add(sw); + return sw; + } + } + + public bool IsOptional { get; set; } = false; + public bool CanHaveValue { get; set; } = false; + + public string Name { get; set; } = String.Empty; + public string DefaultValue { get; set; } = null; + public string ExampleValue { get; set; } = null; + + private string mvarValue = null; + public string Value + { + get { return mvarValue == null ? DefaultValue : mvarValue; } + private set { mvarValue = value; } + } + } +} \ No newline at end of file diff --git a/MBS.Framework.CLI/MBS.Framework.CLI.csproj b/MBS.Framework.CLI/MBS.Framework.CLI.csproj new file mode 100644 index 0000000..fd25956 --- /dev/null +++ b/MBS.Framework.CLI/MBS.Framework.CLI.csproj @@ -0,0 +1,45 @@ + + + + Debug + AnyCPU + {DA900843-92F7-49A5-AE16-A27658AA2F3C} + Library + MBS.Framework.Console + MBS.Framework.CLI + + + true + full + false + ..\Output\Debug + DEBUG; + prompt + 4 + ..\Output\Debug\MBS.Framework.CLI.xml + false + + + true + ..\Output\Release + prompt + 4 + ..\Output\Release\MBS.Framework.CLI.xml + false + + + + + + + + + + + + {00266B21-35C9-4A7F-A6BA-D54D7FDCC25C} + MBS.Framework + + + + \ No newline at end of file diff --git a/MBS.Framework.CLI/Properties/AssemblyInfo.cs b/MBS.Framework.CLI/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..1cb8678 --- /dev/null +++ b/MBS.Framework.CLI/Properties/AssemblyInfo.cs @@ -0,0 +1,26 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("MBS.Framework.Console")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("Mike Becker")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] diff --git a/MBS.Framework.sln b/MBS.Framework.sln new file mode 100644 index 0000000..48ba0aa --- /dev/null +++ b/MBS.Framework.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MBS.Framework", "MBS.Framework\MBS.Framework.csproj", "{00266B21-35C9-4A7F-A6BA-D54D7FDCC25C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MBS.Framework.CLI", "MBS.Framework.CLI\MBS.Framework.CLI.csproj", "{DA900843-92F7-49A5-AE16-A27658AA2F3C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x86 = Debug|x86 + Release|x86 = Release|x86 + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {00266B21-35C9-4A7F-A6BA-D54D7FDCC25C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {00266B21-35C9-4A7F-A6BA-D54D7FDCC25C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {00266B21-35C9-4A7F-A6BA-D54D7FDCC25C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {00266B21-35C9-4A7F-A6BA-D54D7FDCC25C}.Release|Any CPU.Build.0 = Release|Any CPU + {DA900843-92F7-49A5-AE16-A27658AA2F3C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DA900843-92F7-49A5-AE16-A27658AA2F3C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DA900843-92F7-49A5-AE16-A27658AA2F3C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DA900843-92F7-49A5-AE16-A27658AA2F3C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/MBS.Framework/Collections/Generic/AutoDictionary.cs b/MBS.Framework/Collections/Generic/AutoDictionary.cs new file mode 100644 index 0000000..8fa4dca --- /dev/null +++ b/MBS.Framework/Collections/Generic/AutoDictionary.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace MBS.Framework.Collections.Generic +{ + /// + /// Provides a that automatically adds or updates a key or value when + /// it is requested. + /// + /// The type of the key part of the dictionary. + /// The type of the value part of the dictionary. + public class AutoDictionary : Dictionary + { + /// + /// Retrieves or updates an item with the specified key. If the item does not exist on update, + /// it will be created. If the item does not exist on retrieval, the value specified for + /// will be returned. + /// + /// The key of the item to retrieve or update. + /// The value returned on retrieval when the item with the specified key does not exist. + /// The item with the specified key if it exists in this collection; otherwise, defaultValue. + public TValue this[TKey key, TValue defaultValue = default(TValue)] + { + get + { + if (ContainsKey(key)) + { + // we already contain an item with this key, so return the value accordingly + return base[key]; + } + else + { + // we do not already contain an item with this key, so create a new value set to the + // specified default value and return that + base.Add(key, defaultValue); + return defaultValue; + } + } + set + { + // the .NET Framework Dictionary`2 implementation handles the "add or update" case + // automatically if a non-existent key is specified + base[key] = value; + } + } + } +} diff --git a/MBS.Framework/Collections/Generic/BidirectionalDictionary.cs b/MBS.Framework/Collections/Generic/BidirectionalDictionary.cs new file mode 100644 index 0000000..6666588 --- /dev/null +++ b/MBS.Framework/Collections/Generic/BidirectionalDictionary.cs @@ -0,0 +1,123 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Text; + +namespace MBS.Framework.Collections.Generic +{ + /// + /// Provides a collection that can be keyed either forward (T1=>T2) or backward (T2=>T1). + /// + /// The type of the value on which to forward-key the collection. + /// The type of the value on which to backward-key the collection. + public class BidirectionalDictionary : System.Collections.IEnumerable + { + private Dictionary mvarForwardDictionary = new Dictionary(); + private Dictionary mvarBackwardDictionary = new Dictionary(); + + /// + /// Adds the specified first and second value to the collection. + /// + /// The first value to add. + /// The second value to add. + public void Add(T1 value1, T2 value2) + { + mvarForwardDictionary.Add(value1, value2); + mvarBackwardDictionary.Add(value2, value1); + } + + /// + /// Removes the first and second value associated with the specified first value. + /// + /// The first value of the first-second value pair to remove. + public void RemoveByValue1(T1 value1) + { + T2 value2 = mvarForwardDictionary[value1]; + mvarForwardDictionary.Remove(value1); + mvarBackwardDictionary.Remove(value2); + } + /// + /// Removes the first and second value associated with the specified second value. + /// + /// The second value of the first-second value pair to remove. + public void RemoveByValue2(T2 value2) + { + T1 value1 = mvarBackwardDictionary[value2]; + mvarForwardDictionary.Remove(value1); + mvarBackwardDictionary.Remove(value2); + } + + /// + /// Gets the first value associated with the specified second value. + /// + /// The second value of the first-second value pair to search for. + /// The first value associated with the specified second value. + public T1 GetValue1(T2 value2) + { + return mvarBackwardDictionary[value2]; + } + /// + /// Gets the second value associated with the specified first value. + /// + /// The first value of the first-second value pair to search for. + /// The second value associated with the specified first value. + public T2 GetValue2(T1 value1) + { + return mvarForwardDictionary[value1]; + } + + /// + /// Determines if the specified first value is contained in this collection. + /// + /// The value to search for. + /// True if the value exists in the first value dictionary; otherwise, false. + public bool ContainsValue1(T1 value) + { + return mvarForwardDictionary.ContainsKey(value); + } + /// + /// Determines if the specified second value is contained in this collection. + /// + /// The value to search for. + /// True if the value exists in the second value dictionary; otherwise, false. + public bool ContainsValue2(T2 value) + { + return mvarBackwardDictionary.ContainsKey(value); + } + + /// + /// Gets a that can be used to iterate over this collection. + /// + /// A that can be used to iterate over this collection. + public IEnumerator> GetEnumerator() + { + return mvarForwardDictionary.GetEnumerator(); + } + /// + /// Gets a that can be used to iterate over this collection. + /// + /// A that can be used to iterate over this collection. + IEnumerator IEnumerable.GetEnumerator() + { + return mvarForwardDictionary.GetEnumerator(); + } + + /// + /// Returns the number of items in this collection. + /// + public int Count + { + get + { + if (mvarForwardDictionary.Count != mvarBackwardDictionary.Count) + { + // this should never happen + throw new InvalidOperationException("Count mismatch"); + } + + // they should be equal, so choose one at random to return and hardcode it ;) + return mvarBackwardDictionary.Count; + } + } + } +} diff --git a/MBS.Framework/Drawing/Color.cs b/MBS.Framework/Drawing/Color.cs new file mode 100644 index 0000000..efaa534 --- /dev/null +++ b/MBS.Framework/Drawing/Color.cs @@ -0,0 +1,481 @@ +// +// Color.cs +// +// Author: +// Michael Becker +// +// Copyright (c) 2019 +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; +using System.Text; + +namespace MBS.Framework.Drawing +{ + public struct Color + { + public static readonly Color Empty; + + private double mvarR; + public double R { get { return mvarR; } set { mvarR = value; } } + + private double mvarG; + public double G { get { return mvarG; } set { mvarG = value; } } + + private double mvarB; + public double B { get { return mvarB; } set { mvarB = value; } } + + private double mvarA; + public double A { get { return mvarA; } set { mvarA = value; } } + + + public static Color FromRGBASingle(float r, float g, float b, float a = 1.0f) + { + return Color.FromRGBADouble(r, g, b, a); + } + public static Color FromRGBADouble(double r, double g, double b, double a = 1.0) + { + Color color = new Color(); + color.R = r; + color.G = g; + color.B = b; + color.A = a; + return color; + } + + public static Color FromRGBAByte(byte r, byte g, byte b, byte a = 255) + { + return FromRGBAInt32((int)r, (int)g, (int)b, (int)a); + } + public static Color FromRGBAInt32(int r, int g, int b, int a = 255) + { + Color color = new Color(); + color.R = ((double)r / 255); + color.G = ((double)g / 255); + color.B = ((double)b / 255); + color.A = ((double)a / 255); + return color; + } + + public static Color FromString(string value) + { + /* + if (value.StartsWith("@")) + { + if (ThemeManager.CurrentTheme != null) return ThemeManager.CurrentTheme.GetColorFromString(value); + } + else */ if (value.StartsWith("#") && value.Length == 7) + { + string RRGGBB = value.Substring(1); + byte RR = Byte.Parse(RRGGBB.Substring(0, 2), System.Globalization.NumberStyles.HexNumber); + byte GG = Byte.Parse(RRGGBB.Substring(2, 2), System.Globalization.NumberStyles.HexNumber); + byte BB = Byte.Parse(RRGGBB.Substring(4, 2), System.Globalization.NumberStyles.HexNumber); + return Color.FromRGBAByte(RR, GG, BB); + } + else if (value.StartsWith("rgb(") && value.EndsWith(")")) + { + string r_g_b = value.Substring(3, value.Length - 4); + string[] rgb = r_g_b.Split(new char[] { ',' }); + if (rgb.Length == 3) + { + byte r = Byte.Parse(rgb[0].Trim()); + byte g = Byte.Parse(rgb[1].Trim()); + byte b = Byte.Parse(rgb[2].Trim()); + return Color.FromRGBAByte(r, g, b); + } + } + else if (value.StartsWith("rgba(") && value.EndsWith(")")) + { + string r_g_b = value.Substring(3, value.Length - 4); + string[] rgb = r_g_b.Split(new char[] { ',' }); + if (rgb.Length == 3) + { + byte r = Byte.Parse(rgb[0].Trim()); + byte g = Byte.Parse(rgb[1].Trim()); + byte b = Byte.Parse(rgb[2].Trim()); + byte a = Byte.Parse(rgb[3].Trim()); + return Color.FromRGBAByte(r, g, b, a); + } + } + else + { + /* + try + { + System.Drawing.Color color = System.Drawing.Color.FromName(value); + return color; + } + catch + { + + } + */ + } + return Color.Empty; + } + + public byte GetRedByte() + { + return (byte)(mvarR * 255); + } + public byte GetGreenByte() + { + return (byte)(mvarG * 255); + } + public byte GetBlueByte() + { + return (byte)(mvarB * 255); + } + public byte GetAlphaByte() + { + return (byte)(mvarA * 255); + } + + public string ToHexadecimalVB() + { + StringBuilder sb = new StringBuilder(); + sb.Append("&H"); + sb.Append(GetRedByte().ToString("X")); + sb.Append(GetGreenByte().ToString("X")); + sb.Append(GetBlueByte().ToString("X")); + sb.Append(GetAlphaByte().ToString("X")); + return sb.ToString(); + } + public string ToHexadecimalHTML() + { + StringBuilder sb = new StringBuilder(); + sb.Append('#'); + sb.Append(GetRedByte().ToString("x").PadLeft(2, '0')); + sb.Append(GetGreenByte().ToString("x").PadLeft(2, '0')); + sb.Append(GetBlueByte().ToString("x").PadLeft(2, '0')); + return sb.ToString().ToUpper(); + } + + public float[] ToFloatRGB() + { + return new float[] { (float)R, (float)G, (float)B }; + } + public float[] ToFloatRGBA() + { + return new float[] { (float)R, (float)G, (float)B, (float)A }; + } + + public int ToInt32() + { + return BitConverter.ToInt32(new byte[] { (byte)mvarA, (byte)mvarB, (byte)mvarG, (byte)mvarR }, 0); + } + + public override string ToString() + { + return ToHexadecimalHTML(); + } + + /*private double mvarRed; + public double Red { get { return mvarRed; } set { mvarRed = value; } } + public int RedInt32 { get { return (int)(mvarRed * 255); } set { mvarRed = (double)value / 255.0; } } + + private double mvarGreen; + public double Green { get { return mvarGreen; } set { mvarGreen = value; } } + public int GreenInt32 { get { return (int)(mvarGreen * 255); } set { mvarGreen = (double)value / 255.0; } } + + private double mvarBlue; + public double Blue { get { return mvarBlue; } set { mvarBlue = value; } } + public int BlueInt32 { get { return (int)(mvarBlue * 255); } set { mvarBlue = (double)value / 255.0; } } + + private double mvarAlpha; + public double Alpha { get { return mvarAlpha; } set { mvarAlpha = value; } } + public int AlphaInt32 { get { return (int)(mvarAlpha * 255); } set { mvarAlpha = (double)value / 255.0; } } + + public double Hue + { + get + { + int r = this.RedInt32; + int g = this.GreenInt32; + int b = this.BlueInt32; + + byte minRGB = (byte)Math.Min (r, Math.Min (g, b)); + byte maxRGB = (byte)Math.Max (r, Math.Max (g, b)); + if (maxRGB == minRGB) return 0.0; + + float num = (float)(maxRGB - minRGB); + float redFraction = (float)((int)maxRGB - r) / num; + float greenFraction = (float)((int)maxRGB - g) / num; + float blueFraction = (float)((int)maxRGB - b) / num; + float hue = 0f; + if (r == (int)maxRGB) + { + hue = 60f * (6f + blueFraction - greenFraction); + } + if (g == (int)maxRGB) + { + hue = 60f * (2f + redFraction - blueFraction); + } + if (b == (int)maxRGB) + { + hue = 60f * (4f + greenFraction - redFraction); + } + if (hue > 360f) + { + hue -= 360f; + } + return (double)(hue / HSL_SCALE); + } + set { UpdateHSL (value, Saturation, Luminosity); } + } + public int HueInt32 + { + get { return (int)(Hue * HSL_SCALE); } + set { Hue = CheckRange ((double)value / HSL_SCALE); } + } + public double Saturation + { + get + { + int minRGB = Math.Min (this.RedInt32, Math.Min (this.GreenInt32, this.BlueInt32)); + int maxRGB = Math.Max (this.RedInt32, Math.Max (this.GreenInt32, this.BlueInt32)); + if (maxRGB == minRGB) return 0.0; + + int num = (int)(maxRGB + minRGB); + if (num > 255) + { + num = 510 - num; + } + return (double)((double)(maxRGB - minRGB) / (double)num) / HSL_SCALE; + } + set { UpdateHSL (Hue, value, Luminosity); } + } + public int SaturationInt32 + { + get { return (int)(Saturation * HSL_SCALE); } + set { Saturation = CheckRange ((double)value / HSL_SCALE); } + } + public double Luminosity + { + get + { + int minRGB = Math.Min (this.RedInt32, Math.Min (this.GreenInt32, this.BlueInt32)); + int maxRGB = Math.Max (this.RedInt32, Math.Max (this.GreenInt32, this.BlueInt32)); + return (double)((double)(maxRGB + minRGB) / 510.0) / HSL_SCALE; + } + set { UpdateHSL (Hue, Saturation, value); } + } + public int LuminosityInt32 + { + get { return (int)(Luminosity * HSL_SCALE); } + set { Luminosity = CheckRange ((double)value / HSL_SCALE); } + } + + private void UpdateHSL(double h, double s, double l) + { + if (l != 0) + { + if (s == 0) + mvarRed = mvarGreen = mvarBlue = l; + else + { + double temp2 = GetTemp2(h, s, l); + double temp1 = 2.0 * l - temp2; + + mvarRed = GetColorComponent(temp1, temp2, h + 1.0 / 3.0); + mvarGreen = GetColorComponent(temp1, temp2, h); + mvarBlue = GetColorComponent(temp1, temp2, h - 1.0 / 3.0); + } + } + else + { + mvarRed = 0.0; + mvarGreen = 0.0; + mvarBlue = 0.0; + } + } + + private const double HSL_SCALE = 240.0; + private double CheckRange(double value) + { + if (value < 0.0) + value = 0.0; + else if (value > 1.0) + value = 1.0; + return value; + } + + public static Color FromHSL(int h, int s, int l) + { + return FromHSL ((double)h / HSL_SCALE, (double)s / HSL_SCALE, (double)l / HSL_SCALE); + } + + public static Color FromHSL(double h, double s, double l) + { + double r = 0, g = 0, b = 0; + if (l != 0) + { + if (s == 0) + r = g = b = l; + else + { + double temp2 = GetTemp2(h, s, l); + double temp1 = 2.0 * l - temp2; + + r = GetColorComponent(temp1, temp2, h + 1.0 / 3.0); + g = GetColorComponent(temp1, temp2, h); + b = GetColorComponent(temp1, temp2, h - 1.0 / 3.0); + } + } + return Color.FromRGBA((int)(255 * r), (int)(255 * g), (int)(255 * b)); + } + + private static double GetColorComponent(double temp1, double temp2, double temp3) + { + temp3 = MoveIntoRange(temp3); + if (temp3 < 1.0 / 6.0) + return temp1 + (temp2 - temp1) * 6.0 * temp3; + else if (temp3 < 0.5) + return temp2; + else if (temp3 < 2.0 / 3.0) + return temp1 + ((temp2 - temp1) * ((2.0 / 3.0) - temp3) * 6.0); + else + return temp1; + } + private static double MoveIntoRange(double temp3) + { + if (temp3 < 0.0) + temp3 += 1.0; + else if (temp3 > 1.0) + temp3 -= 1.0; + return temp3; + } + private static double GetTemp2(double h, double s, double l) + { + double temp2; + if (l < 0.5) //<=?? + temp2 = l * (1.0 + s); + else + temp2 = l + s - (l * s); + return temp2; + } + + public static readonly Color Empty; + + public override bool Equals(object obj) + { + if (obj is Color) + { + Color color = (Color)obj; + return ((mvarRed == color.mvarRed) && (mvarGreen == color.mvarGreen) && (mvarBlue == color.mvarBlue) && (mvarAlpha == color.mvarAlpha)); + } + return false; + } + public override int GetHashCode() + { + return base.GetHashCode(); + } + + public static Color FromRGBA(double red, double green, double blue, double alpha = 1.0) + { + Color color = new Color(); + color.Red = red; + color.Green = green; + color.Blue = blue; + color.Alpha = alpha; + return color; + } + public static Color FromRGBA(float red, float green, float blue, float alpha = 1.0f) + { + Color color = new Color(); + color.Red = red; + color.Green = green; + color.Blue = blue; + color.Alpha = alpha; + return color; + } + public static Color FromRGBA(byte red, byte green, byte blue, byte alpha = 255) + { + Color color = new Color(); + color.Red = ((double)red / 255); + color.Green = ((double)green / 255); + color.Blue = ((double)blue / 255); + color.Alpha = ((double)alpha / 255); + return color; + } + public static Color FromRGBA(int red, int green, int blue, int alpha = 255) + { + Color color = new Color(); + color.Red = ((double)red / 255); + color.Green = ((double)green / 255); + color.Blue = ((double)blue / 255); + color.Alpha = ((double)alpha / 255); + return color; + } + + public int CompareTo(Color other) + { + int thisVal = ToInt32(); + int otherVal = other.ToInt32(); + return thisVal.CompareTo(otherVal); + } + + public static bool operator ==(Color left, Color right) + { + return left.Equals(right); + } + public static bool operator !=(Color left, Color right) + { + return !left.Equals(right); + } + + public static Color FromString(string value) + { + if (value.StartsWith("#")) + { + // hex string + value = value.Substring(1); + + string rr = value.Substring(0, 2); + string gg = value.Substring(2, 2); + string bb = value.Substring(4, 2); + + byte r = Byte.Parse(rr, System.Globalization.NumberStyles.HexNumber); + byte g = Byte.Parse(gg, System.Globalization.NumberStyles.HexNumber); + byte b = Byte.Parse(bb, System.Globalization.NumberStyles.HexNumber); + + return Color.FromRGBA(r, g, b); + } + return Color.Empty; + } + */ + + public override bool Equals(object obj) + { + Color c = (Color)obj; + try + { + return (c.R == R && c.G == G && c.B == B && c.A == A); + } + catch (Exception ex) + { + } + return base.Equals(obj); + } + + public static bool operator ==(Color left, Color right) + { + return left.Equals(right); + } + public static bool operator !=(Color left, Color right) + { + return !left.Equals(right); + } + } +} diff --git a/MBS.Framework/Drawing/Colors.cs b/MBS.Framework/Drawing/Colors.cs new file mode 100644 index 0000000..178a30a --- /dev/null +++ b/MBS.Framework/Drawing/Colors.cs @@ -0,0 +1,307 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace MBS.Framework.Drawing +{ + public static class Colors + { + static Colors() + { + Aqua = Color.FromRGBAByte(0x00, 0xFF, 0xFF); + Black = Color.FromRGBAByte(0x00, 0x00, 0x00); + Blue = Color.FromRGBAByte(0x00, 0x00, 0xFF); + Fuchsia = Color.FromRGBAByte(0xFF, 0x00, 0xFF); + Gray = Color.FromRGBAByte(0x80, 0x80, 0x80); + Green = Color.FromRGBAByte(0x00, 0x80, 0x00); + Lime = Color.FromRGBAByte(0x00, 0xFF, 0x00); + Maroon = Color.FromRGBAByte(0x80, 0x00, 0x00); + Navy = Color.FromRGBAByte(0x00, 0x00, 0x80); + Olive = Color.FromRGBAByte(0x80, 0x80, 0x00); + Purple = Color.FromRGBAByte(0x80, 0x00, 0x80); + Red = Color.FromRGBAByte(0xFF, 0x00, 0x00); + Silver = Color.FromRGBAByte(0xC0, 0xC0, 0xC0); + Teal = Color.FromRGBAByte(0x00, 0x80, 0x80); + Yellow = Color.FromRGBAByte(0xFF, 0xFF, 0x00); + White = Color.FromRGBAByte(0xFF, 0xFF, 0xFF); + AliceBlue = Color.FromRGBAByte(0xF0, 0xF8, 0xFF); + AntiqueWhite = Color.FromRGBAByte(0xFA, 0xEB, 0xD7); + Aquamarine = Color.FromRGBAByte(0x7F, 0xFF, 0xD4); + Azure = Color.FromRGBAByte(0xF0, 0xFF, 0xFF); + Beige = Color.FromRGBAByte(0xF5, 0xF5, 0xDC); + Bisque = Color.FromRGBAByte(0xFF, 0xE4, 0xC4); + BlanchedAlmond = Color.FromRGBAByte(0xFF, 0xEB, 0xCD); + BlueViolet = Color.FromRGBAByte(0x8A, 0x2B, 0xE2); + Brown = Color.FromRGBAByte(0xA5, 0x2A, 0x2A); + BurlyWood = Color.FromRGBAByte(0xDE, 0xB8, 0x87); + CadetBlue = Color.FromRGBAByte(0x5F, 0x9E, 0xA0); + Chartreuse = Color.FromRGBAByte(0x7F, 0xFF, 0x00); + Chocolate = Color.FromRGBAByte(0xD2, 0x69, 0x1E); + Coral = Color.FromRGBAByte(0xFF, 0x7F, 0x50); + CornflowerBlue = Color.FromRGBAByte(0x64, 0x95, 0xED); + Cornsilk = Color.FromRGBAByte(0xFF, 0xF8, 0xDC); + Crimson = Color.FromRGBAByte(0xDC, 0x14, 0x3C); + Cyan = Color.FromRGBAByte(0x00, 0xFF, 0xFF); + DarkBlue = Color.FromRGBAByte(0x00, 0x00, 0x8B); + DarkCyan = Color.FromRGBAByte(0x00, 0x8B, 0x8B); + DarkGoldenrod = Color.FromRGBAByte(0xB8, 0x86, 0x0B); + DarkGray = Color.FromRGBAByte(0xA9, 0xA9, 0xA9); + DarkGreen = Color.FromRGBAByte(0x00, 0x64, 0x00); + DarkKhaki = Color.FromRGBAByte(0xBD, 0xB7, 0x6B); + DarkMagenta = Color.FromRGBAByte(0x8B, 0x00, 0x8B); + DarkOliveGreen = Color.FromRGBAByte(0x55, 0x6B, 0x2F); + DarkOrange = Color.FromRGBAByte(0xFF, 0x8C, 0x00); + DarkOrchid = Color.FromRGBAByte(0x99, 0x32, 0xCC); + DarkRed = Color.FromRGBAByte(0x8B, 0x00, 0x00); + DarkSalmon = Color.FromRGBAByte(0xE9, 0x96, 0x7A); + DarkSeaGreen = Color.FromRGBAByte(0x8F, 0xBC, 0x8F); + DarkSlateBlue = Color.FromRGBAByte(0x48, 0x3D, 0x8B); + DarkSlateGray = Color.FromRGBAByte(0x2F, 0x4F, 0x4F); + DarkTurquoise = Color.FromRGBAByte(0x00, 0xCE, 0xD1); + + DarkViolet = Color.FromRGBAByte(0x94, 0x00, 0xD3); + DeepPink = Color.FromRGBAByte(0xFF, 0x14, 0x93); + DeepSkyBlue = Color.FromRGBAByte(0x00, 0xBF, 0xFF); + DimGray = Color.FromRGBAByte(0x69, 0x69, 0x69); + DodgerBlue = Color.FromRGBAByte(0x1E, 0x90, 0xFF); + Firebrick = Color.FromRGBAByte(0xB2, 0x22, 0x22); + FloralWhite = Color.FromRGBAByte(0xFF, 0xFA, 0xF0); + ForestGreen = Color.FromRGBAByte(0x22, 0x8B, 0x22); + Gainsboro = Color.FromRGBAByte(0xDC, 0xDC, 0xDC); + GhostWhite = Color.FromRGBAByte(0xF8, 0xF8, 0xFF); + Gold = Color.FromRGBAByte(0xFF, 0xD7, 0x00); + Goldenrod = Color.FromRGBAByte(0xDA, 0xA5, 0x20); + GreenYellow = Color.FromRGBAByte(0xAD, 0xFF, 0x2F); + Honeydew = Color.FromRGBAByte(0xF0, 0xFF, 0xF0); + HotPink = Color.FromRGBAByte(0xFF, 0x69, 0xB4); + IndianRed = Color.FromRGBAByte(0xCD, 0x5C, 0x5C); + Indigo = Color.FromRGBAByte(0x4B, 0x00, 0x82); + Ivory = Color.FromRGBAByte(0xFF, 0xFF, 0xF0); + Khaki = Color.FromRGBAByte(0xF0, 0xE6, 0x8C); + Lavender = Color.FromRGBAByte(0xE6, 0xE6, 0xFA); + LavenderBlush = Color.FromRGBAByte(0xFF, 0xF0, 0xF5); + LawnGreen = Color.FromRGBAByte(0x7C, 0xFC, 0x00); + LemonChiffon = Color.FromRGBAByte(0xFF, 0xFA, 0xCD); + LightBlue = Color.FromRGBAByte(0xAD, 0xD8, 0xE6); + LightCoral = Color.FromRGBAByte(0xF0, 0x80, 0x80); + LightCyan = Color.FromRGBAByte(0xE0, 0xFF, 0xFF); + LightGoldenrodYellow = Color.FromRGBAByte(0xFA, 0xFA, 0xD2); + LightGreen = Color.FromRGBAByte(0x90, 0xEE, 0x90); + LightGray = Color.FromRGBAByte(0xD3, 0xD3, 0xD3); + LightPink = Color.FromRGBAByte(0xFF, 0xB6, 0xC1); + LightSalmon = Color.FromRGBAByte(0xFF, 0xA0, 0x7A); + LightSeaGreen = Color.FromRGBAByte(0x20, 0xB2, 0xAA); + LightSkyBlue = Color.FromRGBAByte(0x87, 0xCE, 0xFA); + LightSlateGray = Color.FromRGBAByte(0x77, 0x88, 0x99); + LightSteelBlue = Color.FromRGBAByte(0xB0, 0xC4, 0xDE); + LightYellow = Color.FromRGBAByte(0xFF, 0xFF, 0xE0); + LimeGreen = Color.FromRGBAByte(0x32, 0xCD, 0x32); + + Linen = Color.FromRGBAByte(0xFA, 0xF0, 0xE6); + Magenta = Color.FromRGBAByte(0xFF, 0x00, 0xFF); + MediumAquamarine = Color.FromRGBAByte(0x66, 0xCD, 0xAA); + MediumBlue = Color.FromRGBAByte(0x00, 0x00, 0xCD); + MediumOrchid = Color.FromRGBAByte(0xBA, 0x55, 0xD3); + MediumPurple = Color.FromRGBAByte(0x93, 0x70, 0xDB); + MediumSeaGreen = Color.FromRGBAByte(0x3C, 0xB3, 0x71); + MediumSlateBlue = Color.FromRGBAByte(0x7B, 0x68, 0xEE); + MediumSpringGreen = Color.FromRGBAByte(0x00, 0xFA, 0x9A); + MediumTurquoise = Color.FromRGBAByte(0x48, 0xD1, 0xCC); + MediumVioletRed = Color.FromRGBAByte(0xC7, 0x15, 0x85); + MidnightBlue = Color.FromRGBAByte(0x19, 0x19, 0x70); + MintCream = Color.FromRGBAByte(0xF5, 0xFF, 0xFA); + MistyRose = Color.FromRGBAByte(0xFF, 0xE4, 0xE1); + Moccasin = Color.FromRGBAByte(0xFF, 0xE4, 0xB5); + NavajoWhite = Color.FromRGBAByte(0xFF, 0xDE, 0xAD); + OldLace = Color.FromRGBAByte(0xFD, 0xF5, 0xE6); + OliveDrab = Color.FromRGBAByte(0x6B, 0x8E, 0x23); + Orange = Color.FromRGBAByte(0xFF, 0xA5, 0x00); + OrangeRed = Color.FromRGBAByte(0xFF, 0x45, 0x00); + Orchid = Color.FromRGBAByte(0xDA, 0x70, 0xD6); + PaleGoldenrod = Color.FromRGBAByte(0xEE, 0xE8, 0xAA); + PaleTurquoise = Color.FromRGBAByte(0xAF, 0xEE, 0xEE); + PaleVioletRed = Color.FromRGBAByte(0xDB, 0x70, 0x93); + PapayaWhip = Color.FromRGBAByte(0xFF, 0xEF, 0xD5); + PeachPuff = Color.FromRGBAByte(0xFF, 0xDA, 0xB9); + Peru = Color.FromRGBAByte(0xCD, 0x85, 0x3F); + Pink = Color.FromRGBAByte(0xFF, 0xC0, 0xCB); + Plum = Color.FromRGBAByte(0xDD, 0xA0, 0xDD); + PowderBlue = Color.FromRGBAByte(0xB0, 0xE0, 0xE6); + RosyBrown = Color.FromRGBAByte(0xBC, 0x8F, 0x8F); + RoyalBlue = Color.FromRGBAByte(0x41, 0x69, 0xE1); + SaddleBrown = Color.FromRGBAByte(0x8B, 0x45, 0x13); + Salmon = Color.FromRGBAByte(0xFA, 0x80, 0x72); + SandyBrown = Color.FromRGBAByte(0xF4, 0xA4, 0x60); + SeaGreen = Color.FromRGBAByte(0x2E, 0x8B, 0x57); + + Seashell = Color.FromRGBAByte(0xFF, 0xF5, 0xEE); + Sienna = Color.FromRGBAByte(0xA0, 0x52, 0x2D); + SkyBlue = Color.FromRGBAByte(0x87, 0xCE, 0xEB); + SlateBlue = Color.FromRGBAByte(0x6A, 0x5A, 0xCD); + SlateGray = Color.FromRGBAByte(0x70, 0x80, 0x90); + Snow = Color.FromRGBAByte(0xFF, 0xFA, 0xFA); + SpringGreen = Color.FromRGBAByte(0x00, 0xFF, 0x7F); + SteelBlue = Color.FromRGBAByte(0x46, 0x82, 0xB4); + + Tan = Color.FromRGBAByte(0xD2, 0xB4, 0x8C); + Thistle = Color.FromRGBAByte(0xD8, 0xBF, 0xD8); + Tomato = Color.FromRGBAByte(0xFF, 0x63, 0x47); + Transparent = Color.FromRGBAByte(0x00, 0x00, 0x00, 0x00); + Turquoise = Color.FromRGBAByte(0x40, 0xE0, 0xD0); + Violet = Color.FromRGBAByte(0xEE, 0x82, 0xEE); + Wheat = Color.FromRGBAByte(0xF5, 0xDE, 0xB3); + WhiteSmoke = Color.FromRGBAByte(0xF5, 0xF5, 0xF5); + YellowGreen = Color.FromRGBAByte(0x9A, 0xCD, 0x32); + } + + // HTML Standard Colors + public static Color Aqua { get; private set; } + public static Color Black { get; private set; } + public static Color Blue { get; private set; } + public static Color Fuchsia { get; private set; } + public static Color Gray { get; private set; } + public static Color Green { get; private set; } + public static Color Lime { get; private set; } + public static Color Maroon { get; private set; } + public static Color Navy { get; private set; } + public static Color Olive { get; private set; } + public static Color Purple { get; private set; } + public static Color Red { get; private set; } + public static Color Silver { get; private set; } + public static Color Teal { get; private set; } + public static Color Yellow { get; private set; } + public static Color White { get; private set; } + + // HTML Extended Colors + + public static Color AliceBlue { get; private set; } + public static Color AntiqueWhite { get; private set; } + public static Color Aquamarine { get; private set; } + public static Color Azure { get; private set; } + public static Color Beige { get; private set; } + public static Color Bisque { get; private set; } + public static Color BlanchedAlmond { get; private set; } + public static Color BlueViolet { get; private set; } + public static Color Brown { get; private set; } + public static Color BurlyWood { get; private set; } + public static Color CadetBlue { get; private set; } + public static Color Chartreuse { get; private set; } + public static Color Chocolate { get; private set; } + public static Color Coral { get; private set; } + public static Color CornflowerBlue { get; private set; } + public static Color Cornsilk { get; private set; } + public static Color Crimson { get; private set; } + public static Color Cyan { get; private set; } + public static Color DarkBlue { get; private set; } + public static Color DarkCyan { get; private set; } + public static Color DarkGoldenrod { get; private set; } + public static Color DarkGray { get; private set; } + public static Color DarkGreen { get; private set; } + public static Color DarkKhaki { get; private set; } + public static Color DarkMagenta { get; private set; } + public static Color DarkOliveGreen { get; private set; } + public static Color DarkOrange { get; private set; } + public static Color DarkOrchid { get; private set; } + public static Color DarkRed { get; private set; } + public static Color DarkSalmon { get; private set; } + public static Color DarkSeaGreen { get; private set; } + public static Color DarkSlateBlue { get; private set; } + public static Color DarkSlateGray { get; private set; } + public static Color DarkTurquoise { get; private set; } + + public static Color DarkViolet { get; private set; } + public static Color DeepPink { get; private set; } + public static Color DeepSkyBlue { get; private set; } + public static Color DimGray { get; private set; } + public static Color DodgerBlue { get; private set; } + public static Color Firebrick { get; private set; } + public static Color FloralWhite { get; private set; } + public static Color ForestGreen { get; private set; } + public static Color Gainsboro { get; private set; } + public static Color GhostWhite { get; private set; } + public static Color Gold { get; private set; } + public static Color Goldenrod { get; private set; } + public static Color GreenYellow { get; private set; } + public static Color Honeydew { get; private set; } + public static Color HotPink { get; private set; } + public static Color IndianRed { get; private set; } + public static Color Indigo { get; private set; } + public static Color Ivory { get; private set; } + public static Color Khaki { get; private set; } + public static Color Lavender { get; private set; } + public static Color LavenderBlush { get; private set; } + public static Color LawnGreen { get; private set; } + public static Color LemonChiffon { get; private set; } + public static Color LightBlue { get; private set; } + public static Color LightCoral { get; private set; } + public static Color LightCyan { get; private set; } + public static Color LightGoldenrodYellow { get; private set; } + public static Color LightGreen { get; private set; } + public static Color LightGray { get; private set; } + public static Color LightPink { get; private set; } + public static Color LightSalmon { get; private set; } + public static Color LightSeaGreen { get; private set; } + public static Color LightSkyBlue { get; private set; } + public static Color LightSlateGray { get; private set; } + public static Color LightSteelBlue { get; private set; } + public static Color LightYellow { get; private set; } + public static Color LimeGreen { get; private set; } + + public static Color Linen { get; private set; } + public static Color Magenta { get; private set; } + public static Color MediumAquamarine { get; private set; } + public static Color MediumBlue { get; private set; } + public static Color MediumOrchid { get; private set; } + public static Color MediumPurple { get; private set; } + public static Color MediumSeaGreen { get; private set; } + public static Color MediumSlateBlue { get; private set; } + public static Color MediumSpringGreen { get; private set; } + public static Color MediumTurquoise { get; private set; } + public static Color MediumVioletRed { get; private set; } + public static Color MidnightBlue { get; private set; } + public static Color MintCream { get; private set; } + public static Color MistyRose { get; private set; } + public static Color Moccasin { get; private set; } + public static Color NavajoWhite { get; private set; } + public static Color OldLace { get; private set; } + public static Color OliveDrab { get; private set; } + public static Color Orange { get; private set; } + public static Color OrangeRed { get; private set; } + public static Color Orchid { get; private set; } + public static Color PaleGoldenrod { get; private set; } + public static Color PaleTurquoise { get; private set; } + public static Color PaleVioletRed { get; private set; } + public static Color PapayaWhip { get; private set; } + public static Color PeachPuff { get; private set; } + public static Color Peru { get; private set; } + public static Color Pink { get; private set; } + public static Color Plum { get; private set; } + public static Color PowderBlue { get; private set; } + public static Color RosyBrown { get; private set; } + public static Color RoyalBlue { get; private set; } + public static Color SaddleBrown { get; private set; } + public static Color Salmon { get; private set; } + public static Color SandyBrown { get; private set; } + public static Color SeaGreen { get; private set; } + + public static Color Seashell { get; private set; } + public static Color Sienna { get; private set; } + public static Color SkyBlue { get; private set; } + public static Color SlateBlue { get; private set; } + public static Color SlateGray { get; private set; } + public static Color Snow { get; private set; } + public static Color SpringGreen { get; private set; } + public static Color SteelBlue { get; private set; } + + public static Color Tan { get; private set; } + public static Color Thistle { get; private set; } + public static Color Tomato { get; private set; } + public static Color Transparent { get; private set; } + public static Color Turquoise { get; private set; } + public static Color Violet { get; private set; } + public static Color Wheat { get; private set; } + public static Color WhiteSmoke { get; private set; } + public static Color YellowGreen { get; private set; } + } +} diff --git a/MBS.Framework/Drawing/Dimension.cs b/MBS.Framework/Drawing/Dimension.cs new file mode 100644 index 0000000..f907d08 --- /dev/null +++ b/MBS.Framework/Drawing/Dimension.cs @@ -0,0 +1,6 @@ +namespace MBS.Framework.Drawing +{ + public abstract class Dimension + { + } +} diff --git a/MBS.Framework/Drawing/Dimension2D.cs b/MBS.Framework/Drawing/Dimension2D.cs new file mode 100644 index 0000000..6ed22d1 --- /dev/null +++ b/MBS.Framework/Drawing/Dimension2D.cs @@ -0,0 +1,35 @@ +namespace MBS.Framework.Drawing +{ + public class Dimension2D : Dimension + { + private double mvarWidth = 0.0; + public double Width { get { return mvarWidth; } set { mvarWidth = value; } } + private double mvarHeight = 0.0; + public double Height { get { return mvarHeight; } set { mvarHeight = value; } } + + public static Dimension2D Empty = new Dimension2D(); + + public Dimension2D() + { + } + public Dimension2D(double width, double height) + { + mvarWidth = width; + mvarHeight = height; + } + + public Dimension2D Rotate() + { + Dimension2D size = this; + double width = size.Width; + size.Width = size.Height; + size.Height = width; + return size; + } + + public override string ToString() + { + return Width.ToString() + "x" + Height.ToString(); + } + } +} diff --git a/MBS.Framework/Drawing/Dimension3D.cs b/MBS.Framework/Drawing/Dimension3D.cs new file mode 100644 index 0000000..080dd9d --- /dev/null +++ b/MBS.Framework/Drawing/Dimension3D.cs @@ -0,0 +1,25 @@ +using System; +namespace MBS.Framework.Drawing +{ + public struct Dimension3D : ICloneable + { + public static readonly Dimension3D Empty; + + public double Width { get; set; } + public double Height { get; set; } + public double Depth { get; set; } + + public Dimension3D(double width, double height, double depth) + { + Width = width; + Height = height; + Depth = depth; + } + + public object Clone() + { + Dimension3D clone = new Dimension3D(Width, Height, Depth); + return clone; + } + } +} diff --git a/MBS.Framework/Drawing/Padding.cs b/MBS.Framework/Drawing/Padding.cs new file mode 100644 index 0000000..56e6689 --- /dev/null +++ b/MBS.Framework/Drawing/Padding.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace MBS.Framework.Drawing +{ + public struct Padding + { + private int mvarLeft; + public int Left { get { return mvarLeft; } set { mvarLeft = value; } } + private int mvarTop; + public int Top { get { return mvarTop; } set { mvarTop = value; } } + private int mvarRight; + public int Right { get { return mvarRight; } set { mvarRight = value; } } + private int mvarBottom; + public int Bottom { get { return mvarBottom; } set { mvarBottom = value; } } + + public int All + { + get + { + if (mvarLeft == mvarTop && mvarTop == mvarRight && mvarRight == mvarBottom) return mvarLeft; + return -1; + } + set + { + mvarLeft = value; + mvarTop = value; + mvarRight = value; + mvarBottom = value; + } + } + + public Padding(int all) + { + mvarBottom = all; + mvarLeft = all; + mvarRight = all; + mvarTop = all; + } + public Padding(int top, int bottom, int left, int right) + { + mvarBottom = bottom; + mvarLeft = left; + mvarRight = right; + mvarTop = top; + } + } +} diff --git a/MBS.Framework/Drawing/Rectangle.cs b/MBS.Framework/Drawing/Rectangle.cs new file mode 100644 index 0000000..d9045f0 --- /dev/null +++ b/MBS.Framework/Drawing/Rectangle.cs @@ -0,0 +1,133 @@ +// +// Rectangle.cs +// +// Author: +// Mike Becker +// +// Copyright (c) 2019 Mike Becker +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; +using System.Text; + +namespace MBS.Framework.Drawing +{ + public struct Rectangle : IComparable, IEquatable + { + public static readonly Rectangle Empty = new Rectangle(); + + public Rectangle(Vector2D location, Dimension2D size) + { + X = location.X; + Y = location.Y; + Width = size.Width; + Height = size.Height; + } + public Rectangle(double x, double y, double width, double height) + { + X = x; + Y = y; + Width = width; + Height = height; + } + + public double X { get; set; } + public double Y { get; set; } + public double Width { get; set; } + public double Height { get; set; } + + public Vector2D Location + { + get { return new Vector2D(X, Y); } + set { X = value.X; Y = value.Y; } + } + public Dimension2D Size + { + get { return new Dimension2D(Width, Height); } + set { Width = value.Width; Height = value.Height; } + } + + public double Right { get { return X + Width; } set { Width = value - X; } } + public double Bottom { get { return Y + Height; } set { Height = value - Y; } } + + public Rectangle Deflate(Padding padding) + { + Rectangle rect = this; + rect.X += padding.Left; + rect.Y += padding.Top; + rect.Width -= padding.Right; + rect.Height -= padding.Bottom; + return rect; + } + + + public bool Contains(double x, double y) + { + return (x >= X && y >= Y && x <= Right && y <= Bottom); + } + public bool Contains(Vector2D point) + { + return Contains(point.X, point.Y); + } + + public int CompareTo(Rectangle other) + { + double thisArea = this.Width * this.Height; + double otherArea = other.Width * other.Height; + + return (int)(thisArea - otherArea); + } + + #region IEquatable implementation + + public bool Equals(Rectangle other) + { + return (this.Width == other.Width && this.Height == other.Height); + } + + #endregion + + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("("); + sb.Append(X.ToString()); + sb.Append(", "); + sb.Append(Y.ToString()); + sb.Append(")-("); + sb.Append(Right.ToString()); + sb.Append(", "); + sb.Append(Bottom.ToString()); + sb.Append(")"); + sb.Append(", "); + sb.Append(Width.ToString()); + sb.Append("x"); + sb.Append(Height.ToString()); + return sb.ToString(); + } + + public static bool operator ==(Rectangle left, Rectangle right) + { + return left.Equals(right); + } + public static bool operator !=(Rectangle left, Rectangle right) + { + return !left.Equals(right); + } + public override bool Equals(object obj) + { + return base.Equals(obj); + } + } +} diff --git a/MBS.Framework/Drawing/Vector.cs b/MBS.Framework/Drawing/Vector.cs new file mode 100644 index 0000000..9f69160 --- /dev/null +++ b/MBS.Framework/Drawing/Vector.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace MBS.Framework.Drawing +{ + public abstract class Vector + { + } + public class Vector2D + { + private double mvarX = 0.0; + public double X { get { return mvarX; } set { mvarX = value; } } + private double mvarY = 0.0; + public double Y { get { return mvarY; } set { mvarY = value; } } + + public Vector2D() + { + } + public Vector2D(double x, double y) + { + mvarX = x; + mvarY = y; + } + } +} diff --git a/MBS.Framework/MBS.Framework.csproj b/MBS.Framework/MBS.Framework.csproj new file mode 100644 index 0000000..28b012c --- /dev/null +++ b/MBS.Framework/MBS.Framework.csproj @@ -0,0 +1,47 @@ + + + + Debug + AnyCPU + {00266B21-35C9-4A7F-A6BA-D54D7FDCC25C} + Library + MBS.Framework + MBS.Framework + + + true + full + false + ..\Output\Debug + DEBUG; + prompt + 4 + ..\Output\Debug\MBS.Framework.xml + false + + + true + ..\Output\Release + prompt + 4 + ..\Output\Release\MBS.Framework.xml + false + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MBS.Framework/Properties/AssemblyInfo.cs b/MBS.Framework/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..828fad5 --- /dev/null +++ b/MBS.Framework/Properties/AssemblyInfo.cs @@ -0,0 +1,46 @@ +// +// AssemblyInfo.cs +// +// Author: +// Michael Becker +// +// Copyright (c) 2019 +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("MBS.Framework")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")]