Code

screen: move screen_paint() to screen_paint.c
[ncmpc.git] / src / screen_paint.c
1 /* ncmpc (Ncurses MPD Client)
2  * (c) 2004-2017 The Music Player Daemon Project
3  * Project homepage: http://musicpd.org
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
20 #include "screen.h"
21 #include "screen_interface.h"
22 #include "config.h"
23 #include "mpdclient.h"
24 #include "options.h"
25 #include "player_command.h"
27 #include <mpd/client.h>
29 #include <assert.h>
31 void
32 paint_top_window(const struct mpdclient *c)
33 {
34         const char *title =
35 #ifndef NCMPC_MINI
36                 screen.welcome_source_id == 0 &&
37 #endif
38                 screen.current_page->get_title != NULL
39                 ? screen.current_page->get_title(screen.buf, screen.buf_size)
40                 : "";
41         assert(title != NULL);
43         title_bar_paint(&screen.title_bar, title, c->status);
44 }
46 static void
47 update_progress_window(struct mpdclient *c, bool repaint)
48 {
49         unsigned elapsed;
50         if (c->status == NULL)
51                 elapsed = 0;
52         else if (seek_id >= 0 && seek_id == mpd_status_get_song_id(c->status))
53                 elapsed = seek_target_time;
54         else
55                 elapsed = mpd_status_get_elapsed_time(c->status);
57         unsigned duration = mpdclient_is_playing(c)
58                 ? mpd_status_get_total_time(c->status)
59                 : 0;
61         if (progress_bar_set(&screen.progress_bar, elapsed, duration) ||
62             repaint)
63                 progress_bar_paint(&screen.progress_bar);
64 }
66 void
67 screen_paint(struct mpdclient *c, bool main_dirty)
68 {
69         /* update title/header window */
70         paint_top_window(c);
72         /* paint the bottom window */
74         update_progress_window(c, true);
75         status_bar_paint(&screen.status_bar, c->status, c->song);
77         /* paint the main window */
79         if (main_dirty) {
80                 wclear(screen.main_window.w);
81                 if (screen.current_page->paint != NULL)
82                         screen.current_page->paint();
83         }
85         /* move the cursor to the origin */
87         if (!options.hardware_cursor)
88                 wmove(screen.main_window.w, 0, 0);
90         wnoutrefresh(screen.main_window.w);
92         /* tell curses to update */
93         doupdate();
94 }