ncmpc  0.31
screen.hxx
Go to the documentation of this file.
1 /* ncmpc (Ncurses MPD Client)
2  * (c) 2004-2018 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  */
19 
20 #ifndef SCREEN_H
21 #define SCREEN_H
22 
23 #include "config.h"
24 #include "Window.hxx"
25 #include "TitleBar.hxx"
26 #include "ProgressBar.hxx"
27 #include "StatusBar.hxx"
28 #include "History.hxx"
29 #include "Point.hxx"
30 #include "ncmpc_curses.h"
31 #include "util/Compiler.h"
32 
33 #include <mpd/client.h>
34 
35 #include <memory>
36 #include <string>
37 #include <map>
38 
39 enum class Command : unsigned;
40 struct mpdclient;
41 struct PageMeta;
42 class Page;
43 
45  struct Layout {
46  Size size;
47 
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;
52 
53  constexpr explicit Layout(Size _size)
54  :size(_size) {}
55 
56  constexpr unsigned GetMainRows() const {
57  return GetProgressY() - main_y;
58  }
59 
60  constexpr Size GetMainSize() const {
61  return {size.width, GetMainRows()};
62  }
63 
64  constexpr int GetProgressY() const {
65  return GetStatusY() - 1;
66  }
67 
68  constexpr int GetStatusY() const {
69  return size.height - 1;
70  }
71  };
72 
73  Layout layout;
74 
75  TitleBar title_bar;
76 public:
78 
79 private:
80  ProgressBar progress_bar;
81 
82 public:
84 
85 private:
86  using PageMap = std::map<const PageMeta *,
87  std::unique_ptr<Page>>;
88  PageMap pages;
89  PageMap::iterator current_page = pages.begin();
90 
91  const PageMeta *mode_fn_prev;
92 
93  char *buf;
94  size_t buf_size;
95 
96 public:
97  std::string findbuf;
99 
100  ScreenManager();
101  ~ScreenManager();
102 
103  void Init(struct mpdclient *c);
104  void Exit();
105 
107  return {0, (int)title_bar.GetHeight()};
108  }
109 
110  const PageMeta &GetCurrentPageMeta() const {
111  return *current_page->first;
112  }
113 
114  PageMap::iterator MakePage(const PageMeta &sf);
115 
116  void OnResize();
117 
118  gcc_pure
119  bool IsVisible(const Page &page) const {
120  return &page == current_page->second.get();
121  }
122 
123  void Switch(const PageMeta &sf, struct mpdclient &c);
124  void Swap(struct mpdclient &c, const struct mpd_song *song);
125 
126 
127  void PaintTopWindow();
128  void Paint(bool main_dirty);
129 
130  void Update(struct mpdclient &c);
131  void OnCommand(struct mpdclient &c, Command cmd);
132 
133 #ifdef HAVE_GETMOUSE
134  bool OnMouse(struct mpdclient &c, Point p, mmask_t bstate);
135 #endif
136 
137 private:
138  void NextMode(struct mpdclient &c, int offset);
139 };
140 
141 #endif
Command
Definition: Command.hxx:29
virtual bool OnCommand(struct mpdclient &c, Command cmd)=0
gcc_pure bool IsVisible(const Page &page) const
Definition: screen.hxx:119
const PageMeta & GetCurrentPageMeta() const
Definition: screen.hxx:110
Definition: screen.hxx:44
std::list< std::string > History
Definition: History.hxx:26
void PaintTopWindow()
StatusBar status_bar
Definition: screen.hxx:83
PageMap::iterator MakePage(const PageMeta &sf)
Definition: Window.hxx:28
void Update(struct mpdclient &c)
Definition: Page.hxx:73
std::string findbuf
Definition: screen.hxx:97
Point GetMainPosition() const
Definition: screen.hxx:106
Definition: PageMeta.hxx:32
Definition: mpdclient.hxx:17
Window main_window
Definition: screen.hxx:77
Definition: StatusBar.hxx:36
virtual void OnResize(Size size)=0
Definition: Size.hxx:26
static constexpr unsigned GetHeight()
Definition: TitleBar.hxx:37
Definition: TitleBar.hxx:28
void Swap(struct mpdclient &c, const struct mpd_song *song)
unsigned width
Definition: Size.hxx:27
unsigned height
Definition: Size.hxx:27
Definition: Point.hxx:28
virtual void Paint() const =0
History find_history
Definition: screen.hxx:98
void Init(struct mpdclient *c)
Definition: ProgressBar.hxx:25
Definition: Page.hxx:36
void Switch(const PageMeta &sf, struct mpdclient &c)