ref: 982e810a84ef67bd44c6f3ad008e147af5780d73
parent: cf6789dc703ba88c7fa125d0895f75ec0f6baf80
author: cancel <cancel@cancel.fm>
date: Mon Dec 3 04:53:11 EST 2018
Clean up field copying, add wrapper
--- a/field.c
+++ b/field.c
@@ -32,6 +32,11 @@
void field_deinit(Field* f) { free(f->buffer); }
+void field_copy(Field* src, Field* dest) {
+ field_resize_raw_if_necessary(dest, src->height, src->width);
+ field_copy_subrect(src, dest, 0, 0, 0, 0, src->height, src->width);
+}
+
void field_copy_subrect(Field* src, Field* dest, Usz src_y, Usz src_x,
Usz dest_y, Usz dest_x, Usz height, Usz width) {
Usz src_height = src->height;
--- a/field.h
+++ b/field.h
@@ -6,6 +6,7 @@
void field_resize_raw(Field* field, Usz height, Usz width);
void field_resize_raw_if_necessary(Field* field, Usz height, Usz width);
void field_deinit(Field* field);
+void field_copy(Field* src, Field* dest);
void field_copy_subrect(Field* src, Field* dest, Usz src_y, Usz src_x,
Usz dest_y, Usz dest_x, Usz height, Usz width);
void field_fill_subrect(Field* field, Usz y, Usz x, Usz height, Usz width,
--- a/tui_main.c
+++ b/tui_main.c
@@ -236,16 +236,12 @@
hist->first = new_node->next;
hist->first->prev = NULL;
}
- field_resize_raw_if_necessary(&new_node->field, field->height,
- field->width);
} else {
new_node = malloc(sizeof(Undo_node));
++hist->count;
field_init(&new_node->field);
- field_resize_raw(&new_node->field, field->height, field->width);
}
- field_copy_subrect(field, &new_node->field, 0, 0, 0, 0, field->height,
- field->width);
+ field_copy(field, &new_node->field);
new_node->tick_num = tick_num;
if (hist->last) {
hist->last->next = new_node;
@@ -263,12 +259,7 @@
Undo_node* last = hist->last;
if (!last)
return;
- Usz height = last->field.height;
- Usz width = last->field.width;
- if (out_field->height != height || out_field->width != width) {
- field_resize_raw(out_field, height, width);
- }
- field_copy_subrect(&last->field, out_field, 0, 0, 0, 0, height, width);
+ field_copy(&last->field, out_field);
*out_tick_num = last->tick_num;
if (hist->first == last) {
hist->first = NULL;
@@ -461,12 +452,10 @@
// etc.
if (needs_remarking) {
field_resize_raw_if_necessary(&scratch_field, field.height, field.width);
- field_copy_subrect(&field, &scratch_field, 0, 0, 0, 0, field.height,
- field.width);
+ field_copy(&field, &scratch_field);
orca_run(field.buffer, markmap_r.buffer, field.height, field.width,
tick_num, &bank);
- field_copy_subrect(&scratch_field, &field, 0, 0, 0, 0, field.height,
- field.width);
+ field_copy(&scratch_field, &field);
needs_remarking = false;
}
draw_field(stdscr, term_height, term_width, 0, 0, field.buffer,