コード例 #1
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);
        }
コード例 #2
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);
        }