Skip to content

Commit

Permalink
Merge branch 'Redo-function'
Browse files Browse the repository at this point in the history
  • Loading branch information
kellyegan committed Oct 28, 2014
2 parents 938d2df + 1812d0b commit 5501563
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 14 additions & 2 deletions Drawing.pde
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import processing.core.PApplet;

class Drawing {
List<Stroke> strokes;
List<Stroke> undos;
Stroke currentStroke;

float minimumDistance;
Expand All @@ -35,6 +36,7 @@ class Drawing {
Drawing(PApplet a, String filepath ) {
app = a;
strokes = new ArrayList<Stroke>();
undos = new ArrayList<Stroke>();
minimumDistance = 10;
load( filepath );
}
Expand Down Expand Up @@ -186,6 +188,7 @@ class Drawing {
* @param brushStyle Brush to apply to this new stroke
*/
void startStroke(Brush brushStyle) {
undos.clear();
if( currentStroke == null ) {
currentStroke = new Stroke( app, brushStyle );
strokes.add( currentStroke );
Expand Down Expand Up @@ -314,15 +317,24 @@ class Drawing {
* Remove all Stroke data from the Drawing object
*/
void clearStrokes() {
strokes = new ArrayList<Stroke>();
strokes.clear();
}

/**
* Removes the last stroke from the Drawing object
*/
void undoLastStroke() {
if( !strokes.isEmpty() ) {
strokes.remove(strokes.size() - 1);
undos.add( strokes.remove(strokes.size() - 1) );
}
}

/**
* Add last stroke removed from Drawing object back.
*/
void redoLastStroke() {
if( !undos.isEmpty() ) {
strokes.add( undos.remove(undos.size() - 1 ) );
}
}

Expand Down
4 changes: 3 additions & 1 deletion sketch3d.pde
Original file line number Diff line number Diff line change
Expand Up @@ -527,9 +527,11 @@ void keyPressed() {
d.clearStrokes();
break;
case 'z':
case 'Z':
d.undoLastStroke();
break;
case 'Z':
d.redoLastStroke();
break;
case '1':
arcBall.setView( arcBall.FRONT );
break;
Expand Down

0 comments on commit 5501563

Please sign in to comment.