/// <summary> /// Return cursor for command /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="zoomLevel"></param> /// <returns>null if coordinates are not fine</returns> public Cursor GetCursor(float x, float y, System.Drawing.Drawing2D.Matrix viewMatrix) { // transform x,y back to object coordinates to check for selection System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix(); mat.Multiply(this.TransformationMatrix, System.Drawing.Drawing2D.MatrixOrder.Append); mat.Multiply(this.Owner.DrawMatrix, System.Drawing.Drawing2D.MatrixOrder.Append); mat.Multiply(viewMatrix, System.Drawing.Drawing2D.MatrixOrder.Append); mat.Invert(); PointF tmpPoint = new PointF(x, y); PointF[] points = new PointF[1]; points[0] = tmpPoint; mat.TransformPoints(points); tmpPoint = points[0]; // check if this item should be selected float w = (float)this.WidthInPixels / this.Owner.ViewMatrix.Elements[0]; float h = (float)this.HeightInPixels / this.Owner.ViewMatrix.Elements[3]; // if starting coordinate fall inside this component rect if (tmpPoint.X >= 0 && tmpPoint.X <= w && tmpPoint.Y >= 0 && tmpPoint.Y <= h) { return(this.cursor); } else { return(null); } }
/// <summary> /// Check if this command can be selected and return true in case it can /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> public bool CanBeSelected(float x, float y, System.Drawing.Drawing2D.Matrix viewMatrix) { // transform x,y back to object coordinates to check for selection System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix(); mat.Multiply(this.TransformationMatrix, System.Drawing.Drawing2D.MatrixOrder.Append); mat.Multiply(this.Owner.DrawMatrix, System.Drawing.Drawing2D.MatrixOrder.Append); mat.Multiply(viewMatrix, System.Drawing.Drawing2D.MatrixOrder.Append); mat.Invert(); PointF tmpPoint = new PointF(x, y); PointF[] points = new PointF[1]; points[0] = tmpPoint; mat.TransformPoints(points); tmpPoint = points[0]; // check if this item should be selected //float tmpX = LocationInPixelsX * zoomLevel; //float tmpY = LocationInPixelsY * zoomLevel; //float w = widthInPixels; //** zoomLevel; //float h = heightInPixels; //* zoomLevel; float w = (float)this.WidthInPixels / this.Owner.ViewMatrix.Elements[0]; float h = (float)this.HeightInPixels / this.Owner.ViewMatrix.Elements[3]; // if starting coordinate fall inside this component rect if (tmpPoint.X >= 0 && tmpPoint.X <= w && tmpPoint.Y >= 0 && tmpPoint.Y <= h) { return(true); } else { return(false); } }
public virtual void Draw(float zoomLevel, System.Drawing.Graphics gc) { System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix(); mat.Multiply(this.TransformationMatrix, System.Drawing.Drawing2D.MatrixOrder.Append); mat.Multiply(this.Owner.DrawMatrix, System.Drawing.Drawing2D.MatrixOrder.Append); mat.Multiply(this.Owner.ViewMatrix, System.Drawing.Drawing2D.MatrixOrder.Append); gc.Transform = mat; float w = (float)this.WidthInPixels / this.Owner.ViewMatrix.Elements[0]; float h = (float)this.HeightInPixels / this.Owner.ViewMatrix.Elements[3]; Pen p = new Pen(Color.Gray, 1.0f / zoomLevel); gc.DrawRectangle(p, 0, 0, w, h); }
void GDIPaint(ScGraphics g, ScDrawNode node) { if (node == null) { return; } ScLayer layer = node.layer; if (node.rootLayer == null) { g.SetClip(node.clipRect); g.Transform = layer.GlobalMatrix; g.layer = layer; layer.OnGDIPaint(g); } else { ScLayer rootLayer = node.rootLayer; Matrix m = new Matrix(); m.Translate(-rootLayer.DrawBox.X, -rootLayer.DrawBox.Y); m.Multiply(layer.GlobalMatrix); g.SetClip(node.clipRect); g.Transform = m; g.layer = layer; layer.OnGDIPaint(g); m.Dispose(); } g.layer = null; g.ResetTransform(); g.ResetClip(); }
void DrawCustomItem(Graphics g, int index, int x, int y) { MemoryStream ms = new MemoryStream(); switch (index) { case 1: ResourceImages.Enabled.Save(ms, ImageFormat.Png); break; case 2: ResourceImages.Disabled.Save(ms, ImageFormat.Png); break; } System.Drawing.Image image = System.Drawing.Image.FromStream(ms); //flip the image around its center using (System.Drawing.Drawing2D.Matrix m = g.Transform) { using (System.Drawing.Drawing2D.Matrix saveM = m.Clone()) { float c = (float)y; using (System.Drawing.Drawing2D.Matrix m2 = new System.Drawing.Drawing2D.Matrix(1, 0, 0, -1, 0, 2 * c)) m.Multiply(m2); //g.Transform = m; g.DrawImage(image, new PointF((float)(x), (float)(y))); g.Transform = saveM; } } }
public static System.Drawing.Drawing2D.Matrix multiply(System.Drawing.Drawing2D.Matrix a, System.Drawing.Drawing2D.Matrix b) { //UPGRADE_TODO: Method 'java.awt.geom.AffineTransform.clone' was converted to 'System.Drawing.Drawing2D.Matrix.Clone' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073_javaawtgeomAffineTransformclone_3"' System.Drawing.Drawing2D.Matrix tm = (System.Drawing.Drawing2D.Matrix)a.Clone(); //UPGRADE_TODO: Method 'java.awt.geom.AffineTransform.concatenate' was converted to 'System.Drawing.Drawing2D.Matrix.Multiply' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073_javaawtgeomAffineTransformconcatenate_javaawtgeomAffineTransform_3"' tm.Multiply(b, System.Drawing.Drawing2D.MatrixOrder.Append); return(tm); }
/// <summary> /// Draw all areas of the selected quest and highlight the selected area. /// </summary> private void Area_Paint(object sender, PaintEventArgs e) { e.Graphics.Clear(Area.BackColor); Matrix transformMatrix = new Matrix(); transformMatrix.Rotate(90); transformMatrix.Multiply(new Matrix(-1, 0, 0, 1, 0, 0)); // Flip x-axis WoWQuestStep[] steps = ((QuestDisplayData)bsQuests.Current).Steps; float maxX = steps.Max(step => step.AreaPoints.Max(ap => ap.X)); float maxY = steps.Max(step => step.AreaPoints.Max(ap => ap.Y)); transformMatrix.Translate(-maxX - 5, -maxY - 5); e.Graphics.Transform = transformMatrix; // Draw all areas foreach (WoWQuestStep step in steps) { PointF[] drawPoints = ConvertToDrawingPoints(step.AreaPoints); if (drawPoints.Length < 3) { foreach (PointF point in drawPoints) { // Draw a point 5x5 pixels e.Graphics.FillEllipse(AREA_FILL, point.X - 2, point.Y - 2, 5F, 5F); e.Graphics.DrawEllipse(AREA_BORDER, point.X - 2, point.Y - 2, 5F, 5F); } } else { e.Graphics.FillPolygon(AREA_FILL, drawPoints); e.Graphics.DrawPolygon(AREA_BORDER, drawPoints); } } // Highlight selected area if (SelectedAreaPoints != null) { if (SelectedAreaPoints.Length < 3) { foreach (PointF point in SelectedAreaPoints) { e.Graphics.FillEllipse(AREA_HIGHLIGHT, point.X - 2, point.Y - 2, 5F, 5F); e.Graphics.DrawEllipse(AREA_BORDER, point.X - 2, point.Y - 2, 5F, 5F); } } else { e.Graphics.FillPolygon(AREA_HIGHLIGHT, this.SelectedAreaPoints); e.Graphics.DrawPolygon(AREA_BORDER, this.SelectedAreaPoints); } } }
/// <summary> /// Calculates the cumulative transform. /// </summary> /// <remarks>Once this method is executed, the <see cref="CumulativeTransform"/> /// property will reflect any changes in the transform parameters.</remarks> protected virtual void Calculate() { if (!this.RecalculationRequired) { return; } // The cumulative transform is the product of the transform of the // parent graphic and the transform of this graphic (i.e. the current transform) // If there is no parent graphic, then the cumulative transform = current transform if (_cumulativeTransform == null) { _cumulativeTransform = new Matrix(); } _cumulativeTransform.Reset(); IGraphic parentGraphic = this.OwnerGraphic.ParentGraphic; if (parentGraphic != null) { _cumulativeTransform.Multiply(parentGraphic.SpatialTransform.CumulativeTransform); } CalculatePreTransform(_cumulativeTransform); _cumulativeTransform.Multiply(this.Transform); CalculatePostTransform(_cumulativeTransform); this.RecalculationRequired = false; // Validate if there's a validation policy in place. Otherwise, assume all is good. if (_validationPolicy != null) { _validationPolicy.Validate(this); } }
public GDILayer PushLayer(GDIGraphics g, ScDrawNode node) { ScLayer sclayer = node.layer; GDILayer gdiLayer = new GDILayer(g); GDILayerParameters layerParameters = new GDILayerParameters(); layerParameters.ContentBounds = sclayer.DrawBox; layerParameters.MaskAntialiasMode = GDIAntialiasMode.PerPrimitive; layerParameters.Opacity = sclayer.Opacity; layerParameters.ClipRect = new RectangleF( (int)(node.clipRect.X - sclayer.DrawBox.X - 1), (int)(node.clipRect.Y - sclayer.DrawBox.Y - 1), (int)(node.clipRect.Width + 2), (int)(node.clipRect.Height + 2)); Matrix m = new Matrix(); m.Translate(-sclayer.DrawBox.X, -sclayer.DrawBox.Y); m.Multiply(sclayer.GlobalMatrix); node.m = m; node.rootLayer = node.layer; if (!sclayer.Parent.IsComputedStraight) { m = new Matrix(); m.Translate(-sclayer.Parent.DrawBox.X, -sclayer.Parent.DrawBox.Y); m.Multiply(sclayer.GlobalMatrix); layerParameters.GeometricMask = sclayer.CreateTransLastHitGeometryForGDI(m); m.Dispose(); } else { layerParameters.GeometricMask = sclayer.TransLastHitGraphicsPath; layerParameters.parentClipRect = node.clipRect; } node.clipRect = layerParameters.ClipRect; layerParameters.sclayer = sclayer; g.PushLayer(layerParameters, gdiLayer); return(gdiLayer); }
private void SynchronizeChildMatrices() { if (_childMatrices != null && !_matrix.IsIdentity) { _updatingChildren = true; try { for (int i = 0; i < _children.Count; i++) { System.Drawing.Drawing2D.Matrix m = (System.Drawing.Drawing2D.Matrix)_childMatrices[i].Clone(); m.Multiply(_matrix, System.Drawing.Drawing2D.MatrixOrder.Append); _children[i].Transform = m; } } finally { _updatingChildren = false; } } }
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); }
/// <summary> /// Main Overloaded Node Drawing /// Functionality Copied from examples and by looking at how it is implemeted by Default /// /// The major difference between this DrawNode and Default behavior is to allow an Image to be in the node /// For a visual Cue. /// </summary> /// <param name="node"></param> /// <param name="graphics"></param> /// <returns></returns> bool DrawNode(DrawingNode node, object graphics) { Graphics g = (Graphics)graphics; Image image = getGroupImage(node.UserData); //Set Alpha on Given Fill Color so Image Can show Through.. //node.Attr.FillColor = new DrawingColor(100, node.Attr.FillColor.R,node.Attr.FillColor.G,node.Attr.FillColor.B); Color border = Color.FromArgb(node.Attr.Color.R, node.Attr.Color.G, node.Attr.Color.B); Pen borderPen = new Pen(border, (float)node.Attr.LineWidth); SolidBrush borderBrush = new SolidBrush(border); Color fill = Color.FromArgb(200, node.Attr.FillColor.R, node.Attr.FillColor.G, node.Attr.FillColor.B); using (System.Drawing.Drawing2D.Matrix m = g.Transform) { using (System.Drawing.Drawing2D.Matrix saveM = m.Clone()) { System.Drawing.Drawing2D.GraphicsPath path = FillTheGraphicsPath(node.GeometryNode.BoundaryCurve); g.SetClip(FillTheGraphicsPath(node.GeometryNode.BoundaryCurve)); using (var m2 = new System.Drawing.Drawing2D.Matrix(1, 0, 0, -1, 0, 2 * (float)node.GeometryNode.Center.Y)) m.Multiply(m2); g.Transform = m; g.FillPath(new SolidBrush(fill), path); //Fill the inside g.DrawImage(image, new PointF((float)(node.GeometryNode.Center.X - node.GeometryNode.Width / 2) + 2, (float)(node.GeometryNode.Center.Y - node.GeometryNode.Height / 2) + 2)); Font f = new Font(node.Label.FontName, (float)node.Label.FontSize, (System.Drawing.FontStyle)(int) node.Label.FontStyle); g.DrawString(node.LabelText, f, new SolidBrush(ForeColor), new PointF((float)(node.GeometryNode.Center.X - node.GeometryNode.Width / 2 + image.Width), (float)(node.GeometryNode.Center.Y - g.MeasureString(node.LabelText, f).Height / 2))); g.DrawPath(borderPen, path); // Draw the Border g.Transform = saveM; g.ResetClip(); } } image.Dispose(); return(true);//returning false would enable the default rendering }
bool DrawNode(DrawingNode node, object graphics) { Graphics g = (Graphics)graphics; Image image = ImageOfNode(node); //flip the image around its center using (System.Drawing.Drawing2D.Matrix m = g.Transform) { using (System.Drawing.Drawing2D.Matrix saveM = m.Clone()) { g.SetClip(FillTheGraphicsPath(node.GeometryNode.BoundaryCurve)); using (var m2 = new System.Drawing.Drawing2D.Matrix(1, 0, 0, -1, 0, 2 * (float)node.GeometryNode.Center.Y)) m.Multiply(m2); g.Transform = m; g.DrawImage(image, new PointF((float)(node.GeometryNode.Center.X - node.GeometryNode.Width / 2), (float)(node.GeometryNode.Center.Y - node.GeometryNode.Height / 2))); g.Transform = saveM; } } return(true);//returning false would enable the default rendering }
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); } }
private void drawUsingPolygon(DrawContext context, System.Drawing.Drawing2D.Matrix transform, ScenicColor color) { #if PENDING if (glyphPolygons == null) { glyphPolygons = new FilledPath[glyphCodes.Length]; for (int i = 0; i < glyphCodes.Length; i++) { System.Drawing.Drawing2D.Matrix temp_Matrix; temp_Matrix = new System.Drawing.Drawing2D.Matrix(); temp_Matrix.Translate((float)positions[i * 2], (float)positions[i * 2 + 1]); System.Drawing.Drawing2D.Matrix at = temp_Matrix; //UPGRADE_TODO: Interface 'java.awt.Shape' was converted to 'System.Drawing.Drawing2D.GraphicsPath' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073_3"' System.Drawing.Drawing2D.GraphicsPath shape = TextRenderer.getGlyphOutline(font, at, glyphCodes[i]); Path path = new AWTShapePath(shape); glyphPolygons[i] = new FilledPath(path); } } System.Drawing.Drawing2D.Matrix temp = new System.Drawing.Drawing2D.Matrix(); for (int i = 0; i < glyphPolygons.Length; i++) { System.Drawing.Drawing2D.Matrix temp_Matrix2; temp_Matrix2 = new System.Drawing.Drawing2D.Matrix(); temp_Matrix2.Translate((float)positions[i * 2], (float)positions[i * 2 + 1]); System.Drawing.Drawing2D.Matrix at = temp_Matrix2; //UPGRADE_ISSUE: Method 'java.awt.geom.AffineTransform.setTransform' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaawtgeomAffineTransformsetTransform_javaawtgeomAffineTransform_3"' temp.setTransform(transform); //UPGRADE_TODO: Method 'java.awt.geom.AffineTransform.concatenate' was converted to 'System.Drawing.Drawing2D.Matrix.Multiply' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073_javaawtgeomAffineTransformconcatenate_javaawtgeomAffineTransform_3"' temp.Multiply(at, System.Drawing.Drawing2D.MatrixOrder.Append); glyphPolygons[i].draw(context, temp, color); } #endif }
/// <summary> /// Draw page and its children /// </summary> /// <param name="gc"></param> /// <param name="clipRect"></param> public void Draw(Graphics gc, Rectangle clipRect) { System.Drawing.Drawing2D.Matrix finalMatrix = new System.Drawing.Drawing2D.Matrix(); finalMatrix = this.drawMatrix.Clone(); finalMatrix.Multiply(this.ViewMatrix, System.Drawing.Drawing2D.MatrixOrder.Append); gc.Transform = finalMatrix; // draw fill color using (SolidBrush brush = new SolidBrush(fillColor)) { gc.FillRectangle(brush, 0, 0, (float)this.WidthInPixels, (float)this.HeightInPixels); } // draw background image if (pictureForDisplay != null) { gc.DrawImage(pictureForDisplay, 0, 0, (float)this.WidthInPixels, (float)this.HeightInPixels); } this.LastDrawMatrix = finalMatrix; EditorController.Instance.Grid.Draw(gc); foreach (EditorItem item in Children) { item.Draw(this.ViewMatrix, gc, clipRect); } // draw item commands foreach (EditorItem child in Children) { child.DrawCommands((float)this.ZoomLevel / 100, gc); } }
/// <summary> /// Draw page and its children /// </summary> /// <param name="gc"></param> /// <param name="clipRect"></param> public void Draw(Graphics gc, Rectangle clipRect) { System.Drawing.Drawing2D.Matrix finalMatrix = new System.Drawing.Drawing2D.Matrix(); finalMatrix = this.drawMatrix.Clone(); finalMatrix.Multiply(this.ViewMatrix, System.Drawing.Drawing2D.MatrixOrder.Append); gc.Transform = finalMatrix; // draw fill color using (SolidBrush brush = new SolidBrush(fillColor)) { gc.FillRectangle(brush, 0, 0, (float)this.WidthInPixels, (float)this.HeightInPixels); } // draw background image if (pictureForDisplay != null) { gc.DrawImage(pictureForDisplay, 0, 0, (float)this.WidthInPixels, (float)this.HeightInPixels); } this.LastDrawMatrix = finalMatrix; EditorController.Instance.Grid.Draw(gc); foreach(EditorItem item in Children) { item.Draw(this.ViewMatrix, gc, clipRect); } // draw item commands foreach (EditorItem child in Children) { child.DrawCommands((float)this.ZoomLevel / 100, gc); } }
public override void Move(float dx, float dy) { // convert dx, dy to vector in object space System.Drawing.Drawing2D.Matrix mat = this.Owner.DrawMatrix.Clone(); mat.Multiply(this.TransformationMatrix, System.Drawing.Drawing2D.MatrixOrder.Append); mat.Multiply(this.Owner.ViewMatrix, System.Drawing.Drawing2D.MatrixOrder.Append); mat.Invert(); PointF tmpPoint = new PointF(dx, dy); PointF[] points = new PointF[1]; points[0] = tmpPoint; mat.TransformVectors(points); tmpPoint = points[0]; dx = tmpPoint.X; dy = tmpPoint.Y; float udx = UnitsManager.Instance.ConvertUnit(tmpPoint.X, MeasureUnits.pixel, this.Owner.MeasureUnit); float udy = UnitsManager.Instance.ConvertUnit(tmpPoint.Y, MeasureUnits.pixel, this.Owner.MeasureUnit); //dx = UnitsManager.Instance.ConvertUnit(tmpPoint.X, MeasureUnits.pixel, this.Owner.MeasureUnit); //dy = UnitsManager.Instance.ConvertUnit(tmpPoint.Y, MeasureUnits.pixel, this.Owner.MeasureUnit); switch (this.CommandPosition) { case CommandPosition.TopLeft: this.Owner.LocationInUnitsX = startLocX + udx; this.Owner.LocationInUnitsY = startLocY + udy; this.Owner.WidthInPixels = startWidth - dx; this.Owner.HeightInPixels = startHeight - dy; this.Owner.AnchorAll(udx, udy, -dx, -dy); break; case CommandPosition.TopCenter: this.Owner.LocationInUnitsY = startLocY + udy; this.Owner.HeightInPixels = startHeight - dy; this.Owner.AnchorAll(0.0f, udy, 0.0f, -dy); break; case CommandPosition.TopRight: this.Owner.LocationInUnitsY = startLocY + udy; this.Owner.WidthInPixels = startWidth + dx; this.Owner.HeightInPixels = startHeight - dy; this.Owner.AnchorAll(0.0f, udy, dx, -dy); break; case CommandPosition.MiddleLeft: this.Owner.LocationInUnitsX = startLocX + udx; this.Owner.WidthInPixels = startWidth - dx; this.Owner.AnchorAll(udx, 0.0f, -dx, 0.0f); break; case CommandPosition.MiddleRight: this.Owner.WidthInPixels = startWidth + dx; this.Owner.AnchorAll(0.0f, 0.0f, dx, 0.0f); break; case CommandPosition.BottomLeft: this.Owner.LocationInUnitsX = startLocX + udx; this.Owner.WidthInPixels = startWidth - dx; this.Owner.HeightInPixels = startHeight + dy; this.Owner.AnchorAll(udx, 0.0f, -dx, dy); break; case CommandPosition.BottomCenter: this.Owner.HeightInPixels = startHeight + dy; this.Owner.AnchorAll(0.0f, 0.0f, 0.0f, dy); break; case CommandPosition.BottomRight: this.Owner.WidthInPixels = startWidth + dx; this.Owner.HeightInPixels = startHeight + dy; this.Owner.AnchorAll(0.0f, 0.0f, dx, dy); break; } if (this.Owner.WidthInPixels < UnitsManager.Instance.ConvertUnit(1.0f, MeasureUnits.mm, MeasureUnits.pixel)) { this.Owner.WidthInPixels = UnitsManager.Instance.ConvertUnit(1.0f, MeasureUnits.mm, MeasureUnits.pixel); } if (this.Owner.HeightInPixels < UnitsManager.Instance.ConvertUnit(1.0f, MeasureUnits.mm, MeasureUnits.pixel)) { this.Owner.HeightInPixels = UnitsManager.Instance.ConvertUnit(1.0f, MeasureUnits.mm, MeasureUnits.pixel); } this.Owner.DockAll(); if (this.Owner.Parent != null) { this.Owner.Parent.DockAll(); } }
private void drawUsingPolygon(DrawContext context, System.Drawing.Drawing2D.Matrix transform, ScenicColor color) { #if PENDING if (glyphPolygons == null) { glyphPolygons = new FilledPath[glyphCodes.Length]; for (int i = 0; i < glyphCodes.Length; i++) { System.Drawing.Drawing2D.Matrix temp_Matrix; temp_Matrix = new System.Drawing.Drawing2D.Matrix(); temp_Matrix.Translate((float) positions[i * 2], (float) positions[i * 2 + 1]); System.Drawing.Drawing2D.Matrix at = temp_Matrix; //UPGRADE_TODO: Interface 'java.awt.Shape' was converted to 'System.Drawing.Drawing2D.GraphicsPath' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073_3"' System.Drawing.Drawing2D.GraphicsPath shape = TextRenderer.getGlyphOutline(font, at, glyphCodes[i]); Path path = new AWTShapePath(shape); glyphPolygons[i] = new FilledPath(path); } } System.Drawing.Drawing2D.Matrix temp = new System.Drawing.Drawing2D.Matrix(); for (int i = 0; i < glyphPolygons.Length; i++) { System.Drawing.Drawing2D.Matrix temp_Matrix2; temp_Matrix2 = new System.Drawing.Drawing2D.Matrix(); temp_Matrix2.Translate((float) positions[i * 2], (float) positions[i * 2 + 1]); System.Drawing.Drawing2D.Matrix at = temp_Matrix2; //UPGRADE_ISSUE: Method 'java.awt.geom.AffineTransform.setTransform' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaawtgeomAffineTransformsetTransform_javaawtgeomAffineTransform_3"' temp.setTransform(transform); //UPGRADE_TODO: Method 'java.awt.geom.AffineTransform.concatenate' was converted to 'System.Drawing.Drawing2D.Matrix.Multiply' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073_javaawtgeomAffineTransformconcatenate_javaawtgeomAffineTransform_3"' temp.Multiply(at, System.Drawing.Drawing2D.MatrixOrder.Append); glyphPolygons[i].draw(context, temp, color); } #endif }
private void DrawFillPattern(Graphics g) { Stopwatch sw = Stopwatch.StartNew(); float matrixScale; var fillPattern = FillPattern; if (fillPattern == null) return; if (fillPattern.Target == FillPatternTarget.Model) matrixScale = Scale; else matrixScale = Scale * 10; try { var width = (ActualWidth == 0 ? Width : ActualWidth) == 0 ? 100 : (ActualWidth == 0 ? Width : ActualWidth); if (double.IsNaN(width)) width = 100; var height = (ActualHeight == 0 ? Height : ActualHeight) == 0 ? 30 : (ActualHeight == 0 ? Height : ActualHeight); if (double.IsNaN(height)) height = 30; var viewRect = new Rectangle(0, 0, (int)width, (int)height); var centerX = (viewRect.Left + viewRect.Left + viewRect.Width) / 2; var centerY = (viewRect.Top + viewRect.Top + viewRect.Height) / 2; g.TranslateTransform(centerX, centerY); var rectF = new Rectangle(-1, -1, 2, 2); g.FillRectangle(Brushes.Blue, rectF); //draw a small rectangle in the center of the image g.ResetTransform(); var fillGrids = fillPattern.GetFillGrids(); Debug.Print(new string('-', 100)); Debug.Print("FilPattern name: {0}", fillPattern.Name); if (fillPattern.Target == FillPatternTarget.Model) Debug.Print("FillPattern type: Model"); else Debug.Print("FillPattern type: Drafting"); Debug.Print("Matrix scale: {0}", matrixScale); Debug.Print("Grids count: {0}", fillGrids.Count); Debug.Print("Len\\Area: {0}", fillPattern.LengthPerArea); Debug.Print("Lines\\Len: {0}", fillPattern.LinesPerLength); Debug.Print("Strokes\\Area: {0}", fillPattern.StrokesPerArea); foreach (var fillGrid in fillGrids) { var degreeAngle = (float)RadianToGradus(fillGrid.Angle); Debug.Print(new string('-', 50)); Debug.Print("Origin: U:{0} V:{1}", fillGrid.Origin.U, fillGrid.Origin.V); Debug.Print("Offset: {0}", fillGrid.Offset); Debug.Print("Angle: {0}", degreeAngle); Debug.Print("Shift: {0}", fillGrid.Shift); var pen = new Pen(System.Drawing.Color.Black) { Width = 1f / matrixScale }; float dashLength = 1; var segments = fillGrid.GetSegments(); if (segments.Count > 0) { pen.DashPattern = segments .Select(Convert.ToSingle) .ToArray(); Debug.Print("\tSegments:"); foreach (var segment in segments) { Debug.Print("\t\t{0}", segment); } dashLength = pen.DashPattern.Sum(); } g.ResetTransform(); var rotateMatrix = new Matrix(); rotateMatrix.Rotate(degreeAngle); var matrix = new Matrix(1, 0, 0, -1, centerX, centerY); //-1 reflects about x-axis matrix.Scale(matrixScale, matrixScale); matrix.Translate((float)fillGrid.Origin.U, (float)fillGrid.Origin.V); var backMatrix = matrix.Clone(); backMatrix.Multiply(rotateMatrix); matrix.Multiply(rotateMatrix); var offset = (-10) * dashLength; matrix.Translate(offset, 0); backMatrix.Translate(offset, 0); Debug.Print("Offset: {0}", offset); bool moving_forward = true; bool moving_back = true; int safety = 500; double alternator = 0; while (moving_forward || moving_back) //draw segments shifting and offsetting each time { Debug.Write("*"); var rectF1 = new RectangleF(-2 / matrixScale, -2 / matrixScale, 4 / matrixScale, 4 / matrixScale); if (moving_forward && LineIntersectsRect(matrix, viewRect)) { g.Transform = matrix; g.DrawLine(pen, new PointF(0, 0), new PointF(LENGTH, 0)); } else { moving_forward = false; Debug.Print("\n----> Matrix does not intersect view"); } if (moving_back && LineIntersectsRect(backMatrix, viewRect)) { g.Transform = backMatrix; g.DrawLine(pen, new PointF(0, 0), new PointF(LENGTH, 0)); } else { moving_back = false; Debug.Print("\n----> Back matrix does not intersect view"); } if (safety == 0) { Debug.Print("\n--------> Safety limit exceeded"); break; } else --safety; matrix.Translate((float)fillGrid.Shift, (float)fillGrid.Offset); backMatrix.Translate(-(float)fillGrid.Shift, -(float)fillGrid.Offset); alternator += fillGrid.Shift; if (Math.Abs(alternator) > Math.Abs(offset)) { Debug.Print("\n----> Alternating"); matrix.Translate(offset, 0); backMatrix.Translate(offset, 0); alternator = 0d; } } } sw.Stop(); g.ResetTransform(); #if DEBUG g.DrawString(string.Format("{0} ms", sw.ElapsedMilliseconds), System.Drawing.SystemFonts.DefaultFont, Brushes.Red, 0, 0); #endif Debug.Print(new string('-', 50)); Pen p = new Pen(System.Drawing.Color.Black); p.Width = 1f / matrixScale; Debug.Print("Finished"); } catch (Exception ex) { Debug.Print(ex.ToString()); } }
/// <summary> /// Return cursor for command /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="zoomLevel"></param> /// <returns>null if coordinates are not fine</returns> public Cursor GetCursor(float x, float y, System.Drawing.Drawing2D.Matrix viewMatrix) { // transform x,y back to object coordinates to check for selection System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix(); mat.Multiply(this.TransformationMatrix, System.Drawing.Drawing2D.MatrixOrder.Append); mat.Multiply(this.Owner.DrawMatrix, System.Drawing.Drawing2D.MatrixOrder.Append); mat.Multiply(viewMatrix, System.Drawing.Drawing2D.MatrixOrder.Append); mat.Invert(); PointF tmpPoint = new PointF(x, y); PointF[] points = new PointF[1]; points[0] = tmpPoint; mat.TransformPoints(points); tmpPoint = points[0]; // check if this item should be selected float w = (float)this.WidthInPixels / this.Owner.ViewMatrix.Elements[0]; float h = (float)this.HeightInPixels / this.Owner.ViewMatrix.Elements[3]; // if starting coordinate fall inside this component rect if (tmpPoint.X >= 0 && tmpPoint.X <= w && tmpPoint.Y >= 0 && tmpPoint.Y <= h) { return this.cursor; } else { return null; } }
/// <summary> /// Check if this command can be selected and return true in case it can /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> public bool CanBeSelected(float x, float y, System.Drawing.Drawing2D.Matrix viewMatrix) { // transform x,y back to object coordinates to check for selection System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix(); mat.Multiply(this.TransformationMatrix, System.Drawing.Drawing2D.MatrixOrder.Append); mat.Multiply(this.Owner.DrawMatrix, System.Drawing.Drawing2D.MatrixOrder.Append); mat.Multiply(viewMatrix, System.Drawing.Drawing2D.MatrixOrder.Append); mat.Invert(); PointF tmpPoint = new PointF(x, y); PointF[] points = new PointF[1]; points[0] = tmpPoint; mat.TransformPoints(points); tmpPoint = points[0]; // check if this item should be selected //float tmpX = LocationInPixelsX * zoomLevel; //float tmpY = LocationInPixelsY * zoomLevel; //float w = widthInPixels; //** zoomLevel; //float h = heightInPixels; //* zoomLevel; float w = (float)this.WidthInPixels / this.Owner.ViewMatrix.Elements[0]; float h = (float)this.HeightInPixels / this.Owner.ViewMatrix.Elements[3]; // if starting coordinate fall inside this component rect if (tmpPoint.X >= 0 && tmpPoint.X <= w && tmpPoint.Y >= 0 && tmpPoint.Y <= h) { return true; } else { return false; } }
private void DrawFillPattern(Graphics gfx, double width, double height) { // verify fill pattern var fillPattern = FillPattern; if (fillPattern == null) { return; } // determine drawing scale float matrixScale; if (fillPattern.Target == FillPatternTarget.Model) { matrixScale = _scale; } else { matrixScale = _scale * 10; } // prepare pen var pen = new Pen(System.Drawing.Color.Black) { Width = 1f / matrixScale }; try { // setup rectangle and center var viewRect = new Rectangle(0, 0, (int)width, (int)height); var centerX = (viewRect.Left + viewRect.Left + viewRect.Width) / 2; var centerY = (viewRect.Top + viewRect.Top + viewRect.Height) / 2; gfx.ResetTransform(); // draw each fill grid foreach (var fillGrid in fillPattern.GetFillGrids()) { // radian to degree: inline math is faster var degreeAngle = (float)(fillGrid.Angle * 180 / Math.PI); // setup pen dash float dashLength = 1; var segments = fillGrid.GetSegments(); if (segments.Count > 0) { pen.DashPattern = segments.Select(Convert.ToSingle).ToArray(); dashLength = pen.DashPattern.Sum(); } gfx.ResetTransform(); // determine offset and rotation var offset = (-10) * dashLength; var rotateMatrix = new Matrix(); rotateMatrix.Rotate(degreeAngle); var matrix = new Matrix(1, 0, 0, -1, centerX, centerY); matrix.Scale(matrixScale, matrixScale); matrix.Translate((float)fillGrid.Origin.U, (float)fillGrid.Origin.V); // make a copy for backward move var backMatrix = matrix.Clone(); matrix.Multiply(rotateMatrix); matrix.Translate(offset, 0); backMatrix.Multiply(rotateMatrix); backMatrix.Translate(offset, 0); int safety = 250; double alternator = 0; // draw moving forward while (IntersectsWith(matrix, viewRect) && safety > 0) { gfx.Transform = matrix; gfx.DrawLine(pen, 0, 0, _length, 0); matrix.Translate((float)fillGrid.Shift, (float)fillGrid.Offset); alternator += fillGrid.Shift; if (Math.Abs(alternator) > Math.Abs(offset)) { matrix.Translate(offset, 0); alternator = 0d; } --safety; } // draw moving backward safety = 250; alternator = 0; while (IntersectsWith(backMatrix, viewRect) && safety > 0) { gfx.Transform = backMatrix; gfx.DrawLine(pen, 0, 0, _length, 0); backMatrix.Translate(-(float)fillGrid.Shift, -(float)fillGrid.Offset); alternator += fillGrid.Shift; if (Math.Abs(alternator) > Math.Abs(offset)) { backMatrix.Translate(offset, 0); alternator = 0d; } --safety; } } } catch (Exception ex) { logger.Debug(ex.ToString()); } }
private void DrawFillPattern(Graphics g) { Stopwatch sw = Stopwatch.StartNew(); float matrixScale; var fillPattern = FillPattern; if (fillPattern == null) { return; } if (fillPattern.Target == FillPatternTarget.Model) { matrixScale = Scale; } else { matrixScale = Scale * 10; } try { var width = (ActualWidth == 0 ? Width : ActualWidth) == 0 ? 100 : (ActualWidth == 0 ? Width : ActualWidth); if (double.IsNaN(width)) { width = 100; } var height = (ActualHeight == 0 ? Height : ActualHeight) == 0 ? 30 : (ActualHeight == 0 ? Height : ActualHeight); if (double.IsNaN(height)) { height = 30; } var viewRect = new Rectangle( 0, 0, (int)width, (int)height); var centerX = (viewRect.Left + viewRect.Left + viewRect.Width) / 2; var centerY = (viewRect.Top + viewRect.Top + viewRect.Height) / 2; g.TranslateTransform(centerX, centerY); var rectF = new Rectangle(-1, -1, 2, 2); g.FillRectangle(Brushes.Blue, rectF); //draw a small rectangle in the center of the image g.ResetTransform(); var fillGrids = fillPattern.GetFillGrids(); Debug.Print(new string( '-', 100 )); Debug.Print("FilPattern name: {0}", fillPattern.Name); if (fillPattern.Target == FillPatternTarget.Model) { Debug.Print("FillPattern type: Model"); } else { Debug.Print("FillPattern type: Drafting"); } Debug.Print("Matrix scale: {0}", matrixScale); Debug.Print("Grids count: {0}", fillGrids.Count); Debug.Print("Len\\Area: {0}", fillPattern.LengthPerArea); Debug.Print("Lines\\Len: {0}", fillPattern.LinesPerLength); Debug.Print("Strokes\\Area: {0}", fillPattern.StrokesPerArea); foreach (var fillGrid in fillGrids) { var degreeAngle = (float)RadianToGradus(fillGrid.Angle); Debug.Print(new string( '-', 50 )); Debug.Print("Origin: U:{0} V:{1}", fillGrid.Origin.U, fillGrid.Origin.V); Debug.Print("Offset: {0}", fillGrid.Offset); Debug.Print("Angle: {0}", degreeAngle); Debug.Print("Shift: {0}", fillGrid.Shift); var pen = new Pen(System.Drawing.Color.Black) { Width = 1f / matrixScale }; float dashLength = 1; var segments = fillGrid.GetSegments(); if (segments.Count > 0) { pen.DashPattern = segments .Select(s => Math.Max(float.Epsilon, Convert.ToSingle(s))) .ToArray(); Debug.Print("\tSegments:"); foreach (var segment in segments) { Debug.Print("\t\t{0}", segment); } dashLength = pen.DashPattern.Sum(); } g.ResetTransform(); var rotateMatrix = new Matrix(); rotateMatrix.Rotate(degreeAngle); var matrix = new Matrix( 1, 0, 0, -1, centerX, centerY); //-1 reflects about x-axis matrix.Scale(matrixScale, matrixScale); matrix.Translate((float)fillGrid.Origin.U, (float)fillGrid.Origin.V); var backMatrix = matrix.Clone(); backMatrix.Multiply(rotateMatrix); matrix.Multiply(rotateMatrix); var offset = (-10) * dashLength; matrix.Translate(offset, 0); backMatrix.Translate(offset, 0); Debug.Print("Offset: {0}", offset); bool moving_forward = true; bool moving_back = true; int safety = 500; double alternator = 0; while (moving_forward || moving_back) // draw segments shifting and offsetting each time { Debug.Write("*"); var rectF1 = new RectangleF( -2 / matrixScale, -2 / matrixScale, 4 / matrixScale, 4 / matrixScale); if (moving_forward && LineIntersectsRect( matrix, viewRect)) { g.Transform = matrix; g.DrawLine(pen, new PointF(0, 0), new PointF(LENGTH, 0)); } else { moving_forward = false; Debug.Print("\n----> Matrix does not intersect view"); } if (moving_back && LineIntersectsRect( backMatrix, viewRect)) { g.Transform = backMatrix; g.DrawLine(pen, new PointF(0, 0), new PointF(LENGTH, 0)); } else { moving_back = false; Debug.Print("\n----> Back matrix does not intersect view"); } if (safety == 0) { Debug.Print("\n--------> Safety limit exceeded"); break; } else { --safety; } matrix.Translate((float)fillGrid.Shift, (float)fillGrid.Offset); backMatrix.Translate(-(float)fillGrid.Shift, -(float)fillGrid.Offset); alternator += fillGrid.Shift; if (Math.Abs(alternator) > Math.Abs(offset)) { Debug.Print("\n----> Alternating"); matrix.Translate(offset, 0); backMatrix.Translate(offset, 0); alternator = 0d; } } } sw.Stop(); g.ResetTransform(); #if DEBUG g.DrawString(string.Format( "{0} ms", sw.ElapsedMilliseconds), System.Drawing.SystemFonts.DefaultFont, Brushes.Red, 0, 0); #endif Debug.Print(new string( '-', 50 )); Pen p = new Pen(System.Drawing.Color.Black); p.Width = 1f / matrixScale; Debug.Print("Finished"); } catch (Exception ex) { Debug.Print(ex.ToString()); } }