private void movingVideo(Point pos) { TransformParam st = ViewModel.DisplayModel.VideoTransform; Vector vec = pos - _downPoint; if (vec.X > _mvLeft.X) { vec.X = _mvLeft.X; } if (vec.Y > _mvLeft.Y) { vec.Y = _mvLeft.Y; } if (vec.X < _mvRight.X) { vec.X = _mvRight.X; } if (vec.Y < _mvRight.Y) { vec.Y = _mvRight.Y; } Point p = _mvLeft - vec; st.TranslateX = -p.X; st.TranslateY = -p.Y; }
private void Button_PreviewMouseDown(object sender, MouseButtonEventArgs e) { _moving = true; Button btn = e.Source as Button; if (btn == null) { return; } Console.WriteLine(btn); m_startPos = e.GetPosition(gridArcBall); btn.AddHandler(Button.MouseMoveEvent, new RoutedEventHandler(Button_MouseMove), true); //计算控制按钮的平移 GeneralTransform gt = btn.TransformToVisual(gridArcBall); Point center = gt.Transform(new Point(btn.ActualWidth / 2, btn.ActualHeight / 2)); //获取旋转角度。 double angle = getRotateAngle(center); //计算相对中心点偏移量。 Point refCenter = new Point(center.X - gridArcBall.ActualWidth / 2, center.Y - gridArcBall.ActualHeight / 2); double maxLen = (gridArcBall.ActualHeight - btn.ActualHeight) / 2; TransformParam tp = (TransformParam)btnCtrlArrow.DataContext; tp.TranslateX = center.X - btnCtrlArrow.ActualWidth / 2; tp.TranslateY = center.Y - btnCtrlArrow.ActualHeight / 2; tp.RotateAngle = angle; if (!btn.Equals(btnCenter)) { SetPTZSpeed(refCenter.X / maxLen, refCenter.Y / maxLen); } Console.WriteLine("MouseDown"); }
//重新计算缩放和平移。 private void GridMain_SizeChanged(object sender, SizeChangedEventArgs e) { TransformParam tp = ViewModel.DisplayModel.VideoTransform; Vector transVec = new Vector(tp.TranslateX, tp.TranslateY); transVec = calcTranslate(transVec, tp); tp.TranslateX = transVec.X; tp.TranslateY = transVec.Y; }
private bool beginMoveVideo() { TransformParam st = ViewModel.DisplayModel.VideoTransform; if (st.ScaleX <= 1 && st.ScaleY <= 1) { return(false); } else { _mvLeft = gridMain.TranslatePoint(new Point(), videoDisp); _mvRight = gridMain.TranslatePoint(new Point(gridMain.ActualWidth, gridMain.ActualHeight), videoDisp); _mvRight = new Point(_mvRight.X - videoDisp.ActualWidth, _mvRight.Y - videoDisp.ActualHeight); _mvLeft = new Point(_mvLeft.X * st.ScaleX, _mvLeft.Y * st.ScaleY); _mvRight = new Point(_mvRight.X * st.ScaleX, _mvRight.Y * st.ScaleY); return(true); } }
private Vector calcTranslate(Vector vec, TransformParam tp) { if (vec.X > 0) { vec.X = 0; } if (vec.Y > 0) { vec.Y = 0; } double realW = videoDisp.ActualWidth * tp.ScaleX; double realH = videoDisp.ActualHeight * tp.ScaleY; if (vec.X + realW < gridMain.ActualWidth) { vec.X = gridMain.ActualWidth - realW; } if (vec.Y + realH < gridMain.ActualHeight) { vec.Y = gridMain.ActualHeight - realH; } return(vec); }
private void scaleVideo(MouseWheelEventArgs e) { TransformParam tp = ViewModel.DisplayModel.VideoTransform; Point p = e.GetPosition(videoDisp); if (e.Delta > 0 && tp.ScaleX <= 4.9) { tp.ScaleY = tp.ScaleX = tp.ScaleX + 0.1; } else if (e.Delta < 0 && tp.ScaleX > 1) { tp.ScaleY = tp.ScaleX = tp.ScaleX - 0.1; } p = new Point(p.X * tp.ScaleX, p.Y * tp.ScaleY); Point parentPos = e.GetPosition(gridMain); Vector transVec = parentPos - p; transVec = calcTranslate(transVec, tp); tp.TranslateX = transVec.X; tp.TranslateY = transVec.Y; }
private void Button_MouseMove(object sender, RoutedEventArgs e) { if (!_moving) { return; } Button btn = e.Source as Button; if (btn == null) { return; } Point pnt = ((MouseEventArgs)e).GetPosition(gridArcBall); Point temp = new Point(pnt.X - m_startPos.X, pnt.Y - m_startPos.Y); //计算控制按钮的平移 GeneralTransform gt = btn.TransformToVisual(gridArcBall); Point center = gt.Transform(new Point(btn.ActualWidth / 2, btn.ActualHeight / 2)); center = new Point(center.X + temp.X, center.Y + temp.Y); //计算相对中心点偏移量。 Point refCenter = new Point(center.X - gridArcBall.ActualWidth / 2, center.Y - gridArcBall.ActualHeight / 2); double len = Math.Sqrt(refCenter.X * refCenter.X + refCenter.Y * refCenter.Y); double maxLen = (gridArcBall.ActualHeight - btn.ActualHeight) / 2; if (len >= maxLen) { double scale = maxLen / len; refCenter.X *= scale; refCenter.Y *= scale; len = maxLen; } //获取旋转角度。 double angle = getRotateAngle(center); //计算速度提示条的平移量。 double ratio = 1d - (btn.ActualWidth + speedBar1.ActualWidth) / 2 / len; Point speedCenter = new Point(refCenter.X * ratio, refCenter.Y * ratio); speedCenter = new Point(speedCenter.X + gridArcBall.ActualWidth / 2, speedCenter.Y + gridArcBall.ActualHeight / 2); //变换速度提示条。 TransformParam scTP = (TransformParam)speedBar1.DataContext; scTP.TranslateX = speedCenter.X - speedBar1.ActualWidth / 2; scTP.TranslateY = speedCenter.Y - speedBar1.ActualHeight / 2; scTP.RotateAngle = angle; center = new Point(refCenter.X + gridArcBall.ActualWidth / 2, refCenter.Y + gridArcBall.ActualHeight / 2); TransformParam tp = (TransformParam)btnCtrlArrow.DataContext; tp.TranslateX = center.X - btnCtrlArrow.ActualWidth / 2; tp.TranslateY = center.Y - btnCtrlArrow.ActualHeight / 2; tp.RotateAngle = angle; //设置速度 if (Math.Abs(temp.X) > 0 || Math.Abs(temp.Y) > 0) { lock (_obj) _curPosition = new Point(refCenter.X / maxLen, refCenter.Y / maxLen); //SetPTZSpeed(refCenter.X / maxLen, refCenter.Y / maxLen); } speedBar1.Speed = len / maxLen; }