Exemplo n.º 1
0
        public void RenderSliderHorizontal(SpriteFont font, Rectangle boundingRect, float value, float minvalue, float maxValue, Slider.SliderMode mode, bool drawLabel, bool invertValue, SpriteBatch spriteBatch)
        {
            const int padding = 5;

            if (invertValue)
            {
                value = maxValue - value;
            }

            int       fieldSize = Math.Max(Math.Min((int)(0.2f * boundingRect.Width), 150), 64);
            Rectangle rect      = new Rectangle(boundingRect.X + padding, boundingRect.Y + boundingRect.Height / 2 - TileHeight / 2, boundingRect.Width - fieldSize - padding * 2, boundingRect.Height / 2);
            Rectangle fieldRect = new Rectangle(boundingRect.Right - fieldSize, boundingRect.Y + boundingRect.Height / 2 - TileHeight / 2, fieldSize, boundingRect.Height / 2);
            int       maxX      = rect.X + rect.Width;
            int       diffX     = rect.Width % TileWidth;
            int       right     = maxX;
            int       left      = rect.X;
            int       top       = rect.Y;


            for (int x = left; x <= right; x += TileWidth)
            {
                spriteBatch.Draw(Texture, new Rectangle(x, rect.Y, TileWidth, TileHeight), GetSourceRect(Tile.Track), Color.White);
            }

            spriteBatch.Draw(Texture, new Rectangle(maxX - diffX, rect.Y, diffX, TileHeight), GetSourceRect(Tile.Track), Color.White);

            int sliderX = (int)((value - minvalue) / (maxValue - minvalue) * rect.Width + rect.X);

            spriteBatch.Draw(Texture, new Rectangle(sliderX - TileWidth / 2, rect.Y, TileWidth, TileHeight), GetSourceRect(Tile.SliderTex), Color.White);

            if (!drawLabel)
            {
                return;
            }
            RenderField(fieldRect, spriteBatch);

            float v = 0.0f;

            if (invertValue)
            {
                value = value - maxValue;
            }
            if (mode == Slider.SliderMode.Float)
            {
                v = (float)Math.Round(value, 2);
            }
            else
            {
                v = (int)value;
            }

            string toDraw = "" + v;

            Vector2 origin = Datastructures.SafeMeasure(font, toDraw) * 0.5f;

            Drawer2D.SafeDraw(spriteBatch, toDraw, font, Color.Black, new Vector2(fieldRect.X + fieldRect.Width / 2, fieldRect.Y + 16), origin);
        }
Exemplo n.º 2
0
        public void RenderSliderVertical(SpriteFont font, Rectangle boundingRect, float value, float minvalue, float maxValue, Slider.SliderMode mode, bool drawLabel, bool invert, SpriteBatch spriteBatch)
        {
            const int padding = 5;

            if (invert)
            {
                value = maxValue - value;
            }


            int       fieldSize = Math.Max(Math.Min((int)(0.2f * boundingRect.Width), 150), 64);
            Rectangle rect      = new Rectangle(boundingRect.X + boundingRect.Width / 2 - TileWidth / 2, boundingRect.Y + padding, boundingRect.Width, boundingRect.Height - TileHeight - padding * 2);
            Rectangle fieldRect = new Rectangle(boundingRect.Right - fieldSize, boundingRect.Y + boundingRect.Height - TileHeight / 2, fieldSize, TileHeight);

            int maxY   = rect.Y + rect.Height;
            int diffY  = rect.Height % TileHeight;
            int bottom = maxY;
            int left   = rect.X;
            int top    = rect.Y;


            for (int y = top; y <= bottom; y += TileHeight)
            {
                spriteBatch.Draw(Texture, new Rectangle(rect.X, y, TileWidth, TileHeight), GetSourceRect(Tile.TrackVert), Color.White);
            }

            spriteBatch.Draw(Texture, new Rectangle(rect.X, maxY - diffY, TileWidth, diffY), GetSourceRect(Tile.TrackVert), Color.White);

            float d = (value - minvalue) / (maxValue - minvalue);

            int sliderY = (int)((d) * rect.Height + rect.Y);

            spriteBatch.Draw(Texture, new Rectangle(rect.X, sliderY - TileHeight / 2, TileWidth, TileHeight), GetSourceRect(Tile.SliderVertical), Color.White);

            if (!drawLabel)
            {
                return;
            }

            RenderField(fieldRect, spriteBatch);

            if (invert)
            {
                value = -(value - maxValue);
            }

            float v = 0.0f;

            if (mode == Slider.SliderMode.Float)
            {
                v = (float)Math.Round(value, 2);
            }
            else
            {
                v = (int)value;
            }

            string toDraw = "" + v;

            Vector2 origin = Datastructures.SafeMeasure(font, toDraw) * 0.5f;

            Drawer2D.SafeDraw(spriteBatch, toDraw, font, Color.Black, new Vector2(fieldRect.X + fieldRect.Width / 2, fieldRect.Y + 16), origin);
        }