/* 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:
xcursor /= 2;
ycursor /= 2;
}
+ change = 1;
}
break;
case KEY_ESC:
xcursor *= 2;
ycursor *= 2;
}
+ change = 1;
}
break;
}