Skip to content

Dev merged into master #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions src/WPFDevelopers.Shared/Controls/CropAvatar/CropAvatar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static CropAvatar()

public ImageSource OutImageSource
{
get => (ImageSource)GetValue(OutImageSourceProperty);
get => (ImageSource) GetValue(OutImageSourceProperty);
set => SetValue(OutImageSourceProperty, value);
}

Expand Down Expand Up @@ -95,19 +95,20 @@ private void Image_MouseLeave(object sender, MouseEventArgs e)
SettingPoint();
}

void SettingPoint()
private void SettingPoint()
{
if (isLeft == true)
{
_StartX = Canvas.GetLeft(image);
initialX = voffsetX;
}
else if(isLeft == false)
else if (isLeft == false)
{
_StartY = Canvas.GetTop(image);
initialY = voffsetY;
}
}

private void Image_MouseUp(object sender, MouseButtonEventArgs e)
{
if (isDown)
Expand All @@ -127,7 +128,7 @@ private void Image_MouseMove(object sender, MouseEventArgs e)
if (vNewStartX <= xPath && vNewStartX >= -(bitmapFrame.Width - 200 - xPath))
{
Canvas.SetLeft(image, vNewStartX);
voffsetX = initialX - (int)Math.Round(voffset);
voffsetX = initialX - (int) Math.Round(voffset);
voffsetX = voffsetX < 0 ? 0 : voffsetX;
crop = new CroppedBitmap(bitmapFrame, new Int32Rect(voffsetX, 0, _size, _size));
}
Expand All @@ -140,11 +141,12 @@ private void Image_MouseMove(object sender, MouseEventArgs e)
if (vNewStartY <= yPath && vNewStartY >= -(bitmapFrame.Height - 200 - yPath))
{
Canvas.SetTop(image, vNewStartY);
voffsetY = initialY - (int)Math.Round(voffset);
voffsetY = initialY - (int) Math.Round(voffset);
voffsetY = voffsetY < 0 ? 0 : voffsetY;
crop = new CroppedBitmap(bitmapFrame, new Int32Rect(0, voffsetY, _size, _size));
}
}

OutImageSource = crop;
}
}
Expand Down Expand Up @@ -197,7 +199,7 @@ private void InitialImage()
isLeft = null;
}

bitmapFrame = ControlsHelper.CreateResizedImage(bitmap, (int)image.Width, (int)image.Height, 0);
bitmapFrame = ControlsHelper.CreateResizedImage(bitmap, (int) image.Width, (int) image.Height, 0);
image.Source = bitmapFrame;
if (image.Source != null)
{
Expand All @@ -213,18 +215,21 @@ private void InitialImage()
Canvas.SetTop(image, _StartY);
if (isLeft == true)
{
initialX = ((int)image.Width - 200) / 2;
initialX = ((int) image.Width - 200) / 2;
initialY = 0;
crop = new CroppedBitmap(bitmapFrame, new Int32Rect(initialX, 0, _size, _size));
}
else if (isLeft == false)
{
initialY = ((int)image.Height - 200) / 2;
initialY = ((int) image.Height - 200) / 2;
initialX = 0;
crop = new CroppedBitmap(bitmapFrame, new Int32Rect(0, initialY, _size, _size));
}
else
{
crop = new CroppedBitmap(bitmapFrame, new Int32Rect(0, 0, _size, _size));
}

OutImageSource = crop;
}
}
Expand Down
80 changes: 43 additions & 37 deletions src/WPFDevelopers.Shared/Controls/CropImage/CropImage.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Windows;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
Expand All @@ -25,56 +24,61 @@ public class CropImage : Control
private const string RectangleBottomTemplateName = "PART_RectangleBottom";
private const string BorderTemplateName = "PART_Border";

private BitmapFrame bitmapFrame;
private Rectangle _rectangleLeft, _rectangleTop, _rectangleRight, _rectangleBottom;
public static readonly DependencyProperty SourceProperty =
DependencyProperty.Register("Source", typeof(ImageSource), typeof(CropImage),
new PropertyMetadata(null, OnSourceChanged));

public static readonly DependencyProperty CurrentRectProperty =
DependencyProperty.Register("CurrentRect", typeof(Rect), typeof(CropImage), new PropertyMetadata(null));

public static readonly DependencyProperty CurrentAreaBitmapProperty =
DependencyProperty.Register("CurrentAreaBitmap", typeof(ImageSource), typeof(CropImage),
new PropertyMetadata(null));

private Border _border;
private Canvas _canvas;
private Rectangle _rectangleLeft, _rectangleTop, _rectangleRight, _rectangleBottom;

public ImageSource Source

private AdornerLayer adornerLayer;

private BitmapFrame bitmapFrame;
private bool isDragging;
private double offsetX, offsetY;
private ScreenCutAdorner screenCutAdorner;

static CropImage()
{
get { return (ImageSource)GetValue(SourceProperty); }
set { SetValue(SourceProperty, value); }
DefaultStyleKeyProperty.OverrideMetadata(typeof(CropImage),
new FrameworkPropertyMetadata(typeof(CropImage)));
}

public static readonly DependencyProperty SourceProperty =
DependencyProperty.Register("Source", typeof(ImageSource), typeof(CropImage), new PropertyMetadata(null, OnSourceChanged));
public ImageSource Source
{
get => (ImageSource) GetValue(SourceProperty);
set => SetValue(SourceProperty, value);
}

public Rect CurrentRect
{
get { return (Rect)GetValue(CurrentRectProperty); }
private set { SetValue(CurrentRectProperty, value); }
get => (Rect) GetValue(CurrentRectProperty);
private set => SetValue(CurrentRectProperty, value);
}

public static readonly DependencyProperty CurrentRectProperty =
DependencyProperty.Register("CurrentRect", typeof(Rect), typeof(CropImage), new PropertyMetadata(null));


public ImageSource CurrentAreaBitmap
{
get { return (ImageSource)GetValue(CurrentAreaBitmapProperty); }
private set { SetValue(CurrentAreaBitmapProperty, value); }
get => (ImageSource) GetValue(CurrentAreaBitmapProperty);
private set => SetValue(CurrentAreaBitmapProperty, value);
}

public static readonly DependencyProperty CurrentAreaBitmapProperty =
DependencyProperty.Register("CurrentAreaBitmap", typeof(ImageSource), typeof(CropImage), new PropertyMetadata(null));


private AdornerLayer adornerLayer;
private ScreenCutAdorner screenCutAdorner;
private bool isDragging;
private double offsetX, offsetY;
private static void OnSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var crop = (CropImage)d;
var crop = (CropImage) d;
if (crop != null)
crop.DrawImage();
}

static CropImage()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(CropImage),
new FrameworkPropertyMetadata(typeof(CropImage)));
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
Expand All @@ -87,7 +91,7 @@ public override void OnApplyTemplate()
DrawImage();
}

void DrawImage()
private void DrawImage()
{
if (Source == null)
{
Expand All @@ -98,9 +102,10 @@ void DrawImage()
adornerLayer = null;
return;
}

_border.Visibility = Visibility.Visible;
var bitmap = (BitmapImage)Source;
bitmapFrame = ControlsHelper.CreateResizedImage(bitmap, (int)bitmap.Width, (int)bitmap.Height, 0);
var bitmap = (BitmapImage) Source;
bitmapFrame = ControlsHelper.CreateResizedImage(bitmap, (int) bitmap.Width, (int) bitmap.Height, 0);
_canvas.Width = bitmap.Width;
_canvas.Height = bitmap.Height;
_canvas.Background = new ImageBrush(bitmap);
Expand Down Expand Up @@ -163,7 +168,7 @@ private void Border_MouseMove(object sender, MouseEventArgs e)
}
}

void Render()
private void Render()
{
var cy = Canvas.GetTop(_border);
cy = cy < 0 ? 0 : cy;
Expand Down Expand Up @@ -200,6 +205,7 @@ private void Border_SizeChanged(object sender, SizeChangedEventArgs e)
{
Render();
}

private CroppedBitmap CutBitmap()
{
var width = _border.Width;
Expand All @@ -210,8 +216,8 @@ private CroppedBitmap CutBitmap()
var top = Canvas.GetTop(_border);
CurrentRect = new Rect(left, top, width, height);
return new CroppedBitmap(bitmapFrame,
new Int32Rect((int)CurrentRect.X, (int)CurrentRect.Y, (int)CurrentRect.Width, (int)CurrentRect.Height));

new Int32Rect((int) CurrentRect.X, (int) CurrentRect.Y, (int) CurrentRect.Width,
(int) CurrentRect.Height));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static readonly DependencyProperty MaxDropDownHeightProperty

public bool IsDropDownOpen
{
get => (bool)GetValue(IsDropDownOpenProperty);
get => (bool) GetValue(IsDropDownOpenProperty);
set => SetValue(IsDropDownOpenProperty, value);
}

Expand All @@ -54,7 +54,7 @@ public bool IsDropDownOpen
[TypeConverter(typeof(LengthConverter))]
public double MaxDropDownHeight
{
get => (double)GetValue(MaxDropDownHeightProperty);
get => (double) GetValue(MaxDropDownHeightProperty);
set => SetValue(MaxDropDownHeightProperty, value);
}

Expand All @@ -68,29 +68,29 @@ public object SelectAllContent

public bool IsSelectAllActive
{
get => (bool)GetValue(IsSelectAllActiveProperty);
get => (bool) GetValue(IsSelectAllActiveProperty);
set => SetValue(IsSelectAllActiveProperty, value);
}


public string Delimiter
{
get => (string)GetValue(DelimiterProperty);
get => (string) GetValue(DelimiterProperty);
set => SetValue(DelimiterProperty, value);
}


public string Text
{
get => (string)GetValue(TextProperty);
get => (string) GetValue(TextProperty);
set => SetValue(TextProperty, value);
}

private static void OnIsDropDownOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var MultiSelectComboBox = (MultiSelectComboBox)d;
var MultiSelectComboBox = (MultiSelectComboBox) d;

if (!(bool)e.NewValue)
if (!(bool) e.NewValue)
MultiSelectComboBox.Dispatcher.BeginInvoke(new Action(() => { Mouse.Capture(null); }),
DispatcherPriority.Send);
}
Expand Down Expand Up @@ -156,7 +156,6 @@ protected virtual void UpdateText()
SetCurrentValue(TextProperty, newValue);
_ignoreTextValueChanged = false;
}

}

protected object GetItemDisplayValue(object item)
Expand Down
Loading