limit refresh
authorLaurent MAZET <laurent.mazet@thalesgroup.com>
Tue, 8 Oct 2024 10:43:36 +0000 (12:43 +0200)
committerLaurent MAZET <laurent.mazet@thalesgroup.com>
Tue, 8 Oct 2024 10:43:36 +0000 (12:43 +0200)
ndisplay.c

index 572e9cbe0130f66e44476d93377a54e15158e5ab..ac41fd2ffe7d63ceab90de41f47268a84ee113fe 100644 (file)
@@ -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;
         }