using System;
using System.Collections.Generic;
using System.IO;
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;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace AIRS
{
///
/// Full_Screen_View.xaml 的交互逻辑
///
public partial class Full_Screen_View : Window
{
private Boolean isDown = false;
Point ptDown = new Point();
public String cir_rect = "";
public double zoom_key = 1;
public double rect_left = 0;
public double rect_top = 0;
public Boolean[] feild_change;
public Full_Screen_View()
{
InitializeComponent();
}
ScaleTransform st;
TranslateTransform tt;
TransformGroup group;
bool isDrag = false;
Point startPoint;
public string ProcessFileName = "AI";//传来的文件夹名
public int ProcessOrInitial = 1;//调用本页时查看分析过程图时参数为1,图片放大缩小时为0
public int cureent = 0;//默认选中第一个图片
List picList = new List();//图片列表
public int selectindex = 0;//将来会被弃用
public Dictionary> imglist = new Dictionary>();
public List ImgAnalysisList = new List();//list测试完的图片名分析过程图只是传过来一张
bool isyuantudingwei = true;
private void pdisyuan()
{
if (ProcessOrInitial == 0)
{
isyuantudingwei = true;
}
if (ProcessOrInitial == 1)
{
isyuantudingwei = false;
}
}
///
/// 按键响应
///
///
///
private void MainWindows_Keydown(object sender, System.Windows.Input.KeyEventArgs e)
{
if (Keyboard.IsKeyDown(Key.Left))
{
e.Handled = true;
if (cureent > 0)
{
cureent--;
select_picture_index_path(cureent, picList);
ShowImagesAnalysis(cureent, ImgAnalysisList);
}
//MessageBox.Show("按下了左键!");
}
if (Keyboard.IsKeyDown(Key.Right))
{
e.Handled = true;
if (cureent < picList.Count - 1)
{
cureent++;
select_picture_index_path(cureent, picList);
ShowImagesAnalysis(cureent, ImgAnalysisList);
}
//MessageBox.Show("按下了右键!");
}
if (Keyboard.IsKeyDown(Key.Escape))
{
e.Handled = true;
this.Close();
//MessageBox.Show("按下了右键!");
}
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
this.img_l_f.PreviewMouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(Button_Previous_Click);
this.img_r_f.PreviewMouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(Button_Next_Click);
//ShowImg(selectindex, imglist["imgList"]);
cureent = selectindex;
showProjects();
pdisyuan();
Console.WriteLine("传来的"+ProcessOrInitial);
//ShowImagesAnalysis(cureent,ImgAnalysisList);//检验名称信息列表
//ShowImagesAnalysis(selectindex,ImgAnalysisList);//检验名称信息列表
//ShowCheckBoxTextAndCheck();
group = (TransformGroup)grdMap.RenderTransform;
st = group.Children[0] as ScaleTransform;
tt = group.Children[3] as TranslateTransform;
for(int i=0;i
/// 定位原图
///
///
///
private void Menu_Click_Positionimage(object sender, RoutedEventArgs e)
{
// MainWindow mainWindow = new MainWindow();
if (isyuantudingwei == true)
{
if (File.Exists(imglist["imgList"][cureent]))
{
// MessageBox.Show("有原图" + ProcessOrInitial + isyuan + imglist["imgList"][cureent]);
//mainWindow.OpenFolderAndSelectFile(imglist["imgList"][cureent]);
Common.locateFile(imglist["imgList"][cureent]);
}
}
else
{
if (File.Exists(ListImagesPathParsingProcess(imglist["imgList"])[cureent]))
{
Common.locateFile(ListImagesPathParsingProcess(imglist["imgList"])[cureent]);
//mainWindow.OpenFolderAndSelectFile(ListImagesPathParsingProcess(imglist["imgList"])[cureent]);
// MessageBox.Show("分析过程路径" + ProcessOrInitial + isyuan + ListImagesPathParsingProcess(imglist["imgList"])[cureent]);
}
}
}
///
/// 显示原图或分析过程
///
///
///
private void CheckBox_Click(object sender, RoutedEventArgs e)
{
isyuantudingwei = !isyuantudingwei;
//MessageBox.Show("看卡" + isyuan);
showProjects();
//if (CheckBoxProcessOrInitial.IsChecked == true)
//{
// // ProcessOrInitial = 0;
// showProjects();
// //MessageBox.Show("按下了1键" +CheckBoxProcessOrInitial.IsChecked);
//}
//else
//{
// // ProcessOrInitial = 1;
// showProjects();
// //MessageBox.Show("按下了2键" +CheckBoxProcessOrInitial.IsChecked);
//}
//ShowCheckBoxTextAndCheck();
//if (ProcessOrInitial == 0)
//{
// //ProcessOrInitial = 1;
// //showProjects();
// //MessageBox.Show("按下了右键" +CheckBoxProcessOrInitial.IsChecked);
//}
//if (ProcessOrInitial == 1)
//{
// // ProcessOrInitial = 0;
// // showProjects();
// //MessageBox.Show("按下了右键" + CheckBoxProcessOrInitial.IsChecked);
//}
}
//private void checkboxzt()
//{
// if (ProcessOrInitial == 0)
// {
// CheckBoxProcessOrInitial.Visibility = Visibility.Hidden;
// // CheckBoxProcessOrInitial.IsChecked = true;
// }
// if(ProcessOrInitial == 1)
// {
// CheckBoxProcessOrInitial.Visibility = Visibility.Visible;
// CheckBoxProcessOrInitial.IsChecked = false;
// }
//}
///
/// 根据传来的ProcessOrInitial的值 显示状态
///
private void showProjects()
{
if (ProcessOrInitial == 0)
{
//CheckBoxProcessOrInitial.Content = "显示原图";
//CheckBoxProcessOrInitial.IsChecked = true;
//ShowImg(selectindex, imglist["imgList"]);
ShowImagesAnalysis(cureent, ImgAnalysisList);
ShowImg(cureent, imglist["imgList"]);
CheckBoxProcessOrInitial.Visibility = Visibility.Hidden;
//MessageBox.Show("按下了右键" + CheckBoxProcessOrInitial.IsChecked);
}
if (ProcessOrInitial == 1)
{
CheckBoxProcessOrInitial.Visibility = Visibility.Visible;
// CheckBoxProcessOrInitial.IsChecked = false;
if (CheckBoxProcessOrInitial.IsChecked == true)
{
ShowImagesAnalysis(cureent, ImgAnalysisList);
ShowImg(cureent, imglist["imgList"]);
}
else
{
List list = new List();
//CheckBoxProcessOrInitial.Content = "分析过程";
//CheckBoxProcessOrInitial.IsChecked = true;
list = ListImagesPathParsingProcess(imglist["imgList"]);
//ShowImg(selectindex, imglist["imgList"]);
ShowImagesAnalysis(cureent, ImgAnalysisList);
ShowImg(cureent, list);
}
//MessageBox.Show("按下了右键" + CheckBoxProcessOrInitial.IsChecked);
}
//checkboxzt();
}
private void grdMap_MouseWheel(object sender, MouseWheelEventArgs e)
{
var point = e.GetPosition(grdRelative); // 实际点击的点
var actualPoint = group.Inverse.Transform(point); // 想要缩放的点
slider.Value = slider.Value + (double)e.Delta / 1000;
tt.X = -((actualPoint.X * (slider.Value - 1))) + point.X - actualPoint.X;
tt.Y = -((actualPoint.Y * (slider.Value - 1))) + point.Y - actualPoint.Y;
}
private void grdMap_MouseDown(object sender, MouseButtonEventArgs e)
{
isDrag = true;
startPoint = e.GetPosition(grdRelative);
}
private void grdMap_MouseUp(object sender, MouseButtonEventArgs e)
{
isDrag = false;
}
private void grdMap_MouseLeave(object sender, MouseEventArgs e)
{
isDrag = false;
}
private void grdMap_MouseMove(object sender, MouseEventArgs e)
{
if (isDrag)
{
Point p = e.GetPosition(grdRelative);
Point topPoint = grdMap.TranslatePoint(new Point(0, 0), grdRelative);
Point bottomPoint = grdMap.TranslatePoint(new Point(grdMap.ActualWidth, grdMap.ActualHeight), grdRelative);
double moveX = p.X - startPoint.X;
double moveY = p.Y - startPoint.Y;
//向上向下移动条件判断(会有一点点的小偏移,如果想更精确的控制,那么分向上和向下两种情况,并判断边距)
if ((moveY < 0 && bottomPoint.Y > grdRelative.ActualHeight) || (moveY > 0 && topPoint.Y < 0))
{
tt.Y += (p.Y - startPoint.Y);
startPoint.Y = p.Y;
}
//向左向右移动条件判断
if ((moveX < 0 && bottomPoint.X > grdRelative.ActualWidth) || (moveX > 0 && topPoint.X < 0))
{
tt.X += (p.X - startPoint.X);
startPoint.X = p.X;
}
}
}
///
/// 显示图片
///
///
public void ShowImg(int index,List list)
{
try
{
if (index > -1 && list.Count > 0)
{
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.CacheOption = BitmapCacheOption.OnLoad;
picList = list;
cureent = index;
if (!File.Exists(picList[index]))
{
// Console.WriteLine(picList[index]);
// MessageBox.Show("图片不存在!", "提示您", MessageBoxButton.OK, MessageBoxImage.Warning);
if (!File.Exists(imglist["imgList"][index]))
{
MessageBox.Show("原图片与分析图片都不存在!", "提示您", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
bi.UriSource = new Uri(imglist["imgList"][index]);
bi.EndInit();
// target.Source = new BitmapImage(new Uri(listPics[index]));
target.Source = bi;
showLeftAndRight();
this.show.Text = "未能分析";
return;
}
Uri uri = new Uri(picList[index], UriKind.Absolute);
//bi.BeginInit();
//bi.CacheOption = BitmapCacheOption.OnLoad;
bi.UriSource = uri;
bi.EndInit();
// BitmapImage source = new BitmapImage(uri);
target.Source = bi;
//计算缩放比
int iw = bi.PixelWidth;
int ih = bi.PixelHeight;
double vw = target.Width;
double vh = target.Height;
double propw = iw / vw;
double proph = ih / vh;
if (propw > proph)
{
zoom_key = propw;
rect_top = (vh - ih / propw) / 2;
rect_left = 0;
}
else
{
zoom_key = proph;
rect_top = 0;
rect_left = (vw - iw / proph) / 2;
}
//检测是否有视场文件
if (isyuantudingwei)
{
String field = System.IO.Path.GetDirectoryName(picList[index]) + "\\AI\\";
field = field + System.IO.Path.GetFileNameWithoutExtension(picList[index]) + ".fld";
if (File.Exists(field))
{
StreamReader file = new StreamReader(field);
using (JsonTextReader reader = new JsonTextReader(file))
{
JObject o = (JObject)JToken.ReadFrom(reader);
JObject param = JObject.Parse(o["viewport"].ToString());
string c_r = param["type"].ToString();
if (c_r.ToString() == "C")
{
double r = Convert.ToDouble(param["w"].ToString()) / 2;
double x = Convert.ToDouble(param["x"].ToString()) + r;
double y = Convert.ToDouble(param["y"].ToString()) + r;
this.circle.RadiusX = r / zoom_key;
this.circle.RadiusY = r / this.zoom_key;
this.circle.Center = new Point(x / this.zoom_key + this.rect_left, y / this.zoom_key + this.rect_top);
this.field.Fill = new SolidColorBrush(Color.FromArgb(0x80, 0xFF, 0xFF, 0xFF));
this.fieldr.Fill = new SolidColorBrush(Color.FromArgb(0x80, 0xFF, 0xFF, 0xFF));
this.field.Visibility = Visibility.Visible;
this.fieldr.Visibility = Visibility.Hidden;
}
else
{
double _left = Convert.ToDouble(param["x"].ToString());
double _top = Convert.ToDouble(param["y"].ToString());
double _width = Convert.ToDouble(param["w"].ToString());
double _height = Convert.ToDouble(param["h"].ToString());
this.rectrr.Rect = new Rect(_left / this.zoom_key + this.rect_left, _top / zoom_key + this.rect_top, _width / this.zoom_key, _height / this.zoom_key);
this.field.Fill = new SolidColorBrush(Color.FromArgb(0x80, 0xFF, 0xFF, 0xFF));
this.fieldr.Fill = new SolidColorBrush(Color.FromArgb(0x80, 0xFF, 0xFF, 0xFF));
this.field.Visibility = Visibility.Hidden;
this.fieldr.Visibility = Visibility.Visible;
}
reader.Close();
file.Close();
file.Dispose();
}
}
}
}
else
{
MessageBox.Show("图片在来的路上?", "提示您", MessageBoxButton.OK, MessageBoxImage.Warning);
}
}
catch (Exception e)
{
System.Windows.MessageBox.Show(e.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
}
//for(int i = 0; i < picList.Count; i++)
//{
// Uri uri = new Uri(picList[i], UriKind.Absolute);
// BitmapImage source = new BitmapImage(uri);
// target.Source = source;
// // this.show.Text = source.PixelWidth.ToString();
//}
}
///
/// 显示图片分析数据
///
///
///
///
public void ShowImagesAnalysis(int index, List listAnalysis)
{
try
{
show.Text = listAnalysis[index];
showLeftAndRight();
}
catch (Exception e)
{
System.Windows.MessageBox.Show(e.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
///
/// 上一页
///
///
///
private void Button_Previous_Click(object sender, RoutedEventArgs e)
{
if (cureent > 0)
{
cureent--;
ShowImagesAnalysis(cureent, ImgAnalysisList);
select_picture_index_path(cureent, picList);
}
}
///
/// 下一页
///
///
///
private void Button_Next_Click(object sender, RoutedEventArgs e)
{
if (cureent < picList.Count - 1)
{
cureent++;
ShowImagesAnalysis(cureent, ImgAnalysisList);
select_picture_index_path(cureent, picList);
}
}
///
/// 显示图片//显示分析图片用到了
///
///
///
///
public void select_picture_index_path(int index, List listPics)
{
try
{
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.CacheOption = BitmapCacheOption.OnLoad;
if (!File.Exists(picList[index]))
{
// Console.WriteLine(picList[index]);
// MessageBox.Show("图片不存在!", "提示您", MessageBoxButton.OK, MessageBoxImage.Warning);
if (!File.Exists(imglist["imgList"][index]))
{
MessageBox.Show("原图片与分析图片都不存在!", "提示您", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
bi.UriSource = new Uri(imglist["imgList"][index]);
bi.EndInit();
// target.Source = new BitmapImage(new Uri(listPics[index]));
target.Source = bi;
show.Text = "未能分析";
showLeftAndRight();
return;
}
bi.UriSource = new Uri(listPics[index]);
bi.EndInit();
// target.Source = new BitmapImage(new Uri(listPics[index]));
target.Source = bi;
//计算缩放比
int iw = bi.PixelWidth;
int ih = bi.PixelHeight;
double vw = target.Width;
double vh = target.Height;
double propw = iw / vw;
double proph = ih / vh;
if (propw > proph)
{
zoom_key = propw;
rect_top = (vh - ih / propw) / 2;
rect_left = 0;
}
else
{
zoom_key = proph;
rect_top = 0;
rect_left = (vw - iw / proph) / 2;
}
//检测是否有视场文件
if (isyuantudingwei)
{
String field = System.IO.Path.GetDirectoryName(picList[index]) + "\\AI\\";
field = field + System.IO.Path.GetFileNameWithoutExtension(listPics[index]) + ".fld";
if (File.Exists(field))
{
StreamReader file = new StreamReader(field);
using (JsonTextReader reader = new JsonTextReader(file))
{
JObject o = (JObject)JToken.ReadFrom(reader);
JToken c_r = o["Circle_Rect"];
cir_rect = c_r.ToString();
if (c_r.ToString() == "Circle")
{
JObject circle = JObject.Parse(o["Circle"].ToString());
double r = Convert.ToDouble(circle["Radius"].ToString());
double x = Convert.ToDouble(circle["Center_X"].ToString());
double y = Convert.ToDouble(circle["Center_Y"].ToString());
this.circle.RadiusX = r / zoom_key;
this.circle.RadiusY = r / zoom_key;
this.circle.Center = new Point(x / zoom_key + rect_left, y / zoom_key + rect_top);
this.field.Visibility = Visibility.Visible;
fieldr.Visibility = Visibility.Hidden;
}
else
{
JObject recta = JObject.Parse(o["Rectangle"].ToString());
double _left = Convert.ToDouble(recta["Left"].ToString());
double _top = Convert.ToDouble(recta["Top"].ToString());
double _width = Convert.ToDouble(recta["Width"].ToString());
double _height = Convert.ToDouble(recta["Height"].ToString());
rectrr.Rect = new Rect(_left / zoom_key + rect_left, _top / zoom_key + rect_top, _width / zoom_key, _height / zoom_key);
this.field.Visibility = Visibility.Hidden;
this.fieldr.Visibility = Visibility.Visible;
}
reader.Close();
file.Close();
file.Dispose();
}
}
}
showLeftAndRight();
}
catch (Exception e)
{
System.Windows.MessageBox.Show(e.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
///
/// 移动鼠标时是否显示翻页图标
///
///
///
private void MouseMove_Border(object sender, System.Windows.Input.MouseEventArgs e)
{
Point p = e.GetPosition(this);
double X = p.X;
double Y = p.Y;
double one_four = this.ActualWidth / 4;
if (X > one_four && X < this.grid.ActualWidth - one_four)
{
HiddenLeftAndRight();
//this.btn_close.Visibility = Visibility.Hidden;
//this.img_l_f.Visibility = Visibility.Hidden;
//this.img_r_f.Visibility = Visibility.Hidden;
}
else
{
//this.img_l_f.Visibility = Visibility.Visible;
//this.img_r_f.Visibility = Visibility.Visible;
showLeftAndRight();
// this.btn_close.Visibility = Visibility.Visible;
}
}
///
/// 隐藏上一页下一页
///
public void HiddenLeftAndRight()
{
this.img_l_f.Visibility = Visibility.Hidden;
this.img_r_f.Visibility = Visibility.Hidden;
}
///
/// 显示上一页下一页
///
public void showLeftAndRight()
{
if (picList.Count > 0)
{
if (picList.Count == 1)
{
HiddenLeftAndRight();
}
else
{
if (cureent == 0)
{
this.img_l_f.Visibility = Visibility.Hidden;
this.img_r_f.Visibility = Visibility.Visible;
}
else if (cureent == picList.Count - 1)
{
this.img_l_f.Visibility = Visibility.Visible;
this.img_r_f.Visibility = Visibility.Hidden;
}
else
{
this.img_l_f.Visibility = Visibility.Visible;
this.img_r_f.Visibility = Visibility.Visible;
}
}
}
}
/// 关闭窗口
///
///
///
private void button_close(object sender, RoutedEventArgs e)
{
this.Close();
}
///
/// 上一张 鼠标移动时发生移动时发生
///
///
///
private void Last_Img_MouseMove(object sender, MouseEventArgs e)
{
lasttimgellipse.Fill = new SolidColorBrush(Color.FromRgb(50, 150, 250));
//Uri uri = new Uri("img/u71.png", UriKind.Relative);
//BitmapImage img = new BitmapImage(uri);
//img_l.Source = img;
}
///
/// 上一张 鼠标移除后发生
///
///
///
private void Last_Img_MouseLeave(object sender, MouseEventArgs e)
{
lasttimgellipse.Fill = new SolidColorBrush(Color.FromRgb(16, 133, 250));
//Uri uri = new Uri("img/u7.png",UriKind.Relative);
//BitmapImage img = new BitmapImage(uri);
//img_l.Source = img;
//lasttimgellipse.ReleaseMouseCapture();
}
///
/// 下一张 鼠标移动时发生移动时发生
///
///
///
private void Next_Img_MouseMove(object sender, MouseEventArgs e)
{
nextimgellipse.Fill = new SolidColorBrush(Color.FromRgb(50, 150, 250));
//Uri uri = new Uri("img/u91.png", UriKind.Relative);
//BitmapImage img = new BitmapImage(uri);
//img_r.Source = img;
}
///
/// 上一张 鼠标移除后发生
///
///
///
private void Next_Img_MouseLeave(object sender, MouseEventArgs e)
{
nextimgellipse.Fill = new SolidColorBrush(Color.FromRgb(16, 133, 250));
//Uri uri = new Uri("img/u9.png", UriKind.Relative);
//BitmapImage img = new BitmapImage(uri);
//img_r.Source = img;
}
///
/// 关闭 鼠标移动时发生移动时发生
///
///
///
private void btn_MouseEnter(object sender, MouseEventArgs e)
{
btn_close.Foreground =new SolidColorBrush(Colors.Black);
}
///
/// 关闭 鼠标移除后发生
///
///
///
private void btn_MouseLeave(object sender, MouseEventArgs e)
{
btn_close.Foreground = new SolidColorBrush(Colors.White);
}
///
/// 显示checkbox文本以及选中状态
///
//private void ShowCheckBoxTextAndCheck()
//{
// if (ProcessOrInitial == 0)
// {
// // ProcessOrInitial = 1;
// CheckBoxProcessOrInitial.Content = "显示原图";
// CheckBoxProcessOrInitial.IsChecked = true;
// //MessageBox.Show("按下了右键" + CheckBoxProcessOrInitial.IsChecked);
// }
// if (ProcessOrInitial == 1)
// {
// // ProcessOrInitial = 0;
// CheckBoxProcessOrInitial.Content = "分析过程";
// CheckBoxProcessOrInitial.IsChecked = true;
// //MessageBox.Show("按下了右键" + CheckBoxProcessOrInitial.IsChecked);
// }
//}
///
/// 分析过程的图片列表
///
private List ListImagesPathParsingProcess(List list)
{
List fxlist = new List();
try
{
if (list.Count > 0)
{
DirectoryInfo root = new DirectoryInfo(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(list[0]), ProcessFileName));
if (Directory.Exists(root.ToString()))
{
FileInfo[] files = root.GetFiles();
//if (files.Length > 0)
//{
// foreach (FileInfo li in files)
// {
// fxlist.Add(li.FullName);
// //Console.WriteLine("111 " + li.FullName);//路径加图片名
// }
//}
//else
//{
// MessageBox.Show("没有任何文件!");
//}
for (int i = 0; i < list.Count; i++)
{
string path = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(list[i]), ProcessFileName, System.IO.Path.GetFileName(list[i]));
fxlist.Add(path);
//Console.WriteLine(path);
}
}
else
{
DirectoryInfo directoryInfo = new DirectoryInfo(root.ToString());
directoryInfo.Create();
for (int i = 0; i < list.Count; i++)
{
string path = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(list[i]), ProcessFileName, System.IO.Path.GetFileName(list[i]));
fxlist.Add(path);
//Console.WriteLine(path);
}
//MessageBox.Show(root.ToString()+"文件夹不存在!");
}
}
}
catch (Exception e)
{
System.Windows.MessageBox.Show(e.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
}
return fxlist;
}
private void can_tar_MouseDown(object sender, MouseButtonEventArgs e)
{
ptDown = e.GetPosition((IInputElement)sender);
if (cir_rect == "Circle")
{
double liner = Math.Pow(ptDown.X - circle.Center.X, 2.0) + Math.Pow(ptDown.Y - circle.Center.Y, 2.0);
if (liner > Math.Pow(circle.RadiusX, 2.0))
{
return;
}
}
else
{
if (ptDown.X < rectrr.Rect.X || ptDown.X > (rectrr.Rect.X + rectrr.Rect.Width) ||
ptDown.Y < rectrr.Rect.Y || ptDown.Y > (rectrr.Rect.Y + rectrr.Rect.Height))
{
return;
}
}
this.Cursor = System.Windows.Input.Cursors.Hand;
isDown = true;
}
private void can_tar_MouseMove(object sender, MouseEventArgs e)
{
if (isDown)
{
this.Cursor = System.Windows.Input.Cursors.ScrollAll;
if (cir_rect == "Circle")
{
Point pt = e.GetPosition((IInputElement)sender);
double x = pt.X - ptDown.X;
double y = pt.Y - ptDown.Y;
Point ptm = circle.Center;
ptm.X = ptm.X + x;
ptm.Y = ptm.Y + y;
ptDown = new Point(ptDown.X + x, ptDown.Y + y);
circle.Center = new Point(circle.Center.X + x, circle.Center.Y + y);
//判断圆是否出图像
if ((circle.Center.X - circle.RadiusX) < rect_left)
{
circle.Center = new Point(circle.RadiusX + rect_left, circle.Center.Y);
}
if ((circle.Center.Y - circle.RadiusY) < rect_top)
{
circle.Center = new Point(circle.Center.X, circle.RadiusY + rect_top);
}
if ((circle.Center.X + circle.RadiusX) > (target.Width - rect_left))
{
circle.Center = new Point(target.Width - rect_left - circle.RadiusX, circle.Center.Y);
}
if ((circle.Center.Y + circle.RadiusY) > (target.Height - rect_top))
{
circle.Center = new Point(circle.Center.X, target.Height - rect_top - circle.RadiusY);
}
}
else
{
Point pt = e.GetPosition((IInputElement)sender);
double x = pt.X - ptDown.X;
double y = pt.Y - ptDown.Y;
Rect rtm = rectrr.Rect;
rtm.X = rtm.X + x;
rtm.Y = rtm.Y + y;
ptDown = new Point(ptDown.X + x, ptDown.Y + y);
rectrr.Rect = rtm;
if (rectrr.Rect.X < rect_left)
{
rtm.X = rect_left;
rectrr.Rect = rtm;
}
if (rectrr.Rect.Y < rect_top)
{
rtm.Y = rect_top;
rectrr.Rect = rtm;
}
if ((rectrr.Rect.X + rectrr.Rect.Width) > (target.Width - rect_left))
{
rtm.X = target.Width - rect_left - rectrr.Rect.Width;
rectrr.Rect = rtm;
}
if ((rectrr.Rect.Y + rectrr.Rect.Height) > (target.Height - rect_top))
{
rtm.Y = target.Height - rect_top - rectrr.Rect.Height;
rectrr.Rect = rtm;
}
}
}
}
private void can_tar_MouseUp(object sender, MouseButtonEventArgs e)
{
if (isDown == true)
{
isDown = false;
feild_change[cureent] = true;
this.Cursor = System.Windows.Input.Cursors.Arrow;
}
}
private void can_tar_MouseLeave(object sender, MouseEventArgs e)
{
if (isDown == true)
{
isDown = false;
feild_change[cureent] = true;
this.Cursor = System.Windows.Input.Cursors.Arrow;
}
}
}
}