public override void Highlight(DrawingContext dc, GeometryStyleBase geometryStyle) { if (null == dc || !(geometryStyle is LineStyle)) { return; } LineStyle style = geometryStyle as LineStyle; Pen pen = new Pen(style.LineBrush, 6); pen.DashStyle = style.DashStyle; if (pen.CanFreeze) { pen.Freeze(); } if (!_moving) { _beforeMoveFirstPoint = geometryStyle.FirstPoint; _beforeMoveSecondPoint = geometryStyle.SecondPoint; } dc.DrawLine(pen, geometryStyle.FirstPoint, geometryStyle.SecondPoint); }
public virtual void Move(DrawingContext dc, GeometryStyleBase geometryStyle, double offsetX, double offsetY) { if (null == dc) { return; } geometryStyle.FirstPoint = new Point() { X = _beforeMoveFirstPoint.X + offsetX, Y = _beforeMoveFirstPoint.Y + offsetY }; geometryStyle.SecondPoint = new Point() { X = _beforeMoveSecondPoint.X + offsetX, Y = _beforeMoveSecondPoint.Y + offsetY }; if (geometryStyle.Highlight) { Highlight(dc, geometryStyle); } else { Render(dc, geometryStyle); } _moving = true; }
public override void Render(DrawingContext dc, GeometryStyleBase geometryStyle) { if (null == dc || !(geometryStyle is TextStyle)) { return; } TextStyle style = geometryStyle as TextStyle; if (style.Font == null) { return; } FontFamily fontFamily = new FontFamily(style.Font.FontFamily.Name); if (!_moving) { _beforeMoveFirstPoint = geometryStyle.FirstPoint; _beforeMoveSecondPoint = geometryStyle.SecondPoint; } if (style.Text == null) { dc.DrawRectangle(Brushes.Transparent, _pen, new Rect(geometryStyle.FirstPoint, geometryStyle.SecondPoint)); } else { dc.DrawText(new FormattedText(style.Text, new System.Globalization.CultureInfo("zh-cn"), FlowDirection.LeftToRight, new Typeface(fontFamily, style.Font.Italic ? FontStyles.Italic : FontStyles.Normal, FontWeights.Normal, FontStretches.Normal), style.Font.Size, style.Foreground), geometryStyle.FirstPoint); } }
public override void Render(DrawingContext dc, GeometryStyleBase geometryStyle) { if (null == dc || !(geometryStyle is RectangleStyle)) { return; } RectangleStyle style = geometryStyle as RectangleStyle; Pen pen = new Pen(style.LineBrush, 6); pen.DashStyle = style.DashStyle; if (pen.CanFreeze) { pen.Freeze(); } if (!_moving) { _beforeMoveFirstPoint = geometryStyle.FirstPoint; _beforeMoveSecondPoint = geometryStyle.SecondPoint; } dc.DrawRectangle(style.FillBrush, pen, new Rect(geometryStyle.FirstPoint, geometryStyle.SecondPoint)); }
public override void Excute(GeometryStyleBase style) { if (style == null || style is LineStyle) { return; } double dx = style.SecondPoint.X - style.FirstPoint.X; double dy = style.SecondPoint.Y - style.FirstPoint.Y; double atan = Math.Atan(dy / dx); if (dx > 0) { if (dy > 0) { style.SecondPoint = new Point(style.SecondPoint.X, style.FirstPoint.Y + dx); } else { style.SecondPoint = new Point(style.SecondPoint.X, style.FirstPoint.Y - dx); } } else { if (dy > 0) { style.SecondPoint = new Point(style.SecondPoint.X, style.FirstPoint.Y - dx); } else { style.SecondPoint = new Point(style.SecondPoint.X, style.FirstPoint.Y + dx); } } }
public override void Render(DrawingContext dc, GeometryStyleBase geometryStyle) { if (null == dc || !(geometryStyle is CircleStyle)) { return; } CircleStyle style = geometryStyle as CircleStyle; Pen pen = new Pen(style.LineBrush, 6); pen.DashStyle = style.DashStyle; if (pen.CanFreeze) { pen.Freeze(); } if (!_moving) { _beforeMoveFirstPoint = geometryStyle.FirstPoint; _beforeMoveSecondPoint = geometryStyle.SecondPoint; } dc.DrawEllipse(style.FillBrush, pen, new Point( (geometryStyle.FirstPoint.X + geometryStyle.SecondPoint.X) / 2, (geometryStyle.FirstPoint.Y + geometryStyle.SecondPoint.Y) / 2), Math.Abs(geometryStyle.FirstPoint.X - geometryStyle.SecondPoint.X) / 2, Math.Abs(geometryStyle.FirstPoint.Y - geometryStyle.SecondPoint.Y) / 2); }
public override void Render(DrawingContext dc, GeometryStyleBase geometryStyle) { if (null == dc || !(geometryStyle is ImageStyle)) { return; } ImageStyle style = geometryStyle as ImageStyle; if (!_moving) { _beforeMoveFirstPoint = geometryStyle.FirstPoint; _beforeMoveSecondPoint = geometryStyle.SecondPoint; } if (style.ImageUri == null) { dc.DrawRectangle(Brushes.Transparent, _pen, new Rect(geometryStyle.FirstPoint, geometryStyle.SecondPoint)); } else { BitmapSource source = new System.Windows.Media.Imaging.BitmapImage(style.ImageUri); dc.DrawImage(source, new Rect(geometryStyle.FirstPoint, geometryStyle.SecondPoint)); } }
public override void Excute(GeometryStyleBase style) { if (style == null || !(style is LineStyle)) { return; } double dx = style.SecondPoint.X - style.FirstPoint.X; double dy = style.SecondPoint.Y - style.FirstPoint.Y; double atan = Math.Atan(dy / dx); if (atan <= Math.PI / 2 - 0.57) { style.SecondPoint = new Point(style.SecondPoint.X, style.FirstPoint.Y); } else if (atan >= Math.PI / 2 + 0.57) { style.SecondPoint = new Point(style.FirstPoint.X, style.SecondPoint.Y); } else { style.SecondPoint = new Point(style.SecondPoint.X, style.FirstPoint.Y + Math.Abs((style.SecondPoint.X - style.FirstPoint.X))); } }
public void Excute(GeometryStyleBase style) { if (style == null) { return; } foreach (var strategy in this) { strategy.Excute(style); } }
public override void Render(DrawingContext dc, GeometryStyleBase geometryStyle) { if (null == dc || !(geometryStyle is TriangleStyle)) { return; } TriangleStyle style = geometryStyle as TriangleStyle; Pen pen = new Pen(style.LineBrush, 6); pen.DashStyle = style.DashStyle; if (pen.CanFreeze) { pen.Freeze(); } if (!_moving) { _beforeMoveFirstPoint = geometryStyle.FirstPoint; _beforeMoveSecondPoint = geometryStyle.SecondPoint; } PathGeometry triangle = new PathGeometry(); PathFigure figure = new PathFigure(); figure.IsClosed = true; figure.StartPoint = new Point((geometryStyle.FirstPoint.X + geometryStyle.SecondPoint.X) / 2, geometryStyle.FirstPoint.Y); figure.Segments = new PathSegmentCollection() { new LineSegment() { Point = geometryStyle.SecondPoint }, new LineSegment() { Point = new Point(geometryStyle.FirstPoint.X, geometryStyle.SecondPoint.Y) } }; triangle.Figures = new PathFigureCollection() { figure }; dc.DrawGeometry(style.FillBrush, pen, triangle); }
public abstract void Highlight(DrawingContext dc, GeometryStyleBase geometryStyle);
public void Refresh(DrawingContext dc, GeometryStyleBase geometryStyle) { Render(dc, geometryStyle); }
public abstract void Render(DrawingContext dc, GeometryStyleBase geometryStyle);
public void Hide(DrawingContext dc, GeometryStyleBase geometryStyle) { //什么也不干就是隐藏 }
public abstract void Excute(GeometryStyleBase style);
public Image(GeometryStyleBase style, GeometryBaseAction action) : base() { Style = style; Action = action; }
public Triangle(GeometryStyleBase style, GeometryBaseAction action) : base() { Style = style; Action = action; }