/// <summary> /// Edit -> Redo menu button - redo last action if it was undone /// </summary> private void RedoButtonClick(object sender, EventArgs e) { CloseAllPopUps(); if (taskControl.removed.Any()) { taskControl.tasks.Push(taskControl.removed.Pop()); } RestorePoint restorePoint = taskControl.redoQueue.RemoveLast(); if (restorePoint != null) { RestorePoint old = new RestorePoint( imageSet.imageMode, restorePoint.taskType, imageSet.image.Clone(imageSet.rectangle, imageSet.image.PixelFormat), imageSet.thumb.Clone(imageSet.thumbRectangle, imageSet.thumb.PixelFormat), imageSet.saturation, imageSet.brightness, imageSet.clarity ); taskControl.undoQueue.Add(old); ApplyRestorePoint(restorePoint); log.Add("Last un-done action was re-done"); } else { log.Add("Action cannot be re-done, there is no other actions in the queue"); } }
/// <summary> /// Applies image restore point from undo/redo queue and /// propagates to thumbnails also /// </summary> /// <param name="restorePoint">Restore point to be applied</param> private void ApplyRestorePoint(RestorePoint restorePoint) { imageSet.image = restorePoint.image; imageSet.thumb = restorePoint.thumb; imageSet.saturation = restorePoint.saturation; imageSet.brightness = restorePoint.brightness; imageSet.clarity = restorePoint.clarity; imageSet.thumbRed = imageSet.CopyThumbnailWithFilter(ColorFilters.RedFilter); imageSet.thumbGreen = imageSet.CopyThumbnailWithFilter(ColorFilters.GreenFilter); imageSet.thumbBlue = imageSet.CopyThumbnailWithFilter(ColorFilters.BlueFilter); saturationChanging = true; brightnessChanging = true; clarityChanging = true; saturationTrackBar.Value = restorePoint.saturation; brightnessTrackBar.Value = restorePoint.brightness; clarityTrackBar.Value = restorePoint.clarity; saturationChanging = false; brightnessChanging = false; clarityChanging = false; RedrawImageSet(); }
/// <summary> /// Processes all tasks in main (not waiting) linked list and /// creates restore point to undo queue /// Waits in the while loop while another task should be executed /// or while loop is terminated by main form signal /// </summary> private void Process() { while (form.tasksRunning) { if (head != null) { head.ongoing = true; RestorePoint old = new RestorePoint( form.imageSet.imageMode, head.taskType, form.imageSet.image.Clone(form.imageSet.rectangle, form.imageSet.image.PixelFormat), form.imageSet.thumb.Clone(form.imageSet.thumbRectangle, form.imageSet.thumb.PixelFormat), form.imageSet.saturation, form.imageSet.brightness, form.imageSet.clarity ); undoQueue.Add(old); redoQueue.Flush(); head.Process(); head = head.next; if (head != null) { head.previous = null; } form.RedrawImageSet(); } else { Thread.Sleep(100); } } }
/// <summary> /// Removes and returns last restore point from queue /// </summary> /// <returns>Last added restore point from queue</returns> public RestorePoint RemoveLast() { if (free == 0) { free = length - 1; } else { --free; } RestorePoint response = data[free]; data[free] = null; return(response); }
/// <summary> /// Adds restore point to free cell to restore point array /// </summary> /// <param name="restorePoint">Restore point to add</param> public void Add(RestorePoint restorePoint) { data[free] = restorePoint; free = (free + 1) % length; }