Beispiel #1
0
 private void addUndoAction(UndoActionType type)
 {
     if (CurrentDrawObject == null)
     {
         return;
     }
     _undos.Push(new UndoAction()
     {
         UndoActionType = type,
         DrawObject     = CurrentDrawObject.GetSerializable()
     });
 }
Beispiel #2
0
        private void undoRedo(UndoAction action, Stack <UndoAction> opposites, bool redo)
        {
            var opposite = new UndoAction();

            if (action.UndoActionType == UndoActionType.AddDrawObject)
            {
                opposite.UndoActionType = UndoActionType.DeleteDrawObject;
            }
            else if (action.UndoActionType == UndoActionType.DeleteDrawObject)
            {
                opposite.UndoActionType = UndoActionType.AddDrawObject;
            }
            else
            {
                opposite.UndoActionType = action.UndoActionType;
            }

            if (action.UndoActionType == UndoActionType.DeleteDrawObject)
            {
                CurrentDrawObject   = DrawObject.FromSerialized(_currGraphics, action.DrawObject, _zoomMultiplier);
                opposite.DrawObject = CurrentDrawObject.GetSerializable();
                _drawObjects.Add(CurrentDrawObject);
            }
            else
            {
                var drawObj = _drawObjects.First(d => d.ID == action.DrawObject.ID);
                opposite.DrawObject = drawObj.GetSerializable();
                if (action.UndoActionType == UndoActionType.AddDrawObject)
                {
                    _drawObjects.Remove(drawObj);
                }
                else if (action.UndoActionType == UndoActionType.CropImage)
                {
                    _cropRectangle = redo ?
                                     (CurrentDrawObject as SelectDrawObject).GetSelectionRectangle()
                                                : Rectangle.Empty;
                    LoadImage(true);
                }
                else
                {
                    drawObj.Undo(action.DrawObject);
                }
            }

            opposites.Push(opposite);

            serializeDrawObjects();

            redraw(true);
        }
Beispiel #3
0
        //private void pictMain_KeyPress(object sender, KeyPressEventArgs e)
        //{
        //	if (CurrentDrawObject is TextDrawObject)
        //	{
        //		if (e.KeyChar == 13)
        //			(CurrentDrawObject as TextDrawObject).CurrentText += "\r\n";
        //		else
        //			(CurrentDrawObject as TextDrawObject).CurrentText += e.KeyChar.ToString();
        //		redraw(true);
        //	}
        //}

        private void pictMain_MouseUp(object sender, MouseEventArgs e)
        {
            if (CurrentDrawObject != null && !_drawObjects.Contains(CurrentDrawObject))
            {
                _drawObjects.Add(CurrentDrawObject);
                addUndoAction(UndoActionType.AddDrawObject);
                if (!(CurrentDrawObject is TextDrawObject))
                {
                    serializeDrawObjects();
                }
                btnCrop.Visible            = CurrentDrawObject is SelectDrawObject;
                CurrentDrawObject.Selected = true;
                //if (!(_currentDrawObject is TextDrawObject) && !(_currentDrawObject is SelectDrawObject))
                //	_currentDrawObject = null;
                _lock = true;
                foreach (var tool in _tools)
                {
                    tool.Checked = false;
                }
                _drawObjectType = null;
                setVisibilities();
                _lock = false;
                if (CurrentDrawObject is FillDrawObject)
                {
                    drawObjects(CurrentDrawObject as FillDrawObject);
                }

                redraw(true);
            }
            else if (CurrentDrawObject != null)
            {
                var peek = _undos.Peek();
                if (peek.UndoActionType == UndoActionType.MoveResize)
                {
                    var test = CurrentDrawObject.GetSerializable();
                    if (test.ID == peek.DrawObject.ID &&
                        test.StartPoint.X == peek.DrawObject.StartPoint.X &&
                        test.StartPoint.Y == peek.DrawObject.StartPoint.Y &&
                        test.EndPoint.X == peek.DrawObject.EndPoint.X &&
                        test.EndPoint.Y == peek.DrawObject.EndPoint.Y)
                    {
                        _undos.Pop();
                    }
                }
                serializeDrawObjects();
            }

            _mouseDownLocation = Point.Empty;
        }