Beispiel #1
0
        private void DrawLine(PointInt32 endPoint)
        {
            var startPoint = (PointInt32)_startPoint;

            foreach (PointInt32 p in WorldRenderer.DrawLine(startPoint, endPoint))
            {
                if (_selection.IsValid(p))
                {
                    int x = p.X;
                    int y = p.Y;
                    if (HistMan.SaveHistory)
                    {
                        HistMan.AddTileToBuffer(x, y, ref _world.Tiles[x, y]);
                    }
                    _world.SetTileXY(ref x, ref y, ref _tilePicker, ref _selection);
                    _renderer.UpdateWorldImage(p);
                }
            }

            // Make sure the actual corners are defined

            /* if (_selection.IsValid(startPoint) bmp.SetPixel(startPoint.X, startPoint.Y, previewColor);
             * if (_selection.IsValid(endPoint)   bmp.SetPixel(endPoint.X, endPoint.Y, previewColor); */
        }
Beispiel #2
0
        private void DrawLine(PointInt32 endPoint)
        {
            foreach (PointInt32 p in WorldRenderer.DrawLine(_startPoint, endPoint))
            {
                if (_selection.SelectionVisibility == Visibility.Visible)
                {
                    // if selection is active, and point is not inside, skip point
                    if (!_selection.Rectangle.Contains(p))
                    {
                        continue;
                    }
                }

                // center
                int x0 = p.X - _properties.Offset.X;
                int y0 = p.Y - _properties.Offset.Y;

                if (_properties.BrushShape == ToolBrushShape.Square)
                {
                    if (_properties.IsOutline)
                    {
                        TilePicker outline = Utility.DeepCopy(_tilePicker);
                        outline.Wall.IsActive = false;

                        // eraise a center section
                        TilePicker eraser = Utility.DeepCopy(_tilePicker);
                        eraser.IsEraser      = true;
                        eraser.Wall.IsActive = false; // don't erase the wall for the interrior

                        TilePicker wall = Utility.DeepCopy(_tilePicker);
                        wall.Tile.IsActive = false;



                        var interior = new Int32Rect(x0 + _properties.OutlineThickness,
                                                     y0 + _properties.OutlineThickness,
                                                     _properties.Width - (_properties.OutlineThickness * 2),
                                                     _properties.Height - (_properties.OutlineThickness * 2));

                        // Erase center
                        FillRectangle(interior, ref eraser);
                        // Fill center
                        if (wall.Wall.IsActive)
                        {
                            FillRectangle(interior, ref wall);
                        }
                        // Draw outline
                        if (outline.Tile.IsActive)
                        {
                            for (int i = 0; i < _properties.OutlineThickness; i++)
                            {
                                DrawRectangle(new Int32Rect(x0 + i, y0 + i, _properties.Width - (i * 2) - 1, _properties.Height - (i * 2) - 1), ref outline);
                            }
                        }
                    }
                    else
                    {
                        FillRectangle(new Int32Rect(x0, y0, _properties.Width, _properties.Height), ref _tilePicker);
                    }
                }
                else if (_properties.BrushShape == ToolBrushShape.Round)
                {
                    if (_properties.IsOutline)
                    {
                        TilePicker outline = Utility.DeepCopy(_tilePicker);
                        outline.Wall.IsActive = false;

                        // eraise a center section
                        TilePicker eraser = Utility.DeepCopy(_tilePicker);
                        eraser.IsEraser      = true;
                        eraser.Wall.IsActive = false; // don't erase the wall for the interrior

                        TilePicker wall = Utility.DeepCopy(_tilePicker);
                        wall.Tile.IsActive = false;


                        // Draw outline
                        if (outline.Tile.IsActive)
                        {
                            FillEllipse(x0, y0, x0 + _properties.Width, y0 + _properties.Height, ref outline);
                        }

                        // Erase center
                        FillEllipse(x0 + _properties.OutlineThickness,
                                    y0 + _properties.OutlineThickness,
                                    x0 + _properties.Width - _properties.OutlineThickness,
                                    y0 + _properties.Height - _properties.OutlineThickness, ref eraser);
                        // Fill center
                        if (wall.Wall.IsActive)
                        {
                            FillEllipse(x0 + _properties.OutlineThickness,
                                        y0 + _properties.OutlineThickness,
                                        x0 + _properties.Width - _properties.OutlineThickness,
                                        y0 + _properties.Height - _properties.OutlineThickness, ref wall);
                        }



                        eraser = null;
                    }
                    else
                    {
                        FillEllipse(x0, y0, x0 + _properties.Width, y0 + _properties.Height, ref _tilePicker);
                    }
                }
                if (_properties.IsOutline)
                {
                    _renderer.UpdateWorldImage(new Int32Rect(x0, y0, _properties.Width + 1, _properties.Height + 1));
                }
            }
        }
Beispiel #3
0
        public override bool MoveTool(TileMouseEventArgs e)
        {
            WriteableBitmap bmp;

            if (_startPoint != null)
            {
                _endPoint = e.Tile;
            }
            CheckDirectionandDraw(e);
            ToolAnchorMode mode = ToolAnchorMode.Center;

            // Line draw preview
            if (_isRightDown && _startPoint != null && _endPoint != null)
            {
                var sp    = (PointInt32)_startPoint;
                var ep    = (PointInt32)_endPoint;
                var delta = ep - sp;
                var rect  = new RectI(new PointInt32(), new SizeInt32(Math.Abs(delta.X) + 1, Math.Abs(delta.Y) + 1));

                // figure out exactly which PreviewMode
                mode = 0;
                if (delta.X < 0)
                {
                    mode += (int)ToolAnchorModeParts.Left;
                }
                else if (delta.X == 0)
                {
                    mode += (int)ToolAnchorModeParts.Center;
                }
                else if (delta.X > 0)
                {
                    mode += (int)ToolAnchorModeParts.Right;
                }

                if (delta.Y < 0)
                {
                    mode += (int)ToolAnchorModeParts.Top;
                }
                else if (delta.Y == 0)
                {
                    mode += (int)ToolAnchorModeParts.Middle;
                }
                else if (delta.Y > 0)
                {
                    mode += (int)ToolAnchorModeParts.Bottom;
                }

                // which direction to draw the line
                var linePnts = new PointInt32[2];
                switch (mode)
                {
                case ToolAnchorMode.TopLeft:     linePnts = new[] { rect.BottomRight, rect.TopLeft }; break;

                case ToolAnchorMode.TopRight:    linePnts = new[] { rect.BottomLeft, rect.TopRight }; break;

                case ToolAnchorMode.BottomLeft:  linePnts = new[] { rect.TopRight, rect.BottomLeft }; break;

                case ToolAnchorMode.BottomRight: linePnts = new[] { rect.TopLeft, rect.BottomRight }; break;

                default:      // has middle or center, order doesn't matter
                    linePnts = new[] { rect.TopLeft, rect.BottomRight };
                    break;
                }

                bmp = new WriteableBitmap(
                    rect.W,
                    rect.H,
                    96,
                    96,
                    System.Windows.Media.PixelFormats.Bgra32,
                    null);

                bmp.Clear();
                foreach (PointInt32 p in WorldRenderer.DrawLine(linePnts[0], linePnts[1]))
                {
                    if (_selection.IsValid(p))
                    {
                        bmp.SetPixel(p.X, p.Y, previewColor);
                    }
                }
            }
            // Single dot
            else
            {
                bmp = new WriteableBitmap(
                    1,
                    1,
                    96,
                    96,
                    System.Windows.Media.PixelFormats.Bgra32,
                    null);

                bmp.Clear();
                bmp.SetPixel(0, 0, previewColor);
            }

            _properties.Image       = bmp;
            _properties.PreviewMode = mode;

            return(false);
        }