internal static float ConvertSweepAngle(float sweepAngle, float startAngle, SpatialTransform transform, CoordinateSystem targetSystem) { PointF x = new PointF(100, 0); PointF[] startVector = new PointF[] { x }; Matrix rotation = new Matrix(); rotation.Rotate(startAngle); rotation.TransformVectors(startVector); PointF[] sweepVector = (PointF[])startVector.Clone(); rotation.Reset(); rotation.Rotate(sweepAngle); rotation.TransformVectors(sweepVector); rotation.Dispose(); SizeF startVectorTransformed, sweepVectorTransformed; if (targetSystem == Graphics.CoordinateSystem.Destination) { startVectorTransformed = transform.ConvertToDestination(new SizeF(startVector[0])); sweepVectorTransformed = transform.ConvertToDestination(new SizeF(sweepVector[0])); } else { startVectorTransformed = transform.ConvertToSource(new SizeF(startVector[0])); sweepVectorTransformed = transform.ConvertToSource(new SizeF(sweepVector[0])); } // simply return the angle between the start and sweep angle, in the target system. return((int)Math.Round(Vector.SubtendedAngle(sweepVectorTransformed.ToPointF(), PointF.Empty, startVectorTransformed.ToPointF()))); }
/// <summary> /// Demonstrates the use of XGraphics.Transform. /// </summary> public override void RenderPage(XGraphics gfx) { //gfx.Clear(this.properties.General.BackColor.Color); base.RenderPage(gfx); gfx.DrawLine(XPens.MediumSlateBlue, 0, 0, 150, 200); gfx.DrawPolygon(properties.Pen1.Pen, GetPentagram(75, new PointF(150, 200))); Matrix matrix = new Matrix(); //matrix.Scale(2f, 1.5f); //matrix.Translate(-200, -400); //matrix.Rotate(45); //matrix.Translate(200, 400); //gfx.Transform = matrix; //gfx.TranslateTransform(50, 30); #if true gfx.TranslateTransform(30, 40, XMatrixOrder.Prepend); gfx.ScaleTransform(2.0f, 2.0f, XMatrixOrder.Prepend); gfx.RotateTransform(15, XMatrixOrder.Prepend); #else gfx.TranslateTransform(30, 40, XMatrixOrder.Append); gfx.ScaleTransform(2.0f, 2.0f, XMatrixOrder.Append); gfx.RotateTransform(15, XMatrixOrder.Append); #endif bool id = matrix.IsIdentity; matrix.Scale(2.0f, 2.0f, MatrixOrder.Prepend); //matrix.Translate(30, -50); matrix.Rotate(15, MatrixOrder.Prepend); //Matrix mtx = gfx.Transform.ToGdiMatrix(); //gfx.Transform = matrix; gfx.DrawLine(XPens.MediumSlateBlue, 0, 0, 150, 200); gfx.DrawPolygon(properties.Pen2.Pen, GetPentagram(75, new PointF(150, 200))); }
/// <summary> /// Applies matrix transformation to graphics /// </summary> private static void TransformCoordinates() { using (var bitmap = new Bitmap(600, 300, PixelFormat.Format24bppRgb, RgbColor.White)) using (var graphics = bitmap.GetAdvancedGraphics()) { // Move coordinate system var matrix1 = new System.Drawing.Drawing2D.Matrix(); matrix1.Translate(bitmap.Width / 2, bitmap.Height / 2); graphics.Transform = matrix1; DrawEllipseAndText(graphics, 30); // Move, shear and rotate coordinate system var matrix2 = new System.Drawing.Drawing2D.Matrix(); matrix2.Translate(bitmap.Width / 2, bitmap.Height / 2); matrix2.Shear(0.5f, 0.1f); matrix2.Rotate(30f); graphics.Transform = matrix2; DrawEllipseAndText(graphics, 255); bitmap.Save("../../../../_Output/TransformCoordinates.png"); } }
private void Form1_Paint(object sender, PaintEventArgs e) { using (Graphics g = e.Graphics) { // Создаем траекторию GraphicsPath path = new GraphicsPath(); Rectangle rect = new Rectangle(20, 20, 150, 150); path.AddRectangle(rect); // Создаем градиентную кисть PathGradientBrush pgBrush = new PathGradientBrush(path.PathPoints); // Уснинавливаем цвета кисти pgBrush.CenterColor = Color.Red; pgBrush.SurroundColors = new Color[] { Color.Blue }; // Создаем объект Matrix Matrix X = new Matrix(); // Translate X.Translate(30.0f, 10.0f, MatrixOrder.Append); // Rotate X.Rotate(10.0f, MatrixOrder.Append); // Scale X.Scale(1.2f, 1.0f, MatrixOrder.Append); // Shear X.Shear(.2f, 0.03f, MatrixOrder.Prepend); // Применяем преобразование к траектории и кисти path.Transform(X); pgBrush.Transform = X; // Выполняем визуализацию g.FillPath(pgBrush, path); } }
public static Bitmap RotateImage(Bitmap image, float angle) { int w = image.Width; int h = image.Height; Bitmap tempImg = new Bitmap(w, h); Graphics g = Graphics.FromImage(tempImg); g.Clear(Color.Transparent); g.DrawImageUnscaled(image, 0, 0); g.Dispose(); GraphicsPath path = new GraphicsPath(); path.AddRectangle(new RectangleF(0f, 0f, w, h)); System.Drawing.Drawing2D.Matrix mtrx = new System.Drawing.Drawing2D.Matrix(); mtrx.Rotate(angle); RectangleF rct = path.GetBounds(mtrx); Bitmap newImg = new Bitmap((int)rct.Width, (int)rct.Height); g = Graphics.FromImage(newImg); g.Clear(Color.Transparent); g.TranslateTransform(-rct.X, -rct.Y); g.RotateTransform(angle); g.InterpolationMode = InterpolationMode.HighQualityBilinear; g.DrawImageUnscaled(tempImg, 0, 0); g.Dispose(); tempImg.Dispose(); return(newImg); }
/// <summary> /// Returned points 1-4 are the left track, points 5-8 are the right track, 9-16 are the turret /// They should be drawn individually /// </summary> public static PointF[] TankPolygonPoints(int offsetX, int offsetY, float rotDegrees, float size) { var points = new PointF[16] { // Left track new PointF(-1, -1), new PointF(-1, 1), new PointF(-0.5f, 1), new PointF(-0.5f, -1), // Right track new PointF(0.5f, -1), new PointF(1, -1), new PointF(1, 1), new PointF(0.5f, 1), // Turret new PointF(-0.5f, -0.5f), new PointF(0.5f, -0.5f), new PointF(-0.5f, 0.5f), new PointF(-0.25f, 0.5f), new PointF(-0.25f, 1.75f), new PointF(0.25f, 1.75f), new PointF(0.25f, 0.5f), new PointF(0.5f, 0.5f) }; var matrix = new Matrix(); matrix.Rotate(rotDegrees, MatrixOrder.Append); matrix.Translate(offsetX, offsetY, MatrixOrder.Append); matrix.Scale(size, size); matrix.TransformPoints(points); return points; }
public Bitmap RotateImg(Bitmap bmp, float angle) { var bkColor = Color.White; int w = bmp.Width; int h = bmp.Height; PixelFormat pf; pf = bkColor == Color.Transparent ? PixelFormat.Format32bppArgb : bmp.PixelFormat; Bitmap tempImg = new Bitmap(w, h, pf); Graphics g = Graphics.FromImage(tempImg); g.Clear(bkColor); g.DrawImageUnscaled(bmp, 1, 1); g.Dispose(); GraphicsPath path = new GraphicsPath(); path.AddRectangle(new RectangleF(0f, 0f, w, h)); Matrix mtrx = new Matrix(); //Using System.Drawing.Drawing2D.Matrix class mtrx.Rotate(angle); RectangleF rct = path.GetBounds(mtrx); Bitmap newImg = new Bitmap(Convert.ToInt32(rct.Width), Convert.ToInt32(rct.Height), pf); g = Graphics.FromImage(newImg); g.Clear(bkColor); g.TranslateTransform(-rct.X, -rct.Y); g.RotateTransform(angle); g.InterpolationMode = InterpolationMode.HighQualityBilinear; g.DrawImageUnscaled(tempImg, 0, 0); g.Dispose(); tempImg.Dispose(); return newImg; }
public static Bitmap KiRotate(Bitmap bmp, float angle, Color bkColor) { PixelFormat pf; int w = bmp.Width + 2; int h = bmp.Height + 2; if (bkColor == Color.Transparent) { pf = PixelFormat.Format32bppArgb; } else { pf = bmp.PixelFormat; } Bitmap tmp = new Bitmap(w, h, pf); Graphics g = Graphics.FromImage(tmp); g.Clear(bkColor); g.DrawImageUnscaled(bmp, 1, 1); g.Dispose(); GraphicsPath path = new GraphicsPath(); path.AddRectangle(new RectangleF(0f, 0f, (float)w, (float)h)); Matrix mtrx = new Matrix(); mtrx.Rotate(angle); RectangleF rct = path.GetBounds(mtrx); Bitmap dst = new Bitmap((int)rct.Width, (int)rct.Height, pf); g = Graphics.FromImage(dst); g.Clear(bkColor); g.TranslateTransform(-rct.X, -rct.Y); g.RotateTransform(angle); g.InterpolationMode = InterpolationMode.HighQualityBilinear; g.DrawImageUnscaled(tmp, 0, 0); g.Dispose(); tmp.Dispose(); return dst; }
protected override void OnPaint(PaintEventArgs e) { if (backBuffer == null) backBuffer = new Bitmap(this.ClientSize.Width, this.ClientSize.Height); Graphics g = doubleBuffering ? Graphics.FromImage(backBuffer) : e.Graphics; g.SmoothingMode = smoothing ? SmoothingMode.AntiAlias : SmoothingMode.Default; g.Clear(SystemColors.Control); Matrix mx = new Matrix(); mx.Rotate(angle); mx.Translate(this.ClientSize.Width / 2, this.ClientSize.Height / 2, MatrixOrder.Append); g.Transform = mx; g.FillRectangle(Brushes.Red, -100, -100, 200, 200); mx = new Matrix(); mx.Rotate(-angle); mx.Translate(this.ClientSize.Width / 2, this.ClientSize.Height / 2, MatrixOrder.Append); g.Transform = mx; g.FillRectangle(Brushes.Green, -75, -75, 150, 150); mx = new Matrix(); mx.Rotate(angle * 2); mx.Translate(this.ClientSize.Width / 2, this.ClientSize.Height / 2, MatrixOrder.Append); g.Transform = mx; g.FillRectangle(Brushes.Blue, -50, -50, 100, 100); if (doubleBuffering) { g.Dispose(); e.Graphics.DrawImageUnscaled(backBuffer, 0, 0); } }
public Color[,] rotate(Color[,] Org_Buffer, int angle) { flag_rotate_shear = true; Matrix M = new Matrix(); M.Rotate(angle); return Transform(Org_Buffer, M); }
static public Matrix GetMatrix (int index) { // not defined (-1) or first (0) if (index <= 0) return null; Matrix m = new Matrix (); switch (index) { case 1: // empty break; case 2: m.Rotate (15); break; case 3: m.RotateAt (45, new PointF (100, 100)); break; case 4: m.Scale (1.5f, 0.5f); break; case 5: m.Shear (2.0f, 2.0f); break; case 6: m.Translate (50, 50); break; } return m; }
public static void Run() { // ExStart:CalculateCenterOfSubShapes // The path to the documents directory. string dataDir = RunExamples.GetDataDir_Shapes(); // Load Visio diagram Diagram diagram = new Diagram(dataDir + "Drawing1.vsdx"); // Get a group shape by ID and page index is 0 Shape shape = diagram.Pages[0].Shapes.GetShape(795); // Get a sub-shape of the group shape by id Shape subShape = shape.Shapes.GetShape(794); Matrix m = new Matrix(); // Apply the translation vector m.Translate(-(float)subShape.XForm.LocPinX.Value, -(float)subShape.XForm.LocPinY.Value); // Set the elements of that matrix to a rotation m.Rotate((float)subShape.XForm.Angle.Value); // Apply the translation vector m.Translate((float)subShape.XForm.PinX.Value, (float)subShape.XForm.PinY.Value); // Get pinx and piny double pinx = m.OffsetX; double piny = m.OffsetY; // Calculate the sub-shape pinx and piny double resultx = shape.XForm.PinX.Value - shape.XForm.LocPinX.Value - pinx; double resulty = shape.XForm.PinY.Value - shape.XForm.LocPinY.Value - piny; // ExEnd:CalculateCenterOfSubShapes }
internal void Draw(Graphics g) { GraphicsPath p = DrawDynamic(); if (p == null) { DrawStatic(g); return; } System.Drawing.Drawing2D.Matrix m = new System.Drawing.Drawing2D.Matrix(); m.Scale(OwningScene.DrawingScale, OwningScene.DrawingScale); m.Rotate(Body.Rotation); m.Translate(Body.Position.X, Body.Position.Y); p.Transform(m); if (Mode == DrawMode.Draw) { g.DrawPath(new Pen(DrawColor), p); } else { g.FillPath(new SolidBrush(DrawColor), p); } }
public override void Draw(CGRect rect) { Graphics g = Graphics.FromCurrentContext (); int offset = 20; // Scale: var m = new Matrix(1, 2, 3, 4, 0, 1); g.DrawString ("Original Matrix:", Font, Brushes.Black, 10, 10); DrawMatrix (m, g, 10, 10 + offset); g.DrawString ("Scale - Prepend:", Font, Brushes.Black, 10, 10 + 2 * offset); m.Scale (1, 0.5f, MatrixOrder.Prepend); DrawMatrix (m, g, 10, 10 + 3 * offset); g.DrawString ("Scale - Append:", Font, Brushes.Black, 10, 10 + 4 * offset); m = new Matrix (1, 2, 3, 4, 0, 1); m.Scale (1, 0.5f, MatrixOrder.Append); DrawMatrix (m, g, 10, 10 + 5 * offset); // Translation: m = new Matrix (1, 2, 3, 4, 0, 1); g.DrawString ("Translation - Prepend:", Font, Brushes.Black, 10, 10 + 6 * offset); m.Translate (1, 0.5f, MatrixOrder.Prepend); DrawMatrix (m, g, 10, 10 + 7 * offset); g.DrawString ("Translation - Append:", Font, Brushes.Black, 10, 10 + 8 * offset); // Reset m to the original matrix: m = new Matrix(1, 2, 3, 4, 0, 1); m.Translate (1, 0.5f, MatrixOrder.Append); DrawMatrix (m, g, 10, 10 + 9 * offset); m = new Matrix (1, 2, 3, 4, 0, 1); g.DrawString ("Rotation - Prepend:", Font, Brushes.Black, 10, 10 + 10 * offset); m.Rotate (45, MatrixOrder.Prepend); DrawMatrix (m, g, 10, 10 + 11 * offset); g.DrawString ("Rotation - Append:", Font, Brushes.Black, 10, 10 + 12 * offset); // Reset m to the original matrix: m = new Matrix (1, 2, 3, 4, 0, 1); m.Rotate (45, MatrixOrder.Append); DrawMatrix (m, g, 10, 10 + 13 * offset); // Rotation at (x = 1, y = 2): m = new Matrix (1, 2, 3, 4, 0, 1); g.DrawString ("Rotation At - Prepend:", Font, Brushes.Black, 10, 10 + 14 * offset); m.RotateAt (45, new Point (1, 2), MatrixOrder.Prepend); DrawMatrix (m, g, 10, 10 + 15 * offset); g.DrawString ("Rotation At - Append:", Font, Brushes.Black, 10, 10 + 16 * offset); m = new Matrix (1, 2, 3, 4, 0, 1); m.RotateAt (45, new Point (1, 2), MatrixOrder.Append); DrawMatrix(m, g, 10, 10 + 17 * offset); // Shear: m = new Matrix (1, 2, 3, 4, 0, 1); g.DrawString ("Shear - Prepend:", Font, Brushes.Black, 10, 10 + 18 * offset); m.Shear (1, 2, MatrixOrder.Prepend); DrawMatrix (m, g, 10, 10 + 19 * offset); g.DrawString ("Shear - Append:", Font, Brushes.Black, 10, 10 + 20 * offset); // Reset m to the original matrix: m = new Matrix (1, 2, 3, 4, 0, 1); m.Shear (1, 2, MatrixOrder.Append); DrawMatrix (m, g, 10, 10 + 21 * offset); }
private void Form2_Paint(object sender, PaintEventArgs e) { //패스 그래디언트 Point[] pts = { new Point(100, 0), new Point(0, 100), new Point(200, 100) }; PathGradientBrush B = new PathGradientBrush(pts, WrapMode.Tile); e.Graphics.FillRectangle(B, ClientRectangle); //패스 그래디언트 끝 //패스변형 GraphicsPath Path = new GraphicsPath(); Path.AddString("한글", new FontFamily("궁서"), 0, 100, new Point(10, 30), new StringFormat()); //확장 후 외곽선 그리기 Path.Widen(new Pen(Color.Black, 3)); e.Graphics.DrawPath(Pens.Black, Path); //확장 후 채우기 Path.Widen(new Pen(Color.Blue, 3)); e.Graphics.DrawPath(Pens.Black, Path); //곡선 펴기 Path.Flatten(new Matrix(), 12f); e.Graphics.DrawPath(Pens.Black, Path); //회전 Matrix M = new Matrix(); M.Rotate(-10); Path.Transform(M); e.Graphics.FillPath(Brushes.Blue, Path); //휘기 RectangleF R = Path.GetBounds(); PointF[] arPoint = new PointF[4]; arPoint[0] = new PointF(R.Left, R.Top + 30); arPoint[1] = new PointF(R.Right, R.Top - 10); arPoint[2] = new PointF(R.Left + 10, R.Bottom - 10); arPoint[3] = new PointF(R.Right + 30, R.Bottom + 30); Path.Warp(arPoint, R); e.Graphics.FillPath(Brushes.Blue, Path); //클리핑 //graphicspath path= new graphicspath(); //path.fillmode = fillmode.winding; //path.addellipse(50, 10, 100, 80); //path.addellipse(20, 45, 160, 120); //e.graphics.fillpath(brushes.white, path); //e.graphics.setclip(path); //for (int y = 0; y < bottom; y+= 20) //{ // string str = "눈사람의 모양의클리핑 영역에 글자를 쓴것입니다"; // e.graphics.drawstring(str, font, brushes.blue, 0, y); //} //클리핑 끝 }
public void full_transform(float ScX, float ScY, float ShX, float ShY, float RoAngle) { Matrix transform_matrix = new Matrix(); transform_matrix.Scale(ScX, ScY, MatrixOrder.Append); transform_matrix.Shear(ShX, ShY, MatrixOrder.Append); transform_matrix.Rotate(RoAngle, MatrixOrder.Append); Transform(transform_matrix); }
/// <summary> /// Draws the GameObject /// </summary> /// <param name="draw">Graphics to use for drawing</param> public void Draw(Graphics draw) { Matrix rotate = new Matrix(); rotate.Rotate(m_rotation); Matrix oldTransform = draw.Transform; draw.Transform = rotate; PreformDraw(draw); draw.Transform = oldTransform; }
public Bitmap RotateBitmap(Bitmap bm, float angle) { // Make a Matrix to represent rotation // by this angle. Matrix rotate_at_origin = new Matrix(); rotate_at_origin.Rotate(angle); // Rotate the image's corners to see how big // it will be after rotation. PointF[] points = { new PointF(0, 0), new PointF(bm.Width, 0), new PointF(bm.Width, bm.Height), new PointF(0, bm.Height), }; rotate_at_origin.TransformPoints(points); float xmin, xmax, ymin, ymax; GetPointBounds(points, out xmin, out xmax, out ymin, out ymax); // Make a bitmap to hold the rotated result. int wid = (int)Math.Round(xmax - xmin); int hgt = (int)Math.Round(ymax - ymin); Bitmap result = new Bitmap(wid, hgt); // Create the real rotation transformation. Matrix rotate_at_center = new Matrix(); rotate_at_center.RotateAt(angle, new PointF(0, 0)); // Draw the image onto the new bitmap rotated. using (Graphics gr = Graphics.FromImage(result)) { // Use smooth image interpolation. gr.InterpolationMode = InterpolationMode.HighQualityBilinear; // Clear with the color in the image's upper left corner. gr.Clear(bm.GetPixel(0, 0)); gr.Clear(Color.White); // Set up the transformation to rotate. gr.Transform = rotate_at_center; // Draw the image centered on the bitmap. int x = 0; int y = 0; gr.DrawImage(bm, x, y); } // Return the result bitmap. return result; }
/// <summary> /// This method is called by the owner brick when the brick has rotated to allow /// the attached rulers to follow the brick. /// </summary> public void brickRotateNotification() { // compute the rotation matrix Matrix matrix = new Matrix(); matrix.Rotate(mOwnerBrick.Orientation); // rotate all the anchor offset foreach (Anchor anchor in mAnchors) anchor.rotate(matrix); // then call the move notification brickMoveNotification(); }
void Parent_PCBIFormGraphicPaneDrawing(Graphics g, int ClientWidth, int ClientHeight) { if (!parent.JobIsLoaded) { return; } int pcbCount = 0; IStep PanelStep = parent.GetCurrentStep(); if (PanelStep == null) { return; } RectangleF PanelSize = PanelStep.GetBounds(); if (PanelSize == RectangleF.Empty) { return; } DrawSingleBoard(g, PanelSize, new PointD(0, 0), pcbCount, PanelStep.Name, "0"); pcbCount++; List <IStep.StepAndRepeatClass> srList = PanelStep.GetChildStepClasses(); foreach (IStep.StepAndRepeatClass sr in srList) { IStep step = parent.GetStep(sr.NAME); System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix(); matrix.Rotate(-(float)sr.ANGLE, System.Drawing.Drawing2D.MatrixOrder.Append); matrix.Translate((float)sr.X, (float)sr.Y, System.Drawing.Drawing2D.MatrixOrder.Append); RectangleF BoardSize = IMath.RectangleTransformWithMatrix(step.GetBoundsD(), matrix).ToRectangleF(); PointD originOfBoard = new PointD(sr.X, sr.Y); IMath.TransformPoint(matrix, originOfBoard); DrawSingleBoard(g, BoardSize, originOfBoard, pcbCount, sr.NAME, sr.ANGLE.ToString("N2")); if (sr.NX > 1 || sr.NY > 1) { for (int iy = 0; iy < sr.NY; iy++) { for (int ix = 0; ix < sr.NX; ix++) { System.Drawing.Drawing2D.Matrix matrixsr = matrix.Clone(); double offsetX = sr.DX * ix; double offsetY = sr.DY * iy; matrixsr.Translate((float)offsetX, (float)offsetY, System.Drawing.Drawing2D.MatrixOrder.Append); BoardSize = IMath.RectangleTransformWithMatrix(step.GetBoundsD(), matrixsr).ToRectangleF(); originOfBoard = new PointD(sr.X + offsetX, sr.Y + offsetY); DrawSingleBoard(g, BoardSize, originOfBoard, pcbCount, sr.NAME, sr.ANGLE.ToString("N2")); pcbCount++; } } } pcbCount++; } }
/// <summary> /// Demonstrates the use of XGraphics.Transform. /// </summary> public override void RenderPage(XGraphics gfx) { base.RenderPage(gfx); //XGraphicsState state = gfx.Save(); gfx.Save(); gfx.IntersectClip(new XRect(20, 20, 300, 500)); gfx.DrawRectangle(XBrushes.Yellow, 0, 0, gfx.PageSize.Width, gfx.PageSize.Height); gfx.Restore(); gfx.Save(); gfx.IntersectClip(new XRect(100, 200, 300, 500)); gfx.DrawRectangle(XBrushes.LightBlue, 0, 0, gfx.PageSize.Width, gfx.PageSize.Height); gfx.DrawLine(XPens.MediumSlateBlue, 0, 0, 150, 200); gfx.DrawPolygon(properties.Pen1.Pen, GetPentagram(75, new PointF(150, 200))); Matrix matrix = new Matrix(); //matrix.Scale(2f, 1.5f); //matrix.Translate(-200, -400); //matrix.Rotate(45); //matrix.Translate(200, 400); //gfx.Transform = matrix; //gfx.TranslateTransform(50, 30); #if true gfx.TranslateTransform(30, 40, XMatrixOrder.Prepend); gfx.ScaleTransform(2.0f, 2.0f, XMatrixOrder.Prepend); gfx.RotateTransform(15, XMatrixOrder.Prepend); #else gfx.TranslateTransform(30, 40, XMatrixOrder.Append); gfx.ScaleTransform(2.0f, 2.0f, XMatrixOrder.Append); gfx.RotateTransform(15, XMatrixOrder.Append); #endif bool id = matrix.IsIdentity; matrix.Scale(2.0f, 2.0f, MatrixOrder.Prepend); //matrix.Translate(30, -50); matrix.Rotate(15, MatrixOrder.Prepend); //Matrix mtx = gfx.Transform.ToGdiMatrix(); //gfx.Transform = matrix; gfx.DrawLine(XPens.MediumSlateBlue, 0, 0, 150, 200); gfx.DrawPolygon(properties.Pen2.Pen, GetPentagram(75, new PointF(150, 200))); gfx.Restore(); gfx.DrawLine(XPens.Red, 0, 0, 1000, 1000); gfx.DrawPolygon(XPens.SandyBrown, GetPentagram(75, new PointF(150, 200))); }
public void Draw() { /*System.Drawing.Drawing2D.Matrix transform = System.Drawing.Drawing2D.Matrix.CreateTranslation(new Vector3(-pivot, 0.0f)) * * System.Drawing.Drawing2D.Matrix.CreateRotationZ(angle) * * System.Drawing.Drawing2D.Matrix.CreateTranslation(new Vector3(position, 0.0f));*/ DrawingMatrix = new System.Drawing.Drawing2D.Matrix(); Visual.X = (int)Position.X; Visual.Y = (int)Position.Y; DrawingMatrix.Rotate((float)Rotation, MatrixOrder.Append); Whiteboard.Transform = DrawingMatrix; Whiteboard.DrawRectangle(Color, Visual); }
public override void redo() { // get the rotation angle according to the rotation direction float rotationAngle = mRotateCW ? -mRotationStep : mRotationStep; // rotate all the objects Matrix rotation = new Matrix(); rotation.Rotate(rotationAngle); foreach (Layer.LayerItem item in mItems) rotate(item, rotation, rotationAngle, true); // update the bounding rectangle (because the text is not square) mLayer.updateBoundingSelectionRectangle(); }
public override void undo() { // get the rotation angle according to the rotation direction float rotationAngle = mRotateCW ? mRotationStep : -mRotationStep; // rotate all the objects Matrix rotation = new Matrix(); rotation.Rotate(rotationAngle); foreach (Layer.LayerItem item in mItems) rotate(item, rotation, rotationAngle, (item as LayerRuler.RulerItem).IsNotAttached); // update the bounding rectangle (because the ruler is not square) mLayer.updateBoundingSelectionRectangle(); }
public static void FileImposition(float width, float height, Stream exitStream, int numberDocOfPages, bool rotateSeconds, params Stream[] fileStreams) { Point currentPoint = null; var baseFont = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); //http://forums.asp.net/t/1692347.aspx/1 using (var document = new Document(new Rectangle(width, height))) { var writer = PdfWriter.GetInstance(document, exitStream); { document.Open(); var content = writer.DirectContent; document.NewPage(); var fileCount = 1; foreach (var fileStream in fileStreams) { var reader = new PdfReader(fileStream); var numberOfPages = reader.NumberOfPages; var isSecond = (fileCount % 2 == 0); if (numberOfPages > 0) { var page = writer.GetImportedPage(reader, 1); var pageRect = reader.GetPageSizeWithRotation(1); var matrix = new Matrix(); if (currentPoint == null) { currentPoint = new Point(0, pageRect.Height); } matrix.Translate(currentPoint.X, currentPoint.Y); matrix.Rotate(-90); currentPoint.Y += pageRect.Height; content.AddTemplate(page, matrix); content.BeginText(); content.SetFontAndSize(baseFont, 100); content.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "Data", currentPoint.X, currentPoint.Y,0); content.EndText(); currentPoint.Y += 100; } fileCount++; } } } }
private static void DrawPointMass(IPointMass pointMass, Pen pen, Brush brush, Graphics g) { var triangle = new[] { new PointF(1, 0), new PointF(-0.7f, 0.7f), new PointF(-0.7f, -0.7f) }; using (var m = new Matrix()) { m.Translate(pointMass.Position.X, pointMass.Position.Y); m.Rotate((float)(Math.Atan2(pointMass.Velocity.Y, pointMass.Velocity.X) * 180 / Math.PI)); m.Scale(pointMass.Radius*0.9f, pointMass.Radius*0.9f); m.TransformPoints(triangle); } g.FillPolygon(brush, triangle); g.DrawCircle(pen, pointMass.Position, pointMass.Radius); }
private SizeF ConvertSize(SizeF size, float angle) { System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix(); matrix.Rotate(angle); // 旋转矩形四个顶点 PointF[] pts = new PointF[4]; pts[0].X = -size.Width / 2f; pts[0].Y = -size.Height / 2f; pts[1].X = -size.Width / 2f; pts[1].Y = size.Height / 2f; pts[2].X = size.Width / 2f; pts[2].Y = size.Height / 2f; pts[3].X = size.Width / 2f; pts[3].Y = -size.Height / 2f; matrix.TransformPoints(pts); // 求取四个顶点的包围盒 float left = float.MaxValue; float right = float.MinValue; float top = float.MaxValue; float bottom = float.MinValue; foreach (PointF pt in pts) { // 求取并集 if (pt.X < left) { left = pt.X; } if (pt.X > right) { right = pt.X; } if (pt.Y < top) { top = pt.Y; } if (pt.Y > bottom) { bottom = pt.Y; } } SizeF result = new SizeF(right - left, bottom - top); return(result); }
public override void DrawEffectImage(Bitmap current, Bitmap next, EffectingPanel effecingPanel) { Bitmap doubleBufferingBitmap = null; // ダブルバッファリング用画面 Graphics bg = null; // ダブルバッファリング用画面描画用Graphics SolidBrush solidBrush = null; Rectangle rectangle; Matrix matrix = null; try { int deltaDegree = 10; doubleBufferingBitmap = new Bitmap(current); bg = Graphics.FromImage(doubleBufferingBitmap); solidBrush = new SolidBrush(System.Drawing.Color.Black); rectangle = new Rectangle(0, 0, current.Width, current.Height); matrix = new Matrix(); ResetInterval(); for (int angle = 0; angle <= 360; angle += deltaDegree) { bg.ResetTransform(); // リセット座標変換 bg.FillRectangle(solidBrush, rectangle); matrix.Reset(); matrix.Translate(doubleBufferingBitmap.Width / 2, doubleBufferingBitmap.Height / 2, MatrixOrder.Append); // 原点移動 matrix.Rotate((float)angle); bg.Transform = matrix; // 座標設定 bg.DrawImage(current, -doubleBufferingBitmap.Width / 2, -doubleBufferingBitmap.Height / 2); // 画像の中心が(0, 0)になるように描画 effecingPanel.pictureBox.Image = doubleBufferingBitmap; effecingPanel.pictureBox.Refresh(); Thread.Sleep(20); DoEventAtIntervals(); } matrix.Dispose(); bg.Dispose(); doubleBufferingBitmap.Dispose(); } catch(SystemException ex) { Console.WriteLine(ex.Message); } }
protected override void OnPaint(PaintEventArgs e) { if (_backBuffer == null) { _backBuffer = new Bitmap(this.ClientSize.Width, this.ClientSize.Height); } Graphics g = null; if (_doBuffer) g = Graphics.FromImage(_backBuffer); else g = e.Graphics; g.Clear(Color.White); g.SmoothingMode = SmoothingMode.AntiAlias; Matrix mx = new Matrix(); mx.Rotate(_angle, MatrixOrder.Append); mx.Translate(this.ClientSize.Width / 2, this.ClientSize.Height / 2, MatrixOrder.Append); g.Transform = mx; g.FillRectangle(Brushes.Red, -100, -100, 200, 200); mx = new Matrix(); mx.Rotate(-_angle, MatrixOrder.Append); mx.Translate(this.ClientSize.Width / 2, this.ClientSize.Height / 2, MatrixOrder.Append); g.Transform = mx; g.FillRectangle(Brushes.Green, -75, -75, 149, 149); mx = new Matrix(); mx.Rotate(_angle * 2, MatrixOrder.Append); mx.Translate(this.ClientSize.Width / 2, this.ClientSize.Height / 2, MatrixOrder.Append); g.Transform = mx; g.FillRectangle(Brushes.Blue, -50, -50, 100, 100); if (_doBuffer) { g.Dispose(); //Copy the back buffer to the screen e.Graphics.DrawImageUnscaled(_backBuffer, 0, 0); } //base.OnPaint (e); //optional but not recommended }
private void drawAnt(Ant ant, Graphics g) { int x, y; toScreenCoords(ant.x, ant.y, out x, out y); SolidBrush brush = new SolidBrush(new Color[] { Color.DarkRed, Color.Black }[ant.color]); Matrix m = new Matrix(); m.Translate(x + CELL_SIZE / 2, y + CELL_SIZE / 2); m.Rotate(60 * ant.direction); g.Transform = m; g.FillEllipse(brush, -5, -3, 10, 6); if (ant.hasFood) { Pen pen = new Pen(Color.Yellow); g.DrawRectangle(pen, 2, -1, 2, 2); } g.ResetTransform(); }
//http://www.tinaja.com/glib/bezcirc2.pdf private CircularBezier(PointD start, PointD center, PointD end) { double Θ = new VectorD(center, start).GetAngleWith(new VectorD(center, end)); double φ = Θ/2; double x0 = Math.Cos(φ); double y0 = Math.Sin(φ); double x3 = x0; double y3 = -y0; double x1 = (4 - x0)/3; double y1 = ((1 - x0)*(3 - x0))/(3*y0); double x2 = x1; double y2 = -y1; var points = new PointF[] {new PointD(x0, y3), new PointD(x1, y2), new PointD(x2, y1), new PointD(x3, y0)}; var matrix = new Matrix(); matrix.Rotate( Convert.ToSingle(Geometrics.RadianToDegree(Math.Atan2(start.Y - center.Y, start.X - center.X) + φ)) + 360); matrix.Scale(Convert.ToSingle(new LineD(start, center).Length), Convert.ToSingle(new LineD(start, center).Length)); matrix.TransformPoints(points); matrix = new Matrix(); matrix.Translate(Convert.ToSingle(center.X), Convert.ToSingle(center.Y)); matrix.TransformPoints(points); p0 = points[0]; p1 = points[1]; p2 = points[2]; p3 = points[3]; p0f = points[0]; p1f = points[1]; p2f = points[2]; p3f = points[3]; this.center = center; Length = getlength(); }
/// <summary> /// Converts the size. /// </summary> /// <param name="size">The size.</param> /// <param name="angle">The angle.</param> /// <returns>SizeF.</returns> public static SizeF ConvertSize(SizeF size, float angle) { System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix(); matrix.Rotate(angle); PointF[] array = new PointF[4]; array[0].X = (0f - size.Width) / 2f; array[0].Y = (0f - size.Height) / 2f; array[1].X = (0f - size.Width) / 2f; array[1].Y = size.Height / 2f; array[2].X = size.Width / 2f; array[2].Y = size.Height / 2f; array[3].X = size.Width / 2f; array[3].Y = (0f - size.Height) / 2f; matrix.TransformPoints(array); float num = float.MaxValue; float num2 = float.MinValue; float num3 = float.MaxValue; float num4 = float.MinValue; PointF[] array2 = array; for (int i = 0; i < array2.Length; i++) { PointF pointF = array2[i]; if (pointF.X < num) { num = pointF.X; } if (pointF.X > num2) { num2 = pointF.X; } if (pointF.Y < num3) { num3 = pointF.Y; } if (pointF.Y > num4) { num4 = pointF.Y; } } return(new SizeF(num2 - num, num4 - num3)); }
/// <summary> /// If the any of the would to cameraSpace variables are updated will recalculate the cameraTransform /// </summary> private void updateCameraTransform() { if (cameraTransformChanged) { //Reseting camera Transform cameraTransform.Reset(); //Translation to origin cameraTransform.Translate(-worldCenter.X, -worldCenter.Y, MatrixOrder.Append);; //Scale if (worldScale.X != 0 && worldScale.Y != 0 && (worldScale.X != 1 || worldScale.Y != 1)) { cameraTransform.Scale(worldScale.X, worldScale.Y, MatrixOrder.Append); } //Shear if ((worldShear.X != 1 || worldShear.Y != 1) && (worldShear.X != 0 || worldShear.Y != 0)) { cameraTransform.Shear(worldShear.X, worldShear.Y, MatrixOrder.Append); } //Rotation if (worldRotation != 0) { cameraTransform.Rotate(worldRotation, MatrixOrder.Append); } //Moving Center to Centr if (drawBuffers != null) { cameraTransform.Translate(drawBuffers[0].Width / 2, drawBuffers[0].Height / 2, MatrixOrder.Append); } else { cameraTransform.Translate(base.Width / 2, base.Height / 2, MatrixOrder.Append); } cameraTransformChanged = false; //invers Transform setInverseCameraTransform(); if (attachedMouse != null) { attachedMouse.setTransform(inverseCameraTransform); } } }
/// <summary> /// Draws path on Graphics /// </summary> private static void DrawPath() { using (var bitmap = new Bitmap(640, 480, PixelFormat.Format24bppRgb, RgbColor.White)) using (var graphics = bitmap.GetAdvancedGraphics()) { var path = CreatePath(graphics); graphics.DrawPath(new Pen(RgbColor.Red, 2f), path); // Translate coordinates and rotate var matrix = new System.Drawing.Drawing2D.Matrix(); matrix.Translate(bitmap.Width / 3, bitmap.Height / 3); matrix.Rotate(30); graphics.Transform = matrix; graphics.DrawPath(new Pen(RgbColor.Green, 2f), path); bitmap.Save("../../../../_Output/DrawPath.tif"); } }
internal static float ConvertStartAngle(float angle, SpatialTransform transform, CoordinateSystem targetSystem) { PointF xVector = new PointF(100, 0); Matrix rotation = new Matrix(); PointF[] angleVector = new PointF[] { xVector }; rotation.Rotate(angle); rotation.TransformVectors(angleVector); rotation.Dispose(); SizeF xVectorTransformed, angleVectorTransformed; if (targetSystem == Graphics.CoordinateSystem.Destination) { xVectorTransformed = transform.ConvertToDestination(new SizeF(xVector)); angleVectorTransformed = transform.ConvertToDestination(new SizeF(angleVector[0])); } else { xVectorTransformed = transform.ConvertToSource(new SizeF(xVector)); angleVectorTransformed = transform.ConvertToSource(new SizeF(angleVector[0])); } float xRotationOffset = (int)Math.Round(Vector.SubtendedAngle(xVectorTransformed.ToPointF(), PointF.Empty, xVector)); float angleTransformed = (int)Math.Round(Vector.SubtendedAngle(angleVectorTransformed.ToPointF(), PointF.Empty, xVectorTransformed.ToPointF())); // have to figure out where x-axis moved to and then return the difference between the angle // and the x-axis, where both are in 'target' coordinates. float returnAngle = angleTransformed + xRotationOffset; if (returnAngle < 0) { returnAngle += 360; } return(returnAngle); }
/// <summary> /// Snap rotate to some angle. Preserve scale and translation. /// </summary> /// <param name="mat"></param> /// <param name="angle">__ANGLE IS IN DEGREES__</param> /// <returns></returns> public static d2d.Matrix eSnapRotate(this d2d.Matrix mat, double angle) { // Graphics tries to work opposite of OpenGL, in Drawing2D: // PRE - multiply for local // post -multiply for global var curmat = mat.Elements; // get the vector components. var x_axis = new ai.Vector2D(curmat[0], curmat[1]); var y_axis = new ai.Vector2D(curmat[2], curmat[3]); // Get the scale of current matrix double x_len = x_axis.Length(); double y_len = y_axis.Length(); var newmat = new d2d.Matrix(); // Preserve scale and translation // This means: v*M = v*(S * R * T) newmat.Scale((float)x_len, (float)y_len); newmat.Rotate((float)angle); newmat.Translate(curmat[4], curmat[5]); return(newmat.Clone()); }
private void Form1_Paint(object sender, PaintEventArgs e) { using (Graphics g = e.Graphics) { // создаем путь GraphicsPath path = new GraphicsPath(); path.AddLine(20, 50, 200, 50); path.AddArc(50, 50, 100, 50, 10, -220); Matrix X = new Matrix(); // вращаем на 20 градусов X.Rotate(20); // применяем преобразование к GraphicsPath path.Transform(X); // Визуализируем прямоугольник g.DrawRectangle(new Pen(Brushes.Green,2), 10, 10, 60, 60); // Визуализируем путь g.DrawPath(new Pen(Color.Blue, 4), path); // Освобождаем ресурсы } }
private void Form1_Paint(object sender, PaintEventArgs e) { using (Graphics g = e.Graphics) { GraphicsPath path = new GraphicsPath(); Rectangle rect = new Rectangle(20, 20, 150, 150); path.AddRectangle(rect); PathGradientBrush pgBrush = new PathGradientBrush(path.PathPoints); pgBrush.CenterColor = Color.Tomato; pgBrush.SurroundColors = new Color[] { Color.Indigo , Color.Khaki}; Matrix X = new Matrix(); X.Translate(30f, 10f, MatrixOrder.Append); X.Rotate(10f, MatrixOrder.Append); X.Scale(1.2f, 1f, MatrixOrder.Append); path.Transform(X); pgBrush.Transform = X; g.FillPath(pgBrush, path); } }
/// <summary> /// Rotate the image by angle degrees, with bkColor as new background /// Uses some magic with the translatetransform and pixel2d :P WOW! /// </summary> /// <param name="bmp">the image to be rotated</param> /// <param name="angle">the angle to rotate by</param> /// <param name="bkColor">background color for new background pixels</param> /// <returns>bmp rotated by angle degrees</returns> public static Bitmap RotateImg(Bitmap bmp, float angle, Color bkColor) { int w = bmp.Width; int h = bmp.Height; System.Drawing.Imaging.PixelFormat pf = default(System.Drawing.Imaging.PixelFormat); if (bkColor == Color.Transparent) { pf = System.Drawing.Imaging.PixelFormat.Format32bppArgb; } else { pf = bmp.PixelFormat; } Bitmap tempImg = new Bitmap(w, h, pf); Graphics g = Graphics.FromImage(tempImg); g.Clear(bkColor); g.DrawImageUnscaled(bmp, 1, 1); g.Dispose(); System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddRectangle(new RectangleF(0f, 0f, w, h)); System.Drawing.Drawing2D.Matrix mtrx = new System.Drawing.Drawing2D.Matrix(); mtrx.Rotate(angle); RectangleF rct = path.GetBounds(mtrx); Bitmap newImg = new Bitmap(Convert.ToInt32(rct.Width), Convert.ToInt32(rct.Height), pf); g = Graphics.FromImage(newImg); g.Clear(bkColor); g.TranslateTransform(-rct.X, -rct.Y); g.RotateTransform(angle); g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear; g.DrawImageUnscaled(tempImg, 0, 0); g.Dispose(); tempImg.Dispose(); return(newImg); }
public static Bitmap ImageRotateAll(Bitmap btmp, float anglert, Color bgColor) { int wdth = btmp.Width; int hght = btmp.Height; PixelFormat pixfmt = default(PixelFormat); if (bgColor == Color.Transparent) { pixfmt = PixelFormat.Format32bppArgb; } else { pixfmt = btmp.PixelFormat; } Bitmap tempImage = new Bitmap(wdth, hght, pixfmt); Graphics gr = Graphics.FromImage(tempImage); gr.Clear(bgColor); gr.DrawImageUnscaled(btmp, 1, 1); gr.Dispose(); GraphicsPath path = new GraphicsPath(); path.AddRectangle(new RectangleF(0f, 0f, wdth, hght)); Matrix mtrx = new Matrix(); mtrx.Rotate(anglert); RectangleF rect = path.GetBounds(mtrx); Bitmap newImage = new Bitmap(Convert.ToInt32(rect.Width), Convert.ToInt32(rect.Height), pixfmt); gr = Graphics.FromImage(newImage); gr.Clear(bgColor); gr.TranslateTransform(-rect.X, -rect.Y); gr.RotateTransform(anglert); gr.InterpolationMode = InterpolationMode.HighQualityBilinear; gr.DrawImageUnscaled(tempImage, 0, 0); gr.Dispose(); tempImage.Dispose(); return newImage; }
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); }
public void RotateTransform(float angle, MatrixOrder order) { _transform.Rotate(angle, order); }
public MatrixComponents GetMatrixComponents() { System.Drawing.Drawing2D.Matrix srcMatrix = new System.Drawing.Drawing2D.Matrix( this.ScaleX, this.Rotate0, this.Rotate1, this.ScaleY, this.TranslateX, this.TranslateY); System.Drawing.Drawing2D.Matrix m = new System.Drawing.Drawing2D.Matrix(1, 0, 0, 1, 0, 0); // identity // an 'identity' box PointF[] modPts = new PointF[] { new PointF(0, 0), new PointF(1, 0), new PointF(1, 1), new PointF(0, 1) }; float sx, sy, rot, shear, tx, ty; srcMatrix.TransformPoints(modPts); // translation tx = srcMatrix.OffsetX; ty = srcMatrix.OffsetY; m.Translate(-tx, -ty); m.TransformPoints(modPts); m.Reset(); // rotation rot = (float)Math.Atan2(modPts[1].Y, modPts[1].X); // x axis rot = (float)(rot / Math.PI * 180); if (rot == -0) { rot = 0; } if (rot == -180) { rot = 180; } m.Rotate(-1 * rot); m.TransformPoints(modPts); m.Reset(); // scale //sx = Dist(modPts[0], modPts[3]); // bug it seems..? sx = Dist(modPts[0], modPts[1]); sy = Dist(modPts[0], new PointF(0, modPts[3].Y)); if (modPts[0].Y > modPts[3].Y) { sy *= -1; } m.Scale(1 / sx, 1 / sy); m.TransformPoints(modPts); m.Reset(); // skew // ySkew is impossible at this rotation shear = modPts[3].X / Dist(modPts[0], modPts[1]); // rounding shear = Math.Abs(shear) < 0.001 ? 0 : shear; m.Shear(-shear, 0); m.TransformPoints(modPts); m.Dispose(); srcMatrix.Dispose(); return(new MatrixComponents(sx, sy, rot, shear, tx, ty)); }
private const int MinItemRadialAngle = 18; // Minimum space in angles that can be occupied by single item. 18 gives 20 items on radial menu. public override void RecalcSize() { if (_RecalcSizeInProgress) return; // Prevent re-entrancy _RecalcSizeInProgress = true; try { DisposeSubItemsInfo(); m_Rect = new Rectangle(0, 0, _Diameter, _Diameter); //this.WidthInternal = _Diameter; //this.HeightInternal = _Diameter; Rectangle bounds = new Rectangle(this.LeftInternal, this.TopInternal, _Diameter, _Diameter); bounds.Width--; bounds.Height--; Rectangle radialMenuBounds = bounds; Rectangle centerBounds = bounds; centerBounds.Inflate(-((_Diameter - _CenterButtonDiameter) / 2 + 1), -((_Diameter - _CenterButtonDiameter) / 2 + 1)); if (_MenuType == eRadialMenuType.Segment) { bounds.Inflate(-_SubMenuEdgeWidth, -_SubMenuEdgeWidth); bounds.Inflate(-_SubMenuEdgeItemSpacing, -_SubMenuEdgeItemSpacing); } SubItemsCollection displayCollection = GetDisplayCollection(); int visibleCount = GetVisibleItemsCount(displayCollection); if (visibleCount > 0) { int maxItemRadialAngle = _MaxItemRadialAngle; if (maxItemRadialAngle == 0) maxItemRadialAngle = 180; int itemPieAngle = Math.Max(MinItemRadialAngle, Math.Min(maxItemRadialAngle, 360 / visibleCount)); if (itemPieAngle > _MaxItemPieAngle) itemPieAngle = _MaxItemPieAngle; // Single item can consume at most half of the circle int currentAngle = -90 - itemPieAngle / 2; _SubItemsInfo = new RadialSubItemInfo[displayCollection.Count]; for (int i = 0; i < displayCollection.Count; i++) { BaseItem item = displayCollection[i]; if (!item.Visible) continue; RadialMenuItem menuItem = item as RadialMenuItem; if (menuItem != null) { menuItem.RecalcSize(); GraphicsPath path = new GraphicsPath(); path.AddArc(bounds, currentAngle, itemPieAngle); Rectangle cb = centerBounds; cb.Inflate(4, 4); path.AddArc(cb, currentAngle + itemPieAngle, -itemPieAngle); path.CloseAllFigures(); menuItem.DisplayPath = path; menuItem.OutterBounds = bounds; menuItem.CenterBounds = centerBounds; menuItem.ItemAngle = currentAngle; menuItem.ItemPieAngle = itemPieAngle; menuItem.Bounds = Rectangle.Round(path.GetBounds()); } else { item.RecalcSize(); // Position item along the imaginary inner circle Rectangle innerCircle = bounds; innerCircle.Width -= item.WidthInternal; innerCircle.Height -= item.HeightInternal; if (innerCircle.Width < centerBounds.Width) innerCircle.Inflate((centerBounds.Width - innerCircle.Width) / 2, 0); if (innerCircle.Height < centerBounds.Height) innerCircle.Inflate(0, (centerBounds.Height - innerCircle.Height) / 2); Point p = new Point(innerCircle.X + (int)((innerCircle.Width / 2) * Math.Cos((currentAngle + itemPieAngle / 2) * (Math.PI / 180))), innerCircle.Y + (int)((innerCircle.Height / 2) * Math.Sin((currentAngle + itemPieAngle / 2) * (Math.PI / 180)))); p.Offset(innerCircle.Width / 2, innerCircle.Height / 2); item.TopInternal = p.Y; item.LeftInternal = p.X; } if (item != null && AnyVisibleSubItems(item)) { Rectangle outerBounds = bounds; outerBounds.Inflate(_SubMenuEdgeItemSpacing, _SubMenuEdgeItemSpacing); GraphicsPath subPath = new GraphicsPath(); int expandAngle = currentAngle + 1; int expandPieAngle = itemPieAngle - 1; subPath.AddArc(outerBounds, expandAngle, expandPieAngle); subPath.AddArc(radialMenuBounds, expandAngle + expandPieAngle, -expandPieAngle); subPath.CloseAllFigures(); Rectangle signPathBounds = radialMenuBounds; signPathBounds.Inflate(-4, -4); Point p = new Point(signPathBounds.X + (int)((signPathBounds.Width / 2) * Math.Cos((currentAngle + itemPieAngle / 2) * (Math.PI / 180))), signPathBounds.Y + (int)((signPathBounds.Height / 2) * Math.Sin((currentAngle + itemPieAngle / 2) * (Math.PI / 180)))); p.Offset(signPathBounds.Width / 2, signPathBounds.Height / 2); GraphicsPath signPath = UIGraphics.GetTrianglePath(new Point(-6, -6), 12, eTriangleDirection.Right); Matrix m = new Matrix(); if (currentAngle + itemPieAngle / 2 != 0) { m.Rotate(currentAngle + itemPieAngle / 2); m.Translate(p.X, p.Y, MatrixOrder.Append); } else m.Translate(p.X, p.Y); signPath.Transform(m); _SubItemsInfo[i] = new RadialSubItemInfo(subPath, signPath, currentAngle, itemPieAngle); } currentAngle += itemPieAngle; item.Displayed = true; } } } finally { _RecalcSizeInProgress = false; } base.RecalcSize(); }
/// <summary> /// /// </summary> /// <param name="graphics"></param> /// <param name="section"></param> /// <param name="value"></param> public static void WriteString(Graphics graphics, BlockDefinition section, string value) { if (value == null || value == string.Empty) { return; } graphics.SmoothingMode = SmoothingMode.AntiAlias; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; value = System.Web.HttpUtility.HtmlDecode(value); GraphicsPath path = GetTextPath(section, value, graphics); if (section.location.flip) { using (Matrix matrix = new Matrix()) { matrix.Scale(-1, 1, MatrixOrder.Append); path.Transform(matrix); } using (Matrix matrix = new Matrix()) { float min = path.PathPoints.Min(p => p.X); matrix.Translate(((-min)+section.location.x), 0); path.Transform(matrix); } } if (section.location.rotate > 0) { int rotateMod = section.location.rotate % 360; if (!section.location.altrotate) { float centerX = 0; float centerY = 0; centerX = section.location.x; centerY = section.location.y; using (Matrix mat = new Matrix()) { mat.RotateAt(rotateMod, new PointF(centerX, centerY), MatrixOrder.Append); path.Transform(mat); } } else { using (Matrix matrix = new Matrix()) { matrix.Rotate(rotateMod, MatrixOrder.Append); path.Transform(matrix); } using (Matrix matrix = new Matrix()) { float minX = path.PathPoints.Min(p => p.X); float minY = path.PathPoints.Min(p => p.Y); matrix.Translate(((-minX) + section.location.x), ((-minY) + section.location.y)); path.Transform(matrix); } } } SolidBrush b = new SolidBrush(section.text.color); if (section.border.size > 0) { Pen p = new Pen(section.border.color, section.border.size); graphics.DrawPath(p, path); graphics.FillPath(b, path); p.Dispose(); } else { graphics.FillPath(b, path); } b.Dispose(); path.Dispose(); }
public void RotateTransform(float p) { System.Drawing.Drawing2D.Matrix M2 = new System.Drawing.Drawing2D.Matrix(); M2.Rotate(p); DoTransform(M2); }
public void RotateTransform(float angle, MatrixOrder order) { gradientTransform.Rotate(angle, order); changed = true; }