Esempio n. 1
0
        public void ShouldCorrectlyUndo()
        {
            var history = new History();
            var element = new Ball() { X = 0, Y = 0 };
            var change = new TranslationChange(element, 5, 5);

            history.AddAndDo(change);
            history.Undo();

            Assert.IsFalse(history.CanUndo());
            Assert.IsTrue(history.CanRedo());

            Assert.AreEqual(0, element.X, 0.1);
            Assert.AreEqual(0, element.Y, 0.1);
        }
Esempio n. 2
0
        protected override void OnMouseUp(object sender, MouseEventArgs e)
        {
            if (State == SelectionState.Dragging && posChange != null)
            {
                Editor.History.Add(posChange);
                posChange = null;
            }
            if (State == SelectionState.Shaping && currentPoint != shapeData.startPoint)
            {
                var translation = new TranslationChange(SelectedElement, SelectedElement.Location - shapeData.initialPoint);
                var scale = new PropertyChange(SelectedElement, "Scale", SelectedElement.Scale, shapeData.initialScale);
                var rotation = new PropertyChange(SelectedElement, "BaseRotation", SelectedElement.BaseRotation, shapeData.initialRotation);
                Editor.History.Add(new CompoundChange(new IChange[] { translation, scale, rotation }));
            }

            State = SelectionState.Idle;

            Editor.Invalidate();
        }
Esempio n. 3
0
        protected override void OnMouseMove(object sender, MouseEventArgs e)
        {
            if (SelectedElement == null) State = SelectionState.Idle;

            if (State == SelectionState.Dragging)
            {
                var pos = e.GetPosition(Editor);
                var newPos = Editor.PointToPinball(new Vector(pos.X, pos.Y) - delta);

                SelectedElement.Location = newPos;

                posChange = new TranslationChange(SelectedElement, newPos - startVector);

                Editor.Invalidate();
            }
            else if (State == SelectionState.Shaping)
            {
                var pos = e.GetPosition(Editor);
                currentPoint = new Point(pos.X, pos.Y);

                SelectedElement.Scale = ((currentPoint - shapeData.origin).Length / (shapeData.startPoint - shapeData.origin).Length) * shapeData.initialScale;

                var newLoc = Editor.PointToPinball(shapeData.origin) - SelectedElement.GetRotationOrigin();
                SelectedElement.Location = new Vector(newLoc.X, newLoc.Y);
                SelectedElement.BaseRotation = shapeData.initialRotation + Vector.AngleBetween(shapeData.startPoint - shapeData.origin, currentPoint - shapeData.origin);

                Editor.Invalidate();
            }
        }
Esempio n. 4
0
        public void ShouldRaiseEvents()
        {
            var eventsRaised = 0;
            var history = new History();
            var element = new Ball() { X = 0, Y = 0 };
            var change = new TranslationChange(element, 5, 5);

            // Bind closure expression
            history.Change += () =>
            {
                eventsRaised++;
            };

            // Act
            history.AddAndDo(change);
            history.Undo();
            history.Redo();

            Assert.AreEqual(3, eventsRaised);
        }