diff options
author | Max Kellermann <max@duempel.org> | 2008-09-17 12:18:00 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-09-17 12:18:00 +0200 |
commit | ca2b9d1390a56b89336b963113b5763edd70238e (patch) | |
tree | fb21cce04bc44a9bcb4a8e06fadd1b02776defc9 | |
parent | 104b126c69b89cc4b7caf301fbdbd0b1c9a21bda (diff) | |
download | mpd-ca2b9d1390a56b89336b963113b5763edd70238e.tar.gz mpd-ca2b9d1390a56b89336b963113b5763edd70238e.tar.xz mpd-ca2b9d1390a56b89336b963113b5763edd70238e.zip |
list_window: added list_window_scroll_cmd()
It is similar to list_window_cmd(), but it scrolls the window instead
of moving the selection. It is used by the "lyrics" and the "help"
screen.
-rw-r--r-- | src/list_window.c | 50 | ||||
-rw-r--r-- | src/list_window.h | 7 | ||||
-rw-r--r-- | src/screen_help.c | 38 | ||||
-rw-r--r-- | src/screen_lyrics.c | 36 |
4 files changed, 62 insertions, 69 deletions
diff --git a/src/list_window.c b/src/list_window.c index 88f0a690c..f26088da4 100644 --- a/src/list_window.c +++ b/src/list_window.c @@ -296,6 +296,56 @@ list_window_cmd(struct list_window *lw, unsigned rows, command_t cmd) return 1; } +int +list_window_scroll_cmd(struct list_window *lw, unsigned rows, command_t cmd) +{ + switch (cmd) { + case CMD_LIST_PREVIOUS: + if (lw->start > 0) + lw->start--; + break; + + case CMD_LIST_NEXT: + if (lw->start + lw->rows < rows) + lw->start++; + break; + + case CMD_LIST_FIRST: + lw->start = 0; + break; + + case CMD_LIST_LAST: + if (rows > lw->rows) + lw->start = rows - lw->rows; + else + lw->start = 0; + break; + + case CMD_LIST_NEXT_PAGE: + lw->start += lw->rows - 1; + if (lw->start + lw->rows > rows) { + if (rows > lw->rows) + lw->start = rows - lw->rows; + else + lw->start = 0; + } + break; + + case CMD_LIST_PREVIOUS_PAGE: + if (lw->start > lw->rows) + lw->start -= lw->rows; + else + lw->start = 0; + break; + + default: + return 0; + } + + lw->repaint = lw->clear = 1; + return 1; +} + list_window_state_t * list_window_init_state(void) { diff --git a/src/list_window.h b/src/list_window.h index 2efff8a5c..ab02f4bdd 100644 --- a/src/list_window.h +++ b/src/list_window.h @@ -49,6 +49,13 @@ void list_window_paint(struct list_window *lw, /* perform basic list window commands (movement) */ int list_window_cmd(struct list_window *lw, unsigned rows, command_t cmd); +/** + * Scroll the window. Returns non-zero if the command has been + * consumed. + */ +int +list_window_scroll_cmd(struct list_window *lw, unsigned rows, command_t cmd); + /* select functions */ void list_window_set_selected(struct list_window *lw, unsigned n); diff --git a/src/screen_help.c b/src/screen_help.c index 7c5134fc6..850608181 100644 --- a/src/screen_help.c +++ b/src/screen_help.c @@ -240,44 +240,8 @@ help_update(mpd_unused screen_t *screen, mpd_unused mpdclient_t *c) static int help_cmd(screen_t *screen, mpd_unused mpdclient_t *c, command_t cmd) { - lw->repaint=1; - lw->clear=1; - switch(cmd) { - case CMD_LIST_NEXT: - if (lw->start + lw->rows < (unsigned)help_text_rows) - lw->start++; + if (list_window_scroll_cmd(lw, help_text_rows, cmd)) return 1; - case CMD_LIST_PREVIOUS: - if (lw->start > 0) - lw->start--; - return 1; - case CMD_LIST_FIRST: - lw->start = 0; - return 1; - case CMD_LIST_LAST: - if ((unsigned)help_text_rows > lw->rows) - lw->start = help_text_rows - lw->rows; - else - lw->start = 0; - return 1; - case CMD_LIST_NEXT_PAGE: - lw->start = lw->start + lw->rows; - if (lw->start + lw->rows >= (unsigned)help_text_rows) { - if ((unsigned)help_text_rows > lw->rows) - lw->start = help_text_rows - lw->rows; - else - lw->start = 0; - } - return 1; - case CMD_LIST_PREVIOUS_PAGE: - if (lw->start > lw->rows) - lw->start -= lw->rows; - else - lw->start = 0; - return 1; - default: - break; - } lw->selected = lw->start+lw->rows; if (screen_find(screen, diff --git a/src/screen_lyrics.c b/src/screen_lyrics.c index e6e2cf0df..5356548c9 100644 --- a/src/screen_lyrics.c +++ b/src/screen_lyrics.c @@ -289,40 +289,12 @@ lyrics_update(mpd_unused screen_t *screen, mpd_unused mpdclient_t *c) static int lyrics_cmd(screen_t *screen, mpdclient_t *c, command_t cmd) { + if (list_window_scroll_cmd(lw, current.lines->len, cmd)) + return 1; + lw->repaint=1; + switch(cmd) { - case CMD_LIST_NEXT: - if (current.lines != NULL && lw->start+lw->rows < current.lines->len+1) - lw->start++; - return 1; - case CMD_LIST_PREVIOUS: - if( lw->start >0 ) - lw->start--; - return 1; - case CMD_LIST_FIRST: - lw->start = 0; - return 1; - case CMD_LIST_LAST: - if ((unsigned)lyrics_text_rows > lw->rows) - lw->start = lyrics_text_rows - lw->rows; - else - lw->start = 0; - return 1; - case CMD_LIST_NEXT_PAGE: - lw->start = lw->start + lw->rows - 1; - if (lw->start + lw->rows >= (unsigned)lyrics_text_rows + 1) { - if ((unsigned)lyrics_text_rows + 1 > lw->rows) - lw->start = lyrics_text_rows + 1 - lw->rows; - else - lw->start = 0; - } - return 1; - case CMD_LIST_PREVIOUS_PAGE: - if (lw->start > lw->rows) - lw->start -= lw->rows; - else - lw->start = 0; - return 1; case CMD_SELECT: /* XXX */ if (current.loader != NULL) { |