Exemple #1
0
 private void OnRedo(BitmapChanges change)
 {
     if (RedoHappened != null)
     {
         RedoHappened(change);
     }
 }
Exemple #2
0
 private void OnUndo(BitmapChanges change)
 {
     if (UndoHappened != null)
     {
         UndoHappened(change);
     }
 }
Exemple #3
0
        /// <summary>
        /// Removes and disposes the last undo.
        /// </summary>
        public void DisposeLastUndo()
        {
            if (undos.Count < 1)
            {
                return;
            }

            BitmapChanges change = undos.Pop();

            // if the change being removed had any bitmap data stored dispose it
            switch (change)
            {
            case BitmapChanges.Cropped:
            case BitmapChanges.Resized:
            case BitmapChanges.SetGray:
            case BitmapChanges.TransparentFilled:
                if (bitmapUndoHistoryData.Count < 1)
                {
                    return;
                }

                bitmapUndoHistoryData.Pop().Dispose();
                break;
            }
        }
Exemple #4
0
        /// <summary>
        /// Tracks a change done to the bitmap. Depending on the change the CurrentBitmap will be copied and saved in the history.
        /// <para>This should be called BEFORE the change is applied to the bitmap. If the change has been tracked but not be applied the DisposeLastUndo or DisposeLastRedo should be called.</para>
        /// </summary>
        /// <param name="change">The change that is going to occure to the bitmap.</param>
        public void TrackChange(BitmapChanges change)
        {
            ClearRedos();
            undos.Push(change);

            switch (change)
            {
            // need to track history data
            case BitmapChanges.Cropped:
            case BitmapChanges.Dithered:
            case BitmapChanges.Resized:
            case BitmapChanges.SetGray:
            case BitmapChanges.TransparentFilled:
                bitmapUndoHistoryData.Push(CloneProper());
                break;

            // changes are easily undone and do not need to be kept in memory
            case BitmapChanges.Inverted:
            case BitmapChanges.RotatedLeft:
            case BitmapChanges.RotatedRight:
            case BitmapChanges.FlippedHorizontal:
            case BitmapChanges.FlippedVirtical:
                break;
            }
        }
Exemple #5
0
        private void OnUndoRedo(BitmapChanges change)
        {
            if (ibMain == null)
            {
                return;
            }

            //InvalidateImageBox();
            ibMain.UpdateLayout();
        }
Exemple #6
0
        /// <summary>
        /// Undoes the last tracked change.
        /// </summary>
        public void Undo()
        {
            if (undos.Count < 1)
            {
                return;
            }

            BitmapChanges change = undos.Pop();

            redos.Push(change);

            switch (change)
            {
            // need to track history data
            case BitmapChanges.Cropped:
            case BitmapChanges.Resized:
            case BitmapChanges.Dithered:
            case BitmapChanges.SetGray:
            case BitmapChanges.TransparentFilled:
                bitmapRedoHistoryData.Push(CloneProper());
                CurrentBitmap.UpdateImage(bitmapUndoHistoryData.Pop());
                break;

            // changes are easily undone and do not need to be kept in memory
            case BitmapChanges.Inverted:
                CurrentBitmap.InvertColor();
                break;

            case BitmapChanges.RotatedLeft:
                CurrentBitmap.RotateRight90();
                break;

            case BitmapChanges.RotatedRight:
                CurrentBitmap.RotateLeft90();
                break;

            case BitmapChanges.FlippedHorizontal:
                CurrentBitmap.FlipHorizontal();
                break;

            case BitmapChanges.FlippedVirtical:
                CurrentBitmap.FlipVertical();
                break;
            }
            OnUndo(change);
        }