Пример #1
0
        public override void OnMouseDown(MouseEventArgs e)
        {
            if (TilesetSelection == Rectangle.Empty || World.IsDragging || e.Button != MouseButtons.Left)
            {
                return;
            }

            ChangesUndo = new TileChangesList(World.SelectedLayer);
            ChangesRedo = new TileChangesList(World.SelectedLayer);

            Point location = RelativePoint(e.Location);

            // draw a uniform line if shift is pressed when clicked
            if (lastRenderedPoint != PointNull && (Control.ModifierKeys & Keys.Shift) == Keys.Shift)
            {
                renderUniformLine(lastRenderedPoint, location);
            }
            else
            {
                renderPointCentered(location, true);
            }

            lastMouseMove = location;

            mouseDown = true;
        }
        /// <summary>
        /// Renders the tileset selection to the world centered
        /// on given point
        /// </summary>
        /// <param name="point"> Point origin </param>
        /// <param name="invalidate"> Flag for invalidating the world canvas after done calculating changes </param>
        protected void renderPointCentered(Point point, bool invalidate = false)
        {
            //cast changes as changes list
            TileChangesList undo = ChangesUndo as TileChangesList,
                            redo = ChangesRedo as TileChangesList;

            int width   = TilesetSelection.Width / TileSize.Width,
                height  = TilesetSelection.Height / TileSize.Height,
                offsetX = (int)Math.Floor((float)width / 2),
                offsetY = (int)Math.Floor((float)height / 2);

            bool checkRectangle = World.SelectionRectangle != Rectangle.Empty;

            for (int x = point.X, sx = 0; x < point.X + width; x++, sx++)
            {
                for (int y = point.Y, sy = 0; y < point.Y + height; y++, sy++)
                {
                    Point change = new Point(x - offsetX, y - offsetY);

                    if (!World.PointInWorld(change.X, change.Y))
                    {
                        continue;
                    }

                    if (checkRectangle && !World.SelectionRectangle.Contains(change))
                    {
                        continue;
                    }

                    if (undo != null && !undo.ContainsKey(change))
                    {
                        undo[change] = World.GetTile(change);
                    }

                    WorldTile tile = TileFromSelectionOffset(sx, sy);

                    World.SetTile(change.X, change.Y, tile, World.SelectedLayer);

                    if (redo != null)
                    {
                        redo[change] = tile;
                    }
                }
            }

            lastRenderedPoint = point;

            if (invalidate)
            {
                World.InvalidateCanvas();
            }
        }
        /// <summary>
        /// Generic history callback delegate specifically for tile based tools
        /// </summary>
        /// <param name="obj"> History arguement</param>
        protected virtual void ApplyTileChanges(HistoryAction action, object obj)
        {
            lastRenderedPoint = PointNull;

            TileChangesList changes = (TileChangesList)obj;

            foreach (var change in changes)
            {
                World.SetTile(change.Key.X, change.Key.Y, change.Value, changes.Layer);
            }

            World.SelectLayer(changes.Layer);
        }
        public override void OnMouseDown(MouseEventArgs e)
        {
            if (TilesetSelection == Rectangle.Empty || World.IsDragging || e.Button != MouseButtons.Left)
                return;

            ChangesUndo = new TileChangesList(World.SelectedLayer);
            ChangesRedo = new TileChangesList(World.SelectedLayer);

            Point location = RelativePoint(e.Location);

            // draw a uniform line if shift is pressed when clicked
            if (lastRenderedPoint != PointNull && (Control.ModifierKeys & Keys.Shift) == Keys.Shift)
            {
                renderUniformLine(lastRenderedPoint, location);
            }
            else
            {
                renderPointCentered(location, true);
            }

            lastMouseMove = location;

            mouseDown = true;
        }