Ignore:
Timestamp:
Sep 27, 2008, 3:12:46 PM (11 years ago)
Author:
Sam Hocevar
Message:

Starting refactoring to get rid of libcucul. The initial reason for the
split is rendered moot by the plugin system: when enabled, binaries do
not link directly with libX11 or libGL. I hope this is a step towards
more consisteny and clarity.

File:
1 moved

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/ruby/caca-canvas.c

    r2820 r2821  
    11/*
    2  *  libcucul Ruby bindings
     2 *  libcaca Ruby bindings
    33 *  Copyright (c) 2007 Pascal Terjan <pterjan@linuxfr.org>
    44 *
     
    1111
    1212#include <ruby.h>
    13 #include <cucul.h>
     13#include <caca.h>
    1414#include <errno.h>
    15 #include "cucul-dither.h"
    16 #include "cucul-font.h"
     15#include "caca-dither.h"
     16#include "caca-font.h"
    1717#include "common.h"
    1818
     
    2222static VALUE x (VALUE self)                             \
    2323{                                                       \
    24     if( cucul_##x (_SELF) <0)                           \
     24    if( caca_##x (_SELF) <0)                           \
    2525        rb_raise(rb_eRuntimeError, strerror(errno));    \
    2626                                                        \
     
    3131static VALUE get_##x (VALUE self)                       \
    3232{                                                       \
    33     return INT2NUM(cucul_get_##x (_SELF));              \
     33    return INT2NUM(caca_get_##x (_SELF));              \
    3434}
    3535
    3636static void canvas_free(void * p)
    3737{
    38     cucul_free_canvas((cucul_canvas_t *)p);
     38    caca_free_canvas((caca_canvas_t *)p);
    3939}
    4040
     
    4646}
    4747
    48 VALUE canvas_create(cucul_canvas_t *canvas)
     48VALUE canvas_create(caca_canvas_t *canvas)
    4949{
    5050    return Data_Wrap_Struct(cCanvas, NULL, NULL, canvas);
     
    5353static VALUE canvas_initialize(VALUE self, VALUE width, VALUE height)
    5454{
    55     cucul_canvas_t *canvas;
    56 
    57     canvas = cucul_create_canvas(NUM2INT(width), NUM2INT(height));
     55    caca_canvas_t *canvas;
     56
     57    canvas = caca_create_canvas(NUM2INT(width), NUM2INT(height));
    5858
    5959    if(canvas == NULL)
     
    7272static VALUE set_canvas_width(VALUE self, VALUE width)
    7373{
    74     cucul_set_canvas_size(_SELF, NUM2INT(width), cucul_get_canvas_height(_SELF));
     74    caca_set_canvas_size(_SELF, NUM2INT(width), caca_get_canvas_height(_SELF));
    7575    return width;
    7676}
     
    8484static VALUE set_canvas_height(VALUE self, VALUE height)
    8585{
    86     cucul_set_canvas_size(_SELF, cucul_get_canvas_width(_SELF), NUM2INT(height));
     86    caca_set_canvas_size(_SELF, caca_get_canvas_width(_SELF), NUM2INT(height));
    8787    return height;
    8888}
     
    9696static VALUE set_canvas_size(VALUE self, VALUE height, VALUE width)
    9797{
    98     cucul_set_canvas_size(_SELF, NUM2INT(width), NUM2INT(height));
     98    caca_set_canvas_size(_SELF, NUM2INT(width), NUM2INT(height));
    9999    return self;
    100100}
     
    104104static VALUE gotoxy(VALUE self, VALUE x, VALUE y)
    105105{
    106     if( cucul_gotoxy(_SELF, NUM2INT(x), NUM2INT(y)) <0) {
     106    if( caca_gotoxy(_SELF, NUM2INT(x), NUM2INT(y)) <0) {
    107107        rb_raise(rb_eRuntimeError, strerror(errno));
    108108    }
     
    117117static VALUE put_char(VALUE self, VALUE x, VALUE y, VALUE ch)
    118118{
    119     cucul_put_char(_SELF, NUM2INT(x), NUM2INT(y), NUM2ULONG(ch));
     119    caca_put_char(_SELF, NUM2INT(x), NUM2INT(y), NUM2ULONG(ch));
    120120    return self;
    121121}
     
    124124{
    125125    unsigned long int ch;
    126     ch = cucul_get_char(_SELF, NUM2INT(x), NUM2INT(y));
     126    ch = caca_get_char(_SELF, NUM2INT(x), NUM2INT(y));
    127127    return INT2NUM(ch);
    128128}
     
    130130static VALUE put_str(VALUE self, VALUE x, VALUE y, VALUE str)
    131131{
    132     cucul_put_str(_SELF, NUM2INT(x), NUM2INT(y), StringValuePtr(str));
     132    caca_put_str(_SELF, NUM2INT(x), NUM2INT(y), StringValuePtr(str));
    133133    return self;
    134134}
     
    137137{
    138138    unsigned long int ch;
    139     ch = cucul_get_attr(_SELF, NUM2INT(x), NUM2INT(y));
     139    ch = caca_get_attr(_SELF, NUM2INT(x), NUM2INT(y));
    140140    return INT2NUM(ch);
    141141}
     
    143143static VALUE set_attr(VALUE self, VALUE attr)
    144144{
    145     if(cucul_set_attr(_SELF, NUM2ULONG(attr)) <0)
     145    if(caca_set_attr(_SELF, NUM2ULONG(attr)) <0)
    146146        rb_raise(rb_eRuntimeError, strerror(errno));
    147147
     
    157157static VALUE put_attr(VALUE self, VALUE x, VALUE y, VALUE attr)
    158158{
    159     if(cucul_put_attr(_SELF, NUM2INT(x), NUM2INT(y), NUM2ULONG(attr)) <0)
     159    if(caca_put_attr(_SELF, NUM2INT(x), NUM2INT(y), NUM2ULONG(attr)) <0)
    160160        rb_raise(rb_eRuntimeError, strerror(errno));
    161161
     
    165165static VALUE set_color_ansi(VALUE self, VALUE fg, VALUE bg)
    166166{
    167     if(cucul_set_color_ansi(_SELF, NUM2INT(fg), NUM2INT(bg)) <0)
     167    if(caca_set_color_ansi(_SELF, NUM2INT(fg), NUM2INT(bg)) <0)
    168168        rb_raise(rb_eRuntimeError, strerror(errno));
    169169
     
    173173static VALUE set_color_argb(VALUE self, VALUE fg, VALUE bg)
    174174{
    175     if(cucul_set_color_argb(_SELF, NUM2UINT(fg), NUM2UINT(bg)) <0) {
     175    if(caca_set_color_argb(_SELF, NUM2UINT(fg), NUM2UINT(bg)) <0) {
    176176        rb_raise(rb_eRuntimeError, strerror(errno));
    177177    }
     
    187187    y = NUM2INT(ry);
    188188    string = rb_funcall2(rb_mKernel, rb_intern("sprintf"), argc-2, argv+2);
    189     cucul_put_str(_SELF, x, y, StringValuePtr(string));
     189    caca_put_str(_SELF, x, y, StringValuePtr(string));
    190190    return self;
    191191}
     
    197197static VALUE set_canvas_handle(VALUE self, VALUE x, VALUE y)
    198198{
    199     cucul_set_canvas_handle(_SELF, NUM2INT(x), NUM2INT(y));
     199    caca_set_canvas_handle(_SELF, NUM2INT(x), NUM2INT(y));
    200200    return self;
    201201}
     
    203203static VALUE blit(int argc, VALUE* argv, VALUE self) {
    204204    VALUE x, y, src, mask;
    205     cucul_canvas_t *csrc, *cmask;
     205    caca_canvas_t *csrc, *cmask;
    206206
    207207    rb_scan_args(argc, argv, "31", &x, &y, &src, &mask);
     
    214214        rb_raise(rb_eArgError, "src is not a Cucul::Canvas");
    215215    }
    216     Data_Get_Struct(src, cucul_canvas_t, csrc);
     216    Data_Get_Struct(src, caca_canvas_t, csrc);
    217217
    218218    if(!NIL_P(mask))
     
    222222            rb_raise(rb_eArgError, "mask is not a Cucul::Canvas");
    223223        }
    224         Data_Get_Struct(mask, cucul_canvas_t, cmask);
     224        Data_Get_Struct(mask, caca_canvas_t, cmask);
    225225    }
    226226    else
    227227        cmask = NULL;
    228228   
    229     if(cucul_blit(_SELF, NUM2INT(x), NUM2INT(y), csrc, cmask)<0)
     229    if(caca_blit(_SELF, NUM2INT(x), NUM2INT(y), csrc, cmask)<0)
    230230        rb_raise(rb_eRuntimeError, strerror(errno));
    231231
     
    235235static VALUE set_canvas_boundaries(VALUE self, VALUE x, VALUE y, VALUE w, VALUE h)
    236236{
    237     if(cucul_set_canvas_boundaries(_SELF, NUM2INT(x), NUM2INT(y), NUM2UINT(w), NUM2UINT(h))<0)
     237    if(caca_set_canvas_boundaries(_SELF, NUM2INT(x), NUM2INT(y), NUM2UINT(w), NUM2UINT(h))<0)
    238238    {
    239239        rb_raise(rb_eRuntimeError, strerror(errno));
     
    257257static VALUE draw_line(VALUE self, VALUE x1, VALUE y1, VALUE x2, VALUE y2, VALUE ch)
    258258{
    259     cucul_draw_line(_SELF, NUM2INT(x1), NUM2INT(y1), NUM2INT(x2), NUM2INT(y2),NUM2ULONG(ch));
     259    caca_draw_line(_SELF, NUM2INT(x1), NUM2INT(y1), NUM2INT(x2), NUM2INT(y2),NUM2ULONG(ch));
    260260    return self;
    261261}
     
    309309    n--;
    310310
    311     cucul_draw_polyline(_SELF, ax, ay, n, NUM2ULONG(ch));
     311    caca_draw_polyline(_SELF, ax, ay, n, NUM2ULONG(ch));
    312312
    313313    free(ax);
     
    319319static VALUE draw_thin_line(VALUE self, VALUE x1, VALUE y1, VALUE x2, VALUE y2)
    320320{
    321     cucul_draw_thin_line(_SELF, NUM2INT(x1), NUM2INT(y1), NUM2INT(x2), NUM2INT(y2));
     321    caca_draw_thin_line(_SELF, NUM2INT(x1), NUM2INT(y1), NUM2INT(x2), NUM2INT(y2));
    322322    return self;
    323323}
     
    371371    n--;
    372372
    373     cucul_draw_thin_polyline(_SELF, ax, ay, n);
     373    caca_draw_thin_polyline(_SELF, ax, ay, n);
    374374
    375375    free(ax);
     
    381381static VALUE draw_circle(VALUE self, VALUE x, VALUE y, VALUE r, VALUE ch)
    382382{
    383     cucul_draw_circle(_SELF, NUM2INT(x), NUM2INT(y), NUM2INT(r), NUM2ULONG(ch));
     383    caca_draw_circle(_SELF, NUM2INT(x), NUM2INT(y), NUM2INT(r), NUM2ULONG(ch));
    384384    return self;
    385385}
     
    387387static VALUE draw_ellipse(VALUE self, VALUE x, VALUE y, VALUE a, VALUE b, VALUE ch)
    388388{
    389     cucul_draw_ellipse(_SELF, NUM2INT(x), NUM2INT(y), NUM2INT(a), NUM2INT(b), NUM2ULONG(ch));
     389    caca_draw_ellipse(_SELF, NUM2INT(x), NUM2INT(y), NUM2INT(a), NUM2INT(b), NUM2ULONG(ch));
    390390    return self;
    391391}
     
    393393static VALUE draw_thin_ellipse(VALUE self, VALUE x, VALUE y, VALUE a, VALUE b)
    394394{
    395     cucul_draw_thin_ellipse(_SELF, NUM2INT(x), NUM2INT(y), NUM2INT(a), NUM2INT(b));
     395    caca_draw_thin_ellipse(_SELF, NUM2INT(x), NUM2INT(y), NUM2INT(a), NUM2INT(b));
    396396    return self;
    397397}
     
    399399static VALUE fill_ellipse(VALUE self, VALUE x, VALUE y, VALUE a, VALUE b, VALUE ch)
    400400{
    401     cucul_fill_ellipse(_SELF, NUM2INT(x), NUM2INT(y), NUM2INT(a), NUM2INT(b), NUM2ULONG(ch));
     401    caca_fill_ellipse(_SELF, NUM2INT(x), NUM2INT(y), NUM2INT(a), NUM2INT(b), NUM2ULONG(ch));
    402402    return self;
    403403}
     
    405405static VALUE draw_box(VALUE self, VALUE x, VALUE y, VALUE w, VALUE h, VALUE ch)
    406406{
    407     cucul_draw_box(_SELF, NUM2INT(x), NUM2INT(y), NUM2INT(w), NUM2INT(h), NUM2ULONG(ch));
     407    caca_draw_box(_SELF, NUM2INT(x), NUM2INT(y), NUM2INT(w), NUM2INT(h), NUM2ULONG(ch));
    408408    return self;
    409409}
     
    411411static VALUE draw_thin_box(VALUE self, VALUE x, VALUE y, VALUE w, VALUE h)
    412412{
    413     cucul_draw_thin_box(_SELF, NUM2INT(x), NUM2INT(y), NUM2INT(w), NUM2INT(h));
     413    caca_draw_thin_box(_SELF, NUM2INT(x), NUM2INT(y), NUM2INT(w), NUM2INT(h));
    414414    return self;
    415415}
     
    417417static VALUE draw_cp437_box(VALUE self, VALUE x, VALUE y, VALUE w, VALUE h)
    418418{
    419     cucul_draw_cp437_box(_SELF, NUM2INT(x), NUM2INT(y), NUM2INT(w), NUM2INT(h));
     419    caca_draw_cp437_box(_SELF, NUM2INT(x), NUM2INT(y), NUM2INT(w), NUM2INT(h));
    420420    return self;
    421421}
     
    423423static VALUE fill_box(VALUE self, VALUE x, VALUE y, VALUE w, VALUE h, VALUE ch)
    424424{
    425     cucul_fill_box(_SELF, NUM2INT(x), NUM2INT(y), NUM2INT(w), NUM2INT(h), NUM2ULONG(ch));
     425    caca_fill_box(_SELF, NUM2INT(x), NUM2INT(y), NUM2INT(w), NUM2INT(h), NUM2ULONG(ch));
    426426    return self;
    427427}
     
    429429static VALUE draw_triangle(VALUE self, VALUE x1, VALUE y1, VALUE x2, VALUE y2, VALUE x3, VALUE y3, VALUE ch)
    430430{
    431     cucul_draw_triangle(_SELF, NUM2INT(x1), NUM2INT(y1), NUM2INT(x2), NUM2INT(y2),  NUM2INT(x3), NUM2INT(y3), NUM2ULONG(ch));
     431    caca_draw_triangle(_SELF, NUM2INT(x1), NUM2INT(y1), NUM2INT(x2), NUM2INT(y2),  NUM2INT(x3), NUM2INT(y3), NUM2ULONG(ch));
    432432    return self;
    433433}
     
    435435static VALUE draw_thin_triangle(VALUE self, VALUE x1, VALUE y1, VALUE x2, VALUE y2, VALUE x3, VALUE y3)
    436436{
    437     cucul_draw_thin_triangle(_SELF, NUM2INT(x1), NUM2INT(y1), NUM2INT(x2), NUM2INT(y2),  NUM2INT(x3), NUM2INT(y3));
     437    caca_draw_thin_triangle(_SELF, NUM2INT(x1), NUM2INT(y1), NUM2INT(x2), NUM2INT(y2),  NUM2INT(x3), NUM2INT(y3));
    438438    return self;
    439439}
     
    441441static VALUE fill_triangle(VALUE self, VALUE x1, VALUE y1, VALUE x2, VALUE y2, VALUE x3, VALUE y3, VALUE ch)
    442442{
    443     cucul_fill_triangle(_SELF, NUM2INT(x1), NUM2INT(y1), NUM2INT(x2), NUM2INT(y2),  NUM2INT(x3), NUM2INT(y3), NUM2ULONG(ch));
     443    caca_fill_triangle(_SELF, NUM2INT(x1), NUM2INT(y1), NUM2INT(x2), NUM2INT(y2),  NUM2INT(x3), NUM2INT(y3), NUM2ULONG(ch));
    444444    return self;
    445445}
     
    451451    Check_Type(pixels, T_STRING);
    452452
    453     cucul_dither_bitmap(_SELF, NUM2INT(x), NUM2INT(y), NUM2INT(w), NUM2INT(h), DATA_PTR(d), StringValuePtr(pixels));
     453    caca_dither_bitmap(_SELF, NUM2INT(x), NUM2INT(y), NUM2INT(w), NUM2INT(h), DATA_PTR(d), StringValuePtr(pixels));
    454454    return self;
    455455}
     
    461461static VALUE set_frame(VALUE self, VALUE id)
    462462{
    463     if(cucul_set_frame(_SELF, NUM2INT(id))<0)
     463    if(caca_set_frame(_SELF, NUM2INT(id))<0)
    464464        rb_raise(rb_eArgError, strerror(errno));
    465465
     
    475475static VALUE get_frame_name(VALUE self)
    476476{
    477     return rb_str_new2(cucul_get_frame_name(_SELF));
     477    return rb_str_new2(caca_get_frame_name(_SELF));
    478478}
    479479
    480480static VALUE set_frame_name(VALUE self, VALUE name)
    481481{
    482     if(cucul_set_frame_name(_SELF, StringValuePtr(name))<0)
     482    if(caca_set_frame_name(_SELF, StringValuePtr(name))<0)
    483483        rb_raise(rb_eRuntimeError, strerror(errno));
    484484
     
    494494static VALUE create_frame(VALUE self, VALUE id)
    495495{
    496     if(cucul_create_frame(_SELF, NUM2INT(id))<0) {
     496    if(caca_create_frame(_SELF, NUM2INT(id))<0) {
    497497        rb_raise(rb_eRuntimeError, strerror(errno));
    498498    }
     
    502502static VALUE free_frame(VALUE self, VALUE id)
    503503{
    504     if(cucul_free_frame(_SELF, NUM2INT(id))<0) {
     504    if(caca_free_frame(_SELF, NUM2INT(id))<0) {
    505505        rb_raise(rb_eArgError, strerror(errno));
    506506    }
     
    513513{
    514514    void *buf;
    515     cucul_font_t *f;
     515    caca_font_t *f;
    516516    VALUE b;
    517517
     
    528528
    529529    f = DATA_PTR(font);
    530     cucul_render_canvas(_SELF, f, buf, NUM2UINT(width), NUM2UINT(height), NUM2UINT(pitch));
     530    caca_render_canvas(_SELF, f, buf, NUM2UINT(width), NUM2UINT(height), NUM2UINT(pitch));
    531531
    532532    b = rb_str_new(buf, width*height*4);
     
    538538{
    539539    long int bytes;
    540     bytes = cucul_import_memory (_SELF, StringValuePtr(data), RSTRING(StringValue(data))->len, StringValuePtr(format));
     540    bytes = caca_import_memory (_SELF, StringValuePtr(data), RSTRING(StringValue(data))->len, StringValuePtr(format));
    541541    if(bytes <= 0)
    542542        rb_raise(rb_eRuntimeError, strerror(errno));
     
    548548{
    549549    long int bytes;
    550     bytes = cucul_import_file (_SELF, StringValuePtr(filename), StringValuePtr(format));
     550    bytes = caca_import_file (_SELF, StringValuePtr(filename), StringValuePtr(format));
    551551    if(bytes <= 0)
    552552        rb_raise(rb_eRuntimeError, strerror(errno));
     
    560560    void *result;
    561561    VALUE ret;
    562     result = cucul_export_memory (_SELF, StringValuePtr(format), &bytes);
     562    result = caca_export_memory (_SELF, StringValuePtr(format), &bytes);
    563563    ret = rb_str_new(result, bytes);
    564564    free(result);
     
    571571/****/
    572572
    573 void Init_cucul_canvas(VALUE mCucul)
     573void Init_caca_canvas(VALUE mCucul)
    574574{
    575575    cCanvas = rb_define_class_under(mCucul, "Canvas", rb_cObject);
Note: See TracChangeset for help on using the changeset viewer.