From a60c40e042cd1c2cc73dfa60b74a54e67a017d6a Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 20 Mar 2017 20:37:33 +0100 Subject: [PATCH] screen: move screen_paint() to screen_paint.c --- Makefile.am | 1 + src/screen.c | 65 -------------------------------- src/screen.h | 3 ++ src/screen_paint.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 98 insertions(+), 65 deletions(-) create mode 100644 src/screen_paint.c diff --git a/Makefile.am b/Makefile.am index 5329315..2981785 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 \ diff --git a/src/screen.c b/src/screen.c index a08cf59..299d27e 100644 --- a/src/screen.c +++ b/src/screen.c @@ -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) { diff --git a/src/screen.h b/src/screen.h index 7c2d214..8a91d46 100644 --- a/src/screen.h +++ b/src/screen.h @@ -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 index 0000000..39daa18 --- /dev/null +++ b/src/screen_paint.c @@ -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 + +#include + +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(); +} -- 2.30.2