示例#1
0
        public void CoordsToWorldPixels_DefaultScale(int col, int row, int expectedX, int expectedY)
        {
            (int actualX, int actualY) = _pixelMapper.CoordsToWorldPixels(col, row);

            Assert.Equal(expectedX, actualX);
            Assert.Equal(expectedY, actualY);
        }
示例#2
0
        public bool HandleInteraction(int x, int y, int width, int height, MouseAction action)
        {
            if (action == MouseAction.Move)
            {
                return(false);
            }

            x -= 100;
            y -= height - _pixelMapper.Rows - 100;

            if (x <= 0 || x >= _pixelMapper.Columns ||
                y <= 0 || y >= _pixelMapper.Rows)
            {
                return(false);
            }

            // we're inside the minimap
            (x, y) = _pixelMapper.CoordsToWorldPixels(x, y);

            x -= _pixelMapper.ViewPortWidth / 2;
            y -= _pixelMapper.ViewPortHeight / 2;

            _pixelMapper.SetViewPort(x, y);

            return(true);
        }
示例#3
0
        public override void Draw(SKCanvas canvas, RectangleF dirtyRect)
        {
            if (dirtyRect.IsEmpty)
            {
                return;
            }
            if (!_redraw)
            {
                return;
            }

            const int maxGridSize = PixelMapper.MaxGridSize;

            using var bitmap = new SKBitmap(maxGridSize, maxGridSize);

            using var tempCanvas = new SKCanvas(bitmap);
            tempCanvas.Clear(SKColor.Parse(Colors.VeryLightGray.HexCode));
            using var canvasWrapper = new SKCanvasWrapper(tempCanvas);

            foreach (Track track in _trackLayout)
            {
                (int x, int y) = _pixelMapper.CoordsToWorldPixels(track.Column, track.Row);
                tempCanvas.DrawRect(new SKRect(x, y, _trackParameters.CellSize + x, _trackParameters.CellSize + y), _paint);
            }

            tempCanvas.DrawRect(new SKRect(_pixelMapper.ViewPortX * -1, _pixelMapper.ViewPortY * -1, Math.Abs(_pixelMapper.ViewPortX) + _pixelMapper.ViewPortWidth, Math.Abs(_pixelMapper.ViewPortY) + _pixelMapper.ViewPortHeight), _viewPortPaint);

            canvas.DrawBitmap(bitmap, new SKRect(0, 0, maxGridSize, maxGridSize), new SKRect(0, 0, 100, 100));

            _redraw = false;
        }
示例#4
0
        public bool HandlePointerAction(int x, int y, int width, int height, PointerAction action)
        {
            if (!this.Enabled)
            {
                return(false);
            }

            if (action == Rendering.PointerAction.Move)
            {
                return(false);
            }

            x -= width - _pixelMapper.Columns - 50;
            y -= height - _pixelMapper.Rows - 50;

            if (x <= 0 || x >= _pixelMapper.Columns ||
                y <= 0 || y >= _pixelMapper.Rows)
            {
                return(false);
            }

            // we're inside the minimap
            (x, y) = _pixelMapper.CoordsToWorldPixels(x, y);

            x -= _pixelMapper.ViewPortWidth / 2;
            y -= _pixelMapper.ViewPortHeight / 2;

            _pixelMapper.SetViewPort(x, y);

            return(true);
        }
示例#5
0
        public override void DragInteraction(PointF[] points)
        {
            (int x, int y) = _pixelMapper.CoordsToWorldPixels((int)points[0].X, (int)points[0].Y);

            x -= _pixelMapper.ViewPortWidth / 2;
            y -= _pixelMapper.ViewPortHeight / 2;

            _pixelMapper.SetViewPort((int)x, (int)y);
        }
示例#6
0
        public override void Draw(SKCanvas canvas, RectangleF dirtyRect)
        {
            if (dirtyRect.IsEmpty)
            {
                return;
            }
            if (!_redraw)
            {
                return;
            }

            const int maxGridSize = PixelMapper.MaxGridSize;

            using var bitmap = new SKBitmap(maxGridSize, maxGridSize, SKImageInfo.PlatformColorType, SKAlphaType.Premul);

            using var tempCanvas = new SKCanvas(bitmap);
            tempCanvas.Clear(TerrainColourLookup.DefaultColour.ToSkia());
            using var canvasWrapper = new SKCanvasWrapper(tempCanvas);

            using var paint = new SKPaint
                  {
                      Style = SKPaintStyle.Fill,
                  };

            foreach (Terrain terrain in _terrainMap)
            {
                paint.Color    = TerrainColourLookup.GetTerrainColour(terrain).ToSkia();
                (int x, int y) = _pixelMapper.CoordsToWorldPixels(terrain.Column, terrain.Row);
                tempCanvas.DrawRect(new SKRect(x, y, _gameParameters.CellSize + x, _gameParameters.CellSize + y), paint);
            }

            foreach (Track track in _trackLayout.OfType <Track>())
            {
                (int x, int y) = _pixelMapper.CoordsToWorldPixels(track.Column, track.Row);
                tempCanvas.DrawRect(new SKRect(x, y, _gameParameters.CellSize + x, _gameParameters.CellSize + y), _paint);
            }

            tempCanvas.DrawRect(new SKRect(_pixelMapper.ViewPortX * -1, _pixelMapper.ViewPortY * -1, Math.Abs(_pixelMapper.ViewPortX) + _pixelMapper.ViewPortWidth, Math.Abs(_pixelMapper.ViewPortY) + _pixelMapper.ViewPortHeight), _viewPortPaint);

            canvas.DrawBitmap(bitmap, new SKRect(0, 0, maxGridSize, maxGridSize), new SKRect(0, 0, 100, 100));

            _redraw = false;
        }