public void Draw(object ds, XEllipse ellipse, double dx, double dy, ImmutableArray <ShapeProperty> db, Record r) { var _ds = ds as CanvasDrawingSession; double thickness = ellipse.Style.Thickness / _state.Zoom; var brush = ToColor(ellipse.Style.Fill); var pen = ToColor(ellipse.Style.Stroke); var ss = CreateStrokeStyle(ellipse.Style); var rect = CreateRect( ellipse.TopLeft, ellipse.BottomRight, dx, dy); DrawEllipseInternal( _ds, brush, pen, ss, ellipse.IsStroked, ellipse.IsFilled, ref rect, thickness); ss.Dispose(); }
public XEllipse CreateEllipse(double thickness, double x, double y, double width, double height, bool isFilled, ArgbColor stroke, ArgbColor fill) { var strokeBrush = ToSolidColorBrush(stroke); var fillBrush = ToSolidColorBrush(fill); strokeBrush.Freeze(); fillBrush.Freeze(); var ellipse = new Ellipse() { Fill = isFilled ? fillBrush : TransparentBrush, Stroke = strokeBrush, StrokeThickness = thickness, StrokeStartLineCap = PenLineCap.Round, StrokeEndLineCap = PenLineCap.Round, Width = width, Height = height }; Canvas.SetLeft(ellipse, x); Canvas.SetTop(ellipse, y); var xellipse = new XEllipse(ellipse); return(xellipse); }
/// <summary> /// /// </summary> /// <param name="gfx"></param> /// <param name="ellipse"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <param name="db"></param> /// <param name="r"></param> public void Draw(object gfx, XEllipse ellipse, double dx, double dy, ImmutableArray <ShapeProperty> db, Record r) { var _gfx = gfx as Graphics; Brush brush = ToSolidBrush(ellipse.Style.Fill); Pen pen = ToPen(ellipse.Style, _scaleToPage); var rect = CreateRect( ellipse.TopLeft, ellipse.BottomRight, dx, dy); if (ellipse.IsFilled) { _gfx.FillEllipse( brush, _scaleToPage(rect.X), _scaleToPage(rect.Y), _scaleToPage(rect.Width), _scaleToPage(rect.Height)); } if (ellipse.IsStroked) { _gfx.DrawEllipse( pen, _scaleToPage(rect.X), _scaleToPage(rect.Y), _scaleToPage(rect.Width), _scaleToPage(rect.Height)); } brush.Dispose(); pen.Dispose(); }
/// <summary> /// Initialize new instance of <see cref="EllipseSelection"/> class. /// </summary> /// <param name="layer">The selection shapes layer.</param> /// <param name="shape">The selected shape.</param> /// <param name="style">The selection shapes style.</param> /// <param name="point">The selection point shape.</param> public EllipseSelection(XLayer layer, XEllipse shape, ShapeStyle style, BaseShape point) { _layer = layer; _ellipse = shape; _style = style; _point = point; }
public void Reset() { if (TempEllipse != null) { _state.OverlaySheet.Remove(TempEllipse); TempEllipse = null; } }
public void MoveDelta(double dx, double dy, XEllipse ellipse) { double left = _blockHelper.GetLeft(ellipse) + dx; double top = _blockHelper.GetTop(ellipse) + dy; _blockHelper.SetLeft(ellipse, left); _blockHelper.SetTop(ellipse, top); }
/// <inheritdoc/> public override void LeftDown(double x, double y) { base.LeftDown(x, y); double sx = _editor.Project.Options.SnapToGrid ? ProjectEditor.Snap(x, _editor.Project.Options.SnapX) : x; double sy = _editor.Project.Options.SnapToGrid ? ProjectEditor.Snap(y, _editor.Project.Options.SnapY) : y; switch (_currentState) { case ToolState.None: { var style = _editor.Project.CurrentStyleLibrary.Selected; _ellipse = XEllipse.Create( sx, sy, _editor.Project.Options.CloneStyle ? style.Clone() : style, _editor.Project.Options.PointShape, _editor.Project.Options.DefaultIsStroked, _editor.Project.Options.DefaultIsFilled); var result = _editor.TryToGetConnectionPoint(sx, sy); if (result != null) { _ellipse.TopLeft = result; } _editor.Project.CurrentContainer.WorkingLayer.Shapes = _editor.Project.CurrentContainer.WorkingLayer.Shapes.Add(_ellipse); _editor.Project.CurrentContainer.WorkingLayer.Invalidate(); ToStateOne(); Move(_ellipse); _currentState = ToolState.One; _editor.CancelAvailable = true; } break; case ToolState.One: { if (_ellipse != null) { _ellipse.BottomRight.X = sx; _ellipse.BottomRight.Y = sy; var result = _editor.TryToGetConnectionPoint(sx, sy); if (result != null) { _ellipse.BottomRight = result; } _editor.Project.CurrentContainer.WorkingLayer.Shapes = _editor.Project.CurrentContainer.WorkingLayer.Shapes.Remove(_ellipse); Remove(); base.Finalize(_ellipse); _editor.Project.AddShape(_editor.Project.CurrentContainer.CurrentLayer, _ellipse); _currentState = ToolState.None; _editor.CancelAvailable = false; } } break; } }
/// <summary> /// Get the bounding rectangle for <see cref="XEllipse"/> shape. /// </summary> /// <param name="ellipse"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <returns></returns> public static Rect2 GetEllipseBounds(XEllipse ellipse, double dx, double dy) { return(Rect2.FromPoints( ellipse.TopLeft.X, ellipse.TopLeft.Y, ellipse.BottomRight.X, ellipse.BottomRight.Y, dx, dy)); }
private Rect2 GetEllipseBounds(XEllipse ellipse) { var bounds = new Rect2( ellipse.X - ellipse.RadiusX, ellipse.Y - ellipse.RadiusY, ellipse.RadiusX + ellipse.RadiusX, ellipse.RadiusY + ellipse.RadiusY); return(bounds); }
public void Cancel() { _state.OverlaySheet.ReleaseCapture(); _state.OverlaySheet.Remove(TempLine); _state.OverlaySheet.Remove(TempStartEllipse); _state.OverlaySheet.Remove(TempEndEllipse); TempLine = null; TempStartEllipse = null; TempEndEllipse = null; }
public void Init(ImmutablePoint p) { double x = _itemController.Snap(p.X, _state.Options.SnapSize); double y = _itemController.Snap(p.Y, _state.Options.SnapSize); SelectionStartPoint = new ImmutablePoint(x, y); TempEllipse = _blockFactory.CreateEllipse(_state.Options.LineThickness / _state.ZoomController.Zoom, x, y, 0.0, 0.0, false, ArgbColors.Black, ArgbColors.Transparent); _state.OverlaySheet.Add(TempEllipse); _state.OverlaySheet.Capture(); }
/// <inheritdoc/> public override void Draw(object dc, XEllipse ellipse, double dx, double dy, ImmutableArray <XProperty> db, XRecord r) { var canvas = dc as SKCanvas; using (SKPaint brush = ToSKPaintBrush(ellipse.Style.Fill)) using (SKPaint pen = ToSKPaintPen(ellipse.Style, _scaleToPage, _sourceDpi, _targetDpi)) { var rect = CreateRect(ellipse.TopLeft, ellipse.BottomRight, dx, dy, _scaleToPage); DrawEllipseInternal(canvas, brush, pen, ellipse.IsStroked, ellipse.IsFilled, ref rect); } }
/// <summary> /// Transfer selection state to <see cref="ToolState.One"/>. /// </summary> public void ToStateOne() { _ellipse = XEllipse.Create(0, 0, _style, null); _p1HelperPoint = XPoint.Create(0, 0, _point); _p2HelperPoint = XPoint.Create(0, 0, _point); _centerHelperPoint = XPoint.Create(0, 0, _point); _layer.Shapes = _layer.Shapes.Add(_ellipse); _layer.Shapes = _layer.Shapes.Add(_p1HelperPoint); _layer.Shapes = _layer.Shapes.Add(_p2HelperPoint); _layer.Shapes = _layer.Shapes.Add(_centerHelperPoint); }
/// <summary> /// Remove selection. /// </summary> public void Remove() { if (_ellipse != null) { _layer.Shapes = _layer.Shapes.Remove(_ellipse); _ellipse = null; } if (_startLine != null) { _layer.Shapes = _layer.Shapes.Remove(_startLine); _startLine = null; } if (_endLine != null) { _layer.Shapes = _layer.Shapes.Remove(_endLine); _endLine = null; } if (_p1HelperPoint != null) { _layer.Shapes = _layer.Shapes.Remove(_p1HelperPoint); _p1HelperPoint = null; } if (_p2HelperPoint != null) { _layer.Shapes = _layer.Shapes.Remove(_p2HelperPoint); _p2HelperPoint = null; } if (_centerHelperPoint != null) { _layer.Shapes = _layer.Shapes.Remove(_centerHelperPoint); _centerHelperPoint = null; } if (_startHelperPoint != null) { _layer.Shapes = _layer.Shapes.Remove(_startHelperPoint); _startHelperPoint = null; } if (_endHelperPoint != null) { _layer.Shapes = _layer.Shapes.Remove(_endHelperPoint); _endHelperPoint = null; } _layer.Invalidate(); }
/// <summary> /// Transfer selection state to <see cref="ToolState.Three"/>. /// </summary> public void ToStateThree() { if (_ellipse != null) { _layer.Shapes = _layer.Shapes.Remove(_ellipse); _ellipse = null; } _endLine = XLine.Create(0, 0, _style, null); _endHelperPoint = XPoint.Create(0, 0, _point); _layer.Shapes = _layer.Shapes.Add(_endLine); _layer.Shapes = _layer.Shapes.Add(_endHelperPoint); }
public ItemEllipse Serialize(XEllipse ellipse) { return(new ItemEllipse() { Id = ellipse.Id, X = _blockHelper.GetLeft(ellipse), Y = _blockHelper.GetTop(ellipse), Width = _blockHelper.GetWidth(ellipse), Height = _blockHelper.GetHeight(ellipse), IsFilled = _blockHelper.IsTransparent(ellipse), Stroke = _blockHelper.GetStroke(ellipse), Fill = _blockHelper.GetFill(ellipse) }); }
/// <summary> /// /// </summary> /// <param name="dc"></param> /// <param name="ellipse"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <param name="db"></param> /// <param name="r"></param> public void Draw(object dc, XEllipse ellipse, double dx, double dy, ImmutableArray <ShapeProperty> db, Record r) { var _dc = dc as DrawingContext; var style = ellipse.Style; if (style == null) { return; } double thickness = style.Thickness / _state.Zoom; double half = thickness / 2.0; Tuple <Brush, Pen> cache = null; Brush fill; Pen stroke; if (_enableStyleCache && _styleCache.TryGetValue(style, out cache)) { fill = cache.Item1; stroke = cache.Item2; } else { fill = CreateBrush(style.Fill); stroke = CreatePen(style, thickness); if (_enableStyleCache) { _styleCache.Add(style, Tuple.Create(fill, stroke)); } } var rect = CreateRect( ellipse.TopLeft, ellipse.BottomRight, dx, dy); double rx = rect.Width / 2.0; double ry = rect.Height / 2.0; var center = new Point(rect.X + rx, rect.Y + ry); DrawEllipseInternal( _dc, half, fill, stroke, ellipse.IsStroked, ellipse.IsFilled, ref center, rx, ry); }
private IEllipse ReadEllipse() { var ellipse = new XEllipse() { Id = _reader.ReadInt32(), Point1 = ReadPoint(), Point2 = ReadPoint(), Stroke = ReadColor(), StrokeThickness = _reader.ReadDouble(), Fill = ReadColor() }; _natives.Add(ellipse.Id, ellipse); return(ellipse); }
/// <inheritdoc/> XEllipse IShapeFactory.Ellipse(double x1, double y1, double x2, double y2, bool isStroked, bool isFilled, string text) { var style = _editor.Project.CurrentStyleLibrary.Selected; var ellipse = XEllipse.Create( x1, y1, x2, y2, _editor.Project.Options.CloneStyle ? style.Clone() : style, _editor.Project.Options.PointShape, isStroked, isFilled, text); _editor.Project.AddShape(_editor.Project.CurrentContainer.CurrentLayer, ellipse); return(ellipse); }
/// <inheritdoc/> XEllipse IShapeFactory.Ellipse(XPoint topLeft, XPoint bottomRight, bool isStroked, bool isFilled, string text) { var style = _editor.Project.CurrentStyleLibrary.Selected; var ellipse = XEllipse.Create( topLeft, bottomRight, _editor.Project.Options.CloneStyle ? style.Clone() : style, _editor.Project.Options.PointShape, isStroked, isFilled, text); _editor.Project.AddShape(_editor.Project.CurrentContainer.CurrentLayer, ellipse); return(ellipse); }
/// <inheritdoc/> public override void Draw(object dc, XEllipse ellipse, double dx, double dy, ImmutableArray <XProperty> db, XRecord r) { var _dc = dc as AM.DrawingContext; AM.IBrush brush = ToBrush(ellipse.Style.Fill); AM.Pen pen = ToPen(ellipse.Style, _scaleToPage); var rect = CreateRect(ellipse.TopLeft, ellipse.BottomRight, dx, dy); DrawEllipseInternal( _dc, brush, pen, ellipse.IsStroked, ellipse.IsFilled, ref rect); }
/// <summary> /// /// </summary> /// <param name="ellipse"></param> /// <param name="rect"></param> /// <param name="selected"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <returns></returns> public static bool HitTestEllipse(XEllipse ellipse, Rect2 rect, ISet <BaseShape> selected, double dx, double dy) { if (RectangleBounds.GetEllipseBounds(ellipse, dx, dy).IntersectsWith(rect)) { if (selected != null) { selected.Add(ellipse); return(false); } else { return(true); } } return(false); }
public void Finish(XPoint end) { double x1 = _blockHelper.GetX1(TempLine); double y1 = _blockHelper.GetY1(TempLine); double x2 = _blockHelper.GetX2(TempLine); double y2 = _blockHelper.GetY2(TempLine); if (Math.Round(x1, 1) == Math.Round(x2, 1) && Math.Round(y1, 1) == Math.Round(y2, 1)) { Cancel(); } else { if (end != null) { TempLine.End = end; } _state.OverlaySheet.ReleaseCapture(); _state.OverlaySheet.Remove(TempLine); _state.OverlaySheet.Remove(TempStartEllipse); _state.OverlaySheet.Remove(TempEndEllipse); _state.HistoryController.Register("Create Line"); if (TempLine.Start != null) { _pointController.ConnectStart(TempLine.Start, TempLine); } if (TempLine.End != null) { _pointController.ConnectEnd(TempLine.End, TempLine); } _state.ContentBlock.Lines.Add(TempLine); _state.ContentSheet.Add(TempLine); TempLine = null; TempStartEllipse = null; TempEndEllipse = null; } }
/// <summary> /// /// </summary> /// <param name="ellipse"></param> /// <param name="v"></param> /// <param name="threshold"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <returns></returns> public static BaseShape HitTestEllipse(XEllipse ellipse, Vector2 v, double threshold, double dx, double dy) { if (RectangleBounds.GetPointBounds(ellipse.TopLeft, threshold, dx, dy).Contains(v)) { return(ellipse.TopLeft); } if (RectangleBounds.GetPointBounds(ellipse.BottomRight, threshold, dx, dy).Contains(v)) { return(ellipse.BottomRight); } if (RectangleBounds.GetEllipseBounds(ellipse, dx, dy).Contains(v)) { return(ellipse); } return(null); }
public void DrawEllipse(object dc, IStyle style, XEllipse ellipse) { double thickness = style.Thickness / Zoom; var pen = new Pen( new SolidColorBrush( Color.FromArgb( (byte)style.Stroke.A, (byte)style.Stroke.R, (byte)style.Stroke.G, (byte)style.Stroke.B)), thickness); pen.Freeze(); if (ellipse.IsFilled) { var brush = new SolidColorBrush( Color.FromArgb( (byte)style.Fill.A, (byte)style.Fill.R, (byte)style.Fill.G, (byte)style.Fill.B)); brush.Freeze(); (dc as DrawingContext).DrawEllipse( brush, pen, new Point(ellipse.X, ellipse.Y), ellipse.RadiusX, ellipse.RadiusY); } else { (dc as DrawingContext).DrawEllipse( null, pen, new Point(ellipse.X, ellipse.Y), ellipse.RadiusX, ellipse.RadiusY); } }
public void Init(ImmutablePoint p, XPoint start) { double x = _itemController.Snap(p.X, _state.Options.SnapSize); double y = _itemController.Snap(p.Y, _state.Options.SnapSize); TempLine = _blockFactory.CreateLine(_state.Options.LineThickness / _state.ZoomController.Zoom, x, y, x, y, ArgbColors.Black); if (start != null) { TempLine.Start = start; } TempStartEllipse = _blockFactory.CreateEllipse(_state.Options.LineThickness / _state.ZoomController.Zoom, x - 4.0, y - 4.0, 8.0, 8.0, true, ArgbColors.Black, ArgbColors.Black); TempEndEllipse = _blockFactory.CreateEllipse(_state.Options.LineThickness / _state.ZoomController.Zoom, x - 4.0, y - 4.0, 8.0, 8.0, true, ArgbColors.Black, ArgbColors.Black); _state.OverlaySheet.Add(TempLine); _state.OverlaySheet.Add(TempStartEllipse); _state.OverlaySheet.Add(TempEndEllipse); _state.OverlaySheet.Capture(); }
public void Reset() { if (TempLine != null) { _state.OverlaySheet.Remove(TempLine); TempLine = null; } if (TempStartEllipse != null) { _state.OverlaySheet.Remove(TempStartEllipse); TempLine = null; } if (TempEndEllipse != null) { _state.OverlaySheet.Remove(TempEndEllipse); TempEndEllipse = null; } }
public void Finish() { double x = _blockHelper.GetLeft(TempEllipse); double y = _blockHelper.GetTop(TempEllipse); double width = _blockHelper.GetWidth(TempEllipse); double height = _blockHelper.GetHeight(TempEllipse); if (width == 0.0 || height == 0.0) { Cancel(); } else { _state.OverlaySheet.ReleaseCapture(); _state.OverlaySheet.Remove(TempEllipse); _state.HistoryController.Register("Create Ellipse"); _state.ContentBlock.Ellipses.Add(TempEllipse); _state.ContentSheet.Add(TempEllipse); TempEllipse = null; } }
/// <summary> /// /// </summary> /// <param name="dc"></param> /// <param name="ellipse"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <param name="db"></param> /// <param name="r"></param> public void Draw(object dc, XEllipse ellipse, double dx, double dy, ImmutableArray <ShapeProperty> db, Record r) { var _dc = dc as DrawingContext; Brush brush = ToSolidBrush(ellipse.Style.Fill); Pen pen = ToPen(ellipse.Style, _scaleToPage); var rect = CreateRect( ellipse.TopLeft, ellipse.BottomRight, dx, dy); DrawEllipseInternal( _dc, brush, pen, ellipse.IsStroked, ellipse.IsFilled, ref rect); // TODO: brush.Dispose(); // TODO: pen.Dispose(); }
/// <inheritdoc/> public override void Draw(object dc, XEllipse ellipse, double dx, double dy, ImmutableArray <XProperty> db, XRecord r) { var _dc = dc as DrawingContext; var style = ellipse.Style; if (style == null) { return; } double thickness = style.Thickness / _state.ZoomX; double half = thickness / 2.0; Tuple <Brush, Pen> styleCached = _styleCache.Get(style); Brush fill; Pen stroke; if (styleCached != null) { fill = styleCached.Item1; stroke = styleCached.Item2; } else { fill = CreateBrush(style.Fill); stroke = CreatePen(style, thickness); _styleCache.Set(style, Tuple.Create(fill, stroke)); } var rect = CreateRect(ellipse.TopLeft, ellipse.BottomRight, dx, dy); double rx = rect.Width / 2.0; double ry = rect.Height / 2.0; var center = new Point(rect.X + rx, rect.Y + ry); DrawEllipseInternal(_dc, half, fill, stroke, ellipse.IsStroked, ellipse.IsFilled, ref center, rx, ry); }
public IPin CreatePin() { var shape = new XEllipse() { Point1 = new XPoint(-4.0, -4.0), Point2 = new XPoint(4.0, 4.0), Stroke = new XColor(0x00, 0x00, 0x00, 0x00), StrokeThickness = 0.0, Fill = new XColor(0xFF, 0x00, 0x00, 0x00) }; var pin = new XPin() { Point = new XPoint(0.0, 0.0), Shape = shape, }; pin.Point.Connected.Add(pin); return pin; }
public IEllipse CreateEllipse() { var ellipse = new XEllipse() { Point1 = new XPoint(0.0, 0.0), Point2 = new XPoint(0.0, 0.0), Stroke = new XColor(0xFF, 0x00, 0x00, 0x00), StrokeThickness = 2.0, Fill = new XColor(0x00, 0xFF, 0xFF, 0xFF) }; ellipse.Point1.Connected.Add(ellipse); ellipse.Point2.Connected.Add(ellipse); return ellipse; }
private IEllipse ReadEllipse() { var ellipse = new XEllipse() { Id = _reader.ReadInt32(), Point1 = ReadPoint(), Point2 = ReadPoint(), Stroke = ReadColor(), StrokeThickness = _reader.ReadDouble(), Fill = ReadColor() }; _natives.Add(ellipse.Id, ellipse); return ellipse; }