static public void TransformPoints(PointF[] points, PointF origin, bool diagonal, bool horizontal, bool vertical) { Matrix translate = new Matrix(); Matrix rotate = new Matrix(); // Put the points into origin/local space translate.Translate(-origin.X, -origin.Y); translate.TransformPoints(points); // Apply the flips/rotations (order matters) if (horizontal) { Matrix h = new Matrix(-1, 0, 0, 1, 0, 0); rotate.Multiply(h); } if (vertical) { Matrix v = new Matrix(1, 0, 0, -1, 0, 0); rotate.Multiply(v); } if (diagonal) { Matrix d = new Matrix(0, 1, 1, 0, 0, 0); rotate.Multiply(d); } // Apply the combined flip/rotate transformation rotate.TransformPoints(points); // Put points back into world space translate.Invert(); translate.TransformPoints(points); }
public static void SetGraphTransform(Graph graph, Graphics graphics) { var pen = new Pen(Brushes.Black); using (System.Drawing.Drawing2D.Matrix m = graphics.Transform) { using (System.Drawing.Drawing2D.Matrix saveM = m.Clone()) { foreach (Microsoft.Msagl.Drawing.Node node in graph.Nodes) { graphics.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); graphics.DrawLine(pen, PointF(node.GeometryNode.Center), PointF(new Microsoft.Msagl.Core.Geometry.Point((int)node.GeometryNode.Center.X + 20, (int)node.GeometryNode.Center.Y + 20))); graphics.Transform = m; graphics.Transform = saveM; graphics.ResetClip(); } } } /* * //instead of setting transormation for graphics it is possible to transform the geometry graph, just to test that GeometryGraph.Transform() works * * var planeTransformation=new PlaneTransformation(scale,0,dx, 0, scale, dy); * geometryGraph.Transform(planeTransformation); */ // graphics.Transform = new Matrix((float)scale, 0, 0, (float)scale, (float)dx, (float)dy); }
private static Matrix getAffineTransformMatrix(PointF p01, PointF p02, PointF p03, PointF p11, PointF p12, PointF p13) { Matrix a = new Matrix(p02.X - p01.X, p02.Y - p01.Y, p03.X - p01.X, p03.Y - p01.Y, p01.X, p01.Y); Matrix b = new Matrix(p12.X - p11.X, p12.Y - p11.Y, p13.X - p11.X, p13.Y - p11.Y, p11.X, p11.Y); if (!a.IsInvertible) return null; a.Invert(); a.Multiply(b, MatrixOrder.Append); return a; }
public override void DrawRect(System.Drawing.RectangleF dirtyRect) { Graphics g = new Graphics(); int offset = 20; // Invert matrix: Matrix m = new Matrix(1, 2, 3, 4, 0, 0); g.DrawString("Original Matrix:", this.Font, Brushes.Black, 10, 10); DrawMatrix(m, g, 10, 10 + offset); g.DrawString("Inverted Matrix:", this.Font, Brushes.Black, 10, 10 + 2*offset); m.Invert(); DrawMatrix(m, g, 10, 10 + 3 * offset); // Matrix multiplication - MatrixOrder.Append: Matrix m1 = new Matrix(1, 2, 3, 4, 0, 1); Matrix m2 = new Matrix(0, 1, 2, 1, 0, 1); g.DrawString("Original Matrices:", this.Font, Brushes.Black, 10, 10 + 4 * offset); DrawMatrix(m1, g, 10, 10 + 5 * offset); DrawMatrix(m2, g, 10 + 130, 10 + 5 * offset); m1.Multiply(m2, MatrixOrder.Append); g.DrawString("Resultant Matrix - Append:", this.Font, Brushes.Black, 10, 10 + 6 * offset); DrawMatrix(m1, g, 10, 10 + 7 * offset); // Matrix multiplication - MatrixOrder.Prepend: m1 = new Matrix(1, 2, 3, 4, 0, 1); m1.Multiply(m2, MatrixOrder.Prepend); g.DrawString("Resultant Matrix - Prepend:", this.Font, Brushes.Black, 10, 10 + 8 * offset); DrawMatrix(m1, g, 10, 10 + 9 * offset); }
public virtual void Rotate(float angle, PointF center) { Matrix tempMatrix = new Matrix(); tempMatrix.RotateAt(angle, center); tempMatrix.Multiply(TransformationMatrix); TransformationMatrix = tempMatrix; }
/* * Translate * методът се ползва при скалиране * за нулиране на нежелан ефект при скалирнаето(изместване на фигурата в страни) * и за нормално транслиране - преместване * **/ public virtual void Translate(float X,float Y) { Matrix tempMatrix = new Matrix(); tempMatrix.Translate(X, Y); tempMatrix.Multiply(TransformationMatrix); TransformationMatrix = tempMatrix; }
public override void Draw(CGRect rect) { Graphics g = Graphics.FromCurrentContext (); int offset = 20; // Invert matrix: var m = new Matrix (1, 2, 3, 4, 0, 0); g.DrawString ("Original Matrix:", Font, Brushes.Black, 10, 10); DrawMatrix (m, g, 10, 10 + offset); g.DrawString ("Inverted Matrix:", Font, Brushes.Black, 10, 10 + 2 * offset); m.Invert (); DrawMatrix (m, g, 10, 10 + 3 * offset); // Matrix multiplication - MatrixOrder.Append: var m1 = new Matrix (1, 2, 3, 4, 0, 1); var m2 = new Matrix (0, 1, 2, 1, 0, 1); g.DrawString ("Original Matrices:", Font, Brushes.Black, 10, 10 + 4 * offset); DrawMatrix (m1, g, 10, 10 + 5 * offset); DrawMatrix (m2, g, 10 + 130, 10 + 5 * offset); m1.Multiply (m2, MatrixOrder.Append); g.DrawString ("Resultant Matrix - Append:", Font, Brushes.Black, 10, 10 + 6 * offset); DrawMatrix (m1, g, 10, 10 + 7 * offset); // Matrix multiplication - MatrixOrder.Prepend: m1 = new Matrix (1, 2, 3, 4, 0, 1); m1.Multiply (m2, MatrixOrder.Prepend); g.DrawString ("Resultant Matrix - Prepend:", Font, Brushes.Black, 10, 10 + 8 * offset); DrawMatrix (m1, g, 10, 10 + 9 * offset); }
/// <summary> /// Рисует границу узла /// </summary> /// <param name="node"></param> /// <param name="graphics"></param> /// <returns></returns> private bool DrawNode(Node 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; g.ResetClip(); } } return(true);//returning false would enable the default rendering }
public void DrawMaskInto(Graphics g, Color c) { SysMatrix orgM = g.Transform; SysMatrix newM = GetMatrix().SysMatrix(); newM.Multiply(orgM, MatrixOrder.Append); g.Transform = newM; stage.Gdi.RenderMaskInto(Definition, 0, g, c); newM.Dispose(); g.Transform = orgM; }
private static Matrix CreateTransformMatrix(TileInfo tileInfo) { // The code below needs no comments, it is fully intuitive. // I wrote in in one go and it ran correctly right away. var matrix = new Matrix(); var flipMatrix = new Matrix(1, 0, 0, -1, 0, 0); matrix.Multiply(flipMatrix); matrix.Scale( (float) (TileWidth/tileInfo.Extent.Width), (float) (TileHeight/tileInfo.Extent.Height)); matrix.Translate(-(float) tileInfo.Extent.MinX, -(float) tileInfo.Extent.MaxY); return matrix; }
public void DrawInto(Graphics g, float offsetX, float offsetY) { SysMatrix orgM = g.Transform; SysMatrix newM = GetMatrix().SysMatrix(); newM.Multiply(orgM, MatrixOrder.Append); newM.Translate(-offsetX, -offsetY, MatrixOrder.Append); g.Transform = newM; stage.Gdi.RenderInto(Definition, 0, g); newM.Dispose(); g.Transform = orgM; }
protected override GraphicsPath GetBaselinePath(ISvgRenderer renderer) { var path = this.OwnerDocument.IdManager.GetElementById(this.ReferencedPath) as SvgVisualElement; if (path == null) return null; var pathData = (GraphicsPath)path.Path(renderer).Clone(); if (path.Transforms.Count > 0) { Matrix transformMatrix = new Matrix(1, 0, 0, 1, 0, 0); foreach (var transformation in path.Transforms) { transformMatrix.Multiply(transformation.Matrix); } pathData.Transform(transformMatrix); } return pathData; }
private Matrix GetParentsTransform(Node node) { if (node is PseudoGroup) { return new Matrix(); } if ((node == null) || (node.Parent == null)) { throw new ArgumentNullException("node && parent are null!"); } Matrix matrix = new Matrix(); for (ICompositeNode node2 = node.Parent; !(node2 is Syncfusion.Windows.Forms.Diagram.Model); node2 = ((Node)node2).Parent) { Matrix transformations = ((Node)node2).GetTransformations(); ((Node)node2).AppendFlipTransforms(transformations); matrix.Multiply(transformations, MatrixOrder.Append); } return matrix; }
/// <summary> /// Will Draw a rectangle in this view /// </summary> /// <param name="rectangle">The size and scale of the rectangle</param> /// <param name="edgeColor">The Color of the rectangle edge</param> /// <param name="edgeWidth">The width of the rectangels outer edge</param> /// <param name="tranformation">The Affine Transformation that will be applied to this line. Note this member is not required and can be null</param> /// <returns>If True the line was drawn successfully, If False the draw was abourted due to an error</returns> public bool paintRectangle(System.Drawing.RectangleF rectangle, System.Drawing.Color fillColor, System.Drawing.Color edgeColor, float edgeWidth, Matrix tranformation) { //Can only Draw one Rectangle at a time, sorry if (rectangle != null && edgeColor != null && edgeWidth >= 0) { if (aquirePaintLock()) { if (currentGraphicsObject != null) { //Transform publicMatrix.Reset(); if (tranformation != null) { publicMatrix.Multiply(tranformation, MatrixOrder.Append); } publicMatrix.Multiply(cameraTransform, MatrixOrder.Append); currentGraphicsObject.Transform = publicMatrix; //Fill Brush if (fillColor != null && fillColor.A > 0) { publicBrush.Color = fillColor; currentGraphicsObject.FillRectangle(publicBrush, rectangle); } //Edge Pen if (edgeColor != null && edgeColor.A > 0) { publicPen.Color = edgeColor; publicPen.Width = edgeWidth; currentGraphicsObject.DrawRectangle(publicPen, rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height); } releasePaintLock(); return(true); } releasePaintLock(); } } return(false); }
void DrawActiveButtonByState(Graphics g, _States state, int x, int y) { MemoryStream ms = new MemoryStream(); switch (state) { case _States.Normal: CxViewerResources.PathButton.Save(ms, ImageFormat.Png); break; case _States.MouseOver: CxViewerResources.PathActiveButton.Save(ms, ImageFormat.Png); break; case _States.Clicked: CxViewerResources.PathActiveButton.Save(ms, ImageFormat.Png); break; case _States.Selected: CxViewerResources.PathSelectedButton.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, (float)(x), (float)(y), 200, 28); g.Transform = saveM; } } }
public void Draw(ObjectPainter painter) { var angle = _time*90/(float) Math.PI; var world = new Matrix(); if (UseTranslation) world.Translate(_time * 25, _time * 30); world.Rotate(angle); var scale = new Matrix(); scale.Scale(100, 100); world.Multiply(scale); painter.Paint(world, _square); angle = _time*1.5f*90/(float) Math.PI; world = new Matrix(); if (UseTranslation) world.Translate(_time * 20, _time * 25); world.Rotate(angle); scale = new Matrix(); scale.Scale(200, 200); world.Multiply(scale); painter.Paint(world, _square); }
static void DrawStringInRectCenter(Graphics g, Brush brush, Font f, string s, RectangleF r /*, double rectLineWidth*/) { if (String.IsNullOrEmpty(s)) { return; } using (System.Drawing.Drawing2D.Matrix m = g.Transform) { using (System.Drawing.Drawing2D.Matrix saveM = m.Clone()) { //rotate the label around its center float c = (r.Bottom + r.Top) / 2; using (System.Drawing.Drawing2D.Matrix m2 = new System.Drawing.Drawing2D.Matrix(1, 0, 0, -1, 0, 2 * c)) { m.Multiply(m2); } g.Transform = m; using (StringFormat stringFormat = StringFormat.GenericTypographic) { g.DrawString(s, f, brush, r.Left, r.Top, stringFormat); } g.Transform = saveM; } } }
public SvgElement AddElement(ISvgElement mypath) { // AttributeFunc.SetAttributeValue((XmlElement)mypath,"layer",SvgDocument.currentLayer); XmlNode node1 = OwnerDocument.RootElement; XmlNode newNode =null; Matrix matrix1 = new Matrix(); // if (node1 is IGraph) // { // matrix1 = ((IGraph) node1).GraphTransform.Matrix.Clone(); // Matrix matrix2 = this.coordTransform.Clone(); // matrix2.Invert(); // matrix1.Multiply(matrix2, MatrixOrder.Append); // } // matrix1.Invert(); // matrix1 = TransformFunc.RoundMatrix(matrix1, 2); bool flag1 = OwnerDocument.AcceptChanges; // OwnerDocument.AcceptChanges = false; OwnerDocument.AcceptChanges = true; if (mypath is IGraphPath) { ISvgBrush brush1 = ((IGraphPath) mypath).GraphBrush; if ((brush1 is ITransformBrush) && (((SvgElement) brush1).ParentNode == null)) { bool flag2 = OwnerDocument.AcceptChanges; OwnerDocument.AcceptChanges = true; OwnerDocument.NumberOfUndoOperations++; XmlNode node2 = OwnerDocument.AddDefsElement((SvgElement) brush1); OwnerDocument.AcceptChanges = false; if (node2 is ITransformBrush) { string text1 = ((SvgElement) node2).ID; AttributeFunc.SetAttributeValue((SvgElement) mypath, "fill", "url(#" + text1 + ")"); } OwnerDocument.AcceptChanges = flag2; } brush1 = ((IGraphPath) mypath).GraphStroke.Brush; if ((brush1 is ITransformBrush) && (((SvgElement) brush1).ParentNode == null)) { bool flag3 = OwnerDocument.AcceptChanges; OwnerDocument.AcceptChanges = true; OwnerDocument.NumberOfUndoOperations++; XmlNode node3 = OwnerDocument.AddDefsElement((SvgElement) brush1); OwnerDocument.AcceptChanges = false; if (node3 is ITransformBrush) { string text2 = ((SvgElement) node3).ID; AttributeFunc.SetAttributeValue((SvgElement) mypath, "stroke", "url(#" + text2 + ")"); } OwnerDocument.AcceptChanges = flag3; } } if (!matrix1.IsIdentity && (mypath is IGraph)) { bool flag4 = OwnerDocument.AcceptChanges; OwnerDocument.AcceptChanges = false; Matrix matrix3 = ((IGraph) mypath).Transform.Matrix.Clone(); matrix1.Multiply(matrix3); Transf transf1 = new Transf(); transf1.setMatrix(matrix1); AttributeFunc.SetAttributeValue((SvgElement) mypath, "transform", transf1.ToString()); OwnerDocument.AcceptChanges = flag4; } if (((SvgElement) mypath).ParentNode != node1) { if (((ContainerElement) node1).IsValidChild((SvgElement) mypath)) { // node1.AppendChild((SvgElement) mypath); SvgElement element1 =(SvgElement) mypath;//(SvgElement)OwnerDocument.ImportNode((SvgElement) mypath,true); newNode = node1.AppendChild(element1); OwnerDocument.Render(element1); } } OwnerDocument.AcceptChanges = flag1; return newNode!=null?newNode as SvgElement:null; }
public void Translate() { foreach (var shape in Selection) { Matrix m = new Matrix(); m.Translate(EndPoint.X - StartPoint.X, EndPoint.Y - StartPoint.Y); m.Multiply(shape.TransformMatrix.GetMatrix()); shape.TransformMatrix.GetElements(m); IsChanged = true; } StartPoint = EndPoint; }
/// <summary> /// Check if the line is a Iterator element. if true, reset the new P1, P2 by OffsetTransform /// The new P1, P2 will be used to compute the intersections /// </summary> private void CheckForIterater() { if (this.m_HasIterator) { Matrix totalOffset = new Matrix(1, 0, 0, 1, 0, 0); for (int i = 0; i < this.m_IteratorIndex; i++) totalOffset.Multiply(this.m_OffsetTransform); PointF[] points={this.m_Line.P1,this.m_Line.P2}; totalOffset.TransformPoints(points); this.m_Line.P1 = points[0]; this.m_Line.P2 = points[1]; } }
public void Multiply_InvalidOrder () { Matrix matrix = new Matrix (10, 20, 30, 40, 50, 60); matrix.Multiply (new Matrix (10, 20, 30, 40, 50, 60), (MatrixOrder)Int32.MinValue); }
public static object GetAnimateValue(SvgElement element, string attributename, DomType domtype, object orivalue) { PointF[] tfArray6; PointF[] tfArray7; PointF[] tfArray8; int num8; Matrix matrix1 = new Matrix(); string text1 = string.Empty; GraphicsPath path1 = null; string text2 = string.Empty; PointF[] tfArray1 = null; bool flag1 = true; if (element.AnimateNameValues.ContainsKey(attributename)) { AnimateInfo info1 = (AnimateInfo) element.AnimateNameValues[attributename]; object[] objArray1 = info1.AnimateValues; bool[] flagArray1 = info1.ValueAdds; int num1 = 0; if ((domtype == DomType.SvgString) || (domtype == DomType.SvgLink)) { for (int num2 = objArray1.Length - 1; num2 >= 0; num2--) { if ((objArray1[num2] is string) && (objArray1[num2].ToString() != string.Empty)) { if (element is ItopVector.Core.Figure.Image) { ((ItopVector.Core.Figure.Image) element).RefImage = ImageFunc.GetImageForURL(objArray1[num2].ToString(), element); } return objArray1[num2].ToString(); } } return orivalue; } object[] objArray2 = objArray1; for (int num10 = 0; num10 < objArray2.Length; num10++) { PointF[] tfArray2; float single3; GraphicsPath path2; PointF[] tfArray3; PointF[] tfArray4; PointF[] tfArray5; object obj1 = objArray2[num10]; bool flag2 = flagArray1[num1]; switch (domtype) { case DomType.SvgMatrix: { Matrix matrix2 = new Matrix(); if ((obj1 != null) && (obj1.ToString() != string.Empty)) { matrix2 = ((Matrix) obj1).Clone(); } if (flag2) { matrix1.Multiply(matrix2); goto Label_046F; } matrix1 = matrix2; goto Label_046F; } case DomType.SvgNumber: { single3 = 0f; if ((obj1 != null) && (obj1.ToString() != string.Empty)) { single3 = (float) obj1; if (!flag2 || (text1 == string.Empty)) { goto Label_0246; } float single9 = float.Parse(text1) + single3; text1 = single9.ToString(); } goto Label_046F; } case DomType.SvgString: { goto Label_046F; } case DomType.SvgColor: { string text3 = string.Empty; if ((obj1 != null) && (obj1.ToString() != string.Empty)) { text3 = (string) obj1; } if (text3 != string.Empty) { if ((flag2 && (text2 != string.Empty)) && (!text2.Trim().StartsWith("url") && !text3.Trim().StartsWith("url"))) { Color color1 = ColorFunc.ParseColor(text3); Color color2 = ColorFunc.ParseColor(text2); int num4 = (color1.R + color2.R) / 2; int num5 = (color1.G + color2.G) / 2; int num6 = (color1.B + color2.B) / 2; string[] textArray1 = new string[7] { "rgb(", num4.ToString(), ",", num5.ToString(), ",", num6.ToString(), ")" } ; text2 = string.Concat(textArray1); goto Label_046F; } text2 = text3; } goto Label_046F; } case DomType.SvgPath: { if ((obj1 != null) && (obj1.ToString() != string.Empty)) { path2 = (GraphicsPath) obj1; if (!flag2 || (path1 == null)) { goto Label_0460; } tfArray3 = path2.PathPoints; tfArray4 = path1.PathPoints; if (tfArray3.Length == tfArray4.Length) { goto Label_03B5; } } goto Label_046F; } case DomType.SvgPoints: { tfArray2 = new PointF[0]; if (obj1 is PointF[]) { tfArray2 = (PointF[]) obj1; } if (!flag2) { break; } if (tfArray1.Length == tfArray2.Length) { for (int num3 = 0; num3 < tfArray2.Length; num3++) { PointF tf1 = tfArray1[num3]; PointF tf2 = tfArray2[num3]; float single1 = (tf1.X + tf2.X) / 2f; float single2 = (tf1.Y + tf2.Y) / 2f; tfArray1[num3] = new PointF(single1, single2); } } goto Label_046F; } default: { goto Label_046F; } } tfArray1 = (PointF[]) tfArray2.Clone(); goto Label_046F; Label_0246: text1 = single3.ToString(); goto Label_046F; Label_03B5: tfArray5 = new PointF[tfArray4.Length]; Array.Copy(tfArray3, tfArray1, tfArray5.Length); byte[] buffer1 = path2.PathTypes; byte[] buffer2 = path1.PathTypes; for (int num7 = 0; num7 < Math.Min(tfArray3.Length, tfArray4.Length); num7++) { PointF tf3 = tfArray3[num7]; PointF tf4 = tfArray4[num7]; float single4 = tf3.X + tf4.X; float single5 = tf3.Y + tf4.Y; tfArray5[num7] = new PointF(single4, single5); } path1 = new GraphicsPath(tfArray5, path2.PathTypes); goto Label_046D; Label_0460: path1 = (GraphicsPath) path2.Clone(); Label_046D:; Label_046F:; } if (flagArray1.Length > 0) { flag1 = flagArray1[flagArray1.Length - 1]; } } switch (domtype) { case DomType.SvgMatrix: { Matrix matrix3 = new Matrix(); if (orivalue != null) { matrix3 = ((Matrix) orivalue).Clone(); } if (flag1) { matrix3.Multiply(matrix1); } else { matrix3 = matrix1.Clone(); } return matrix3.Clone(); } case DomType.SvgNumber: { if ((flag1 && (orivalue != null)) && (orivalue.ToString() != string.Empty)) { float single6 = (float) orivalue; if (text1 == string.Empty) { text1 = single6.ToString(); break; } float single10 = float.Parse(text1) + single6; text1 = single10.ToString(); } break; } case DomType.SvgString: { return orivalue; } case DomType.SvgColor: { if (text2 == string.Empty) { return orivalue; } if ((flag1 && (orivalue != null)) && (!text2.Trim().StartsWith("url") && !((string) orivalue).Trim().StartsWith("url"))) { Color color3 = ColorFunc.ParseColor((string) orivalue); Color color4 = ColorFunc.ParseColor(text2); string[] textArray2 = new string[7]; textArray2[0] = "rgb("; int num11 = (color3.R + color4.R) / 2; textArray2[1] = num11.ToString(); textArray2[2] = ","; int num12 = (color3.G + color4.G) / 2; textArray2[3] = num12.ToString(); textArray2[4] = ","; int num13 = (color3.B + color4.B) / 2; textArray2[5] = num13.ToString(); textArray2[6] = ")"; text2 = string.Concat(textArray2); } return text2; } case DomType.SvgPath: { if (path1 == null) { return orivalue; } if (!flag1 || (orivalue == null)) { return path1; } tfArray6 = ((GraphicsPath) orivalue).PathPoints; tfArray7 = path1.PathPoints; tfArray8 = new PointF[tfArray6.Length]; Array.Copy(tfArray6, tfArray1, tfArray8.Length); num8 = 0; goto Label_0738; } case DomType.SvgPoints: { if (tfArray1.Length > 0) { PointF[] tfArray9 = new PointF[0]; if (!(orivalue is PointF[]) || !flag1) { return tfArray1; } tfArray9 = (PointF[]) orivalue; if (tfArray9.Length != tfArray1.Length) { return tfArray1; } for (int num9 = 0; num9 < tfArray1.Length; num9++) { tfArray1[num9] = new PointF((tfArray1[num9].X + tfArray9[num9].X) / 2f, (tfArray1[num9].Y + tfArray9[num9].Y) / 2f); } } return tfArray1; } default: { return string.Empty; } } if (text1 != string.Empty) { return float.Parse(text1); } if ((orivalue.ToString() == string.Empty) || (orivalue == null)) { return (float) AttributeFunc.GetDefaultValue(element, attributename); } return (float) orivalue; Label_0738: if (num8 >= Math.Min(tfArray6.Length, tfArray7.Length)) { return new GraphicsPath(tfArray8, path1.PathTypes); } PointF tf5 = tfArray6[num8]; PointF tf6 = tfArray7[num8]; float single7 = tf5.X + tf6.X; float single8 = tf5.Y + tf6.Y; tfArray8[num8] = new PointF(single7, single8); num8++; goto Label_0738; }
private void RenderTo(Graphics g) { Matrix matrix1=new Matrix(); Matrix matrix2=new Matrix(); matrix1=((SVG)this.vectorcontrol.SVGDocument.RootElement).GraphTransform.Matrix; matrix2.Multiply(matrix1); matrix1.Reset(); matrix1.Multiply(g.Transform); g.ResetTransform(); g.TranslateTransform(10,10); try { this.vectorcontrol.RenderTo(g); } finally { g.Transform=matrix1.Clone(); matrix1.Reset(); matrix1.Multiply(matrix2); } }
public void Render(Graphics g, WorldTransform t) { if (this.observedVehicle.ObservationState != ObservedVehicleState.Deleted || (this.observedVehicle.ObservationState == ObservedVehicleState.Deleted && DrawingUtility.DisplayDeletedVehicles)) { Coordinates wll = t.WorldLowerLeft; Coordinates wup = t.WorldUpperRight; if ((Position.X < wll.X || Position.X > wup.X || Position.Y < wll.Y || Position.Y > wup.Y)) { return; } Matrix bodyTrans = new Matrix(); bodyTrans.Rotate((float)(this.Heading) * 180 / (float)Math.PI - 90); bodyTrans.Translate((float)Position.X, (float)Position.Y, MatrixOrder.Append); Matrix origTrans = g.Transform.Clone(); bodyTrans.Multiply(g.Transform, MatrixOrder.Append); g.Transform = bodyTrans; float penWidth = nomPixelWidth / t.Scale; using (Pen p = new Pen(color, penWidth)) { DrawRectangle(g, p, bodyRect); // build the transform for the rear wheels // do the left wheel Matrix wheelTransform = bodyTrans.Clone(); wheelTransform.Translate(-WheelOffset, 0, MatrixOrder.Prepend); try { g.Transform = wheelTransform; g.FillRectangle(Brushes.White, wheelRectL); DrawRectangle(g, p, wheelRectL); } catch (Exception) { } // do the right wheel wheelTransform = bodyTrans.Clone(); wheelTransform.Translate(WheelOffset, 0, MatrixOrder.Prepend); try { g.Transform = wheelTransform; g.FillRectangle(Brushes.White, wheelRectR); DrawRectangle(g, p, wheelRectR); } catch (Exception) { } // do the front wheels // do the left wheel wheelTransform = bodyTrans.Clone(); wheelTransform.Translate(-WheelOffset, WheelBase, MatrixOrder.Prepend); wheelTransform.Rotate(steeringAngle * 180 / (float)Math.PI, MatrixOrder.Prepend); try { g.Transform = wheelTransform; g.FillRectangle(Brushes.White, wheelRectL); DrawRectangle(g, p, wheelRectL); } catch (Exception) { } // do the right wheel wheelTransform = bodyTrans.Clone(); wheelTransform.Translate(WheelOffset, WheelBase, MatrixOrder.Prepend); wheelTransform.Rotate(steeringAngle * 180 / (float)Math.PI, MatrixOrder.Prepend); try { g.Transform = wheelTransform; g.FillRectangle(Brushes.White, wheelRectR); DrawRectangle(g, p, wheelRectR); } catch (Exception) { } } g.Transform = origTrans; // draw Position DrawingUtility.DrawControlPoint(this.Position, color, this.observedVehicle.Id.ToString(), ContentAlignment.MiddleCenter, ControlPointStyle.LargeBox, g, t); Coordinates head = this.Position + this.observedVehicle.Heading.Normalize(this.observedVehicle.Length / 2.0); DrawingUtility.DrawControlLine(this.Position, head, color, g, t); } }
public void FlushTransform(Matrix parentTransform) { mParentMatrix = parentTransform; // setup cached matrix. mCachedMatrix = mParentMatrix.Clone(); mCachedMatrix.Multiply(mCachedKey.GetTransform()); // set the sub tracks. foreach (AnimationTrack track in mAnimTracks) track.FlushTransform(mCachedMatrix); }
private static bool CustomDrawNode(Microsoft.Msagl.Drawing.Node node, object graphics, NodeTypes nodeType) { try { double width = 110; double height = 40; Microsoft.Msagl.GeometryGraph geomGraph = new Microsoft.Msagl.GeometryGraph(); GeomNode geomCreek = new Microsoft.Msagl.Node(node.Id, Microsoft.Msagl.Splines.CurveFactory.CreateBox(width, height, 0, 0, node.Attr.GeometryNode.Center)); node.Attr.GeometryNode.BoundaryCurve = Microsoft.Msagl.Splines.CurveFactory.CreateBox(width, height, 0, 0, node.Attr.GeometryNode.Center); Graphics g = (Graphics)graphics; MemoryStream ms = new MemoryStream(); switch (nodeType) { case NodeTypes.Normal: CxViewerResources.NormalNode.Save(ms, ImageFormat.Png); break; case NodeTypes.NormalSelected: CxViewerResources.NormalSelected.Save(ms, ImageFormat.Png); break; case NodeTypes.MultiRelaitions: CxViewerResources.MultiRelaitions.Save(ms, ImageFormat.Png); break; case NodeTypes.MultiRelaitionsSelected: CxViewerResources.MultiRelaitionsSelected.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)node.Attr.GeometryNode.Center.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.SetClip(FillTheGraphicsPath(node.Attr.GeometryNode.BoundaryCurve)); g.DrawImage(image, new PointF((float)(node.Attr.GeometryNode.Center.X - node.Attr.GeometryNode.Width / 2), (float)(node.Attr.GeometryNode.Center.Y - node.Attr.GeometryNode.Height / 2))); Font myFont = new System.Drawing.Font("Helvetica", 10, System.Drawing.FontStyle.Italic); System.Drawing.Brush myBrush = new SolidBrush(System.Drawing.Color.Blue); Rectangle rectString = new Rectangle(Convert.ToInt32(node.Attr.GeometryNode.Center.X - node.Attr.GeometryNode.Width / 2), Convert.ToInt32(node.Attr.GeometryNode.Center.Y - node.Attr.GeometryNode.Height / 2), Convert.ToInt32(width), Convert.ToInt32(height)); StringFormat stringFormat = new StringFormat(); stringFormat.Alignment = StringAlignment.Center; stringFormat.LineAlignment = StringAlignment.Center; g.DrawString(node.Label.Text, myFont, myBrush, rectString, stringFormat // new PointF((float)(node.Attr.GeometryNode.Center.X - node.Attr.GeometryNode.Width / 2), (float)(node.Attr.GeometryNode.Center.Y - 5)) ); g.Transform = saveM; } } } catch (Exception err) { Common.Logger.Create().Error(err.ToString()); } return(true);//returning false would enable the default rendering }
private static Matrix CreateTransformMatrix(int canvasWidth, int canvasHeight, float minX, float minY, float width, float height) { // The code below needs no comments, it is fully intuitive. // I wrote in in one go and it ran correctly right away. var matrix = new Matrix(); var flipMatrix = new Matrix(1, 0, 0, -1, 0, 0); matrix.Multiply(flipMatrix); matrix.Scale(canvasWidth/width, canvasHeight/height); var maxY = minY + height; matrix.Translate(-minX, -maxY); return matrix; }
public void PanZoom(float delta, float scale, float xPos) { var scaleX = 1 + scale*0.003f; //update view matrix var m = new Matrix(scaleX, 0, 0, 1, xPos - xPos*scaleX, 0); m.Multiply(FView); m.Translate(delta / m.Elements[0], 0); FView = m; PanZoomMatrix = new SvgMatrix(FView.Elements.ToList()); FViewChanged = true; }
private void RenderTo(Graphics g) { SvgDocument svgdoc = tlVectorControl1.SVGDocument; Matrix matrix1 = new Matrix(); Matrix matrix2 = new Matrix(); matrix1 = ((SVG)svgdoc.RootElement).GraphTransform.Matrix; matrix2.Multiply(matrix1); matrix1.Reset(); matrix1.Multiply(g.Transform); g.ResetTransform(); try { SVG svg1 = svgdoc.DocumentElement as SVG; svgdoc.BeginPrint = true; SmoothingMode mode1 = svgdoc.SmoothingMode; svgdoc.SmoothingMode = g.SmoothingMode; svg1.Draw(g, svgdoc.ControlTime); svgdoc.SmoothingMode = mode1; svgdoc.BeginPrint = false; } finally { g.Transform = matrix1.Clone(); matrix1.Reset(); matrix1.Multiply(matrix2); } }
private void Render(object sender, PaintEventArgs e) { try { int location = -1; if (engine != null) { LevelArea level_area = Engine.Current.LevelArea; if (level_area != null) location = level_area.x044_SnoId; } if (last_location != location) { if (auto_clear_navmesh) { m_Navmesh.Clear(); LoadDebugConfig(); } last_location = location; } Matrix m = new Matrix(); m.Scale(render_scale, render_scale); m.Translate((Width - 16) / (2 * render_scale), (Height - 30) / (2 * render_scale)); // when Diablo is running display navmesh in the same manner as Diablo does if (engine != null) { m.Rotate(135); Matrix flip_x_m = new Matrix(1, 0, 0, -1, 0, 0); m.Multiply(flip_x_m); } e.Graphics.Transform = m; e.Graphics.CompositingQuality = CompositingQuality.GammaCorrected; e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; int cells_count = 0; int grid_cells_count = 0; if (render_grids || render_cells) { using (m_Navmesh.AquireReadDataLock()) { List<GridCell> grid_cells = m_Navmesh.dbg_GetGridCells(); if (render_grids) { foreach (Nav.GridCell grid_cell in grid_cells) RenderHelper.Render(grid_cell, render_center, e, render_connections, render_id); grid_cells_count = grid_cells.Count; } if (render_cells) { float max_move_cost_mult = 1; foreach (Nav.GridCell grid_cell in grid_cells) { foreach (Nav.Cell cell in grid_cell.Cells) { RenderHelper.Render(cell, render_center, e, render_connections, render_id, m_LastMaxMoveCostMult); max_move_cost_mult = Math.Max(max_move_cost_mult, cell.MovementCostMult); } cells_count += grid_cell.Cells.Count; } m_LastMaxMoveCostMult = max_move_cost_mult; } } } if (render_explore_cells || render_explore_dist) { using (m_Navmesh.Explorator.AquireReadDataLock()) { List<ExploreCell> explore_cells = m_Navmesh.Explorator.dbg_GetExploreCells(); if (render_explore_cells) { foreach (Nav.ExploreCell explore_cell in explore_cells) RenderHelper.Render(explore_cell, m_Navmesh.Navigator.ExploreCellPrecision, render_center, e, render_connections, render_id); } if (render_explore_dist) { if (explore_cells.Exists(c => c.Id == explore_cell_id_to_render_dists)) RenderHelper.Render(m_Navmesh, explore_cells.Find(c => c.Id == explore_cell_id_to_render_dists), render_center, e, render_id); } } } if (render_regions) { var regions = m_Navmesh.Regions; foreach (var region in regions) RenderHelper.DrawRectangle(e.Graphics, Pens.Black, render_center, region.area.Min, region.area.Max); //Vec3 safe_point = m_Navmesh.Navigator.GetNearestGridCellOutsideAvoidAreas(); //if (!safe_point.IsEmpty) // RenderHelper.DrawPoint(e.Graphics, Pens.Green, render_center, safe_point); } if (render_axis) { e.Graphics.DrawString("X", new Font("Arial", 6 / render_scale), Brushes.Black, 25 / render_scale, 0); e.Graphics.DrawLine(RenderHelper.AXIS_PEN, -25 / render_scale, 0, 25 / render_scale, 0); e.Graphics.DrawString("Y", new Font("Arial", 6 / render_scale), Brushes.Black, 0, 25 / render_scale); e.Graphics.DrawLine(RenderHelper.AXIS_PEN, 0, -25 / render_scale, 0, 25 / render_scale); } if (render_explore_cells && m_Navmesh.Explorator is Nav.ExploreEngine.TSP) { ((Nav.ExploreEngine.TSP)m_Navmesh.Explorator).TryGetExplorePath(ref last_explore_path); RenderHelper.DrawLines(e.Graphics, RenderHelper.EXPLORE_PATH_PEN, render_center, last_explore_path, 1); } if (!render_original_path && render_path) { DestType last_path_dest_type = DestType.None; if (m_Navmesh.Navigator.TryGetPath(ref last_path, ref last_path_dest_type)) last_path.Insert(0, m_Navmesh.Navigator.CurrentPos); RenderHelper.DrawLines(e.Graphics, RenderHelper.PATH_PEN, render_center, last_path, 1); } if (render_backtrack_path) { if (m_Navmesh.Navigator.TryGetBackTrackPath(ref last_back_track_path)) last_back_track_path.Insert(0, m_Navmesh.Navigator.CurrentPos); RenderHelper.DrawLines(e.Graphics, Pens.Blue, render_center, last_back_track_path, 1); } if (render_positions_history) { m_Navmesh.Navigator.TryGetDebugPositionsHistory(ref last_positions_history); RenderHelper.DrawLines(e.Graphics, Pens.Green, render_center, last_positions_history, 1); } if (!m_Navmesh.Navigator.CurrentPos.IsEmpty) RenderHelper.DrawPoint(e.Graphics, Pens.Blue, render_center, m_Navmesh.Navigator.CurrentPos); if (!m_Navmesh.Navigator.Destination.IsEmpty) RenderHelper.DrawPoint(e.Graphics, Pens.LightBlue, render_center, m_Navmesh.Navigator.Destination); { Vec3 curr = m_Navmesh.Navigator.CurrentPos; Vec3 dest = m_Navmesh.Navigator.Destination; if (!curr.IsEmpty && !dest.IsEmpty) { if (render_original_path) { List<Vec3> path = new List<Vec3>(); m_Navmesh.Navigator.FindPath(curr, dest, MovementFlag.Walk, ref path, -1, false, false, 0, false, 0, false); path.Insert(0, curr); RenderHelper.DrawLines(e.Graphics, Pens.Black, render_center, path, 1); } if (render_ray_cast) RenderHelper.DrawLine(e.Graphics, m_Navmesh.RayCast2D(curr, dest, MovementFlag.Walk) ? Pens.Green : Pens.Red, render_center, curr, dest); } } if (waypoints_paths.Count > 0) { int waypoint_id = 1; foreach (List<Vec3> p in waypoints_paths) { if (p.Count > 0) { RenderHelper.DrawCircle(e.Graphics, Pens.Black, render_center, p[0], 3); RenderHelper.DrawString(e.Graphics, Brushes.Black, render_center, p[0], waypoint_id.ToString(), 10); } RenderHelper.DrawLines(e.Graphics, Pens.Red, render_center, p, 1); ++waypoint_id; } } if (bot != null) { if (!bot.Paused && center_on_bot) render_center = new PointF(bot.Position.X, bot.Position.Y); bot.Render(e.Graphics, render_center); } e.Graphics.ResetTransform(); Font legend_font = new Font("Arial", 8, FontStyle.Bold); Font stats_font = new Font("Arial", 8); TextRenderer.DrawText(e.Graphics, "L: Toggle render legend", legend_font, new Point(10, 10), render_legend ? Color.White : Color.Black, render_legend ? Color.Black : Color.Transparent); if (render_legend) { e.Graphics.DrawString("F1: Reload waypoints", legend_font, Brushes.Black, 10, 25); e.Graphics.DrawString("F2: Reload nav data", legend_font, Brushes.Black, 10, 40); e.Graphics.DrawString("F3: Dump nav data", legend_font, Brushes.Black, 10, 55); e.Graphics.DrawString("F4: Clear nav data", legend_font, Brushes.Black, 10, 70); e.Graphics.DrawString("F5: Serialize nav data", legend_font, Brushes.Black, 10, 85); e.Graphics.DrawString("F6: Deserialize nav data", legend_font, Brushes.Black, 10, 100); e.Graphics.DrawString("F10: Activate some test", legend_font, Brushes.Black, 10, 115); TextRenderer.DrawText(e.Graphics, "1: Toggle render grid cells", legend_font, new Point(10, 130), render_grids ? Color.White : Color.Black, render_grids ? Color.Black : Color.Transparent); TextRenderer.DrawText(e.Graphics, "2: Toggle render cells", legend_font, new Point(10, 145), render_cells ? Color.White : Color.Black, render_cells ? Color.Black : Color.Transparent); TextRenderer.DrawText(e.Graphics, "3: Toggle render explore cells", legend_font, new Point(10, 160), render_explore_cells ? Color.White : Color.Black, render_explore_cells ? Color.Black : Color.Transparent); TextRenderer.DrawText(e.Graphics, "4: Toggle render connections", legend_font, new Point(10, 175), render_connections ? Color.White : Color.Black, render_connections ? Color.Black : Color.Transparent); TextRenderer.DrawText(e.Graphics, "5: Toggle render IDs", legend_font, new Point(10, 190), render_id ? Color.White : Color.Black, render_id ? Color.Black : Color.Transparent); TextRenderer.DrawText(e.Graphics, "6: Toggle render axis", legend_font, new Point(10, 205), render_axis ? Color.White : Color.Black, render_axis ? Color.Black : Color.Transparent); TextRenderer.DrawText(e.Graphics, "7: Toggle render regions", legend_font, new Point(10, 220), render_regions ? Color.White : Color.Black, render_regions ? Color.Black : Color.Transparent); TextRenderer.DrawText(e.Graphics, "8: Toggle render original path", legend_font, new Point(10, 235), render_original_path ? Color.White : Color.Black, render_original_path ? Color.Black : Color.Transparent); TextRenderer.DrawText(e.Graphics, "9: Toggle render ray cast", legend_font, new Point(10, 250), render_ray_cast ? Color.White : Color.Black, render_ray_cast ? Color.Black : Color.Transparent); TextRenderer.DrawText(e.Graphics, "0: Toggle render back track path", legend_font, new Point(10, 265), render_backtrack_path ? Color.White : Color.Black, render_backtrack_path ? Color.Black : Color.Transparent); e.Graphics.DrawString("S: Set current pos", legend_font, Brushes.Black, 10, 280); e.Graphics.DrawString("E: Set destination pos", legend_font, Brushes.Black, 10, 295); e.Graphics.DrawString("B: Run bot", legend_font, Brushes.Black, 10, 310); TextRenderer.DrawText(e.Graphics, "A: Toggle auto clear navmesh", legend_font, new Point(10, 325), auto_clear_navmesh ? Color.White : Color.Black, auto_clear_navmesh ? Color.Black : Color.Transparent); e.Graphics.DrawString("F7: Reload debug.ini", legend_font, Brushes.Black, 10, 340); TextRenderer.DrawText(e.Graphics, "Ctrl+1: Toggle render path", legend_font, new Point(10, 355), render_path ? Color.White : Color.Black, render_path ? Color.Black : Color.Transparent); TextRenderer.DrawText(e.Graphics, "Ctrl+2: Toggle regions", legend_font, new Point(10, 370), m_Navmesh.RegionsEnabled ? Color.White : Color.Black, m_Navmesh.RegionsEnabled ? Color.Black : Color.Transparent); TextRenderer.DrawText(e.Graphics, "Ctrl+3: Toggle danger regions", legend_font, new Point(10, 385), m_Navmesh.DangerRegionsEnabled ? Color.White : Color.Black, m_Navmesh.DangerRegionsEnabled ? Color.Black : Color.Transparent); TextRenderer.DrawText(e.Graphics, "Ctrl+4: Toggle render positions history", legend_font, new Point(10, 400), render_positions_history ? Color.White : Color.Black, render_positions_history ? Color.Black : Color.Transparent); } e.Graphics.DrawString("Cells count: " + cells_count, stats_font, Brushes.Black, 10, Height - 55); } catch (Exception) { } }
private void RenderTo(Graphics g) { Matrix matrix1 = new Matrix(); Matrix matrix2 = new Matrix(); matrix1 = ((SVG)svgdoc.RootElement).GraphTransform.Matrix; matrix2.Multiply(matrix1); matrix1.Reset(); matrix1.Multiply(g.Transform); g.ResetTransform(); try { //this.vectorControl.RenderTo(g); //if ((g != null) && ((this.svgDocument != null) && (this.svgDocument.DocumentElement != null))) SVG svg1 = svgdoc.DocumentElement as SVG; svgdoc.BeginPrint = true; SmoothingMode mode1 = svgdoc.SmoothingMode; svgdoc.SmoothingMode = g.SmoothingMode; svg1.Draw(g, svgdoc.ControlTime); svgdoc.SmoothingMode = mode1; svgdoc.BeginPrint = false; } finally { g.Transform = matrix1.Clone(); matrix1.Reset(); matrix1.Multiply(matrix2); } }
public void UnGroup2(ItopVector.Core.Figure.Group group) { if (group.ParentNode is ItopVector.Core.Figure.Group) { string LayerID=group.GetAttribute("layer"); XmlNode node1 = group.PreviousSibling; while (!(node1 is SvgElement) && (node1 != null)) { node1 = node1.PreviousSibling; } SvgElementCollection collection1 = group.GraphList; SvgDocument document1 = this.SVGDocument; document1.NumberOfUndoOperations += ((2*collection1.Count) + 500); ItopVector.Core.Figure.Group group1 = (ItopVector.Core.Figure.Group) group.ParentNode; Matrix matrix1 = group.Transform.Matrix.Clone(); for (int num1 = collection1.Count - 1; num1 >= 0; num1--) { SvgElement element1 = (SvgElement) collection1[num1]; if (element1 is IGraph) { Matrix matrix2 = new Matrix(); if (element1.SvgAttributes.ContainsKey("transform")) { matrix2 = ((Matrix) element1.SvgAttributes["transform"]).Clone(); } matrix2.Multiply(matrix1, MatrixOrder.Append); Transf transf1 = new Transf(); transf1.setMatrix(matrix2); string text1 = transf1.ToString(); AttributeFunc.SetAttributeValue(element1, "transform", text1); // AttributeFunc.SetAttributeValue(element1, "layer", LayerID); } element1.AllowRename =false; if (node1 != null) { group1.InsertAfter(element1, node1); } else { group1.PrependChild(element1); } element1.AllowRename =true; } group1.RemoveChild(group); this.SVGDocument.NotifyUndo(); } }
private bool CheckConstrainingRegion(Matrix matrixTransformation, PointF ptPinPoint, SizeF szSize) { bool flag = true; if ((this.Root != null) && this.Root.BoundaryConstraintsEnabled) { RectangleF bounds = new RectangleF((PointF)Point.Empty, szSize); PointF[] pts = new PointF[] { bounds.Location, new PointF(bounds.Right, bounds.Top), new PointF(bounds.Left, bounds.Bottom), new PointF(bounds.Right, bounds.Bottom) }; PointF[] tfArray2 = new PointF[] { ptPinPoint }; Matrix parentsTransformations = HandlesHitTesting.GetParentsTransformations(this, false); matrixTransformation.Multiply(parentsTransformations, MatrixOrder.Append); matrixTransformation.TransformPoints(pts); parentsTransformations.TransformPoints(tfArray2); bounds = RectangleF.Union(Geometry.CreateRect(pts), new RectangleF(tfArray2[0], SizeF.Empty)); flag = this.CheckConstrainingRegion(bounds); } return flag; }
void DoTransform(System.Drawing.Drawing2D.Matrix M) { trans.Multiply(M); Transform = trans; }
private Matrix getWorldTransform() { Matrix worldTransformMatrix = new Matrix(); worldTransformMatrix.Multiply(translateMatrix, MatrixOrder.Append); worldTransformMatrix.Multiply(scaleMatrix, MatrixOrder.Append); worldTransformMatrix.Multiply(zoomTranslateMatrix, MatrixOrder.Append); return worldTransformMatrix; }
public void Multiply_Prepend () { Matrix matrix = new Matrix (10, 20, 30, 40, 50, 60); matrix.Multiply (new Matrix (10, 20, 30, 40, 50, 60), MatrixOrder.Prepend); Assert.AreEqual (700, matrix.Elements[0], "J#1"); Assert.AreEqual (1000, matrix.Elements[1], "J#2"); Assert.AreEqual (1500, matrix.Elements[2], "J#3"); Assert.AreEqual (2200, matrix.Elements[3], "J#4"); Assert.AreEqual (2350, matrix.Elements[4], "J#5"); Assert.AreEqual (3460, matrix.Elements[5], "J#6"); }
protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (!tracking) { Cursor cursor = this.moveToolCursor; for (int i = 0; i < this.moveNubs.Length; ++i) { MoveNubRenderer nub = this.moveNubs[i]; if (nub.Visible && nub.IsPointTouching(new Point(e.X, e.Y), true)) { cursor = this.handCursor; break; } } this.Cursor = cursor; } else { if (this.context.currentMode != Mode.Translate) { this.Cursor = this.handCursorMouseDown; } Point newMouseXY = new Point(e.X, e.Y); Point newOffset = new Point(newMouseXY.X - context.startMouseXY.X, newMouseXY.Y - context.startMouseXY.Y); PreRender(); this.dontDrop = true; Selection.PerformChanging(); using (Matrix translateMatrix = new Matrix()) { RectangleF rect; translateMatrix.Reset(); if (this.context.baseTransform != null) { Selection.SetInterimTransform(this.context.baseTransform); } Matrix interim = Selection.GetInterimTransformCopy(); switch (this.context.currentMode) { case Mode.Translate: translateMatrix.Translate((float)newOffset.X, (float)newOffset.Y, MatrixOrder.Append); break; case Mode.Rotate: rect = this.context.liftedBounds; PointF center = new PointF(rect.X + (rect.Width / 2.0f), rect.Y + (rect.Height / 2.0f)); center = Utility.TransformOnePoint(interim, center); double theta1 = Math.Atan2(context.startMouseXY.Y - center.Y, context.startMouseXY.X - center.X); double theta2 = Math.Atan2(e.Y - center.Y, e.X - center.X); double thetaDelta = theta2 - theta1; this.angleDelta = (float)(thetaDelta * (180.0f / Math.PI)); float angle = this.context.startAngle + this.angleDelta; if ((ModifierKeys & Keys.Shift) != 0) { angle = ConstrainAngle(angle); angleDelta = angle - this.context.startAngle; } translateMatrix.RotateAt(angleDelta, center, MatrixOrder.Append); this.rotateNub.Location = center; this.rotateNub.Angle = this.context.startAngle + angleDelta; break; case Mode.Scale: PointF xyAxes = GetEdgeVector(this.context.startEdge); PointF xAxis = new PointF(xyAxes.X, 0); PointF yAxis = new PointF(0, xyAxes.Y); PointF edgeX = Utility.TransformOneVector(interim, xAxis); PointF edgeY = Utility.TransformOneVector(interim, yAxis); PointF edgeXN = Utility.NormalizeVector2(edgeX); PointF edgeYN = Utility.NormalizeVector2(edgeY); PointF xu; float xulen; PointF xv; Utility.GetProjection((PointF)newOffset, edgeXN, out xu, out xulen, out xv); PointF yu; float yulen; PointF yv; Utility.GetProjection((PointF)newOffset, edgeYN, out yu, out yulen, out yv); PdnGraphicsPath startPath2 = this.context.startPath.Clone(); RectangleF sp2Bounds = startPath2.GetBounds(); PointF sp2BoundsCenter = new PointF((sp2Bounds.Left + sp2Bounds.Right) / 2.0f, (sp2Bounds.Top + sp2Bounds.Bottom) / 2.0f); float tAngle = Utility.GetAngleOfTransform(interim); bool isFlipped = Utility.IsTransformFlipped(interim); using (Matrix spm = new Matrix()) { spm.Reset(); spm.RotateAt(-tAngle, sp2BoundsCenter, MatrixOrder.Append); translateMatrix.RotateAt(-tAngle, sp2BoundsCenter, MatrixOrder.Append); startPath2.Transform(spm); } RectangleF spBounds2 = startPath2.GetBounds(); startPath2.Dispose(); startPath2 = null; float xTranslate; float yTranslate; bool allowConstrain; Edge theEdge = this.context.startEdge; // If the transform is flipped, then GetTransformAngle will return 180 degrees // even though no rotation has actually taken place. Thus we have to scratch // our head and go "hmm, let's make some adjustments to this." Otherwise stretching // the top and bottom nubs goes in the wrong direction. if (isFlipped) { theEdge = FlipEdgeVertically(theEdge); } switch (theEdge) { default: throw new InvalidEnumArgumentException(); case Edge.TopLeft: allowConstrain = true; xTranslate = -spBounds2.X - spBounds2.Width; yTranslate = -spBounds2.Y - spBounds2.Height; break; case Edge.Top: allowConstrain = false; xTranslate = 0; yTranslate = -spBounds2.Y - spBounds2.Height; break; case Edge.TopRight: allowConstrain = true; xTranslate = -spBounds2.X; yTranslate = -spBounds2.Y - spBounds2.Height; break; case Edge.Left: allowConstrain = false; xTranslate = -spBounds2.X - spBounds2.Width; yTranslate = 0; break; case Edge.Right: allowConstrain = false; xTranslate = -spBounds2.X; yTranslate = 0; break; case Edge.BottomLeft: allowConstrain = true; xTranslate = -spBounds2.X - spBounds2.Width; yTranslate = -spBounds2.Y; break; case Edge.Bottom: allowConstrain = false; xTranslate = 0; yTranslate = -spBounds2.Y; break; case Edge.BottomRight: allowConstrain = true; xTranslate = -spBounds2.X; yTranslate = -spBounds2.Y; break; } translateMatrix.Translate(xTranslate, yTranslate, MatrixOrder.Append); float newWidth = spBounds2.Width + xulen; float newHeight = spBounds2.Height + yulen; float xScale = newWidth / spBounds2.Width; float yScale = newHeight / spBounds2.Height; if (allowConstrain && (this.ModifierKeys & Keys.Shift) != 0) { ConstrainScaling(this.context.liftedBounds, spBounds2.Width, spBounds2.Height, newWidth, newHeight, out xScale, out yScale); } translateMatrix.Scale(xScale, yScale, MatrixOrder.Append); translateMatrix.Translate(-xTranslate, -yTranslate, MatrixOrder.Append); translateMatrix.RotateAt(+tAngle, sp2BoundsCenter, MatrixOrder.Append); break; default: throw new InvalidEnumArgumentException(); } this.context.deltaTransform.Reset(); this.context.deltaTransform.Multiply(this.context.liftTransform, MatrixOrder.Append); this.context.deltaTransform.Multiply(translateMatrix, MatrixOrder.Append); translateMatrix.Multiply(this.context.baseTransform, MatrixOrder.Prepend); Selection.SetInterimTransform(translateMatrix); interim.Dispose(); interim = null; } // advertise our angle of rotation to any host (i.e. mainform) that might want to use that information this.hostShouldShowAngle = this.rotateNub.Visible; this.hostAngle = -this.rotateNub.Angle; Selection.PerformChanged(); dontDrop = false; Render(newOffset, true); Update(); this.context.offset = newOffset; if (this.enableOutline) { DocumentWorkspace.ResetOutlineWhiteOpacity(); } } }
public void Render(Graphics g, WorldTransform t) { Coordinates wll = t.WorldLowerLeft; Coordinates wup = t.WorldUpperRight; if ((position.X < wll.X || position.X > wup.X || position.Y < wll.Y || position.Y > wup.Y)) { return; } Matrix bodyTrans = new Matrix(); bodyTrans.Rotate((float)(this.Heading) * 180 / (float)Math.PI - 90); bodyTrans.Translate((float)position.X, (float)position.Y, MatrixOrder.Append); Matrix origTrans = g.Transform.Clone(); bodyTrans.Multiply(g.Transform, MatrixOrder.Append); g.Transform = bodyTrans; float penWidth = nomPixelWidth / t.Scale; using (Pen p = new Pen(color, penWidth)) { DrawRectangle(g, p, bodyRect); // build the transform for the rear wheels // do the left wheel Matrix wheelTransform = bodyTrans.Clone(); wheelTransform.Translate(-wheelOffset, 0, MatrixOrder.Prepend); try { g.Transform = wheelTransform; g.FillRectangle(Brushes.White, wheelRectL); DrawRectangle(g, p, wheelRectL); } catch (Exception) { } // do the right wheel wheelTransform = bodyTrans.Clone(); wheelTransform.Translate(wheelOffset, 0, MatrixOrder.Prepend); try { g.Transform = wheelTransform; g.FillRectangle(Brushes.White, wheelRectR); DrawRectangle(g, p, wheelRectR); } catch (Exception) { } // do the front wheels // do the left wheel wheelTransform = bodyTrans.Clone(); wheelTransform.Translate(-wheelOffset, wheelbase, MatrixOrder.Prepend); wheelTransform.Rotate(steeringAngle * 180 / (float)Math.PI, MatrixOrder.Prepend); try { g.Transform = wheelTransform; g.FillRectangle(Brushes.White, wheelRectL); DrawRectangle(g, p, wheelRectL); } catch (Exception) { } // do the right wheel wheelTransform = bodyTrans.Clone(); wheelTransform.Translate(wheelOffset, wheelbase, MatrixOrder.Prepend); wheelTransform.Rotate(steeringAngle * 180 / (float)Math.PI, MatrixOrder.Prepend); try { g.Transform = wheelTransform; g.FillRectangle(Brushes.White, wheelRectR); DrawRectangle(g, p, wheelRectR); } catch (Exception) { } } g.Transform = origTrans; // draw Position DrawingUtility.DrawControlPoint(this.position, color, null, ContentAlignment.MiddleCenter, ControlPointStyle.LargeX, g, t); }
public override void UpdateScene() { base.UpdateScene(); Background.X = Model.Time.Value; Background.Y = -Model.Value.Value; CollapsedView.X = Background.X; var isSelected = Model.Selected.Value; Label.Visible = isSelected || FHovered; if (Label.Visible) { var m = new Matrix(); var h = Parent.KeyframeDefinition.Radius * 3 * Parent.KeyframeDefinition.Transforms[0].Matrix.Elements[3]; var y = Math.Max(Background.Y, -Parent.Model.Maximum.Value + h); m.Translate(Background.X + 0.15f, y); m.Multiply(Parent.KeyframeDefinition.Transforms[0].Matrix); Label.Transforms[0] = new SvgMatrix(m.Elements.ToList()); Label.Text = string.Format("{0:0.0000}", Model.Value.Value) + " " + string.Format("{0:0.00}", Model.Time.Value); } Background.CustomAttributes["class"] = isSelected ? "kf selected" : "kf"; var css = "ckf"; if (Model.Ease.Value > 0) css = "ekf"; CollapsedView.CustomAttributes["class"] = isSelected ? css + " selected" : css; var ease = "_NE"; switch (Model.Ease.Value) { case 1: ease = "_EI"; break; case 2: ease = "_EO"; break; case 3: ease = "_EIO"; break; } CollapsedView.ReferencedElement = new Uri("#" + Parent.Model.GetID() + ease, UriKind.Relative); Background.Visible = !Parent.Collapsed; CollapsedView.Visible = Parent.Collapsed; }