-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
30969ba
commit d2e7653
Showing
10 changed files
with
419 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
OngekiFumenEditor/Kernel/SettingPages/FumenVisualEditor/Models/ColorPropertyWrapper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using Caliburn.Micro; | ||
using OngekiFumenEditor.Utils; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows.Media; | ||
|
||
namespace OngekiFumenEditor.Kernel.SettingPages.FumenVisualEditor.Models | ||
{ | ||
public class ColorPropertyWrapper : PropertyChangedBase | ||
{ | ||
private readonly PropertyInfo propertyInfo; | ||
private readonly object owner; | ||
private SolidColorBrush cachedColorBrush; | ||
private SolidColorBrush cachedReverseColorBrush; | ||
|
||
public ColorPropertyWrapper(PropertyInfo propertyInfo, object owner) | ||
{ | ||
this.propertyInfo = propertyInfo; | ||
this.owner = owner; | ||
|
||
RefreshBrush(); | ||
} | ||
|
||
private void RefreshBrush() | ||
{ | ||
var color = Color; | ||
cachedColorBrush = new SolidColorBrush(color.ToMediaColor()); | ||
cachedReverseColorBrush = new SolidColorBrush(System.Windows.Media.Color.FromArgb(color.A, (byte)(255 - color.R), (byte)(255 - color.G), (byte)(255 - color.B))); | ||
|
||
NotifyOfPropertyChange(nameof(Brush)); | ||
NotifyOfPropertyChange(nameof(ReverseBrush)); | ||
} | ||
|
||
public System.Drawing.Color Color | ||
{ | ||
get => (System.Drawing.Color)propertyInfo.GetValue(owner, null); | ||
set | ||
{ | ||
propertyInfo.SetValue(owner, value, null); | ||
RefreshBrush(); | ||
|
||
NotifyOfPropertyChange(nameof(Color)); | ||
NotifyOfPropertyChange(nameof(ColorString)); | ||
} | ||
} | ||
|
||
public SolidColorBrush Brush => cachedColorBrush; | ||
public SolidColorBrush ReverseBrush => cachedReverseColorBrush; | ||
|
||
public string Name => propertyInfo.Name; | ||
|
||
public string ColorString | ||
{ | ||
get | ||
{ | ||
var r = Color; | ||
return $"{r.R}, {r.G}, {r.B}, {r.A}"; | ||
} | ||
set | ||
{ | ||
var split = value.Split(','); | ||
var r = int.Parse(split[0].Trim()); | ||
var g = int.Parse(split[1].Trim()); | ||
var b = int.Parse(split[2].Trim()); | ||
var a = split.Length > 3 ? int.Parse(split[3]) : 255; | ||
|
||
Color = System.Drawing.Color.FromArgb(a, r, g, b); | ||
} | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...ernel/SettingPages/FumenVisualEditor/ViewModels/FumenVisualEditorColorSettingViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using Caliburn.Micro; | ||
using Gemini.Modules.Settings; | ||
using OngekiFumenEditor.Kernel.SettingPages.FumenVisualEditor.Models; | ||
using OngekiFumenEditor.Properties; | ||
using OngekiFumenEditor.UI.Dialogs; | ||
using OngekiFumenEditor.Utils; | ||
using System.ComponentModel.Composition; | ||
using System.Linq; | ||
|
||
namespace OngekiFumenEditor.Kernel.SettingPages.FumenVisualEditor.ViewModels | ||
{ | ||
[Export(typeof(ISettingsEditor))] | ||
[PartCreationPolicy(CreationPolicy.Shared)] | ||
public class FumenVisualEditorColorSettingViewModel : PropertyChangedBase, ISettingsEditor | ||
{ | ||
public EditorGlobalSetting Setting => EditorGlobalSetting.Default; | ||
|
||
public FumenVisualEditorColorSettingViewModel() | ||
{ | ||
ColorsProperties = typeof(EditorGlobalSetting) | ||
.GetProperties() | ||
.Where(x => x.Name.StartsWith("Color") && x.PropertyType == typeof(System.Drawing.Color)) | ||
.Select(x => new ColorPropertyWrapper(x, EditorGlobalSetting.Default)) | ||
.ToArray(); | ||
} | ||
|
||
public string SettingsPagePath => Resources.TabDocument + "\\" + Resources.TabEditor; | ||
|
||
public string SettingsPageName => "渲染色彩管理"; | ||
|
||
public ColorPropertyWrapper[] ColorsProperties { get; private set; } | ||
|
||
public void ApplyChanges() | ||
{ | ||
EditorGlobalSetting.Default.Save(); | ||
} | ||
|
||
public void OnSelectColor(ActionExecutionContext context) | ||
{ | ||
if (context.Source.DataContext is not ColorPropertyWrapper colorProperty) | ||
return; | ||
|
||
var dialog = new CommonColorPicker(() => | ||
{ | ||
return colorProperty.Color.ToMediaColor(); | ||
}, color => | ||
{ | ||
colorProperty.Color = color.ToDrawingColor(); | ||
}, $"设置新的 {colorProperty.Name} 颜色"); | ||
dialog.Show(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...Editor/Kernel/SettingPages/FumenVisualEditor/Views/FumenVisualEditorColorSettingView.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<UserControl | ||
x:Class="OngekiFumenEditor.Kernel.SettingPages.FumenVisualEditor.Views.FumenVisualEditorColorSettingView" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:cal="http://caliburnmicro.com" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:markup="clr-namespace:OngekiFumenEditor.UI.Markup" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:res="clr-namespace:OngekiFumenEditor.Properties" | ||
xmlns:valueconverters="clr-namespace:OngekiFumenEditor.Kernel.SettingPages.FumenVisualEditor.ValueConverters" | ||
xmlns:vm="clr-namespace:OngekiFumenEditor.Kernel.SettingPages.FumenVisualEditor.ViewModels" | ||
d:Background="White" | ||
d:DataContext="{d:DesignInstance IsDesignTimeCreatable=True, | ||
Type=vm:FumenVisualEditorColorSettingViewModel}" | ||
d:DesignWidth="800" | ||
mc:Ignorable="d"> | ||
<ItemsControl | ||
ItemsSource="{Binding ColorsProperties}" | ||
ScrollViewer.CanContentScroll="True" | ||
VirtualizingPanel.IsVirtualizing="True" | ||
VirtualizingPanel.VirtualizationMode="Recycling"> | ||
<ItemsControl.ItemTemplate> | ||
<DataTemplate> | ||
<Grid Margin="5"> | ||
<Label VerticalAlignment="Center" Content="{Binding Name}" /> | ||
<StackPanel | ||
HorizontalAlignment="Right" | ||
VerticalAlignment="Center" | ||
Orientation="Horizontal"> | ||
<Border | ||
Width="25" | ||
Margin="5,0" | ||
Background="{Binding Brush}" | ||
CornerRadius="7" /> | ||
<Label VerticalAlignment="Center" Content="{Binding ColorString}" /> | ||
<Button | ||
Margin="5,0" | ||
Padding="10,2" | ||
cal:Message.Attach="OnSelectColor($executionContext)" | ||
Content="选择" /> | ||
</StackPanel> | ||
</Grid> | ||
</DataTemplate> | ||
</ItemsControl.ItemTemplate> | ||
</ItemsControl> | ||
</UserControl> |
15 changes: 15 additions & 0 deletions
15
...tor/Kernel/SettingPages/FumenVisualEditor/Views/FumenVisualEditorColorSettingView.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System.Windows.Controls; | ||
|
||
namespace OngekiFumenEditor.Kernel.SettingPages.FumenVisualEditor.Views | ||
{ | ||
/// <summary> | ||
/// FumenVisualEditorGlobalSettingView.xaml 的交互逻辑 | ||
/// </summary> | ||
public partial class FumenVisualEditorColorSettingView : UserControl | ||
{ | ||
public FumenVisualEditorColorSettingView() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.