Esempio n. 1
0
        public override void Initialize(Microsoft.Xna.Framework.Content.ContentManager content, GraphicsDevice graphics)
        {
            border      = new Texture2D(graphics, (int)Width, (int)Height, false, SurfaceFormat.Color);
            progressBar = new Texture2D(graphics, (int)Width - 4, border.Height - 4, false, SurfaceFormat.Color);

            Height = border.Height;

            area.Width  = (int)Width;
            area.Height = (int)Height;

            sourceRect = new Rectangle(0, 0, progressBar.Width, progressBar.Height);
            destRect   = new Rectangle((int)Position.X + 2, (int)Position.Y + 2, (int)(progressBar.Width * value / 100f), progressBar.Height);

            Color[] pixel = new Color[border.Width * border.Height];

            for (int y = 0; y < border.Height; y++)
            {
                for (int x = 0; x < border.Width; x++)
                {
                    if (x == 0 || y == 0 || x == border.Width - 1 || y == border.Height - 1)
                    {
                        pixel[x + y * border.Width] = Color.Black;

                        if ((x == 0 && y == 0) || (x == border.Width - 1 && y == 0) ||
                            (x == 0 && y == border.Height - 1) || (x == border.Width - 1 && y == border.Height - 1))
                        {
                            pixel[x + y * border.Width] = Color.Transparent;
                        }
                    }
                    else
                    {
                        pixel[x + y * border.Width] = new Color(new Vector4(BackColor.ToVector3(), 1f));
                    }
                }
            }

            border.SetData <Color>(pixel);

            pixel = new Color[progressBar.Width * progressBar.Height];

            for (int y = 0; y < progressBar.Height; y++)
            {
                for (int x = 0; x < progressBar.Width; x++)
                {
                    bool bInvisiblePixel = false;

                    if (style == Style.Blocks)
                    {
                        int xPos = x % (int)((float)progressBar.Width / (float)numberOfBlocks);
                        if (xPos == 0)
                        {
                            bInvisiblePixel = true;
                        }
                    }

                    if (!bInvisiblePixel)
                    {
                        float gradient   = 1.0f - y * 0.035f;
                        Color pixelColor = new Color(new Vector4(ForeColor.ToVector3() * gradient, 1f));
                        pixel[x + y * progressBar.Width] = pixelColor;
                    }
                }
            }

            progressBar.SetData <Color>(pixel);

            base.Initialize(content, graphics);
        }