/
test_caca.c
63 lines (57 loc) · 1.62 KB
/
test_caca.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
//#include <stdio.h>
#include <stdint.h>
#include <string.h>
#ifndef __APPLE__
#include <wchar.h>
#endif
#include <caca.h>
uint32_t gfx[64*32];
int main(void)
{
// R G B A
uint32_t pattern = 0xFFFF00FF;
#ifdef __APPLE__
memset_pattern4(gfx, &pattern, sizeof(gfx));
#else
wmemset(gfx, pattern, (64*32) * sizeof(char));
#endif
gfx[0] = 0xFF0000FF; // R
gfx[1] = 0x00FF00FF; // G
gfx[2] = 0x0000FFFF; // B
gfx[63] = 0xFF0000FF; // R
gfx[64*31] =0x00FF00FF; // G
int x = 64, y = 32;
gfx[(y-1)*64+(x-1)] = 0x0000FFFF; // B
caca_canvas_t *cv; caca_display_t *dp; caca_event_t ev;
dp = caca_create_display(NULL);
if(!dp)
return 1;
#if 0
printf("Current driver: %s\n", caca_get_display_driver(dp));
char **drivers = caca_get_display_driver_list();
caca_free_display(dp);
while(*drivers != NULL) {
printf("%s\n", *drivers);
drivers++;
}
exit(0);
#endif
cv = caca_get_canvas(dp);
caca_dither_t *dither = caca_create_dither(32, 64, 32, 4*64,
0xFF000000,
0x00FF0000,
0x0000FF00,
0x000000FF);
int cw = caca_get_canvas_width(cv);
int ch = caca_get_canvas_height(cv);
caca_set_display_title(dp, "Hello!");
//caca_set_color_ansi(cv, CACA_BLUE, CACA_WHITE);
//caca_put_str(cv, 0, 0, "This is a message");
caca_dither_bitmap(cv, 0,0,cw,ch, dither, gfx);
caca_refresh_display(dp);
caca_free_dither(dither);
//caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1);
caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1);
caca_free_display(dp);
return 0;
}