using ivf_tl_Entity.GlobalEntitys;
using ivf_tl_Operate.CustomUserControls;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace ivf_tl_Operate.Windows
{
///
/// PhotoWindowNew.xaml 的交互逻辑
///
public partial class PhotoWindowNew : Window
{
public PictureView currentPhoto = null;
public bool isSource = false;
public PhotoWindowNew(ObservableCollection photoBoxes, long id,bool _isSource)
{
InitializeComponent();
this.Owner = AppData.Instance.MainWindow;
//CurrentEmbryo = embryo;
Photos = new List(photoBoxes);
isSource = _isSource;
var a = Photos.FirstOrDefault(x => x.Num == id);
if (a == null) return;
currentPhoto = a;
CurrentNum = Photos.IndexOf(currentPhoto);
InitPic();
}
public void InitPic()
{
TransformGroup transformGroup = new TransformGroup();
ScaleTransform sfr = new ScaleTransform();//缩放
transformGroup.Children.Add(sfr);
TranslateTransform ttf = new TranslateTransform();//平移
transformGroup.Children.Add(ttf);
string imageurl = currentPhoto.imageUrl;
if (isSource) imageurl = currentPhoto.sourceImageUrl;
Image currentImage = new Image
{
Source = AppData.Instance.ConvertHelper.StringToBitmapImage($"{AppData.Instance.BaseUrl}{imageurl}?token={AppData.Instance.HttpHelper.GetToken()}"),
Cursor = Cursors.Hand,
RenderTransform = transformGroup,
};
currentImage.MouseWheel += (s, arg) =>
{
Point centerPoint = arg.GetPosition(_container);
sfr.CenterX = centerPoint.X;
sfr.CenterY = centerPoint.Y;
var delta = arg.Delta * 0.001;
if (sfr.ScaleX + delta < 0.1) return;
if (sfr.ScaleX + delta > 4.0) return;
sfr.ScaleX += arg.Delta * 0.001;
sfr.ScaleY += arg.Delta * 0.001;
};
Point StartPosition = new Point();
Point EndPosition = new Point();
currentImage.MouseDown += (s, arg) =>
{
StartPosition = arg.GetPosition(currentImage);
};
currentImage.MouseMove += (s, arg) =>
{
if (arg.LeftButton != MouseButtonState.Pressed) return;
EndPosition = arg.GetPosition(currentImage);
var X = EndPosition.X - StartPosition.X;
var Y = EndPosition.Y - StartPosition.Y;
ttf.X += X;
ttf.Y += Y;
};
this._container.Child = currentImage;
//this._textbox.Text = currentPhoto.Name;
}
public int CurrentNum
{
get { return (int)GetValue(CurrentNumProperty); }
set { SetValue(CurrentNumProperty, value); }
}
// Using a DependencyProperty as the backing store for CurrentNum. This enables animation, styling, binding, etc...
public static readonly DependencyProperty CurrentNumProperty =
DependencyProperty.Register("CurrentNum", typeof(int), typeof(PhotoWindowNew), new PropertyMetadata(-1));
public int AllPicNum
{
get { return (int)GetValue(AllPicNumProperty); }
set { SetValue(AllPicNumProperty, value); }
}
// Using a DependencyProperty as the backing store for AllPicNum. This enables animation, styling, binding, etc...
public static readonly DependencyProperty AllPicNumProperty =
DependencyProperty.Register("AllPicNum", typeof(int), typeof(PhotoWindowNew), new PropertyMetadata(0));
public List Photos
{
get { return (List)GetValue(PhotosProperty); }
set { SetValue(PhotosProperty, value); }
}
// Using a DependencyProperty as the backing store for Photos. This enables animation, styling, binding, etc...
public static readonly DependencyProperty PhotosProperty =
DependencyProperty.Register("Photos", typeof(List), typeof(PhotoWindowNew), new PropertyMetadata(new List(), new PropertyChangedCallback(PhotosPropertyChanged)));
private static void PhotosPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (!(d is PhotoWindowNew source)) return;
if (!(e.NewValue is List newValue))
{
return;
}
source.AllPicNum = newValue.Count;
}
private void ZoomMax_MouseUp(object sender, MouseButtonEventArgs e)
{
Image image = this._container.Child as Image;
if (image == null) return;
TransformGroup transformGroup = image.RenderTransform as TransformGroup;
ScaleTransform scaleTransform = transformGroup.Children[0] as ScaleTransform;
scaleTransform.CenterX = 560;
scaleTransform.CenterY = 560;
scaleTransform.ScaleX += 0.1;
scaleTransform.ScaleY += 0.1;
}
private void ZoomMin_MouseUp(object sender, MouseButtonEventArgs e)
{
Image image = this._container.Child as Image;
if (image == null) return;
TransformGroup transformGroup = image.RenderTransform as TransformGroup;
ScaleTransform scaleTransform = transformGroup.Children[0] as ScaleTransform;
scaleTransform.CenterX = 560;
scaleTransform.CenterY = 560;
if (scaleTransform.ScaleX > 0.1)
{
scaleTransform.ScaleX -= 0.1;
scaleTransform.ScaleY -= 0.1;
}
}
private void Image_MouseUp(object sender, MouseButtonEventArgs e)
{
this.Close();
}
private void SingleImageExport_MouseUp(object sender, MouseButtonEventArgs e)
{
}
private void PreviousPic_MouseUp(object sender, MouseButtonEventArgs e)
{
if (CurrentNum == -1)
{
CurrentNum = Photos.IndexOf(currentPhoto);
if (CurrentNum > 0)
{
currentPhoto = Photos[--CurrentNum];
InitPic();
}
}
else
{
if (CurrentNum > 0)
{
currentPhoto = Photos[--CurrentNum];
InitPic();
}
}
}
private void NextPic_MouseUp(object sender, MouseButtonEventArgs e)
{
if (CurrentNum == -1)
{
CurrentNum = Photos.IndexOf(currentPhoto);
if (CurrentNum != -1 && CurrentNum < (Photos.Count - 1))
{
currentPhoto = Photos[++CurrentNum];
InitPic();
}
}
else
{
if (CurrentNum < (Photos.Count - 1))
{
currentPhoto = Photos[++CurrentNum];
InitPic();
}
}
}
}
}