diff --git a/LiveShot.API/Controls/ResizeMarker/ResizeMarkerGradient.cs b/LiveShot.API/Controls/ResizeMarker/ResizeMarkerGradient.cs new file mode 100644 index 0000000..7864cb4 --- /dev/null +++ b/LiveShot.API/Controls/ResizeMarker/ResizeMarkerGradient.cs @@ -0,0 +1,27 @@ +using System.Windows; +using System.Windows.Media; + +namespace LiveShot.API.Controls.ResizeMarker +{ + public class ResizeMarkerGradient + { + public static LinearGradientBrush Striped = new() + { + StartPoint = new Point(0, 0), + EndPoint = new Point(1, 0.5), + GradientStops = new GradientStopCollection + { + new(Colors.Black, 0.0), + new(Colors.Black, 0.5), + new(Colors.White, 0.5), + new(Colors.White, 1) + }, + RelativeTransform = new ScaleTransform + { + ScaleX = 0.3, + ScaleY = 0.3 + }, + SpreadMethod = GradientSpreadMethod.Repeat + }; + } +} \ No newline at end of file diff --git a/LiveShot.API/Events/Input/ResizeMarker/OnResizeMarkerMouseEnter.cs b/LiveShot.API/Events/Input/ResizeMarker/OnResizeMarkerMouseEnter.cs new file mode 100644 index 0000000..72daede --- /dev/null +++ b/LiveShot.API/Events/Input/ResizeMarker/OnResizeMarkerMouseEnter.cs @@ -0,0 +1,6 @@ +namespace LiveShot.API.Events.Input.ResizeMarker +{ + public class OnResizeMarkerMouseEnter : Event + { + } +} \ No newline at end of file diff --git a/LiveShot.API/Events/Input/ResizeMarker/OnResizeMarkerMouseLeave.cs b/LiveShot.API/Events/Input/ResizeMarker/OnResizeMarkerMouseLeave.cs new file mode 100644 index 0000000..92a2943 --- /dev/null +++ b/LiveShot.API/Events/Input/ResizeMarker/OnResizeMarkerMouseLeave.cs @@ -0,0 +1,6 @@ +namespace LiveShot.API.Events.Input.ResizeMarker +{ + public class OnResizeMarkerMouseLeave : Event + { + } +} \ No newline at end of file diff --git a/LiveShot.API/Upload/Imgur/ImgurService.cs b/LiveShot.API/Upload/Imgur/ImgurService.cs index 090d059..76d0eee 100644 --- a/LiveShot.API/Upload/Imgur/ImgurService.cs +++ b/LiveShot.API/Upload/Imgur/ImgurService.cs @@ -15,7 +15,7 @@ public class ImgurService : IUploadService public ImgurService(IConfiguration configuration) { - _clientId = configuration.GetSection("Imgur")?["ClientID"]; + _clientId = configuration.GetSection("UploadTypes")?.GetSection("Imgur")?["ClientID"]; } public async Task Upload(Bitmap bitmap) diff --git a/LiveShot.API/Utils/ImageUtils.cs b/LiveShot.API/Utils/ImageUtils.cs index 1fd758e..fe4ed54 100644 --- a/LiveShot.API/Utils/ImageUtils.cs +++ b/LiveShot.API/Utils/ImageUtils.cs @@ -27,21 +27,34 @@ public static bool CopyImage(Selection selection, Bitmap source, Bitmap canvasBi public static Bitmap GetBitmap(Selection selection, Bitmap source, Bitmap canvasBitmap) { - var bitmap = new Bitmap((int) selection.Width, (int) selection.Height); + double realWidth = selection.Width; + double realHeight = selection.Height; + + if (selection.Left + realWidth > source.Width) + { + realWidth = source.Width - selection.Left; + } + + if (selection.Top + realHeight > source.Height) + { + realHeight = source.Height - selection.Top; + } + + var bitmap = new Bitmap((int)realWidth, (int)realHeight); using var graphics = Graphics.FromImage(bitmap); graphics.DrawImage( source, new Rectangle(0, 0, bitmap.Width, bitmap.Height), - new Rectangle((int) selection.Left, (int) selection.Top, bitmap.Width, bitmap.Height), + new Rectangle((int)selection.Left, (int)selection.Top, bitmap.Width, bitmap.Height), GraphicsUnit.Pixel ); graphics.DrawImage( canvasBitmap, new Rectangle(0, 0, bitmap.Width, bitmap.Height), - new Rectangle((int) selection.Left, (int) selection.Top, bitmap.Width, bitmap.Height), + new Rectangle((int)selection.Left, (int)selection.Top, bitmap.Width, bitmap.Height), GraphicsUnit.Pixel ); @@ -51,7 +64,7 @@ public static Bitmap GetBitmap(Selection selection, Bitmap source, Bitmap canvas public static Bitmap GetBitmapFromCanvas(System.Windows.Controls.Canvas canvas) { var bitmapSource = new RenderTargetBitmap( - (int) canvas.ActualWidth, (int) canvas.ActualHeight, 96, 96, PixelFormats.Pbgra32 + (int)canvas.ActualWidth, (int)canvas.ActualHeight, 96, 96, PixelFormats.Pbgra32 ); bitmapSource.Render(canvas); @@ -128,7 +141,7 @@ public static BitmapSource GetMagnifiedBitmap(Point point, int size, Bitmap sour graphics.DrawImage( source, new Rectangle(0, 0, size, size), - new Rectangle((int) (point.X - size / 2), (int) (point.Y - size / 2), size, size), + new Rectangle((int)(point.X - size / 2), (int)(point.Y - size / 2), size, size), GraphicsUnit.Pixel ); diff --git a/LiveShot.UI.Controls/Canvas/DrawCanvas.cs b/LiveShot.UI.Controls/Canvas/DrawCanvas.cs index 1447db3..de0e335 100644 --- a/LiveShot.UI.Controls/Canvas/DrawCanvas.cs +++ b/LiveShot.UI.Controls/Canvas/DrawCanvas.cs @@ -178,16 +178,13 @@ private void OnKeyDown(Event e) private void OnMouseWheel(Event e) { - if (KeyBoardUtils.IsCtrlPressed) + if (e.GetArgs().Delta > 0) { - if (e.GetArgs().Delta > 0) - { - DrawingStrokeThickness++; - } - else - { - DrawingStrokeThickness--; - } + DrawingStrokeThickness--; + } + else + { + DrawingStrokeThickness++; } } diff --git a/LiveShot.UI.Controls/Canvas/SelectCanvas.cs b/LiveShot.UI.Controls/Canvas/SelectCanvas.cs index a1f36e0..35151ea 100644 --- a/LiveShot.UI.Controls/Canvas/SelectCanvas.cs +++ b/LiveShot.UI.Controls/Canvas/SelectCanvas.cs @@ -10,6 +10,7 @@ using LiveShot.API.Drawing; using LiveShot.API.Events; using LiveShot.API.Events.Input; +using LiveShot.API.Events.Input.ResizeMarker; using LiveShot.API.Events.Selection; using LiveShot.API.Utils; using LiveShot.UI.Controls.Panel; @@ -18,6 +19,12 @@ namespace LiveShot.UI.Controls.Canvas { public class SelectCanvas : System.Windows.Controls.Canvas { + #region Properties + + public static readonly DependencyProperty SizePanelProperty = DependencyProperty.Register( + "SizePanel", typeof(StackPanel), typeof(SelectCanvas) + ); + public static readonly DependencyProperty SizeLabelProperty = DependencyProperty.Register( "SizeLabel", typeof(Label), typeof(SelectCanvas) ); @@ -26,6 +33,38 @@ public class SelectCanvas : System.Windows.Controls.Canvas "OpacityRectangle", typeof(Rectangle), typeof(SelectCanvas) ); + public static readonly DependencyProperty ResizeMarkTopLeftProperty = DependencyProperty.Register( + nameof(ResizeMarkTopLeft), typeof(StackPanel), typeof(SelectCanvas) + ); + + public static readonly DependencyProperty ResizeMarkTopProperty = DependencyProperty.Register( + nameof(ResizeMarkTop), typeof(StackPanel), typeof(SelectCanvas) + ); + + public static readonly DependencyProperty ResizeMarkTopRightProperty = DependencyProperty.Register( + nameof(ResizeMarkTopRight), typeof(StackPanel), typeof(SelectCanvas) + ); + + public static readonly DependencyProperty ResizeMarkLeftProperty = DependencyProperty.Register( + nameof(ResizeMarkLeft), typeof(StackPanel), typeof(SelectCanvas) + ); + + public static readonly DependencyProperty ResizeMarkRightProperty = DependencyProperty.Register( + nameof(ResizeMarkRight), typeof(StackPanel), typeof(SelectCanvas) + ); + + public static readonly DependencyProperty ResizeMarkBottomLeftProperty = DependencyProperty.Register( + nameof(ResizeMarkBottomLeft), typeof(StackPanel), typeof(SelectCanvas) + ); + + public static readonly DependencyProperty ResizeMarkBottomProperty = DependencyProperty.Register( + nameof(ResizeMarkBottom), typeof(StackPanel), typeof(SelectCanvas) + ); + + public static readonly DependencyProperty ResizeMarkBottomRightProperty = DependencyProperty.Register( + nameof(ResizeMarkBottomRight), typeof(StackPanel), typeof(SelectCanvas) + ); + public static readonly DependencyProperty RightPanelProperty = DependencyProperty.Register( "RightPanel", typeof(RightDragPanel), typeof(SelectCanvas) ); @@ -38,45 +77,109 @@ public class SelectCanvas : System.Windows.Controls.Canvas "DrawingCanvas", typeof(AbstractDrawCanvas), typeof(SelectCanvas) ); + #endregion + private readonly Collection _rectangles = new(); private bool _dragging = true; + private bool _moving; + private bool _draggingOnResizeMark; + private uint _hoveringResizeMark; + + private Point? _resizeMarkAnchor; private IEventPipeline? _events; - private bool _moving; private Point? _startPosition; private Point? _tmpCursorPosition; + #region Property accessors + + public StackPanel SizePanel + { + get => (StackPanel)GetValue(SizePanelProperty); + set => SetValue(SizePanelProperty, value); + } + public Label SizeLabel { - get => (Label) GetValue(SizeLabelProperty); + get => (Label)GetValue(SizeLabelProperty); set => SetValue(SizeLabelProperty, value); } public Rectangle OpacityRectangle { - get => (Rectangle) GetValue(OpacityRectangleProperty); + get => (Rectangle)GetValue(OpacityRectangleProperty); set => SetValue(OpacityRectangleProperty, value); } + public StackPanel ResizeMarkTopLeft + { + get => (StackPanel)GetValue(ResizeMarkTopLeftProperty); + set => SetValue(ResizeMarkTopLeftProperty, value); + } + + public StackPanel ResizeMarkTop + { + get => (StackPanel)GetValue(ResizeMarkTopProperty); + set => SetValue(ResizeMarkTopProperty, value); + } + + public StackPanel ResizeMarkTopRight + { + get => (StackPanel)GetValue(ResizeMarkTopRightProperty); + set => SetValue(ResizeMarkTopRightProperty, value); + } + + public StackPanel ResizeMarkLeft + { + get => (StackPanel)GetValue(ResizeMarkLeftProperty); + set => SetValue(ResizeMarkLeftProperty, value); + } + + public StackPanel ResizeMarkRight + { + get => (StackPanel)GetValue(ResizeMarkRightProperty); + set => SetValue(ResizeMarkRightProperty, value); + } + + public StackPanel ResizeMarkBottomLeft + { + get => (StackPanel)GetValue(ResizeMarkBottomLeftProperty); + set => SetValue(ResizeMarkBottomLeftProperty, value); + } + + public StackPanel ResizeMarkBottom + { + get => (StackPanel)GetValue(ResizeMarkBottomProperty); + set => SetValue(ResizeMarkBottomProperty, value); + } + + public StackPanel ResizeMarkBottomRight + { + get => (StackPanel)GetValue(ResizeMarkBottomRightProperty); + set => SetValue(ResizeMarkBottomRightProperty, value); + } + public RightDragPanel RightPanel { - get => (RightDragPanel) GetValue(RightPanelProperty); + get => (RightDragPanel)GetValue(RightPanelProperty); set => SetValue(RightPanelProperty, value); } public BottomDragPanel BottomPanel { - get => (BottomDragPanel) GetValue(BottomPanelProperty); + get => (BottomDragPanel)GetValue(BottomPanelProperty); set => SetValue(BottomPanelProperty, value); } public AbstractDrawCanvas DrawingCanvas { - get => (AbstractDrawCanvas) GetValue(DrawingCanvasProperty); + get => (AbstractDrawCanvas)GetValue(DrawingCanvasProperty); set => SetValue(DrawingCanvasProperty, value); } + #endregion + public Selection? Selection { get; private set; } public void WithEvents(IEventPipeline events) @@ -86,6 +189,22 @@ public void WithEvents(IEventPipeline events) _events.Subscribe(OnKeyDown); _events.Subscribe(OnKeyUp); _events.Subscribe(OnCursorUpdate); + _events.Subscribe(OnResizeMarkerMouseEnter); + _events.Subscribe(OnResizeMarkerMouseLeave); + } + + private void OnResizeMarkerMouseEnter(Event obj) + { + if (_draggingOnResizeMark) return; + + _hoveringResizeMark = uint.Parse((string)obj.GetArgs().Tag); + } + + private void OnResizeMarkerMouseLeave(Event obj) + { + if (_draggingOnResizeMark) return; + + _hoveringResizeMark = 0; } private static void OnSelectionKeyDown(Action shiftPressed, Action normal) @@ -103,9 +222,11 @@ private void UpdateSelection() if (Selection is null) { ClearOpacityRectangles(); + ClearResizeMarks(); OpacityRectangle.Visibility = Visibility.Visible; + SizePanel.Visibility = Visibility.Hidden; SizeLabel.Content = API.Properties.Resources.CaptureScreen_SizeLabel_Empty; UpdatePanels(Visibility.Hidden); @@ -113,18 +234,94 @@ private void UpdateSelection() return; } - if (_dragging || _moving) + if (_dragging || _moving || _draggingOnResizeMark) { UpdatePanels(Visibility.Hidden); UpdateOpacityRectangles(); + UpdateResizeMarks(); + UpdateSizePanel(); SetLeft(Selection.Rectangle, Selection.Left); SetTop(Selection.Rectangle, Selection.Top); SizeLabel.Content = Selection.Label; + SizePanel.Visibility = Visibility.Visible; } } + private void UpdateSizePanel() + { + if (Selection is null) return; + + double top = Selection.Top - SizePanel.ActualHeight - 5; + double left = Selection.Left + 5; + + if (top <= 0) + { + top = 5; + } + + if (left + SizePanel.ActualWidth + 5 > Width) + { + left = Selection.Left - SizePanel.ActualWidth - 5; + top = Selection.Top + 5; + } + + SetTop(SizePanel, top); + SetLeft(SizePanel, left); + } + + private void ClearResizeMarks() + { + ResizeMarkTopLeft.Visibility = Visibility.Hidden; + ResizeMarkTop.Visibility = Visibility.Hidden; + ResizeMarkTopRight.Visibility = Visibility.Hidden; + ResizeMarkLeft.Visibility = Visibility.Hidden; + ResizeMarkRight.Visibility = Visibility.Hidden; + ResizeMarkBottomLeft.Visibility = Visibility.Hidden; + ResizeMarkBottom.Visibility = Visibility.Hidden; + ResizeMarkBottomRight.Visibility = Visibility.Hidden; + } + + private void UpdateResizeMarks() + { + if (Selection is null) return; + + double resizeMarkCenter = ResizeMarkTopLeft.Width / 2; + + ResizeMarkTopLeft.Visibility = Visibility.Visible; + SetLeft(ResizeMarkTopLeft, Selection.Left - resizeMarkCenter); + SetTop(ResizeMarkTopLeft, Selection.Top - resizeMarkCenter); + + ResizeMarkTop.Visibility = Visibility.Visible; + SetLeft(ResizeMarkTop, Selection.Left + Selection.Width / 2 - resizeMarkCenter); + SetTop(ResizeMarkTop, Selection.Top - resizeMarkCenter); + + ResizeMarkTopRight.Visibility = Visibility.Visible; + SetLeft(ResizeMarkTopRight, Selection.Left + Selection.Width - resizeMarkCenter); + SetTop(ResizeMarkTopRight, Selection.Top - resizeMarkCenter); + + ResizeMarkLeft.Visibility = Visibility.Visible; + SetLeft(ResizeMarkLeft, Selection.Left - resizeMarkCenter); + SetTop(ResizeMarkLeft, Selection.Top + Selection.Height / 2 - resizeMarkCenter); + + ResizeMarkRight.Visibility = Visibility.Visible; + SetLeft(ResizeMarkRight, Selection.Left + Selection.Width - resizeMarkCenter); + SetTop(ResizeMarkRight, Selection.Top + Selection.Height / 2 - resizeMarkCenter); + + ResizeMarkBottomLeft.Visibility = Visibility.Visible; + SetLeft(ResizeMarkBottomLeft, Selection.Left - resizeMarkCenter); + SetTop(ResizeMarkBottomLeft, Selection.Top + Selection.Height - resizeMarkCenter); + + ResizeMarkBottom.Visibility = Visibility.Visible; + SetLeft(ResizeMarkBottom, Selection.Left + Selection.Width / 2 - resizeMarkCenter); + SetTop(ResizeMarkBottom, Selection.Top + Selection.Height - resizeMarkCenter); + + ResizeMarkBottomRight.Visibility = Visibility.Visible; + SetLeft(ResizeMarkBottomRight, Selection.Left + Selection.Width - resizeMarkCenter); + SetTop(ResizeMarkBottomRight, Selection.Top + Selection.Height - resizeMarkCenter); + } + private void ClearOpacityRectangles() { foreach (var rectangle in _rectangles) @@ -139,7 +336,7 @@ private void UpdatePanels(Visibility visibility, bool dispatchUpdate = false) { _events?.Dispatch(OnSelectionChangeArgs.From(Selection)); } - + RightPanel.Visibility = visibility; BottomPanel.Visibility = visibility; } @@ -204,8 +401,16 @@ private void MouseLeftButtonPress(MouseButtonEventArgs e) var position = e.GetPosition(this); - _moving = Selection.Contains(position); - _dragging = !_moving; + if (_hoveringResizeMark != 0) + { + _draggingOnResizeMark = true; + } + else + { + _moving = Selection.Contains(position); + _dragging = !_moving; + } + _startPosition = position; _tmpCursorPosition = _startPosition; } @@ -224,6 +429,9 @@ private void MouseLeftButtonRelease() { _dragging = false; _moving = false; + _hoveringResizeMark = 0; + _draggingOnResizeMark = false; + _resizeMarkAnchor = null; _startPosition = null; _tmpCursorPosition = null; @@ -239,15 +447,130 @@ protected override void OnMouseMove(MouseEventArgs e) Cursor = GetCursor(newPosition); - if (_moving) + if (_draggingOnResizeMark) + ResizeSelectionByMarks(newPosition); + else if (_moving) MoveSelection(newPosition); - else if (_dragging) ResizeSelection(newPosition); + else if (_dragging) + ResizeSelection(newPosition); UpdateSelection(); } + private void ResizeSelectionByMarks(Point cursorPosition) + { + if (Selection is null) return; + + var resizeX = false; + var resizeY = false; + + switch (_hoveringResizeMark) + { + case 1: + _resizeMarkAnchor ??= new Point( + Selection.Left + Selection.Width, + Selection.Top + Selection.Height + ); + + resizeX = true; + resizeY = true; + + break; + case 2: + _resizeMarkAnchor ??= new Point( + Selection.Left + Selection.Width / 2, + Selection.Top + Selection.Height + ); + + resizeY = true; + + break; + case 3: + _resizeMarkAnchor ??= new Point( + Selection.Left, + Selection.Top + Selection.Height + ); + + resizeX = true; + resizeY = true; + + break; + case 4: + _resizeMarkAnchor ??= new Point( + Selection.Left + Selection.Width, + Selection.Top + Selection.Height / 2 + ); + + resizeX = true; + + break; + case 5: + _resizeMarkAnchor ??= new Point( + Selection.Left, + Selection.Top + Selection.Height / 2 + ); + + resizeX = true; + + break; + case 6: + _resizeMarkAnchor ??= new Point( + Selection.Left + Selection.Width, + Selection.Top + ); + + resizeX = true; + resizeY = true; + + break; + case 7: + _resizeMarkAnchor ??= new Point( + Selection.Left + Selection.Width / 2, + Selection.Top + ); + + resizeY = true; + + break; + case 8: + _resizeMarkAnchor ??= new Point( + Selection.Left, + Selection.Top + ); + + resizeX = true; + resizeY = true; + + break; + } + + if (_resizeMarkAnchor is not { } anchor) return; + + bool growingX = cursorPosition.X > anchor.X; + bool growingY = cursorPosition.Y > anchor.Y; + + if (resizeX) + { + Selection.Left = growingX ? anchor.X : cursorPosition.X; + Selection.Width = growingX + ? cursorPosition.X - Selection.Left + : anchor.X - Selection.Left; + } + + if (resizeY) + { + Selection.Top = growingY ? anchor.Y : cursorPosition.Y; + Selection.Height = growingY + ? cursorPosition.Y - Selection.Top + : anchor.Y - Selection.Top; + } + } + private Cursor GetCursor(Point point) { + if (_hoveringResizeMark != 0) + return GetHoveringResizeMarkCursor(); + if (Selection is null) return Cursors.Arrow; @@ -258,16 +581,25 @@ private Cursor GetCursor(Point point) return DrawingCanvas.Tool == CanvasTool.Default ? Cursors.Arrow : DrawingCanvas.DrawingCursor; } + private Cursor GetHoveringResizeMarkCursor() => _hoveringResizeMark switch + { + 1 or 8 => Cursors.SizeNWSE, + 2 or 7 => Cursors.SizeNS, + 3 or 6 => Cursors.SizeNESW, + 4 or 5 => Cursors.SizeWE, + _ => throw new ArgumentOutOfRangeException() + }; + private void ResizeSelection(Point cursorPosition) { if (_startPosition is not { } startPosition || Selection is null) return; (double left, double top) = PointUtils.GetCoords(startPosition, cursorPosition); - Selection.Left = (int) left; - Selection.Top = (int) top; - Selection.Width = (int) Math.Abs(startPosition.X - cursorPosition.X); - Selection.Height = (int) Math.Abs(startPosition.Y - cursorPosition.Y); + Selection.Left = (int)left; + Selection.Top = (int)top; + Selection.Width = (int)Math.Abs(startPosition.X - cursorPosition.X); + Selection.Height = (int)Math.Abs(startPosition.Y - cursorPosition.Y); } private void MoveSelection(Point cursorPosition) @@ -308,9 +640,9 @@ private void OnKeyDown(Event e) } if (new[] - { - Key.Up, Key.Right, Key.Down, Key.Left - }.Contains(args.Key)) + { + Key.Up, Key.Right, Key.Down, Key.Left + }.Contains(args.Key)) { UpdatePanels(Visibility.Hidden); UpdateSelection(); diff --git a/LiveShot.UI/Properties/appsettings.json b/LiveShot.UI/Properties/appsettings.json index 325b382..6b27933 100644 --- a/LiveShot.UI/Properties/appsettings.json +++ b/LiveShot.UI/Properties/appsettings.json @@ -1,6 +1,6 @@ { "CultureUI": "en-US", - "UploadType": "CustomExample", + "UploadType": "Imgur", "UploadTypes": { "Imgur": { "ClientID": "d4d456ae8b941e7" diff --git a/LiveShot.UI/Views/CaptureScreenView.xaml b/LiveShot.UI/Views/CaptureScreenView.xaml index eb1c3db..e6c23d5 100644 --- a/LiveShot.UI/Views/CaptureScreenView.xaml +++ b/LiveShot.UI/Views/CaptureScreenView.xaml @@ -23,102 +23,122 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/LiveShot.UI/Views/CaptureScreenView.xaml.cs b/LiveShot.UI/Views/CaptureScreenView.xaml.cs index ca89c48..b0322b3 100644 --- a/LiveShot.UI/Views/CaptureScreenView.xaml.cs +++ b/LiveShot.UI/Views/CaptureScreenView.xaml.cs @@ -3,16 +3,22 @@ using System.Drawing; using System.Linq; using System.Windows; +using System.Windows.Controls; using System.Windows.Forms; using System.Windows.Input; using System.Windows.Media; using LiveShot.API; +using LiveShot.API.Controls.ResizeMarker; using LiveShot.API.Drawing; using LiveShot.API.Events.Input; +using LiveShot.API.Events.Input.ResizeMarker; using LiveShot.API.Utils; using LiveShot.UI.Controls.Button; using Microsoft.Extensions.DependencyInjection; +using Brushes = System.Windows.Media.Brushes; using KeyEventArgs = System.Windows.Input.KeyEventArgs; +using MouseEventArgs = System.Windows.Input.MouseEventArgs; +using Panel = System.Windows.Controls.Panel; namespace LiveShot.UI.Views { @@ -70,9 +76,30 @@ ILiveShotService liveShotService SaveBtn.Click += (_, _) => SaveImage(); CloseBtn.Click += (_, _) => Close(); + foreach ( + var resizeMark in new[] + { + ResizeMarkTopLeft, ResizeMarkTop, ResizeMarkTopRight, + ResizeMarkLeft, ResizeMarkRight, + ResizeMarkBottomLeft, ResizeMarkBottom, ResizeMarkBottomRight + } + ) PrepareResizeMark(resizeMark); + CaptureScreen(); } + private void PrepareResizeMark(Panel resizeMark) + { + resizeMark.MouseEnter += (sender, _) => _events.Dispatch(sender); + resizeMark.MouseLeave += (sender, _) => _events.Dispatch(sender); + + resizeMark.Width = resizeMark.Height = 6; + resizeMark.Background = ResizeMarkerGradient.Striped; + resizeMark.Opacity = 1; + + resizeMark.SetValue(Panel.ZIndexProperty, 2); + } + private void UndoBtnOnClick(object sender, RoutedEventArgs e) { Undo(); @@ -122,7 +149,7 @@ private void Undo() private void CaptureScreen() { (int screenTop, int screenLeft, int screenWidth, int screenHeight) = - ((int, int, int, int)) (Top, Left, Width, Height); + ((int, int, int, int))(Top, Left, Width, Height); var bitmap = ImageUtils.CaptureScreen(screenWidth, screenHeight, screenLeft, screenTop); var bitmapSource = ImageUtils.GetBitmapSource(bitmap);