diff --git a/HFUTCourseSimulation/Dialog/EditCourse.xaml b/HFUTCourseSimulation/Dialog/EditCourse.xaml index e597c96..bdf3d9e 100644 --- a/HFUTCourseSimulation/Dialog/EditCourse.xaml +++ b/HFUTCourseSimulation/Dialog/EditCourse.xaml @@ -7,7 +7,8 @@ xmlns:userdata="clr-namespace:HFUTCourseSimulation.Kernel.UserData" mc:Ignorable="d" d:DataContext="{d:DesignInstance userdata:Course}" - Title="编辑课程" Height="500" Width="600" WindowStyle="ToolWindow"> + x:Name="uiMainWindow" + Title="编辑课程" Height="500" Width="600" WindowStyle="ToolWindow" Loaded="uiMainWindow_Loaded" Closed="uiMainWindow_Closed"> @@ -21,16 +22,16 @@ - + - + - + @@ -41,7 +42,46 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/HFUTCourseSimulation/Dialog/EditCourse.xaml.cs b/HFUTCourseSimulation/Dialog/EditCourse.xaml.cs index 7e8738f..340b0e9 100644 --- a/HFUTCourseSimulation/Dialog/EditCourse.xaml.cs +++ b/HFUTCourseSimulation/Dialog/EditCourse.xaml.cs @@ -19,7 +19,72 @@ namespace HFUTCourseSimulation.Dialog { public partial class EditCourse : Window { public EditCourse() { InitializeComponent(); - this.DataContext = Kernel.Context.Instance.currentCourse; } + + public Kernel.UserData.Course CurrentCourse { get; set; } + + private void uiMainWindow_Loaded(object sender, RoutedEventArgs e) { + this.DataContext = CurrentCourse; + } + + private void uiMainWindow_Closed(object sender, EventArgs e) { + this.DataContext = null; + } + + private void uiSchedulesList_MouseDoubleClick(object sender, MouseButtonEventArgs e) { + // It just an alias to edit + uiCtxMenuEditSchedule_Click(sender, e); + } + + private void uiCtxMenuNewSchedule_Click(object sender, RoutedEventArgs e) { + // Create new item and order user edit it + var item = new Kernel.UserData.Schedule(); + var dialog = new EditSchedule(); + dialog.CurrentSchedule = item; + dialog.ShowDialog(); + + // Then insert or append it into list + var idx = uiSchedulesList.SelectedIndex; + if (idx < 0) { + // No selection, append. + CurrentCourse.Schedules.Add(item); + } else { + // Has selection, insert + CurrentCourse.Schedules.Insert(idx, item); + } + } + + private void uiCtxMenuEditSchedule_Click(object sender, RoutedEventArgs e) { + var idx = uiSchedulesList.SelectedIndex; + if (idx < 0) return; + + var dialog = new EditSchedule(); + dialog.CurrentSchedule = CurrentCourse.Schedules[idx]; + dialog.ShowDialog(); + } + + private void uiCtxMenuDeleteSchedule_Click(object sender, RoutedEventArgs e) { + // Check whether there is item can be deleted + var idx = uiSchedulesList.SelectedIndex; + if (idx < 0) return; + + // Order a confirm + var rv = Util.Win32Dialog.Confirm("确认删除选中的课程安排吗?该操作不可撤销!", "确认删除"); + if (!rv) return; + + // Remove it + CurrentCourse.Schedules.RemoveAt(idx); + } + + private void uiCtxMenuClearSchedule_Click(object sender, RoutedEventArgs e) { + // Order a confirm + var rv = Util.Win32Dialog.Confirm("确认删除所有课程安排吗?该操作不可撤销!", "确认清空"); + if (!rv) return; + + // Clear all schedules + CurrentCourse.Schedules.Clear(); + } + } + } diff --git a/HFUTCourseSimulation/Dialog/EditSchedule.xaml b/HFUTCourseSimulation/Dialog/EditSchedule.xaml index 0b1e655..14c8f57 100644 --- a/HFUTCourseSimulation/Dialog/EditSchedule.xaml +++ b/HFUTCourseSimulation/Dialog/EditSchedule.xaml @@ -7,7 +7,8 @@ xmlns:userdata="clr-namespace:HFUTCourseSimulation.Kernel.UserData" mc:Ignorable="d" d:DataContext="{d:DesignInstance userdata:Schedule}" - Title="编辑课程安排" Height="450" Width="600" WindowStyle="ToolWindow"> + x:Name="uiMainWindow" + Title="编辑课程安排" Height="450" Width="600" WindowStyle="ToolWindow" Loaded="uiMainWindow_Loaded" Closed="uiMainWindow_Closed"> diff --git a/HFUTCourseSimulation/Dialog/EditSchedule.xaml.cs b/HFUTCourseSimulation/Dialog/EditSchedule.xaml.cs index 5a6f5c9..b8b37bf 100644 --- a/HFUTCourseSimulation/Dialog/EditSchedule.xaml.cs +++ b/HFUTCourseSimulation/Dialog/EditSchedule.xaml.cs @@ -19,9 +19,17 @@ namespace HFUTCourseSimulation.Dialog { public partial class EditSchedule : Window { public EditSchedule() { InitializeComponent(); - this.DataContext = Kernel.Context.Instance.currentSchedule; } - + + public Kernel.UserData.Schedule CurrentSchedule { get; set; } + + private void uiMainWindow_Loaded(object sender, RoutedEventArgs e) { + this.DataContext = CurrentSchedule; + } + + private void uiMainWindow_Closed(object sender, EventArgs e) { + this.DataContext = null; + } } } diff --git a/HFUTCourseSimulation/HFUTCourseSimulation.csproj b/HFUTCourseSimulation/HFUTCourseSimulation.csproj index a7f0a9e..33155b3 100644 --- a/HFUTCourseSimulation/HFUTCourseSimulation.csproj +++ b/HFUTCourseSimulation/HFUTCourseSimulation.csproj @@ -83,7 +83,6 @@ - diff --git a/HFUTCourseSimulation/ImageExport.cs b/HFUTCourseSimulation/ImageExport.cs index 8c3bf65..3fe6013 100644 --- a/HFUTCourseSimulation/ImageExport.cs +++ b/HFUTCourseSimulation/ImageExport.cs @@ -89,7 +89,7 @@ namespace HFUTCourseSimulation { var cellx = courses.Start.week - 1; var celly = courses.Start.index - 1; //background - cellBrush = new SolidBrush(Util.ColorTrans.ToWpfColor(courses.BkColor)); + cellBrush = new SolidBrush(Util.ColorTrans.ToWinformColor(courses.BkColor)); graphics.FillRectangle(cellBrush, cellx * BodyCellWidth, celly * BodyCellHeight, BodyCellWidth, BodyCellHeight * courses.Span); //draw text diff --git a/HFUTCourseSimulation/Kernel/Context.cs b/HFUTCourseSimulation/Kernel/Context.cs deleted file mode 100644 index 720bfa5..0000000 --- a/HFUTCourseSimulation/Kernel/Context.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace HFUTCourseSimulation.Kernel { - - public class Context { - public static readonly Context Instance = new Context(); - private Context() { - currentSemester = null; - currentCourse = null; - currentSchedule = null; - } - - public UserData.Semester currentSemester; - public UserData.Course currentCourse; - public UserData.Schedule currentSchedule; - public UserData.ColorPair currentColor; - public string currentFilePath; - } - -} diff --git a/HFUTCourseSimulation/Kernel/OldUserData/V1.cs b/HFUTCourseSimulation/Kernel/OldUserData/V1.cs index 879b4ed..09c5243 100644 --- a/HFUTCourseSimulation/Kernel/OldUserData/V1.cs +++ b/HFUTCourseSimulation/Kernel/OldUserData/V1.cs @@ -1,6 +1,4 @@ -using HFUTCourseSimulation.Kernel.UserData; -using HFUTCourseSimulation.Util; -using Newtonsoft.Json; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Globalization; @@ -56,10 +54,8 @@ namespace HFUTCourseSimulation.Kernel.OldUserData.V1 { return new UserData.Course() { Name = Name, Description = Description, - Color = new UserData.ColorPair() { - Foreground = System.Drawing.Color.White, - Background = ColorTrans.ToWpfColor(BkColor) - }, + Foreground = Colors.Black, + Background = BkColor, Schedules = Schedule.Select((item) => item.ToLatest()).ToList() }; } @@ -106,7 +102,7 @@ namespace HFUTCourseSimulation.Kernel.OldUserData.V1 { if (reader.TokenType == JsonToken.Integer) { var argb = Convert.ToInt32(reader.Value); // Read color and force set its Alpha to zero. - var rv = Util.ColorTrans.ToWinformColor(argb); + var rv = Util.ColorTrans.ToWpfColor(argb); rv.A = 255; return rv; } else { diff --git a/HFUTCourseSimulation/Kernel/SimData.cs b/HFUTCourseSimulation/Kernel/SimData.cs index 2635fb2..bc2fd8e 100644 --- a/HFUTCourseSimulation/Kernel/SimData.cs +++ b/HFUTCourseSimulation/Kernel/SimData.cs @@ -105,7 +105,7 @@ namespace HFUTCourseSimulation.Kernel.SimData { /// /// 课程的颜色 /// - public readonly UserData.ColorPair color; + public readonly Util.ColorPair color; /// /// 课程的起始节次。 /// 该类保证该值位于1到indexCount之间(含首尾)。 diff --git a/HFUTCourseSimulation/Kernel/UserData.cs b/HFUTCourseSimulation/Kernel/UserData.cs index 80af443..1db15fa 100644 --- a/HFUTCourseSimulation/Kernel/UserData.cs +++ b/HFUTCourseSimulation/Kernel/UserData.cs @@ -1,11 +1,11 @@ using Newtonsoft.Json; using System; using System.Collections.Generic; -using System.Drawing; using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows.Media; using HFUTCourseSimulation.Util; namespace HFUTCourseSimulation.Kernel.UserData { @@ -66,7 +66,9 @@ namespace HFUTCourseSimulation.Kernel.UserData { public Course() { Name = ""; Description = ""; - Color = ColorTrans.ToStorageColor(Util.ColorPreset.MdColors.Indigo); + var color = Util.ColorPreset.MdColors.Indigo; + Foreground = color.Foreground; + Background = color.Background; Schedules = new List(); } @@ -81,10 +83,17 @@ namespace HFUTCourseSimulation.Kernel.UserData { [JsonProperty("description")] public string Description { get; set; } /// - /// 课程的颜色 + /// 课程的前景色(文本) /// - [JsonProperty("color")] - public ColorPair Color { get; set; } + [JsonProperty("foreground")] + [JsonConverter(typeof(CustomColorConverter))] + public Color Foreground { get; set; } + /// + /// 课程的背景色(背景) + /// + [JsonProperty("background")] + [JsonConverter(typeof(CustomColorConverter))] + public Color Background { get; set; } /// /// 课程的所有安排 /// @@ -116,29 +125,6 @@ namespace HFUTCourseSimulation.Kernel.UserData { public string Index { get; set; } } - /// - /// 存储时所用的颜色对,与辅助类里的颜色对有所区别。 - /// - public class ColorPair { - public ColorPair() { - Foreground = Color.Black; - Background = Color.White; - } - - /// - /// 前景色(文本的颜色) - /// - [JsonProperty("foreground")] - [JsonConverter(typeof(CustomColorConverter))] - public Color Foreground { get; set; } - /// - /// 背景色 - /// - [JsonProperty("background")] - [JsonConverter(typeof(CustomColorConverter))] - public Color Background { get; set; } - } - internal class CustomDateTimeConverter : JsonConverter { private static readonly string DatetimeFormat = "yyyy-MM-dd"; @@ -164,14 +150,14 @@ namespace HFUTCourseSimulation.Kernel.UserData { public override Color ReadJson(JsonReader reader, Type objectType, Color existingValue, bool hasExistingValue, JsonSerializer serializer) { if (reader.TokenType == JsonToken.Integer) { var argb = Convert.ToInt32(reader.Value); - return Color.FromArgb(argb); + return ColorTrans.ToWpfColor(argb); } else { throw new JsonSerializationException($"expect a integer but got {reader.TokenType}"); } } public override void WriteJson(JsonWriter writer, Color value, JsonSerializer serializer) { - writer.WriteValue(value.ToArgb()); + writer.WriteValue(ColorTrans.ToInt(value)); } } diff --git a/HFUTCourseSimulation/MainWindow.xaml b/HFUTCourseSimulation/MainWindow.xaml index 8802353..4d4f8ce 100644 --- a/HFUTCourseSimulation/MainWindow.xaml +++ b/HFUTCourseSimulation/MainWindow.xaml @@ -62,11 +62,29 @@ - + - + + + + + + + + + + + + + + + + + + + @@ -75,6 +93,7 @@ + diff --git a/HFUTCourseSimulation/MainWindow.xaml.cs b/HFUTCourseSimulation/MainWindow.xaml.cs index ff31443..cdefffd 100644 --- a/HFUTCourseSimulation/MainWindow.xaml.cs +++ b/HFUTCourseSimulation/MainWindow.xaml.cs @@ -1,7 +1,9 @@ -using System; +using HFUTCourseSimulation.Dialog; +using Newtonsoft.Json; +using System; using System.Collections.Generic; -using System.Linq; using System.IO; +using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; @@ -13,7 +15,6 @@ using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; -using Newtonsoft.Json; namespace HFUTCourseSimulation { /// @@ -22,20 +23,20 @@ namespace HFUTCourseSimulation { public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); - this.context = Kernel.Context.Instance; UpdateUiLayout(); } #region Context and Assistant Functions - private readonly Kernel.Context context; + private Kernel.UserData.Semester CurrentSemester { get; set; } + private string CurrentFilePath { get; set; } /// /// 返回当前是否有文件被加载。 /// /// private bool IsFileLoaded() { - return !(context.currentSemester is null); + return !(CurrentSemester is null); } /// @@ -43,7 +44,7 @@ namespace HFUTCourseSimulation { /// /// private bool HasAssocFile() { - return !(context.currentFilePath is null); + return !(CurrentFilePath is null); } /// @@ -75,7 +76,7 @@ namespace HFUTCourseSimulation { // Window Caption if (isFileLoaded) { if (hasAssocFile) { - this.Title = $"HFUT课表模拟 - {context.currentFilePath}"; + this.Title = $"HFUT课表模拟 - {CurrentFilePath}"; } else { this.Title = "HFUT课表模拟 - [未命名]"; } @@ -89,7 +90,7 @@ namespace HFUTCourseSimulation { /// private void UpdateDataSource() { if (this.IsFileLoaded()) { - this.DataContext = context.currentSemester; + this.DataContext = CurrentSemester; } else { this.DataContext = null; } @@ -100,8 +101,8 @@ namespace HFUTCourseSimulation { #region Menu Handlers private void uiMenuNew_Click(object sender, RoutedEventArgs e) { - context.currentSemester = new Kernel.UserData.Semester(); - context.currentFilePath = null; + CurrentSemester = new Kernel.UserData.Semester(); + CurrentFilePath = null; UpdateUiLayout(); UpdateDataSource(); } @@ -114,8 +115,8 @@ namespace HFUTCourseSimulation { // Try to read file. try { using (var fs = new StreamReader(filepath, Encoding.UTF8)) { - context.currentSemester = JsonConvert.DeserializeObject(fs.ReadToEnd()); - context.currentFilePath = filepath; + CurrentSemester = JsonConvert.DeserializeObject(fs.ReadToEnd()); + CurrentFilePath = filepath; } } catch (Exception ex) { Util.Win32Dialog.Error(ex.ToString(), "打开文件时出错"); @@ -136,8 +137,8 @@ namespace HFUTCourseSimulation { try { using (var fs = new StreamReader(filepath, Encoding.UTF8)) { var obj = JsonConvert.DeserializeObject(fs.ReadToEnd()); - context.currentSemester = obj.ToLatest(); - context.currentFilePath = filepath; + CurrentSemester = obj.ToLatest(); + CurrentFilePath = filepath; } } catch (Exception ex) { Util.Win32Dialog.Error(ex.ToString(), "打开文件时出错"); @@ -152,16 +153,16 @@ namespace HFUTCourseSimulation { private void uiMenuSave_Click(object sender, RoutedEventArgs e) { // Check whether there is associated file. // If it not, order user select one. - if (context.currentFilePath is null) { + if (CurrentFilePath is null) { var filepath = Util.Win32Dialog.SaveSemester(); if (filepath is null) return; - context.currentFilePath = filepath; + CurrentFilePath = filepath; } // Try to save file try { - using (var fs = new StreamWriter(context.currentFilePath, false, Encoding.UTF8)) { - fs.Write(JsonConvert.SerializeObject(context.currentSemester)); + using (var fs = new StreamWriter(CurrentFilePath, false, Encoding.UTF8)) { + fs.Write(JsonConvert.SerializeObject(CurrentSemester)); } } catch (Exception ex) { Util.Win32Dialog.Error(ex.ToString(), "保存文件时出错"); @@ -178,12 +179,12 @@ namespace HFUTCourseSimulation { if (filepath is null) return; // Update it to current path for following editing. - context.currentFilePath = filepath; + CurrentFilePath = filepath; // Try to save file try { - using (var fs = new StreamWriter(context.currentFilePath, false, Encoding.UTF8)) { - fs.Write(JsonConvert.SerializeObject(context.currentSemester)); + using (var fs = new StreamWriter(CurrentFilePath, false, Encoding.UTF8)) { + fs.Write(JsonConvert.SerializeObject(CurrentSemester)); } } catch (Exception ex) { Util.Win32Dialog.Error(ex.ToString(), "保存文件时出错"); @@ -200,8 +201,8 @@ namespace HFUTCourseSimulation { if (!rv) return; // Clear semester and assoc file - context.currentSemester = null; - context.currentFilePath = null; + CurrentSemester = null; + CurrentFilePath = null; // Update UI and data source UpdateUiLayout(); @@ -260,25 +261,57 @@ namespace HFUTCourseSimulation { #region Main Area Handlers private void uiCoursesList_MouseDoubleClick(object sender, MouseButtonEventArgs e) { - //if (this.uiCoursesList.SelectedIndex < 0) { - // MessageBox.Show("未选择任何项", "错误", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK); - // return; - //} - - //General.CourseCache = General.GeneralSheet.Courses[uiCoursesList.SelectedIndex].Clone(); - //SyncCourseData(); + // It just an alias to edit + uiCtxMenuEditCourse_Click(sender, e); } private void uiCtxMenuNewCourse_Click(object sender, RoutedEventArgs e) { + // Create new item and order user edit it + var item = new Kernel.UserData.Course(); + var dialog = new Dialog.EditCourse(); + dialog.CurrentCourse = item; + dialog.ShowDialog(); + // Then insert or append it into list + var idx = uiCoursesList.SelectedIndex; + if (idx < 0) { + // No selection, append. + CurrentSemester.Courses.Add(item); + } else { + // Has selection, insert + CurrentSemester.Courses.Insert(idx, item); + } } private void uiCtxMenuEditCourse_Click(object sender, RoutedEventArgs e) { + var idx = uiCoursesList.SelectedIndex; + if (idx < 0) return; + var dialog = new Dialog.EditCourse(); + dialog.CurrentCourse = CurrentSemester.Courses[idx]; + dialog.ShowDialog(); } private void uiCtxMenuDeleteCourse_Click(object sender, RoutedEventArgs e) { + // Check whether there is item can be deleted + var idx = uiCoursesList.SelectedIndex; + if (idx < 0) return; + // Order a confirm + var rv = Util.Win32Dialog.Confirm("确认删除选中的课程吗?该操作不可撤销!", "确认删除"); + if (!rv) return; + + // Remove it + CurrentSemester.Courses.RemoveAt(idx); + } + + private void uiCtxMenuClearCourse_Click(object sender, RoutedEventArgs e) { + // Order a confirm + var rv = Util.Win32Dialog.Confirm("确认删除所有课程吗?该操作不可撤销!", "确认清空"); + if (!rv) return; + + // Clear all schedules + CurrentSemester.Courses.Clear(); } #endregion diff --git a/HFUTCourseSimulation/SimulationCore.cs b/HFUTCourseSimulation/SimulationCore.cs index e3b9247..bc9b0be 100644 --- a/HFUTCourseSimulation/SimulationCore.cs +++ b/HFUTCourseSimulation/SimulationCore.cs @@ -37,7 +37,7 @@ namespace HFUTCourseSimulation { if (this.itemDict.Keys.Contains(vectorCache)) { ErrorList.Add($"课程冲突:无法将{item.Name}安排到 {weekItem}周,星期{dayItem},第{indexItem}节。因为此处已被{itemDict[vectorCache].Name}占据"); } else { - itemDict.Add(vectorCache, new SimulationItem() { Name = item.Name, Desc = item.Description, BkColor = Util.ColorTrans.ToWinformColor(item.BkColor) }); + itemDict.Add(vectorCache, new SimulationItem() { Name = item.Name, Desc = item.Description, BkColor = Util.ColorTrans.ToWpfColor(item.BkColor) }); } } } diff --git a/HFUTCourseSimulation/Util/ColorPair.cs b/HFUTCourseSimulation/Util/ColorPair.cs index eab371a..38011f2 100644 --- a/HFUTCourseSimulation/Util/ColorPair.cs +++ b/HFUTCourseSimulation/Util/ColorPair.cs @@ -1,9 +1,9 @@ using System; using System.Collections.Generic; -using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows.Media; namespace HFUTCourseSimulation.Util { @@ -32,28 +32,28 @@ namespace HFUTCourseSimulation.Util { /// Material Design颜色合集 /// public static class MdColors { - private static Color LightText => Color.White; - private static Color DarkText => Color.FromArgb(33, 33, 33); + private static Color LightText => Colors.White; + private static Color DarkText => Color.FromRgb(33, 33, 33); - public static ColorPair Red => new ColorPair(LightText, Color.FromArgb(244, 67, 54)); - public static ColorPair Pink => new ColorPair(LightText, Color.FromArgb(233, 30, 99)); - public static ColorPair Purple => new ColorPair(LightText, Color.FromArgb(156, 39, 176)); - public static ColorPair DeepPurple => new ColorPair(LightText, Color.FromArgb(103, 58, 183)); - public static ColorPair Indigo => new ColorPair(LightText, Color.FromArgb(63, 81, 181)); - public static ColorPair Blue => new ColorPair(LightText, Color.FromArgb(33, 150, 243)); - public static ColorPair LightBlue => new ColorPair(LightText, Color.FromArgb(3, 169, 244)); - public static ColorPair Cyan => new ColorPair(LightText, Color.FromArgb(0, 188, 212)); - public static ColorPair Teal => new ColorPair(LightText, Color.FromArgb(0, 150, 136)); - public static ColorPair Green => new ColorPair(LightText, Color.FromArgb(76, 175, 80)); - public static ColorPair LightGreen => new ColorPair(DarkText, Color.FromArgb(139, 195, 74)); - public static ColorPair Lime => new ColorPair(DarkText, Color.FromArgb(205, 220, 57)); - public static ColorPair Yellow => new ColorPair(DarkText, Color.FromArgb(255, 235, 59)); - public static ColorPair Amber => new ColorPair(DarkText, Color.FromArgb(255, 193, 7)); - public static ColorPair Orange => new ColorPair(DarkText, Color.FromArgb(255, 152, 0)); - public static ColorPair DeepOrange => new ColorPair(LightText, Color.FromArgb(255, 87, 34)); - public static ColorPair Brown => new ColorPair(LightText, Color.FromArgb(121, 85, 72)); - public static ColorPair Grey => new ColorPair(DarkText, Color.FromArgb(158, 158, 158)); - public static ColorPair BlueGrey => new ColorPair(LightText, Color.FromArgb(96, 125, 139)); + public static ColorPair Red => new ColorPair(LightText, Color.FromRgb(244, 67, 54)); + public static ColorPair Pink => new ColorPair(LightText, Color.FromRgb(233, 30, 99)); + public static ColorPair Purple => new ColorPair(LightText, Color.FromRgb(156, 39, 176)); + public static ColorPair DeepPurple => new ColorPair(LightText, Color.FromRgb(103, 58, 183)); + public static ColorPair Indigo => new ColorPair(LightText, Color.FromRgb(63, 81, 181)); + public static ColorPair Blue => new ColorPair(LightText, Color.FromRgb(33, 150, 243)); + public static ColorPair LightBlue => new ColorPair(LightText, Color.FromRgb(3, 169, 244)); + public static ColorPair Cyan => new ColorPair(LightText, Color.FromRgb(0, 188, 212)); + public static ColorPair Teal => new ColorPair(LightText, Color.FromRgb(0, 150, 136)); + public static ColorPair Green => new ColorPair(LightText, Color.FromRgb(76, 175, 80)); + public static ColorPair LightGreen => new ColorPair(DarkText, Color.FromRgb(139, 195, 74)); + public static ColorPair Lime => new ColorPair(DarkText, Color.FromRgb(205, 220, 57)); + public static ColorPair Yellow => new ColorPair(DarkText, Color.FromRgb(255, 235, 59)); + public static ColorPair Amber => new ColorPair(DarkText, Color.FromRgb(255, 193, 7)); + public static ColorPair Orange => new ColorPair(DarkText, Color.FromRgb(255, 152, 0)); + public static ColorPair DeepOrange => new ColorPair(LightText, Color.FromRgb(255, 87, 34)); + public static ColorPair Brown => new ColorPair(LightText, Color.FromRgb(121, 85, 72)); + public static ColorPair Grey => new ColorPair(DarkText, Color.FromRgb(158, 158, 158)); + public static ColorPair BlueGrey => new ColorPair(LightText, Color.FromRgb(96, 125, 139)); } } diff --git a/HFUTCourseSimulation/Util/ColorTrans.cs b/HFUTCourseSimulation/Util/ColorTrans.cs index 4ade058..06a7210 100644 --- a/HFUTCourseSimulation/Util/ColorTrans.cs +++ b/HFUTCourseSimulation/Util/ColorTrans.cs @@ -4,11 +4,8 @@ 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; +using WpfColor = System.Windows.Media.Color; +using WinformColor = System.Drawing.Color; namespace HFUTCourseSimulation.Util { @@ -16,32 +13,32 @@ namespace HFUTCourseSimulation.Util { #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(int argb) { + return WinformColor.FromArgb(argb); } 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 WpfColor ToWpfColor(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 WpfColor.FromArgb((byte)a, (byte)r, (byte)g, (byte)b); + } + + public static WpfColor ToWpfColor(WinformColor c) { + return WpfColor.FromArgb(c.A, c.R, c.G, c.B); } public static int ToInt(WinformColor c) { + return c.ToArgb(); + } + + public static int ToInt(WpfColor c) { uint argb = 0; argb |= c.A; argb <<= 8; argb |= c.R; argb <<= 8; @@ -52,17 +49,5 @@ namespace HFUTCourseSimulation.Util { #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 - } }