-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindow.c
71 lines (59 loc) · 1.58 KB
/
window.c
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
#include <string.h>
#include "window.h"
void w_create(Window* W, int height, int width, int starty, int startx, const char* name, enum WinType type) {
W->window_ptr = newwin(height, width, starty, startx);
W->selected = false;
W->width = width;
W->height = height;
W->name = name;
W->index = 0;
W->type = type;
W->redraw = true;
// scrollok(w->window_ptr, true);
}
void w_cleanup(Window* windows) {
short i;
Window* w = windows;
for (i = 0; i < 3; i++, w++) {
JSList* l = w->list;
jack_slist_free(l);
w->redraw = true;
}
}
void w_draw_border(Window* W) {
int col = (W->width - strlen(W->name) - 4) / 2;
if (col < 0) col = 0;
/* 0, 0 gives default characters for the vertical and horizontal lines */
box(W->window_ptr, 0, 0);
if (W->selected) {
wattron(W->window_ptr, WA_BOLD|COLOR_PAIR(4));
mvwprintw(W->window_ptr, 0, col, "=[%s]=", W->name);
wattroff(W->window_ptr, WA_BOLD|COLOR_PAIR(4));
} else {
mvwprintw(W->window_ptr, 0, col, " [%s] ", W->name);
}
}
void w_assign_list(Window* W, JSList* list) {
W->list = list;
W->count = jack_slist_length(W->list);
W->redraw = true;
if (W->index > W->count - 1)
W->index = 0;
}
void w_resize(Window* W, int height, int width, int starty, int startx) {
//delwin(W->window_ptr);
//W->window_ptr = newwin(height, width, starty, startx);
wresize(W->window_ptr, height, width);
mvwin(W->window_ptr, starty, startx);
W->width = width;
W->height = height;
W->redraw = true;
}
void w_item_next(Window* W) {
if (W->index < W->count - 1)
W->index++;
}
void w_item_previous(Window* W) {
if (W->index > 0)
W->index--;
}