Beispiel #1
0
        /// <summary>
        /// Draws the ninepatch at the specified point
        /// </summary>
        /// <param name="sb">The spritebatch to use for drawing</param>
        /// <param name="position">The position to draw it at (top left)</param>
        /// <param name="contentWidth">The width of the content inside the Ninepatch</param>
        /// <param name="contentHeight">The height of the content inside the Ninepatch</param>
        /// <param name="angle">The angle in degrees to rotate the ninepatch.</param>
        public void Draw(SpriteBatch sb, Vector2 position, int contentWidth, int contentHeight, float angle = 0, float alpha = 1)
        {
            var topLeft   = new Rectangle(1, 1, LeftMostPatch - 1, TopMostPatch - 1);
            var topMiddle = new Rectangle(LeftMostPatch, 1, (RightMostPatch - LeftMostPatch), TopMostPatch - 1);
            var topRight  = new Rectangle(RightMostPatch + 1, 1, (Texture.Width - 1) - RightMostPatch, TopMostPatch - 1);

            var left   = new Rectangle(1, TopMostPatch, LeftMostPatch - 1, (BottomMostPatch - TopMostPatch));
            var middle = new Rectangle(LeftMostPatch, TopMostPatch, (RightMostPatch - LeftMostPatch), (BottomMostPatch - TopMostPatch));
            var right  = new Rectangle(RightMostPatch + 1, TopMostPatch, (Texture.Width - 1) - RightMostPatch, (BottomMostPatch - TopMostPatch));

            var bottomLeft   = new Rectangle(1, BottomMostPatch, LeftMostPatch - 1, (Texture.Height - 1) - BottomMostPatch);
            var bottomMiddle = new Rectangle(LeftMostPatch, BottomMostPatch, (RightMostPatch - LeftMostPatch), (Texture.Height - 1) - BottomMostPatch);
            var bottomRight  = new Rectangle(RightMostPatch + 1, BottomMostPatch, (Texture.Width - 1) - RightMostPatch, (Texture.Height - 1) - BottomMostPatch);

            int   topMiddleWidth            = topMiddle.Width;
            int   leftMiddleHeight          = left.Height;
            float scaleMiddleByHorizontally = (contentWidth / (float)topMiddleWidth);
            float scaleMiddleByVertically   = (contentHeight / (float)leftMiddleHeight);

            Vector2 drawTl = position;
            Vector2 drawT  = drawTl + new Vector2(topLeft.Width, 0);
            Vector2 drawTr = drawT + new Vector2(topMiddle.Width * scaleMiddleByHorizontally, 0);

            Vector2 drawL = drawTl + new Vector2(0, topLeft.Height);
            Vector2 drawM = drawT + new Vector2(0, topMiddle.Height);
            Vector2 drawR = drawTr + new Vector2(0, topRight.Height);

            Vector2 drawBl = drawL + new Vector2(0, leftMiddleHeight * scaleMiddleByVertically);
            Vector2 drawBm = drawM + new Vector2(0, leftMiddleHeight * scaleMiddleByVertically);
            Vector2 drawBr = drawR + new Vector2(0, leftMiddleHeight * scaleMiddleByVertically);

            drawTl = RotateAroundOrigin(drawTl, position, angle);
            drawT  = RotateAroundOrigin(drawT, position, angle);
            drawTr = RotateAroundOrigin(drawTr, position, angle);

            drawL = RotateAroundOrigin(drawL, position, angle);
            drawM = RotateAroundOrigin(drawM, position, angle);
            drawR = RotateAroundOrigin(drawR, position, angle);

            drawBl = RotateAroundOrigin(drawBl, position, angle);
            drawBm = RotateAroundOrigin(drawBm, position, angle);
            drawBr = RotateAroundOrigin(drawBr, position, angle);

            var angR = (float)ConversionManager.DegreeToRadians(angle);

            sb.Draw(Texture, drawTl, topLeft, Color.White * alpha, angR, Vector2.Zero, Vector2.One, SpriteEffects.None, 0f);
            sb.Draw(Texture, drawT, topMiddle, Color.White * alpha, angR, Vector2.Zero, new Vector2(scaleMiddleByHorizontally, 1), SpriteEffects.None, 0f);
            sb.Draw(Texture, drawTr, topRight, Color.White * alpha, angR, Vector2.Zero, Vector2.One, SpriteEffects.None, 0f);

            sb.Draw(Texture, drawL, left, Color.White * alpha, angR, Vector2.Zero, new Vector2(1, scaleMiddleByVertically), SpriteEffects.None, 0f);
            sb.Draw(Texture, drawM, middle, Color.White * alpha, angR, Vector2.Zero, new Vector2(scaleMiddleByHorizontally, scaleMiddleByVertically), SpriteEffects.None, 0f);
            sb.Draw(Texture, drawR, right, Color.White * alpha, angR, Vector2.Zero, new Vector2(1, scaleMiddleByVertically), SpriteEffects.None, 0f);

            sb.Draw(Texture, drawBl, bottomLeft, Color.White * alpha, angR, Vector2.Zero, Vector2.One, SpriteEffects.None, 0f);
            sb.Draw(Texture, drawBm, bottomMiddle, Color.White * alpha, angR, Vector2.Zero, new Vector2(scaleMiddleByHorizontally, 1), SpriteEffects.None, 0f);
            sb.Draw(Texture, drawBr, bottomRight, Color.White * alpha, angR, Vector2.Zero, Vector2.One, SpriteEffects.None, 0f);
        }
        public void DegreeToRadiansTest()
        {
            double degree   = 0F; // TODO: Initialize to an appropriate value
            double expected = 0F; // TODO: Initialize to an appropriate value
            double actual;

            actual = ConversionManager.DegreeToRadians(degree);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
Beispiel #3
0
        /// <summary>
        /// Rotates a point with the specified angle
        /// </summary>
        /// <param name="point">The point to rotate</param>
        /// <param name="angle">The angle in degrees of the angle to rotate the point by.</param>
        /// <returns></returns>
        public static Vector2 RotatePoint(Vector2 point, double angle)
        {
            Vector2 real = point;
            Vector2 ret  = Vector2.Zero;

            //We need to use radians for Math.* functions
            angle = ConversionManager.DegreeToRadians(angle);
            ret.X = (float)((real.X * Math.Cos(angle)) - (real.Y * Math.Sin(angle)));
            ret.Y = (float)((real.X * Math.Sin(angle)) + (real.Y * Math.Cos(angle)));

            return(ret);
        }
Beispiel #4
0
        public override void OrderChildren(View parentView)
        {
            timeStep += step;
            double angle     = timeStep % 360;
            double angleStep = (360 / parentView.Children.Length);

            Vector2 center = new Vector2(parentView.ContentBoundBox.Width / 2, parentView.ContentBoundBox.Height / 2);

            foreach (View child in parentView.Children)
            {
                double rads = ConversionManager.DegreeToRadians(angle);

                child.X = (int)(-_radius * Math.Sin(rads));
                child.Y = (int)(_radius * Math.Cos(rads));

                child.Position.Value += center;
                child.Position.Value -= new Vector2(child.Width / 2, child.Height / 2);

                angle += angleStep;
            }
        }