using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using WinformColor = System.Windows.Media.Color; using WpfColor = System.Drawing.Color; using StorageColorPair = HFUTCourseSimulation.Kernel.UserData.ColorPair; using RuntimeColorPair = HFUTCourseSimulation.Util.ColorPair; namespace HFUTCourseSimulation.Util { public static class ColorTrans { #region Color Transform public static WpfColor ToWpfColor(int argb) { return WpfColor.FromArgb(argb); } public static WpfColor ToWpfColor(WinformColor c) { return WpfColor.FromArgb(c.A, c.R, c.G, c.B); } public static WinformColor ToWinformColor(int _argb) { var argb = (uint)_argb; var a = (argb & 0xff000000) >> 24; var r = (argb & 0x00ff0000) >> 16; var g = (argb & 0x0000ff00) >> 8; var b = (argb & 0x000000ff); return WinformColor.FromArgb((byte)a, (byte)r, (byte)g, (byte)b); } public static WinformColor ToWinformColor(WpfColor c) { return WinformColor.FromArgb(c.A, c.R, c.G, c.B); } public static int ToInt(WpfColor c) { return c.ToArgb(); } public static int ToInt(WinformColor c) { uint argb = 0; argb |= c.A; argb <<= 8; argb |= c.R; argb <<= 8; argb |= c.G; argb <<= 8; argb |= c.B; return (int)argb; } #endregion #region Color Pair Transform public static StorageColorPair ToStorageColor(RuntimeColorPair cp) { return new StorageColorPair() { Foreground = cp.Foreground, Background = cp.Background }; } public static RuntimeColorPair ToRuntimeColor(StorageColorPair cp) { return new RuntimeColorPair(cp.Foreground, cp.Background); } #endregion } }