| 1 |
/* |
| 2 |
* frames canvas frame switching features |
| 3 |
* Copyright (c) 2006-2012 Sam Hocevar <[email protected]> |
| 4 |
* All Rights Reserved |
| 5 |
* |
| 6 |
* This program is free software. It comes without any warranty, to |
| 7 |
* the extent permitted by applicable law. You can redistribute it |
| 8 |
* and/or modify it under the terms of the Do What the Fuck You Want |
| 9 |
* to Public License, Version 2, as published by Sam Hocevar. See |
| 10 |
* http://www.wtfpl.net/ for more details. |
| 11 |
*/ |
| 12 |
|
| 13 |
#include "config.h" |
| 14 |
|
| 15 |
#if !defined(__KERNEL__) |
| 16 |
# include <stdio.h> |
| 17 |
#endif |
| 18 |
|
| 19 |
#include "caca.h" |
| 20 |
|
| 21 |
int main(int argc, char *argv[]) |
| 22 |
{ |
| 23 |
caca_canvas_t *cv; |
| 24 |
caca_display_t *dp; |
| 25 |
|
| 26 |
int n, frame; |
| 27 |
|
| 28 |
/* Create a canvas with 200 frames */ |
| 29 |
cv = caca_create_canvas(0, 0); |
| 30 |
if(cv == NULL) |
| 31 |
{ |
| 32 |
printf("Can't create canvas\n"); |
| 33 |
return -1; |
| 34 |
} |
| 35 |
|
| 36 |
for(frame = 1; frame < 200; frame++) |
| 37 |
caca_create_frame(cv, frame); |
| 38 |
|
| 39 |
fprintf(stderr, "canvas created, size is %ix%i\n", |
| 40 |
caca_get_canvas_width(cv), caca_get_canvas_height(cv)); |
| 41 |
|
| 42 |
/* Resize it to 150 x 80 (around 19MB) */ |
| 43 |
caca_set_canvas_size(cv, 150, 80); |
| 44 |
|
| 45 |
fprintf(stderr, "canvas expanded, size is %ix%i\n", |
| 46 |
caca_get_canvas_width(cv), caca_get_canvas_height(cv)); |
| 47 |
|
| 48 |
/* Fill the first 16 frames with a different colour */ |
| 49 |
for(frame = 0; frame < 16; frame++) |
| 50 |
{ |
| 51 |
caca_set_frame(cv, frame); |
| 52 |
caca_set_color_ansi(cv, CACA_WHITE, frame); |
| 53 |
caca_fill_box(cv, 0, 0, 40, 15, ':'); |
| 54 |
caca_set_color_ansi(cv, CACA_WHITE, CACA_BLUE); |
| 55 |
caca_put_str(cv, frame * 5 / 2, frame, "カカ"); |
| 56 |
caca_set_color_ansi(cv, CACA_DEFAULT, CACA_TRANSPARENT); |
| 57 |
} |
| 58 |
|
| 59 |
/* Resize it to a more decent size */ |
| 60 |
caca_set_canvas_size(cv, 41, 16); |
| 61 |
|
| 62 |
fprintf(stderr, "canvas shrinked, size is %ix%i\n", |
| 63 |
caca_get_canvas_width(cv), caca_get_canvas_height(cv)); |
| 64 |
|
| 65 |
dp = caca_create_display(cv); |
| 66 |
caca_set_display_time(dp, 50000); |
| 67 |
|
| 68 |
fprintf(stderr, "display attached, size is %ix%i\n", |
| 69 |
caca_get_canvas_width(cv), caca_get_canvas_height(cv)); |
| 70 |
|
| 71 |
n = 0; |
| 72 |
while(!caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, 0)) |
| 73 |
{ |
| 74 |
caca_set_frame(cv, n % 16); |
| 75 |
caca_refresh_display(dp); |
| 76 |
n++; |
| 77 |
} |
| 78 |
|
| 79 |
caca_free_display(dp); |
| 80 |
|
| 81 |
/* It is possible, though not necessary, to free all additional frames |
| 82 |
* separately. */ |
| 83 |
caca_free_canvas(cv); |
| 84 |
|
| 85 |
return 0; |
| 86 |
} |
| 87 |
|