-
-
Notifications
You must be signed in to change notification settings - Fork 122
/
Copy pathbitmapstates.c
163 lines (148 loc) · 4.48 KB
/
bitmapstates.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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#include <unistd.h>
#include <notcurses/notcurses.h>
static void
emit(struct ncplane* n, const char* str){
fprintf(stderr, "\n\n\n%s\n", str);
ncplane_erase_region(n, 6, 0, INT_MAX, 0);
ncplane_putstr_yx(n, 6, 0, str);
}
// draw a bitmap of 6x6 cells with a cell left out
static int
wipebitmap(struct notcurses* nc){
int cellpxy, cellpxx;
ncplane_pixel_geom(notcurses_stdplane(nc), NULL, NULL,
&cellpxy, &cellpxx, NULL, NULL);
int pixy = cellpxy * 6;
int pixx = cellpxx * 6;
uint32_t pixels[pixx * pixy];
memset(pixels, 0xff, sizeof(pixels));
struct ncvisual* ncv = ncvisual_from_rgba(pixels,
6 * cellpxy,
6 * cellpxx * 4,
6 * cellpxx);
if(ncv == NULL){
return -1;
}
struct ncvisual_options vopts = {
.blitter = NCBLIT_PIXEL,
};
struct ncplane* n = ncvisual_render(nc, ncv, &vopts);
if(n == NULL){
return -1;
}
emit(notcurses_stdplane(nc), "Ought see full square");
notcurses_debug(nc, stderr);
notcurses_render(nc);
sleep(2);
ncplane_erase(notcurses_stdplane(nc));
for(int y = 1 ; y < 5 ; ++y){
for(int x = 1 ; x < 5 ; ++x){
ncplane_putchar_yx(notcurses_stdplane(nc), y, x, '*');
}
}
uint64_t channels = 0;
ncchannels_set_bg_alpha(&channels, NCALPHA_TRANSPARENT);
ncchannels_set_fg_alpha(&channels, NCALPHA_TRANSPARENT);
ncplane_set_base(notcurses_stdplane(nc), "", 0, channels);
ncplane_move_top(notcurses_stdplane(nc));
emit(notcurses_stdplane(nc), "Ought see 16 *s");
notcurses_render(nc);
sleep(2);
ncplane_erase(notcurses_stdplane(nc));
emit(notcurses_stdplane(nc), "Ought see full square");
notcurses_debug(nc, stderr);
notcurses_render(nc);
sleep(2);
ncplane_erase(notcurses_stdplane(nc));
for(int y = 1 ; y < 5 ; ++y){
for(int x = 1 ; x < 5 ; ++x){
ncplane_putchar_yx(notcurses_stdplane(nc), y, x, ' ');
}
}
emit(notcurses_stdplane(nc), "Ought see 16 spaces");
notcurses_debug(nc, stderr);
notcurses_render(nc);
sleep(2);
ncplane_erase(notcurses_stdplane(nc));
ncplane_destroy(n);
emit(notcurses_stdplane(nc), "Ought see nothing");
notcurses_debug(nc, stderr);
notcurses_render(nc);
sleep(2);
ncplane_erase(notcurses_stdplane(nc));
for(int i = cellpxy ; i < 5 * cellpxy ; ++i){
memset(pixels + (i * 6 * cellpxx + cellpxx), 0, cellpxx * 4 * sizeof(*pixels));
}
struct ncvisual* ncve = ncvisual_from_rgba(pixels, 6 * cellpxy, 6 * cellpxx * 4, 6 * cellpxx);
if(ncve == NULL){
return -1;
}
if((n = ncvisual_render(nc, ncve, &vopts)) == NULL){
return -1;
}
emit(notcurses_stdplane(nc), "Ought see empty square");
notcurses_debug(nc, stderr);
notcurses_render(nc);
sleep(2);
vopts.n = n;
ncplane_move_top(notcurses_stdplane(nc));
// now, actually wipe the middle with *s, and then ensure that a new render
// gets wiped out before being displayed
if(ncvisual_render(nc, ncv, &vopts) == NULL){
return -1;
}
emit(notcurses_stdplane(nc), "Ought see full square");
notcurses_debug(nc, stderr);
notcurses_render(nc);
sleep(2);
for(int y = 1 ; y < 5 ; ++y){
for(int x = 1 ; x < 5 ; ++x){
ncplane_putchar_yx(notcurses_stdplane(nc), y, x, '*');
}
}
emit(notcurses_stdplane(nc), "Ought see 16 *s");
notcurses_debug(nc, stderr);
notcurses_render(nc);
sleep(2);
if(ncvisual_render(nc, ncv, &vopts) == NULL){
return -1;
}
emit(notcurses_stdplane(nc), "Ought *still* see 16 *s");
notcurses_debug(nc, stderr);
notcurses_render(nc);
sleep(2);
ncplane_move_yx(n, 0, 7);
emit(notcurses_stdplane(nc), "Full square on right");
notcurses_debug(nc, stderr);
notcurses_render(nc);
sleep(2);
ncplane_move_yx(n, 0, 0);
emit(notcurses_stdplane(nc), "Ought see 16 *s");
notcurses_debug(nc, stderr);
notcurses_render(nc);
sleep(2);
ncplane_move_yx(n, 0, 7);
emit(notcurses_stdplane(nc), "Full square on right");
notcurses_debug(nc, stderr);
notcurses_render(nc);
sleep(2);
ncvisual_destroy(ncve);
ncvisual_destroy(ncv);
ncplane_destroy(n);
return 0;
}
int main(void){
struct notcurses_options opts = {
.loglevel = NCLOGLEVEL_TRACE,
.flags = NCOPTION_DRAIN_INPUT,
};
struct notcurses* nc = notcurses_core_init(&opts, NULL);
if(notcurses_check_pixel_support(nc) < 1){
notcurses_stop(nc);
return EXIT_FAILURE;
}
fprintf(stderr, " stderr ought be redirected\n");
int r = wipebitmap(nc);
r |= notcurses_stop(nc);
return r;
}