ncmpc  0.31
BasicMarquee.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 BASIC_MARQUEE_HXX
21 #define BASIC_MARQUEE_HXX
22 
23 #include "util/Compiler.h"
24 
25 #include <string>
26 
33 class BasicMarquee {
34  const char *const separator;
35 
39  std::string text;
40 
44  std::string buffer;
45 
49  size_t max_offset;
50 
54  unsigned width = 0;
55 
60  unsigned offset;
61 
62 public:
63  BasicMarquee(const char *_separator)
64  :separator(_separator) {}
65 
66  bool IsDefined() const {
67  return width > 0;
68  }
69 
76  bool Set(unsigned width, const char *text);
77 
81  void Clear();
82 
83  void Rewind() {
84  offset = 0;
85  }
86 
87  void Step() {
88  ++offset;
89 
90  if (offset >= max_offset)
91  offset = 0;
92  }
93 
94  gcc_pure
95  std::pair<const char *, size_t> ScrollString() const;
96 };
97 
98 #endif
Definition: BasicMarquee.hxx:33
gcc_pure std::pair< const char *, size_t > ScrollString() const
BasicMarquee(const char *_separator)
Definition: BasicMarquee.hxx:63
void Rewind()
Definition: BasicMarquee.hxx:83
bool Set(unsigned width, const char *text)
bool IsDefined() const
Definition: BasicMarquee.hxx:66
void Step()
Definition: BasicMarquee.hxx:87