Inheritance: MarshalByRefObject, IDisposable
Ejemplo n.º 1
0
        public override void Draw(CGRect rect)
        {
            Graphics g = Graphics.FromCurrentContext ();
            int offset = 20;

            // Invert matrix:
            var m = new Matrix (1, 2, 3, 4, 0, 0);
            g.DrawString ("Original Matrix:", Font, Brushes.Black, 10, 10);
            DrawMatrix (m, g, 10, 10 + offset);
            g.DrawString ("Inverted Matrix:", Font, Brushes.Black, 10, 10 + 2 * offset);
            m.Invert ();
            DrawMatrix (m, g, 10, 10 + 3 * offset);

            // Matrix multiplication - MatrixOrder.Append:
            var m1 = new Matrix (1, 2, 3, 4, 0, 1);
            var m2 = new Matrix (0, 1, 2, 1, 0, 1);
            g.DrawString ("Original Matrices:", Font, Brushes.Black, 10, 10 + 4 * offset);
            DrawMatrix (m1, g, 10, 10 + 5 * offset);
            DrawMatrix (m2, g, 10 + 130, 10 + 5 * offset);
            m1.Multiply (m2, MatrixOrder.Append);
            g.DrawString ("Resultant Matrix - Append:", Font, Brushes.Black, 10, 10 + 6 * offset);
            DrawMatrix (m1, g, 10, 10 + 7 * offset);

            // Matrix multiplication - MatrixOrder.Prepend:
            m1 = new Matrix (1, 2, 3, 4, 0, 1);
            m1.Multiply (m2, MatrixOrder.Prepend);
            g.DrawString ("Resultant Matrix - Prepend:", Font, Brushes.Black, 10, 10 + 8 * offset);
            DrawMatrix (m1, g, 10, 10 + 9 * offset);
        }
Ejemplo n.º 2
0
 public TextureBrush GetBrush(Matrix matrix)
 {
     Bitmap bmp;
     if (_context2D != null)
     {
         bmp = _context2D.GetBitmap();
     }
     else
     {
         bmp = new Bitmap(_imagePath);
     }
     WrapMode wm = WrapMode.Tile;
     switch (_repetition)
     {
         case "repeat":
             wm = WrapMode.Tile;
             break;
         case "no-repeat":
             wm = WrapMode.Clamp;
             break;
         case "repeat-x":
             wm = WrapMode.TileFlipX;
             break;
         case "repeat-y":
             wm = WrapMode.TileFlipY;
             break;
     }
     var brush = new TextureBrush(bmp, wm);
     brush.MultiplyTransform(matrix);
     return brush;
 }
Ejemplo n.º 3
0
        public void Draw(AnimationTrack track, SpriteBatch spBatch)
        {
            System.Drawing.Drawing2D.Matrix worldMatrix = new System.Drawing.Drawing2D.Matrix();
            worldMatrix = track.CachedMatrix;

            // fetch the image out.
            Microsoft.Xna.Framework.Rectangle rect;
            Texture2D texture = GetTexture(track, out rect);

            System.Drawing.Drawing2D.Matrix finalTransform = mViewMatrix.Clone();
            finalTransform.Multiply(worldMatrix);
            float[] gM = finalTransform.Elements;

            Microsoft.Xna.Framework.Matrix xM = new Microsoft.Xna.Framework.Matrix();

            xM.M11 = gM[0];
            xM.M12 = gM[1];
            xM.M21 = gM[2];
            xM.M22 = gM[3];
            xM.M41 = gM[4];
            xM.M42 = gM[5];
            xM.M33 = 1;
            xM.M44 = 1;
            Microsoft.Xna.Framework.Rectangle dRect = new Microsoft.Xna.Framework.Rectangle();
            dRect.X = 100;
            dRect.Y = 100;
            dRect.Width = rect.Width;
            dRect.Height = rect.Height;

            spBatch.Begin(SpriteSortMode.Immediate,BlendState.AlphaBlend,SamplerState.LinearClamp,DepthStencilState.None,RasterizerState.CullCounterClockwise,null,xM);
            spBatch.Draw(texture, dRect, rect, Microsoft.Xna.Framework.Color.White);
            spBatch.End();
        }
Ejemplo n.º 4
0
        private static Bitmap GetEyeOfSightImage()
        {
            var roestte = new Bitmap(120, 120);
            
            //Anyone for a more sophisticated roestte?
            using (var g = Graphics.FromImage(roestte))
            {
                var t = new Matrix(1f, 0f, 0f, 1f, 60, 60);
                g.Transform = t;

                var f = new Font("Arial", 20, FontStyle.Bold);
                var b = new SolidBrush(Color.Black);
                var p = new Pen(Color.Black, 5);
                var sf = new StringFormat(StringFormat.GenericTypographic) {Alignment = StringAlignment.Center};
                var rect = new RectangleF(- 45f, - 45f, 90f, 90f);

                foreach (var s in Directions)
                {
                    g.DrawString(s, f, b, 0, -55, sf);
                    g.DrawArc(p, rect, 290f, 50f);
                    g.RotateTransform(90f);
                }
            }
            return roestte;
        }
	// Constructor, which saves away all of the important information.
	// We assume that the lock on the "graphics" object is held by the caller.
	internal GraphicsContainer(Graphics graphics)
			{
				// Push this container onto the stack.
				this.graphics = graphics;
				next = graphics.stackTop;
				graphics.stackTop = this;

				// Save the graphics state information.
				clip = graphics.Clip;
				if(clip != null)
				{
					clip = clip.Clone();
				}
				compositingMode = graphics.CompositingMode;
				compositingQuality = graphics.CompositingQuality;
				interpolationMode = graphics.InterpolationMode;
				pageScale = graphics.PageScale;
				pageUnit = graphics.PageUnit;
				pixelOffsetMode = graphics.PixelOffsetMode;
				renderingOrigin = graphics.RenderingOrigin;
				smoothingMode = graphics.SmoothingMode;
				textContrast = graphics.TextContrast;
				textRenderingHint = graphics.TextRenderingHint;
				if (graphics.transform == null)
				{
					transform = null;
				}
				else
				{
					transform = Matrix.Clone(graphics.transform);
				}
			}
Ejemplo n.º 6
0
        protected override void OnRender(Graphics g, Map map)
        {
            // Render the rosetta
            base.OnRender(g, map);
            
            var clip = g.ClipBounds;
            var oldTransform = g.Transform;
            var newTransform = new Matrix(1f, 0f, 0f, 1f, clip.Left + Size.Width*0.5f, clip.Top + Size.Height*0.5f);

            g.Transform = newTransform;

            var width = Size.Width;
            var height = Size.Height;
            var pts = new[]
                          {
                              new PointF(0f, -0.35f*height),
                              new PointF(0.125f*width, 0.35f*height),
                              new PointF(0f, 0.275f*height),
                              new PointF(-0.125f*width, 0.35f*height),
                              new PointF(0f, -0.35f*height),
                          };

            // need to outline the needle
            if (NeedleOutlineWidth>0)
            {
                g.DrawPolygon(new Pen(OpacityColor(NeedleOutlineColor), NeedleOutlineWidth), pts);
            }

            // need to outline the needle
            g.FillPolygon(new SolidBrush(OpacityColor(NeedleFillColor)), pts );

            g.Transform = oldTransform;

        }
Ejemplo n.º 7
0
        public static Map InitializeMap(float angle)
        {
            string wmsUrl = "http://dev:8080/geoserver/ows?service=wms&version=1.1.1&request=GetCapabilities";

            Map map = new Map();

            WmsLayer layWms = new WmsLayer("Demis Map", wmsUrl);

            layWms.AddLayer("sf:roads");
            //layWms.AddLayer("Topography");
            //layWms.AddLayer("Hillshading");

            layWms.SetImageFormat(layWms.OutputFormats[0]);
            layWms.ContinueOnError = true;
                //Skip rendering the WMS Map if the server couldn't be requested (if set to false such an event would crash the app)
            layWms.TimeOut = 5000; //Set timeout to 5 seconds
            layWms.SRID = 4326;
            map.Layers.Add(layWms);

            //limit the zoom to 360 degrees width
            map.MaximumZoom = 360;
            map.BackColor = Color.LightBlue;

            map.Zoom = 360;
            map.Center = new Point(0, 0);

            Matrix mat = new Matrix();
            mat.RotateAt(angle, map.WorldToImage(map.Center));
            map.MapTransform = mat;

            map.ZoomToExtents();
            return map;
        }
Ejemplo n.º 8
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.º 9
0
 // Methods
 internal Marker(string prefix, string localname, string ns, SvgDocument doc)
     : base(prefix, localname, ns, doc)
 {
     markerTransForm = new Matrix();
     brush = new SolidColor(Color.Black);
     stroke = new Stroke();
 }
Ejemplo n.º 10
0
 public void Dispose()
 {
     if (control != null)
     {
         control.Dispose();
         control = null;
     }
 }
Ejemplo n.º 11
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.º 12
0
 public static Matrix ScaleBitmapMatrix(Matrix m)
 {
     System.Drawing.Drawing2D.Matrix mx =
         new System.Drawing.Drawing2D.Matrix(m.ScaleX, m.Rotate0, m.Rotate1, m.ScaleY, m.TranslateX, m.TranslateY);
     mx.Scale(1 / 20F, 1 / 20F);
     float[] els = mx.Elements;
     return new Matrix(els[0], els[1], els[2], els[3], els[4], els[5]);
 }
Ejemplo n.º 13
0
    public void DrawImage()
    {
        //Creates an output Bitmap
        Bitmap   oOutputBitmap = new Bitmap(iWidth, iHeight, PixelFormat.Format24bppRgb);
        Graphics oGraphics     = Graphics.FromImage(oOutputBitmap);

        oGraphics.TextRenderingHint = TextRenderingHint.AntiAlias;

        //Create a Drawing area
        RectangleF oRectangleF = new RectangleF(0, 0, iWidth, iHeight);
        Brush      oBrush      = default(Brush);

        //Draw background (Lighter colors RGB 100 to 255)
        oBrush = new HatchBrush(aHatchStyles[oRandom.Next
                                                 (aHatchStyles.Length - 1)], Color.FromArgb((oRandom.Next(100, 255)),
                                                                                            (oRandom.Next(100, 255)), (oRandom.Next(100, 255))), Color.White);
        oGraphics.FillRectangle(oBrush, oRectangleF);

        System.Drawing.Drawing2D.Matrix oMatrix = new System.Drawing.Drawing2D.Matrix();
        int i = 0;

        for (i = 0; i <= sCaptchaText.Length - 1; i++)
        {
            oMatrix.Reset();
            int iChars = sCaptchaText.Length;
            int x      = iWidth / (iChars + 1) * i;
            int y      = iHeight / 2;

            //Rotate text Random
            oMatrix.RotateAt(oRandom.Next(-20, 20), new PointF(x, y));
            oGraphics.Transform = oMatrix;

            //Draw the letters with Random Font Type, Size and Color
            oGraphics.DrawString
            (
                //Text
                sCaptchaText.Substring(i, 1),
                //Random Font Name and Style
                new Font(aFontNames[oRandom.Next(aFontNames.Length - 1)],
                         aFontEmSizes[oRandom.Next(aFontEmSizes.Length - 1)],
                         aFontStyles[oRandom.Next(aFontStyles.Length - 1)]),
                //Random Color (Darker colors RGB 0 to 100)
                new SolidBrush(Color.FromArgb(oRandom.Next(0, 100),
                                              oRandom.Next(0, 100), oRandom.Next(0, 100))),
                x,
                oRandom.Next(0, 15)
            );
            oGraphics.ResetTransform();
        }

        MemoryStream oMemoryStream = new MemoryStream();

        oOutputBitmap.Save(oMemoryStream, System.Drawing.Imaging.ImageFormat.Png);
        byte[] oBytes = oMemoryStream.GetBuffer();
        captchaImage = "data:image/png;base64," + Convert.ToBase64String(oBytes, 0, oBytes.Length);
        oOutputBitmap.Dispose();
        oMemoryStream.Close();
    }
Ejemplo n.º 14
0
        /// <summary>
        /// Draws the background of the collapsed band
        /// </summary>
        /// <param name="g">The canvas to draw on</param>
        /// <param name="bounds">The bounds of the drawing</param>
        /// <param name="text">The text that should appear into the bar</param>
        /// <param name="font">The font to use when drawing the text</param>
        /// <param name="state">The inputstate of the collapsed band</param>
        public override void DrawNaviBandCollapsedBg(Graphics g, Rectangle bounds, string text, Font font,
                                                     bool rightToLeft, InputState state)
        {
            using (SolidBrush b = new SolidBrush(ColourTable.BandCollapsedBgColor1))
            {
                if (state == InputState.Hovered)
                {
                    b.Color = ColourTable.BandCollapsedHoveredColor1;
                }
                else if (state == InputState.Clicked)
                {
                    b.Color = ColourTable.BandCollapsedClickedColor1;
                }

                g.FillRectangle(b, bounds);
            }

            // inner border
            using (Pen p = new Pen(ColourTable.Border))
            {
                g.DrawLine(p, new Point(bounds.Left, bounds.Top), new Point(bounds.Right,
                                                                            bounds.Top));
                p.Color = ColourTable.BorderInner;
                if (state == InputState.Normal)
                {
                    g.DrawLine(p, new Point(bounds.Left, bounds.Top + 1), new Point(bounds.Right,
                                                                                    bounds.Top + 1));
                    g.DrawLine(p, new Point(bounds.Left, bounds.Top + 1), new Point(bounds.Left,
                                                                                    bounds.Bottom));
                }
            }

            using (Brush brush = new SolidBrush(ColourTable.Text))
            {
                if (rightToLeft)
                {
                    Point ptCenter = new Point(bounds.X + bounds.Width / 2 + 7, bounds.Y +
                                               bounds.Height / 2);
                    System.Drawing.Drawing2D.Matrix transform = g.Transform;
                    transform.RotateAt(90, ptCenter);
                    g.Transform = transform;
                    using (StringFormat format = new StringFormat())
                    {
                        format.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
                        g.DrawString(text, font, brush, ptCenter, format);
                    }
                }
                else
                {
                    Point ptCenter = new Point(bounds.X + bounds.Width / 2 - 7, bounds.Y +
                                               bounds.Height / 2);
                    System.Drawing.Drawing2D.Matrix transform = g.Transform;
                    transform.RotateAt(270, ptCenter);
                    g.Transform = transform;
                    g.DrawString(text, font, brush, ptCenter);
                }
            }
        }
Ejemplo n.º 15
0
        // Return a bitmap rotated around its center.
        public static Bitmap RotateBitmap(Bitmap bm, float angle)
        {
            // Make a Matrix to represent rotation
            // by this angle.
            System.Drawing.Drawing2D.Matrix rotate_at_origin = new System.Drawing.Drawing2D.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(wid / 2f, hgt / 2f));

            // Draw the image onto the new bitmap rotated.
            using (Graphics gr = Graphics.FromImage(result))
            {
                // Use smooth image interpolation.
                gr.InterpolationMode = InterpolationMode.High;

                // Clear with the color in the image's upper left corner.
                gr.Clear(bm.GetPixel(0, 0));

                //// For debugging. (It's easier to see the background.)
                //gr.Clear(Color.LightBlue);

                // Set up the transformation to rotate.
                gr.Transform = rotate_at_center;

                // Draw the image centered on the bitmap.
                int x = (wid - bm.Width) / 2;
                int y = (hgt - bm.Height) / 2;
                gr.DrawImage(bm, x, y);
            }

            // Return the result bitmap.
            return(result);
        }
Ejemplo n.º 16
0
        protected System.Drawing.Drawing2D.Matrix m; // Matrice di trasfrmazione 2D

        /// <summary>
        /// Costruttore
        /// </summary>
        public Elemento()
        {
            name     = string.Empty;
            id       = UNASSIGNED;
            sel      = false;
            clipped  = Def.ClipFlag.Inside;
            connesso = false;
            m        = new Matrix();            // Matrice identità
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Draws the picture to the graphics.
 /// </summary>
 /// <param name="g">The g.</param>
 public void Draw(Graphics g)
 {
     Point drawLocation = new Point((int)(location.X - offset.X), (int)(location.Y - offset.Y));
     Matrix m = new Matrix();
     m.RotateAt(-angle, location);
     g.Transform = m;
     g.DrawImage(bitmap, new Rectangle(drawLocation.X, drawLocation.Y, bitmap.Width / this.frameCountW, bitmap.Height / this.frameCountH),
         new Rectangle(this.frameW * bitmap.Width / this.frameCountW, this.frameH * bitmap.Height / this.frameCountH, bitmap.Width / this.frameCountW, bitmap.Height / this.frameCountH), GraphicsUnit.Pixel);
 }
Ejemplo n.º 18
0
        void generateTransformMat()
        {
            mTransformMat = new Matrix();
            mTransformMat.Translate(mTranslation.X, mTranslation.Y);
            mTransformMat.Scale(mZoomAmt.Value, mZoomAmt.Value, MatrixOrder.Append);

            mTransformMatInv = mTransformMat.Clone();
            mTransformMatInv.Invert();
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Sets the transform graphics object in this way that its transformation matrix transforms points (realMiddle, realLeftTop, realRightDown) into (screenMiddle, screenLeftTop, screenRightDown).
        /// </summary>
        /// <param name="ScreenMiddle">The "screen" coordinates of the middle of the plot. </param>
        /// <param name="ScreenLeftTop">The "screen" coordinates of the left top point of the plot (we assume that the higher the point lies the larger value has its Y coordinate).</param>
        /// <param name="ScreenRightDown">The "screen" coordinates of the right down point of the plot. </param>
        /// <param name="RealMiddle">The "real" coordinates of the middle of the plot.</param>
        /// <param name="RealLeftTop">The "real" coordinates of the left top point of the plot.</param>
        /// <param name="RealRightDown">The "real" coordinates of the right down point of the plot.</param>
        /// <param name="Transform">The graphics object storing transformation matrix from "screen" to "plot" coordinates.</param>
        static public void SetGraphics(MyPointDouble screenMiddle, MyPointDouble screenLeftTop, MyPointDouble screenRightDown, MyPointDouble realMiddle, MyPointDouble realLeftTop, MyPointDouble realRightDown, ref Graphics transform)
        {
            RectangleF RealRectangle = new RectangleF((float)realMiddle.x, (float)realMiddle.y, (float)(realRightDown.x - realMiddle.x), (float)(realLeftTop.y - realMiddle.y));

            PointF[] ScreenArray = { screenMiddle.ToPointF(), screenLeftTop.ToPointF(), screenRightDown.ToPointF() };

            System.Drawing.Drawing2D.Matrix Transformation = new System.Drawing.Drawing2D.Matrix(RealRectangle, ScreenArray);
            transform.Transform = Transformation;
        }
        /// <summary>
        /// Snap translation part of the matrix to a given vector.
        /// </summary>
        /// <param name="mat"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public static d2d.Matrix eSnapTranslate(this d2d.Matrix mat, double x, double y)
        {
            var curmat = mat.Elements;
            var newmat = new d2d.Matrix(curmat[0], curmat[1]
                                        , curmat[2], curmat[3]
                                        , (float)x, (float)y);

            return(newmat.Clone());
        }
Ejemplo n.º 21
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.º 22
0
        public override void Draw(Graphics g, convertToDestinationDelegate convertToDestination, double pixelScale)
        {
            Point startPoint = convertToDestination(StartPoint);
            Point endPoint   = convertToDestination(EndPoint);

            double lenght = (int)Math.Sqrt(Math.Pow(endPoint.X - startPoint.X, 2) + Math.Pow(endPoint.Y - startPoint.Y, 2));

            string text = string.Format("{0} mm", Math.Round(lenght / pixelScale, 0));

            int width = 2;

            Pen pen = new Pen(this.Color, width);

            pen.Alignment = PenAlignment.Inset;
            pen.StartCap  = LineCap.DiamondAnchor;
            pen.EndCap    = LineCap.DiamondAnchor;

            g.DrawLine(pen, startPoint, endPoint);

            path = new GraphicsPath();
            path.StartFigure();
            path.AddLine(startPoint.X, startPoint.Y - width, startPoint.X + (int)lenght, startPoint.Y - width);
            path.AddLine(startPoint.X + (int)lenght, startPoint.Y - width, startPoint.X + (int)lenght, startPoint.Y + width);
            path.AddLine(startPoint.X + (int)lenght, startPoint.Y + width, startPoint.X, startPoint.Y + width);


            float cos = (float)(endPoint.X - startPoint.X) / (float)lenght;


            float arc = (float)(Math.Acos(cos) * (float)180 / Math.PI);

            if (endPoint.Y - startPoint.Y < 0)
            {
                arc = 360 - arc;
            }
            System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix();
            matrix.RotateAt(arc, startPoint);
            path.Transform(matrix);
            path.CloseFigure();


            GraphicsPath pathString = new GraphicsPath();

            pathString.StartFigure();
            pathString.AddString(text,
                                 new FontFamily("Arial"), (int)FontStyle.Regular
                                 ,
                                 16,
                                 new PointF(startPoint.X + (int)lenght / 2 - 20, startPoint.Y - 30),
                                 StringFormat.GenericDefault);

            pathString.Transform(matrix);
            pathString.CloseFigure();

            g.FillPath(new SolidBrush(this.Color), pathString);
        }
Ejemplo n.º 23
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.º 24
0
 public override void ApplyTransformation(System.Drawing.Drawing2D.Matrix transform)
 {
     if (stayCount != 0)
     {
         stayCount--;
         return;
     }
     transform.Translate(toX - fromX, toY - fromY);
     isEnd = true;
 }
Ejemplo n.º 25
0
	// Constructor.
	internal Graphics(IToolkitGraphics graphics)
			{
				this.graphics = graphics;
				this.clip = null;
				this.transform = null;
				this.pageScale = 1.0f;
				this.pageUnit = GraphicsUnit.World;
				this.stackTop = null;
				this.baseWindow = Rectangle.Empty;
			}
Ejemplo n.º 26
0
 /// <summary>
 /// Will return a copy of the Transform currently used to map the world Space of the draw Set to the pixel Space of the screen
 /// </summary>
 /// <returns></returns>
 public void setInverseCameraTransform()
 {
     inverseCameraTransform = cameraTransform.Clone();
     inverseCameraTransform.Invert();
     //adjusting for any warping as a result of differently sized buffers
     if (drawBuffers != null && (drawBuffers[0].Width != base.Width || drawBuffers[0].Height != base.Height))
     {
         inverseCameraTransform.Scale(base.Width / drawBuffers[0].Width, base.Height / drawBuffers[0].Height, MatrixOrder.Append);
     }
 }
Ejemplo n.º 27
0
 /// <summary>
 /// The default constructor.
 /// </summary>
 public View()
 {
     T3D    = new Graphics3D.Matrix();
     T3Dinv = new Graphics3D.Matrix();
     T2D    = new System.Drawing.Drawing2D.Matrix();
     T2Dinv = new System.Drawing.Drawing2D.Matrix();
     Screen = 2;
     Eye    = 3;
     depth  = new Point(0.3, 0.3);
 }
Ejemplo n.º 28
0
        void DrawMatrix(Matrix m, Graphics g, int x, int y)
        {
            string str = null;
            for (int i = 0; i < m.Elements.Length; i++) {
                str += m.Elements[i].ToString ();
                str += ", ";
            }

            g.DrawString (str, Font, Brushes.Black, x, y);
        }
Ejemplo n.º 29
0
    ///<summary>
    /// Creates a new DrawableAffine instance using the specified Matrix.
    ///</summary>
    ///<param name="matrix">The matrix.</param>
    public DrawableAffine(Matrix matrix)
    {
      Throw.IfNull("matrix", matrix);

      ScaleX = (double)matrix.Elements[0];
      ScaleY = (double)matrix.Elements[1];
      ShearX = (double)matrix.Elements[2];
      ShearY = (double)matrix.Elements[3];
      TranslateX = (double)matrix.Elements[4];
      TranslateY = (double)matrix.Elements[5];
    }
Ejemplo n.º 30
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.º 31
0
    /// <summary>
    /// Initializes a new instance of the <see cref="DrawableAffine"/> class.
    /// </summary>
    /// <param name="matrix">The matrix.</param>
    public DrawableAffine(Matrix matrix)
    {
      Throw.IfNull(nameof(matrix), matrix);

      ScaleX = matrix.Elements[0];
      ScaleY = matrix.Elements[1];
      ShearX = matrix.Elements[2];
      ShearY = matrix.Elements[3];
      TranslateX = matrix.Elements[4];
      TranslateY = matrix.Elements[5];
    }
Ejemplo n.º 32
0
        public void resize(int width, int height)
        {
            this.imgWidth = width;
            this.imgHeight = height;
            this.img = new Bitmap(width, height);

            img = new Bitmap(width, height);
            gd = Graphics.FromImage(img);
            this.aftInitial = gd.Transform;
            this.setAntiAliasing(false);
        }
Ejemplo n.º 33
0
        public static bool IsIdentity(this System.Drawing.Drawing2D.Matrix m)
        {
            bool result = false;

            float[] els = m.Elements;
            if (els[0] == 1 && els[1] == 0 && els[2] == 0 && els[3] == 1 && els[4] == 0 && els[5] == 0)
            {
                result = true;
            }
            return(result);
        }
Ejemplo n.º 34
0
        public void resize(int width, int height)
        {
            this.imgWidth  = width;
            this.imgHeight = height;
            this.img       = new Bitmap(width, height);

            img             = new Bitmap(width, height);
            gd              = Graphics.FromImage(img);
            this.aftInitial = gd.Transform;
            this.setAntiAliasing(false);
        }
Ejemplo n.º 35
0
 public void SetMatrix(Vex.Matrix m)
 {
     Vex.Transform t = instance.GetTransformAtTime(0);
     t.Matrix = m;
     if (sysMatrix != null)
     {
         sysMatrix.Dispose();
     }
     sysMatrix          = m.SysMatrix();
     HasSaveableChanges = true;
 }
        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++;
            }
        }
Ejemplo n.º 37
0
   public ModifyCTM(
 Matrix value
 )
       : this(value.Elements[0],
   value.Elements[1],
   value.Elements[2],
   value.Elements[3],
   value.Elements[4],
   value.Elements[5])
   {
   }
Ejemplo n.º 38
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]);
        }
Ejemplo n.º 39
0
            protected override void Render(RectangleF sourceBounds, Matrix transform, Graphics g)
            {
                g.SmoothingMode = SmoothingMode.AntiAlias;
                g.InterpolationMode = InterpolationMode.HighQualityBicubic;

                g.Transform = transform;
                sourceBounds.Inflate(1, 1); // allow for pen widths
                g.SetClip(sourceBounds);

                foreach (IPrintingAdapter printingAdapter in m_viewingContext.Control.AsAll<IPrintingAdapter>())
                    printingAdapter.Print(this, g);
            }
 /// <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.º 41
0
 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);
 }
Ejemplo n.º 42
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.º 43
0
        /// <summary>
        /// Only the scale and rotate.
        /// </summary>
        /// <param name="matrix"></param>
        /// <param name="point"></param>
        public void TransformVector(System.Drawing.Drawing2D.Matrix matrix, ref PointF point)
        {
            // Formula.
            // p.x = mat[0][0] * pt.x + mat[0][1] * pt.y;
            // p.y = mat[1][0] * pt.x + mat[1][1] * pt.y;

            float[] elements = matrix.Elements;
            // *Important* stores the value, otherwise changed in first calculation.
            float x = point.X;

            point.X = elements[0] * point.X + elements[2] * point.Y;
            point.Y = elements[1] * x + elements[3] * point.Y;
        }
Ejemplo n.º 44
0
 /// <summary>
 /// Will Draw this image to in the given camera
 /// </summary>
 /// <param name="painLocation">The Camera this Sprite will be drawn in</param>
 /// <param name="frame">Determines the Frame of the Sprite that will be drawn, Note if the given fram index does not exist this function will fail</param>
 /// <param name="Transformation">Determines the Location, Scale, Rotation and Shere of the image, Note The Image will alwats be scaled up from size 1x1 and its center will always be at (0,0) So if you want to see the image scale it up</param>
 /// <returns>if True, the  sprite was drawn successfully, ontherwise returns false</returns>
 public bool paint(Camera painLocation, int frame, System.Drawing.Drawing2D.Matrix Transformation)
 {
     if (isLoaded() && frame >= 0 && frame < totalFrames && painLocation != null && Transformation != null)
     {
         tempMatrix.Reset();
         tempMatrix.Scale((float)(1f / positionScale.Width), (float)(1f / positionScale.Height), MatrixOrder.Append);
         tempMatrix.Multiply(Transformation, MatrixOrder.Append);
         frameLocation.X = frame % collumns * frameLocation.Width;
         frameLocation.Y = (frame / collumns) % rows * frameLocation.Height;
         return(painLocation.paintImage(spriteSheets[(frame / (collumns * rows)) % spriteSheets.Length], frameLocation, positionScale, tempMatrix));
     }
     return(false);
 }
        public static Matrix4 Mat4FromMat(System.Drawing.Drawing2D.Matrix inp)
        {
            Matrix4 M = Matrix4.Identity;

            M.M11   = inp.Elements[0];
            M.M12   = inp.Elements[1];
            M.M21   = inp.Elements[2];
            M.M22   = inp.Elements[3];
            M[3, 0] = inp.OffsetX;
            M[3, 1] = inp.OffsetY;

            return(M);
        }
Ejemplo n.º 46
0
            /// <summary>
            /// Sets the View parameters so that the <see cref="PlotModel"/>'s bounds world coordinates transform to device
            /// coordinates will fit in to the <see cref="Rectangle"/> bounds.
            /// </summary>
            public void SetBounds(PlotModel Model, Rectangle bounds)
            {
                ResetBounds();
                RectangleF b = Bounds(Model);

                PointF[] v = new PointF[3];
                v[0].X = bounds.X; v[0].Y = bounds.Y;
                v[1].X = bounds.X + bounds.Width; v[1].Y = bounds.Y;
                v[2].X = bounds.X; v[2].Y = bounds.Y + bounds.Height;
                T2D    = new System.Drawing.Drawing2D.Matrix(b, v);
                T2Dinv = T2D.Clone();
                T2Dinv.Invert();
            }
Ejemplo n.º 47
0
        public void DrawMaskInto(Graphics g, Color c)
        {
            SysMatrix orgM = g.Transform;
            SysMatrix newM = GetMatrix().SysMatrix();

            newM.Multiply(orgM, MatrixOrder.Append);
            g.Transform = newM;

            stage.Gdi.RenderMaskInto(Definition, 0, g, c);

            newM.Dispose();
            g.Transform = orgM;
        }
Ejemplo n.º 48
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.º 49
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="flip"></param>
        /// <returns></returns>
        public Image CreateImage(AlignmentType flip)
        {
            Image image = Source;
            Bitmap flippedImage = Opetion != null && Opetion.TragetSize != null
                ? new Bitmap(Opetion.TragetSize.Value.Width, Opetion.TragetSize.Value.Height)
                : new Bitmap(image.Width, image.Height);
            using (Graphics g = Graphics.FromImage(flippedImage))
            {
                //Matrix transformation
                Matrix m = null;
                switch (flip)
                {
                    case AlignmentType.Horizontally | AlignmentType.Vertically:
                        {
                            m = new Matrix(-1, 0, 0, -1, 0, 0);
                            m.Translate(flippedImage.Width, flippedImage.Height, MatrixOrder.Append);
                            break;
                        }
                    case AlignmentType.Horizontally:
                        {
                            m = new Matrix(-1, 0, 0, 1, 0, 0);
                            m.Translate(flippedImage.Width, 0, MatrixOrder.Append);
                            break;
                        }
                    case AlignmentType.Vertically:
                        {
                            m = new Matrix(1, 0, 0, -1, 0, 0);
                            m.Translate(0, flippedImage.Height, MatrixOrder.Append);
                            break;
                        }
                    default: throw new ImageException("Not support");
                }

                //Draw
                g.Transform = m;
                if (Opetion != null)
                {
                    var attributes = GetOpacity(Opetion.Opacity);
                    g.DrawImage(image, new Rectangle(0, 0, flippedImage.Width, flippedImage.Height), 0, 0, flippedImage.Width, flippedImage.Height, GraphicsUnit.Pixel, attributes);
                }
                else
                {
                    g.DrawImage(image, 0, 0);
                }

                //clean up
                m.Dispose();
            }

            return flippedImage;
        }
Ejemplo n.º 50
0
        public override void Draw(DrawParams param)
        {
            float height = param.ModelToView(Height);

            using (Brush brush = new SolidBrush(OutlineStyle.Color))
                using (Brush back = new SolidBrush(FillStyle.Color))
                    using (Font font = new Font(FontFamily, height, FontStyle, GraphicsUnit.Pixel))
                    {
                        // Convert the text alignment point (x, y) to pixel coordinates
                        PointF[] pt = new PointF[] { new PointF(X, Y) };
                        param.Graphics.TransformPoints(CoordinateSpace.Device, CoordinateSpace.World, pt);
                        float x = pt[0].X;
                        float y = pt[0].Y;

                        // Revert transformation to identity while drawing text
                        System.Drawing.Drawing2D.Matrix oldMatrix = param.Graphics.Transform;
                        param.Graphics.ResetTransform();

                        // Calculate alignment in pixel coordinates
                        float dx = 0;
                        float dy = 0;
                        SizeF sz = param.Graphics.MeasureString(String, font);
                        if (HorizontalAlignment == StringAlignment.Far)
                        {
                            dx = -sz.Width;
                        }
                        else if (HorizontalAlignment == StringAlignment.Center)
                        {
                            dx = -sz.Width / 2;
                        }
                        if (VerticalAlignment == StringAlignment.Near)
                        {
                            dy = -sz.Height;
                        }
                        else if (VerticalAlignment == StringAlignment.Center)
                        {
                            dy = -sz.Height / 2;
                        }

                        param.Graphics.TranslateTransform(dx, dy, MatrixOrder.Append);
                        param.Graphics.RotateTransform(-Rotation, MatrixOrder.Append);
                        param.Graphics.TranslateTransform(x, y, MatrixOrder.Append);

                        // Fill background
                        param.Graphics.FillRectangle(back, 0, 0, sz.Width, sz.Height);
                        param.Graphics.DrawString(String, font, brush, 0, 0);

                        // Restore old transformation
                        param.Graphics.Transform = oldMatrix;
                    }
        }
Ejemplo n.º 51
0
        /// <summary>
        /// This routine draws the animated bomb
        /// using two toggling graphics paths
        /// giving the effect of a spinning bomb
        /// </summary>
        /// <param name="g"></param>
        public override void Draw(Graphics g)
        {
            UpdateBounds();
            Matrix m = new Matrix();

            m.Translate(MovingBounds.Left, MovingBounds.Top);
            // g.FillRectangle(Brushes.White , MovingBounds);
            if (_invert)
            {

                bombInTransformed = (GraphicsPath)bombIn.Clone();
                bombInTransformed.Transform(m);
                g.DrawPath(BombPen, bombInTransformed);
                bombInTransformed.Dispose();
            }
            else
            {
                bombOutTransformed = (GraphicsPath)bombOut.Clone();
                bombOutTransformed.Transform(m);
                g.DrawPath(BombPen, bombOutTransformed);
                bombOutTransformed.Dispose();
            }

              /*          Matrix flipMatrix = new Matrix();
            flipMatrix.Scale(-1.0f, 1.0f);

            m.Translate(MovingBounds.Left, MovingBounds.Top);

            if (_invert)
            {
                m.Scale(-1, 1);  // flip around the y axis
            }

            // g.FillRectangle(Brushes.White , MovingBounds);
                bombInTransformed = (GraphicsPath)bombIn.Clone();
                bombInTransformed.Transform(m);

                g.DrawPath(BombPen, bombInTransformed);
                bombInTransformed.Dispose();
            */

            _invert = !_invert;

            //            g.DrawPolygon(Pens.White, new PointF[]{new PointF(Position.X, Position.Y),
            //                                                   new PointF(Position.X + width, Position.Y + seg),
            //                                                   new PointF(Position.X, Position.Y + seg*2),
            //                                                    new PointF(Position.X + 3, Position.Y + seg*3)});

            Position.Y += TheBombInterval;
        }
Ejemplo n.º 52
0
        public void Draw(KalikoImage image) {
            var graphics = image.Graphics;
            var graphicsPath = new GraphicsPath();
            var stringFormat = new StringFormat {
                Alignment = Alignment,
                LineAlignment = VerticalAlignment
            };

            graphics.SmoothingMode = SmoothingMode.AntiAlias;
            graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;

            if (Font == null) {
                Font = image.Font ?? new Font("Arial", 32, FontStyle.Bold, GraphicsUnit.Pixel);
            }

            if (TargetArea == Rectangle.Empty) {
                TargetArea = new Rectangle(0, 0, image.Width, image.Height);
            }

            if (Point == Point.Empty) {
                graphicsPath.AddString(Text, Font.FontFamily, (int)Font.Style, Font.Size, TargetArea, stringFormat);
            }
            else {
                graphicsPath.AddString(Text, Font.FontFamily, (int)Font.Style, Font.Size, Point, stringFormat);
            }

            if (Rotation != 0) {
                var rotationTransform = new Matrix(1, 0, 0, 1, 0, 0);
                var bounds = graphicsPath.GetBounds();
                rotationTransform.RotateAt(Rotation, new PointF(bounds.X + (bounds.Width / 2f), bounds.Y + (bounds.Height / 2f)));
                graphicsPath.Transform(rotationTransform);
            }

            if (TextShadow != null) {
                DrawShadow(graphics, graphicsPath);
            }

            if (Outline > 0) {
                var pen = new Pen(OutlineColor, Outline) {
                    LineJoin = LineJoin.Round
                };
                graphics.DrawPath(pen, graphicsPath);
            }

            if (TextBrush == null) {
                TextBrush = new SolidBrush(TextColor);
            }

            graphics.FillPath(TextBrush, graphicsPath);
        }
Ejemplo n.º 53
0
        //private static readonly Point ImageIndent = new Point(2, 2);
        public override void Render(MetroRendererInfo renderingInfo)
        {
            MetroTileItem item = (MetroTileItem)renderingInfo.Control;
            if (item.Frames.Count == 0)
            {
                using (HatchBrush brush = new HatchBrush(HatchStyle.ForwardDiagonal, Color.Red))
                    renderingInfo.PaintEventArgs.Graphics.FillRectangle(brush, item.Bounds);
                return;
            }
            
            Matrix currentTransform = null;
            float zoom = 0.95f;
            System.Drawing.Drawing2D.Matrix mx = null;

            if (renderingInfo.ItemPaintArgs.DragInProgress)
            {
                currentTransform = renderingInfo.PaintEventArgs.Graphics.Transform;
                
                mx = new System.Drawing.Drawing2D.Matrix(zoom, 0, 0, zoom, 0, 0);
                float offsetX = (item.WidthInternal * (1.0f / zoom) - item.WidthInternal) / 2;
                float offsetY = (item.HeightInternal * (1.0f / zoom) - item.HeightInternal) / 2;
                mx.Translate(offsetX, offsetY);
                renderingInfo.PaintEventArgs.Graphics.Transform = mx;
            }

            if (item.CurrentFrameOffset != 0 && item.LastFrame != item.CurrentFrame)
            {
                Graphics g = renderingInfo.PaintEventArgs.Graphics;
                if (currentTransform == null)
                    currentTransform = g.Transform;
                g.TranslateTransform(0, -(item.HeightInternal - item.CurrentFrameOffset - InflatePixels * 2), MatrixOrder.Append);
                // Draw last frame first then offset the current frame
                RenderFrame(renderingInfo, item.LastFrame);
                if (mx != null)
                    g.Transform = mx;
                else
                    g.Transform = currentTransform;
                g.TranslateTransform(0, item.CurrentFrameOffset, MatrixOrder.Append);

                RenderFrame(renderingInfo, item.CurrentFrame);
            }
            else
                RenderFrame(renderingInfo, item.CurrentFrame);

            if (currentTransform != null)
            {
                renderingInfo.PaintEventArgs.Graphics.Transform = currentTransform;
                currentTransform.Dispose();
            }
        }
Ejemplo n.º 54
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.º 55
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.º 56
0
        public static Bitmap CreateFillPolygon(Device d, GraphicsPath path, Brush brush)
        {
            RectangleF rectF = path.GetBounds();
            System.Drawing.Drawing2D.Matrix m = new System.Drawing.Drawing2D.Matrix();
            m.Translate(-rectF.X, -rectF.Y);
            path.Transform(m);

            AGT_TextureResource gdi = new AGT_TextureResource(rectF.Width, rectF.Height);
            if (gdi != null)
            {
                Graphics g = gdi.GetGraphics();
                if (g != null)
                {
                    g.FillPath(brush, path);
                    return gdi.ToBitmap();
                }
            }
            return null;
        }
        protected override void RenderFrameByAngle(PaintEventArgs e, Rectangle r)
        {
            Graphics g = e.Graphics;

            Matrix myMatrix = new Matrix();
            myMatrix.RotateAt(GaugeFrame.FrameColor.GradientAngle, GaugeFrame.Center);

            e.Graphics.Transform = myMatrix;

            using (Brush br = GaugeFrame.FrameColor.GetBrush(GaugeFrame.Bounds, 0))
                g.FillEllipse(br, GaugeFrame.Bounds);

            RenderFrameBorder(g);

            using (Brush br = GaugeFrame.FrameColor.GetBrush(r, 180))
                g.FillEllipse(br, r);

            g.ResetTransform();
        }
Ejemplo n.º 58
0
        internal static Map InitializeMap(float angle, string[] filenames)
        {
            if (filenames == null)
                return null;

            var providers = new SharpMap.Data.Providers.ShapeFile[filenames.Length];
            for (int i = 0; i < filenames.Length; i++)
            {
                providers[i] = new ShapeFile(filenames[i], true);
                providers[i].Open();
            }

            var map = LayerTools.GetMapForProviders(providers);

            Matrix mat = new Matrix();
            mat.RotateAt(angle, map.WorldToImage(map.Center));
            map.MapTransform = mat;

            return map;
        }
Ejemplo n.º 59
0
 public CanvasState(GraphicsState state, FontFamily family, string font, double lineWidth, double miterLimit,
                    string lineJoin, string lineCap, string globalCompositeOperation, double shadowOffsetX,
                    double shadowOffsetY, double shadowBlur, string shadowColor, string fillStyle,
                    string strokeStyle, Matrix transformation)
 {
     _graphicsState = state;
     _family = family;
     _font = font;
     _lineWidth = lineWidth;
     _miterLimit = miterLimit;
     _lineJoin = lineJoin;
     _lineCap = lineCap;
     _globalCompositeOperation = globalCompositeOperation;
     _shadowOffsetX = shadowOffsetX;
     _shadowOffsetY = shadowOffsetY;
     _shadowBlur = shadowBlur;
     _shadowColor = shadowColor;
     _fillStyle = fillStyle;
     _strokeStyle = strokeStyle;
     Transformation = transformation;
 }
Ejemplo n.º 60
0
        /// <summary>
        /// Generates a dictionary of Symbol id and rendered bitmap.
        /// </summary>
        /// <param name="v"></param>
        /// <returns></returns>
        public Dictionary<uint, Bitmap> GenerateMappedBitmaps(VexObject v, bool includeImages)
        {
            Dictionary<uint, Bitmap> result = new Dictionary<uint, Bitmap>();

            foreach (uint key in v.Definitions.Keys)
            {
                IDefinition def = v.Definitions[key];
                if (def is Symbol)
                {
                    Symbol symbol = (Symbol)def;
                    Bitmap myBitmap = new Bitmap(
                        (int)symbol.StrokeBounds.Size.Width + 1,
                        (int)symbol.StrokeBounds.Size.Height + 1);
                    myBitmap.SetResolution(96, 96);

                    translateMatrix = new System.Drawing.Drawing2D.Matrix(
                        1, 0, 0, 1, -symbol.StrokeBounds.Point.X, -symbol.StrokeBounds.Point.Y);
                    g = Graphics.FromImage(myBitmap);
                    g.SmoothingMode = SmoothingMode.AntiAlias;
                    g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    g.CompositingMode = CompositingMode.SourceOver;
                    g.CompositingQuality = CompositingQuality.AssumeLinear;

                    DrawSymbol(symbol);

                    result.Add(symbol.Id, myBitmap);
                    translateMatrix.Dispose();
                }
                else if (includeImages && def is Vex.Image)
                {
                    Bitmap bmp = new Bitmap(def.Path);
                    result.Add(def.Id, bmp);
                }
            }
            return result;
        }