public override void Draw(System.Drawing.Graphics g) { if (g == null) { throw new System.ArgumentNullException("g"); } if (base.Dragging) { System.Drawing.Rectangle rectangle = GetViewportRectangle(); if (base.Brush != null) { System.Drawing.Drawing2D.Matrix prevBrushMatrix = PathVObjectCreateDesigner.AdaptBrushToViewport(base.Brush, this.VObjectHost.HostViewer); try { g.FillEllipse(base.Brush, rectangle); } finally { if (prevBrushMatrix != null) { VObjectsUtils.SetBrushMatrix(base.Brush, prevBrushMatrix); } } } if (base.Pen != null) { using (System.Drawing.Pen pen = CreateViewportPen()) g.DrawEllipse(pen, rectangle); } } }
private void DrawVObjectBounds(System.Drawing.Graphics g) { if (g == null) { throw new System.ArgumentNullException("g"); } if (_objectBorderPen != null) { System.Drawing.RectangleF baseRect = _obj.GetVObjectBounds(); System.Drawing.PointF[] points = new System.Drawing.PointF[5]; points[0] = baseRect.Location; points[1] = new System.Drawing.PointF(baseRect.Right, baseRect.Top); points[2] = new System.Drawing.PointF(baseRect.Right, baseRect.Bottom); points[3] = new System.Drawing.PointF(baseRect.Left, baseRect.Bottom); points[4] = System.Drawing.PointF.Empty; VObjectsUtils.TransformPointsInplace(_obj.Transform, points); for (int i = 0; i < points.Length; i++) { points[i] = _hostControl.WorkspaceToControl(points[i], Aurigma.GraphicsMill.Unit.Point); } points[points.Length - 1] = points[0]; g.DrawLines(_objectBorderPen, points); } }
public virtual bool NotifyMouseMove(System.Windows.Forms.MouseEventArgs e) { if (e == null) { throw new System.ArgumentNullException("e"); } if (_areaOriginDefined) { System.Drawing.RectangleF invalidationRect = System.Drawing.RectangleF.Empty; if (_areaDefined) { invalidationRect = VObjectsUtils.GetBoundingRectangle(_cornerPoints); } _areaDefined = true; _cornerPoints[1] = _objectHost.HostViewer.ControlToWorkspace(new System.Drawing.Point(e.X, e.Y), Aurigma.GraphicsMill.Unit.Point); invalidationRect = System.Drawing.RectangleF.Union(invalidationRect, VObjectsUtils.GetBoundingRectangle(_cornerPoints)); invalidationRect.Inflate((int)_borderPen.Width * 2, (int)_borderPen.Width * 2); _objectHost.HostViewer.InvalidateViewer(new MultiLayerViewerInvalidationTarget(_objectHost.HostViewer.WorkspaceToControl(invalidationRect, Aurigma.GraphicsMill.Unit.Point))); } return(true); }
protected void UpdatePath() { // After deserialization _points array will be null. if (_points == null) { return; } if (_path != null) { _path.Dispose(); } System.Drawing.RectangleF bounds = VObjectsUtils.GetBoundingRectangle(_points); if (bounds.Width < VObject.Eps) { _points[0].X += 0.05f; } if (bounds.Height < VObject.Eps) { _points[0].Y += 0.05f; } _path = new System.Drawing.Drawing2D.GraphicsPath(); _path.AddLines(_points); if (_closePath) { _path.CloseFigure(); } }
protected void SwitchToDefaultDesigner() { System.Drawing.RectangleF invalidationRect = VObjectsUtils.GetBoundingRectangle(_cornerPoints); invalidationRect.Inflate((int)_borderPen.Width * 2, (int)_borderPen.Width * 2); _objectHost.HostViewer.InvalidateViewer(new MultiLayerViewerInvalidationTarget(_objectHost.HostViewer.WorkspaceToControl(invalidationRect, Aurigma.GraphicsMill.Unit.Point))); _objectHost.CurrentDesigner = _objectHost.DefaultDesigner; }
public override void UpdateSettings() { base.UpdateSettings(); CompositeVObject castedObj = (CompositeVObject)base.ActualVObject; castedObj.MultipleVObjectsTransformationEnabled = VObjectsUtils.GetBoolDesignerProperty(base.VObjectHost, DesignerSettingsConstants.MultipleVObjectsTransformationEnabled, castedObj.MultipleVObjectsTransformationEnabled); }
public void UpdateSettings() { if (!this.Connected) { throw new Aurigma.GraphicsMill.UnexpectedException(StringResources.GetString("ExStrDesignerShouldBeAttached")); } _multiSelect = VObjectsUtils.GetBoolDesignerProperty(_objectHost, DesignerSettingsConstants.MultiSelect, _multiSelect); }
/// <summary> /// Method generates actual image for specified viewport. /// </summary> private void BuildUpViewportImage(Aurigma.GraphicsMill.Bitmap canvas, float zoom, System.Drawing.Rectangle viewport, System.Drawing.Rectangle invalidatedRect) { if (canvas.Width != viewport.Width || canvas.Height != viewport.Height) { throw new System.ArgumentException(StringResources.GetString("ExStrCanvasAndViewportDimsShouldBeEqual")); } // We should take into account 2 issues here // 1) Shift or resize of the viewport. // 2) Invalidated areas. // // Note: Current implementation may draw twice invalidatedRect in some case. Taking this case // into account would cause code complication. I think that it is a rather rare case, because invalidatedRect // is usually empty during scrolling. On the other hand, it is not empty during // object editing, but in such case viewportOrigin is not changed. In both of these most regular cases // invalidatedRect will be drawn once. // Drawing actual cached region of the viewportOrigin. System.Drawing.Rectangle cachedRegion = _viewportCache.GetActualRegion(zoom, viewport); System.Drawing.Rectangle[] cachedActualRegions = VObjectsUtils.SubstractRectangle(cachedRegion, invalidatedRect); for (int i = 0; i < cachedActualRegions.Length; i++) { if (cachedActualRegions[i].Width < 1 || cachedActualRegions[i].Height < 1) { continue; } using (var canvasGdiGraphics = canvas.GetGraphics()) { _viewportCache.DrawCached(canvasGdiGraphics, zoom, viewport, cachedActualRegions[i]); } } // Drawing non-cached parts of the viewportOrigin image. invalidatedRect.Intersect(viewport); if (invalidatedRect.Width > 0 && invalidatedRect.Height > 0) { DrawNoncachedArea(canvas, zoom, viewport, invalidatedRect); } System.Drawing.Rectangle[] newRegions = VObjectsUtils.SubstractRectangle(viewport, cachedRegion); for (int i = 0; i < newRegions.Length; i++) { newRegions[i].Intersect(viewport); if (newRegions[i].Width < 1 || newRegions[i].Height < 1) { continue; } DrawNoncachedArea(canvas, zoom, viewport, newRegions[i]); } }
private void UpdateBaseRectangle() { if (_children.Count > 0) { _baseRect = VObjectsUtils.GetBoundingRectangle(_children[0].GetVObjectBounds(), _children[0].Transform); for (int i = 1; i < _children.Count; i++) { _baseRect = System.Drawing.RectangleF.Union(_baseRect, VObjectsUtils.GetBoundingRectangle(_children[i].GetVObjectBounds(), _children[i].Transform)); } } }
protected void RestoreBrush() { if (_brush != null && _brush.GetType() != typeof(System.Drawing.SolidBrush) && _brush.GetType() != typeof(System.Drawing.Drawing2D.HatchBrush)) { if (_brushMatrices.Count < 1) { throw new Aurigma.GraphicsMill.UnexpectedException(StringResources.GetString("ExStrModifyBrushTransformOrderCorrupted")); } VObjectsUtils.SetBrushMatrix(_brush, (System.Drawing.Drawing2D.Matrix)_brushMatrices.Peek()); } }
protected override System.Drawing.Rectangle GetInvalidationRectangle() { System.Drawing.Rectangle result = VObjectsUtils.GetBoundingRectangle((System.Drawing.Point[])_points.ToArray(typeof(System.Drawing.Point))); if (base.Pen != null) { int inflateValue = (int)System.Math.Ceiling(base.Pen.Width * base.VObjectHost.HostViewer.GetControlPixelsPerUnitX(Aurigma.GraphicsMill.Unit.Point)); result.Inflate(inflateValue, inflateValue); } return(result); }
internal static System.Windows.Forms.Cursor GetCursorDesignerProperty(IVObjectHost objectHost, string key) { object result = VObjectsUtils.GetObjectDesignerProperty(objectHost, key); if (result != null && result.GetType() == typeof(System.Windows.Forms.Cursor)) { return((System.Windows.Forms.Cursor)result); } else { return(null); } }
private void UpdateControlPoints() { if (_updateProvider) { System.Drawing.PointF[] interim = VObjectsUtils.TransformPoints(_obj.Transform, _obj.Points); for (int i = 0; i < _transformedPoints.Count; i++) { _transformedPoints[i].Location = interim[i]; } _updateProvider = false; } }
protected override System.Drawing.Rectangle GetInvalidationRectangle() { System.Drawing.Rectangle result = System.Drawing.Rectangle.Empty; if (_points.Count > 0) { System.Drawing.Point[] points = GetViewportPoints(_points.Count + 1); points[points.Length - 1] = _viewportMousePosition; result = VObjectsUtils.GetBoundingRectangle(points); int inflateValue = (int)System.Math.Ceiling(System.Math.Max(1.0f, 2 * base.Pen.Width * base.VObjectHost.HostViewer.Zoom)); result.Inflate(inflateValue, inflateValue); } return(result); }
protected override IVObject CreateObject() { PolylineVObject result = null; if (_points.Count > 1) { System.Drawing.PointF[] points = (System.Drawing.PointF[])_points.ToArray(typeof(System.Drawing.PointF)); System.Drawing.RectangleF pointsBounds = VObjectsUtils.GetBoundingRectangle(points); if (pointsBounds.Width > 1.0f && pointsBounds.Height > 1.0f) { result = new PolylineVObject(points, _closePath, _fillMode); result.Pen = base.Pen; result.Brush = base.Brush; } } return(result); }
public void DragPoint(int index, System.Drawing.PointF newPosition) { if (index < 0 || index >= _obj.Points.Length) { throw new System.ArgumentOutOfRangeException("index"); } System.Drawing.PointF dragVector = new System.Drawing.PointF(newPosition.X - _transformedPoints[index].X, newPosition.Y - _transformedPoints[index].Y); using (System.Drawing.Drawing2D.Matrix inverseMatrix = (System.Drawing.Drawing2D.Matrix)_obj.Transform.Clone()) { inverseMatrix.Invert(); VObjectsUtils.TransformVector(inverseMatrix, ref dragVector); _obj.Points[index].X += dragVector.X; _obj.Points[index].Y += dragVector.Y; } _obj.Update(); }
public override void Draw(System.Drawing.Graphics g) { if (g == null) { throw new System.ArgumentNullException("g"); } if (_points.Count > 0) { System.Drawing.Point[] points = GetViewportPoints(_points.Count + 1); points[points.Length - 1] = _viewportMousePosition; if (_closePath) { if (base.Brush != null) { System.Drawing.Drawing2D.Matrix prevBrushMatrix = PathVObjectCreateDesigner.AdaptBrushToViewport(base.Brush, this.VObjectHost.HostViewer); try { g.FillPolygon(base.Brush, points, _fillMode); } finally { if (prevBrushMatrix != null) { VObjectsUtils.SetBrushMatrix(base.Brush, prevBrushMatrix); } } } if (base.Pen != null) { g.DrawPolygon(base.CreateViewportPen(), points); } } else { if (base.Pen != null) { g.DrawLines(base.CreateViewportPen(), points); } } } }
public virtual bool NotifyMouseUp(System.Windows.Forms.MouseEventArgs e) { if (e == null) { throw new System.ArgumentNullException("e"); } if (e.Button == System.Windows.Forms.MouseButtons.Left && _areaOriginDefined) { System.Drawing.RectangleF destinationRect; if (_areaDefined) { destinationRect = VObjectsUtils.GetBoundingRectangle(_cornerPoints); } else { destinationRect = new System.Drawing.RectangleF(_cornerPoints[0], System.Drawing.SizeF.Empty); } System.Drawing.Rectangle invalidationRect = System.Drawing.Rectangle.Empty; IVObject obj = CreateObject(destinationRect); if (obj != null) { _objectHost.CurrentLayer.VObjects.Add(obj); invalidationRect = _objectHost.HostViewer.WorkspaceToControl(obj.GetTransformedVObjectBounds(), Aurigma.GraphicsMill.Unit.Point); } if (_areaDefined) { System.Drawing.Rectangle tmp = _objectHost.HostViewer.WorkspaceToControl(destinationRect, Aurigma.GraphicsMill.Unit.Point); tmp.Inflate((int)_borderPen.Width * 2, (int)_borderPen.Width * 2); invalidationRect = System.Drawing.Rectangle.Union(invalidationRect, tmp); _areaDefined = false; } _objectHost.HostViewer.InvalidateViewer(new MultiLayerViewerInvalidationTarget(invalidationRect, _objectHost.CurrentLayer)); _objectHost.CurrentDesigner = _objectHost.DefaultDesigner; } return(true); }
internal static System.Drawing.Drawing2D.Matrix AdaptBrushToViewport(System.Drawing.Brush brush, Aurigma.GraphicsMill.WinControls.ICoordinateMapper coordinateMapper) { System.Drawing.Drawing2D.Matrix originalMatrix = null; if (brush != null && brush.GetType() != typeof(System.Drawing.SolidBrush) && brush.GetType() != typeof(System.Drawing.Drawing2D.HatchBrush)) { originalMatrix = VObjectsUtils.GetBrushMatrix(brush); System.Drawing.Point viewportTranslation = coordinateMapper.WorkspaceToControl(System.Drawing.PointF.Empty, Aurigma.GraphicsMill.Unit.Pixel); float scale = coordinateMapper.GetControlPixelsPerUnitX(Aurigma.GraphicsMill.Unit.Point); System.Drawing.Drawing2D.Matrix brushMatrix = new System.Drawing.Drawing2D.Matrix(); brushMatrix.Scale(scale, scale, System.Drawing.Drawing2D.MatrixOrder.Append); brushMatrix.Translate(viewportTranslation.X, viewportTranslation.Y, System.Drawing.Drawing2D.MatrixOrder.Append); brushMatrix.Multiply(originalMatrix, System.Drawing.Drawing2D.MatrixOrder.Prepend); VObjectsUtils.SetBrushMatrix(brush, brushMatrix); } return(originalMatrix); }
public override void Draw(System.Drawing.Graphics g) { if (g == null) { throw new System.ArgumentNullException("g"); } if (_points.Count > 1) { using (System.Drawing.Pen pen = CreateViewportPen()) { System.Drawing.Point[] points = (System.Drawing.Point[])_points.ToArray(typeof(System.Drawing.Point)); if (_closePath) { if (base.Brush != null) { System.Drawing.Drawing2D.Matrix prevBrushMatrix = PathVObjectCreateDesigner.AdaptBrushToViewport(base.Brush, base.VObjectHost.HostViewer); try { g.FillPolygon(base.Brush, points, _fillMode); } finally { if (prevBrushMatrix != null) { VObjectsUtils.SetBrushMatrix(base.Brush, prevBrushMatrix); } } } g.DrawPolygon(pen, points); } else { g.DrawLines(pen, points); } } } }
protected void AdaptBrushToViewport(ICoordinateMapper coordinateMapper) { if (coordinateMapper == null) { throw new System.ArgumentNullException("coordinateMapper"); } if (_brush != null && _brush.GetType() != typeof(System.Drawing.SolidBrush) && _brush.GetType() != typeof(System.Drawing.Drawing2D.HatchBrush)) { System.Drawing.Drawing2D.Matrix originalMatrix = VObjectsUtils.GetBrushMatrix(_brush); _brushMatrices.Push(originalMatrix); System.Drawing.Point viewportTranslation = coordinateMapper.WorkspaceToControl(System.Drawing.PointF.Empty, Aurigma.GraphicsMill.Unit.Pixel); float scale = coordinateMapper.GetControlPixelsPerUnitX(Aurigma.GraphicsMill.Unit.Point); System.Drawing.Drawing2D.Matrix brushMatrix = (System.Drawing.Drawing2D.Matrix)_matrix.Clone(); brushMatrix.Scale(scale, scale, System.Drawing.Drawing2D.MatrixOrder.Append); brushMatrix.Translate(viewportTranslation.X, viewportTranslation.Y, System.Drawing.Drawing2D.MatrixOrder.Append); brushMatrix.Multiply(originalMatrix, System.Drawing.Drawing2D.MatrixOrder.Prepend); VObjectsUtils.SetBrushMatrix(_brush, brushMatrix); } }
public override bool NotifyMouseMove(System.Windows.Forms.MouseEventArgs e) { if (_dragging) { System.Drawing.PointF[] points = new System.Drawing.PointF[3]; points[0] = _point0; points[1] = _point1; _point1 = base.VObjectHost.HostViewer.ControlToWorkspace(new System.Drawing.Point(e.X, e.Y), Aurigma.GraphicsMill.Unit.Point); points[2] = _point1; System.Drawing.RectangleF workspaceChangedRect = VObjectsUtils.GetBoundingRectangle(points); if (base.Pen != null) { workspaceChangedRect.Inflate(base.Pen.Width * 2, base.Pen.Width * 2); } System.Drawing.Rectangle invalidationRect = base.VObjectHost.HostViewer.WorkspaceToControl(workspaceChangedRect, Aurigma.GraphicsMill.Unit.Point); invalidationRect.Inflate(VObject.InvalidationMargin); base.VObjectHost.HostViewer.InvalidateViewer(new MultiLayerViewerInvalidationTarget(invalidationRect)); } return(base.NotifyMouseMove(e)); }
public override void Draw(System.Drawing.Rectangle renderingRect, System.Drawing.Graphics g, ICoordinateMapper coordinateMapper) { if (g == null) { throw new System.ArgumentNullException("g"); } if (coordinateMapper == null) { throw new System.ArgumentNullException("coordinateMapper"); } // FillPath doesn't support specifying FillMode, it always uses FillMode.Alternate, // so we have to use Graphics.FillPolygon method in other cases. if (!_closePath || base.Brush == null || _fillMode == System.Drawing.Drawing2D.FillMode.Alternate) { base.Draw(renderingRect, g, coordinateMapper); } else { System.Drawing.PointF[] transformedPoints = VObjectsUtils.TransformPoints(base.Transform, _points); for (int i = 0; i < transformedPoints.Length; i++) { transformedPoints[i] = coordinateMapper.WorkspaceToControl(transformedPoints[i], Aurigma.GraphicsMill.Unit.Point); } System.Drawing.Drawing2D.SmoothingMode oldSmoothingMode = g.SmoothingMode; System.Drawing.Pen pen = base.CreateViewportPen(coordinateMapper); try { switch (base.DrawMode) { case VObjectDrawMode.Draft: g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed; break; case VObjectDrawMode.Normal: g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; break; default: throw new Aurigma.GraphicsMill.UnexpectedException(StringResources.GetString("ExStrUnexpectedDrawMode")); } if (base.Brush != null) { AdaptBrushToViewport(coordinateMapper); try { g.FillPolygon(base.Brush, transformedPoints, _fillMode); } finally { RestoreBrush(); } } if (pen != null) { g.DrawPolygon(pen, transformedPoints); } } finally { pen.Dispose(); g.SmoothingMode = oldSmoothingMode; } } }
public virtual void UpdateSettings() { _resizeProportionallyWithShift = VObjectsUtils.GetBoolDesignerProperty(_objectHost, DesignerSettingsConstants.ResizeProportionallyWithShift, _resizeProportionallyWithShift); _multiSelect = VObjectsUtils.GetBoolDesignerProperty(_objectHost, DesignerSettingsConstants.MultiSelect, _multiSelect); }
protected System.Drawing.RectangleF GetWorkspaceRectangle() { return(VObjectsUtils.GetBoundingRectangle(_point0, _point1)); }