From aaf01e8b2addc0c5f6bf8671b497f177e36ada04 Mon Sep 17 00:00:00 2001 From: ac-stef Date: Sun, 16 Feb 2014 16:50:48 +0100 Subject: [PATCH] redo for the editor an undo for undos :) --- config/resetbinds.cfg | 1 + source/src/editing.cpp | 26 ++++++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/config/resetbinds.cfg b/config/resetbinds.cfg index 42d14a38..b1705aec 100644 --- a/config/resetbinds.cfg +++ b/config/resetbinds.cfg @@ -94,6 +94,7 @@ bind P [ editheight 2 1 ] bind Q [] editbind Q [ domodifier 1 ] bind R reload +editbind R redo bind S backward bind T saycommand // or even "saycommand >" bind U [] diff --git a/source/src/editing.cpp b/source/src/editing.cpp index 29f91b5c..63bef642 100644 --- a/source/src/editing.cpp +++ b/source/src/editing.cpp @@ -289,16 +289,22 @@ void cursorupdate() // called every frame fr glLineWidth(1); } -vector undos; // unlimited undo +vector undos, redos; // unlimited undo VAR(undomegs, 0, 5, 50); // bounded by n megs void pruneundos(int maxremain) // bound memory { - int t = 0; + int u = 0, r = 0; + maxremain /= sizeof(sqr); loopvrev(undos) { - t += undos[i]->xs*undos[i]->ys*sizeof(sqr); - if(t>maxremain) delete[] (uchar *)undos.remove(i); + u += undos[i]->xs * undos[i]->ys; + if(u > maxremain) delete[] (uchar *)undos.remove(i); + } + loopvrev(redos) + { + r += redos[i]->xs * redos[i]->ys; + if(r > maxremain) delete[] (uchar *)redos.remove(i); } } @@ -313,6 +319,17 @@ void editundo() EDITMP; if(undos.empty()) { conoutf("nothing more to undo"); return; } block *p = undos.pop(); + redos.add(blockcopy(*p)); + blockpaste(*p); + freeblock(p); +} + +void editredo() +{ + EDITMP; + if(redos.empty()) { conoutf("nothing more to redo"); return; } + block *p = redos.pop(); + undos.add(blockcopy(*p)); blockpaste(*p); freeblock(p); } @@ -782,6 +799,7 @@ COMMAND(arch, "i"); COMMANDF(slope, "ii", (int *xd, int *yd) { slope(*xd, *yd); }); COMMANDF(vdelta, "i", (int *d) { setvdelta(*d); }); COMMANDN(undo, editundo, ""); +COMMANDN(redo, editredo, ""); COMMAND(copy, ""); COMMAND(paste, ""); COMMANDF(edittex, "ii", (int *type, int *dir) { edittex(*type, *dir); });