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