Kaynağa Gözat

* Added an emulation layer for pre-1.0 libcaca API. Legacy applications

just need to include <caca0.h> instead of <caca.h> and should be source-
    compatible with old versions of libcaca.

    Most of the old API works, except features and caca_sqrt(). Sprites do
    work API-wise but due to the new format they are no longer working in
    the same way.
tags/v0.99.beta14
Sam Hocevar sam 18 yıl önce
ebeveyn
işleme
7e587a46b9
3 değiştirilmiş dosya ile 389 ekleme ve 1 silme
  1. +3
    -1
      caca/Makefile.am
  2. +195
    -0
      caca/caca0.c
  3. +191
    -0
      caca/caca0.h

+ 3
- 1
caca/Makefile.am Dosyayı Görüntüle

@@ -6,7 +6,7 @@ DISTCLEANFILES = caca.pc
pkgconfig_DATA = caca.pc
pkgconfigdir = $(libdir)/pkgconfig

include_HEADERS = caca.h
include_HEADERS = caca.h caca0.h

lib_LTLIBRARIES = libcaca.la

@@ -14,6 +14,8 @@ libcaca_la_SOURCES = \
caca.c \
caca.h \
caca_internals.h \
caca0.c \
caca0.h \
graphics.c \
event.c \
time.c \


+ 195
- 0
caca/caca0.c Dosyayı Görüntüle

@@ -0,0 +1,195 @@
/*
* libcaca Colour ASCII-Art library
* Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
* All Rights Reserved
*
* $Id$
*
* This library 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.
*/

/*
* This file contains glue code for applications using the pre-1.0
* libcaca API.
*/

#include "config.h"
#include "common.h"

#if !defined(__KERNEL__)
# include <stdio.h>
#endif

#include "caca.h"
#include "caca_internals.h"

/* These variables are needed to emulate old non-thread safe behaviour */
cucul_canvas_t *__caca0_cv = NULL;
caca_display_t *__caca0_dp = NULL;
unsigned char __caca0_fg;
unsigned char __caca0_bg;
char __caca0_utf8[2] = " ";

/* These functions are needed, too */
int __caca0_init(void);
void __caca0_end(void);
unsigned int __caca0_get_event(unsigned int, int);
int __caca0_get_feature(int);
void __caca0_set_feature(int);
char const *__caca0_get_feature_name(int);
cucul_canvas_t *__caca0_load_sprite(char const *);

/* Emulation functions */
int __caca0_init(void)
{
__caca0_cv = cucul_create_canvas(0, 0);
if(!__caca0_cv)
return -1;
__caca0_dp = caca_create_display(__caca0_cv);
if(!__caca0_dp)
{
cucul_free_canvas(__caca0_cv);
__caca0_cv = NULL;
return -1;
}
__caca0_fg = CUCUL_COLOR_LIGHTGRAY;
__caca0_bg = CUCUL_COLOR_BLACK;
return 0;
}

void __caca0_end(void)
{
caca_free_display(__caca0_dp);
__caca0_dp = NULL;
cucul_free_canvas(__caca0_cv);
__caca0_cv = NULL;
}

unsigned int __caca0_get_event(unsigned int m, int t)
{
caca_event_t ev;
int ret;

ret = caca_get_event(__caca0_dp, (m >> 24) & 0x7f, &ev, t);
if(!ret)
return 0x00000000;

switch(ev.type)
{
case CACA_EVENT_KEY_PRESS:
return 0x01000000 | ev.data.key.ch;
case CACA_EVENT_KEY_RELEASE:
return 0x02000000 | ev.data.key.ch;
case CACA_EVENT_MOUSE_PRESS:
return 0x04000000 | ev.data.mouse.button;
case CACA_EVENT_MOUSE_RELEASE:
return 0x08000000 | ev.data.mouse.button;
case CACA_EVENT_MOUSE_MOTION:
return 0x10000000 | ((ev.data.mouse.x & 0xfff) << 12)
| (ev.data.mouse.y & 0xfff);
case CACA_EVENT_RESIZE:
return 0x20000000;
default:
break;
}

return 0x00000000;
}

enum caca_feature
{
CACA_BACKGROUND = 0x10,
CACA_BACKGROUND_BLACK = 0x11,
CACA_BACKGROUND_SOLID = 0x12,
#define CACA_BACKGROUND_MIN 0x11
#define CACA_BACKGROUND_MAX 0x12
CACA_ANTIALIASING = 0x20,
CACA_ANTIALIASING_NONE = 0x21,
CACA_ANTIALIASING_PREFILTER = 0x22,
#define CACA_ANTIALIASING_MIN 0x21
#define CACA_ANTIALIASING_MAX 0x22
CACA_DITHERING = 0x30,
CACA_DITHERING_NONE = 0x31,
CACA_DITHERING_ORDERED2 = 0x32,
CACA_DITHERING_ORDERED4 = 0x33,
CACA_DITHERING_ORDERED8 = 0x34,
CACA_DITHERING_RANDOM = 0x35,
#define CACA_DITHERING_MIN 0x31
#define CACA_DITHERING_MAX 0x35
CACA_FEATURE_UNKNOWN = 0xffff
};

int __caca0_get_feature(int feature)
{
return feature;
}

void __caca0_set_feature(int feature)
{
switch(feature)
{
case CACA_BACKGROUND:
feature = CACA_BACKGROUND_SOLID;
case CACA_BACKGROUND_BLACK:
case CACA_BACKGROUND_SOLID:
//_caca_background = feature;
break;

case CACA_ANTIALIASING:
feature = CACA_ANTIALIASING_PREFILTER;
case CACA_ANTIALIASING_NONE:
case CACA_ANTIALIASING_PREFILTER:
//_caca_antialiasing = feature;
break;

case CACA_DITHERING:
feature = CACA_DITHERING_ORDERED4;
case CACA_DITHERING_NONE:
case CACA_DITHERING_ORDERED2:
case CACA_DITHERING_ORDERED4:
case CACA_DITHERING_ORDERED8:
case CACA_DITHERING_RANDOM:
//_caca_dithering = feature;
break;
}
}

char const *__caca0_get_feature_name(int feature)
{
switch(feature)
{
case CACA_BACKGROUND_BLACK: return "black background";
case CACA_BACKGROUND_SOLID: return "solid background";

case CACA_ANTIALIASING_NONE: return "no antialiasing";
case CACA_ANTIALIASING_PREFILTER: return "prefilter antialiasing";

case CACA_DITHERING_NONE: return "no dithering";
case CACA_DITHERING_ORDERED2: return "2x2 ordered dithering";
case CACA_DITHERING_ORDERED4: return "4x4 ordered dithering";
case CACA_DITHERING_ORDERED8: return "8x8 ordered dithering";
case CACA_DITHERING_RANDOM: return "random dithering";

default: return "unknown";
}
}

cucul_canvas_t *__caca0_load_sprite(char const *file)
{
cucul_buffer_t *buf;
cucul_canvas_t *cv;

buf = cucul_load_file(file);
if(!buf)
return NULL;
cv = cucul_import_canvas(buf, "");
cucul_free_buffer(buf);
if(!cv)
return NULL;

return cv;
}


+ 191
- 0
caca/caca0.h Dosyayı Görüntüle

@@ -0,0 +1,191 @@
/*
* libcaca Colour ASCII-Art library
* Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
* All Rights Reserved
*
* $Id$
*
* This library 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.
*/

/*
* This header contains glue code for applications using the pre-1.0
* libcaca API.
*/

#ifndef __CACA0_H__
#define __CACA0_H__

#include <caca.h>

#ifdef __cplusplus
extern "C"
{
#endif

/* Function emulation */
extern int __caca0_init(void);
extern void __caca0_end(void);
extern unsigned int __caca0_get_event(unsigned int, int);
extern int __caca0_get_feature(int);
extern void __caca0_set_feature(int);
extern char const *__caca0_get_feature_name(int);
extern cucul_canvas_t *__caca0_load_sprite(char const *);

/* These variables are needed to emulate old non-thread safe behaviour */
extern cucul_canvas_t *__caca0_cv;
extern caca_display_t *__caca0_dp;
extern unsigned char __caca0_fg;
extern unsigned char __caca0_bg;
extern char __caca0_utf8[];

/* These enums and macros changed names or values */
enum caca_color
{
CACA_COLOR_BLACK = CUCUL_COLOR_BLACK,
CACA_COLOR_BLUE = CUCUL_COLOR_BLUE,
CACA_COLOR_GREEN = CUCUL_COLOR_GREEN,
CACA_COLOR_CYAN = CUCUL_COLOR_CYAN,
CACA_COLOR_RED = CUCUL_COLOR_RED,
CACA_COLOR_MAGENTA = CUCUL_COLOR_MAGENTA,
CACA_COLOR_BROWN = CUCUL_COLOR_BROWN,
CACA_COLOR_LIGHTGRAY = CUCUL_COLOR_LIGHTGRAY,
CACA_COLOR_DARKGRAY = CUCUL_COLOR_DARKGRAY,
CACA_COLOR_LIGHTBLUE = CUCUL_COLOR_LIGHTBLUE,
CACA_COLOR_LIGHTGREEN = CUCUL_COLOR_LIGHTGREEN,
CACA_COLOR_LIGHTCYAN = CUCUL_COLOR_LIGHTCYAN,
CACA_COLOR_LIGHTRED = CUCUL_COLOR_LIGHTRED,
CACA_COLOR_LIGHTMAGENTA = CUCUL_COLOR_LIGHTMAGENTA,
CACA_COLOR_YELLOW = CUCUL_COLOR_YELLOW,
CACA_COLOR_WHITE = CUCUL_COLOR_WHITE,
};

enum caca_feature
{
CACA_BACKGROUND = 0x10,
CACA_BACKGROUND_BLACK = 0x11,
CACA_BACKGROUND_SOLID = 0x12,
#define CACA_BACKGROUND_MIN 0x11
#define CACA_BACKGROUND_MAX 0x12
CACA_ANTIALIASING = 0x20,
CACA_ANTIALIASING_NONE = 0x21,
CACA_ANTIALIASING_PREFILTER = 0x22,
#define CACA_ANTIALIASING_MIN 0x21
#define CACA_ANTIALIASING_MAX 0x22
CACA_DITHERING = 0x30,
CACA_DITHERING_NONE = 0x31,
CACA_DITHERING_ORDERED2 = 0x32,
CACA_DITHERING_ORDERED4 = 0x33,
CACA_DITHERING_ORDERED8 = 0x34,
CACA_DITHERING_RANDOM = 0x35,
#define CACA_DITHERING_MIN 0x31
#define CACA_DITHERING_MAX 0x35
CACA_FEATURE_UNKNOWN = 0xffff
};

#define CACA_EVENT_NONE 0x00000000
#define CACA_EVENT_KEY_PRESS 0x01000000
#define CACA_EVENT_KEY_RELEASE 0x02000000
#define CACA_EVENT_MOUSE_PRESS 0x04000000
#define CACA_EVENT_MOUSE_RELEASE 0x08000000
#define CACA_EVENT_MOUSE_MOTION 0x10000000
#define CACA_EVENT_RESIZE 0x20000000
#define CACA_EVENT_ANY 0xff000000

/* Backwards compatibility macros for even older shit */
#define caca_dithering caca_feature
#define caca_set_dithering caca_set_feature
#define caca_get_dithering_name caca_get_feature_name
#define CACA_DITHER_NONE CACA_DITHERING_NONE
#define CACA_DITHER_ORDERED CACA_DITHERING_ORDERED8
#define CACA_DITHER_RANDOM CACA_DITHERING_RANDOM

/* Macros to redefine all the shit */
#define caca_init __caca0_init
#define caca_set_delay(x) caca_set_display_time(__caca0_dp, x)
#define caca_get_feature __caca0_get_feature
#define caca_set_feature __caca0_set_feature
#define caca_get_feature_name __caca0_get_feature_name
#define caca_get_rendertime() caca_get_display_time(__caca0_dp)
#define caca_get_width() cucul_get_canvas_width(__caca0_cv)
#define caca_get_height() cucul_get_canvas_height(__caca0_cv)
#define caca_set_window_title(s) caca_set_display_title(__caca0_dp, s)
#define caca_get_window_width() caca_get_display_width(__caca0_dp)
#define caca_get_window_height() caca_get_display_height(__caca0_dp)
#define caca_refresh() caca_refresh_display(__caca0_dp)
#define caca_end __caca0_end

#define caca_get_event(x) __caca0_get_event(x, 0)
#define caca_wait_event(x) __caca0_get_event(x, -1)
#define caca_get_mouse_x() caca_get_mouse_x(__caca0_dp)
#define caca_get_mouse_y() caca_get_mouse_y(__caca0_dp)

#define caca_set_color(x, y) cucul_set_color(__caca0_cv, x, y)
#define caca_get_color_name cucul_get_color_name
#define caca_putchar(x, y, c) cucul_putchar(__caca0_cv, x, y, c)
#define caca_putstr(x, y, s) cucul_putstr(__caca0_cv, x, y, s)
#define caca_printf(x, y, f, z...) cucul_printf(__caca0_cv, x, y, f, ##z)
#define caca_clear() cucul_clear_canvas(__caca0_cv)

#define caca_draw_line(x, y, z, t, c) \
(__caca0_utf8[0] = c, \
cucul_draw_line(__caca0_cv, x, y, z, t, __caca0_utf8))
#define caca_draw_polyline(x, y, z, c) \
(__caca0_utf8[0] = c, \
cucul_draw_polyline(__caca0_cv, x, y, z, __caca0_utf8))
#define caca_draw_thin_line(x, y, z, t) \
cucul_draw_thin_line(__caca0_cv, x, y, z, t)
#define caca_draw_thin_polyline(x, y, z) \
cucul_draw_thin_polyline(__caca0_cv, x, y, z)
#define caca_draw_circle(x, y, z, c) \
(__caca0_utf8[0] = c, cucul_draw_circle(__caca0_cv, x, y, z, __caca0_utf8))
#define caca_draw_ellipse(x, y, z, t, c) \
(__caca0_utf8[0] = c, \
cucul_draw_ellipse(__caca0_cv, x, y, z, t, __caca0_utf8))
#define caca_draw_thin_ellipse(x, y, z, t) \
cucul_draw_thin_ellipse(__caca0_cv, x, y, z, t)
#define caca_fill_ellipse(x, y, z, t, c) \
(__caca0_utf8[0] = c, \
cucul_fill_ellipse(__caca0_cv, x, y, z, t, __caca0_utf8))
#define caca_draw_box(x, y, z, t, c) \
(__caca0_utf8[0] = c, cucul_draw_box(__caca0_cv, x, y, z, t, __caca0_utf8))
#define caca_draw_thin_box(x, y, z, t) \
cucul_draw_thin_box(__caca0_cv, x, y, z, t)
#define caca_fill_box(x, y, z, t, c) \
(__caca0_utf8[0] = c, cucul_fill_box(__caca0_cv, x, y, z, t, __caca0_utf8))
#define caca_draw_triangle(x, y, z, t, u, v, c) \
(__caca0_utf8[0] = c, \
cucul_draw_triangle(__caca0_cv, x, y, z, t, u, v, __caca0_utf8))
#define caca_draw_thin_triangle(x, y, z, t, u, v) \
cucul_draw_thin_triangle(__caca0_cv, x, y, z, t, u, v)
#define caca_fill_triangle(x, y, z, t, u, v, c) \
(__caca0_utf8[0] = c, \
cucul_fill_triangle(__caca0_cv, x, y, z, t, u, v, __caca0_utf8))

#define caca_rand(a, b) cucul_rand(a, (b)+1)

#define caca_sprite cucul_canvas
#define caca_load_sprite __caca0_load_sprite
#define caca_get_sprite_frames(c) 0
#define caca_get_sprite_width(c, f) cucul_get_canvas_width(c)
#define caca_get_sprite_height(c, f) cucul_get_canvas_height(c)
#define caca_get_sprite_dx(c, f) 0
#define caca_get_sprite_dx(c, f) 0
#define caca_draw_sprite(x, y, c, f) cucul_blit(__caca0_cv, x, y, c, NULL)
#define caca_free_sprite cucul_free_canvas

#define caca_bitmap cucul_dither
#define caca_create_bitmap cucul_create_dither
#define caca_set_bitmap_palette cucul_set_dither_palette
#define caca_draw_bitmap(x, y, z, t, b, p) \
cucul_dither_bitmap(__caca0_cv, x, y, z, t, b, p)
#define caca_free_bitmap cucul_free_dither

#ifdef __cplusplus
}
#endif

#endif /* __CACA0_H__ */

Yükleniyor…
İptal
Kaydet