-
-
Save gdyrrahitis/5bfb63fbe5573d06d780366b7c6e2ebc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void Draw() | |
{ | |
// Save state | |
SavePreviousState(); | |
// Carry out the command execution | |
var brush = new SolidBrush(_color); | |
var rectangle = new System.Drawing.Rectangle(_point.X, _point.Y, Width, Height); | |
_graphics.FillRectangle(brush, rectangle); | |
} | |
// Saving all pixels in the area we are going to draw | |
// We are storing the color of each pixel | |
// When we perform an undo, all pixels will be restored to initial state | |
private void SavePreviousState() | |
{ | |
for (int i = _point.X; i < _point.X + Width; i++) | |
{ | |
for (int j = _point.Y; j < _point.Y + Height; j++) | |
{ | |
_previousState.Add(_bitmap.GetPixel(i, j)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment