Esempio n. 1
0
        public MapControl(UITile[,] map)
        {
            InitializeComponent();
            _tiles      = new TileStatus[map.GetLength(0), map.GetLength(1)];
            _vm         = new MapControlViewModel();
            DataContext = _vm;

            _vm.TileBitmap = new WriteableBitmap(BitmapHelper.CreateBitmap(map, TileHelper.UI_MAP_TILE_PIXELSIZE));

            for (int x = 0; x < map.GetLength(0); x++)
            {
                for (int y = 0; y < map.GetLength(1); y++)
                {
                    _tiles[x, y] = new TileStatus(x, y)
                    {
                        Tile = map[x, y]
                    };
                }
            }


            //Set the startup size of the grid. This should be immediately overwritten by the SizeChanged event firing, but this ensures we have a valid startup configuration.
            MapGrid.Width  = map.GetLength(0) * TileHelper.UI_MAP_TILE_PIXELSIZE;
            MapGrid.Height = map.GetLength(1) * TileHelper.UI_MAP_TILE_PIXELSIZE;
            _tileWidth     = TileHelper.UI_MAP_TILE_PIXELSIZE;

            //When the control is resized, resize the internal grid to fill the available space without stretching.
            SizeChanged += (sender, args) =>
            {
                double widthMult  = args.NewSize.Width / map.GetLength(0);
                double heightMult = args.NewSize.Height / map.GetLength(1);
                double mult       = Math.Min(widthMult, heightMult);
                var    width      = (int)Math.Floor(map.GetLength(0) * mult);
                var    height     = (int)Math.Floor(map.GetLength(1) * mult);
                MapGrid.Width  = width;
                MapGrid.Height = height;
                _tileWidth     = mult;
            };
        }
Esempio n. 2
0
 private static Int32Rect DeSelect(TileStatus tile, IntPtr backBufferPtr, int backBufferStride)
 {
     tile.Selected = false;
     return(BitmapHelper.OverwriteTile(backBufferPtr, backBufferStride, tile.Tile, tile.X, tile.Y, TileHelper.UI_MAP_TILE_PIXELSIZE));
 }