1*86d7f5d3SJohn Marino /*
2*86d7f5d3SJohn Marino * Copyright (c)2004 Cat's Eye Technologies. All rights reserved.
3*86d7f5d3SJohn Marino *
4*86d7f5d3SJohn Marino * Redistribution and use in source and binary forms, with or without
5*86d7f5d3SJohn Marino * modification, are permitted provided that the following conditions
6*86d7f5d3SJohn Marino * are met:
7*86d7f5d3SJohn Marino *
8*86d7f5d3SJohn Marino * Redistributions of source code must retain the above copyright
9*86d7f5d3SJohn Marino * notice, this list of conditions and the following disclaimer.
10*86d7f5d3SJohn Marino *
11*86d7f5d3SJohn Marino * Redistributions in binary form must reproduce the above copyright
12*86d7f5d3SJohn Marino * notice, this list of conditions and the following disclaimer in
13*86d7f5d3SJohn Marino * the documentation and/or other materials provided with the
14*86d7f5d3SJohn Marino * distribution.
15*86d7f5d3SJohn Marino *
16*86d7f5d3SJohn Marino * Neither the name of Cat's Eye Technologies nor the names of its
17*86d7f5d3SJohn Marino * contributors may be used to endorse or promote products derived
18*86d7f5d3SJohn Marino * from this software without specific prior written permission.
19*86d7f5d3SJohn Marino *
20*86d7f5d3SJohn Marino * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21*86d7f5d3SJohn Marino * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22*86d7f5d3SJohn Marino * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23*86d7f5d3SJohn Marino * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24*86d7f5d3SJohn Marino * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25*86d7f5d3SJohn Marino * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26*86d7f5d3SJohn Marino * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27*86d7f5d3SJohn Marino * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28*86d7f5d3SJohn Marino * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29*86d7f5d3SJohn Marino * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30*86d7f5d3SJohn Marino * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
31*86d7f5d3SJohn Marino * OF THE POSSIBILITY OF SUCH DAMAGE.
32*86d7f5d3SJohn Marino */
33*86d7f5d3SJohn Marino
34*86d7f5d3SJohn Marino /*
35*86d7f5d3SJohn Marino * curses_bar.c
36*86d7f5d3SJohn Marino * $Id: curses_bar.c,v 1.7 2005/02/08 06:03:21 cpressey Exp $
37*86d7f5d3SJohn Marino */
38*86d7f5d3SJohn Marino
39*86d7f5d3SJohn Marino #include <ncurses.h>
40*86d7f5d3SJohn Marino #include <panel.h>
41*86d7f5d3SJohn Marino #include <stdlib.h>
42*86d7f5d3SJohn Marino #include <string.h>
43*86d7f5d3SJohn Marino
44*86d7f5d3SJohn Marino #include "libaura/mem.h"
45*86d7f5d3SJohn Marino
46*86d7f5d3SJohn Marino #include "curses_util.h"
47*86d7f5d3SJohn Marino #include "curses_bar.h"
48*86d7f5d3SJohn Marino
49*86d7f5d3SJohn Marino struct curses_bar *
curses_bar_new(unsigned int x,unsigned int y,unsigned int width,unsigned int height,int colors,int flags)50*86d7f5d3SJohn Marino curses_bar_new(unsigned int x, unsigned int y,
51*86d7f5d3SJohn Marino unsigned int width, unsigned int height,
52*86d7f5d3SJohn Marino int colors, int flags)
53*86d7f5d3SJohn Marino {
54*86d7f5d3SJohn Marino struct curses_bar *b;
55*86d7f5d3SJohn Marino
56*86d7f5d3SJohn Marino AURA_MALLOC(b, curses_bar);
57*86d7f5d3SJohn Marino
58*86d7f5d3SJohn Marino if (flags & CURSES_BAR_WIDEN)
59*86d7f5d3SJohn Marino width = xmax;
60*86d7f5d3SJohn Marino if (flags & CURSES_BAR_BOTTOM)
61*86d7f5d3SJohn Marino y = ymax - 1;
62*86d7f5d3SJohn Marino
63*86d7f5d3SJohn Marino b->x = x;
64*86d7f5d3SJohn Marino b->y = y;
65*86d7f5d3SJohn Marino b->width = width;
66*86d7f5d3SJohn Marino b->height = height;
67*86d7f5d3SJohn Marino b->colors = colors;
68*86d7f5d3SJohn Marino
69*86d7f5d3SJohn Marino if ((b->win = newwin(height, width, y, x)) == NULL) {
70*86d7f5d3SJohn Marino AURA_FREE(b, curses_bar);
71*86d7f5d3SJohn Marino return(NULL);
72*86d7f5d3SJohn Marino }
73*86d7f5d3SJohn Marino
74*86d7f5d3SJohn Marino curses_colors_set(b->win, colors);
75*86d7f5d3SJohn Marino curses_window_blank(b->win);
76*86d7f5d3SJohn Marino
77*86d7f5d3SJohn Marino if ((b->pan = new_panel(b->win)) == NULL) {
78*86d7f5d3SJohn Marino delwin(b->win);
79*86d7f5d3SJohn Marino AURA_FREE(b, curses_bar);
80*86d7f5d3SJohn Marino return(NULL);
81*86d7f5d3SJohn Marino }
82*86d7f5d3SJohn Marino
83*86d7f5d3SJohn Marino return(b);
84*86d7f5d3SJohn Marino }
85*86d7f5d3SJohn Marino
86*86d7f5d3SJohn Marino void
curses_bar_free(struct curses_bar * b)87*86d7f5d3SJohn Marino curses_bar_free(struct curses_bar *b)
88*86d7f5d3SJohn Marino {
89*86d7f5d3SJohn Marino if (b != NULL) {
90*86d7f5d3SJohn Marino if (b->pan != NULL) {
91*86d7f5d3SJohn Marino del_panel(b->pan);
92*86d7f5d3SJohn Marino if (b->win != NULL) {
93*86d7f5d3SJohn Marino delwin(b->win);
94*86d7f5d3SJohn Marino }
95*86d7f5d3SJohn Marino }
96*86d7f5d3SJohn Marino AURA_FREE(b, curses_bar);
97*86d7f5d3SJohn Marino }
98*86d7f5d3SJohn Marino
99*86d7f5d3SJohn Marino update_panels();
100*86d7f5d3SJohn Marino doupdate();
101*86d7f5d3SJohn Marino }
102*86d7f5d3SJohn Marino
103*86d7f5d3SJohn Marino void
curses_bar_set_text(struct curses_bar * b,const char * text)104*86d7f5d3SJohn Marino curses_bar_set_text(struct curses_bar *b, const char *text)
105*86d7f5d3SJohn Marino {
106*86d7f5d3SJohn Marino int spaces;
107*86d7f5d3SJohn Marino
108*86d7f5d3SJohn Marino curses_colors_set(b->win, b->colors);
109*86d7f5d3SJohn Marino mvwaddstr(b->win, 0, 0, text);
110*86d7f5d3SJohn Marino spaces = b->width - strlen(text);
111*86d7f5d3SJohn Marino whline(b->win, ' ', spaces);
112*86d7f5d3SJohn Marino }
113