Mercurial > hg > nnchat
comparison ui.c @ 585:199fd3371035
Improve screen update economy by only refreshing when needed.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 07 Jul 2013 02:08:46 +0300 |
parents | 97a49a6cc959 |
children | 2c6945599b16 |
comparison
equal
deleted
inserted
replaced
584:6d23385c0643 | 585:199fd3371035 |
---|---|
330 | 330 |
331 | 331 |
332 void nnwin_update(BOOL force, BOOL mask, nn_editbuf_t *ebuf, char *username, int usercolor) | 332 void nnwin_update(BOOL force, BOOL mask, nn_editbuf_t *ebuf, char *username, int usercolor) |
333 { | 333 { |
334 int sx, sy; | 334 int sx, sy; |
335 | 335 BOOL changed = FALSE; |
336 // Save cursor position | |
337 getyx(stdscr, sy, sx); | |
338 | 336 |
339 // Clear screen if forced or main or editbuf are dirty | 337 // Clear screen if forced or main or editbuf are dirty |
340 if (force || (currWin != NULL && currWin->dirty) || (ebuf != NULL && ebuf->dirty)) | 338 if (force || (currWin != NULL && currWin->dirty) || (ebuf != NULL && ebuf->dirty)) |
341 { | 339 { |
340 // Save cursor position | |
341 getyx(stdscr, sy, sx); | |
342 | |
342 wattrset(stdscr, A_NORMAL); | 343 wattrset(stdscr, A_NORMAL); |
343 wbkgdset(stdscr, COLOR_PAIR(0)); | 344 wbkgdset(stdscr, COLOR_PAIR(0)); |
344 werase(stdscr); | 345 werase(stdscr); |
345 force = TRUE; | 346 force = TRUE; |
347 changed = TRUE; | |
348 } | |
349 else | |
350 { | |
351 // Save cursor position | |
352 getyx(stdscr, sy, sx); | |
346 } | 353 } |
347 | 354 |
348 // Check if update is forced or if the window is dirty | 355 // Check if update is forced or if the window is dirty |
349 if (currWin != NULL && (force || currWin->dirty)) | 356 if (currWin != NULL && (force || currWin->dirty)) |
350 { | 357 { |
351 int y, offs; | 358 int y, offs; |
352 qringbuf_t *buf = currWin->data; | 359 qringbuf_t *buf = currWin->data; |
360 | |
361 changed = TRUE; | |
353 | 362 |
354 for (y = scrHeight - 4, offs = buf->size - 1 - currWin->pos; offs >= 0 && y > 0; offs--) | 363 for (y = scrHeight - 4, offs = buf->size - 1 - currWin->pos; offs >= 0 && y > 0; offs--) |
355 { | 364 { |
356 nn_line_t *line = (nn_line_t *) buf->data[offs]; | 365 nn_line_t *line = (nn_line_t *) buf->data[offs]; |
357 if (line != NULL) | 366 if (line != NULL) |
387 | 396 |
388 currWin->dirty = FALSE; | 397 currWin->dirty = FALSE; |
389 } | 398 } |
390 | 399 |
391 // Update statusline | 400 // Update statusline |
401 if (changed || force) | |
392 { | 402 { |
393 char tmpStamp[32], tmpStr[128]; | 403 char tmpStamp[32], tmpStr[128]; |
394 int i; | 404 int i; |
395 | 405 |
396 str_get_timestamp(tmpStamp, sizeof(tmpStamp), "%H:%M:%S"); | 406 str_get_timestamp(tmpStamp, sizeof(tmpStamp), "%H:%M:%S"); |
426 { | 436 { |
427 snprintf(tmpStr, sizeof(tmpStr), "%d ", i + 1); | 437 snprintf(tmpStr, sizeof(tmpStr), "%d ", i + 1); |
428 waddstr(stdscr, tmpStr); | 438 waddstr(stdscr, tmpStr); |
429 } | 439 } |
430 } | 440 } |
431 } | 441 |
432 | 442 // Restore cursor position |
433 // Restore cursor position | 443 wmove(stdscr, sy, sx); |
434 wmove(stdscr, sy, sx); | 444 } |
435 | 445 |
436 // Update editbuf if needed | 446 // Update editbuf if needed |
437 if (appCursesInit && ebuf != NULL && (force || ebuf->dirty)) | 447 if (ebuf != NULL && (force || ebuf->dirty)) |
438 { | 448 { |
439 int yoffs = ebuf->pos / scrWidth, | 449 int yoffs = ebuf->pos / scrWidth, |
440 xoffs = ebuf->pos % scrWidth; | 450 xoffs = ebuf->pos % scrWidth; |
441 | 451 |
442 wmove(stdscr, scrHeight - 3, 0); | 452 wmove(stdscr, scrHeight - 3, 0); |
458 waddnstr(stdscr, tmp, ebuf->len); | 468 waddnstr(stdscr, tmp, ebuf->len); |
459 th_free(tmp); | 469 th_free(tmp); |
460 } | 470 } |
461 wmove(stdscr, scrHeight - 3 + yoffs, xoffs); | 471 wmove(stdscr, scrHeight - 3 + yoffs, xoffs); |
462 | 472 |
463 } | 473 changed = TRUE; |
464 | 474 } |
465 wrefresh(stdscr); | 475 |
476 if (changed) | |
477 wrefresh(stdscr); | |
466 } | 478 } |
467 | 479 |
468 | 480 |
469 void nnwin_input_process(nn_editbuf_t *editBuf, nn_editstate_t *editState, | 481 void nnwin_input_process(nn_editbuf_t *editBuf, nn_editstate_t *editState, |
470 BOOL (*callback)(int, nn_editbuf_t *, nn_editstate_t *)) | 482 BOOL (*callback)(int, nn_editbuf_t *, nn_editstate_t *)) |