public bool IsValid(PointInt32 point)
        {
            if (_selectionVisibility != Visibility.Visible)
                return true;

            return (Rectangle.Contains(point));
        }
 public void SetRectangle(PointInt32 p1, PointInt32 p2)
 {
     int x = p1.X < p2.X ? p1.X : p2.X;
     int y = p1.Y < p2.Y ? p1.Y : p2.Y;
     int width = Math.Abs(p2.X - p1.X) + 1;
     int height = Math.Abs(p2.Y - p1.Y) + 1;
     Rectangle = new Int32Rect(x, y, width, height);
     SelectionVisibility = Visibility.Visible;
 }
 private void ScrollToTile(PointInt32 tile)
 {
     var vm = (WorldViewModel)DataContext;
     double zoom = vm.Zoom;
     var partView = (ScrollViewer)FindName("WorldScrollViewer");
     if (partView != null)
     {
         partView.ScrollToHorizontalOffset((tile.X * zoom) - (partView.ActualWidth / 2.0));
         partView.ScrollToVerticalOffset((tile.Y * zoom) - (partView.ActualHeight / 2.0));
     }
 }
        public static bool Contains(this Int32Rect rect, PointInt32 point)
        {
            int xabs = (point.X - rect.X);
            int yabs = (point.Y - rect.Y);

            if (xabs < 0)
                return false;

            if (yabs < 0)
                return false;

            return xabs < rect.Width && yabs < rect.Height;
        }
        private void ViewportMouseWheel(object sender, MouseWheelEventArgs e)
        {
            var cargs = new TileMouseEventArgs
                            {
                                Tile = GetTileAtPixel(e.GetPosition((IInputElement)sender)),
                                LeftButton = e.LeftButton,
                                RightButton = e.RightButton,
                                MiddleButton = e.MiddleButton,
                                WheelDelta = e.Delta
                            };

            var vm = (WorldViewModel)DataContext;
            var partView = (ScrollViewer)FindName("WorldScrollViewer");

            double initialZoom = vm.Zoom;
            var initialScrollPosition = new Point(partView.HorizontalOffset, partView.VerticalOffset);
            var initialCenterTile =
                new PointInt32((int)(partView.HorizontalOffset / initialZoom + (partView.ActualWidth / 2) / initialZoom),
                               (int)(partView.VerticalOffset / initialZoom + (partView.ActualHeight / 2) / initialZoom));

            if (vm.MouseWheelCommand.CanExecute(cargs))
                vm.MouseWheelCommand.Execute(cargs);

            double finalZoom = vm.Zoom;
            //var finalScrollPosition = new Point(partView.HorizontalOffset, partView.VerticalOffset);
            double zoomRatio = 1 - finalZoom / initialZoom;
            var scaleCenterTile = new PointInt32(
                (int)(initialCenterTile.X - ((cargs.Tile.X - initialCenterTile.X) * zoomRatio)),
                (int)(initialCenterTile.Y - ((cargs.Tile.Y - initialCenterTile.Y) * zoomRatio)));
            ScrollToTile(scaleCenterTile);
        }
Ejemplo n.º 6
0
 public Sign(string text, PointInt32 location)
 {
     _Text = text;
     _Location = location;
 }
Ejemplo n.º 7
0
        private void PlaceBrownChest(PointInt32 p)
        {
            // anchor at top-right of chest
            int x = p.X;
            int y = p.Y;

            // Validate free space
            if (!_world.Tiles[x, y].IsActive && !_world.Tiles[x + 1, y].IsActive && !_world.Tiles[x, y + 1].IsActive && !_world.Tiles[x + 1, y + 1].IsActive)
            {
                // Validate floor    WorldSettings.Tiles[].IsSolid
                if ((_world.Tiles[x, y + 2].IsActive && (WorldSettings.Tiles[_world.Tiles[x, y + 2].Type].IsSolid)) &&
                    (_world.Tiles[x + 1, y + 2].IsActive && (WorldSettings.Tiles[_world.Tiles[x + 1, y + 2].Type].IsSolid)))
                {
                    // Place Chest
                    var tp = new TilePicker();
                    SetTileSprite(new PointInt32(x, y), new PointShort(0, 0), 21);
                    SetTileSprite(new PointInt32(x, y + 1), new PointShort(0, 18), 21);
                    SetTileSprite(new PointInt32(x + 1, y), new PointShort(18, 0), 21);
                    SetTileSprite(new PointInt32(x + 1, y + 1), new PointShort(18, 18), 21);
                }
            }
        }
Ejemplo n.º 8
0
        private void CheckDirectionandDraw(TileMouseEventArgs e)
        {
            PointInt32 p = e.Tile;
            if (_isRightDown)
            {
                if (_isLeftDown)
                    p.X = _startPoint.X;
                else
                    p.Y = _startPoint.Y;

                DrawLine(p);
                _startPoint = p;
            }
            else if (_isLeftDown)
            {
                DrawLine(p);
                _startPoint = p;
            }
        }
Ejemplo n.º 9
0
 public WorldHeader()
 {
     _FileName = "";
     _WorldName = "No World Loaded";
     _MaxTiles = new PointInt32(0, 0);
 }
 public void UpdateWorldImage(PointInt32 location)
 {
     Tile tile = _world.Tiles[location.X, location.Y];
     Color color = GetTileColor(location.Y, tile);
     _worldImage.Image.SetPixel(location.X, location.Y, color);
 }
Ejemplo n.º 11
0
 public RectInt32(PointInt32 topLeft, PointInt32 bottomRight)
 {
     TopLeft = topLeft;
     BottomRight = bottomRight;
 }
Ejemplo n.º 12
0
 public RectInt32(int left, int right, int top, int bottom)
 {
     TopLeft = new PointInt32(left, top);
     BottomRight = new PointInt32(right, bottom);
 }
Ejemplo n.º 13
0
        private void CalcOffset()
        {
            switch (Mode)
            {
                case ToolAnchorMode.Center:
                    Offset = new PointInt32(Width/2, Height/2);
                    break;
                case ToolAnchorMode.TopLeft:
                    Offset = new PointInt32(0, 0);
                    break;
                case ToolAnchorMode.TopCenter:
                    Offset = new PointInt32(Width/2, 0);
                    break;
                case ToolAnchorMode.TopRight:
                    Offset = new PointInt32(Width, 0);
                    break;
                case ToolAnchorMode.MiddleRight:
                    Offset = new PointInt32(Width, Height/2);
                    break;
                case ToolAnchorMode.BottomRight:
                    Offset = new PointInt32(Width, Height);
                    break;
                case ToolAnchorMode.BottomCenter:
                    Offset = new PointInt32(Width/2, Height);
                    break;
                case ToolAnchorMode.BottomLeft:
                    Offset = new PointInt32(0, Height);
                    break;
                case ToolAnchorMode.MiddleLeft:
                    Offset = new PointInt32(0, Height/2);
                    break;
                default:
                    Offset = new PointInt32(0, 0);
                    break;
            }
            MaxOutlineThickness = (int) Math.Max(1, Math.Min(Math.Floor(Height/2.0), Math.Floor(Width/2.0)));

            OnToolPreviewRequest(this, new EventArgs());
        }
Ejemplo n.º 14
0
 private bool Check2x2(PointInt32 loc, PointInt32 hit)
 {
     return (loc.X == hit.X || loc.X + 1 == hit.X) &&
            (loc.Y == hit.Y || loc.Y + 1 == hit.Y);
 }
 public static void FloodFillContig(this World world, PointInt32 start, Int32Rect area, TilePicker tile)
 {
 }
Ejemplo n.º 16
0
 private void PasteClipboard(PointInt32 anchor)
 {
     _clipboardMan.PasteBufferIntoWorld(_world, _clipboardMan.Buffer, anchor);
     _renderer.UpdateWorldImage(new Int32Rect(anchor.X, anchor.Y, _clipboardMan.Buffer.Size.X + 1, _clipboardMan.Buffer.Size.Y + 1));
 }
Ejemplo n.º 17
0
        public void PasteBufferIntoWorld(World world, ClipboardBuffer buffer, PointInt32 anchor)
        {
            for (int x = 0; x < buffer.Size.X; x++)
            {
                for (int y = 0; y < buffer.Size.Y; y++)
                {
                    if (world.IsPointInWorld(x + anchor.X, y + anchor.Y))
                    {
                        HistMan.AddTileToBuffer(x + anchor.X, y + anchor.Y, ref world.Tiles[x + anchor.X, y + anchor.Y]);
                        Tile curTile = (Tile)buffer.Tiles[x, y].Clone();

                        // Remove overwritten chests data
                        if (world.Tiles[x + anchor.X, y + anchor.Y].Type == 21)
                        {
                            var data = world.GetChestAtTile(x + anchor.X, y + anchor.Y);
                            if (data != null)
                                world.Chests.Remove(data);
                        }

                        // Remove overwritten sign data
                        if (world.Tiles[x + anchor.X, y + anchor.Y].Type == 55 || world.Tiles[x + anchor.X, y + anchor.Y].Type == 85)
                        {
                            var data = world.GetSignAtTile(x + anchor.X, y + anchor.Y);
                            if (data != null)
                                world.Signs.Remove(data);
                        }

                        // Add new chest data
                        if (curTile.Type == 21)
                        {
                            if (world.GetChestAtTile(x + anchor.X, y + anchor.Y) == null)
                            {
                                var data = buffer.GetChestAtTile(x, y);
                                if (data != null) // allow? chest copying may not work...
                                {
                                    // Copied chest
                                    var newChest = Utility.DeepCopy(data);
                                    newChest.Location = new PointInt32(x + anchor.X, y + anchor.Y);
                                    world.Chests.Add(newChest);
                                }
                                else
                                {
                                    // Empty chest
                                    world.Chests.Add(new Chest(new PointInt32(x + anchor.X, y + anchor.Y)));
                                }
                            }
                        }

                        // Add new sign data
                        if (curTile.Type == 55 || curTile.Type == 85)
                        {
                            if (world.GetSignAtTile(x + anchor.X, y + anchor.Y) == null)
                            {
                                var data = buffer.GetSignAtTile(x, y);
                                if (data != null)
                                {
                                    // Copied sign
                                    var newSign = Utility.DeepCopy(data);
                                    newSign.Location = new PointInt32(x + anchor.X, y + anchor.Y);
                                    world.Signs.Add(newSign);
                                }
                                else
                                {
                                    world.Signs.Add(new Sign("", new PointInt32(x + anchor.X, y + anchor.Y)));
                                }
                            }
                        }

                        world.Tiles[x + anchor.X, y + anchor.Y] = curTile;
                    }
                }
            }

            HistMan.AddBufferToHistory();
        }
Ejemplo n.º 18
0
 private void SetTileSprite(PointInt32 point, PointShort frame, byte type)
 {
     var curTile = _world.Tiles[point.X, point.Y];
     if (curTile != null)
     {
         curTile.IsActive = true;
         curTile.Type = type;
         curTile.Frame = frame;
         _renderer.UpdateWorldImage(point);
     }
 }
Ejemplo n.º 19
0
 public ClipboardBuffer(PointInt32 size)
 {
     Size = size;
     Tiles = new Tile[size.X, size.Y];
 }
Ejemplo n.º 20
0
 public override bool PressTool(TileMouseEventArgs e)
 {
     if (e.LeftButton == MouseButtonState.Pressed)
         _startselection = e.Tile;
     if (e.RightButton == MouseButtonState.Pressed && e.LeftButton == MouseButtonState.Released)
     {
         _selection.Deactive();
     }
     return true;
 }
Ejemplo n.º 21
0
 public RectInt32(PointInt32 location, int width, int height)
 {
     TopLeft = location;
     BottomRight = new PointInt32(location.X + width, location.Y + Height);
 }
Ejemplo n.º 22
0
        public void Flood(PointInt32 pt)
        {
            int bitmapWidth = _world.Header.MaxTiles.X;
            int bitmapHeight = _world.Header.MaxTiles.Y;

            int x = pt.X;
            int y = pt.Y;
            tilesChecked = new bool[bitmapWidth * bitmapHeight];

            var originTile = (Tile)_world.Tiles[x, y].Clone();
            LinearFloodFill(ref x, ref y, ref _tilePicker, ref originTile);

            while (ranges.Count > 0)
            {
                //**Get Next Range Off the Queue
                FloodFillRange range = ranges.Dequeue();

                //**Check Above and Below Each Pixel in the Floodfill Range
                int downPxIdx = (bitmapWidth * (range.Y + 1)) + range.StartX;//CoordsToPixelIndex(lFillLoc,y+1);
                int upPxIdx = (bitmapWidth * (range.Y - 1)) + range.StartX;//CoordsToPixelIndex(lFillLoc, y - 1);
                int upY = range.Y - 1;//so we can pass the y coord by ref
                int downY = range.Y + 1;
                for (int i = range.StartX; i <= range.EndX; i++)
                {
                    //*Start Fill Upwards
                    //if we're not above the top of the bitmap and the pixel above this one is within the color tolerance
                    if (range.Y > 0 && (!tilesChecked[upPxIdx]) && CheckTileMatch(ref originTile, ref _world.Tiles[i, upY], ref _tilePicker) && _selection.IsValid(new PointInt32(i, upY)))
                        LinearFloodFill(ref i, ref upY, ref _tilePicker, ref originTile);

                    //*Start Fill Downwards
                    //if we're not below the bottom of the bitmap and the pixel below this one is within the color tolerance
                    if (range.Y < (bitmapHeight - 1) && (!tilesChecked[downPxIdx]) && CheckTileMatch(ref originTile, ref _world.Tiles[i, downY], ref _tilePicker) && _selection.IsValid(new PointInt32(i, downY)))
                        LinearFloodFill(ref i, ref downY, ref _tilePicker, ref originTile);
                    downPxIdx++;
                    upPxIdx++;
                }

                if (upY < minY)
                    minY = upY;
                if (downY > maxY)
                    maxY = downY;
            }
        }
Ejemplo n.º 23
0
        public bool Contains(PointInt32 point)
        {
            int xabs = (point.X - X);
            int yabs = (point.Y - Y);

            if (xabs < 0)
                return false;

            if (yabs < 0)
                return false;

            return xabs < Width && yabs < Height;
        }
Ejemplo n.º 24
0
 private static bool MatchFields(PointInt32 a, PointInt32 m)
 {
     return (a.X == m.X && a.Y == m.Y);
 }
        public static IEnumerable<PointInt32> DrawLine(PointInt32 begin, PointInt32 end)
        {
            int y0 = begin.Y;
            int x0 = begin.X;
            int y1 = end.Y;
            int x1 = end.X;

            int dy = y1 - y0;
            int dx = x1 - x0;
            int stepx, stepy;

            if (dy < 0)
            {
                dy = -dy;
                stepy = -1;
            }
            else
            {
                stepy = 1;
            }
            if (dx < 0)
            {
                dx = -dx;
                stepx = -1;
            }
            else
            {
                stepx = 1;
            }
            dy <<= 1;
            dx <<= 1;

            //y0 *= width;
            //y1 *= width;
            yield return new PointInt32(x0, y0);
            if (dx > dy)
            {
                int fraction = dy - (dx >> 1);
                while (x0 != x1)
                {
                    if (fraction >= 0)
                    {
                        y0 += stepy;
                        fraction -= dx;
                    }
                    x0 += stepx;
                    fraction += dy;
                    yield return new PointInt32(x0, y0);
                }
            }
            else
            {
                int fraction = dx - (dy >> 1);
                while (y0 != y1)
                {
                    if (fraction >= 0)
                    {
                        x0 += stepx;
                        fraction -= dy;
                    }
                    y0 += stepy;
                    fraction += dx;
                    yield return new PointInt32(x0, y0);
                }
            }
        }
Ejemplo n.º 26
0
 public bool Equals(PointInt32 p)
 {
     return MatchFields(this, p);
 }
Ejemplo n.º 27
0
        public override bool PressTool(TileMouseEventArgs e)
        {
            if (!_isRightDown && !_isLeftDown)
                _startPoint = e.Tile;

            CheckDirectionandDraw(e);
            _isLeftDown = (e.LeftButton == MouseButtonState.Pressed);
            _isRightDown = (e.RightButton == MouseButtonState.Pressed);
            return true;
        }
Ejemplo n.º 28
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;
         }
         _world.SetTileXY(p.X, p.Y, _tilePicker);
         _renderer.UpdateWorldImage(p);
     }
 }
Ejemplo n.º 29
0
 private void DrawLine(PointInt32 endPoint)
 {
     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);
         }
     }
 }
Ejemplo n.º 30
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)
                {
                    _world.FillRectangle(new Int32Rect(x0, y0, _properties.Width, _properties.Height), _tilePicker);
                    if (_properties.IsOutline)
                    {
                        // eraise a center section
                        TilePicker eraser = Utility.DeepCopy(_tilePicker);
                        eraser.IsEraser = true;
                        eraser.Wall.IsActive = false; // don't erase the wall for the interrior
                        _world.FillRectangle(new Int32Rect(x0 + _properties.OutlineThickness,
                                                           y0 + _properties.OutlineThickness,
                                                           _properties.Width - (_properties.OutlineThickness*2),
                                                           _properties.Height - (_properties.OutlineThickness*2)),
                                             eraser);
                        eraser = null;
                    }
                }
                else if (_properties.BrushShape == ToolBrushShape.Round)
                {
                    _world.FillEllipse(x0, y0, x0 + _properties.Width, y0 + _properties.Height, _tilePicker);
                    if (_properties.IsOutline)
                    {
                        // eraise a center section
                        TilePicker eraser = Utility.DeepCopy(_tilePicker);
                        eraser.IsEraser = true;
                        eraser.Wall.IsActive = false; // don't erase the wall for the interrior
                        _world.FillEllipse(x0 + _properties.OutlineThickness,
                                           y0 + _properties.OutlineThickness,
                                           x0 + _properties.Width - _properties.OutlineThickness,
                                           y0 + _properties.Height - _properties.OutlineThickness, eraser);

                        eraser = null;
                    }
                }
                _renderer.UpdateWorldImage(new Int32Rect(x0, y0, _properties.Width + 1, _properties.Height + 1));
            }
        }