History

plan9: fix field resizing by copying to a separate buffer and back

Sigrid Haflínudóttir committed 6 years ago

Commit b2bacf21 parent 61bd27d1 file · +29 −8Browse files

Unified · Split

plan9.c+29−8
@@ -27,6 +27,8 @@ static int curx, cury; · 26 unmodified lines
2727 static Image *curbg;
2828 static int charw, charh;
2929 static Field field;
30+static Mbuf_reusable mbuf;
31+static Oevent_list events;
3032
3133 static char *menu3i[] = {
3234 "load",
@@ -108,6 +110,19 @@ process(Oevent_list *events) · 75 unmodified lines
108110 }
109111 }
110112
113+static void
114+orcathread(void *)
115+{
116+ int w, h;
117+
118+ w = field.width;
119+ h = field.height;
120+ mbuffer_clear(mbuf.buffer, h, w);
121+ oevent_list_clear(&events);
122+ orca_run(field.buffer, mbuf.buffer, h, w, tick, &events, 0);
123+ process(&events);
124+}
125+
111126 static void
112127 redraw(void)
113128 {
@@ -213,10 +228,9 @@ select(void) · 99 unmodified lines
213228 void
214229 threadmain(int argc, char **argv)
215230 {
216− Mbuf_reusable mbuf;
217− Oevent_list events;
218231 Mousectl *mctl;
219232 Keyboardctl *kctl;
233+ Field copyfield;
220234 Rune key;
221235 Mouse m;
222236 char tmp[256];
@@ -250,6 +264,7 @@ threadmain(int argc, char **argv) · 27 unmodified lines
250264
251265 screensize(&w, &h);
252266 field_init_fill(&field, h, w, '.');
267+ field_init(&copyfield);
253268
254269 linebuf = malloc(sizeof(Rune)*MAX(w+1, 64));
255270 memset(noteoff, 0, sizeof(noteoff));
@@ -258,10 +273,7 @@ threadmain(int argc, char **argv) · 2 unmodified lines
258273 oevent_list_init(&events);
259274
260275 for (tick = 0;; tick++) {
261− mbuffer_clear(mbuf.buffer, h, w);
262− oevent_list_clear(&events);
263− orca_run(field.buffer, mbuf.buffer, h, w, tick, &events, 0);
264− process(&events);
276+ orcathread(nil);
265277 redraw();
266278
267279 oldw = w = field.width;
@@ -357,9 +369,17 @@ threadmain(int argc, char **argv) · 89 unmodified lines
357369 }
358370
359371 if (w != oldw || h != oldh) {
372+ field_copy(&field, &copyfield);
360373 field_resize_raw(&field, h, w);
361− if (w >= oldw && h >= oldh)
362− memset(field.buffer + oldw*oldh, '.', w*h - oldw*oldh);
374+ memset(field.buffer, '.', w*h);
375+ gbuffer_copy_subrect(
376+ copyfield.buffer,
377+ field.buffer,
378+ copyfield.height, copyfield.width,
379+ field.height, field.width,
380+ 0, 0, 0, 0,
381+ MIN(field.height, copyfield.height), MIN(field.width, copyfield.width)
382+ );
363383 }
364384 }
365385
@@ -373,6 +393,7 @@ end: · 7 unmodified lines
373393 mbuf_reusable_deinit(&mbuf);
374394 oevent_list_deinit(&events);
375395 field_deinit(&field);
396+ field_deinit(&copyfield);
376397
377398 threadexitsall(nil);
378399 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t