Code

release v0.29
[ncmpc.git] / src / hscroll.h
1 /* ncmpc (Ncurses MPD Client)
2  * (c) 2004-2017 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  */
20 #ifndef HSCROLL_H
21 #define HSCROLL_H
23 #include "config.h"
24 #include "ncmpc_curses.h"
26 #include <glib.h>
28 /**
29  * This class is used to auto-scroll text which does not fit on the
30  * screen.  Call hscroll_init() to initialize the object,
31  * hscroll_clear() to free resources, and hscroll_set() to begin
32  * scrolling.
33  */
34 struct hscroll {
35         WINDOW *w;
36         const char *separator;
38         /**
39          * The bounding coordinates on the screen.
40          */
41         unsigned x, y, width;
43         /**
44          * ncurses attributes for drawing the text.
45          */
46         attr_t attrs;
48         /**
49          * ncurses colors for drawing the text.
50          */
51         short pair;
53         /**
54          * The scrolled text, in the current locale.
55          */
56         char *text;
58         /**
59          * The current scrolling offset.  This is a character
60          * position, not a screen column.
61          */
62         gsize offset;
64         /**
65          * The id of the timer which updates the scrolled area every
66          * second.
67          */
68         guint source_id;
69 };
71 static inline void
72 hscroll_reset(struct hscroll *hscroll)
73 {
74         hscroll->offset = 0;
75 }
77 static inline void
78 hscroll_step(struct hscroll *hscroll)
79 {
80         ++hscroll->offset;
81 }
83 char *
84 strscroll(struct hscroll *hscroll, const char *str, const char *separator,
85           unsigned width);
87 /**
88  * Initializes a #hscroll object allocated by the caller.
89  */
90 static inline void
91 hscroll_init(struct hscroll *hscroll, WINDOW *w, const char *separator)
92 {
93         hscroll->w = w;
94         hscroll->separator = separator;
95 }
97 /**
98  * Sets a text to scroll.  This installs a timer which redraws every
99  * second with the current window attributes.  Call hscroll_clear() to
100  * disable it.  This function automatically removes the old text.
101  */
102 void
103 hscroll_set(struct hscroll *hscroll, unsigned x, unsigned y, unsigned width,
104             const char *text);
106 /**
107  * Removes the text and the timer.  It may be reused with
108  * hscroll_set().
109  */
110 void
111 hscroll_clear(struct hscroll *hscroll);
113 /**
114  * Explicitly draws the scrolled text.  Calling this function is only
115  * allowed if there is a text currently.
116  */
117 void
118 hscroll_draw(struct hscroll *hscroll);
120 #endif