Skip to content

Commit

Permalink
Merge pull request stakira#847 from maiko3tattun/0917_PianorollKeyboa…
Browse files Browse the repository at this point in the history
…rdColor

Allow to change keyboard color in PianoRoll Window
  • Loading branch information
stakira authored Sep 18, 2023
2 parents 418876b + 5d83773 commit 05076e4
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 57 deletions.
2 changes: 2 additions & 0 deletions OpenUtau/Colors/Brushes.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@
Color="#90CAF9" Opacity="0.5"/>
<SolidColorBrush x:Key="SelectedTrackAccentDarkBrush"
Color="#1E88E5" />
<SolidColorBrush x:Key="SelectedTrackCenterKeyBrush"
Color="#C8E5FC" />

<LinearGradientBrush x:Key="WhiteKeyBrush" StartPoint="0%,50%" EndPoint="100%,50%">
<LinearGradientBrush.GradientStops>
Expand Down
1 change: 1 addition & 0 deletions OpenUtau/Controls/TrackBackground.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public override void Render(DrawingContext context) {
bool isAltTrack = IsAltTrack(track) ^ (ThemeManager.IsDarkMode && !IsKeyboard);
bool isCenterKey = IsKeyboard && IsCenterKey(track);
var brush = isCenterKey ? ThemeManager.CenterKeyBrush
: IsKeyboard ? (isAltTrack ? ThemeManager.BlackKeyBrush : ThemeManager.WhiteKeyBrush)
: isAltTrack ? Foreground : Background;
context.DrawRectangle(
brush,
Expand Down
172 changes: 119 additions & 53 deletions OpenUtau/ThemeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Avalonia.Media;
using Avalonia.Styling;
using OpenUtau.App.Controls;
using OpenUtau.Core.Util;
using ReactiveUI;

namespace OpenUtau.App {
Expand Down Expand Up @@ -51,24 +52,24 @@ class ThemeManager {
public static IBrush ExpActiveNameBrush = Brushes.White;

public static List<TrackColor> TrackColors = new List<TrackColor>(){
new TrackColor("Pink", "#F06292", "#E91E63", "#F48FB1"),
new TrackColor("Red", "#EF5350", "#E53935", "#E57373"),
new TrackColor("Orange", "#FF8A65", "#FF5722", "#FFAB91"),
new TrackColor("Yellow", "#FBC02D", "#F9A825", "#FDD835"),
new TrackColor("Light Green", "#CDDC39", "#AFB42B", "#DCE775"),
new TrackColor("Green", "#66BB6A", "#43A047", "#A5D6A7"),
new TrackColor("Light Blue", "#4FC3F7", "#03A9F4", "#81D4FA"),
new TrackColor("Blue", "#4EA6EA", "#1E88E5", "#90CAF9"),
new TrackColor("Purple", "#BA68C8", "#9C27B0", "#CE93D8"),
new TrackColor("Pink2", "#E91E63", "#C2185B", "#F06292"),
new TrackColor("Red2", "#D32F2F", "#B71C1C", "#EF5350"),
new TrackColor("Orange2", "#FF5722", "#E64A19", "#FF8A65"),
new TrackColor("Yellow2", "#FF8F00", "#FF6F00", "#FFB300"),
new TrackColor("Light Green2", "#AFB42B", "#827717", "#CDDC39"),
new TrackColor("Green2", "#2E7D32", "#1B5E20", "#4CAF50"),
new TrackColor("Light Blue2", "#1976D2", "#0D47A1", "#2196F3"),
new TrackColor("Blue2", "#3949AB", "#283593", "#5C6BC0"),
new TrackColor("Purple2", "#7B1FA2", "#4A148C", "#9C27B0"),
new TrackColor("Pink", "#F06292", "#EC407A", "#F48FB1", "#FAC7D8"),
new TrackColor("Red", "#EF5350", "#E53935", "#E57373", "#F2B9B9"),
new TrackColor("Orange", "#FF8A65", "#FF7043", "#FFAB91", "#FFD5C8"),
new TrackColor("Yellow", "#FBC02D", "#F9A825", "#FDD835", "#FEF1B6"),
new TrackColor("Light Green", "#CDDC39", "#C0CA33", "#DCE775", "#F2F7CE"),
new TrackColor("Green", "#66BB6A", "#43A047", "#A5D6A7", "#D2EBD3"),
new TrackColor("Light Blue", "#4FC3F7", "#29B6F6", "#81D4FA", "#C0EAFD"),
new TrackColor("Blue", "#4EA6EA", "#1E88E5", "#90CAF9", "#C8E5FC"),
new TrackColor("Purple", "#BA68C8", "#AB47BC", "#CE93D8", "#E7C9EC"),
new TrackColor("Pink2", "#E91E63", "#C2185B", "#F06292", "#F8B1C9"),
new TrackColor("Red2", "#D32F2F", "#B71C1C", "#EF5350", "#F7A9A8"),
new TrackColor("Orange2", "#FF5722", "#E64A19", "#FF7043", "#FFB8A1"),
new TrackColor("Yellow2", "#FF8F00", "#FF7F00", "#FFB300", "#FFE097"),
new TrackColor("Light Green2", "#AFB42B", "#9E9D24", "#CDDC39", "#E6EE9C"),
new TrackColor("Green2", "#2E7D32", "#1B5E20", "#43A047", "#A1D0A3"),
new TrackColor("Light Blue2", "#1976D2", "#0D47A1", "#2196F3", "#90CBF9"),
new TrackColor("Blue2", "#3949AB", "#283593", "#5C6BC0", "#AEB5E0"),
new TrackColor("Purple2", "#7B1FA2", "#4A148C", "#AB47BC", "#D5A3DE"),
};

public static void LoadTheme() {
Expand Down Expand Up @@ -135,55 +136,118 @@ public static void LoadTheme() {
FinalPitchBrush = (IBrush)outVar!;
FinalPitchPen = new Pen(FinalPitchBrush, 1);
}
if (resDict.TryGetResource("WhiteKeyBrush", themeVariant, out outVar)) {
WhiteKeyBrush = (IBrush)outVar!;
}
if (resDict.TryGetResource("WhiteKeyNameBrush", themeVariant, out outVar)) {
WhiteKeyNameBrush = (IBrush)outVar!;
}
if (resDict.TryGetResource("CenterKeyBrush", themeVariant, out outVar)) {
CenterKeyBrush = (IBrush)outVar!;
}
if (resDict.TryGetResource("CenterKeyNameBrush", themeVariant, out outVar)) {
CenterKeyNameBrush = (IBrush)outVar!;
}
if (resDict.TryGetResource("BlackKeyBrush", themeVariant, out outVar)) {
BlackKeyBrush = (IBrush)outVar!;
}
if (resDict.TryGetResource("BlackKeyNameBrush", themeVariant, out outVar)) {
BlackKeyNameBrush = (IBrush)outVar!;
}
if (!IsDarkMode) {
ExpBrush = WhiteKeyBrush;
ExpNameBrush = WhiteKeyNameBrush;
ExpActiveBrush = BlackKeyBrush;
ExpActiveNameBrush = BlackKeyNameBrush;
ExpShadowBrush = CenterKeyBrush;
ExpShadowNameBrush = CenterKeyNameBrush;
} else {
ExpBrush = BlackKeyBrush;
ExpNameBrush = BlackKeyNameBrush;
ExpActiveBrush = WhiteKeyBrush;
ExpActiveNameBrush = WhiteKeyNameBrush;
ExpShadowBrush = CenterKeyBrush;
ExpShadowNameBrush = CenterKeyNameBrush;
}
SetKeyboardBrush();
TextLayoutCache.Clear();
MessageBus.Current.SendMessage(new ThemeChangedEvent());
}

public static void ChangeTrackColor(string color) {
public static void ChangePianorollColor(string color) {
if (Application.Current == null) {
return;
}
try {
IResourceDictionary resDict = Application.Current.Resources;
TrackColor tcolor = GetTrackColor(color);

resDict["SelectedTrackAccentBrush"] = tcolor.AccentColor;
resDict["SelectedTrackAccentLightBrush"] = tcolor.AccentColorLight;
resDict["SelectedTrackAccentLightBrushSemi"] = tcolor.AccentColorLightSemi;
resDict["SelectedTrackAccentDarkBrush"] = tcolor.AccentColorDark;
resDict["SelectedTrackCenterKeyBrush"] = tcolor.AccentColorCenterKey;

SetKeyboardBrush();
} catch { }
MessageBus.Current.SendMessage(new ThemeChangedEvent());
}
private static void SetKeyboardBrush() {
if (Application.Current == null) {
return;
}
IResourceDictionary resDict = Application.Current.Resources;
object? outVar;
var themeVariant = ThemeVariant.Default;

if (Preferences.Default.UseTrackColor) {
if (IsDarkMode) {
if (resDict.TryGetResource("SelectedTrackAccentBrush", themeVariant, out outVar)) {
CenterKeyNameBrush = (IBrush)outVar!;
WhiteKeyBrush = (IBrush)outVar!;
}
if (resDict.TryGetResource("SelectedTrackCenterKeyBrush", themeVariant, out outVar)) {
CenterKeyBrush = (IBrush)outVar!;
}
if (resDict.TryGetResource("WhiteKeyNameBrush", themeVariant, out outVar)) {
WhiteKeyNameBrush = (IBrush)outVar!;
}
if (resDict.TryGetResource("BlackKeyBrush", themeVariant, out outVar)) {
BlackKeyBrush = (IBrush)outVar!;
}
if (resDict.TryGetResource("BlackKeyNameBrush", themeVariant, out outVar)) {
BlackKeyNameBrush = (IBrush)outVar!;
}
ExpBrush = BlackKeyBrush;
ExpNameBrush = BlackKeyNameBrush;
ExpActiveBrush = WhiteKeyBrush;
ExpActiveNameBrush = WhiteKeyNameBrush;
ExpShadowBrush = CenterKeyBrush;
ExpShadowNameBrush = CenterKeyNameBrush;
} else { // LightMode
if (resDict.TryGetResource("SelectedTrackAccentBrush", themeVariant, out outVar)) {
CenterKeyNameBrush = (IBrush)outVar!;
WhiteKeyNameBrush = (IBrush)outVar!;
BlackKeyBrush = (IBrush)outVar!;
}
if (resDict.TryGetResource("SelectedTrackCenterKeyBrush", themeVariant, out outVar)) {
CenterKeyBrush = (IBrush)outVar!;
}
if (resDict.TryGetResource("WhiteKeyBrush", themeVariant, out outVar)) {
WhiteKeyBrush = (IBrush)outVar!;
}
if (resDict.TryGetResource("BlackKeyNameBrush", themeVariant, out outVar)) {
BlackKeyNameBrush = (IBrush)outVar!;
}
ExpBrush = WhiteKeyBrush;
ExpNameBrush = WhiteKeyNameBrush;
ExpActiveBrush = BlackKeyBrush;
ExpActiveNameBrush = BlackKeyNameBrush;
ExpShadowBrush = CenterKeyBrush;
ExpShadowNameBrush = CenterKeyNameBrush;
}
} else { // DefColor
if (resDict.TryGetResource("WhiteKeyBrush", themeVariant, out outVar)) {
WhiteKeyBrush = (IBrush)outVar!;
}
if (resDict.TryGetResource("WhiteKeyNameBrush", themeVariant, out outVar)) {
WhiteKeyNameBrush = (IBrush)outVar!;
}
if (resDict.TryGetResource("CenterKeyBrush", themeVariant, out outVar)) {
CenterKeyBrush = (IBrush)outVar!;
}
if (resDict.TryGetResource("CenterKeyNameBrush", themeVariant, out outVar)) {
CenterKeyNameBrush = (IBrush)outVar!;
}
if (resDict.TryGetResource("BlackKeyBrush", themeVariant, out outVar)) {
BlackKeyBrush = (IBrush)outVar!;
}
if (resDict.TryGetResource("BlackKeyNameBrush", themeVariant, out outVar)) {
BlackKeyNameBrush = (IBrush)outVar!;
}
if (!IsDarkMode) {
ExpBrush = WhiteKeyBrush;
ExpNameBrush = WhiteKeyNameBrush;
ExpActiveBrush = BlackKeyBrush;
ExpActiveNameBrush = BlackKeyNameBrush;
ExpShadowBrush = CenterKeyBrush;
ExpShadowNameBrush = CenterKeyNameBrush;
} else {
ExpBrush = BlackKeyBrush;
ExpNameBrush = BlackKeyNameBrush;
ExpActiveBrush = WhiteKeyBrush;
ExpActiveNameBrush = WhiteKeyNameBrush;
ExpShadowBrush = CenterKeyBrush;
ExpShadowNameBrush = CenterKeyNameBrush;
}
}
}

public static string GetString(string key) {
Expand Down Expand Up @@ -211,14 +275,16 @@ public class TrackColor {
public SolidColorBrush AccentColorDark { get; set; } // Pressed
public SolidColorBrush AccentColorLight { get; set; } // PointerOver
public SolidColorBrush AccentColorLightSemi { get; set; } // BackGround
public SolidColorBrush AccentColorCenterKey { get; set; } // Keyboard

public TrackColor(string name, string accentColor, string darkColor, string lightColor) {
public TrackColor(string name, string accentColor, string darkColor, string lightColor, string centerKey) {
Name = name;
AccentColor = SolidColorBrush.Parse(accentColor);
AccentColorDark = SolidColorBrush.Parse(darkColor);
AccentColorLight = SolidColorBrush.Parse(lightColor);
AccentColorLightSemi = SolidColorBrush.Parse(lightColor);
AccentColorLightSemi.Opacity = 0.5;
AccentColorCenterKey = SolidColorBrush.Parse(centerKey);
}
}
}
4 changes: 2 additions & 2 deletions OpenUtau/ViewModels/NotesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -461,14 +461,14 @@ private void LoadWindowTitle(UPart? part, UProject? project) {
private void LoadTrackColor(UPart? part, UProject? project) {
if (part == null || project == null) {
TrackAccentColor = ThemeManager.GetTrackColor("Blue").AccentColor;
ThemeManager.ChangeTrackColor("Blue");
ThemeManager.ChangePianorollColor("Blue");
return;
}
TrackAccentColor = ThemeManager.GetTrackColor(project.tracks[part.trackNo].TrackColor).AccentColor;
string name = Preferences.Default.UseTrackColor
? project.tracks[part.trackNo].TrackColor
: "Blue";
ThemeManager.ChangeTrackColor(name);
ThemeManager.ChangePianorollColor(name);
}

private void UnloadPart() {
Expand Down
2 changes: 0 additions & 2 deletions OpenUtau/Views/PianoRollWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@
LargeChange="{Binding ViewportTracks}"
SmallChange="{Binding SmallChangeY}" PointerWheelChanged="VScrollPointerWheelChanged"/>
<c:TrackBackground Grid.Column="0" Grid.Row="2" IsPianoRoll="True" IsKeyboard="True"
Foreground="{DynamicResource BlackKeyBrush}"
Background="{DynamicResource WhiteKeyBrush}"
DataContext="{Binding NotesViewModel}"
TrackHeight="{Binding TrackHeight}"
TrackOffset="{Binding TrackOffset}"
Expand Down

0 comments on commit 05076e4

Please sign in to comment.