Beispiel #1
0
        public override Geometry.Size StringDisplaySize(string text)
        {
            Drawing_Display disp            = Display.Impl as Drawing_Display;
            Graphics        g               = disp.FrameGraphics;
            bool            disposeGraphics = false;

            if (g == null)
            {
                g = Graphics.FromImage((disp.RenderTarget.Impl as Drawing_IRenderTarget).BackBuffer);

                disposeGraphics = true;
            }

            SizeF  result = new SizeF(g.MeasureString(text, mFont));
            double scalex, scaley;

            if (disposeGraphics)
            {
                g.Dispose();
            }

            GetScale(out scalex, out scaley);

            result.Height *= (float)scalex;
            result.Width  *= (float)scaley;

            return(new Geometry.Size((int)result.Width, (int)result.Height));
        }
Beispiel #2
0
        public Drawing_Surface(Geometry.Size sz)
        {
            mDisplay = Display.Impl as Drawing_Display;

            mImage = new Bitmap(sz.Width, sz.Height);

            System.Diagnostics.Debug.Assert(mImage != null);
        }
Beispiel #3
0
        public Drawing_Surface(Stream st)
        {
            mDisplay = Display.Impl as Drawing_Display;

            mImage = (Bitmap)Bitmap.FromStream(st);
            ConvertImage();

            System.Diagnostics.Debug.Assert(mImage != null);
        }
Beispiel #4
0
        public Drawing_Surface(string fileName)
        {
            mDisplay = Display.Impl as Drawing_Display;

            mImage = (Bitmap)Image.FromFile(fileName);
            ConvertImage();

            System.Diagnostics.Debug.Assert(mImage != null);
        }
Beispiel #5
0
        public Drawing_Surface(Bitmap image, Rectangle sourceRect)
        {
            mDisplay = Display.Impl as Drawing_Display;

            // copy the pixels from the srcRect
            mImage = new Bitmap(sourceRect.Width, sourceRect.Height);

            Graphics g = Graphics.FromImage(mImage);

            g.DrawImage(image,
                        new Rectangle(0, 0, sourceRect.Width, sourceRect.Height),
                        (Rectangle)sourceRect, GraphicsUnit.Pixel);

            g.Dispose();
        }
Beispiel #6
0
        public override void DrawPoints(Geometry.Point[] destPts)
        {
            mDisplay.CheckInFrame("Surface.Draw");
            System.Diagnostics.Debug.Assert(mImage != null);

            Drawing_Display disp = Display.Impl as Drawing_Display;
            Graphics        g    = disp.FrameGraphics;

            Point[] pts = new Point[destPts.Length];

            for (int i = 0; i < pts.Length; i++)
            {
                pts[i] = Interop.Convert(destPts[i]);
            }

            g.DrawImage(mImage, pts);
        }
Beispiel #7
0
        public override void DrawText(Geometry.PointF dest_pt, string text)
        {
            Geometry.PointF dest = Origin.CalcF(DisplayAlignment, StringDisplaySize(text));

            dest_pt.X -= dest.X;
            dest_pt.Y -= dest.Y;

            Drawing_Display disp = Display.Impl as Drawing_Display;
            Graphics        g    = disp.FrameGraphics;

            GraphicsState state = g.Save();
            double        scalex, scaley;

            GetScale(out scalex, out scaley);

            g.TranslateTransform(dest_pt.X, dest_pt.Y);
            g.ScaleTransform((float)scalex, (float)scaley);

            g.DrawString(text, mFont,
                         new SolidBrush(Interop.Convert(Color)), Point.Empty);

            g.Restore(state);
        }
Beispiel #8
0
        public override void Draw(float destX, float destY, Geometry.Rectangle srcRect, float rotationCenterX, float rotationCenterY)
        {
            mDisplay.CheckInFrame("Surface.Draw");

            PointF destPt = new PointF(destX, destY);


            System.Diagnostics.Debug.Assert(mImage != null);

            Drawing_Display disp  = Display.Impl as Drawing_Display;
            Graphics        g     = disp.FrameGraphics;
            GraphicsState   state = g.Save();

            Geometry.PointF translatePoint = Origin.CalcF(DisplayAlignment, DisplaySize);


            if (DisplaySize.Width < 0)
            {
                translatePoint.X += DisplaySize.Width;
                rotationCenterX  += DisplaySize.Width;
            }

            if (DisplaySize.Height < 0)
            {
                translatePoint.Y += DisplaySize.Height;
                rotationCenterY  += DisplaySize.Height;
            }

            // translate to rotation point, rotate, and translate back.
            // System.Drawing rotates Clockwise!  So we must reverse the
            // rotation angle.
            g.TranslateTransform(-rotationCenterX, -rotationCenterY, MatrixOrder.Append);
            g.RotateTransform(-(float)RotationAngleDegrees, MatrixOrder.Append);
            g.TranslateTransform(rotationCenterX, rotationCenterY, MatrixOrder.Append);

            SetInterpolation(g);

            g.TranslateTransform(destPt.X - translatePoint.X,
                                 destPt.Y - translatePoint.Y, MatrixOrder.Append);

            if (Color != Geometry.Color.White)
            {
                ImageAttributes imageAttributes = new ImageAttributes();

                ColorMatrix colorMatrix = new ColorMatrix(new float[][] {
                    new float[] { Color.R / 255.0f, 0.0f, 0.0f, 0.0f, 0.0f },
                    new float[] { 0.0f, Color.G / 255.0f, 0.0f, 0.0f, 0.0f },
                    new float[] { 0.0f, 0.0f, Color.B / 255.0f, 0.0f, 0.0f },
                    new float[] { 0.0f, 0.0f, 0.0f, (float)Alpha, 0.0f },
                    new float[] { 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }
                });

                imageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);

                g.DrawImage(mImage, Interop.Convert(DestRect(0, 0, srcRect)),
                            srcRect.X,
                            srcRect.Y,
                            srcRect.Width,
                            srcRect.Height,
                            GraphicsUnit.Pixel,
                            imageAttributes);
            }
            else
            {
                g.DrawImage(mImage, Interop.Convert(DestRect(0, 0, srcRect)),
                            srcRect.X,
                            srcRect.Y,
                            srcRect.Width,
                            srcRect.Height,
                            GraphicsUnit.Pixel);
            }

            g.Restore(state);
        }