Skip to content

Commit

Permalink
Merge pull request #9 from KennethGomez/feat/user-experience-improvem…
Browse files Browse the repository at this point in the history
…ents

UX Improvements (#6)
  • Loading branch information
KennethGomez committed Dec 28, 2021
2 parents 20b8e6e + e98fda6 commit 5c9c06c
Show file tree
Hide file tree
Showing 10 changed files with 562 additions and 134 deletions.
27 changes: 27 additions & 0 deletions LiveShot.API/Controls/ResizeMarker/ResizeMarkerGradient.cs
Original file line number Diff line number Diff line change
@@ -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
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace LiveShot.API.Events.Input.ResizeMarker
{
public class OnResizeMarkerMouseEnter : Event
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace LiveShot.API.Events.Input.ResizeMarker
{
public class OnResizeMarkerMouseLeave : Event
{
}
}
2 changes: 1 addition & 1 deletion LiveShot.API/Upload/Imgur/ImgurService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> Upload(Bitmap bitmap)
Expand Down
23 changes: 18 additions & 5 deletions LiveShot.API/Utils/ImageUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

Expand All @@ -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);

Expand Down Expand Up @@ -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
);

Expand Down
15 changes: 6 additions & 9 deletions LiveShot.UI.Controls/Canvas/DrawCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,13 @@ private void OnKeyDown(Event e)

private void OnMouseWheel(Event e)
{
if (KeyBoardUtils.IsCtrlPressed)
if (e.GetArgs<MouseWheelEventArgs>().Delta > 0)
{
if (e.GetArgs<MouseWheelEventArgs>().Delta > 0)
{
DrawingStrokeThickness++;
}
else
{
DrawingStrokeThickness--;
}
DrawingStrokeThickness--;
}
else
{
DrawingStrokeThickness++;
}
}

Expand Down
Loading

0 comments on commit 5c9c06c

Please sign in to comment.