示例#1
0
        //---------------------------------------------------------------------------

        private void SetHighlight(int x, int y, int width, int height, bool checkBounds)
        {
            if (Highlight == null)
            {
                Highlight = new SelectionRect(x, y, width, height, checkBounds ? Bounds : null);
            }
            else
            {
                Highlight.Update(x, y, width, height, checkBounds ? Bounds : null);
            }
            OnPropertyChanged("Highlight");
        }
示例#2
0
        //---------------------------------------------------------------------------

        private void UpdateHighlight(int x, int y)
        {
            SelectionRect tilesetSelection = TilesetManager.Get().GetSelection();
            SelectionRect rect             = new SelectionRect(x, y, tilesetSelection.Width, tilesetSelection.Height).Within(new SelectionRect(0, 0, MapWidth, MapHeight));

            switch (EditManager.Get().Mode)
            {
            case EEditMode.Tiles:
                UpdateHighlight(rect.X, rect.Y, rect.Width, rect.Height);
                break;

            case EEditMode.Eraser:
                UpdateHighlight(rect.X, rect.Y, 1, 1);
                break;

            case EEditMode.Fill:
                UpdateHighlight(rect.X, rect.Y, 1, 1);
                break;
            }
        }
示例#3
0
        //---------------------------------------------------------------------------

        private void OnTilesetSelectionChanged(SelectionRect selection)
        {
            if (selection != null && selection.Width > 0 && selection.Height > 0)
            {
                HighlightImage = new WriteableBitmap(selection.Width * 32, selection.Height * 32, 96, 96, PixelFormats.Bgra32, null);

                BitmapSource source = TilesetManager.Get().Tileset?.Source;
                if (source != null)
                {
                    Int32Rect targetRect = new Int32Rect(selection.X * 32, selection.Y * 32, selection.Width * 32, selection.Height * 32);
                    int       bytesPerPixel = (source.Format.BitsPerPixel + 7) / 8;
                    int       stride = bytesPerPixel * targetRect.Width;
                    byte[]    data = new byte[stride * targetRect.Height];
                    TilesetManager.Get().Tileset.Source.CopyPixels(targetRect, data, stride, 0);

                    Int32Rect sourceRect = new Int32Rect(0, 0, selection.Width * 32, selection.Height * 32);
                    HighlightImage.WritePixels(sourceRect, data, stride, 0);
                }
            }
            OnPropertyChanged("HighlightImage");
        }
示例#4
0
        //---------------------------------------------------------------------------

        private void SetHighlight(int x, int y)
        {
            if (Highlight == null)
            {
                Highlight = new SelectionRect(x, y, 1, 1, Bounds);
            }
            else
            {
                Highlight.Update(x, y, 1, 1, Bounds);
            }

            Tileset tileset = TilesetManager.Get().Tileset;

            if (tileset != null && tileset.PxTileWidth > 0 && tileset.PxTileHeight > 0)
            {
                Canvas.SetLeft(HighlightRect, Highlight.X * tileset.PxTileWidth);
                Canvas.SetTop(HighlightRect, Highlight.Y * tileset.PxTileHeight);
                HighlightRect.Width  = tileset.PxTileWidth;
                HighlightRect.Height = tileset.PxTileHeight;
            }
            OnPropertyChanged("Highlight");
        }
示例#5
0
        //---------------------------------------------------------------------------

        private void SetSelection(int x, int y, int width, int height)
        {
            if (Selection == null)
            {
                Selection = new SelectionRect(x, y, width, height, Bounds);
            }
            else
            {
                Selection.Update(x, y, width, height, Bounds);
            }

            Tileset tileset = TilesetManager.Get().Tileset;

            if (tileset != null && tileset.PxTileWidth > 0 && tileset.PxTileHeight > 0)
            {
                Canvas.SetLeft(SelectionRect, Selection.X * tileset.PxTileWidth);
                Canvas.SetTop(SelectionRect, Selection.Y * tileset.PxTileHeight);
                SelectionRect.Width  = Selection.Width * tileset.PxTileWidth;
                SelectionRect.Height = Selection.Height * tileset.PxTileHeight;
            }
            OnPropertyChanged("Selection");
            TilesetManager.Get().UpdateSelection();
        }
示例#6
0
        //---------------------------------------------------------------------------

        private void SetHighlight(Point point, bool isHovering)
        {
            if (isHovering)
            {
                int beginX = (int)(point.X / m_TileWidth);
                int beginY = (int)(point.Y / m_TileHeight);

                switch (EditManager.Get().Mode)
                {
                case EEditMode.Tiles:
                    SelectionRect selection = TilesetManager.Get().GetSelection();
                    SetHighlight(beginX, beginY, selection != null ? selection.Width : 1, selection != null ? selection.Height : 1, true);
                    break;

                case EEditMode.Blocker:
                    SetHighlight(beginX, beginY, 1, 1, true);
                    break;
                }
            }
            else
            {
                SetHighlight(0, 0, 0, 0, false);
            }
        }
示例#7
0
        //---------------------------------------------------------------------------

        private void OnTilesetSelectionChanged(SelectionRect selection)
        {
            TilesetSelectionChanged?.Invoke(selection);
        }
示例#8
0
        //---------------------------------------------------------------------------

        public SelectionRect(int x, int y, int width, int height, SelectionRect bounds)
        {
            Update(x, y, width, height, bounds);
        }