From c12102b31ad32c37c46b73a7a06188914ad96653 Mon Sep 17 00:00:00 2001 From: Laurent MAZET Date: Tue, 8 Oct 2024 12:43:36 +0200 Subject: [PATCH] limit refresh --- ndisplay.c | 83 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 51 insertions(+), 32 deletions(-) diff --git a/ndisplay.c b/ndisplay.c index 572e9cb..ac41fd2 100644 --- a/ndisplay.c +++ b/ndisplay.c @@ -166,74 +166,91 @@ int main (int argc, char *argv[]) /* event loop */ int stop = 0; + int change = 1; while (!stop) { int x, y; - /* clear screen */ - clear (); - /* check cursor location */ if (images[scale]->width - xcursor < COLS / mode) { - xcursor = max (0, images[scale]->width - COLS / mode); + int newxcursor = max (0, images[scale]->width - COLS / mode); + if (newxcursor != xcursor) { + xcursor = newxcursor; + change = 1; + } } if (images[scale]->height - ycursor < LINES) { - ycursor = max (0, images[scale]->height - LINES); + int newycursor = max (0, images[scale]->height - LINES); + if (newycursor != ycursor) { + ycursor = newycursor; + change = 1; + } } - /* display current image view */ - int width = min (images[scale]->width - xcursor, COLS / mode); - int height = min (images[scale]->height - ycursor, LINES); - VERBOSE (DEBUG, FILE *fd = fopen ("my.log", "a"); fprintf (fd, "(%d, %d)\n", width, height); fclose (fd)); - for (x = 0; x < width; x++) { - for (y = 0; y < height; y++) { + if (change) { - int ind = x + xcursor + images[scale]->width * (y + ycursor); - if (ind >= images[scale]->width * images[scale]->height) { - continue; - } - color_t *color = findncolor (correction (images[scale]->red[ind], gf[0]), - correction (images[scale]->green[ind], gf[1]), - correction (images[scale]->blue[ind], gf[2]), COLORS); - attron (COLOR_PAIR (color->code)); - - move (y, x * mode); - cchar_t cchar; - wchar_t wchar[2] = {0}; - wchar[0] = (wchar_t) ' '; - setcchar (&cchar, wchar, A_NORMAL, 0, NULL); - add_wch (&cchar); - if (mode == 2) { - move (y, x * mode + 1); + /* clear screen */ + clear (); + + /* display current image view */ + int width = min (images[scale]->width - xcursor, COLS / mode); + int height = min (images[scale]->height - ycursor, LINES); + VERBOSE (DEBUG, FILE *fd = fopen ("my.log", "a"); fprintf (fd, "(%d, %d)\n", width, height); fclose (fd)); + for (x = 0; x < width; x++) { + for (y = 0; y < height; y++) { + + int ind = x + xcursor + images[scale]->width * (y + ycursor); + if (ind >= images[scale]->width * images[scale]->height) { + continue; + } + color_t *color = findncolor (correction (images[scale]->red[ind], gf[0]), + correction (images[scale]->green[ind], gf[1]), + correction (images[scale]->blue[ind], gf[2]), COLORS); + attron (COLOR_PAIR (color->code)); + + move (y, x * mode); + cchar_t cchar; + wchar_t wchar[2] = {0}; + wchar[0] = (wchar_t) ' '; + setcchar (&cchar, wchar, A_NORMAL, 0, NULL); add_wch (&cchar); + if (mode == 2) { + move (y, x * mode + 1); + add_wch (&cchar); + } } } + attron (COLOR_PAIR(0)); + redrawwin (stdscr); + change = 0; } - attron (COLOR_PAIR(0)); - redrawwin (stdscr); switch (getch ()) { case KEY_UP: case 'i': if (ycursor > 0) { ycursor--; + change = 1; } break; case KEY_LEFT: case 'j': if (xcursor > 0) { xcursor--; + change = 1; } break; case KEY_DOWN: case 'k': - if (images[scale]->height - ycursor >= LINES) { + if (images[scale]->height - ycursor > LINES) { ycursor++; + change = 1; } break; case KEY_RIGHT: case 'l': - if (images[scale]->width - xcursor >= COLS / mode) { + if (images[scale]->width - xcursor > COLS / mode) { xcursor++; + change = 1; } break; case KEY_END: @@ -247,6 +264,7 @@ int main (int argc, char *argv[]) xcursor /= 2; ycursor /= 2; } + change = 1; } break; case KEY_ESC: @@ -264,6 +282,7 @@ int main (int argc, char *argv[]) xcursor *= 2; ycursor *= 2; } + change = 1; } break; } -- 2.30.2