Skip to content

Commit

Permalink
adjust cursors on crop
Browse files Browse the repository at this point in the history
  • Loading branch information
TheJoeFin committed May 4, 2024
1 parent 2057db5 commit 3ce1a09
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 24 deletions.
6 changes: 5 additions & 1 deletion MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

<wpfui:TitleBar
x:Name="wpfuiTitleBar"
Title="Magick Crop by TheJoeFin v1.2.1"
Title="Magick Crop by TheJoeFin v1.3.0"
Height="32"
Foreground="{wpfui:ThemeResource TextFillColorPrimaryBrush}">
<wpfui:TitleBar.Resources>
Expand Down Expand Up @@ -259,6 +259,10 @@
Name="CropImage"
Click="CropImage_Click"
Header="Crop Image" />
<MenuItem
Name="PerspectiveCorrectionMenuItem"
Click="PerspectiveCorrectionMenuItem_Click"
Header="Perspective Correction" />
</ContextMenu>
</wpfui:DropDownButton.Flyout>
<wpfui:SymbolIcon Symbol="ImageEdit24" />
Expand Down
32 changes: 21 additions & 11 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Wpf.Ui;
using Wpf.Ui.Appearance;
Expand All @@ -32,6 +31,7 @@ public partial class MainWindow : FluentWindow
private string openedFileName = string.Empty;

private List<UIElement> _polygonElements;
private Visibility _perspectiveHandlesState = Visibility.Visible;

public MainWindow()
{
Expand Down Expand Up @@ -130,7 +130,6 @@ private void PanCanvas(MouseEventArgs e)
mat.Translate(deltaX, deltaY);
matTrans.Matrix = mat;
e.Handled = true;
Debug.WriteLine($"scaleFactor: {scaleFactor}");
}

private void MovePolyline(Point newPoint)
Expand Down Expand Up @@ -449,7 +448,6 @@ private void ShapeCanvas_PreviewMouseWheel(object sender, MouseWheelEventArgs e)

scaleFactor = e.Delta > 0 ? 1.1 : 1 / 1.1;

Debug.WriteLine($"scaleFactor: {scaleFactor}");
Matrix mat = matTrans.Matrix;
mat.ScaleAt(scaleFactor, scaleFactor, pos1.X, pos1.Y);
matTrans.Matrix = mat;
Expand Down Expand Up @@ -771,6 +769,8 @@ private void CropImage_Click(object sender, RoutedEventArgs e)
ApplySaveSplitButton.Visibility = Visibility.Collapsed;
CropButtonPanel.Visibility = Visibility.Visible;

_perspectiveHandlesState = TopLeft.Visibility;

foreach (UIElement element in _polygonElements)
element.Visibility = Visibility.Collapsed;

Expand All @@ -779,12 +779,6 @@ private void CropImage_Click(object sender, RoutedEventArgs e)

private async void ApplyCropButton_Click(object sender, RoutedEventArgs e)
{
CropButtonPanel.Visibility = Visibility.Collapsed;
ApplySaveSplitButton.Visibility = Visibility.Visible;

foreach (UIElement element in _polygonElements)
element.Visibility = Visibility.Visible;

if (string.IsNullOrEmpty(imagePath))
return;

Expand All @@ -805,8 +799,14 @@ private async void ApplyCropButton_Click(object sender, RoutedEventArgs e)

MainImage.Source = magickImage.ToBitmapSource();

CroppingRectangle.Visibility = Visibility.Collapsed;
SetUiForCompletedTask();

foreach (UIElement element in _polygonElements)
element.Visibility = _perspectiveHandlesState;

CropButtonPanel.Visibility = Visibility.Collapsed;
ApplySaveSplitButton.Visibility = Visibility.Visible;
CroppingRectangle.Visibility = Visibility.Collapsed;
}

private void CancelCrop_Click(object sender, RoutedEventArgs e)
Expand All @@ -815,9 +815,19 @@ private void CancelCrop_Click(object sender, RoutedEventArgs e)
ApplySaveSplitButton.Visibility = Visibility.Visible;

foreach (UIElement element in _polygonElements)
element.Visibility = Visibility.Visible;
element.Visibility = _perspectiveHandlesState;

CroppingRectangle.Visibility = Visibility.Collapsed;
}

private void PerspectiveCorrectionMenuItem_Click(object sender, RoutedEventArgs e)
{
CroppingRectangle.Visibility = Visibility.Collapsed;

Visibility newState = TopLeft.Visibility == Visibility.Visible ? Visibility.Collapsed : Visibility.Visible;

foreach (UIElement element in _polygonElements)
element.Visibility = newState;
}
}

Expand Down
18 changes: 9 additions & 9 deletions ResizableRectangle.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<Grid>
<Rectangle
x:Name="rectangle"
Cursor="ScrollAll"
Cursor="SizeAll"
Fill="Transparent"
MouseDown="element_MouseDown"
Stroke="Blue"
Expand All @@ -37,31 +37,31 @@
Margin="-5,-5,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Cursor="ScrollNW"
Cursor="SizeNWSE"
Fill="Blue"
MouseDown="element_MouseDown"
Tag="TopLeft" />
<Ellipse
Margin="0,-5,-5,0"
HorizontalAlignment="Right"
VerticalAlignment="Top"
Cursor="ScrollNE"
Cursor="SizeNESW"
Fill="Blue"
MouseDown="element_MouseDown"
Tag="TopRight" />
<Ellipse
Margin="0,0,-5,-5"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
Cursor="ScrollSE"
Cursor="SizeNWSE"
Fill="Blue"
MouseDown="element_MouseDown"
Tag="BottomRight" />
<Ellipse
Margin="-5,0,0,-5"
HorizontalAlignment="Left"
VerticalAlignment="Bottom"
Cursor="ScrollSW"
Cursor="SizeNESW"
Fill="Blue"
MouseDown="element_MouseDown"
Tag="BottomLeft" />
Expand All @@ -72,7 +72,7 @@
Margin="0,-3,0,0"
HorizontalAlignment="Center"
VerticalAlignment="Top"
Cursor="ScrollNS"
Cursor="SizeNS"
Fill="Blue"
MouseDown="element_MouseDown"
RadiusX="4"
Expand All @@ -86,7 +86,7 @@
Margin="0,0,-3,0"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Cursor="ScrollWE"
Cursor="SizeWE"
Fill="Blue"
MouseDown="element_MouseDown"
RadiusX="4"
Expand All @@ -100,7 +100,7 @@
Margin="0,0,0,-3"
HorizontalAlignment="Center"
VerticalAlignment="Bottom"
Cursor="ScrollNS"
Cursor="SizeNS"
Fill="Blue"
MouseDown="element_MouseDown"
RadiusX="4"
Expand All @@ -114,7 +114,7 @@
Margin="-3,0,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Cursor="ScrollWE"
Cursor="SizeWE"
Fill="Blue"
MouseDown="element_MouseDown"
RadiusX="4"
Expand Down
3 changes: 0 additions & 3 deletions ResizableRectangle.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using ImageMagick;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
Expand Down Expand Up @@ -54,8 +53,6 @@ private void UserControl_MouseMove(object sender, MouseEventArgs e)
double canvasDeltaX = position.X - MouseDownCanvasPoint.Value.X;
double canvasDeltaY = position.Y - MouseDownCanvasPoint.Value.Y;

Debug.WriteLine($"canvasDeltaX = {canvasDeltaX}, canvasDeltaY = {canvasDeltaY}");

switch (KindOfMove)
{
case MovingKind.Pan:
Expand Down

0 comments on commit 3ce1a09

Please sign in to comment.