public override void ToWorldSpace(ViewPort vp) { if (worldPoints == null) { worldPoints = new List <Point>(); } else { worldPoints.Clear(); } for (int i = 0; i < points.Count; i++) { var point = new Point((points[i].X - vp.StartPoint.X) * vp.Scale, (points[i].Y - vp.StartPoint.Y) * vp.Scale); worldPoints.Add(point); } }
override public void Draw(DrawingContext drawingContext, ViewPort vp) { var geometry = new StreamGeometry(); using (StreamGeometryContext ctx = geometry.Open()) { ctx.BeginFigure(worldPoints[0], true, false); foreach (var point in worldPoints) { ctx.LineTo(point, true, true); } } var center = new Point(geometry.Bounds.X + geometry.Bounds.Width / 2, geometry.Bounds.Y + geometry.Bounds.Height / 2); drawingContext.PushTransform(new RotateTransform(rotationAngle, center.X, center.Y)); drawingContext.PushTransform(new ScaleTransform(scale, scale, center.X, center.Y)); drawingContext.PushTransform(new TranslateTransform(offsetX, offsetY)); drawingContext.DrawGeometry(brush, p, geometry); }
public override void MouseRightUpHandler(ViewPort vp, Point point) { StartPoint = point; if (vp.Scale > 0.1) { double NewWidth = (vp.EndPoint.X - vp.StartPoint.X) * 2; double NewHeight = (vp.EndPoint.Y - vp.StartPoint.Y) * 2; vp.StartPoint = new Point() { X = StartPoint.X / vp.Scale + vp.StartPoint.X - NewWidth / 2, Y = StartPoint.Y / vp.Scale + vp.StartPoint.Y - NewHeight / 2 }; vp.EndPoint = new Point() { X = vp.StartPoint.X + NewWidth, Y = vp.StartPoint.Y + NewHeight }; vp.Scale /= 2; } }
public override void MouseUpHandler(ViewPort vp) { currentState = States.initial; PaintController.figures.RemoveLast(); if (vp.Scale > 50) { return; } if (Point.Subtract(StartPoint, EndPoint).Length > 2) { double scaleX = (vp.EndPoint.X - vp.StartPoint.X) / (EndPoint.X - StartPoint.X); double scaleY = (vp.EndPoint.Y - vp.StartPoint.Y) / (EndPoint.Y - StartPoint.Y); double scale = (scaleX + scaleY) / 2; vp.Scale *= scale; vp.StartPoint = StartPoint; vp.EndPoint = EndPoint; } else { double NewWidth = (vp.EndPoint.X - vp.StartPoint.X) / 2; double NewHeight = (vp.EndPoint.Y - vp.StartPoint.Y) / 2; vp.StartPoint = new Point() { X = StartPoint.X - NewWidth / 2, Y = StartPoint.Y - NewHeight / 2 }; vp.EndPoint = new Point() { X = vp.StartPoint.X + NewWidth, Y = vp.StartPoint.Y + NewHeight }; vp.Scale *= 2; } }
public virtual void EditSize(Point point, ViewPort vp) { point = ToLocalSpace(point, vp); secondPoint = point; }
public Point ToLocalSpace(Point point, ViewPort vp) => new Point(point.X / vp.Scale + vp.StartPoint.X, point.Y / vp.Scale + vp.StartPoint.Y);
public abstract void Draw(DrawingContext drawingContext, ViewPort vp);
public override void MouseDownHandler(Point point1, ViewPort vp) { StartPoint = point1; currentState = States.mouseClick; }
override abstract public void Draw(DrawingContext drawingContext, ViewPort vp);
public override void EditSize(Point point, ViewPort vp) { point = ToLocalSpace(point, vp); points.Add(point); }
public virtual void MouseRightUpHandler(ViewPort vp, Point point) { }
public virtual void MouseUpHandler(ViewPort vp) { currentState = States.initial; }
public abstract void MouseMoveHandler(Point secondPoint, ViewPort vp);
public abstract void MouseDownHandler(Point firstPoint, ViewPort vp);