Esempio n. 1
0
        void applyDeletionChanges(HistoryAction action, object obj)
        {
            TileChangesRegion changes = obj as TileChangesRegion;

            if (action == HistoryAction.Undo)
            {
                SelectionRectangle = new Rectangle(changes.Offset.X, changes.Offset.Y,
                                                   changes.Region.Width, changes.Region.Height);
            }
            else
            {
                SelectionRectangle = Rectangle.Empty;
            }

            Rectangle offsetRect = new Rectangle(0, 0, changes.Region.Width, changes.Region.Height),
                      changeRect = offsetRect;

            changeRect.X = Math.Max(0, changes.Offset.X);
            changeRect.Y = Math.Max(0, changes.Offset.Y);

            for (int x = changes.Offset.X, ox = 0; x < changes.Offset.X + changes.Region.Width; x++, ox++)
            {
                for (int y = changes.Offset.Y, oy = 0; y < changes.Offset.Y + changes.Region.Height; y++, oy++)
                {
                    if (PointInWorld(x, y) && changeRect.Contains(x, y) && offsetRect.Contains(ox, oy))
                    {
                        SetTile(x, y, changes.Region[ox, oy], changes.Layer);
                    }
                }
            }

            SelectLayer(changes.Layer);
        }
Esempio n. 2
0
        protected override void ApplyTileChanges(HistoryAction action, object obj)
        {
            TileChangesRegion changes = obj as TileChangesRegion;

            //iterate through the changed region and apply it to the current layer
            for (int x = changes.Offset.X, ox = 0; x < changes.Offset.X + changes.Region.Width; x++, ox++)
            {
                for (int y = changes.Offset.Y, oy = 0; y < changes.Offset.Y + changes.Region.Height; y++, oy++)
                {
                    World.SetTile(x, y, changes.Region[ox, oy], changes.Layer);
                }
            }

            World.SelectLayer(changes.Layer);
        }
Esempio n. 3
0
        /// <summary>
        /// Renders fill changes
        /// </summary>
        /// <param name="info"> Fill information </param>
        void renderFillInfo(FillInfo info)
        {
            WorldRegion undoRegion = World.GetLayerRegion(info.Bounds, World.SelectedLayer),
                        redoRegion = World.GetLayerRegion(info.Bounds, World.SelectedLayer);

            int selectionWidth  = TilesetSelection.Width / TileSize.Width,
                selectionHeight = TilesetSelection.Height / TileSize.Height;

            // <bounds loop>
            for (int boundsX = info.Bounds.X; boundsX < info.Bounds.Right; boundsX += selectionWidth)
            {
                for (int boundsY = info.Bounds.Y; boundsY < info.Bounds.Bottom; boundsY += selectionHeight)
                {
                    // <render loop>
                    for (int renderX = boundsX, sx = 0; renderX < boundsX + selectionWidth; renderX++, sx++)
                    {
                        for (int renderY = boundsY, sy = 0; renderY < boundsY + selectionHeight; renderY++, sy++)
                        {
                            int offsetX = renderX - info.Bounds.X,
                                offsetY = renderY - info.Bounds.Y;

                            // determine if the point from the current selection iteration should be rendered.
                            // must be inside the region bounds and an existing change
                            if (offsetX >= info.Bounds.Width || offsetY >= info.Bounds.Height || !info.Changes[offsetX][offsetY])
                            {
                                continue;
                            }

                            WorldTile tile = TileFromSelectionOffset(sx, sy);

                            World.SetTile(renderX, renderY, tile);
                            redoRegion[offsetX, offsetY] = tile;
                        }
                    }
                    // </render loop>
                }
            }
            // </bounds loop>

            ChangesUndo = new TileChangesRegion(undoRegion, info.Bounds.Location, World.SelectedLayer);
            ChangesRedo = new TileChangesRegion(redoRegion, info.Bounds.Location, World.SelectedLayer);

            History.Add(PackagedHistoryItem());
        }