Compare commits

...

5 Commits

Author SHA1 Message Date
Ano-sys 7a8e8a0bd3 Added Undo List to hold freshly undid drawn Lines 2025-03-23 00:25:58 +01:00
Ano-sys aaa2715243 Changed Package Versions 2025-03-23 00:24:47 +01:00
Ano-sys 9d4961af86 Added Undo and Redo 2025-03-23 00:24:19 +01:00
Ano-sys da3dc87ed3 Added Global KeyUp Event which is passed to ViewModel 2025-03-23 00:24:06 +01:00
Ano-sys e811a54c61 Altered SplitViews Background and added CornerRadius 2025-03-23 00:23:36 +01:00
5 changed files with 47 additions and 11 deletions
+6 -6
View File
@@ -13,13 +13,13 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Avalonia" Version="11.2.4" /> <PackageReference Include="Avalonia" Version="11.2.5" />
<PackageReference Include="Avalonia.Desktop" Version="11.2.4" /> <PackageReference Include="Avalonia.Desktop" Version="11.2.5" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.2.4" /> <PackageReference Include="Avalonia.Themes.Fluent" Version="11.2.5" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.2.4" /> <PackageReference Include="Avalonia.Fonts.Inter" Version="11.2.5" />
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.--> <!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.2.4" /> <PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.2.5" />
<PackageReference Include="Avalonia.Xaml.Interactions" Version="11.2.0.9" /> <PackageReference Include="Avalonia.Xaml.Interactions" Version="11.2.0.14" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" /> <PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>
+24 -1
View File
@@ -84,7 +84,8 @@ public class MainWindowViewModel : ViewModelBase
private void OnCanvasPointerPressed(PointerPressedEventArgs? e) private void OnCanvasPointerPressed(PointerPressedEventArgs? e)
{ {
if (e == null) return; if (e == null) return;
if(UndoDrawingPoints.Count > 0) UndoDrawingPoints.Clear();
IsDrawing = true; IsDrawing = true;
DrawingPoints.Add(new DrawingPoints(Brush, BrushThickness)); DrawingPoints.Add(new DrawingPoints(Brush, BrushThickness));
DrawingPoint = DrawingPoints[^1]; DrawingPoint = DrawingPoints[^1];
@@ -111,4 +112,26 @@ public class MainWindowViewModel : ViewModelBase
{ {
IsDrawing = false; IsDrawing = false;
} }
public void GlobalKeyUpHandler(KeyEventArgs e)
{
if (e.KeyModifiers != KeyModifiers.Control) return;
switch (e.Key)
{
case Key.Z:
if (DrawingPoints.Count > 0)
{
UndoDrawingPoints.Add(DrawingPoints[^1]);
DrawingPoints.Remove(DrawingPoints[^1]);
}
break;
case Key.Y:
if (UndoDrawingPoints.Count > 0)
{
DrawingPoints.Add(UndoDrawingPoints[^1]);
UndoDrawingPoints.Remove(UndoDrawingPoints[^1]);
}
break;
}
}
} }
+3 -1
View File
@@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.IO; using System.IO;
@@ -27,7 +28,8 @@ public class ViewModelBase : ObservableObject
public IRelayCommand<PointerReleasedEventArgs>? CanvasPointerReleasedCommand { get; set; } public IRelayCommand<PointerReleasedEventArgs>? CanvasPointerReleasedCommand { get; set; }
public ObservableCollection<DrawingPoints> DrawingPoints { get; set; } = new(); public ObservableCollection<DrawingPoints> DrawingPoints { get; set; } = new();
public DrawingPoints? DrawingPoint { get; set; } public DrawingPoints? DrawingPoint { get; set; }
protected List<DrawingPoints> UndoDrawingPoints = new();
protected bool IsDrawing { get; set; } protected bool IsDrawing { get; set; }
private string _selectedColor = "Black"; private string _selectedColor = "Black";
+4 -3
View File
@@ -36,10 +36,10 @@
</Design.DataContext> </Design.DataContext>
<Panel Background="Transparent"> <Panel Background="Transparent">
<SplitView Background="Transparent" IsPaneOpen="{Binding IsSplitOpen, Mode=TwoWay}" DisplayMode="Overlay" OpenPaneLength="250" ClipToBounds="False"> <SplitView Background="Transparent" IsPaneOpen="{Binding IsSplitOpen, Mode=TwoWay}" DisplayMode="Overlay" OpenPaneLength="250" ClipToBounds="False" PaneBackground="Transparent">
<SplitView.Pane> <SplitView.Pane>
<Border Background="Transparent" BorderBrush="Gray" BorderThickness="0" CornerRadius="0, 12.5,12.5,0" > <Border Background="#d4d4fc" BorderBrush="Gray" BorderThickness="1" CornerRadius="0, 12.5,12.5,0">
<Grid Background="#66ffffff"> <Grid Background="#d4d4fc" Margin="5"> <!-- Background of left panel opened -->
<Grid Background="Transparent"> <Grid Background="Transparent">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="50*"></RowDefinition> <RowDefinition Height="50*"></RowDefinition>
@@ -133,6 +133,7 @@
</Grid> </Grid>
</SplitView> </SplitView>
<!-- left Info bar --> <!-- left Info bar -->
<StackPanel Width="30" HorizontalAlignment="Left" IsVisible="{Binding !IsSplitOpen}" Background="#d4d4fc"> <StackPanel Width="30" HorizontalAlignment="Left" IsVisible="{Binding !IsSplitOpen}" Background="#d4d4fc">
<!-- Menu-Opener --> <!-- Menu-Opener -->
<Button Content="≡" <Button Content="≡"
+10
View File
@@ -19,6 +19,16 @@ public partial class MainWindow : Window
DataContext = new MainWindowViewModel(); DataContext = new MainWindowViewModel();
Topmost = true; Topmost = true;
Topmost = false; Topmost = false;
this.KeyUp += OnKeyUp;
}
private void OnKeyUp(object? sender, KeyEventArgs e)
{
if (DataContext is MainWindowViewModel vm)
{
vm.GlobalKeyUpHandler(e);
}
} }
// MVVM like implementations burst the bounds -> implemented the old school way // MVVM like implementations burst the bounds -> implemented the old school way