/// <summary> /// /// </summary> /// <param name="rectangle"></param> /// <param name="x"></param> /// <param name="y"></param> public void TryToConnectBottomRight(XRectangle rectangle, double x, double y) { var result = ShapeBounds.HitTest(_editor.Project.CurrentContainer, new Vector2(x, y), _editor.Project.Options.HitTreshold); if (result != null && result is XPoint) { rectangle.BottomRight = result as XPoint; } }
/// <summary> /// /// </summary> /// <param name="x"></param> /// <param name="y"></param> public override void LeftDown(double x, double y) { double sx = _editor.Project.Options.SnapToGrid ? Editor.Snap(x, _editor.Project.Options.SnapX) : x; double sy = _editor.Project.Options.SnapToGrid ? Editor.Snap(y, _editor.Project.Options.SnapY) : y; switch (_currentState) { case State.None: { _shape = XRectangle.Create( sx, sy, _editor.Project.CurrentStyleLibrary.CurrentStyle, _editor.Project.Options.PointShape, _editor.Project.Options.DefaultIsStroked, _editor.Project.Options.DefaultIsFilled); if (_editor.Project.Options.TryToConnect) { TryToConnectTopLeft(_shape as XRectangle, sx, sy); } _editor.Project.CurrentContainer.WorkingLayer.Shapes = _editor.Project.CurrentContainer.WorkingLayer.Shapes.Add(_shape); _editor.Project.CurrentContainer.WorkingLayer.Invalidate(); ToStateOne(); Move(_shape); _editor.Project.CurrentContainer.HelperLayer.Invalidate(); _currentState = State.One; _editor.CancelAvailable = true; } break; case State.One: { var rectangle = _shape as XRectangle; if (rectangle != null) { rectangle.BottomRight.X = sx; rectangle.BottomRight.Y = sy; if (_editor.Project.Options.TryToConnect) { TryToConnectBottomRight(_shape as XRectangle, sx, sy); } _editor.Project.CurrentContainer.WorkingLayer.Shapes = _editor.Project.CurrentContainer.WorkingLayer.Shapes.Remove(_shape); Remove(); Finalize(_shape); _editor.AddWithHistory(_shape); _currentState = State.None; _editor.CancelAvailable = false; } } break; } }
/// <summary> /// /// </summary> /// <param name="gfx"></param> /// <param name="rectangle"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <param name="db"></param> /// <param name="r"></param> public void Draw(object gfx, XRectangle rectangle, double dx, double dy, ImmutableArray <ShapeProperty> db, Record r) { var _gfx = gfx as Graphics; Brush brush = ToSolidBrush(rectangle.Style.Fill); Pen pen = ToPen(rectangle.Style, _scaleToPage); var rect = CreateRect( rectangle.TopLeft, rectangle.BottomRight, dx, dy); if (rectangle.IsFilled) { _gfx.FillRectangle( brush, _scaleToPage(rect.X), _scaleToPage(rect.Y), _scaleToPage(rect.Width), _scaleToPage(rect.Height)); } if (rectangle.IsStroked) { _gfx.DrawRectangle( pen, _scaleToPage(rect.X), _scaleToPage(rect.Y), _scaleToPage(rect.Width), _scaleToPage(rect.Height)); } if (rectangle.IsGrid) { DrawGridInternal( _gfx, pen, ref rect, rectangle.OffsetX, rectangle.OffsetY, rectangle.CellWidth, rectangle.CellHeight, true); } brush.Dispose(); pen.Dispose(); }
/// <summary> /// Creates a new instance of the XRectangle class. /// </summary> /// <param name="topLeft"></param> /// <param name="bottomRight"></param> /// /// <param name="isStroked"></param> /// <param name="isFilled"></param> /// <param name="text"></param> /// <returns></returns> public XRectangle Rectangle( XPoint topLeft, XPoint bottomRight, bool isStroked = true, bool isFilled = false, string text = null) { var rectangle = XRectangle.Create( topLeft, bottomRight, Context.Editor.Project.CurrentStyleLibrary.CurrentStyle, Context.Editor.Project.Options.PointShape, isStroked, isFilled, text); Context.Editor.AddWithHistory(rectangle); return(rectangle); }
/// <summary> /// Creates a new instance of the XRectangle class. /// </summary> /// <param name="x1"></param> /// <param name="y1"></param> /// <param name="x2"></param> /// <param name="y2"></param> /// <param name="isStroked"></param> /// <param name="isFilled"></param> /// <param name="text"></param> /// <returns></returns> public XRectangle Rectangle( double x1 = 30, double y1 = 30, double x2 = 60, double y2 = 60, bool isStroked = true, bool isFilled = false, string text = null) { var rectangle = XRectangle.Create( x1, y1, x2, y2, Context.Editor.Project.CurrentStyleLibrary.CurrentStyle, Context.Editor.Project.Options.PointShape, isStroked, isFilled, text); Context.Editor.AddWithHistory(rectangle); return(rectangle); }
/// <summary> /// /// </summary> /// <param name="project"></param> /// <param name="container"></param> private void CreateGrid(Project project, Container container) { var style = project .StyleLibraries.FirstOrDefault(g => g.Name == "Template") .Styles.FirstOrDefault(s => s.Name == "Grid"); var layer = container.Layers.FirstOrDefault(); var builder = layer.Shapes.ToBuilder(); var grid = XRectangle.Create( 0, 0, container.Width, container.Height, style, project.Options.PointShape); grid.IsStroked = false; grid.IsFilled = false; grid.IsGrid = true; grid.OffsetX = 30.0; grid.OffsetY = 30.0; grid.CellWidth = 30.0; grid.CellHeight = 30.0; grid.State.Flags &= ~ShapeStateFlags.Printable; builder.Add(grid); layer.Shapes = builder.ToImmutable(); }
/// <summary> /// /// </summary> /// <param name="gfx"></param> /// <param name="rectangle"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <param name="db"></param> /// <param name="r"></param> public void Draw(object gfx, XRectangle rectangle, double dx, double dy, ImmutableArray<ShapeProperty> db, Record r) { var _gfx = gfx as Graphics; Brush brush = ToSolidBrush(rectangle.Style.Fill); Pen pen = ToPen(rectangle.Style, _scaleToPage); var rect = CreateRect( rectangle.TopLeft, rectangle.BottomRight, dx, dy); if (rectangle.IsFilled) { _gfx.FillRectangle( brush, _scaleToPage(rect.X), _scaleToPage(rect.Y), _scaleToPage(rect.Width), _scaleToPage(rect.Height)); } if (rectangle.IsStroked) { _gfx.DrawRectangle( pen, _scaleToPage(rect.X), _scaleToPage(rect.Y), _scaleToPage(rect.Width), _scaleToPage(rect.Height)); } if (rectangle.IsGrid) { DrawGridInternal( _gfx, pen, ref rect, rectangle.OffsetX, rectangle.OffsetY, rectangle.CellWidth, rectangle.CellHeight, true); } brush.Dispose(); pen.Dispose(); }
/// <summary> /// /// </summary> /// <param name="rectangle"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <returns></returns> public static Rect2 GetRectangleBounds(XRectangle rectangle, double dx, double dy) { return(Rect2.Create(rectangle.TopLeft, rectangle.BottomRight, dx, dy)); }
/// <summary> /// /// </summary> /// <param name="x"></param> /// <param name="y"></param> public override void LeftDown(double x, double y) { switch (_currentState) { case State.None: { _editor.Dehover(); if (_editor.Renderers[0].State.SelectedShape == null && _editor.Renderers[0].State.SelectedShapes != null) { var result = ShapeBounds.HitTest(_editor.Project.CurrentContainer, new Vector2(x, y), _editor.Project.Options.HitTreshold); if (result != null) { _startX = _editor.Project.Options.SnapToGrid ? Editor.Snap(x, _editor.Project.Options.SnapX) : x; _startY = _editor.Project.Options.SnapToGrid ? Editor.Snap(y, _editor.Project.Options.SnapY) : y; _historyX = _startX; _historyY = _startY; GenerateMoveSelectionCache(); _currentState = State.One; _editor.CancelAvailable = true; break; } } if (_editor.TryToSelectShape(_editor.Project.CurrentContainer, x, y)) { _startX = _editor.Project.Options.SnapToGrid ? Editor.Snap(x, _editor.Project.Options.SnapX) : x; _startY = _editor.Project.Options.SnapToGrid ? Editor.Snap(y, _editor.Project.Options.SnapY) : y; _historyX = _startX; _historyY = _startY; GenerateMoveSelectionCache(); _currentState = State.One; _editor.CancelAvailable = true; break; } _shape = XRectangle.Create( x, y, _editor.Project.Options.SelectionStyle, null, true, true); _editor.Project.CurrentContainer.WorkingLayer.Shapes = _editor.Project.CurrentContainer.WorkingLayer.Shapes.Add(_shape); _editor.Project.CurrentContainer.WorkingLayer.Invalidate(); _currentState = State.One; _editor.CancelAvailable = true; } break; case State.One: { var rectangle = _shape as XRectangle; if (rectangle != null) { rectangle.BottomRight.X = x; rectangle.BottomRight.Y = y; _editor.Project.CurrentContainer.WorkingLayer.Shapes = _editor.Project.CurrentContainer.WorkingLayer.Shapes.Remove(_shape); _editor.Project.CurrentContainer.WorkingLayer.Invalidate(); _currentState = State.None; _editor.CancelAvailable = false; } } break; } }
/// <summary> /// /// </summary> /// <param name="dc"></param> /// <param name="rectangle"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <param name="db"></param> /// <param name="r"></param> public void Draw(object dc, XRectangle rectangle, double dx, double dy, ImmutableArray<Property> db, Record r) { var _dc = dc as DrawingContext; var style = rectangle.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( rectangle.TopLeft, rectangle.BottomRight, dx, dy); DrawRectangleInternal( _dc, half, fill, stroke, rectangle.IsStroked, rectangle.IsFilled, ref rect); if (rectangle.IsGrid) { DrawGridInternal( _dc, half, stroke, ref rect, rectangle.OffsetX, rectangle.OffsetY, rectangle.CellWidth, rectangle.CellHeight, true); } }
public void Draw(object ds, XRectangle rectangle, double dx, double dy, ImmutableArray<Property> db, Record r) { var _ds = ds as CanvasDrawingSession; double thickness = rectangle.Style.Thickness / _state.Zoom; var brush = ToColor(rectangle.Style.Fill); var pen = ToColor(rectangle.Style.Stroke); var ss = CreateStrokeStyle(rectangle.Style); var rect = CreateRect( rectangle.TopLeft, rectangle.BottomRight, dx, dy); DrawRectangleInternal( _ds, brush, pen, ss, rectangle.IsStroked, rectangle.IsFilled, ref rect, thickness); if (rectangle.IsGrid) { DrawGridInternal( _ds, pen, ss, ref rect, rectangle.OffsetX, rectangle.OffsetY, rectangle.CellWidth, rectangle.CellHeight, true, thickness); } ss.Dispose(); }
/// <summary> /// /// </summary> /// <param name="dc"></param> /// <param name="rectangle"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <param name="db"></param> /// <param name="r"></param> public void Draw(object dc, XRectangle rectangle, double dx, double dy, ImmutableArray<ShapeProperty> db, Record r) { var _dc = dc as DrawingContext; Brush brush = ToSolidBrush(rectangle.Style.Fill); Pen pen = ToPen(rectangle.Style, _scaleToPage); var rect = CreateRect( rectangle.TopLeft, rectangle.BottomRight, dx, dy); DrawRectangleInternal( _dc, brush, pen, rectangle.IsStroked, rectangle.IsFilled, ref rect); if (rectangle.IsGrid) { DrawGridInternal( _dc, pen, ref rect, rectangle.OffsetX, rectangle.OffsetY, rectangle.CellWidth, rectangle.CellHeight, true); } // TODO: brush.Dispose(); // TODO: pen.Dispose(); }
/// <summary> /// /// </summary> /// <param name="pss"></param> /// <returns></returns> public static BaseShape RectanglePointShape(ShapeStyle pss) { return(XRectangle.Create(-4, -4, 4, 4, pss, null, true, false)); }
/// <summary> /// /// </summary> /// <param name="rectangle"></param> /// <param name="x"></param> /// <param name="y"></param> public void TryToConnectTopLeft(XRectangle rectangle, double x, double y) { var result = ShapeBounds.HitTest(_editor.Project.CurrentContainer, new Vector2(x, y), _editor.Project.Options.HitTreshold); if (result != null && result is XPoint) { rectangle.TopLeft = result as XPoint; } }
/// <summary> /// /// </summary> /// <param name="pss"></param> /// <returns></returns> public static BaseShape FilledRectanglePointShape(ShapeStyle pss) { return(XRectangle.Create(-3, -3, 3, 3, pss, null, true, true)); }
/// <summary> /// /// </summary> /// <param name="rectangle"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <returns></returns> public static Rect2 GetRectangleBounds(XRectangle rectangle, double dx, double dy) { return Rect2.Create(rectangle.TopLeft, rectangle.BottomRight, dx, dy); }