summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ca2b9d1)
raw | patch | inline | side by side (parent: ca2b9d1)
author | Max Kellermann <max@duempel.org> | |
Wed, 17 Sep 2008 10:20:42 +0000 (12:20 +0200) | ||
committer | Max Kellermann <max@duempel.org> | |
Wed, 17 Sep 2008 10:20:42 +0000 (12:20 +0200) |
Merge code which used to be duplicated in the screens "play", "help",
"lyrics".
"lyrics".
diff --git a/src/list_window.c b/src/list_window.c
index f26088da482d1cda8a48475bc3a90abe155e9f58..ad671f0cf51ad1a36715e6e1623731d36cb1acc5 100644 (file)
--- a/src/list_window.c
+++ b/src/list_window.c
lw->selected = length - 1;
}
+void
+list_window_center(struct list_window *lw, unsigned rows, unsigned n)
+{
+ if (n > lw->rows / 2)
+ lw->start = n - lw->rows / 2;
+ else
+ lw->start = 0;
+
+ if (lw->start + lw->rows > rows) {
+ if (lw->rows < rows)
+ lw->start = rows - lw->rows;
+ else
+ lw->start = 0;
+ }
+
+ lw->repaint = lw->clear = 1;
+}
+
void
list_window_set_selected(struct list_window *lw, unsigned n)
{
diff --git a/src/list_window.h b/src/list_window.h
index ab02f4bdd759a29c0e7300b861e16530f9597316..3a9fba4c313cb5bda9d3ea3d0e592f42c6eb952e 100644 (file)
--- a/src/list_window.h
+++ b/src/list_window.h
int
list_window_scroll_cmd(struct list_window *lw, unsigned rows, command_t cmd);
+void
+list_window_center(struct list_window *lw, unsigned rows, unsigned n);
/* 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 850608181cb123a6598a34310dc92b4d3f9f7f64..363b440cf8f804bb05b7a3eb94331f747b3b0698 100644 (file)
--- a/src/screen_help.c
+++ b/src/screen_help.c
lw, help_text_rows,
cmd, list_callback, NULL)) {
/* center the row */
- if (lw->selected > lw->rows / 2)
- lw->start = lw->selected - lw->rows / 2;
- else
- lw->start = 0;
- if (lw->start + lw->rows > (unsigned)help_text_rows) {
- if (lw->rows < (unsigned)help_text_rows)
- lw->start = help_text_rows - lw->rows;
- else
- lw->start = 0;
- }
+ list_window_center(lw, help_text_rows, lw->selected);
return 1;
}
diff --git a/src/screen_lyrics.c b/src/screen_lyrics.c
index 5356548c90b5ef691f09196696ceaf28672a9350..6853fecd72bb2a9dc494d2ca3fb435d1d51910e1 100644 (file)
--- a/src/screen_lyrics.c
+++ b/src/screen_lyrics.c
if (list_window_scroll_cmd(lw, current.lines->len, cmd))
return 1;
- lw->repaint=1;
-
switch(cmd) {
case CMD_SELECT:
/* XXX */
lw, lyrics_text_rows,
cmd, list_callback, NULL)) {
/* center the row */
- lw->start = lw->selected - (lw->rows / 2);
- if (lw->start + lw->rows > (unsigned)lyrics_text_rows) {
- if (lw->rows < (unsigned)lyrics_text_rows)
- lw->start = lyrics_text_rows - lw->rows;
- else
- lw->start = 0;
- }
+ list_window_center(lw, current.lines->len, lw->selected);
return 1;
}
diff --git a/src/screen_play.c b/src/screen_play.c
index 6b4de78932a2990ef78ebfa5df1e1a7243453e76..0426176d602b52898540cc95384c607c723f97c8 100644 (file)
--- a/src/screen_play.c
+++ b/src/screen_play.c
/* try to center the song that are playing */
idx = playlist_get_index(c, c->song);
D("Autocenter song id:%d pos:%d index:%d\n", c->song->id,c->song->pos,idx);
- idx -= (lw->rows / 2);
- if (idx + (int)lw->rows > (int)length)
- idx = length - lw->rows;
if (idx < 0)
- idx = 0;
- lw->start = idx;
+ return 0;
+
+ list_window_center(lw, length, idx);
/* make sure the cursor is in the window */
lw->selected = lw->start+offset;
list_window_check_selected(lw, length);
- lw->clear = 1;
- lw->repaint = 1;
-
return 0;
}