configure.ac: require GLib 2.14
[ncmpc.git] / src / hscroll.h
blobabbaded31ae2a6f7797e29f26d2c581c4d6c1f07
1 /* ncmpc (Ncurses MPD Client)
2 * (c) 2004-2010 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.
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.
34 struct hscroll {
35 WINDOW *w;
36 const char *separator;
38 /**
39 * The bounding coordinates on the screen.
41 unsigned x, y, width;
43 /**
44 * ncurses attributes for drawing the text.
46 attr_t attrs;
48 /**
49 * ncurses colors for drawing the text.
51 short pair;
53 /**
54 * The scrolled text, in the current locale.
56 char *text;
58 /**
59 * The current scrolling offset. This is a character
60 * position, not a screen column.
62 gsize offset;
64 /**
65 * The id of the timer which updates the scrolled area every
66 * second.
68 guint source_id;
71 static inline void
72 hscroll_reset(struct hscroll *hscroll)
74 hscroll->offset = 0;
77 static inline void
78 hscroll_step(struct hscroll *hscroll)
80 ++hscroll->offset;
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.
90 static inline void
91 hscroll_init(struct hscroll *hscroll, WINDOW *w, const char *separator)
93 hscroll->w = w;
94 hscroll->separator = separator;
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.
102 void
103 hscroll_set(struct hscroll *hscroll, unsigned x, unsigned y, unsigned width,
104 const char *text);
107 * Removes the text and the timer. It may be reused with
108 * hscroll_set().
110 void
111 hscroll_clear(struct hscroll *hscroll);
114 * Explicitly draws the scrolled text. Calling this function is only
115 * allowed if there is a text currently.
117 void
118 hscroll_draw(struct hscroll *hscroll);
120 #endif