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 #include "progress_bar.h"
25 progress_bar_paint(const struct progress_bar
*p
)
29 mvwhline(p
->window
.w
, 0, 0, ACS_HLINE
, p
->window
.cols
);
32 assert(p
->width
< p
->window
.cols
);
35 whline(p
->window
.w
, '=', p
->width
);
37 mvwaddch(p
->window
.w
, 0, p
->width
, 'O');
40 wnoutrefresh(p
->window
.w
);
44 progress_bar_calc(struct progress_bar
*p
)
49 unsigned old_width
= p
->width
;
50 p
->width
= (p
->window
.cols
* p
->current
) / (p
->max
+ 1);
51 assert(p
->width
< p
->window
.cols
);
53 return p
->width
!= old_width
;
57 progress_bar_resize(struct progress_bar
*p
, unsigned width
, int y
, int x
)
61 p
->window
.cols
= width
;
62 wresize(p
->window
.w
, 1, width
);
63 mvwin(p
->window
.w
, y
, x
);
69 progress_bar_set(struct progress_bar
*p
, unsigned current
, unsigned max
)
76 bool modified
= (max
== 0) != (p
->max
== 0);
81 return progress_bar_calc(p
) || modified
;