Code

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