summaryrefslogtreecommitdiff
path: root/draw.c
diff options
context:
space:
mode:
authorKatolaZ <katolaz@freaknet.org>2019-07-31 00:10:35 +0100
committerKatolaZ <katolaz@freaknet.org>2019-07-31 00:10:35 +0100
commit526ce3a130732d4a2374a6e36a689d9e0cf5cc34 (patch)
tree9b6f76dbc70bf9a4d2becb9b9d8103eb57663aa0 /draw.c
parent6da2f3f89afda08eeba385da1c36414154113d47 (diff)
preliminary support for undo
Diffstat (limited to 'draw.c')
-rw-r--r--draw.c55
1 files changed, 51 insertions, 4 deletions
diff --git a/draw.c b/draw.c
index 3c98534..e3bdbce 100644
--- a/draw.c
+++ b/draw.c
@@ -1,4 +1,5 @@
#include <stdlib.h>
+#include <string.h>
#include "gramscii.h"
#include "config.h"
@@ -103,16 +104,19 @@ void draw_box(int x1, int y1, int fix){
int i;
void (*f)(int, int, char);
- if (fix == FIX)
- f = set_xy;
- else
- f = draw_xy;
xmin = MIN(x, x1);
xmax = MAX(x, x1);
ymin = MIN(y, y1);
ymax = MAX(y, y1);
+ if (fix == FIX){
+ f = set_xy;
+ copy_lines_to_ring(ymin, ymax, CUR);
+ }
+ else
+ f = draw_xy;
+
for(i=xmin+1; i<=xmax; i++){
f(i, ymin, line_h);
f(i, ymax, line_h);
@@ -125,6 +129,8 @@ void draw_box(int x1, int y1, int fix){
f(xmin, ymax, corner);
f(xmax, ymin, corner);
f(xmax, ymax, corner);
+ if (fix == FIX)
+ copy_lines_to_ring(ymin, ymax, LST);
show_cursor();
}
@@ -157,6 +163,7 @@ update_box:
void draw_arrow(int x, int y, char *a, int a_len, int fix){
+ /* FIXME: copy affected lines to undo */
int i, j, cur_dir;
char line;
void (*f)(int, int, char);
@@ -266,6 +273,7 @@ void do_erase(int x1, int y1){
void erase(FILE *fc){
+ /*FIXME: add affected lines to undo */
char c;
int orig_x = x, orig_y = y;
status_bar();
@@ -308,8 +316,11 @@ void visual_box(FILE *fc){
case 'x':/* erase */
if (c == 'x')
yank_region(MIN(orig_x,x), MIN(orig_y,y), MAX(orig_x, x), MAX(orig_y, y));
+ copy_lines_to_ring(MIN(orig_y, y), MAX(orig_y, y), CUR);
erase_box(orig_x, orig_y, f);
erase_blank_lines(MIN(y,orig_y), MAX(y, orig_y));
+ copy_lines_to_ring(MIN(orig_y, y), MAX(orig_y, y), LST);
+
modified = 1;
goto vis_exit;
break;
@@ -331,6 +342,42 @@ vis_exit:
}
void paste(){
+ int y2;
+
+ y2 = y + cutbuf.num - 1;
+ copy_lines_to_ring(y, y2, CUR);
paste_region(x, y);
+ copy_lines_to_ring(y, y2, LST);
+ redraw();
+}
+
+void put_lines(lineset_t *u){
+ int i, n;
+
+ for (i=0; i< u->num; i++){
+ n = u->l[i].n;
+ ensure_line_length(&(screen.l[i]), u->l[i].lst);
+ strcpy(screen.l[n].s, u->l[i].s);
+ screen.l[n].lst = u->l[i].lst;
+ }
+}
+
+
+void undo_change(){
+ if (undo_cur >= 0){
+ put_lines(& (undo[undo_cur]));
+ undo_cur --;
+ }
+ redraw();
+ modified = 1;
+}
+
+void redo_change(){
+ if (undo_cur < undo_lst){
+ undo_cur ++;
+ put_lines(& (undo[undo_cur]));
+ }
redraw();
+ modified = 1;
}
+