1 /* ncmpc (Ncurses MPD Client)
2 * (c) 2004-2020 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.
23 #include "BasicMarquee.hxx"
24 #include "event/TimerEvent.hxx"
28 enum class Style : unsigned;
31 * This class is used to auto-scroll text which does not fit on the
32 * screen. Call hscroll_init() to initialize the object,
33 * hscroll_clear() to free resources, and hscroll_set() to begin
42 * The postion on the screen.
47 * Style for drawing the text.
54 * A timer which updates the scrolled area every second.
59 hscroll(EventLoop &event_loop,
60 WINDOW *_w, const char *_separator) noexcept
61 :w(_w), basic(_separator),
62 timer(event_loop, BIND_THIS_METHOD(OnTimer))
66 bool IsDefined() const noexcept {
67 return basic.IsDefined();
71 * Sets a text to scroll. This installs a timer which redraws
72 * every second with the current window attributes. Call
73 * hscroll_clear() to disable it.
75 void Set(unsigned x, unsigned y, unsigned width, const char *text,
76 Style style, attr_t attr=0) noexcept;
79 * Removes the text and the timer. It may be reused with
82 void Clear() noexcept;
84 void Rewind() noexcept {
88 void Step() noexcept {
93 * Explicitly draws the scrolled text. Calling this function
94 * is only allowed if there is a text currently.
96 void Paint() const noexcept;
99 void OnTimer() noexcept;
101 void ScheduleTimer() noexcept {
102 timer.Schedule(std::chrono::seconds(1));