Пример #1
0
        public void SelectTiles(Point pixelPoint1, Point pixelPoint2)
        {
            pixelPoint1 = this.TilesetModel.Value.GetPoint(pixelPoint1);
            pixelPoint2 = this.TilesetModel.Value.GetPoint(pixelPoint2);
            GeneralTransform pixelToTile  = GeometryUtils.CreateTransform(this.itemTransform.pixelToTile);
            Point            tile1        = GeometryUtils.TransformInt(pixelToTile, pixelPoint1);
            Point            tile2        = GeometryUtils.TransformInt(pixelToTile, pixelPoint2);
            Point            topLeftTile  = GeometryUtils.TopLeftPoint(tile1, tile2);
            Point            topLeftPixel = GeometryUtils.TransformInt(pixelToTile.Inverse, topLeftTile);
            Size             tileSize     = GeometryUtils.ComputeSize(tile1, tile2);
            Size             pixelSize    = GeometryUtils.TransformInt(pixelToTile.Inverse, tileSize);

            DrawSelectLinesFromPixels(topLeftPixel, pixelSize);

            PaddedBrushModel brushModel = new PaddedBrushModel(this.TilesetModel.Value, (int)topLeftTile.X, (int)topLeftTile.Y);

            brushModel.SetSize(tileSize);
            Mat croppedImage = BrushUtils.CropImage(this.ItemImage.Value, topLeftPixel, pixelSize);

            if (this.TilesetModel.Value.IsTransparent.Value)
            {
                croppedImage = ImageUtils.ColorToTransparent(croppedImage, this.TilesetModel.Value.TransparentColor.Value);
            }
            brushModel.TileImage(croppedImage, topLeftPixel, this.TilesetModel.Value);

            this.eventAggregator.GetEvent <NewPaddedBrushEvent>().Publish(brushModel);
        }
Пример #2
0
        public ImageDrawing GetByID(int id, Point startPoint)
        {
            Point topLeftTile = GetPointByID(id);
            Size  sizeOfTile  = GetTileSize();

            RectangleGeometry geometry = new RectangleGeometry(new Rect(topLeftTile, sizeOfTile));

            Mat croppedImage = BrushUtils.CropImage(this.MatImage, topLeftTile, sizeOfTile);

            if (this.IsTransparent.Value)
            {
                croppedImage = ImageUtils.ColorToTransparent(croppedImage, this.TransparentColor.Value);
            }
            Rect         drawingRect = new Rect(startPoint, sizeOfTile);
            ImageDrawing drawing     = ImageUtils.MatToImageDrawing(croppedImage, drawingRect);

            return(drawing);
        }
Пример #3
0
        public void TileImage(Mat tilesImage, Point pixelPoint, TilesetModel tilesetModel)
        {
            this.Tiles.Clear();
            int colCount = tilesImage.Cols / this.TileWidth.Value;
            int rowCount = tilesImage.Rows / this.TileHeight.Value;

            for (int rowIndex = 0; rowIndex < rowCount; ++rowIndex)
            {
                for (int colIndex = 0; colIndex < colCount; ++colIndex)
                {
                    Size         tileSize     = this.GetTileSize();
                    Point        topLeftPoint = new Point(colIndex * this.TileWidth.Value, rowIndex * this.TileHeight.Value);
                    Mat          tileImage    = BrushUtils.CropImage(tilesImage, topLeftPoint, tileSize);
                    Rect         drawingRect  = new Rect(topLeftPoint, tileSize);
                    ImageDrawing drawing      = ImageUtils.MatToImageDrawing(tileImage, drawingRect);

                    Point offsetPoint = Point.Add(pixelPoint, (Vector)topLeftPoint);
                    int   tileID      = tilesetModel.GetID(offsetPoint);
                    int   tilesetID   = tilesetModel.ID;
                    Tile  tile        = new Tile(drawing, tilesetID, tileID);
                    this.Tiles.Add(tile);
                }
            }
        }