1 /* ncmpc (Ncurses MPD Client)
2 * (c) 2004-2018 The Music Player Daemon Project
3 * Project homepage: http://musicpd.org
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.
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.
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.
25 #include "TitleBar.hxx"
26 #include "ProgressBar.hxx"
27 #include "StatusBar.hxx"
28 #include "History.hxx"
30 #include "ncmpc_curses.h"
31 #include "util/Compiler.h"
33 #include <mpd/client.h>
39 enum class Command : unsigned;
48 static constexpr int title_y = 0, title_x = 0;
49 static constexpr int main_y = TitleBar::GetHeight(), main_x = 0;
50 static constexpr int progress_x = 0;
51 static constexpr int status_x = 0;
53 constexpr explicit Layout(Size _size)
56 constexpr unsigned GetMainRows() const {
57 return GetProgressY() - main_y;
60 constexpr Size GetMainSize() const {
61 return {size.width, GetMainRows()};
64 constexpr int GetProgressY() const {
65 return GetStatusY() - 1;
68 constexpr int GetStatusY() const {
69 return size.height - 1;
80 ProgressBar progress_bar;
86 using PageMap = std::map<const PageMeta *,
87 std::unique_ptr<Page>>;
89 PageMap::iterator current_page = pages.begin();
91 const PageMeta *mode_fn_prev;
103 void Init(struct mpdclient *c);
106 Point GetMainPosition() const {
107 return {0, (int)title_bar.GetHeight()};
110 const PageMeta &GetCurrentPageMeta() const {
111 return *current_page->first;
114 PageMap::iterator MakePage(const PageMeta &sf);
119 bool IsVisible(const Page &page) const {
120 return &page == current_page->second.get();
123 void Switch(const PageMeta &sf, struct mpdclient &c);
124 void Swap(struct mpdclient &c, const struct mpd_song *song);
127 void PaintTopWindow();
128 void Paint(bool main_dirty);
130 void Update(struct mpdclient &c);
131 void OnCommand(struct mpdclient &c, Command cmd);
134 bool OnMouse(struct mpdclient &c, Point p, mmask_t bstate);
138 void NextMode(struct mpdclient &c, int offset);