void ClearTile(int x, int y, int width, int height, int srcX, FastBitmap dst)
        {
            Rectangle srcRect = new Rectangle(srcX, 0, tileSize, tileSize);
            Rectangle dstRect = new Rectangle(x, y, width, height);

            BitmapDrawer.DrawTiled(terrainPixels, dst, srcRect, dstRect);
        }
Example #2
0
        public void SetUp()
        {
            var textColorGenerator = Substitute.For <ITextColorGenerator>();

            textColorGenerator.GetTextColor(Arg.Any <int>()).Returns(textColor);

            fontSizeCalculator = Substitute.For <IFontSizeCalculator>();
            fontSizeCalculator.CalculateFontSize(Arg.Any <int>()).Returns(fontSize);
            fontSizeCalculatorFactory = Substitute.For <IFontSizeCalculatorFactory>();
            fontSizeCalculatorFactory.Create(Arg.Any <int>(), Arg.Any <int>()).Returns(fontSizeCalculator);

            imageSettings = new CloudImageSettings(
                new Size(500, 500),
                Color.Black,
                new FontFamily("Arial"),
                textColorGenerator,
                fontSizeCalculatorFactory);

            cloudLayouter = Substitute.For <ICloudLayouter>();
            cloudLayouter.PutNextRectangle(Arg.Any <Size>())
            .Returns(c => new Rectangle(Point.Empty, c.Arg <Size>()));
            cloudLayouterFactory = Substitute.For <ICloudLayouterFactory>();
            cloudLayouterFactory.Create(Arg.Any <Point>()).Returns(cloudLayouter);

            bitmapDrawer = new BitmapDrawer(imageSettings, cloudLayouterFactory);
        }
        public BitmapDrawerTests()
        {
            _bitmapChannel  = MockRepository.GenerateStub <IBitmapChannel>();
            _graphicsGetter = MockRepository.GenerateStub <IGraphicsGetter>();
            _graphics       = MockRepository.GenerateStub <Graphics>();
            _graphicsGetter.Stub(x => x.FromImage(null)).IgnoreArguments().Return(_graphics);

            _target = new BitmapDrawer();
        }
Example #4
0
 public Application(
     IFileReader fileReader,
     ITextParser textParser,
     BitmapDrawer bitmapDrawer,
     ImageFormat imageFormat)
 {
     this.bitmapDrawer = bitmapDrawer;
     this.fileReader   = fileReader;
     this.textParser   = textParser;
     this.imageFormat  = imageFormat;
 }
Example #5
0
        public void DrawFlags()
        {
            using (FastBitmap dst = game.LockBits()) {
                for (int i = table.CurrentIndex; i < maxIndex; i++)
                {
                    int        x = table.X, y = table.usedEntries[i].Y;
                    FastBitmap flag = GetFlag(table.usedEntries[i].Flag);
                    if (flag == null)
                    {
                        continue;
                    }

                    Rectangle rect = new Rectangle(x + 2, y + 3, 16, 11);
                    BitmapDrawer.Draw(flag, dst, rect);
                }
            }
        }
        void MakeClassicTextures(Bitmap bmp)
        {
            int  elemSize = bmp.Width / 16;
            Size size     = new Size(tileSize, tileSize);

            terrainBmp    = Platform.CreateBmp(tileSize * 2, tileSize);
            terrainPixels = new FastBitmap(terrainBmp, true, false);

            // Precompute the scaled background
            using (FastBitmap src = new FastBitmap(bmp, true, true)) {
                BitmapDrawer.DrawScaled(src, terrainPixels, size,
                                        new Rectangle(2 * elemSize, 0, elemSize, elemSize),
                                        new Rectangle(tileSize, 0, tileSize, tileSize), 128, 64);
                BitmapDrawer.DrawScaled(src, terrainPixels, size,
                                        new Rectangle(1 * elemSize, 0, elemSize, elemSize),
                                        new Rectangle(0, 0, tileSize, tileSize), 96, 96);
            }
        }
Example #7
0
        public void DrawFlags()
        {
            using (FastBitmap dst = game.LockBits()) {
                for (int i = table.CurrentIndex; i < maxIndex; i++)
                {
                    TableEntry entry = table.Get(i);
                    FastBitmap flag  = GetFlag(entry.Flag);
                    if (flag == null)
                    {
                        continue;
                    }

                    int       x = table.X, y = entry.Y;
                    Rectangle rect = new Rectangle(x + 2, y + 3, 16, 11);
                    BitmapDrawer.Draw(flag, dst, rect);
                }
            }
        }
Example #8
0
        private static bool TestBitMapSaving()
        {
            string jpgPath =
                Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                                              @"..\..\..\PV178.Homeworks.HW05\Content\Map\map.jpg"));

            using (var bitmapStream = MapImageIO.LoadImgToStream(jpgPath))
            {
                Bitmap       bmp       = new Bitmap(bitmapStream);
                BitmapDrawer bmpDrawer = new BitmapDrawer(bitmapStream);

                using (var resultStream = bmpDrawer.SaveBitmapToStream())
                    using (var expectedStream = new MemoryStream())
                    {
                        bmp.Save(expectedStream, bmp.RawFormat);

                        if (resultStream.Length != expectedStream.Length)
                        {
                            return(false);
                        }

                        int resultByte, expectedByte;

                        do
                        {
                            resultByte   = resultStream.ReadByte();
                            expectedByte = expectedStream.ReadByte();

                            if (resultByte != expectedByte)
                            {
                                return(false);
                            }
                        } while (resultByte != -1 && expectedByte != -1);

                        return(true);
                    }
            }
        }
        public override void Redraw(IDrawer2D drawer)
        {
            if (Window.Minimised || !Visible)
            {
                return;
            }
            Rectangle rect = new Rectangle(X, Y, Width, Height / 2);

            using (FastBitmap bmp = Window.LockBits()) {
                Gradient.Vertical(bmp, rect, boxTop, boxBottom);
                rect.Y += rect.Height;
                Gradient.Vertical(bmp, rect, boxBottom, boxTop);

                if (Value)
                {
                    const int size = 12;
                    int       x    = X + Width / 2 - size / 2;
                    int       y    = Y + Height / 2 - size / 2;
                    BitmapDrawer.DrawIndexed(indices, palette, size, x, y, bmp);
                }
            }
            drawer.DrawRectBounds(FastColour.Black, 1, X, Y, Width - 1, Height - 1);
        }