Exemple #1
0
        internal static Texture2D GenGradTex(GradientPoint[] gp, Orientation gs)
        {
            List <GradientPoint> gradientPoints = gp.ToList <GradientPoint>();

            gradientPoints.OrderBy <GradientPoint, int>((g) => g.pxOffset);
            gradientPoints[0] = new GradientPoint(gradientPoints[0].color, 0);

            int       dim = gradientPoints[gradientPoints.Count - 1].pxOffset;
            Texture2D tex = null;

            switch (gs)
            {
            case Orientation.HORIZONTAL:
                tex = new Texture2D(GUI.game.GraphicsDevice, dim, 1);
                break;

            default:
                tex = new Texture2D(GUI.game.GraphicsDevice, 1, dim);
                break;
            }
            int length = gradientPoints[gradientPoints.Count - 1].pxOffset;

            for (int i = 0; i < gradientPoints.Count - 1; i++)
            {
                GradientPoint g1        = gradientPoints[i];
                GradientPoint g2        = gradientPoints[i + 1];
                Vector3       baseColor = new Vector3(g1.color.R, g1.color.G, g1.color.B) / 255;
                Vector3       stepColor = new Vector3(g2.color.R - g1.color.R, g2.color.G - g1.color.G, g2.color.B - g1.color.B) / (255 * g2.pxOffset - g1.pxOffset);
                for (int j = 0; j < g2.pxOffset - g1.pxOffset; j++)
                {
                    if (gs == Orientation.HORIZONTAL)
                    {
                        tex.SetData <Color>(0, new Rectangle(j + g1.pxOffset, 0, 1, 1), new[] { new Color(baseColor) }, 0, 1);
                    }
                    else
                    {
                        tex.SetData <Color>(0, new Rectangle(0, j + g1.pxOffset, 1, 1), new[] { new Color(baseColor) }, 0, 1);
                    }
                    baseColor += stepColor;
                }
            }
            return(tex);
        }
Exemple #2
0
        internal static Texture2D GenGradTex(GradientPoint[] gp, Orientation gs)
        {
            List<GradientPoint> gradientPoints = gp.ToList<GradientPoint>();
            gradientPoints.OrderBy<GradientPoint, int>((g) => g.pxOffset);
            gradientPoints[0] = new GradientPoint(gradientPoints[0].color, 0);

            int dim = gradientPoints[gradientPoints.Count - 1].pxOffset;
            Texture2D tex = null;
            switch (gs)
            {
                case Orientation.HORIZONTAL:
                    tex = new Texture2D(GUI.game.GraphicsDevice, dim, 1);
                    break;
                default:
                    tex = new Texture2D(GUI.game.GraphicsDevice, 1, dim);
                    break;
            }
            int length = gradientPoints[gradientPoints.Count - 1].pxOffset;
            for (int i = 0; i < gradientPoints.Count - 1; i++)
            {
                GradientPoint g1 = gradientPoints[i];
                GradientPoint g2 = gradientPoints[i + 1];
                Vector3 baseColor = new Vector3(g1.color.R, g1.color.G, g1.color.B) / 255;
                Vector3 stepColor = new Vector3(g2.color.R - g1.color.R, g2.color.G - g1.color.G, g2.color.B - g1.color.B) / (255 * g2.pxOffset - g1.pxOffset);
                for (int j = 0; j < g2.pxOffset - g1.pxOffset; j++)
                {
                    if (gs == Orientation.HORIZONTAL)
                        tex.SetData<Color>(0, new Rectangle(j + g1.pxOffset, 0, 1, 1), new[] { new Color(baseColor) }, 0, 1);
                    else
                        tex.SetData<Color>(0, new Rectangle(0, j + g1.pxOffset, 1, 1), new[] { new Color(baseColor) }, 0, 1);
                    baseColor += stepColor;
                }
            }
            return tex;
        }