TransformPoints() private method

private TransformPoints ( List pts ) : void
pts List
return void
Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        //-----------------------------------------------------------------------------------------------
        public void DisplayGrids(Graphics g, Matrix2D trans_D2C, float zoom)         //g: Client窗口设备坐标系
        {
            g.Transform = trans_D2C;

            using (Pen pen = new Pen(Color.FromArgb(80, 180, 180, 180)))
            {
                for (int y = 0; y < num_Y_grids + 1; y++)
                {
                    g.DrawLine(pen, 0, y << 6, num_X_grids << 6, y << 6);
                }
                for (int x = 0; x < num_X_grids + 1; x++)
                {
                    g.DrawLine(pen, x << 6, 0, x << 6, num_Y_grids << 6);
                }
            }

            g.ResetTransform();

            using (Font font = new Font("Tahoma", 24 * zoom))
                using (Brush brush = new SolidBrush(Color.GreenYellow))
                {
                    PointF[] pos = { new PointF() };
                    for (int x = 0; x < num_X_grids; x++)
                    {
                        //坐标系级调整
                        pos[0].X = (x << 6) + 32;
                        pos[0].Y = 0;
                        trans_D2C.TransformPoints(pos);

                        //像素级调整
                        SizeF size = g.MeasureString(x.ToString(), font);
                        pos[0].X -= size.Width / 2;

                        g.DrawString(x.ToString(), font, brush, pos[0]);
                    }

                    for (int y = 0; y < num_Y_grids; y++)
                    {
                        //坐标系级调整
                        pos[0].X = 0;
                        pos[0].Y = (y << 6) + 32;
                        trans_D2C.TransformPoints(pos);

                        //像素级调整
                        SizeF size = g.MeasureString(y.ToString(), font);
                        pos[0].X -= size.Width;
                        pos[0].Y -= size.Height / 2;

                        g.DrawString(y.ToString(), font, brush, pos[0]);
                    }
                }
        }
Ejemplo n.º 3
0
        public static float[] GetGradientLine(GradientFill gf)
        {
            float[] result = new float[4];

            System.Drawing.PointF[] pts = GradientFill.GradientVexRect.SysPointFs();
            using (Draw2D.Matrix m = gf.Transform.SysMatrix())
            {
                m.TransformPoints(pts);
            }

            if (gf.GradientType == GradientType.Linear)
            {
                result[0] = pts[0].X;
                result[1] = pts[0].Y;
                result[2] = pts[1].X;
                result[3] = pts[1].Y;
            }
            else // radial is center to rightCenter edge
            {
                result[0] = pts[0].X + (pts[1].X - pts[0].X) / 2;
                result[1] = pts[0].Y + (pts[2].Y - pts[0].Y) / 2;
                result[2] = pts[1].X;
                result[3] = pts[1].Y + (pts[2].Y - pts[0].Y) / 2;
            }

            return(result);
        }
Ejemplo n.º 4
0
        partial void TransformPointsImpl(PointF [] pts)
        {
            var tmp = ToSDDPoints(pts);

            t.TransformPoints(tmp);
            Copy(tmp, pts);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// use matrix to transform point
 /// </summary>
 /// <param name="pts">contain the points to be transform</param>
 private void TransFormPoints(Point[] pts)
 {
     System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix(
         1, 0, 0, 1, this.openingPictureBox.Width / 2, this.openingPictureBox.Height / 2);
     matrix.Invert();
     matrix.TransformPoints(pts);
 }
Ejemplo n.º 6
0
        /// <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;
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Will convert the given array of Points from points in WorldSpace to points in PixelSpace
 /// </summary>
 /// <param name="targetPoints">Points to be converted</param>
 public void convertToPixelCoordinates(Point[] targetPoints)
 {
     if (targetPoints != null)
     {
         updateCameraTransform();
         cameraTransform.TransformPoints(targetPoints);
         if (drawBuffers != null)
         {
             for (int loop = 0; loop < targetPoints.Length; loop++)
             {
                 targetPoints[loop].X = (int)((float)targetPoints[loop].X * ((float)base.Width) / (float)drawBuffers[0].Width);
                 targetPoints[loop].Y = (int)((float)targetPoints[loop].Y * ((float)base.Height) / (float)drawBuffers[0].Height);
             }
         }
     }
 }
 public override void OnPaint(PaintEventArgs e, ViewPortData viewPortData)
 {
     Graphics graphics = e.Graphics;
     Bitmap memoryBitmap = viewPortData.MemoryBitmap;
     Rectangle rect = new Rectangle(Point.Empty, memoryBitmap.Size);
     graphics.FillRectangle(AmbientTheme.WorkspaceBackgroundBrush, rect);
     if (((base.parentView.RootDesigner != null) && (base.parentView.RootDesigner.Bounds.Width >= 0)) && (base.parentView.RootDesigner.Bounds.Height >= 0))
     {
         GraphicsContainer container = graphics.BeginContainer();
         Matrix matrix = new Matrix();
         matrix.Scale(viewPortData.Scaling.Width, viewPortData.Scaling.Height, MatrixOrder.Prepend);
         Point[] pts = new Point[] { viewPortData.LogicalViewPort.Location };
         matrix.TransformPoints(pts);
         matrix.Translate((float) (-pts[0].X + viewPortData.ShadowDepth.Width), (float) (-pts[0].Y + viewPortData.ShadowDepth.Height), MatrixOrder.Append);
         graphics.Transform = matrix;
         using (Region region = new Region(ActivityDesignerPaint.GetDesignerPath(base.parentView.RootDesigner, false)))
         {
             Region clip = graphics.Clip;
             graphics.Clip = region;
             AmbientTheme ambientTheme = WorkflowTheme.CurrentTheme.AmbientTheme;
             graphics.FillRectangle(Brushes.White, base.parentView.RootDesigner.Bounds);
             if (ambientTheme.WorkflowWatermarkImage != null)
             {
                 ActivityDesignerPaint.DrawImage(graphics, ambientTheme.WorkflowWatermarkImage, base.parentView.RootDesigner.Bounds, new Rectangle(Point.Empty, ambientTheme.WorkflowWatermarkImage.Size), ambientTheme.WatermarkAlignment, 0.25f, false);
             }
             graphics.Clip = clip;
         }
         graphics.EndContainer(container);
     }
 }
        /**
        For each pixel location in the new buffer P' (NewX, NewY), do:
            Find corresponding old location, P = W-1.P'
            Validate that this old location lie inside the original image boundary (i.e. 0 ≤ OldX < W,  0  ≤ Old Y < H). Otherwise, set the new empty pixel to 0 and continue to next location.
            If Validated, apply Bilinear Interpolation Algorithm to get the new pixel value, as follows:(Refer to above figure)
                */
        public BufferedImage apply_transformation_matrix_to_bitmap_or_buffer(Matrix _transformations_matrix, BufferedImage _src_img, int _new_width, int _new_height, TextBox _console)
        {
            BufferedImage ret = new BufferedImage(_new_width, _new_height);
            BilinearInterpolation obj_bi_lin_interpol = new BilinearInterpolation();
            for (int i = 0; i < _new_width; i++)
            {
                for (int j = 0; j < _new_height; j++)
                {
                    PointF[] points = {
                                          new PointF(i, j)
                                      };
                    _transformations_matrix.TransformPoints(points);
                    _console.Text += "P = (" + points[0].X + ", " + points[0].Y + ")";
                    _console.Text += Environment.NewLine;
                    _console.Text += "P' = (" + i + ", " + j + ")";
                    _console.Text += Environment.NewLine;

                    Color _color = Color.FromArgb(0);
                    if(points[0].X >= 0 && points[0].X < _src_img.width && points[0].Y >= 0 && points[0].Y < _src_img.height)
                        _color = obj_bi_lin_interpol.calculate(_src_img, points[0].X, points[0].Y);
                    ret.buffer[i, j] = _color;
                }
            }
            return ret;
        }
        /// <summary>
        /// Transform a single PointF object and return the result.
        /// </summary>
        /// <param name="mat"></param>
        /// <param name="p"></param>
        /// <returns></returns>
        public static PointF eTransformSinglePointF(this d2d.Matrix mat, PointF p)
        {
            var tmp = new PointF[] { p };

            mat.TransformPoints(tmp);
            return(tmp[0]);
        }
Ejemplo n.º 11
0
        public int GetSelectedPhrase(Point location, float scale, Point Translate)
        {
            System.Drawing.Drawing2D.Matrix m = new System.Drawing.Drawing2D.Matrix();
            //m.Translate(Translate.X, Translate.Y, MatrixOrder.Append);
            m.Scale(scale, scale, System.Drawing.Drawing2D.MatrixOrder.Append);

            System.Drawing.Drawing2D.Matrix mt = new System.Drawing.Drawing2D.Matrix();
            mt.Translate(Translate.X, Translate.Y, MatrixOrder.Append);
            mt.Scale(scale, scale, System.Drawing.Drawing2D.MatrixOrder.Append);

            //e.IGraphics.Transform = m;
            Point[] scaledps = new Point[] { new Point(28, 28) };
            for (int i = phrases.Count - 1; i >= 0; i--)
            {
                Point[] scaledp = new Point[] { new Point(phrases[i].position.X - 4, phrases[i].position.Y - 4) };

                //scaledp
                mt.TransformPoints(scaledp);
                m.TransformPoints(scaledps);
                if (Program.HitTest(location.X, location.Y,
                                    scaledp[0].X, scaledp[0].Y, scaledps[0].X, scaledps[0].Y))
                {
                    return(i);
                }
            }
            return(-1);
        }
Ejemplo n.º 12
0
		public override void Transform(Matrix matrix) {
			Point[] points = capturePoints.ToArray();

			matrix.TransformPoints(points);
			capturePoints.Clear();
			capturePoints.AddRange(points);
			RecalculatePath();
		}
 public BoundingBox Transform(System.Drawing.Drawing2D.Matrix matrix)
 {
     System.Drawing.PointF[] points = new System.Drawing.PointF[2];
     points[0] = new System.Drawing.PointF((float)XMin, (float)YMin);
     points[1] = new System.Drawing.PointF((float)XMax, (float)YMax);
     matrix.TransformPoints(points);
     return(new BoundingBox(points[0].X, points[1].X, points[0].Y, points[1].Y));
 }
Ejemplo n.º 14
0
 /// <summary>Expands the triangle by the specified length and width, keepings its center position constant.</summary>
 /// <param name="width">The number of units to add to the width.</param>
 /// <param name="height">The number of units to add to the height.</param>
 public void Scale(float width, float height)
 {
     using (System.Drawing.Drawing2D.Matrix trans = new System.Drawing.Drawing2D.Matrix())
     {
         trans.Scale(width, height);
         trans.TransformPoints(new PointF[] { this.PointA, this.PointB, this.PointC });
     }
 }
Ejemplo n.º 15
0
        private void drawGraphLine(Graphics graphics, PointF[] points, Pen pen, float yScale, float xScale)
        {
            var matrix = new Matrix();
            matrix.Scale(xScale, yScale);
            matrix.Translate(5, 5, MatrixOrder.Append);
            matrix.TransformPoints(points);

            graphics.DrawLines(pen, points);
        }
Ejemplo n.º 16
0
 //***************************************************************************
 // Static Methods
 //
 public static TriangleF Rotate(TriangleF tri, float degrees, PointF center)
 {
     PointF[] p = new PointF[] { new PointF(tri.PointA.X, tri.PointA.Y), new PointF(tri.PointB.X, tri.PointB.Y), new PointF(tri.PointC.X, tri.PointC.Y) };
     using (System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix())
     {
         mat.RotateAt(degrees, center);
         mat.TransformPoints(p);
     }
     return(new TriangleF(p[0], p[1], p[2]));
 }
Ejemplo n.º 17
0
        public void EraseHighlight(Graphics g, Matrix xformWorldToPixel, Brush eraseBrush)
        {
            PointF[] pts = { new PointF(rect.Left, rect.Bottom), new PointF(rect.Right, rect.Top) };
            xformWorldToPixel.TransformPoints(pts);
            RectangleF rectPixel = RectangleF.FromLTRB(pts[0].X, pts[0].Y, pts[1].X, pts[1].Y);

            rectPixel.Inflate(penWidth / 2F, penWidth / 2F);
            Rectangle r = Util.Round(rectPixel);
            g.FillRectangle(eraseBrush, r);
        }
Ejemplo n.º 18
0
 public void DrawHighlight(Graphics g, Matrix xformWorldToPixel)
 {
     using (Pen redPen = new Pen(Color.Red, penWidth))
     using (Brush blueBrush = new HatchBrush(HatchStyle.Percent25, Color.DarkBlue, Color.Transparent)) {
         PointF[] pts = { new PointF(rect.Left, rect.Bottom), new PointF(rect.Right, rect.Top) };
         xformWorldToPixel.TransformPoints(pts);
         RectangleF rectPixel = RectangleF.FromLTRB(pts[0].X, pts[0].Y, pts[1].X, pts[1].Y);
         g.FillRectangle(blueBrush, rectPixel.X, rectPixel.Y, rectPixel.Width, rectPixel.Height);
         g.DrawRectangle(redPen, rectPixel.X, rectPixel.Y, rectPixel.Width, rectPixel.Height);
     }
 }
Ejemplo n.º 19
0
        public void Paint(Matrix2D T, double x0, double x1, Graphics G)
        {
            Pen             pen    = Pen;
            List <PointF[]> points = Evaluate(x0, x1);

            foreach (PointF[] i in points)
            {
                T.TransformPoints(i);
                G.DrawLines(pen, i);
            }
        }
Ejemplo n.º 20
0
 protected void Transform(Matrix matrixValueToScreen, bool isLog, PointF[] points)
 {
     if (isLog)
     {
         for (int i = 0; i < points.Length; i++)
         {
             points[i] = new PointF(points[i].X, points[i].Y < 0 ? (float)-Math.Log10(-points[i].Y + 1) : (float)Math.Log10(points[i].Y + 1));
         }
     }
     matrixValueToScreen.TransformPoints(points);
 }
Ejemplo n.º 21
0
        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;
        }
Ejemplo n.º 22
0
        public PointF PointToScreenSpace(PointF pntIn)
        {
            System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix();

            PointF[] tempPoints = new PointF[1];
            tempPoints[0] = new PointF(pntIn.X, pntIn.Y);

            mat.RotateAt(selectionSet[0].RotationAngle, new PointF((float)(selectionSet[0].X), (float)(selectionSet[0].Y)));
            mat.TransformPoints(tempPoints);
            return(tempPoints[0]);
        }
 /// <summary>
 /// Applies the geometric transform represented by this System.Drawing.Drawing2D.Matrix
 /// to a specified array of Opentk.Vector2
 /// </summary>
 /// <param name="mat"></param>
 /// <param name="vecs"></param>
 public static void eTransformVector2(this d2d.Matrix mat, tk.Vector2[] vecs)
 {
     PointF[] tmp = vecs.Select(vec => new PointF(vec.X, vec.Y)).ToArray();
     mat.TransformPoints(tmp);
     // set them equal this way we dont mess up if other
     // objects kept pointers to some vector and we just override it
     for (int i = 0; i < vecs.Length; i++)
     {
         vecs[i].X = tmp[i].X;
         vecs[i].Y = tmp[i].Y;
     }
 }
Ejemplo n.º 24
0
        public void ChangeDirection(Point pt, Size sz)
        {
            float angle = 90;
            Matrix matrix = new Matrix();
            matrix.RotateAt(angle, pt);

            int n = pointList.Count;
            Point[] points = new Point[n];
            pointList.CopyTo(points);
            matrix.TransformPoints(points);

            for (int i = 0; i < n; i++)
            {
                Rectangle rc = new Rectangle(0, 0, sz.Width, sz.Height);
                if (!rc.Contains(points[i]))
                {
                    if (points[n - 2].X == points[n - 1].X)
                    {
                        int height = Math.Abs(points[1].Y - points[0].Y);
                        if (points[i].Y < 0)
                        {
                            points[0].Y = 1;
                            points[1].Y = points[0].Y + height;
                        }
                        else if (points[i].Y > sz.Height)
                        {
                            points[0].Y = sz.Height - 2;
                            points[1].Y = points[0].Y - height;
                        }
                    }
                    else if (points[n - 2].Y == points[n - 1].Y)
                    {
                        int width = Math.Abs(points[1].X - points[0].X);
                        if (points[i].X < 0)
                        {
                            points[0].X = 1;
                            points[1].X = points[0].X + width;
                        }
                        else if (points[i].X > sz.Width)
                        {
                            points[0].X = sz.Width - 2;
                            points[1].X = points[0].X - width;
                        }
                    }
                    pointList.Clear();
                    pointList.AddRange(points);
                    return;
                }
            }
            pointList.Clear();
            pointList.AddRange(points);
        }
Ejemplo n.º 25
0
 /// <summary>
 /// фун для матричного преобразования в даном случае увеличения
 /// </summary>
 /// <param name="temp"></param>
 public void myMatrixTransformScale(ref LittleShape2 temp)
 {
     System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix();
     System.Drawing.Drawing2D.Matrix test   = new System.Drawing.Drawing2D.Matrix(1, 0, 0, 1, 0, 0);
     // трансформация  из double[,] в pointF[]
     PointF[] arr = temp.getPointF(rank);
     // увеличение
     matrix.Scale(50, 50);
     // применение увеличения
     matrix.TransformPoints(arr);
     // уже увеличеная фигура (точки)
     temp.setPointF(arr);
 }
Ejemplo n.º 26
0
        public static PointF[] RectToPolygon(RectangleF r, double orientation)
        {
            PointF center = new PointF(r.X + r.Width / 2.0F, r.Y + r.Height / 2.0F);
            PointF TL     = new PointF(r.Left, r.Top);
            PointF TR     = new PointF(r.Right, r.Top);
            PointF BL     = new PointF(r.Left, r.Bottom);
            PointF BR     = new PointF(r.Right, r.Bottom);

            PointF[] points = new PointF[] { BL, TL, TR, BR, BL };
            System.Drawing.Drawing2D.Matrix m = new System.Drawing.Drawing2D.Matrix();
            m.RotateAt((float)orientation, center);
            m.TransformPoints(points);
            return(points);
        }
        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);
        }
Ejemplo n.º 28
0
        // Transform a rectangle with a transform, and return the new rectangle that bounds the corners of the transformed one.
        public static RectangleF BoundsOfTransformedRectangle(RectangleF rect, Matrix transform)
        {
            PointF[] corners = { new PointF(rect.Left, rect.Top),    new PointF(rect.Right, rect.Top),
                             new PointF(rect.Left, rect.Bottom), new PointF(rect.Right, rect.Bottom) };
            transform.TransformPoints(corners);
            float minX = float.MaxValue, maxX = float.MinValue, minY = float.MaxValue, maxY = float.MinValue;
            for (int i = 0; i < corners.Length; ++i) {
                if (corners[i].X < minX)   minX = corners[i].X;
                if (corners[i].X > maxX)   maxX = corners[i].X;
                if (corners[i].Y < minY)   minY = corners[i].Y;
                if (corners[i].Y > maxY)   maxY = corners[i].Y;
            }

            return new RectangleF(minX, minY, maxX - minX, maxY - minY);
        }
Ejemplo n.º 29
0
        public static Point[] MinePolygonPoints(int offsetX, int offsetY, float size)
        {
            var points = new Point[4] {
                new Point(-1, -1),
                new Point(-1, 1),
                new Point(1, 1),
                new Point(1, -1)
            };

            var matrix = new Matrix();
            matrix.Translate(offsetX, offsetY);
            matrix.Scale(size, size);
            matrix.TransformPoints(points);
            return points;
        }
Ejemplo n.º 30
0
        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);
        }
Ejemplo n.º 31
0
        //-----------------------------------------------------------------------------------------------
        public void DisplayWaypoints(Graphics g, Matrix2D trans_D2C, Waypoint w)         //g: Client窗口设备坐标系
        {
            if (w != null)
            {
                g.SmoothingMode = SmoothingMode.HighQuality;

                using (Pen pen = new Pen(Color.Yellow, 3f))
                    using (Brush brush = new SolidBrush(Color.Yellow))
                    {
                        pen.EndCap = LineCap.ArrowAnchor;                 //很酷...

                        Waypoint c = w;
                        Waypoint p = w.parent;

                        //绘制路径
                        while (p != null)
                        {
                            PointF[] pos = { new PointF(p.fp.x, p.fp.y), new PointF(c.fp.x, c.fp.y) };
                            trans_D2C.TransformPoints(pos);

                            //路径起点为一个圆点
                            if (p.parent == null)
                            {
                                pen.StartCap = LineCap.RoundAnchor;
                            }

                            g.DrawLine(pen, pos[0], pos[1]);

                            c = p;
                            p = c.parent;
                        }

                        //绘制位点
                        //g.Transform = trans_D2C;

                        //c = w;
                        //do
                        //{
                        //    g.FillRectangle(brush, c.fp.x - 5, c.fp.y - 5, 10, 10);
                        //    c = c.parent;
                        //} while (c != null);

                        //g.ResetTransform();
                    }

                g.SmoothingMode = SmoothingMode.Default;
            }
        }
Ejemplo n.º 32
0
    /// <summary>
    /// Draw loops on graphics with the specified
    /// transform and graphics attributes.
    /// </summary>
    static void DrawLoopsOnGraphics(
      Graphics graphics,
      List<Point[]> loops,
      Matrix transform )
    {
      foreach( Point[] loop in loops )
      {
        GraphicsPath path = new GraphicsPath();

        transform.TransformPoints( loop );

        path.AddLines( loop );
        
        graphics.DrawPath( Pen, path );
      }
    }
Ejemplo n.º 33
0
        internal PointF [] GetMedianeEnclosingRect(float x1, float y1, float x2, float y2, float rotateAngle)
        {
            float  width      = x2 - x1;
            float  height     = y2 - y1;
            PointF rectCenter = new PointF(x1 + width / 2, y1 + height / 2);
            float  gradLen    = width * Math.Abs((float)Math.Cos(rotateAngle * Math.PI / 180)) +
                                height * Math.Abs((float)Math.Sin(rotateAngle * Math.PI / 180));

            PointF [] points = new PointF [] { new PointF(rectCenter.X - gradLen / 2, rectCenter.Y),
                                               new PointF(rectCenter.X + gradLen / 2, rectCenter.Y) };

            Matrix mx = new Matrix();

            mx.RotateAt((float)rotateAngle, rectCenter);
            mx.TransformPoints(points);
            return(points);
        }
Ejemplo n.º 34
0
        // http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_shadings/dq_shadings.html#//apple_ref/doc/uid/TP30001066-CH207-BBCECJBF
        internal override void Setup(Graphics graphics, bool fill)
        {
            CGContext context = graphics.context;

            // if fill is false then we are being called from a Pen stroke so
            // we need to setup a transparency layer
            // http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_shadings/dq_shadings.html#//apple_ref/doc/uid/TP30001066-CH207-BBCECJBF
            if (!fill)
            {
                context.BeginTransparencyLayer();
                hasTransparencyLayer = true;
                // Make sure we set a color here so that the gradient shows up
                graphics.lastBrushColor = Color.Black;
                return;
            }

            // if this is the same as the last that was set and no changes have been made
            // then return.
            if (graphics.LastBrush != this || changed)
            {
                //setupShadingColors();
            }

            // Transform the start and end points using the brush's transformation matrix
            gradientTransform.TransformPoints(pathPoints);

            RasterizePolygon(context, centerPoint, pathPoints, surroundColors, centerColor);

            // If we are in a Transparency layer then we need to end the transparency
            if (hasTransparencyLayer)
            {
                context.EndTransparencyLayer();
            }

            changed = false;

            graphics.LastBrush = this;
            // We will reset the last pen so that it can be setup again
            // so that we do not loose the settings after stroking the gradient
            // not sure where the setting are being reset so this may be a hack
            // and things are just not being restored correctly.
            graphics.LastPen = null;
            // I am setting this to be used for Text coloring in DrawString
            graphics.lastBrushColor = surroundColors[surroundColors.Length - 1];
        }
Ejemplo n.º 35
0
        public static Icon TankIcon()
        {
            var bitmap = new Bitmap(32, 32);
            using (var g = Graphics.FromImage(bitmap))
            {
                var points = TankPolygonPoints(16, 16, 180, 5);
                var matrix = new Matrix();
                matrix.Scale(1.5f, 1.5f);
                matrix.Translate(-5, -5);
                matrix.TransformPoints(points);

                var pen = new Pen(Color.Black);
                g.DrawPolygon(pen, points);
                g.FillPolygon(pen.Brush, points);
                pen.Dispose();
            }
            return Icon.FromHandle(bitmap.GetHicon());
        }
Ejemplo n.º 36
0
        //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();
        }
Ejemplo n.º 37
0
        /// <summary>
        /// Gets a rectangular bounding box that encompasses the specified rectangle after the specified transformation has
        /// been applied.
        /// </summary>
        /// <param name="rect">The rectangle whose transformation is considered</param>
        /// <param name="transform">The transformation considered</param>
        /// <returns>A bounding box that encompasses the specified the specified rectangle after the specified transformation
        /// has been applied</returns>
        public static Rectangle Transform(this Rectangle rect, Matrix transform)
        {
            //Transform each corner of the rectangle
            Point[] corners = {
                new Point(rect.Left, rect.Top),
                new Point(rect.Right, rect.Top),
                new Point(rect.Left, rect.Bottom),
                new Point(rect.Right, rect.Bottom) };

            transform.TransformPoints(corners);

            // Fit a bounding box on the transformed rectangle
            int x1 = (from c in corners select c.X).Min();
            int x2 = (from c in corners select c.X).Max();
            int y1 = (from c in corners select c.Y).Min();
            int y2 = (from c in corners select c.Y).Max();

            return new Rectangle(x1, y1, x2 - x1, y2 - y1);
        }
Ejemplo n.º 38
0
        /// <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));
        }
Ejemplo n.º 39
0
        public void DisplayLOS(Graphics g, Matrix2D trans_D2C, List <FPoint> losw)        //g: Client窗口设备坐标系
        {
            g.ResetTransform();
            g.SmoothingMode = SmoothingMode.HighQuality;

            if (losw == null)
            {
                return;
            }
            if (losw.Count == 0)
            {
                return;
            }

            PointF[] pos = new PointF[losw.Count];
            for (int i = 0; i < losw.Count; i++)
            {
                pos[i]   = new PointF();
                pos[i].X = losw[i].x;
                pos[i].Y = losw[i].y;
            }

            trans_D2C.TransformPoints(pos);

            using (Pen line_pen = new Pen(Color.DeepPink, 3F))
                using (Pen dot_pen = new Pen(Color.Yellow, 2f))
                {
                    line_pen.EndCap = LineCap.ArrowAnchor;
                    for (int i = 1; i < losw.Count; i++)
                    {
                        g.DrawLine(line_pen, pos[i - 1], pos[i]);
                    }

                    for (int i = 0; i < losw.Count; i++)
                    {
                        g.DrawLine(dot_pen, pos[i].X - 3, pos[i].Y - 3, pos[i].X + 3, pos[i].Y + 3);
                        g.DrawLine(dot_pen, pos[i].X - 3, pos[i].Y + 3, pos[i].X + 3, pos[i].Y - 3);
                    }
                }
        }
Ejemplo n.º 40
0
 public void TransformPoints(Point[] pts)
 {
     Drawing2D.Matrix m = new Drawing2D.Matrix
                          (
         this.ScaleX,
         this.Rotate0,
         this.Rotate1,
         this.ScaleY,
         this.TranslateX,
         this.TranslateY
                          );
     System.Drawing.PointF[] dpts = new System.Drawing.PointF[pts.Length];
     for (int i = 0; i < pts.Length; i++)
     {
         dpts[i] = new System.Drawing.PointF(pts[i].X, pts[i].Y);
     }
     m.TransformPoints(dpts);
     for (int i = 0; i < pts.Length; i++)
     {
         pts[i] = new Point(dpts[i].X, dpts[i].Y);
     }
 }
Ejemplo n.º 41
0
        internal PointF [] GetMedianeEnclosingRect(float x1, float y1, float x2, float y2, bool forwardDiagonal)
        {
            float  width       = x2 - x1;
            float  height      = y2 - y1;
            PointF rectCenter  = new PointF(x1 + width / 2, y1 + height / 2);
            float  rotateAngle = (float)Math.Atan2(width, height);
            float  gradLen     = width * (float)Math.Cos(rotateAngle);

            if (!forwardDiagonal)
            {
                rotateAngle = -rotateAngle;
            }

            PointF [] points = new PointF [] { new PointF(rectCenter.X - gradLen, rectCenter.Y),
                                               new PointF(rectCenter.X + gradLen, rectCenter.Y) };

            Matrix mx = new Matrix();

            mx.RotateAt((float)rotateAngle * (float)(180 / Math.PI), rectCenter);
            mx.TransformPoints(points);
            return(points);
        }
 public override void OnPaint(PaintEventArgs e, ViewPortData viewPortData)
 {
     base.OnPaint(e, viewPortData);
     Graphics graphics = e.Graphics;
     if (((base.parentView.RootDesigner != null) && (base.parentView.RootDesigner.Bounds.Width >= 0)) && (base.parentView.RootDesigner.Bounds.Height >= 0))
     {
         GraphicsContainer container = graphics.BeginContainer();
         Matrix matrix = new Matrix();
         matrix.Scale(viewPortData.Scaling.Width, viewPortData.Scaling.Height, MatrixOrder.Prepend);
         Point[] pts = new Point[] { viewPortData.LogicalViewPort.Location };
         matrix.TransformPoints(pts);
         matrix.Translate((float) (-pts[0].X + viewPortData.ShadowDepth.Width), (float) (-pts[0].Y + viewPortData.ShadowDepth.Height), MatrixOrder.Append);
         graphics.Transform = matrix;
         Rectangle bounds = base.parentView.RootDesigner.Bounds;
         graphics.ExcludeClip(bounds);
         bounds.Inflate(DefaultWorkflowLayout.Separator.Width / 2, DefaultWorkflowLayout.Separator.Height / 2);
         ActivityDesignerPaint.DrawDropShadow(graphics, bounds, AmbientTheme.WorkflowBorderPen.Color, 4, LightSourcePosition.Top | LightSourcePosition.Left, 0.2f, false);
         graphics.FillRectangle(WorkflowTheme.CurrentTheme.AmbientTheme.BackgroundBrush, bounds);
         graphics.DrawRectangle(AmbientTheme.WorkflowBorderPen, bounds);
         graphics.EndContainer(container);
     }
 }
Ejemplo n.º 43
0
        // Function to Fire the Arrow
        private void FireArrow()
        {
            // If the Player is currently Aiming
            if (meTargetPracticeState == ETargetPracticeGameStates.Aiming)
            {
                // Switch to Shooting the Arrow
                meTargetPracticeState = ETargetPracticeGameStates.FiredArrow;

                // Set the Arrows Velocity based on the current Pitch and Amplitude of the Players voice

                // Find the Middle Point of the Bow And Arrow to Rotate around
                PointF sMiddlePoint = new Point();
                sMiddlePoint.X = mrBOW_AND_ARROW_POSITION.X + (mrBOW_AND_ARROW_POSITION.Width / 2.0f);
                sMiddlePoint.Y = mrBOW_AND_ARROW_POSITION.Y + (mrBOW_AND_ARROW_POSITION.Height / 2.0f);

                // Rotate the Bow And Arrow by the specified Bow And Arrow Rotation Amount
                System.Drawing.Drawing2D.Matrix sRotationMatrix = new System.Drawing.Drawing2D.Matrix(1, 0, 0, 1, 0, 0);
                sRotationMatrix.RotateAt(miBowAndArrowRotation, sMiddlePoint);
                PointF[] sPoint = new PointF[1];
                sPoint[0].X = sMiddlePoint.X + 1;
                sPoint[0].Y = sMiddlePoint.Y;
                sRotationMatrix.TransformPoints(sPoint);

                // Set the Arrows initial Direction to travel
                mcArrowVelocity.X = sPoint[0].X - sMiddlePoint.X;
                mcArrowVelocity.Y = sPoint[0].Y - sMiddlePoint.Y;
                mcArrowVelocity.Normalize();

                // Set the Arrows initial speed
                mcArrowVelocity   *= (mfUnitBowAndArrowPower * 300.0f);
                mcArrowVelocity.X += 100.0f;

                // Set the Arrows Rotation to be the same as the Bow And Arrow initially
                miArrowRotation = miBowAndArrowRotation;

                // Play the Fire Arrow sound
                CFMOD.PlaySound(msSoundFire, false);
            }
        }
Ejemplo n.º 44
0
        public int GetSelectedTimeLine(Point location, float scale, Point Translate)
        {
            System.Drawing.Drawing2D.Matrix m = new System.Drawing.Drawing2D.Matrix();
            m.Scale(scale, scale, System.Drawing.Drawing2D.MatrixOrder.Append);
            //e.IGraphics.Transform = m;
            System.Drawing.Drawing2D.Matrix mt = new System.Drawing.Drawing2D.Matrix();
            mt.Translate(Translate.X, Translate.Y, MatrixOrder.Append);
            mt.Scale(scale, scale, System.Drawing.Drawing2D.MatrixOrder.Append);

            for (int i = 0; i < timelines.Count; i++)
            {
                Point[] scaledp  = new Point[] { new Point(timelines[i]._dragtag.X - 4, timelines[i]._dragtag.Y - 4) };
                Point[] scaledps = new Point[] { new Point(19, 19) };
                //scaledp
                mt.TransformPoints(scaledp);
                m.TransformPoints(scaledps);
                if (Program.HitTest(location.X, location.Y,
                                    scaledp[0].X, scaledp[0].Y, scaledps[0].X, scaledps[0].Y))
                {
                    return(i);
                }
            }
            return(-1);
        }
        /**
        For each pixel location in the new buffer P' (NewX, NewY), do:
            Find corresponding old location, P = W-1.P'
            Validate that this old location lie inside the original image boundary (i.e. 0 ≤ OldX < W,  0  ≤ Old Y < H). Otherwise, set the new empty pixel to 0 and continue to next location.
            If Validated, apply Bilinear Interpolation Algorithm to get the new pixel value, as follows:(Refer to above figure)
                */
        public bufferedLockBitmap apply_transformation_matrix_to_bitmap_or_buffer(Matrix _transformations_matrix, bufferedLockBitmap _src_img, int _new_width, int _new_height)
        {
            Bitmap temp = new Bitmap(_new_width, _new_height);
            bufferedLockBitmap ret = new bufferedLockBitmap(temp);
            ret.LockBits();
            BilinearInterpolation obj_bi_lin_interpol = new BilinearInterpolation();
            for (int i = 0; i < _new_width; i++)
            {
                for (int j = 0; j < _new_height; j++)
                {
                    PointF[] points = {
                                          new PointF(i, j)
                                      };
                    _transformations_matrix.TransformPoints(points);

                    Color _color = Color.FromArgb(0);
                    if (points[0].X >= 0 && points[0].X < _src_img.source.Width && points[0].Y >= 0 && points[0].Y < _src_img.source.Height)
                        _color = obj_bi_lin_interpol.calculate(_src_img, points[0].X, points[0].Y, _new_width, _new_height);
                    ret.SetPixel(i, j, _color);
                }
            }
            ret.UnlockBits();
            return ret;
        }
Ejemplo n.º 46
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="gfx"></param>
        /// <param name="line"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="db"></param>
        /// <param name="r"></param>
        public void Draw(object gfx, XLine line, double dx, double dy, ImmutableArray<ShapeProperty> db, Record r)
        {
            var _gfx = gfx as Graphics;

            Brush fillLine = ToSolidBrush(line.Style.Fill);
            Pen strokeLine = ToPen(line.Style, _scaleToPage);

            Brush fillStartArrow = ToSolidBrush(line.Style.StartArrowStyle.Fill);
            Pen strokeStartArrow = ToPen(line.Style.StartArrowStyle, _scaleToPage);

            Brush fillEndArrow = ToSolidBrush(line.Style.EndArrowStyle.Fill);
            Pen strokeEndArrow = ToPen(line.Style.EndArrowStyle, _scaleToPage);

            double _x1 = line.Start.X + dx;
            double _y1 = line.Start.Y + dy;
            double _x2 = line.End.X + dx;
            double _y2 = line.End.Y + dy;

            XLine.SetMaxLength(line, ref _x1, ref _y1, ref _x2, ref _y2);

            float x1 = _scaleToPage(_x1);
            float y1 = _scaleToPage(_y1);
            float x2 = _scaleToPage(_x2);
            float y2 = _scaleToPage(_y2);

            var sas = line.Style.StartArrowStyle;
            var eas = line.Style.EndArrowStyle;
            float a1 = (float)(Math.Atan2(y1 - y2, x1 - x2) * 180.0 / Math.PI);
            float a2 = (float)(Math.Atan2(y2 - y1, x2 - x1) * 180.0 / Math.PI);

            var t1 = new Matrix();
            var c1 = new PointF(x1, y1);
            t1.RotateAt(a1, c1);

            var t2 = new Matrix();
            var c2 = new PointF(x2, y2);
            t2.RotateAt(a2, c2);

            PointF pt1;
            PointF pt2;

            double radiusX1 = sas.RadiusX;
            double radiusY1 = sas.RadiusY;
            double sizeX1 = 2.0 * radiusX1;
            double sizeY1 = 2.0 * radiusY1;

            switch (sas.ArrowType)
            {
                default:
                case ArrowType.None:
                    {
                        pt1 = new PointF(x1, y1);
                    }
                    break;
                case ArrowType.Rectangle:
                    {
                        var pts = new PointF[] { new PointF(x1 - (float)sizeX1, y1) };
                        t1.TransformPoints(pts);
                        pt1 = pts[0];
                        var rect = new Rect2(x1 - sizeX1, y1 - radiusY1, sizeX1, sizeY1);
                        var gs = _gfx.Save();
                        _gfx.MultiplyTransform(t1);
                        DrawRectangleInternal(_gfx, fillStartArrow, strokeStartArrow, sas.IsStroked, sas.IsFilled, ref rect);
                        _gfx.Restore(gs);
                    }
                    break;
                case ArrowType.Ellipse:
                    {
                        var pts = new PointF[] { new PointF(x1 - (float)sizeX1, y1) };
                        t1.TransformPoints(pts);
                        pt1 = pts[0];
                        var gs = _gfx.Save();
                        _gfx.MultiplyTransform(t1);
                        var rect = new Rect2(x1 - sizeX1, y1 - radiusY1, sizeX1, sizeY1);
                        DrawEllipseInternal(_gfx, fillStartArrow, strokeStartArrow, sas.IsStroked, sas.IsFilled, ref rect);
                        _gfx.Restore(gs);
                    }
                    break;
                case ArrowType.Arrow:
                    {
                        var pts = new PointF[]
                        {
                            new PointF(x1, y1),
                            new PointF(x1 - (float)sizeX1, y1 + (float)sizeY1),
                            new PointF(x1, y1),
                            new PointF(x1 - (float)sizeX1, y1 - (float)sizeY1),
                            new PointF(x1, y1)
                        };
                        t1.TransformPoints(pts);
                        pt1 = pts[0];
                        var p11 = pts[1];
                        var p21 = pts[2];
                        var p12 = pts[3];
                        var p22 = pts[4];
                        DrawLineInternal(_gfx, strokeStartArrow, sas.IsStroked, ref p11, ref p21);
                        DrawLineInternal(_gfx, strokeStartArrow, sas.IsStroked, ref p12, ref p22);
                    }
                    break;
            }

            double radiusX2 = eas.RadiusX;
            double radiusY2 = eas.RadiusY;
            double sizeX2 = 2.0 * radiusX2;
            double sizeY2 = 2.0 * radiusY2;

            switch (eas.ArrowType)
            {
                default:
                case ArrowType.None:
                    {
                        pt2 = new PointF(x2, y2);
                    }
                    break;
                case ArrowType.Rectangle:
                    {
                        var pts = new PointF[] { new PointF(x2 - (float)sizeX2, y2) };
                        t2.TransformPoints(pts);
                        pt2 = pts[0];
                        var rect = new Rect2(x2 - sizeX2, y2 - radiusY2, sizeX2, sizeY2);
                        var gs = _gfx.Save();
                        _gfx.MultiplyTransform(t2);
                        DrawRectangleInternal(_gfx, fillEndArrow, strokeEndArrow, eas.IsStroked, eas.IsFilled, ref rect);
                        _gfx.Restore(gs);
                    }
                    break;
                case ArrowType.Ellipse:
                    {
                        var pts = new PointF[] { new PointF(x2 - (float)sizeX2, y2) };
                        t2.TransformPoints(pts);
                        pt2 = pts[0];
                        var gs = _gfx.Save();
                        _gfx.MultiplyTransform(t2);
                        var rect = new Rect2(x2 - sizeX2, y2 - radiusY2, sizeX2, sizeY2);
                        DrawEllipseInternal(_gfx, fillEndArrow, strokeEndArrow, eas.IsStroked, eas.IsFilled, ref rect);
                        _gfx.Restore(gs);
                    }
                    break;
                case ArrowType.Arrow:
                    {
                        var pts = new PointF[]
                        {
                            new PointF(x2, y2),
                            new PointF(x2 - (float)sizeX2, y2 + (float)sizeY2),
                            new PointF(x2, y2),
                            new PointF(x2 - (float)sizeX2, y2 - (float)sizeY2),
                            new PointF(x2, y2)
                        };
                        t2.TransformPoints(pts);
                        pt2 = pts[0];
                        var p11 = pts[1];
                        var p21 = pts[2];
                        var p12 = pts[3];
                        var p22 = pts[4];
                        DrawLineInternal(_gfx, strokeEndArrow, eas.IsStroked, ref p11, ref p21);
                        DrawLineInternal(_gfx, strokeEndArrow, eas.IsStroked, ref p12, ref p22);
                    }
                    break;
            }

            _gfx.DrawLine(strokeLine, pt1, pt2);

            fillLine.Dispose();
            strokeLine.Dispose();

            fillStartArrow.Dispose();
            strokeStartArrow.Dispose();

            fillEndArrow.Dispose();
            strokeEndArrow.Dispose();
        }
Ejemplo n.º 47
0
        public virtual bool HitTest(PointF pntTest)
        {
            System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix();
            mat.RotateAt(-RotationAngle, new PointF(X , Y ));

            PointF[] tempPoints = new PointF[1];

            tempPoints[0].X = pntTest.X;
            tempPoints[0].Y = pntTest.Y;

            mat.TransformPoints( tempPoints);

            RectangleF rect = new RectangleF((X-(Width/2)), (Y-(Height/2)), Width, Height);
            if (rect.Contains(tempPoints[0]))
            {
                return true;
            }

            return false;
        }
Ejemplo n.º 48
0
        public static void NormalizePoints2(Point[] points, Rectangle rectangle, Rectangle needRectangle)
        {
            if (rectangle.Height == 0 || rectangle.Width == 0)
                return;

            float k1 = 1f * needRectangle.Width / rectangle.Width;
            float k2 = 1f * needRectangle.Height / rectangle.Height;
            float k = Math.Min(k1, k2);

            Matrix m = new Matrix();
            m.Scale(k, k);
            m.Translate(needRectangle.X / k - rectangle.X, needRectangle.Y / k - rectangle.Y);
            m.TransformPoints(points);
        }
Ejemplo n.º 49
0
		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);
		}
Ejemplo n.º 50
0
        public void TransformPoints(CoordinateSpace destSpace, CoordinateSpace srcSpace, Point [] pts)
        {
            if (pts == null)
                throw new ArgumentNullException ("pts");

            Matrix transform = new Matrix();
            ConversionHelpers.GetGraphicsTransform (this, destSpace, srcSpace, ref transform);
            transform.TransformPoints (pts);
        }
Ejemplo n.º 51
0
        public static void NormalizePoints(Point[] points, Rectangle rectangle)
        {
            if (rectangle.Height == 0 || rectangle.Width == 0)
                return;

            Matrix m = new Matrix();
            m.Translate(rectangle.Center().X, rectangle.Center().Y);

            if (rectangle.Width > rectangle.Height)
                m.Scale(1, 1f * rectangle.Width / rectangle.Height);
            else
                m.Scale(1f * rectangle.Height / rectangle.Width, 1);

            m.Translate(-rectangle.Center().X, -rectangle.Center().Y);
            m.TransformPoints(points);
        }
 public bool MouseMove(MouseEventArgs e, Matrix transform)
 {
     Point[] pp = new Point[] { e.Location };
     transform.TransformPoints(pp);
     Point location = pp[0];
     
     if (state == State.DRAGGEDINSIDE)
     {
         lock (dragged)
         {
             if ((Control.ModifierKeys & Keys.Control) != 0)
             {
                 if (((DateTime.Now - lastCtrlTime).Milliseconds > 200) || ((lastCtrlLocation.X - location.X) * (lastCtrlLocation.X - location.X) + (lastCtrlLocation.Y - location.Y) * (lastCtrlLocation.Y - location.Y) > 100))
                 {
                     dragged.SetPosition(location, true);
                     lastCtrlTime = DateTime.Now;
                     lastCtrlLocation = location;
                 }
             }
             else
             {
                 dragged.SetPosition(location, false);
             }
         }
         TakeSample();                
         return true;
     }
     else if (state == State.DRAGGEDOUTSIDE)
     {
         dragged.SetSecondParameterAgainstPosition(location);
         TakeSample();                
         return true;
     }
     else if ((state == State.NONE) && (e.Button == MouseButtons.None))
     {
         IDragable inside = getInsideDragabe(location);
         IDragable outside = getOutsideDragabe(location);
         if (inside != null)
         {
             if (inselected != inside)
             {
                 graphicControl.Cursor = Cursors.Hand;
                 if (inselected != null) inselected.SetSelectedState(0, 0);
                 inselected = inside;
                 outselected = null;
                 inselected.SetSelectedState(1, 0);                                                
             }
             return true;
         }
         else if (outside != null)
         {
             if (outselected != outside)
             {
                 graphicControl.Cursor = Cursors.NoMove2D;
                 if (outselected != null) outselected.SetSelectedState(0, 0);
                 outselected = outside;
                 inselected = null;
                 outselected.SetSelectedState(0, 1);                                          
             }
             return true;
         }
         else
         {
             if ((outselected != null) || (inselected != null))
             {
                 graphicControl.Cursor = Cursors.Arrow;
                 if (outselected != null) outselected.SetSelectedState(0, 0);
                 if (inselected != null) inselected.SetSelectedState(0, 0);
                 outselected = null;
                 inselected = null;                        
                 return true;
             }
             return false;
         }
     }
     return false;
 }
Ejemplo n.º 53
0
		/// <summary>
		/// This method is called on a DrawableContainers when:
		/// 1) The capture on the surface is modified in such a way, that the elements would not be placed correctly.
		/// 2) Currently not implemented: an element needs to be moved, scaled or rotated.
		/// This basis implementation makes sure the coordinates of the element, including the TargetGripper, is correctly rotated/scaled/translated.
		/// But this implementation doesn't take care of any changes to the content!!
		/// </summary>
		/// <param name="matrix"></param>
		public virtual void Transform(Matrix matrix) {
			if (matrix == null) {
				return;
			}
			SuspendLayout();
			Point topLeft = new Point(Left, Top);
			Point bottomRight = new Point(Left + Width, Top + Height);
			Point[] points;
			if (TargetGripper != null) {
				points = new[] {topLeft, bottomRight, TargetGripper.Location};

			} else {
				points = new[] { topLeft, bottomRight };
			}
			matrix.TransformPoints(points);

			Left = points[0].X;
			Top = points[0].Y;
			Width = points[1].X - points[0].X;
			Height = points[1].Y - points[0].Y;
			if (TargetGripper != null) {
				TargetGripper.Location = points[points.Length-1];
			}
			ResumeLayout();
		}
        public bool MouseUp(MouseEventArgs e, Matrix transform)
        {
            Point[] pp = new Point[] { e.Location };
            transform.TransformPoints(pp);
            Point location = pp[0];

            if (e.Button == MouseButtons.Left)
            {
                state = State.NONE;                
            }
            return false;
        }
Ejemplo n.º 55
0
        protected override void RenderPath(FillStyle fs, StrokeStyle ss, List <IShapeData> sh, bool silverlight)
        {
            // <Path Fill="#FFFF0000"
            // StrokeThickness="0.00491913" StrokeLineJoin="Round" Stroke="#FF014393"
            // Data="M 196.667,4L 388.667,100L 388.667,292L 196.667,388L 4.66669,292L 4.66669,100L 196.667,4 Z "/>
            if (sh.Count == 0)
            {
                return;
            }

            xw.WriteStartElement("Path");

            bool isGradient    = false;
            bool isTiledBitmap = false;

            if (fs != null)
            {
                if (fs.FillType == FillType.Solid)
                {
                    Color c = ((SolidFill)fs).Color;
                    xw.WriteStartAttribute("Fill");
                    xw.WriteColor(c);
                    xw.WriteEndAttribute();

                    // try to clean up faint edges
                    if (ss == null && c != new Color(0xFF, 0xFF, 0xFF) && c.A != 0)
                    {
                        ss = new SolidStroke(0.3F, c);
                    }
                }
                else if (
                    fs.FillType == FillType.Linear ||
                    fs.FillType == FillType.Radial ||
                    fs.FillType == FillType.Focal)
                {
                    isGradient = true;
                }
                else if (fs.FillType == FillType.Image)
                {
                    // Fill="{StaticResource vb_1}"
                    ImageFill img = (ImageFill)fs;
                    if (img.IsTiled || silverlight)
                    {
                        isTiledBitmap = true;// this causes bitmap to be written inline
                    }
                    else
                    {
                        string brushName = imageBrushes[img.ImagePath];
                        xw.WriteStartAttribute("Fill");
                        xw.WriteValue("{StaticResource " + brushName + "}");
                        xw.WriteEndAttribute();
                    }
                }
            }
            if (ss != null)
            {
                if (ss is SolidStroke)
                {
                    // StrokeThickness="3" StrokeLineJoin="Round" Stroke="#FF014393"
                    // StrokeStartLineCap="Round"
                    // StrokeEndLineCap="Round"
                    SolidStroke st = (SolidStroke)ss;

                    xw.WriteStartAttribute("StrokeThickness");
                    xw.WriteFloat(st.LineWidth);
                    xw.WriteEndAttribute();

                    xw.WriteStartAttribute("StrokeLineJoin");
                    xw.WriteString("Round");
                    xw.WriteEndAttribute();

                    xw.WriteStartAttribute("StrokeStartLineCap");
                    xw.WriteString("Round");
                    xw.WriteEndAttribute();

                    xw.WriteStartAttribute("StrokeEndLineCap");
                    xw.WriteString("Round");
                    xw.WriteEndAttribute();

                    xw.WriteStartAttribute("Stroke");
                    xw.WriteColor(st.Color);
                    xw.WriteEndAttribute();
                }
            }
            float minX = float.PositiveInfinity;
            float minY = float.PositiveInfinity;
            float maxX = float.NegativeInfinity;
            float maxY = float.NegativeInfinity;

            xw.WriteStartAttribute("Data");

            xw.WriteMoveTo(sh[0].StartPoint);

            Point lastPoint = sh[0].StartPoint;

            for (int i = 0; i < sh.Count; i++)
            {
                IShapeData sd = sh[i];
                if (lastPoint != sd.StartPoint)
                {
                    xw.WriteMoveTo(sd.StartPoint);
                }
                switch (sd.SegmentType)
                {
                case SegmentType.Line:
                    xw.WriteLineTo(sd.EndPoint);
                    lastPoint = sd.EndPoint;
                    break;

                case SegmentType.CubicBezier:
                    CubicBezier cb = (CubicBezier)sd;
                    xw.WriteCubicCurveTo(cb.Control0, cb.Control1, cb.Anchor1);
                    lastPoint = cb.EndPoint;
                    minX      = Math.Min(minX, cb.Control0.X);
                    maxX      = Math.Max(maxX, cb.Control0.X);
                    minY      = Math.Min(minY, cb.Control0.Y);
                    maxY      = Math.Max(maxY, cb.Control0.Y);
                    minX      = Math.Min(minX, cb.Control1.X);
                    maxX      = Math.Max(maxX, cb.Control1.X);
                    minY      = Math.Min(minY, cb.Control1.Y);
                    maxY      = Math.Max(maxY, cb.Control1.Y);
                    break;

                case SegmentType.QuadraticBezier:
                    QuadBezier qb = (QuadBezier)sd;
                    xw.WriteQuadraticCurveTo(qb.Control, qb.Anchor1);
                    lastPoint = qb.EndPoint;
                    minX      = Math.Min(minX, qb.Control.X);
                    maxX      = Math.Max(maxX, qb.Control.X);
                    minY      = Math.Min(minY, qb.Control.Y);
                    maxY      = Math.Max(maxY, qb.Control.Y);
                    break;
                }

                // need bounds for gradient :(
                if (isGradient)
                {
                    minX = Math.Min(minX, sd.StartPoint.X);
                    maxX = Math.Max(maxX, sd.StartPoint.X);
                    minY = Math.Min(minY, sd.StartPoint.Y);
                    maxY = Math.Max(maxY, sd.StartPoint.Y);

                    minX = Math.Min(minX, sd.EndPoint.X);
                    maxX = Math.Max(maxX, sd.EndPoint.X);
                    minY = Math.Min(minY, sd.EndPoint.Y);
                    maxY = Math.Max(maxY, sd.EndPoint.Y);
                }
            }
            xw.WriteEndAttribute();

            if (isGradient)
            {
                GradientFill gf = (GradientFill)fs;
                // need a gradient def here
                if (fs.FillType == FillType.Linear)
                {
                    //<Path.Fill>
                    //    <LinearGradientBrush StartPoint="0.14706,0.532137" EndPoint="1.14962,0.55353">
                    //        <LinearGradientBrush.GradientStops>
                    //            <GradientStop Color="#FF4A4A4A" Offset="0"/>
                    //            <GradientStop Color="#FFB0B0B0" Offset="0.412067"/>
                    //            <GradientStop Color="#FFBBBBBB" Offset="0.638141"/>
                    //            <GradientStop Color="#FF545454" Offset="1"/>
                    //        </LinearGradientBrush.GradientStops>
                    //    </LinearGradientBrush>
                    //</Path.Fill>
                    xw.WriteStartElement("Path.Fill");

                    xw.WriteStartElement("LinearGradientBrush");

                    Matrix           m    = gf.Transform;
                    Rectangle        r    = GradientFill.GradientVexRect;
                    sysDraw2D.Matrix m2   = new sysDraw2D.Matrix(m.ScaleX, m.Rotate0, m.Rotate1, m.ScaleY, m.TranslateX, m.TranslateY);
                    float            midY = r.Point.Y + (r.Size.Height / 2);
                    sysDraw.PointF   pt0  = new sysDraw.PointF(r.Point.X, midY);
                    sysDraw.PointF   pt1  = new sysDraw.PointF(r.Point.X + r.Size.Width, midY);
                    sysDraw.PointF[] pts  = new sysDraw.PointF[] { pt0, pt1 };
                    m2.TransformPoints(pts);

                    float ratX = 1 / (maxX - minX);
                    float ratY = 1 / (maxY - minY);
                    float d0x  = (pts[0].X - minX) * ratX;
                    float d0y  = (pts[0].Y - minY) * ratY;
                    float d1x  = (pts[1].X - minX) * ratX;
                    float d1y  = (pts[1].Y - minY) * ratY;

                    xw.WriteStartAttribute("StartPoint");
                    xw.WritePoint(new Point(d0x, d0y));
                    xw.WriteEndAttribute();

                    xw.WriteStartAttribute("EndPoint");
                    xw.WritePoint(new Point(d1x, d1y));
                    xw.WriteEndAttribute();

                    xw.WriteStartAttribute("SpreadMethod");
                    xw.WriteValue("Pad");
                    xw.WriteEndAttribute();

                    xw.WriteStartElement("LinearGradientBrush.GradientStops");
                    for (int i = 0; i < gf.Stops.Count; i++)
                    {
                        xw.WriteStartElement("GradientStop");

                        xw.WriteStartAttribute("Color");
                        xw.WriteColor(gf.Fills[i]);
                        xw.WriteEndAttribute();

                        xw.WriteStartAttribute("Offset");
                        xw.WriteFloat(gf.Stops[i]);
                        xw.WriteEndAttribute();

                        xw.WriteEndElement(); // GradientStop
                    }
                    xw.WriteEndElement();     // LinearGradientBrush.GradientStops
                    xw.WriteEndElement();     // LinearGradientBrush
                    xw.WriteEndElement();     // Path.Fill
                }
                else if (fs.FillType == FillType.Radial)
                {
                    //<Ellipse.Fill>
                    //    <RadialGradientBrush RadiusX="0.622359" RadiusY="0.604589" Center="0.5,0.5" GradientOrigin="0.5,0.5">
                    //        <RadialGradientBrush.RelativeTransform>
                    //            <TransformGroup/>
                    //        </RadialGradientBrush.RelativeTransform>
                    //        <GradientStop Color="#95000000" Offset="0.347222"/>
                    //        <GradientStop Color="#007877A7" Offset="0.773148"/>
                    //    </RadialGradientBrush>
                    //</Ellipse.Fill>

                    xw.WriteStartElement("Path.Fill");

                    xw.WriteStartElement("RadialGradientBrush");

                    Matrix           m    = gf.Transform;
                    Rectangle        r    = GradientFill.GradientVexRect;
                    sysDraw2D.Matrix m2   = new sysDraw2D.Matrix(m.ScaleX, m.Rotate0, m.Rotate1, m.ScaleY, m.TranslateX, m.TranslateY);
                    float            midX = r.Point.X + (r.Size.Width / 2);
                    float            midY = r.Point.Y + (r.Size.Height / 2);
                    sysDraw.PointF   pt0  = new sysDraw.PointF(midX, midY);                     // center
                    sysDraw.PointF   pt1  = new sysDraw.PointF(r.Point.X + r.Size.Width, midY); // radius vector
                    sysDraw.PointF[] pts  = new sysDraw.PointF[] { pt0, pt1 };
                    m2.TransformPoints(pts);

                    float ratX = 1 / (maxX - minX);
                    float ratY = 1 / (maxY - minY);
                    float d0x  = (pts[0].X - minX) * ratX;
                    float d0y  = (pts[0].Y - minY) * ratY;
                    float d1x  = (pts[1].X - pts[0].X);
                    //float d1y = (pts[1].Y - pts[0].Y) * ratY;

                    float rad = (float)Math.Sqrt(d1x * d1x);
                    xw.WriteStartAttribute("RadiusX");
                    xw.WriteFloat(rad * ratX);
                    xw.WriteEndAttribute();
                    xw.WriteStartAttribute("RadiusY");
                    xw.WriteFloat(rad * ratY);
                    xw.WriteEndAttribute();

                    xw.WriteStartAttribute("Center");
                    xw.WritePoint(new Point(d0x, d0y));
                    xw.WriteEndAttribute();

                    xw.WriteStartAttribute("GradientOrigin");
                    xw.WritePoint(new Point(d0x, d0y));
                    xw.WriteEndAttribute();

                    xw.WriteStartAttribute("SpreadMethod");
                    xw.WriteValue("Pad");
                    xw.WriteEndAttribute();

                    //xw.WriteStartElement("RadialGradientBrush.GradientStops");
                    for (int i = 0; i < gf.Stops.Count; i++)
                    {
                        xw.WriteStartElement("GradientStop");

                        xw.WriteStartAttribute("Color");
                        xw.WriteColor(gf.Fills[i]);
                        xw.WriteEndAttribute();

                        xw.WriteStartAttribute("Offset");
                        xw.WriteFloat(1 - gf.Stops[i]); // xaml fill is reversed from gdi
                        xw.WriteEndAttribute();

                        xw.WriteEndElement(); // GradientStop
                    }
                    //xw.WriteEndElement(); // LinearGradientBrush.GradientStops
                    xw.WriteEndElement(); // LinearGradientBrush
                    xw.WriteEndElement(); // Path.Fill
                }
            }
            else if (isTiledBitmap)
            {
                //<Path.Fill>
                //   <ImageBrush ImageSource="Resources\bmp_1.jpg" TileMode="Tile" RelativeTransform=".2,0,0,.2,0,0"/>
                //</Path.Fill>

                ImageFill img = (ImageFill)fs;

                xw.WriteStartElement("Path.Fill");
                xw.WriteStartElement("ImageBrush");

                xw.WriteStartAttribute("ImageSource");
                xw.WriteValue(img.ImagePath);
                xw.WriteEndAttribute();

                if (!silverlight)
                {
                    xw.WriteStartAttribute("TileMode");
                    xw.WriteValue("Tile");
                    xw.WriteEndAttribute();
                }

                //xw.WriteStartAttribute("ViewportUnits");
                //xw.WriteValue("Absolute");
                //xw.WriteEndAttribute();

                Matrix pMatrix = ApplyMatrixToShape(sh, img.Matrix, images[img.ImagePath].StrokeBounds);
                //Matrix pMatrix = ApplyMatrixToImage(img.Matrix, images[img.ImagePath].Bounds);
                xw.WriteStartAttribute("RelativeTransform");
                xw.WriteMatrix(pMatrix);
                //xw.WriteMatrix(img.Matrix);
                xw.WriteEndAttribute();

                xw.WriteEndElement(); // Path.Fill
                xw.WriteEndElement(); // ImageBrush
            }
            xw.WriteEndElement();     // Path
        }
Ejemplo n.º 56
0
        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));
        }
Ejemplo n.º 57
0
        /// <summary>
        /// Without this change, labels render upside down and don't all scale readably.
        /// </summary>
        /// <param name="g"></param>
        /// <param name="ro"></param>
        /// <returns></returns>
        protected RectangleF AdjustForLabel(Graphics g, GdiRenderObject ro)
        {
            // this transform goes from the underlying coordinates to
            // screen coordinates, but for some reason renders text upside down
            // we cannot just scale by 1, -1 because offsets are affected also
            GdiMatrix m = g.Transform;
            // used to scale text size for the current zoom level
            float scale = Math.Abs(m.Elements[0]);

            // get the bounds of the label in the underlying coordinate space
            Point ll = new Point((Int32)ro.Bounds.X, (Int32)ro.Bounds.Y);
            Point ur = new Point((Int32)(ro.Bounds.X + ro.Bounds.Width),
                                 (Int32)(ro.Bounds.Y + ro.Bounds.Height));

            Point[] transformedPoints1 =
            {
                new Point((Int32)ro.Bounds.X,                     (Int32)ro.Bounds.Y),
                new Point((Int32)(ro.Bounds.X + ro.Bounds.Width),
                          (Int32)(ro.Bounds.Y + ro.Bounds.Height))
            };

            // get the label bounds transformed into screen coordinates
            // note that if we just render this as-is the label is upside down
            m.TransformPoints(transformedPoints1);

            // for labels, we're going to use an identity matrix and screen coordinates
            GdiMatrix newM = new GdiMatrix();

            Boolean scaleText = true;

            /*
             *          if (ro.Layer != null)
             *          {
             *              Double min = ro.Layer.Style.MinVisible;
             *              Double max = ro.Layer.Style.MaxVisible;
             *              float scaleMult = Double.IsInfinity(max) ? 2.0f : 1.0f;
             *
             *              //max = Math.Min(max, _presenter.MaximumWorldWidth);
             *              max = Math.Min(max, Map.Extents.Width);
             *              //Double pct = (max - _presenter.WorldWidth) / (max - min);
             *              Double pct = 1 - (Math.Min(_presenter.WorldWidth, Map.Extents.Width) - min) / (max - min);
             *
             *              if (scaleMult > 1)
             *              {
             *                  pct = Math.Max(.5, pct * 2);
             *              }
             *
             *              scale = (float)pct*scaleMult;
             *              labelScale = scale;
             *          }
             */

            // ok, I lied, if we're scaling labels we need to scale our new matrix, but still no offsets
            if (scaleText)
            {
                newM.Scale(scale, scale);
            }
            else
            {
                scale = 1.0f;
            }

            g.Transform = newM;

            Int32 pixelWidth  = ur.X - ll.X;
            Int32 pixelHeight = ur.Y - ll.Y;

            // if we're scaling text, then x,y position will get multiplied by our
            // scale, so adjust for it here so that we can use actual pixel x,y
            // Also center our label on the coordinate instead of putting the label origin on the coordinate
            RectangleF newBounds = new RectangleF(transformedPoints1[0].X / scale,
                                                  (transformedPoints1[0].Y / scale) - pixelHeight,
                                                  pixelWidth,
                                                  pixelHeight);

            //RectangleF newBounds = new RectangleF(transformedPoints1[0].X / scale - (pixelWidth / 2), transformedPoints1[0].Y / scale - (pixelHeight / 2), pixelWidth, pixelHeight);

            return(newBounds);
        }
Ejemplo n.º 58
0
 public void Transform(Matrix matrix)
 {
     matrix.TransformPoints(points);
 }
        private Rectangle GetTransformedRectangle(DockState dockState, Rectangle rect)
        {
            if (dockState != DockState.DockLeftAutoHide && dockState != DockState.DockRightAutoHide)
                return rect;

            PointF[] pts = new PointF[1];
            // the center of the rectangle
            pts[0].X = (float)rect.X + (float)rect.Width / 2;
            pts[0].Y = (float)rect.Y + (float)rect.Height / 2;
            Rectangle rectTabStrip = GetLogicalTabStripRectangle(dockState);
            Matrix matrix = new Matrix();
            matrix.RotateAt(90, new PointF((float)rectTabStrip.X + (float)rectTabStrip.Height / 2,
                (float)rectTabStrip.Y + (float)rectTabStrip.Height / 2));
            matrix.TransformPoints(pts);

            return new Rectangle((int)(pts[0].X - (float)rect.Height / 2 + .5F),
                (int)(pts[0].Y - (float)rect.Width / 2 + .5F),
                rect.Height, rect.Width);
        }
Ejemplo n.º 60
0
        // http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_shadings/dq_shadings.html#//apple_ref/doc/uid/TP30001066-CH207-BBCECJBF
        internal override void Setup(Graphics graphics, bool fill)
        {
            CGContext context = graphics.context;

            // if fill is false then we are being called from a Pen stroke so
            // we need to setup a transparency layer
            // http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_shadings/dq_shadings.html#//apple_ref/doc/uid/TP30001066-CH207-BBCECJBF
            if (!fill)
            {
                context.BeginTransparencyLayer();
                hasTransparencyLayer = true;
                // Make sure we set a color here so that the gradient shows up
                graphics.lastBrushColor = Color.Black;
                return;
            }

            // if this is the same as the last that was set and no changes have been made
            // then return.
            if (graphics.LastBrush != this || changed)
            {
                setupShadingColors();
            }

            CGSize gradientRegionCg = context.GetClipBoundingBox().Size;
            SizeF  gradientRegion   = new SizeF((float)gradientRegionCg.Width, (float)gradientRegionCg.Height);
//			SizeF gradientRegionPath = context.GetPathBoundingBox().Size;
            PointF sp = startPoint;
            PointF ep = endPoint;

            PointF[] points = { sp, ep };

            // Transform the start and end points using the brush's transformation matrix
            gradientTransform.TransformPoints(points);

            sp = points[0];
            ep = points[1];

            var cgf = CyclicGradientFunction(gradientRegion,
                                             ref sp, ref ep);

            var     colorSpace = CGColorSpace.CreateDeviceRGB();
            CGPoint cgsp = new CGPoint(sp.X, sp.Y), cgep = new CGPoint(ep.X, ep.Y);
            var     shading = CGShading.CreateAxial(colorSpace, cgsp, cgep, cgf, false, false);

            colorSpace.Dispose();

            context.SaveState();

            // if path is empty here then we are being called from a Pen stroke so
            // we set the blend mode for strokes and clip the path for fills
            if (!context.IsPathEmpty())
            {
                context.Clip();
            }
            else
            {
                context.SetBlendMode(CGBlendMode.SourceIn);
            }

            context.DrawShading(shading);
            context.RestoreState();

            // If we are in a Transparency layer then we need to end the transparency
            if (hasTransparencyLayer)
            {
                context.EndTransparencyLayer();
            }

            cgf.Dispose();
            shading.Dispose();
            shading = null;

            changed = false;

            graphics.LastBrush = this;
            // We will reset the last pen so that it can be setup again
            // so that we do not loose the settings after stroking the gradient
            // not sure where the setting are being reset so this may be a hack
            // and things are just not being restored correctly.
            graphics.LastPen = null;
            // I am setting this to be used for Text coloring in DrawString
            graphics.lastBrushColor = colors[0];
        }