Browse Source

Updated Avalonia and connected color picker

Krzysztof Krysiński 1 year ago
parent
commit
35cb49a7ff

+ 1 - 1
src/PixiEditor.AvaloniaUI/Helpers/Extensions/LockedFramebufferExtensions.cs

@@ -64,7 +64,7 @@ public static class LockedFramebufferExtensions
     {
         unsafe
         {
-            var bytesPerPixel = framebuffer.Format.BitsPerPixel / 8; //TODO: check if bits per pixel is correct
+            var bytesPerPixel = framebuffer.Format.BitsPerPixel / 8;
             var zero = (byte*)framebuffer.Address;
             var offset = framebuffer.RowBytes * y + bytesPerPixel * x;
             zero[offset + 3] = color.A;

+ 1 - 1
src/PixiEditor.AvaloniaUI/Helpers/ServiceCollectionHelpers.cs

@@ -41,7 +41,6 @@ internal static class ServiceCollectionHelpers
             // View Models
             .AddSingleton<ToolsViewModel>()
             .AddSingleton<IToolsHandler, ToolsViewModel>(x => x.GetRequiredService<ToolsViewModel>())
-            .AddSingleton<IColorsHandler, ColorsViewModel>()
             .AddSingleton<StylusViewModel>()
             .AddSingleton<WindowViewModel>()
             .AddSingleton<FileViewModel>()
@@ -53,6 +52,7 @@ internal static class ServiceCollectionHelpers
             .AddSingleton<SelectionViewModel>()
             .AddSingleton<ViewOptionsViewModel>()
             .AddSingleton<ColorsViewModel>()
+            .AddSingleton<IColorsHandler, ColorsViewModel>(x => x.GetRequiredService<ColorsViewModel>())
             .AddSingleton<RegistryViewModel>()
             .AddSingleton(static x => new DiscordViewModel(x.GetService<ViewModelMain>(), "764168193685979138"))
             .AddSingleton<DebugViewModel>()

+ 4 - 3
src/PixiEditor.AvaloniaUI/PixiEditor.AvaloniaUI.csproj

@@ -31,14 +31,15 @@
         <PackageReference Include="CLSEncoderDecoder" Version="1.0.0" />
         <PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
         <PackageReference Include="DiscordRichPresence" Version="1.2.1.24" />
-        <PackageReference Include="Dock.Avalonia" Version="11.0.0" />
-        <PackageReference Include="Dock.Model.Avalonia" Version="11.0.0" />
+        <PackageReference Include="Dock.Avalonia" Version="11.0.0.3" />
+        <PackageReference Include="Dock.Model.Avalonia" Version="11.0.0.3" />
         <PackageReference Include="Hardware.Info" Version="11.0.0" />
         <PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.2.0" />
         <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
+        <PackageReference Include="PixiEditor.ColorPicker.Models" Version="1.0.5" />
         <PackageReference Include="PixiEditor.Parser" Version="3.3.0" />
       <PackageReference Include="PixiEditor.Parser.Skia" Version="3.0.0" />
-      <PackageReference Include="PixiEditor.ColorPicker.AvaloniaUI" Version="1.0.2" />
+      <PackageReference Include="PixiEditor.ColorPicker.AvaloniaUI" Version="1.0.5" />
     </ItemGroup>
 
     <ItemGroup>

+ 10 - 3
src/PixiEditor.AvaloniaUI/ViewLocator.cs

@@ -17,16 +17,23 @@ public class ViewLocator : IDataTemplate
     {
         [typeof(DockDocumentViewModel)] = typeof(DocumentTemplate),
         [typeof(LayersDockViewModel)] = typeof(LayersManager),
-        [typeof(ColorPickerDockViewModel)] = typeof(StandardColorPicker),
     };
 
     public Control Build(object? data)
     {
-        Type type = data?.GetType() ?? typeof(object);
+        var name = data.GetType().FullName.Replace("ViewModel", "View");
+        var type = Type.GetType(name);
+
+        if (type != null)
+        {
+            return (Control)Activator.CreateInstance(type);
+        }
+
+        type = data?.GetType() ?? typeof(object);
         if (ViewBindingsMap.TryGetValue(type, out Type viewType))
         {
             var instance = Activator.CreateInstance(viewType);
-            if (instance is { })
+            if (instance is not null)
             {
                 return (Control)instance;
             }

+ 11 - 3
src/PixiEditor.AvaloniaUI/ViewModels/Dock/ColorPickerDockViewModel.cs

@@ -1,13 +1,21 @@
-using Dock.Model.Avalonia.Controls;
+using Avalonia;
+using Dock.Model.Avalonia.Controls;
 using PixiEditor.AvaloniaUI.ViewModels.SubViewModels;
 
 namespace PixiEditor.AvaloniaUI.ViewModels.Dock;
 
 internal class ColorPickerDockViewModel : Tool
 {
-    private ColorsViewModel colorsViewModel;
+    public static readonly StyledProperty<ColorsViewModel> ColorsViewModelProperty = AvaloniaProperty.Register<ColorPickerDockViewModel, ColorsViewModel>(
+        nameof(ColorsViewModel));
+
+    public ColorsViewModel ColorsViewModel
+    {
+        get => GetValue(ColorsViewModelProperty);
+        set => SetValue(ColorsViewModelProperty, value);
+    }
     public ColorPickerDockViewModel(ColorsViewModel colorsVm)
     {
-        colorsViewModel = colorsVm;
+        ColorsViewModel = colorsVm;
     }
 }

+ 13 - 0
src/PixiEditor.AvaloniaUI/Views/Dock/ColorPickerDockView.axaml

@@ -0,0 +1,13 @@
+<UserControl xmlns="https://github.com/avaloniaui"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+             xmlns:colorPicker="clr-namespace:ColorPicker;assembly=ColorPicker.AvaloniaUI"
+             xmlns:converters="clr-namespace:PixiEditor.AvaloniaUI.Helpers.Converters"
+             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
+             x:Class="PixiEditor.AvaloniaUI.Views.Dock.ColorPickerDockView">
+    <colorPicker:StandardColorPicker
+        SelectedColor="{Binding DataContext.ColorsViewModel.PrimaryColor, Mode=TwoWay, Converter={converters:GenericColorToMediaColorConverter}}"
+        SecondaryColor="{Binding DataContext.ColorsViewModel.SecondaryColor, Mode=TwoWay, Converter={converters:GenericColorToMediaColorConverter}}"
+        UseHintColor="False"/>
+</UserControl>

+ 14 - 0
src/PixiEditor.AvaloniaUI/Views/Dock/ColorPickerDockView.axaml.cs

@@ -0,0 +1,14 @@
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Markup.Xaml;
+
+namespace PixiEditor.AvaloniaUI.Views.Dock;
+
+public partial class ColorPickerDockView : UserControl
+{
+    public ColorPickerDockView()
+    {
+        InitializeComponent();
+    }
+}
+

+ 4 - 4
src/PixiEditor.Extensions/PixiEditor.Extensions.csproj

@@ -1,20 +1,20 @@
 <Project Sdk="Microsoft.NET.Sdk">
 
     <PropertyGroup>
-        <TargetFramework>net7.0</TargetFramework>
-        <ImplicitUsings>enable</ImplicitUsings>
-        <Nullable>enable</Nullable>
+      <TargetFramework>net7.0</TargetFramework>
+      <ImplicitUsings>enable</ImplicitUsings>
+      <Nullable>enable</Nullable>
       <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
       <Version>0.0.3</Version>
       <Title>PixiEditor Extensions</Title>
       <Authors>PixiEditor Organization</Authors>
       <Copyright>PixiEditor Organization</Copyright>
       <Description>Package for creating custom extensions for pixel art editor PixiEditor</Description>
-      <AvaloniaVersion>11.0.3</AvaloniaVersion>
     </PropertyGroup>
 
     <ItemGroup>
       <PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
+      <PackageReference Include="Avalonia.Remote.Protocol" Version="$(AvaloniaVersion)" />
       <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
       <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
       <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />

+ 2 - 1
src/PixiEditor.OperatingSystem/PixiEditor.OperatingSystem.csproj

@@ -7,7 +7,8 @@
     </PropertyGroup>
 
     <ItemGroup>
-      <PackageReference Include="Avalonia" Version="11.0.0" />
+      <PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
+      <PackageReference Include="Avalonia.Remote.Protocol" Version="$(AvaloniaVersion)" />
     </ItemGroup>
 
 </Project>

+ 2 - 3
src/PixiEditor.UI.Common/PixiEditor.UI.Common.csproj

@@ -4,7 +4,6 @@
         <TargetFramework>net7.0</TargetFramework>
         <ImplicitUsings>enable</ImplicitUsings>
         <Nullable>enable</Nullable>
-        <AvaloniaVersion>11.0.3</AvaloniaVersion>
     </PropertyGroup>
 
     <ItemGroup>
@@ -22,8 +21,8 @@
     <ItemGroup>
       <PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
       <PackageReference Include="Avalonia.Themes.Fluent" Version="$(AvaloniaVersion)" />
-      <PackageReference Include="Avalonia.Xaml.Behaviors" Version="11.0.0-rc2.2" />
-      <PackageReference Include="Dock.Avalonia" Version="11.0.0" />
+      <PackageReference Include="Avalonia.Xaml.Behaviors" Version="11.0.5" />
+      <PackageReference Include="Dock.Avalonia" Version="11.0.0.3" />
     </ItemGroup>
 
     <ItemGroup>

+ 0 - 6
src/PixiEditor.UpdateInstaller/Directory.Build.props

@@ -1,6 +0,0 @@
-<Project>
-  <PropertyGroup>
-    <Nullable>enable</Nullable>
-    <AvaloniaVersion>11.0.3</AvaloniaVersion>
-  </PropertyGroup>
-</Project>

+ 0 - 1
src/PixiEditor.UpdateInstaller/PixiEditor.UpdateInstaller/PixiEditor.UpdateInstaller.csproj

@@ -7,7 +7,6 @@
         <RootNamespace>PixiEditor.UpdateInstaller.New</RootNamespace>
     </PropertyGroup>
 
-
     <ItemGroup>
         <AvaloniaResource Include="Assets\**" />
     </ItemGroup>

+ 1 - 1
src/PixiEditor.Zoombox/PixiEditor.Zoombox.csproj

@@ -56,7 +56,7 @@
       <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
     </PackageReference>
 
-    <PackageReference Include="Avalonia" Version="11.0.3" />
+    <PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
 
     <PackageReference Include="System.Reactive" Version="6.0.0" />
   </ItemGroup>