summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 61b1bbf)
raw | patch | inline | side by side (parent: 61b1bbf)
author | Max Kellermann <max@duempel.org> | |
Fri, 9 Oct 2009 20:28:45 +0000 (22:28 +0200) | ||
committer | Max Kellermann <max@duempel.org> | |
Fri, 9 Oct 2009 20:28:45 +0000 (22:28 +0200) |
Merged code from screen_play.c and list_window_scroll_up(),
list_window_scroll_down().
list_window_scroll_down().
src/list_window.c | patch | blob | history | |
src/list_window.h | patch | blob | history | |
src/screen_play.c | patch | blob | history |
diff --git a/src/list_window.c b/src/list_window.c
index e11e75acf986c6d339c349e4d537ebd3dd0a1589..15ca07aa08a08a056562d835bd16c0f9130ade9f 100644 (file)
--- a/src/list_window.c
+++ b/src/list_window.c
}
}
+void
+list_window_fetch_cursor(struct list_window *lw, unsigned length)
+{
+ if (lw->selected < lw->start + options.scroll_offset) {
+ if (lw->start > 0)
+ lw->selected = lw->start + options.scroll_offset;
+ if (lw->range_selection) {
+ if (lw->selected > lw->range_base) {
+ lw->selected_end = lw->selected;
+ lw->selected_start = lw->range_base;
+ } else {
+ lw->selected_start = lw->selected;
+ }
+ } else {
+ lw->selected_start = lw->selected;
+ lw->selected_end = lw->selected;
+ }
+ } else if (lw->selected > lw->start + lw->rows - 1 - options.scroll_offset) {
+ if (lw->start + lw->rows < length)
+ lw->selected = lw->start + lw->rows - 1 - options.scroll_offset;
+ if (lw->range_selection) {
+ if (lw->selected < lw->range_base) {
+ lw->selected_start = lw->selected;
+ lw->selected_end = lw->range_base;
+ } else {
+ lw->selected_end = lw->selected;
+ }
+ } else {
+ lw->selected_start = lw->selected;
+ lw->selected_end = lw->selected;
+ }
+ }
+}
+
static void
list_window_next(struct list_window *lw, unsigned length)
{
}
static void
-list_window_scroll_up(struct list_window *lw, unsigned n)
+list_window_scroll_up(struct list_window *lw, unsigned length, unsigned n)
{
if (lw->start > 0) {
if (n > lw->start)
lw->start = 0;
else
lw->start -= n;
- if (lw->selected > lw->start + lw->rows - 1 - options.scroll_offset) {
- lw->selected = lw->start + lw->rows - 1 - options.scroll_offset;
- if (lw->range_selection) {
- if (lw->selected < lw->range_base) {
- lw->selected_start = lw->selected;
- lw->selected_end = lw->range_base;
- } else {
- lw->selected_end = lw->selected;
- }
- } else {
- lw->selected_start = lw->selected;
- lw->selected_end = lw->selected;
- }
- }
+
+ list_window_fetch_cursor(lw, length);
}
}
lw->start = length - lw->rows;
else
lw->start += n;
- if (lw->selected < lw->start + options.scroll_offset) {
- lw->selected = lw->start + options.scroll_offset;
- if (lw->range_selection) {
- if (lw->selected > lw->range_base) {
- lw->selected_end = lw->selected;
- lw->selected_start = lw->range_base;
- } else {
- lw->selected_start = lw->selected;
- }
- } else {
- lw->selected_start = lw->selected;
- lw->selected_end = lw->selected;
- }
- }
+
+ list_window_fetch_cursor(lw, length);
}
}
}
break;
case CMD_LIST_SCROLL_UP_LINE:
- list_window_scroll_up(lw, 1);
+ list_window_scroll_up(lw, rows, 1);
break;
case CMD_LIST_SCROLL_DOWN_LINE:
list_window_scroll_down(lw, rows, 1);
break;
case CMD_LIST_SCROLL_UP_HALF:
- list_window_scroll_up(lw, (lw->rows - 1) / 2);
+ list_window_scroll_up(lw, rows, (lw->rows - 1) / 2);
break;
case CMD_LIST_SCROLL_DOWN_HALF:
list_window_scroll_down(lw, rows, (lw->rows - 1) / 2);
diff --git a/src/list_window.h b/src/list_window.h
index 7c6a2a71868dc2cfb0a31f651cc14d34301069b3..d0ba6c14a671b9760ed18740aada5eee98b6b1b4 100644 (file)
--- a/src/list_window.h
+++ b/src/list_window.h
void
list_window_move_cursor(struct list_window *lw, unsigned n);
+/**
+ * Ensures that the cursor is visible on the screen, i.e. it is not
+ * outside the current scrolling range.
+ */
+void
+list_window_fetch_cursor(struct list_window *lw, unsigned length);
+
/* find a string in a list window */
bool
list_window_find(struct list_window *lw,
diff --git a/src/screen_play.c b/src/screen_play.c
index dd3fccdc2492039864a2e392b8464af53cf3a81c..7d079bdc5615a6cd4724169adf93a8b45fb82909 100644 (file)
--- a/src/screen_play.c
+++ b/src/screen_play.c
}
/* make sure the cursor is in the window */
- if (lw->selected < lw->start + options.scroll_offset) {
- if (lw->start > 0)
- lw->selected = lw->start + options.scroll_offset;
- if (lw->range_selection) {
- lw->selected_start = lw->range_base;
- lw->selected_end = lw->selected;
- } else {
- lw->selected_start = lw->selected;
- lw->selected_end = lw->selected;
- }
- } else if (lw->selected > lw->start + lw->rows - 1 - options.scroll_offset) {
- if (lw->start + lw->rows < length)
- lw->selected = lw->start + lw->rows - 1 - options.scroll_offset;
- if (lw->range_selection) {
- lw->selected_start = lw->selected;
- lw->selected_end = lw->range_base;
- } else {
- lw->selected_start = lw->selected;
- lw->selected_end = lw->selected;
- }
- }
+ list_window_fetch_cursor(lw, length);
}
#ifndef NCMPC_MINI