Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fix a case where these tools can add a history item without actually …

…doing anything.
  • Loading branch information...
commit 905a609745f6133e197bd482ce13a95fc212a90c 1 parent 6317904
Jonathan Pobst jpobst authored
12 Pinta/Tools/EraserTool.cs
@@ -43,6 +43,7 @@ public class EraserTool : BaseTool
43 43 private ToolBarButton brush_width_plus;
44 44
45 45 private ImageSurface undo_surface;
  46 + private bool surface_modified;
46 47
47 48 public EraserTool ()
48 49 {
@@ -107,6 +108,7 @@ private void PlusButtonClickedEvent (object o, EventArgs args)
107 108 #region Mouse Handlers
108 109 protected override void OnMouseDown (Gtk.DrawingArea canvas, Gtk.ButtonPressEventArgs args, Cairo.PointD point)
109 110 {
  111 + surface_modified = false;
110 112 undo_surface = PintaCore.Layers.CurrentLayer.Surface.Clone ();
111 113 }
112 114
@@ -129,6 +131,9 @@ protected override void OnMouseMove (object o, Gtk.MotionNotifyEventArgs args, C
129 131 return;
130 132 }
131 133
  134 + if (PintaCore.Workspace.PointInCanvas (point))
  135 + surface_modified = true;
  136 +
132 137 ImageSurface surf = PintaCore.Layers.CurrentLayer.Surface;
133 138
134 139 using (Context g = new Context (surf)) {
@@ -154,7 +159,12 @@ protected override void OnMouseMove (object o, Gtk.MotionNotifyEventArgs args, C
154 159
155 160 protected override void OnMouseUp (Gtk.DrawingArea canvas, Gtk.ButtonReleaseEventArgs args, Cairo.PointD point)
156 161 {
157   - PintaCore.History.PushNewItem (new SimpleHistoryItem (Icon, Name, undo_surface, PintaCore.Layers.CurrentLayerIndex));
  162 + if (surface_modified)
  163 + PintaCore.History.PushNewItem (new SimpleHistoryItem (Icon, Name, undo_surface, PintaCore.Layers.CurrentLayerIndex));
  164 + else if (undo_surface != null)
  165 + (undo_surface as IDisposable).Dispose ();
  166 +
  167 + surface_modified = false;
158 168 }
159 169 #endregion
160 170
16 Pinta/Tools/PaintBrushTool.cs
@@ -43,7 +43,8 @@ public class PaintBrushTool : BaseTool
43 43 private ToolBarButton brush_width_plus;
44 44
45 45 private ImageSurface undo_surface;
46   -
  46 + private bool surface_modified;
  47 +
47 48 public PaintBrushTool ()
48 49 {
49 50 }
@@ -107,6 +108,7 @@ private void PlusButtonClickedEvent (object o, EventArgs args)
107 108 #region Mouse Handlers
108 109 protected override void OnMouseDown (Gtk.DrawingArea canvas, Gtk.ButtonPressEventArgs args, Cairo.PointD point)
109 110 {
  111 + surface_modified = false;
110 112 undo_surface = PintaCore.Layers.CurrentLayer.Surface.Clone ();
111 113 }
112 114
@@ -122,7 +124,7 @@ protected override void OnMouseMove (object o, Gtk.MotionNotifyEventArgs args, C
122 124 last_point = point_empty;
123 125 return;
124 126 }
125   -
  127 +
126 128 DrawingArea drawingarea1 = (DrawingArea)o;
127 129
128 130 int x = (int)point.X;
@@ -132,6 +134,9 @@ protected override void OnMouseMove (object o, Gtk.MotionNotifyEventArgs args, C
132 134 last_point = new Point (x, y);
133 135 return;
134 136 }
  137 +
  138 + if (PintaCore.Workspace.PointInCanvas (point))
  139 + surface_modified = true;
135 140
136 141 ImageSurface surf = PintaCore.Layers.CurrentLayer.Surface;
137 142
@@ -158,7 +163,12 @@ protected override void OnMouseMove (object o, Gtk.MotionNotifyEventArgs args, C
158 163
159 164 protected override void OnMouseUp (Gtk.DrawingArea canvas, Gtk.ButtonReleaseEventArgs args, Cairo.PointD point)
160 165 {
161   - PintaCore.History.PushNewItem (new SimpleHistoryItem (Icon, Name, undo_surface, PintaCore.Layers.CurrentLayerIndex));
  166 + if (surface_modified)
  167 + PintaCore.History.PushNewItem (new SimpleHistoryItem (Icon, Name, undo_surface, PintaCore.Layers.CurrentLayerIndex));
  168 + else if (undo_surface != null)
  169 + (undo_surface as IDisposable).Dispose ();
  170 +
  171 + surface_modified = false;
162 172 }
163 173 #endregion
164 174
18 Pinta/Tools/ShapeTool.cs
@@ -44,7 +44,8 @@ public abstract class ShapeTool : BaseTool
44 44
45 45 protected Rectangle last_dirty;
46 46 protected ImageSurface undo_surface;
47   -
  47 + protected bool surface_modified;
  48 +
48 49 public ShapeTool ()
49 50 {
50 51 }
@@ -123,7 +124,8 @@ protected override void OnMouseDown (Gtk.DrawingArea canvas, Gtk.ButtonPressEven
123 124
124 125 PintaCore.Layers.ToolLayer.Clear ();
125 126 PintaCore.Layers.ToolLayer.Hidden = false;
126   -
  127 +
  128 + surface_modified = false;
127 129 undo_surface = PintaCore.Layers.CurrentLayer.Surface.Clone ();
128 130 }
129 131
@@ -140,8 +142,13 @@ protected override void OnMouseUp (Gtk.DrawingArea canvas, Gtk.ButtonReleaseEven
140 142 PintaCore.Workspace.InvalidateRect (last_dirty.ToGdkRectangle (), false);
141 143
142 144 is_drawing = false;
143   -
144   - PintaCore.History.PushNewItem (CreateHistoryItem ());
  145 +
  146 + if (surface_modified)
  147 + PintaCore.History.PushNewItem (CreateHistoryItem ());
  148 + else if (undo_surface != null)
  149 + (undo_surface as IDisposable).Dispose ();
  150 +
  151 + surface_modified = false;
145 152 }
146 153
147 154 protected override void OnMouseMove (object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point)
@@ -161,6 +168,9 @@ protected override void OnMouseMove (object o, Gtk.MotionNotifyEventArgs args, C
161 168 PintaCore.Workspace.InvalidateRect (dirty.ToGdkRectangle (), false);
162 169
163 170 last_dirty = dirty;
  171 +
  172 + if (PintaCore.Workspace.PointInCanvas (point))
  173 + surface_modified = true;
164 174 }
165 175 #endregion
166 176

0 comments on commit 905a609

Please sign in to comment.
Something went wrong with that request. Please try again.