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
27static Image *curbg;27static Image *curbg;
28static int charw, charh;28static int charw, charh;
29static Field field;29static Field field;
30static Mbuf_reusable mbuf;
31static Oevent_list events;
30 32
31static char *menu3i[] = {33static char *menu3i[] = {
32 "load",34 "load",
@@ -108,6 +110,19 @@ process(Oevent_list *events) · 75 unmodified lines
108 }110 }
109}111}
110 112
113static void
114orcathread(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
111static void126static void
112redraw(void)127redraw(void)
113{128{
@@ -213,10 +228,9 @@ select(void) · 99 unmodified lines
213void228void
214threadmain(int argc, char **argv)229threadmain(int argc, char **argv)
215{230{
216 Mbuf_reusable mbuf;
217 Oevent_list events;
218 Mousectl *mctl;231 Mousectl *mctl;
219 Keyboardctl *kctl;232 Keyboardctl *kctl;
233 Field copyfield;
220 Rune key;234 Rune key;
221 Mouse m;235 Mouse m;
222 char tmp[256];236 char tmp[256];
@@ -250,6 +264,7 @@ threadmain(int argc, char **argv) · 27 unmodified lines
250 264
251 screensize(&w, &h);265 screensize(&w, &h);
252 field_init_fill(&field, h, w, '.');266 field_init_fill(&field, h, w, '.');
267 field_init(&copyfield);
253 268
254 linebuf = malloc(sizeof(Rune)*MAX(w+1, 64));269 linebuf = malloc(sizeof(Rune)*MAX(w+1, 64));
255 memset(noteoff, 0, sizeof(noteoff));270 memset(noteoff, 0, sizeof(noteoff));
@@ -258,10 +273,7 @@ threadmain(int argc, char **argv) · 2 unmodified lines
258 oevent_list_init(&events);273 oevent_list_init(&events);
259 274
260 for (tick = 0;; tick++) {275 for (tick = 0;; tick++) {
261 mbuffer_clear(mbuf.buffer, h, w);276 orcathread(nil);
262 oevent_list_clear(&events);
263 orca_run(field.buffer, mbuf.buffer, h, w, tick, &events, 0);
264 process(&events);
265 redraw();277 redraw();
266 278
267 oldw = w = field.width;279 oldw = w = field.width;
@@ -357,9 +369,17 @@ threadmain(int argc, char **argv) · 89 unmodified lines
357 }369 }
358 370
359 if (w != oldw || h != oldh) {371 if (w != oldw || h != oldh) {
372 field_copy(&field, &copyfield);
360 field_resize_raw(&field, h, w);373 field_resize_raw(&field, h, w);
361 if (w >= oldw && h >= oldh)374 memset(field.buffer, '.', w*h);
362 memset(field.buffer + oldw*oldh, '.', w*h - oldw*oldh);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 );
363 }383 }
364 }384 }
365 385
@@ -373,6 +393,7 @@ end: · 7 unmodified lines
373 mbuf_reusable_deinit(&mbuf);393 mbuf_reusable_deinit(&mbuf);
374 oevent_list_deinit(&events);394 oevent_list_deinit(&events);
375 field_deinit(&field);395 field_deinit(&field);
396 field_deinit(&copyfield);
376 397
377 threadexitsall(nil);398 threadexitsall(nil);
378}399}

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