Code

screen: move screen_paint() to screen_paint.c
authorMax Kellermann <max.kellermann@gmail.com>
Mon, 20 Mar 2017 19:37:33 +0000 (20:37 +0100)
committerMax Kellermann <max.kellermann@gmail.com>
Mon, 20 Mar 2017 19:46:51 +0000 (20:46 +0100)
Makefile.am
src/screen.c
src/screen.h
src/screen_paint.c [new file with mode: 0644]

index 53293154c48225ce9e401a2bdbe9c64c7d7d8249..29817854ad68393bb878538f02bfcf49baa3bf88 100644 (file)
@@ -43,6 +43,7 @@ src_ncmpc_SOURCES = \
        src/status_bar.c src/status_bar.h \
        src/screen.c src/screen.h \
        src/screen_interface.h \
+       src/screen_paint.c \
        src/screen_utils.c src/screen_utils.h \
        src/screen_status.c src/screen_status.h \
        src/screen_list.c src/screen_list.h \
index a08cf595dab01ad5c1616aeff53b2ffa8b362f52..299d27eb4fe03a896478f93a5cea26cbceac4850 100644 (file)
@@ -143,41 +143,6 @@ screen_next_mode(struct mpdclient *c, int offset)
                screen_switch(sf, c);
 }
 
-static void
-paint_top_window(const struct mpdclient *c)
-{
-       const char *title =
-#ifndef NCMPC_MINI
-               screen.welcome_source_id == 0 &&
-#endif
-               screen.current_page->get_title != NULL
-               ? screen.current_page->get_title(screen.buf, screen.buf_size)
-               : "";
-       assert(title != NULL);
-
-       title_bar_paint(&screen.title_bar, title, c->status);
-}
-
-static void
-update_progress_window(struct mpdclient *c, bool repaint)
-{
-       unsigned elapsed;
-       if (c->status == NULL)
-               elapsed = 0;
-       else if (seek_id >= 0 && seek_id == mpd_status_get_song_id(c->status))
-               elapsed = seek_target_time;
-       else
-               elapsed = mpd_status_get_elapsed_time(c->status);
-
-       unsigned duration = mpdclient_is_playing(c)
-               ? mpd_status_get_total_time(c->status)
-               : 0;
-
-       if (progress_bar_set(&screen.progress_bar, elapsed, duration) ||
-           repaint)
-               progress_bar_paint(&screen.progress_bar);
-}
-
 void
 screen_exit(void)
 {
@@ -317,36 +282,6 @@ screen_init(struct mpdclient *c)
                screen.current_page->open(c);
 }
 
-void
-screen_paint(struct mpdclient *c, bool main_dirty)
-{
-       /* update title/header window */
-       paint_top_window(c);
-
-       /* paint the bottom window */
-
-       update_progress_window(c, true);
-       status_bar_paint(&screen.status_bar, c->status, c->song);
-
-       /* paint the main window */
-
-       if (main_dirty) {
-               wclear(screen.main_window.w);
-               if (screen.current_page->paint != NULL)
-                       screen.current_page->paint();
-       }
-
-       /* move the cursor to the origin */
-
-       if (!options.hardware_cursor)
-               wmove(screen.main_window.w, 0, 0);
-
-       wnoutrefresh(screen.main_window.w);
-
-       /* tell curses to update */
-       doupdate();
-}
-
 void
 screen_update(struct mpdclient *c)
 {
index 7c2d2140da2c26c1e58953f57fdfb7426680b7a5..8a91d46279254a7205a16af18d899196de787d2e 100644 (file)
@@ -66,6 +66,9 @@ void screen_init(struct mpdclient *c);
 void screen_exit(void);
 void screen_resize(struct mpdclient *c);
 
+void
+paint_top_window(const struct mpdclient *c);
+
 void
 screen_paint(struct mpdclient *c, bool main_dirty);
 
diff --git a/src/screen_paint.c b/src/screen_paint.c
new file mode 100644 (file)
index 0000000..39daa18
--- /dev/null
@@ -0,0 +1,94 @@
+/* ncmpc (Ncurses MPD Client)
+ * (c) 2004-2017 The Music Player Daemon Project
+ * Project homepage: http://musicpd.org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "screen.h"
+#include "screen_interface.h"
+#include "config.h"
+#include "mpdclient.h"
+#include "options.h"
+#include "player_command.h"
+
+#include <mpd/client.h>
+
+#include <assert.h>
+
+void
+paint_top_window(const struct mpdclient *c)
+{
+       const char *title =
+#ifndef NCMPC_MINI
+               screen.welcome_source_id == 0 &&
+#endif
+               screen.current_page->get_title != NULL
+               ? screen.current_page->get_title(screen.buf, screen.buf_size)
+               : "";
+       assert(title != NULL);
+
+       title_bar_paint(&screen.title_bar, title, c->status);
+}
+
+static void
+update_progress_window(struct mpdclient *c, bool repaint)
+{
+       unsigned elapsed;
+       if (c->status == NULL)
+               elapsed = 0;
+       else if (seek_id >= 0 && seek_id == mpd_status_get_song_id(c->status))
+               elapsed = seek_target_time;
+       else
+               elapsed = mpd_status_get_elapsed_time(c->status);
+
+       unsigned duration = mpdclient_is_playing(c)
+               ? mpd_status_get_total_time(c->status)
+               : 0;
+
+       if (progress_bar_set(&screen.progress_bar, elapsed, duration) ||
+           repaint)
+               progress_bar_paint(&screen.progress_bar);
+}
+
+void
+screen_paint(struct mpdclient *c, bool main_dirty)
+{
+       /* update title/header window */
+       paint_top_window(c);
+
+       /* paint the bottom window */
+
+       update_progress_window(c, true);
+       status_bar_paint(&screen.status_bar, c->status, c->song);
+
+       /* paint the main window */
+
+       if (main_dirty) {
+               wclear(screen.main_window.w);
+               if (screen.current_page->paint != NULL)
+                       screen.current_page->paint();
+       }
+
+       /* move the cursor to the origin */
+
+       if (!options.hardware_cursor)
+               wmove(screen.main_window.w, 0, 0);
+
+       wnoutrefresh(screen.main_window.w);
+
+       /* tell curses to update */
+       doupdate();
+}