File: ui.c

package info (click to toggle)
wavemon 0.4.0b-11
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 452 kB
  • ctags: 247
  • sloc: sh: 2,517; ansic: 2,417; makefile: 64
file content (117 lines) | stat: -rw-r--r-- 3,412 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
 * wavemon - a wireless network monitoring aplication
 *
 * Copyright (c) 2001-2002 Jan Morgenstern <jan@jm-music.de>
 *
 * wavemon is free software; you can redistribute it and/or modify it under 
 * the terms of the GNU General Public License as published by the Free 
 * Software Foundation; either version 2, or (at your option) any later 
 * version.
 * 
 * wavemon is distributed in the hope that it will be useful, but WITHOUT ANY 
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
 * details.
 * 
 * You should have received a copy of the GNU General Public License along 
 * with wavemon; see the file COPYING.  If not, write to the Free Software 
 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#include <stdio.h>
#include <string.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <ncurses.h>

#include "ui.h"
#include "defs.h"

char *screens[] = { "info", "lhist", "aplst", "", "", "", "prefs", "help", "about", "quit" };

void wmenubar(WINDOW *win, int active)
{
	char tmp[12];
	int i, j, n = 0;
	
	wmove(win, 0, 0);
	for (i = 0; i < 10; i++) {
		sprintf(tmp, "F%d", i + 1);
		wattrset(win, A_REVERSE | A_BOLD);
		waddstr(win, tmp);
		wattroff(win, A_REVERSE | A_BOLD);
		sprintf(tmp, "%s%n", screens[i], &n);
		wattrset(win, (i == active ? COLOR_PAIR(CP_ACTIVE) | A_BOLD : COLOR_PAIR(CP_INACTIVE)));
		waddstr(win, tmp);
		for (j = 0; j < 6 - n; j++) waddstr(win, " ");
		wattroff(win, COLOR_PAIR(6));
	}
}

void waddstr_center(WINDOW *win, int y, char *s)
{
	mvwaddstr(win, y, (COLS >> 1) - (strlen(s) >> 1), s);
}

WINDOW *newwin_title(int h, int w, int x, int y, char *title, char t, char b)
{
	WINDOW *win = newwin(h, w, x, y);
	if (b) {
		wmove(win, 0, 0);
		waddch(win, (t ? ACS_LTEE : ACS_ULCORNER));
		whline(win, ACS_HLINE, w - 2);
		mvwaddch(win, 0, w - 1, (t ? ACS_RTEE : ACS_URCORNER));
		mvwvline(win, 1, 0, ACS_VLINE, h);
		mvwvline(win, 1, w - 1, ACS_VLINE, h);
	} else
		wborder(win, ACS_VLINE, ACS_VLINE, ACS_HLINE, ACS_HLINE,
			(t ? ACS_LTEE : ACS_ULCORNER), (t ? ACS_RTEE : ACS_URCORNER),
			ACS_LLCORNER, ACS_LRCORNER);
	
	wmove(win, 0, 2);
	wattrset(win, COLOR_PAIR(5));
	waddstr(win, title);
	wattroff(win, COLOR_PAIR(5));
			
	return win;
}

void waddstr_b(WINDOW *win, char *s)
{
	wattron(win, A_BOLD);
	waddstr(win, s);
	wattroff(win, A_BOLD);
}

void waddbar(WINDOW *win, float v, float minv, float maxv, char y, char x, char maxx, char *cscale, char rev)
{
	int c;
	int col;
	int val = 0;

	char steps = maxx - x;

	val = (v <= maxv ? v : val);

	if (v < cscale[0]) col = (rev ? 2 : 4);
		else if (v < cscale[1]) col = 3;
			else col = (rev ? 4 : 2);

	for (c = 0; c < steps / (float)(maxv - minv) * (val - minv); c++)
		if (c < COLS -2) mvwaddch(win, y, x + c, '=' | A_BOLD | COLOR_PAIR(col));
	while (x + c < maxx) mvwaddch(win, y, x + c++, 183);
}

void waddthreshold(WINDOW *win, float v, float tv, float minv, float maxv, char y, char x, char maxx, char *cscale, char rev, char tch)
{
	int col;
	char steps = maxx - x;

	if (v < cscale[0]) col = (rev ? 2 : 4) | A_BOLD;
		else if (v < cscale[1]) col = 3 | A_BOLD;
			else col = (rev ? 4 : 2) | A_BOLD;

	if (tv > minv && tv < maxv)
		mvwaddch(win, y, x + (steps / (float)(maxv - minv) * (tv - minv)),
			tch | (v > tv ? COLOR_PAIR(col) | A_BOLD : COLOR_PAIR(CP_STANDARD)));
}