Example #1
0
        public override AgateLib.Geometry.Size MeasureString(FontState state, 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_FrameBuffer).BackBufferBitmap);

                disposeGraphics = true;
            }

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

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


            result.Height *= (float)state.ScaleWidth;
            result.Width  *= (float)state.ScaleHeight;

            return(new Geometry.Size((int)result.Width, (int)result.Height));
        }
Example #2
0
        /// <summary>
        /// Creates a Drawing_Surface object which wraps the specified image.
        /// </summary>
        /// <param name="image"></param>
        public Drawing_Surface(Bitmap image)
        {
            mDisplay = Display.Impl as Drawing_Display;

            mImage = image;

            System.Diagnostics.Debug.Assert(mImage != null);
        }
Example #3
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);
        }
Example #4
0
        public Drawing_Surface(Stream st)
        {
            mDisplay = Display.Impl as Drawing_Display;

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

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

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

            System.Diagnostics.Debug.Assert(mImage != null);
        }
Example #6
0
        /// <summary>
        /// Creates a Drawing_Surface object and copies pixels from the specified image.
        /// </summary>
        /// <param name="image"></param>
        /// <param name="sourceRect"></param>
        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();


            System.Diagnostics.Debug.Assert(mImage != null);
        }
Example #7
0
        public override void DrawText(FontState state)
        {
            Geometry.PointF shift = Origin.CalcF(state.DisplayAlignment,
                                                 MeasureString(state, state.Text));

            PointF dest_pt = Interop.Convert(state.Location);

            dest_pt.X -= shift.X;
            dest_pt.Y -= shift.Y;

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

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

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

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

            g.Restore(g_state);
        }
Example #8
0
        private void Draw(SurfaceState s, SurfaceDrawInstance inst)
        {
            mDisplay.CheckInFrame("Surface.Draw");
            System.Diagnostics.Debug.Assert(mImage != null);

            Geometry.SizeF  displaySize    = s.GetDisplaySize(SurfaceSize);
            Geometry.PointF rotationCenter = s.GetRotationCenter(displaySize);

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

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

            if (displaySize.Width < 0)
            {
                translatePoint.X += displaySize.Width;
                rotationCenter.X += displaySize.Width;
            }
            if (displaySize.Height < 0)
            {
                translatePoint.Y += displaySize.Height;
                rotationCenter.Y += displaySize.Height;
            }

            if (s.RotationAngle != 0)
            {
                // translate to rotation point, rotate, and translate back.
                // System.Drawing rotates Clockwise!  So we must reverse the
                // rotation angle.
                g.TranslateTransform(-rotationCenter.X, -rotationCenter.Y, MatrixOrder.Append);
                g.RotateTransform(-(float)s.RotationAngleDegrees, MatrixOrder.Append);
                g.TranslateTransform(rotationCenter.X, rotationCenter.Y, MatrixOrder.Append);
            }

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

            SetInterpolation(g);

            Geometry.Rectangle srcRect = inst.GetSourceRect(SurfaceSize);

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

                ColorMatrix colorMatrix = new ColorMatrix(new float[][] {
                    new float[] { s.Color.R / 255.0f, 0.0f, 0.0f, 0.0f, 0.0f },
                    new float[] { 0.0f, s.Color.G / 255.0f, 0.0f, 0.0f, 0.0f },
                    new float[] { 0.0f, 0.0f, s.Color.B / 255.0f, 0.0f, 0.0f },
                    new float[] { 0.0f, 0.0f, 0.0f, (float)s.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, s.ScaleWidth, s.ScaleHeight)),
                            srcRect.X,
                            srcRect.Y,
                            srcRect.Width,
                            srcRect.Height,
                            GraphicsUnit.Pixel,
                            imageAttributes);
            }
            else
            {
                g.DrawImage(mImage, Interop.Convert(DestRect(0, 0, srcRect, s.ScaleWidth, s.ScaleHeight)),
                            srcRect.X,
                            srcRect.Y,
                            srcRect.Width,
                            srcRect.Height,
                            GraphicsUnit.Pixel);
            }

            g.Restore(state);
        }
 public DrawingBasic2DShader()
 {
     mDisplay = AgateLib.DisplayLib.Display.Impl as Drawing_Display;
 }