Exemple #1
0
        public override void Draw(SpriteBatch spriteBatch)
        {
            Point     pos       = base.DrawPosition.ToPoint();
            Rectangle rectangle = new Rectangle(pos.X, pos.Y, (int)GetWidth(), (int)GetHeight());

            Rectangle value = new Rectangle(0, 0, 1, 1);
            float     r     = 1f;

            if (isSelect)
            {
                r = .25f;
            }
            float g      = 0.9f;
            float b      = 0.1f;
            float a      = 1f;
            float scale2 = 0.6f;
            Color color  = PaintToolsHotbar.buffColor(Color.White, r, g, b, a);

            if (isSelect)
            {
                spriteBatch.Draw(Main.magicPixel, rectangle, color * scale2);
            }

            SpriteEffects effects = SpriteEffects.None;

            if (stampInfo.bFlipHorizontal)
            {
                effects |= SpriteEffects.FlipHorizontally;
            }
            if (stampInfo.bFlipVertical)
            {
                effects |= SpriteEffects.FlipVertically;
            }

            spriteBatch.Draw(texture, base.DrawPosition, null, Color.White, 0f, Vector2.Zero, base.Scale, effects, 0f);

            if (isSelect)
            {
                b      = 0.3f;
                g      = 0.95f;
                scale2 = (a = 1f);
                color  = PaintToolsHotbar.buffColor(Color.White, r, g, b, a);
                spriteBatch.Draw(Main.magicPixel, new Rectangle(pos.X, pos.Y, rectangle.Width, 2), color * scale2);
                spriteBatch.Draw(Main.magicPixel, new Rectangle(pos.X, pos.Y, 2, rectangle.Height), color * scale2);
                spriteBatch.Draw(Main.magicPixel, new Rectangle(pos.X + rectangle.Width - 2, pos.Y, 2, rectangle.Height), color * scale2);
                spriteBatch.Draw(Main.magicPixel, new Rectangle(pos.X, pos.Y + rectangle.Height - 2, rectangle.Width, 2), color * scale2);
            }

            base.Draw(spriteBatch);
        }
        internal Texture2D MakeThumbnail(StampInfo stampInfo)
        {
            int desiredWidth  = 100;
            int desiredHeight = 100;

            int actualWidth  = stampInfo.Width;
            int actualHeight = stampInfo.Height;

            float   scale  = 1;
            Vector2 offset = new Vector2();

            if (actualWidth > desiredWidth || actualHeight > desiredHeight)
            {
                if (actualHeight > actualWidth)
                {
                    scale    = (float)desiredWidth / actualHeight;
                    offset.X = (desiredWidth - actualWidth * scale) / 2;
                }
                else
                {
                    scale    = (float)desiredWidth / actualWidth;
                    offset.Y = (desiredHeight - actualHeight * scale) / 2;
                }
            }
            offset = offset / scale;

            RenderTarget2D renderTarget = new RenderTarget2D(Main.graphics.GraphicsDevice, desiredWidth, desiredHeight);

            Main.instance.GraphicsDevice.SetRenderTarget(renderTarget);
            Main.instance.GraphicsDevice.Clear(Color.Transparent);
            Main.spriteBatch.Begin();

            PaintToolsHotbar.DrawPreview(Main.spriteBatch, stampInfo.Tiles, offset, scale);

            Main.spriteBatch.End();
            Main.instance.GraphicsDevice.SetRenderTarget(null);

            Texture2D mergedTexture = new Texture2D(Main.instance.GraphicsDevice, desiredWidth, desiredHeight);

            Color[] content = new Color[desiredWidth * desiredHeight];
            renderTarget.GetData <Color>(content);
            mergedTexture.SetData <Color>(content);
            return(mergedTexture);
        }