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