예제 #1
0
        private void DrawImpl(float destX, float destY)
        {
            if (mFrames.Count == 0)
            {
                return;
            }
            if (mVisible == false)
            {
                return;
            }

            SpriteFrame currentFrame = CurrentFrame;
            Surface     surf         = currentFrame.Surface;

            currentFrame.DisplaySize = DisplaySize;

            PointF alignment = Origin.CalcF(DisplayAlignment, DisplaySize);
            PointF rotation  = Origin.CalcF(RotationCenter, DisplaySize);

            surf.Alpha            = Alpha;
            surf.DisplayAlignment = OriginAlignment.TopLeft;
            surf.RotationAngle    = RotationAngle;
            surf.Color            = Color;

            currentFrame.Draw(destX - alignment.X, destY - alignment.Y,
                              rotation.X, rotation.Y);
        }
예제 #2
0
        protected void DrawWithoutVB(float destX, float destY, bool alphaBlend)
        {
            // find center
            PointF rotation = Origin.CalcF(RotationCenter, DisplaySize);

            DrawWithoutVB(destX, destY, mSrcRect, rotation.X, rotation.Y, alphaBlend);
        }
예제 #3
0
        private void SetVertsPosition(PositionColorNormalTexture[] verts, int index,
                                      RectangleF dest, float rotationCenterX, float rotationCenterY)
        {
            float destX      = dest.X - 0.5f;
            float destY      = dest.Y - 0.5f;
            float destWidth  = dest.Width;
            float destHeight = dest.Height;


            mCenterPoint = Origin.CalcF(DisplayAlignment, dest.Size);

            destX += rotationCenterX - mCenterPoint.X;
            destY += rotationCenterY - mCenterPoint.Y;

            // Point at (0, 0) local coordinates
            verts[index].X = mRotationCos * (-rotationCenterX) +
                             mRotationSin * (-rotationCenterY) + destX;

            verts[index].Y = -mRotationSin * (-rotationCenterX) +
                             mRotationCos * (-rotationCenterY) + destY;

            // Point at (DisplayWidth, 0) local coordinates
            verts[index + 1].X = mRotationCos * (-rotationCenterX + destWidth) +
                                 mRotationSin * (-rotationCenterY) + destX;

            verts[index + 1].Y = -mRotationSin * (-rotationCenterX + destWidth) +
                                 mRotationCos * (-rotationCenterY) + destY;

            // Point at (0, DisplayHeight) local coordinates
            verts[index + 2].X = mRotationCos * (-rotationCenterX) +
                                 mRotationSin * (-rotationCenterY + destHeight) + destX;

            verts[index + 2].Y = (-mRotationSin * (-rotationCenterX) +
                                  mRotationCos * (-rotationCenterY + destHeight)) + destY;

            // Point at (DisplayWidth, DisplayHeight) local coordinates
            verts[index + 3].X = mRotationCos * (-rotationCenterX + destWidth) +
                                 mRotationSin * (-rotationCenterY + destHeight) + destX;

            verts[index + 3].Y = -mRotationSin * (-rotationCenterX + destWidth) +
                                 mRotationCos * (-rotationCenterY + destHeight) + destY;

            for (int i = 0; i < 4; i++)
            {
                verts[index + i].nx = 0;
                verts[index + i].ny = 0;
                verts[index + i].nz = -1;
            }
        }
예제 #4
0
        private void AddRectToVB(PositionColorNormalTexture[] verts, int startIndex,
                                 RectangleF srcRect, RectangleF destRect)
        {
            // find center
            PointF centerpt = Origin.CalcF(DisplayAlignment, DisplaySize);

            float left   = destRect.Left - 0.5f;
            float top    = destRect.Top - 0.5f;
            float right  = destRect.Right - 0.5f;           // +(float)Math.Floor(destRect.Width / (float)srcRect.Width);
            float bottom = destRect.Bottom - 0.5f;          // +(float)Math.Floor(destRect.Height / (float)srcRect.Height);

            PointF[] corners = new PointF[4]
            {
                new PointF(left, top),
                new PointF(right, top),
                new PointF(left, bottom),
                new PointF(right, bottom)
            };

            PointF[] uv = new PointF[4]
            {
                new PointF(mSrcRect.Left + srcRect.Left, mSrcRect.Top + srcRect.Top),
                new PointF(mSrcRect.Left + srcRect.Right, mSrcRect.Top + srcRect.Top),
                new PointF(mSrcRect.Left + srcRect.Left, mSrcRect.Top + srcRect.Bottom),
                new PointF(mSrcRect.Left + srcRect.Right, mSrcRect.Top + srcRect.Bottom)
            };

            TranslatePointInPlace(ref corners, centerpt);


            for (int i = 0; i < 4; i++)
            {
                verts[startIndex + i] = new PositionColorNormalTexture(
                    corners[i].X, corners[i].Y, 0.0F, Color.ToArgb(),
                    uv[i].X / (float)mTextureSize.Width, uv[i].Y / (float)mTextureSize.Height,
                    0, 0, -1);
            }
        }
예제 #5
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);
        }
예제 #6
0
        private void SetPoints(PointF[] pt, float destX, float destY, float rotationCenterX, float rotationCenterY,
                               float destWidth, float destHeight)
        {
            const int index       = 0;
            PointF    centerPoint = Origin.CalcF(DisplayAlignment, new SizeF(destWidth, destHeight));

            destX += rotationCenterX - centerPoint.X;
            destY += rotationCenterY - centerPoint.Y;

            // Point at (0, 0) local coordinates
            pt[index].X = mRotationCos * (-rotationCenterX) +
                          mRotationSin * (-rotationCenterY) + destX;

            pt[index].Y = -mRotationSin * (-rotationCenterX) +
                          mRotationCos * (-rotationCenterY) + destY;

            // Point at (DisplayWidth, 0) local coordinates
            pt[index + 1].X = mRotationCos * (-rotationCenterX + destWidth) +
                              mRotationSin * (-rotationCenterY) + destX;

            pt[index + 1].Y = -mRotationSin * (-rotationCenterX + destWidth) +
                              mRotationCos * (-rotationCenterY) + destY;

            // Point at (DisplayWidth, DisplayHeight) local coordinates
            pt[index + 2].X = mRotationCos * (-rotationCenterX + destWidth) +
                              mRotationSin * (-rotationCenterY + destHeight) + destX;

            pt[index + 2].Y = -mRotationSin * (-rotationCenterX + destWidth) +
                              mRotationCos * (-rotationCenterY + destHeight) + destY;

            // Point at (0, DisplayHeight) local coordinates
            pt[index + 3].X = mRotationCos * (-rotationCenterX) +
                              mRotationSin * (-rotationCenterY + destHeight) + destX;

            pt[index + 3].Y = (-mRotationSin * (-rotationCenterX) +
                               mRotationCos * (-rotationCenterY + destHeight)) + destY;
        }
예제 #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);
        }
예제 #8
0
        /// <summary>
        /// Draw the sprite to the given destination rectangle.
        /// Overrides scaling settings.
        /// </summary>
        /// <param name="destRect"></param>
        public void Draw(Rectangle destRect)
        {
            if (mFrames.Count == 0)
            {
                return;
            }

            SpriteFrame current = (SpriteFrame)CurrentFrame;

            current.DisplaySize = destRect.Size;
            Surface surf = current.Surface;

            PointF alignment = Origin.CalcF(DisplayAlignment, DisplaySize);
            PointF rotation  = Origin.CalcF(RotationCenter, DisplaySize);

            surf.Alpha            = Alpha;
            surf.DisplayAlignment = DisplayAlignment;
            surf.RotationAngle    = RotationAngle;
            surf.RotationCenter   = RotationCenter;
            surf.Color            = Color;

            current.Draw(destRect.X - alignment.X, destRect.Y - alignment.Y,
                         rotation.X, rotation.Y);
        }
예제 #9
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);
        }
예제 #10
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);
        }
예제 #11
0
        /// <summary>
        /// For function use, see documentation of Surface.
        ///
        /// Info for developers:
        /// This method should draw the surface to the screen, using all the
        /// scaling, rotation, etc. state data in the stored Surface object.
        /// </summary>
        /// <param name="destX"></param>
        /// <param name="destY"></param>
        public virtual void Draw(float destX, float destY)
        {
            Geometry.PointF rotatePoint = Origin.CalcF(RotationCenter, DisplaySize);

            Draw(destX, destY, rotatePoint.X, rotatePoint.Y);
        }