/// <summary> /// A partially cloneable ShapeEngine collection. This constructor creates a partial clone of an existing ShapeEngineCollection. /// </summary> /// <param name="passedCEC">An existing ShapeEngineCollection to partially clone.</param> public ShapeEngineCollection(ShapeEngineCollection passedCEC) { for (int n = 0; n < passedCEC.Count; ++n) { Add(passedCEC[n].PartialClone()); } }
/// <summary> /// A history item for when shapes are finalized. /// </summary> /// <param name="passedEE">The EditEngine being used.</param> /// <param name="icon">The history item's icon.</param> /// <param name="text">The history item's title.</param> /// <param name="passedUserSurface">The stored UserLayer surface.</param> /// <param name="passedUserLayer">The UserLayer being modified.</param> /// <param name="passedSelectedPointIndex">The selected point's index.</param> /// <param name="passedSelectedShapeIndex">The selected point's shape index.</param> /// <param name="passedRedrawEverything">Whether every shape should be redrawn when undoing (e.g. finalization).</param> public ShapesHistoryItem(BaseEditEngine passedEE, string icon, string text, ImageSurface passedUserSurface, UserLayer passedUserLayer, int passedSelectedPointIndex, int passedSelectedShapeIndex, bool passedRedrawEverything) : base(icon, text) { ee = passedEE; userLayer = passedUserLayer; userSurfaceDiff = SurfaceDiff.Create(passedUserSurface, userLayer.Surface, true); if (userSurfaceDiff == null) { userSurface = passedUserSurface; } else { (passedUserSurface as IDisposable).Dispose(); } sEngines = BaseEditEngine.SEngines.PartialClone(); selectedPointIndex = passedSelectedPointIndex; selectedShapeIndex = passedSelectedShapeIndex; redrawEverything = passedRedrawEverything; }
/// <summary> /// A history item for when shapes are modified. /// </summary> /// <param name="passedEE">The EditEngine being used.</param> /// <param name="icon">The history item's icon.</param> /// <param name="text">The history item's title.</param> public ShapesModifyHistoryItem(BaseEditEngine passedEE, string icon, string text) : base(icon, text) { ee = passedEE; sEngines = BaseEditEngine.SEngines.PartialClone(); selectedPointIndex = ee.SelectedPointIndex; selectedShapeIndex = ee.SelectedShapeIndex; }
private void Swap() { //Store the old shape data temporarily. ShapeEngineCollection oldSEngines = sEngines; //Swap half of the data. sEngines = BaseEditEngine.SEngines; //Swap the other half. BaseEditEngine.SEngines = oldSEngines; //Ensure that all of the shapes that should no longer be drawn have their ReEditableLayer removed from the drawing loop. foreach (ShapeEngine se in sEngines) { //Determine if it is currently in the drawing loop and should no longer be. Note: a DrawingLayer could be both removed and then //later added in the same swap operation, but this is faster than looping through each ShapeEngine in BaseEditEngine.SEngines. if (se.DrawingLayer.InTheLoop && !BaseEditEngine.SEngines.Contains(se)) { se.DrawingLayer.TryRemoveLayer(); } } //Ensure that all of the shapes that should now be drawn have their ReEditableLayer in the drawing loop. foreach (ShapeEngine se in BaseEditEngine.SEngines) { //Determine if it is currently out of the drawing loop; if not, it should be. if (!se.DrawingLayer.InTheLoop) { se.DrawingLayer.TryAddLayer(); } } //Swap the selected point data. int temp = selectedPointIndex; selectedPointIndex = ee.SelectedPointIndex; ee.SelectedPointIndex = temp; //Swap the selected shape data. temp = selectedShapeIndex; selectedShapeIndex = ee.SelectedShapeIndex; ee.SelectedShapeIndex = temp; //Determine if the currently active tool matches the shape's corresponding tool, and if not, switch to it. BaseEditEngine.ActivateCorrespondingTool(selectedShapeIndex, true); //The currently active tool should now match the shape's corresponding tool. }
private void Swap(bool redraw) { // Grab the original surface ImageSurface surf = userLayer.Surface; if (userSurfaceDiff != null) { userSurfaceDiff.ApplyAndSwap(surf); PintaCore.Workspace.Invalidate(userSurfaceDiff.GetBounds()); } else { // Undo to the "old" surface userLayer.Surface = userSurface; // Store the original surface for Redo userSurface = surf; //Redraw everything since surfaces were swapped. PintaCore.Workspace.Invalidate(); } //Store the old shape data temporarily. ShapeEngineCollection oldSEngines = sEngines; //Swap half of the data. sEngines = BaseEditEngine.SEngines; //Swap the other half. BaseEditEngine.SEngines = oldSEngines; //Ensure that all of the shapes that should no longer be drawn have their ReEditableLayer removed from the drawing loop. foreach (ShapeEngine se in sEngines) { //Determine if it is currently in the drawing loop and should no longer be. Note: a DrawingLayer could be both removed and then //later added in the same swap operation, but this is faster than looping through each ShapeEngine in BaseEditEngine.SEngines. if (se.DrawingLayer.InTheLoop && !BaseEditEngine.SEngines.Contains(se)) { se.DrawingLayer.TryRemoveLayer(); } } //Ensure that all of the shapes that should now be drawn have their ReEditableLayer in the drawing loop. foreach (ShapeEngine se in BaseEditEngine.SEngines) { //Determine if it is currently out of the drawing loop; if not, it should be. if (!se.DrawingLayer.InTheLoop) { se.DrawingLayer.TryAddLayer(); } } //Swap the selected point data. int temp = selectedPointIndex; selectedPointIndex = ee.SelectedPointIndex; ee.SelectedPointIndex = temp; //Swap the selected shape data. temp = selectedShapeIndex; selectedShapeIndex = ee.SelectedShapeIndex; ee.SelectedShapeIndex = temp; //Determine if the currently active tool matches the shape's corresponding tool, and if not, switch to it. if (BaseEditEngine.ActivateCorrespondingTool(ee.SelectedShapeIndex, true) != null) { //The currently active tool now matches the shape's corresponding tool. if (redraw) { ((ShapeTool)PintaCore.Tools.CurrentTool).EditEngine.DrawAllShapes(); } } }