From 634c8266cca19ab84fc1072848094a78f3711381 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Sat, 22 Apr 2006 19:13:27 +0000 Subject: [PATCH] * Added a test for multiple frames support. * Added a test for textfile loading. --- test/Makefile.am | 8 +++++- test/frames.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++ test/text.c | 60 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 142 insertions(+), 1 deletion(-) create mode 100644 test/frames.c create mode 100644 test/text.c diff --git a/test/Makefile.am b/test/Makefile.am index 67afd77..c45dcda 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -2,7 +2,7 @@ AM_CPPFLAGS = -I$(top_srcdir)/cucul -I$(top_srcdir)/caca -DDATADIR=\"$(pkgdatadir)\" -noinst_PROGRAMS = colors demo dithering event export font gamma hsv spritedit transform truecolor unicode +noinst_PROGRAMS = colors demo dithering event export font frames gamma hsv spritedit text transform truecolor unicode colors_SOURCES = colors.c colors_LDADD = ../caca/libcaca.la ../cucul/libcucul.la @CACA_LIBS@ @@ -22,6 +22,9 @@ export_LDADD = ../cucul/libcucul.la @CUCUL_LIBS@ font_SOURCES = font.c font_LDADD = ../caca/libcaca.la ../cucul/libcucul.la @CACA_LIBS@ +frames_SOURCES = frames.c +frames_LDADD = ../caca/libcaca.la ../cucul/libcucul.la @CACA_LIBS@ + gamma_SOURCES = gamma.c gamma_LDADD = ../caca/libcaca.la ../cucul/libcucul.la @CACA_LIBS@ @MATH_LIBS@ @@ -31,6 +34,9 @@ hsv_LDADD = ../caca/libcaca.la ../cucul/libcucul.la @CACA_LIBS@ spritedit_SOURCES = spritedit.c spritedit_LDADD = ../caca/libcaca.la ../cucul/libcucul.la @CACA_LIBS@ +text_SOURCES = text.c +text_LDADD = ../cucul/libcucul.la + transform_SOURCES = transform.c transform_LDADD = ../caca/libcaca.la ../cucul/libcucul.la @CACA_LIBS@ diff --git a/test/frames.c b/test/frames.c new file mode 100644 index 0000000..bcfcc15 --- /dev/null +++ b/test/frames.c @@ -0,0 +1,75 @@ +/* + * frames canvas frame switching features + * Copyright (c) 2006 Sam Hocevar + * All Rights Reserved + * + * $Id$ + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the Do What The Fuck You Want To + * Public License, Version 2, as published by Sam Hocevar. See + * http://sam.zoy.org/wtfpl/COPYING for more details. + */ + +#include "config.h" + +#if defined(HAVE_INTTYPES_H) +# include +#else +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; +#endif + +#include "cucul.h" +#include "caca.h" + +int main(void) +{ + caca_event_t ev; + cucul_canvas_t *cv; + caca_display_t *dp; + + int n, frame; + + /* Create a canvas with 200 frames */ + cv = cucul_create_canvas(0, 0); + for(frame = 1; frame < 200; frame++) + cucul_create_canvas_frame(cv, frame); + + /* Resize it to 150 x 80 (around 19MB) */ + cucul_set_canvas_size(cv, 150, 80); + + /* Resize it to a more decent size */ + cucul_set_canvas_size(cv, 41, 16); + + dp = caca_create_display(cv); + caca_set_delay(dp, 50000); + + /* Fill the first 16 frames with a different colour */ + for(frame = 0; frame < 16; frame++) + { + cucul_set_canvas_frame(cv, frame); + cucul_set_color(cv, CUCUL_COLOR_WHITE, frame); + cucul_clear_canvas(cv); + cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); + cucul_putstr(cv, frame * 5 / 2, frame, "CACA"); + } + + n = 0; + while(!caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, 0)) + { + cucul_set_canvas_frame(cv, n % 16); + caca_refresh_display(dp); + n++; + } + + caca_free_display(dp); + + /* It is possible, though not necessary, to free all additional frames + * separately. */ + cucul_free_canvas(cv); + + return 0; +} + diff --git a/test/text.c b/test/text.c new file mode 100644 index 0000000..0d0a7fc --- /dev/null +++ b/test/text.c @@ -0,0 +1,60 @@ +/* + * text canvas text import/export + * Copyright (c) 2006 Sam Hocevar + * All Rights Reserved + * + * $Id$ + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the Do What The Fuck You Want To + * Public License, Version 2, as published by Sam Hocevar. See + * http://sam.zoy.org/wtfpl/COPYING for more details. + */ + +#include "config.h" + +#if defined(HAVE_INTTYPES_H) +# include +#else +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; +#endif + +#include +#include + +#include "cucul.h" + +#define STRING \ + "Hello world!\n" \ + " _,----._ \n" \ + " (/ @ @ \\) \n" \ + " | OO | \n" \ + " \\ `--' / \n" \ + " `----' \n" + +int main(void) +{ + cucul_canvas_t *cv; + cucul_buffer_t *buffer; + + cv = cucul_import_canvas(STRING, strlen(STRING), "text"); + + buffer = cucul_export_canvas(cv, "ansi"); + fwrite(cucul_get_buffer_data(buffer), + cucul_get_buffer_size(buffer), 1, stdout); + cucul_free_buffer(buffer); + + cucul_rotate(cv); + + buffer = cucul_export_canvas(cv, "ansi"); + fwrite(cucul_get_buffer_data(buffer), + cucul_get_buffer_size(buffer), 1, stdout); + cucul_free_buffer(buffer); + + cucul_free_canvas(cv); + + return 0; +} +