| 1 | /* |
|---|
| 2 | * frames canvas frame switching features |
|---|
| 3 | * Copyright (c) 2006 Sam Hocevar <sam@zoy.org> |
|---|
| 4 | * All Rights Reserved |
|---|
| 5 | * |
|---|
| 6 | * $Id$ |
|---|
| 7 | * |
|---|
| 8 | * This program is free software; you can redistribute it and/or |
|---|
| 9 | * modify it under the terms of the Do What The Fuck You Want To |
|---|
| 10 | * Public License, Version 2, as published by Sam Hocevar. See |
|---|
| 11 | * http://sam.zoy.org/wtfpl/COPYING for more details. |
|---|
| 12 | */ |
|---|
| 13 | |
|---|
| 14 | #include "config.h" |
|---|
| 15 | #include "common.h" |
|---|
| 16 | #if !defined(__KERNEL__) |
|---|
| 17 | # if defined(HAVE_INTTYPES_H) |
|---|
| 18 | # include <inttypes.h> |
|---|
| 19 | # endif |
|---|
| 20 | |
|---|
| 21 | # include <stdio.h> |
|---|
| 22 | #endif |
|---|
| 23 | #include "cucul.h" |
|---|
| 24 | #include "caca.h" |
|---|
| 25 | |
|---|
| 26 | int main(int argc, char *argv[]) |
|---|
| 27 | { |
|---|
| 28 | cucul_canvas_t *cv; |
|---|
| 29 | caca_display_t *dp; |
|---|
| 30 | |
|---|
| 31 | int n, frame; |
|---|
| 32 | |
|---|
| 33 | /* Create a canvas with 200 frames */ |
|---|
| 34 | cv = cucul_create_canvas(0, 0); |
|---|
| 35 | for(frame = 1; frame < 200; frame++) |
|---|
| 36 | cucul_create_canvas_frame(cv, frame); |
|---|
| 37 | |
|---|
| 38 | fprintf(stderr, "canvas created, size is %ix%i\n", |
|---|
| 39 | cucul_get_canvas_width(cv), cucul_get_canvas_height(cv)); |
|---|
| 40 | |
|---|
| 41 | /* Resize it to 150 x 80 (around 19MB) */ |
|---|
| 42 | cucul_set_canvas_size(cv, 150, 80); |
|---|
| 43 | |
|---|
| 44 | fprintf(stderr, "canvas expanded, size is %ix%i\n", |
|---|
| 45 | cucul_get_canvas_width(cv), cucul_get_canvas_height(cv)); |
|---|
| 46 | |
|---|
| 47 | /* Fill the first 16 frames with a different colour */ |
|---|
| 48 | for(frame = 0; frame < 16; frame++) |
|---|
| 49 | { |
|---|
| 50 | cucul_set_canvas_frame(cv, frame); |
|---|
| 51 | cucul_set_color_ansi(cv, CUCUL_WHITE, frame); |
|---|
| 52 | cucul_fill_box(cv, 0, 0, 40, 15, ':'); |
|---|
| 53 | cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLUE); |
|---|
| 54 | cucul_put_str(cv, frame * 5 / 2, frame, "カカ"); |
|---|
| 55 | cucul_set_color_ansi(cv, CUCUL_DEFAULT, CUCUL_TRANSPARENT); |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | /* Resize it to a more decent size */ |
|---|
| 59 | cucul_set_canvas_size(cv, 41, 16); |
|---|
| 60 | |
|---|
| 61 | fprintf(stderr, "canvas shrinked, size is %ix%i\n", |
|---|
| 62 | cucul_get_canvas_width(cv), cucul_get_canvas_height(cv)); |
|---|
| 63 | |
|---|
| 64 | dp = caca_create_display(cv); |
|---|
| 65 | caca_set_display_time(dp, 50000); |
|---|
| 66 | |
|---|
| 67 | fprintf(stderr, "display attached, size is %ix%i\n", |
|---|
| 68 | cucul_get_canvas_width(cv), cucul_get_canvas_height(cv)); |
|---|
| 69 | |
|---|
| 70 | n = 0; |
|---|
| 71 | while(!caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, 0)) |
|---|
| 72 | { |
|---|
| 73 | cucul_set_canvas_frame(cv, n % 16); |
|---|
| 74 | caca_refresh_display(dp); |
|---|
| 75 | n++; |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | caca_free_display(dp); |
|---|
| 79 | |
|---|
| 80 | /* It is possible, though not necessary, to free all additional frames |
|---|
| 81 | * separately. */ |
|---|
| 82 | cucul_free_canvas(cv); |
|---|
| 83 | |
|---|
| 84 | return 0; |
|---|
| 85 | } |
|---|
| 86 | |
|---|