Skip to content

Commit

Permalink
Merge pull request mohammadKarimi#156 from mohammadKarimi/153-change-…
Browse files Browse the repository at this point in the history
…icons-for-drawing-shape

Change icons for drawing shape
  • Loading branch information
mohammadKarimi authored Nov 28, 2024
2 parents 667d05d + b2e211d commit d136446
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/Riter/Core/Enum/DrawingShape.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ public enum DrawingShape
Circle = 2,
Rectangle = 3,
Database = 4,
Free = 5,
}
12 changes: 12 additions & 0 deletions src/Riter/Core/UI/CursorPath.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.IO;

namespace Riter.Core.UI;
public static class CursorPaths
{
public const string RectangleCursor = "Resources/Cursor/arrow-rectangle.cur";
public const string DatabaseCursor = "Resources/Cursor/arrow-db.cur";
public const string CircleCursor = "Resources/Cursor/arrow-circle.cur";
public const string ArrowCursor = "Resources/Cursor/arrow-arrow.cur";
public const string LineCursor = "Resources/Cursor/arrow-line.cur";
public const string MoveCursor = "Resources/Cursor/arrow-move.cur";
}
50 changes: 46 additions & 4 deletions src/Riter/Core/UI/MainInkCanvasControl.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Windows.Controls;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows.Controls;
using System.Windows.Ink;
using System.Windows.Media;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -30,14 +32,54 @@ public MainInkCanvasControl()
_shapeDrawers = App.ServiceProvider.GetService<IEnumerable<IShapeDrawer>>()
.ToDictionary(drawer => drawer.SupportedShape);

DataContextChanged += MainInkCanvasControl_DataContextChanged;
_strokeHistoryService.SetMainElementToRedoAndUndo(MainInkCanvas);
MainInkCanvas.Strokes.StrokesChanged += StrokesChanged;

MainInkCanvas.MouseLeftButtonDown += StartDrawing;
MainInkCanvas.MouseLeftButtonUp += EndDrawing;
MainInkCanvas.MouseMove += DrawShape;
}

private void MainInkCanvasControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if (e.NewValue is PaletteStateOrchestratorViewModel viewModel)
{
viewModel.InkEditingModeViewModel.PropertyChanged += DrawingViewModel_PropertyChanged;
viewModel.DrawingViewModel.PropertyChanged += DrawingViewModel_PropertyChanged;
}
}

private void DrawingViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
var viewModel = (PaletteStateOrchestratorViewModel)DataContext;
Debug.WriteLine(e.PropertyName);

if (e.PropertyName == nameof(viewModel.InkEditingModeViewModel.InkEditingMode)
&& viewModel.InkEditingModeViewModel.InkEditingMode is InkCanvasEditingMode.None)
{
MainInkCanvas.UseCustomCursor = true;
}

if (e.PropertyName == nameof(viewModel.DrawingViewModel.CurrentShape))
{
MainInkCanvas.Cursor = viewModel.DrawingViewModel.CurrentShape switch
{
DrawingShape.Rectangle => new Cursor(CursorPaths.RectangleCursor),
DrawingShape.Database => new Cursor(CursorPaths.DatabaseCursor),
DrawingShape.Circle => new Cursor(CursorPaths.CircleCursor),
DrawingShape.Arrow => new Cursor(CursorPaths.ArrowCursor),
DrawingShape.Line => new Cursor(CursorPaths.LineCursor),
_ => Cursors.Arrow
};
}

if (e.PropertyName == nameof(viewModel.InkEditingModeViewModel.InkEditingMode)
&& viewModel.InkEditingModeViewModel.InkEditingMode is InkCanvasEditingMode.Ink)
{
MainInkCanvas.UseCustomCursor = false;
}
}

private static bool IsDrawingShapeKeyEntered(Key key) => key == Key.LeftShift || key == Key.RightShift;

/// <summary>
Expand Down Expand Up @@ -87,14 +129,14 @@ private void Window_KeyDown(object sender, KeyEventArgs e)
_isDragging = true;
_inkEditingModeStateHandler.None();
MainInkCanvas.UseCustomCursor = true;
MainInkCanvas.Cursor = Cursors.SizeAll;
MainInkCanvas.Cursor = new Cursor(CursorPaths.MoveCursor);
}

if (IsDrawingShapeKeyEntered(e.Key) && _inkEditingModeStateHandler.InkEditingMode is InkCanvasEditingMode.Ink)
{
_inkEditingModeStateHandler.None();
MainInkCanvas.UseCustomCursor = true;
MainInkCanvas.Cursor = Cursors.Pen;
MainInkCanvas.Cursor = new Cursor(CursorPaths.LineCursor);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Riter/Core/UI/ToolBox.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@
<DataTrigger Binding="{Binding ButtonSelectedViewModel.ButtonSelectedName}" Value="ShapeDrawButton">
<Setter Property="Tag" Value="Selected"/>
</DataTrigger>
<DataTrigger Binding="{Binding DrawingViewModel.CurrentShape}" Value="FreeDraw">
<Setter Property="Content" Value="{StaticResource Icon_RoundedRectangle}"/>
<DataTrigger Binding="{Binding DrawingViewModel.CurrentShape}" Value="{x:Static enum:DrawingShape.Free}">
<Setter Property="Content" Value="{StaticResource Icon_Line_Toolbox}"/>
</DataTrigger>
<DataTrigger Binding="{Binding DrawingViewModel.CurrentShape}" Value="{x:Static enum:DrawingShape.Line}">
<Setter Property="Content" Value="{StaticResource Icon_Line_Toolbox}"/>
Expand Down
Binary file added src/Riter/Resources/Cursor/arrow-arrow.cur
Binary file not shown.
Binary file added src/Riter/Resources/Cursor/arrow-circle.cur
Binary file not shown.
Binary file added src/Riter/Resources/Cursor/arrow-db.cur
Binary file not shown.
Binary file added src/Riter/Resources/Cursor/arrow-line.cur
Binary file not shown.
Binary file added src/Riter/Resources/Cursor/arrow-move.cur
Binary file not shown.
Binary file added src/Riter/Resources/Cursor/arrow-rectangle.cur
Binary file not shown.
20 changes: 20 additions & 0 deletions src/Riter/Riter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,26 @@
<None Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>

<None Update="Resources\Cursor\arrow-arrow.cur">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Resources\Cursor\arrow-circle.cur">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Resources\Cursor\arrow-db.cur">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Resources\Cursor\arrow-line.cur">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Resources\Cursor\arrow-move.cur">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Resources\Cursor\arrow-rectangle.cur">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>

</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 8 additions & 0 deletions src/Riter/ViewModel/StateHandlers/BaseStateHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,12 @@ protected bool SetProperty<T>(ref T field, T newValue, string propertyName, Acti

return false;
}

protected bool AlwaysSetProperty<T>(ref T field, T newValue, string propertyName, Action onChangedAction = null)
{
field = newValue;
onChangedAction?.Invoke();
OnPropertyChanged(propertyName);
return true;
}
}
6 changes: 3 additions & 3 deletions src/Riter/ViewModel/StateHandlers/DrawingStateHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class DrawingStateHandler(
private readonly IButtonSelectedStateHandler _buttonSelectedStateHandler = buttonSelectedStateHandler;
private readonly ISettingPanelStateHandler _settingPanelStateHandler = settingPanelStateHandler;
private bool _isReleased = true;
private DrawingShape _currentShape = DrawingShape.Line;
private DrawingShape _currentShape = DrawingShape.Free;

public bool IsReleased
{
Expand All @@ -36,7 +36,7 @@ public bool IsReleased
public DrawingShape CurrentShape
{
get => _currentShape;
private set => SetProperty(ref _currentShape, value, nameof(CurrentShape));
private set => AlwaysSetProperty(ref _currentShape, value, nameof(CurrentShape));
}

public void Release()
Expand All @@ -54,7 +54,7 @@ public void StartDrawing()

public void StartDrawingShape(DrawingShape shape)
{
CurrentShape = shape;
CurrentShape = shape == DrawingShape.Free ? DrawingShape.Line : shape;

_highlighterStateHandler.DisableHighlighter();
SetupDrawingMode(ButtonNames.ShapeDrawButton);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void Should_StartDrawing_When_StartDrawingIsCalled()
{
_stateHandler.StartDrawing();

_stateHandler.CurrentShape.Should().Be(DrawingShape.Line);
_stateHandler.CurrentShape.Should().Be(DrawingShape.Free);
_stateHandler.IsReleased.Should().BeFalse();
_inkEditingModeStateHandlerMock.Verify(m => m.Ink(), Times.Exactly(2));
_highlighterStateHandlerMock.Verify(m => m.DisableHighlighter(), Times.Once);
Expand Down Expand Up @@ -91,7 +91,7 @@ public void Should_StartHighlighterDrawing_WhenStartHighlighterDrawingIsCalled()
{
_stateHandler.StartHighlighterDrawing();

_stateHandler.CurrentShape.Should().Be(DrawingShape.Line);
_stateHandler.CurrentShape.Should().Be(DrawingShape.Free);
_stateHandler.IsReleased.Should().BeFalse();
_highlighterStateHandlerMock.Verify(m => m.EnableHighlighter(), Times.Once);
_inkEditingModeStateHandlerMock.Verify(m => m.Ink(), Times.Exactly(2));
Expand Down

0 comments on commit d136446

Please sign in to comment.