Skip to content

Commit

Permalink
upgrade to avalonia 11 and fix compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
stakira committed Jun 4, 2023
1 parent bda13a6 commit d60f403
Show file tree
Hide file tree
Showing 49 changed files with 387 additions and 434 deletions.
2 changes: 1 addition & 1 deletion OpenUtau.Test/OpenUtau.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.2.0">
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
4 changes: 2 additions & 2 deletions OpenUtau/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
<ResourceInclude Source="/Strings/Strings.zh-TW.axaml"/>
<ResourceInclude Source="/Strings/Strings.th-TH.axaml"/>
<ResourceInclude Source="/Strings/Strings.axaml"/>
<ResourceInclude Source="/Colors/LightTheme.axaml"/>
<ResourceInclude Source="/Colors/DarkTheme.axaml"/>
<ResourceInclude Source="/Colors/LightTheme.axaml"/>
<ResourceInclude Source="/Colors/Brushes.axaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
<Application.Styles>
<StyleInclude Source="avares://Avalonia.Themes.Fluent/FluentLight.xaml"/>
<FluentTheme />
<StyleInclude Source="avares://Avalonia.Controls.DataGrid/Themes/Fluent.xaml"/>
<StyleInclude Source="/Styles/Styles.axaml"/>
</Application.Styles>
Expand Down
48 changes: 24 additions & 24 deletions OpenUtau/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using Avalonia.Markup.Xaml.MarkupExtensions;
using Avalonia.Markup.Xaml.Styling;
using OpenUtau.App.Views;
using OpenUtau.Classic;
using OpenUtau.Core;
Expand Down Expand Up @@ -38,16 +38,16 @@ public void InitializeCulture() {
Log.Information("Initializing culture.");
string sysLang = CultureInfo.InstalledUICulture.Name;
string prefLang = Core.Util.Preferences.Default.Language;
var languages = GetLanguages();
if (languages.TryGetValue(prefLang, out var res)) {
SetLanguage(res);
} else if (languages.TryGetValue(sysLang, out res)) {
SetLanguage(res);
Core.Util.Preferences.Default.Language = sysLang;
Core.Util.Preferences.Save();
} else {
SetLanguage(languages["en-US"]);
}
//var languages = GetLanguages();
//if (languages.TryGetValue(prefLang, out var res)) {
// SetLanguage(res);
//} else if (languages.TryGetValue(sysLang, out res)) {
// SetLanguage(res);
// Core.Util.Preferences.Default.Language = sysLang;
// Core.Util.Preferences.Save();
//} else {
// SetLanguage(languages["en-US"]);
//}

// Force using InvariantCulture to prevent issues caused by culture dependent string conversion, especially for floating point numbers.
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
Expand Down Expand Up @@ -94,19 +94,19 @@ static void InitializeTheme() {
}

public static void SetTheme() {
var light = Current.Resources.MergedDictionaries
.Select(res => (ResourceInclude)res)
.FirstOrDefault(d => d.Source!.OriginalString.Contains("LightTheme"));
var dark = Current.Resources.MergedDictionaries
.Select(res => (ResourceInclude)res)
.FirstOrDefault(d => d.Source!.OriginalString.Contains("DarkTheme"));
if (Core.Util.Preferences.Default.Theme == 0) {
Current.Resources.MergedDictionaries.Remove(light);
Current.Resources.MergedDictionaries.Add(light);
} else {
Current.Resources.MergedDictionaries.Remove(dark);
Current.Resources.MergedDictionaries.Add(dark);
}
//var light = Current.Resources.MergedDictionaries
// .Select(res => (ResourceInclude)res)
// .FirstOrDefault(d => d.Source!.OriginalString.Contains("LightTheme"));
//var dark = Current.Resources.MergedDictionaries
// .Select(res => (ResourceInclude)res)
// .FirstOrDefault(d => d.Source!.OriginalString.Contains("DarkTheme"));
//if (Core.Util.Preferences.Default.Theme == 0) {
// Current.Resources.MergedDictionaries.Remove(light);
// Current.Resources.MergedDictionaries.Add(light);
//} else {
// Current.Resources.MergedDictionaries.Remove(dark);
// Current.Resources.MergedDictionaries.Add(dark);
//}
ThemeManager.LoadTheme();
}

Expand Down
8 changes: 1 addition & 7 deletions OpenUtau/Controls/ExpSelector.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Grid Height="22" Width="60" Background="{Binding Background}" PointerPressed="TextBlockPointerPressed">
<ComboBox VerticalAlignment="Center" HorizontalAlignment="Left" Height="22"
Focusable="False" Foreground="{Binding TagBrush}" Background="Transparent" Width="20"
SelectedItem="{Binding Descriptor}" Items="{Binding Descriptors}" SelectedIndex="{Binding SelectedIndex}">
SelectedItem="{Binding Descriptor}" ItemsSource="{Binding Descriptors}" SelectedIndex="{Binding SelectedIndex}">
<ComboBox.Styles>
<Style Selector="ComboBox">
<Setter Property="Padding" Value="{DynamicResource ComboBoxPadding}" />
Expand Down Expand Up @@ -77,12 +77,6 @@
CornerRadius="{DynamicResource OverlayCornerRadius}">
<ScrollViewer HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}">
<ItemsPresenter Name="PART_ItemsPresenter"
Items="{TemplateBinding Items}"
Margin="{DynamicResource ComboBoxDropdownContentMargin}"
ItemsPanel="{TemplateBinding ItemsPanel}"
ItemTemplate="{TemplateBinding ItemTemplate}"
VirtualizationMode="{TemplateBinding VirtualizationMode}" />
</ScrollViewer>
</Border>
</Popup>
Expand Down
2 changes: 1 addition & 1 deletion OpenUtau/Controls/ExpSelector.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public ExpSelector() {
((ExpSelectorViewModel)DataContext!).Index = Index;
}

protected override void OnPropertyChanged<T>(AvaloniaPropertyChangedEventArgs<T> change) {
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) {
base.OnPropertyChanged(change);
if (change.Property == IndexProperty) {
((ExpSelectorViewModel)DataContext!).Index = Index;
Expand Down
21 changes: 9 additions & 12 deletions OpenUtau/Controls/ExpressionCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace OpenUtau.App.Controls {
public enum ExpDisMode { Hidden, Visible, Shadow };

class ExpressionCanvas : Canvas {
class ExpressionCanvas : Control {
public static readonly DirectProperty<ExpressionCanvas, double> TickWidthProperty =
AvaloniaProperty.RegisterDirect<ExpressionCanvas, double>(
nameof(TickWidth),
Expand Down Expand Up @@ -75,11 +75,8 @@ public ExpressionCanvas() {
});
}

protected override void OnPropertyChanged<T>(AvaloniaPropertyChangedEventArgs<T> change) {
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) {
base.OnPropertyChanged(change);
if (!change.IsEffectiveValueChange) {
return;
}
InvalidateVisual();
}

Expand Down Expand Up @@ -135,7 +132,7 @@ public override void Render(DrawingContext context) {
double y2 = defaultHeight - Bounds.Height * (value2 - descriptor.defaultValue) / (descriptor.max - descriptor.min);
var pen = value1 == descriptor.defaultValue && value2 == descriptor.defaultValue ? lPen : lPen2;
context.DrawLine(pen, new Point(x1, y1), new Point(x2, y2));
//using (var state = context.PushPreTransform(Matrix.CreateTranslation(x1, y1))) {
//using (var state = context.PushTransform(Matrix.CreateTranslation(x1, y1))) {
// context.DrawGeometry(brush, null, pointGeometry);
//}
index++;
Expand Down Expand Up @@ -166,13 +163,13 @@ public override void Render(DrawingContext context) {
double zeroHeight = Math.Round(Bounds.Height - Bounds.Height * (0f - descriptor.min) / (descriptor.max - descriptor.min));
context.DrawLine(vPen, new Point(x1 + 0.5, zeroHeight + 0.5), new Point(x1 + 0.5, valueHeight + 3));
context.DrawLine(hPen, new Point(x1 + 3, valueHeight), new Point(Math.Max(x1 + 3, x2 - 3), valueHeight));
using (var state = context.PushPreTransform(Matrix.CreateTranslation(x1 + 0.5, valueHeight))) {
using (var state = context.PushTransform(Matrix.CreateTranslation(x1 + 0.5, valueHeight))) {
context.DrawGeometry(overriden ? brush : ThemeManager.BackgroundBrush, vPen, pointGeometry);
}
} else if (descriptor.type == UExpressionType.Options) {
for (int i = 0; i < descriptor.options.Length; ++i) {
double y = optionHeight * (descriptor.options.Length - 1 - i + 0.5);
using (var state = context.PushPreTransform(Matrix.CreateTranslation(x1 + 4.5, y))) {
using (var state = context.PushTransform(Matrix.CreateTranslation(x1 + 4.5, y))) {
if ((int)value == i) {
context.DrawGeometry(brush, null, pointGeometry);
context.DrawGeometry(null, hPen, circleGeometry);
Expand All @@ -190,15 +187,15 @@ public override void Render(DrawingContext context) {
option = "\"\"";
}
var textLayout = TextLayoutCache.Get(option, ThemeManager.ForegroundBrush, 12);
double y = optionHeight * (descriptor.options.Length - 1 - i + 0.5) - textLayout.Size.Height * 0.5;
double y = optionHeight * (descriptor.options.Length - 1 - i + 0.5) - textLayout.Height * 0.5;
y = Math.Round(y);
var size = new Size(textLayout.Size.Width + 8, textLayout.Size.Height + 2);
using (var state = context.PushPreTransform(Matrix.CreateTranslation(12, y))) {
var size = new Size(textLayout.Width + 8, textLayout.Height + 2);
using (var state = context.PushTransform(Matrix.CreateTranslation(12, y))) {
context.DrawRectangle(
ThemeManager.BackgroundBrush,
ThemeManager.NeutralAccentPenSemi,
new Rect(new Point(-4, -0.5), size), 4, 4);
textLayout.Draw(context);
textLayout.Draw(context, new Point());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion OpenUtau/Controls/LyricBox.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
BorderThickness="0" Background="Transparent"
Margin="{DynamicResource AutoCompleteListPadding}"
Items="{Binding Suggestions}" SelectedItem="{Binding SelectedSuggestion}"
ItemsSource="{Binding Suggestions}" SelectedItem="{Binding SelectedSuggestion}"
KeyDown="ListBox_KeyDown">
<ListBox.Styles>
<Style Selector="ListBoxItem">
Expand Down
2 changes: 1 addition & 1 deletion OpenUtau/Controls/LyricBox.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public void EndEdit(bool commit = false) {
viewModel.NoteOrPhoneme = null;
viewModel.IsVisible = false;
viewModel.Text = string.Empty;
KeyboardDevice.Instance.SetFocusedElement(null, NavigationMethod.Unspecified, KeyModifiers.None);
//KeyboardDevice.Instance.SetFocusedElement(null, NavigationMethod.Unspecified, KeyModifiers.None);
}
}
}
29 changes: 13 additions & 16 deletions OpenUtau/Controls/NotesCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using ReactiveUI;

namespace OpenUtau.App.Controls {
class NotesCanvas : Canvas {
class NotesCanvas : Control {
public static readonly DirectProperty<NotesCanvas, double> TickWidthProperty =
AvaloniaProperty.RegisterDirect<NotesCanvas, double>(
nameof(TickWidth),
Expand Down Expand Up @@ -134,11 +134,8 @@ void RefreshGhostNotes() {
.ToList();
}

protected override void OnPropertyChanged<T>(AvaloniaPropertyChangedEventArgs<T> change) {
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) {
base.OnPropertyChanged(change);
if (!change.IsEffectiveValueChange) {
return;
}
InvalidateVisual();
}

Expand Down Expand Up @@ -210,17 +207,17 @@ private void RenderNoteBody(UNote note, NotesViewModel viewModel, DrawingContext
}
string displayLyric = note.lyric;
var textLayout = TextLayoutCache.Get(displayLyric, Brushes.White, 12);
if (textLayout.Size.Width + 5 > size.Width) {
if (textLayout.Width + 5 > size.Width) {
displayLyric = displayLyric[0] + "..";
textLayout = TextLayoutCache.Get(displayLyric, Brushes.White, 12);
if (textLayout.Size.Width + 5 > size.Width) {
if (textLayout.Width + 5 > size.Width) {
return;
}
}
Point textPosition = leftTop.WithX(leftTop.X + 5)
.WithY(Math.Round(leftTop.Y + (size.Height - textLayout.Size.Height) / 2));
using (var state = context.PushPreTransform(Matrix.CreateTranslation(textPosition.X, textPosition.Y))) {
textLayout.Draw(context);
.WithY(Math.Round(leftTop.Y + (size.Height - textLayout.Height) / 2));
using (var state = context.PushTransform(Matrix.CreateTranslation(textPosition.X, textPosition.Y))) {
textLayout.Draw(context, new Point());
}
}

Expand Down Expand Up @@ -256,7 +253,7 @@ private void RenderPitchBend(UNote note, NotesViewModel viewModel, DrawingContex

var brush = note.pitch.snapFirst ? ThemeManager.AccentBrush3 : null;
var pen = ThemeManager.AccentPen3;
using (var state = context.PushPreTransform(Matrix.CreateTranslation(p0.X, p0.Y))) {
using (var state = context.PushTransform(Matrix.CreateTranslation(p0.X, p0.Y))) {
context.DrawGeometry(brush, pen, pointGeometry);
}

Expand All @@ -283,7 +280,7 @@ private void RenderPitchBend(UNote note, NotesViewModel viewModel, DrawingContex
}
}
p0 = p1;
using (var state = context.PushPreTransform(Matrix.CreateTranslation(p0.X, p0.Y))) {
using (var state = context.PushTransform(Matrix.CreateTranslation(p0.X, p0.Y))) {
context.DrawGeometry(null, pen, pointGeometry);
}
}
Expand Down Expand Up @@ -318,7 +315,7 @@ private void RenderVibratoToggle(UNote note, NotesViewModel viewModel, DrawingCo
var togglePos = vibrato.GetToggle(note);
Point icon = viewModel.TickToneToPoint(togglePos.X, togglePos.Y);
var pen = ThemeManager.BarNumberPen;
using (var state = context.PushPreTransform(Matrix.CreateTranslation(icon.X - 10, icon.Y))) {
using (var state = context.PushTransform(Matrix.CreateTranslation(icon.X - 10, icon.Y))) {
context.DrawGeometry(vibrato.length == 0 ? null : pen.Brush, pen, vibratoIcon);
}
}
Expand All @@ -336,13 +333,13 @@ private void RenderVibratoControl(UNote note, NotesViewModel viewModel, DrawingC
context.DrawLine(pen, start, fadeIn);
context.DrawLine(pen, fadeIn, fadeOut);
context.DrawLine(pen, fadeOut, end);
using (var state = context.PushPreTransform(Matrix.CreateTranslation(start))) {
using (var state = context.PushTransform(Matrix.CreateTranslation(start))) {
context.DrawGeometry(pen.Brush, pen, pointGeometry);
}
using (var state = context.PushPreTransform(Matrix.CreateTranslation(fadeIn))) {
using (var state = context.PushTransform(Matrix.CreateTranslation(fadeIn))) {
context.DrawGeometry(pen.Brush, pen, pointGeometry);
}
using (var state = context.PushPreTransform(Matrix.CreateTranslation(fadeOut))) {
using (var state = context.PushTransform(Matrix.CreateTranslation(fadeOut))) {
context.DrawGeometry(pen.Brush, pen, pointGeometry);
}
vibrato.GetPeriodStartEnd(DocManager.Inst.Project, note, out var periodStartPos, out var periodEndPos);
Expand Down
13 changes: 5 additions & 8 deletions OpenUtau/Controls/PartControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,8 @@ public PartControl(UPart part, PartsCanvas canvas) {
}
}

protected override void OnPropertyChanged<T>(AvaloniaPropertyChangedEventArgs<T> change) {
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) {
base.OnPropertyChanged(change);
if (!change.IsEffectiveValueChange) {
return;
}
if (change.Property == OffsetProperty ||
change.Property == TrackHeightProperty ||
change.Property == TickWidthProperty) {
Expand Down Expand Up @@ -169,9 +166,9 @@ public override void Render(DrawingContext context) {

// Text
var textLayout = TextLayoutCache.Get(Text, Foreground!, 12);
using (var state = context.PushPreTransform(Matrix.CreateTranslation(3, 2))) {
context.DrawRectangle(backgroundBrush, null, new Rect(new Point(0, 0), textLayout.Size));
textLayout.Draw(context);
using (var state = context.PushTransform(Matrix.CreateTranslation(3, 2))) {
context.DrawRectangle(backgroundBrush, null, new Rect(new Point(0, 0), new Size(textLayout.Width, textLayout.Height)));
textLayout.Draw(context, new Point());
}

if (part == null) {
Expand All @@ -186,7 +183,7 @@ public override void Render(DrawingContext context) {
minTone -= additional;
maxTone += additional;
}
using var pushedState = context.PushPreTransform(Matrix.CreateScale(1, trackHeight / (maxTone - minTone)));
using var pushedState = context.PushTransform(Matrix.CreateScale(1, trackHeight / (maxTone - minTone)));
foreach (var note in voicePart.notes) {
var start = new Point((int)(note.position * tickWidth), maxTone - note.tone);
var end = new Point((int)(note.End * tickWidth), maxTone - note.tone);
Expand Down
9 changes: 3 additions & 6 deletions OpenUtau/Controls/PartsCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,13 @@ public PartsCanvas() {
.Subscribe(_ => InvalidateVisual());
}

protected override void OnPropertyChanged<T>(AvaloniaPropertyChangedEventArgs<T> change) {
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) {
base.OnPropertyChanged(change);
if (!change.IsEffectiveValueChange) {
return;
}
if (change.Property == ItemsProperty) {
if (change.OldValue != null && change.OldValue.Value is ObservableCollection<UPart> oldCol) {
if (change.OldValue != null && change.OldValue is ObservableCollection<UPart> oldCol) {
oldCol.CollectionChanged -= Items_CollectionChanged;
}
if (change.NewValue.HasValue && change.NewValue.Value is ObservableCollection<UPart> newCol) {
if (change.NewValue != null && change.NewValue is ObservableCollection<UPart> newCol) {
newCol.CollectionChanged += Items_CollectionChanged;
}
}
Expand Down
Loading

0 comments on commit d60f403

Please sign in to comment.