kaka 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +66 -0
- data/ext/caca/caca-canvas.c +806 -0
- data/ext/caca/caca-canvas.h +22 -0
- data/ext/caca/caca-display.c +307 -0
- data/ext/caca/caca-display.h +21 -0
- data/ext/caca/caca-dither.c +209 -0
- data/ext/caca/caca-dither.h +21 -0
- data/ext/caca/caca-event.c +73 -0
- data/ext/caca/caca-event.h +29 -0
- data/ext/caca/caca-font.c +99 -0
- data/ext/caca/caca-font.h +21 -0
- data/ext/caca/caca.c +62 -0
- data/ext/caca/common.h +60 -0
- data/ext/caca/extconf.rb +43 -0
- data/lib/caca.rb +43 -0
- data/lib/caca/version.rb +3 -0
- data/test/canvas_test.rb +61 -0
- data/test/display_test.rb +35 -0
- data/test/dither_test.rb +41 -0
- data/test/font_test.rb +22 -0
- data/test/frame_test.rb +20 -0
- metadata +74 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
/*
|
2
|
+
* libcaca Ruby bindings
|
3
|
+
* Copyright (c) 2007-2010 Pascal Terjan <pterjan@linuxfr.org>
|
4
|
+
* 2012 Sam Hocevar <sam@hocevar.net>
|
5
|
+
*
|
6
|
+
* This library 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
|
+
#ifndef __CACA_CANVAS_H__
|
14
|
+
#define __CACA_CANVAS_H__
|
15
|
+
|
16
|
+
#include <ruby.h>
|
17
|
+
|
18
|
+
extern VALUE cCanvas;
|
19
|
+
extern void Init_caca_canvas(VALUE);
|
20
|
+
extern VALUE canvas_create(caca_canvas_t *canvas);
|
21
|
+
|
22
|
+
#endif
|
@@ -0,0 +1,307 @@
|
|
1
|
+
/*
|
2
|
+
* libcaca Ruby bindings
|
3
|
+
* Copyright (c) 2007-2012 Pascal Terjan <pterjan@linuxfr.org>
|
4
|
+
*
|
5
|
+
* This library is free software. It comes without any warranty, to
|
6
|
+
* the extent permitted by applicable law. You can redistribute it
|
7
|
+
* and/or modify it under the terms of the Do What the Fuck You Want
|
8
|
+
* to Public License, Version 2, as published by Sam Hocevar. See
|
9
|
+
* http://www.wtfpl.net/ for more details.
|
10
|
+
*/
|
11
|
+
|
12
|
+
#include <ruby.h>
|
13
|
+
#include <caca.h>
|
14
|
+
#include <errno.h>
|
15
|
+
#include "caca-event.h"
|
16
|
+
#include "caca-canvas.h"
|
17
|
+
#include "common.h"
|
18
|
+
|
19
|
+
VALUE cDisplay;
|
20
|
+
|
21
|
+
void display_free(void *display)
|
22
|
+
{
|
23
|
+
caca_free_display((caca_display_t *)display);
|
24
|
+
}
|
25
|
+
|
26
|
+
static VALUE display_alloc(VALUE klass)
|
27
|
+
{
|
28
|
+
VALUE obj;
|
29
|
+
obj = Data_Wrap_Struct(klass, 0, display_free, NULL);
|
30
|
+
return obj;
|
31
|
+
}
|
32
|
+
|
33
|
+
static VALUE display_initialize(int argc, VALUE* argv, VALUE self)
|
34
|
+
{
|
35
|
+
caca_display_t *display;
|
36
|
+
caca_canvas_t *canvas = NULL;
|
37
|
+
const char *driver = NULL;
|
38
|
+
VALUE cv = Qnil;
|
39
|
+
VALUE arg1, arg2;
|
40
|
+
|
41
|
+
rb_scan_args(argc, argv, "02", &arg1, &arg2);
|
42
|
+
|
43
|
+
if(CLASS_OF(arg1) == cCanvas)
|
44
|
+
{
|
45
|
+
cv = arg1;
|
46
|
+
if(CLASS_OF(arg2) == cCanvas)
|
47
|
+
{
|
48
|
+
rb_raise(rb_eArgError, "Only one argument can be a Caca::Canvas");
|
49
|
+
}
|
50
|
+
}
|
51
|
+
else if(CLASS_OF(arg2) == cCanvas)
|
52
|
+
{
|
53
|
+
cv = arg2;
|
54
|
+
}
|
55
|
+
|
56
|
+
if(TYPE(arg1) == T_STRING)
|
57
|
+
{
|
58
|
+
driver = StringValuePtr(arg1);
|
59
|
+
if(TYPE(arg2) == T_STRING)
|
60
|
+
{
|
61
|
+
rb_raise(rb_eArgError, "Only one argument can be a string");
|
62
|
+
}
|
63
|
+
}
|
64
|
+
else if(TYPE(arg2) == T_STRING)
|
65
|
+
{
|
66
|
+
driver = StringValuePtr(arg2);
|
67
|
+
}
|
68
|
+
|
69
|
+
if(cv != Qnil)
|
70
|
+
canvas = DATA_PTR(cv);
|
71
|
+
|
72
|
+
if(driver == NULL)
|
73
|
+
{
|
74
|
+
display = caca_create_display(canvas);
|
75
|
+
if(display && NIL_P(cv))
|
76
|
+
{
|
77
|
+
cv = canvas_create(caca_get_canvas(display));
|
78
|
+
}
|
79
|
+
}
|
80
|
+
else
|
81
|
+
{
|
82
|
+
display = caca_create_display_with_driver(canvas, driver);
|
83
|
+
}
|
84
|
+
|
85
|
+
if(display == NULL)
|
86
|
+
{
|
87
|
+
rb_raise(rb_eRuntimeError, "%s", strerror(errno));
|
88
|
+
}
|
89
|
+
|
90
|
+
_SELF = display;
|
91
|
+
|
92
|
+
rb_iv_set(self, "@canvas", cv);
|
93
|
+
|
94
|
+
return self;
|
95
|
+
}
|
96
|
+
|
97
|
+
static VALUE display_refresh(VALUE self)
|
98
|
+
{
|
99
|
+
caca_refresh_display(_SELF);
|
100
|
+
return self;
|
101
|
+
}
|
102
|
+
|
103
|
+
static VALUE set_time(VALUE self, VALUE t)
|
104
|
+
{
|
105
|
+
caca_set_display_time(_SELF, UINT2NUM(t));
|
106
|
+
return t;
|
107
|
+
}
|
108
|
+
|
109
|
+
static VALUE set_time2(VALUE self, VALUE t)
|
110
|
+
{
|
111
|
+
set_time(self, t);
|
112
|
+
return self;
|
113
|
+
}
|
114
|
+
|
115
|
+
static VALUE get_time(VALUE self)
|
116
|
+
{
|
117
|
+
return NUM2UINT(caca_get_display_time(_SELF));
|
118
|
+
}
|
119
|
+
|
120
|
+
static VALUE get_width(VALUE self)
|
121
|
+
{
|
122
|
+
return NUM2UINT(caca_get_display_width(_SELF));
|
123
|
+
}
|
124
|
+
|
125
|
+
static VALUE get_height(VALUE self)
|
126
|
+
{
|
127
|
+
return NUM2UINT(caca_get_display_height(_SELF));
|
128
|
+
}
|
129
|
+
|
130
|
+
static VALUE set_title(VALUE self, VALUE t)
|
131
|
+
{
|
132
|
+
if(caca_set_display_title(_SELF, StringValuePtr(t))<0)
|
133
|
+
{
|
134
|
+
rb_raise(rb_eRuntimeError, "%s", strerror(errno));
|
135
|
+
}
|
136
|
+
return t;
|
137
|
+
}
|
138
|
+
|
139
|
+
static VALUE set_title2(VALUE self, VALUE t)
|
140
|
+
{
|
141
|
+
set_title(self, t);
|
142
|
+
return self;
|
143
|
+
}
|
144
|
+
|
145
|
+
static VALUE get_mouse_x(VALUE self)
|
146
|
+
{
|
147
|
+
return NUM2UINT(caca_get_mouse_x(_SELF));
|
148
|
+
}
|
149
|
+
|
150
|
+
static VALUE get_mouse_y(VALUE self)
|
151
|
+
{
|
152
|
+
return NUM2UINT(caca_get_mouse_y(_SELF));
|
153
|
+
}
|
154
|
+
|
155
|
+
static VALUE set_mouse(VALUE self, VALUE visible)
|
156
|
+
{
|
157
|
+
caca_set_display_time(_SELF, visible);
|
158
|
+
return visible;
|
159
|
+
}
|
160
|
+
|
161
|
+
static VALUE set_mouse2(VALUE self, VALUE visible)
|
162
|
+
{
|
163
|
+
set_mouse(self, visible);
|
164
|
+
return self;
|
165
|
+
}
|
166
|
+
|
167
|
+
static VALUE get_event(VALUE self, VALUE event_mask, VALUE timeout)
|
168
|
+
{
|
169
|
+
char utf8[8];
|
170
|
+
caca_event_t ev;
|
171
|
+
VALUE e;
|
172
|
+
|
173
|
+
event_mask = rb_funcall(event_mask, rb_intern("to_i"), 0);
|
174
|
+
|
175
|
+
if(caca_get_event(_SELF, NUM2UINT(event_mask), &ev, NUM2INT(timeout)) == 0)
|
176
|
+
{
|
177
|
+
return Qnil;
|
178
|
+
}
|
179
|
+
|
180
|
+
switch(caca_get_event_type(&ev))
|
181
|
+
{
|
182
|
+
case CACA_EVENT_KEY_PRESS:
|
183
|
+
caca_get_event_key_utf8(&ev, utf8);
|
184
|
+
e = rb_funcall(cEventKeyPress, rb_intern("new"), 3,
|
185
|
+
UINT2NUM(caca_get_event_key_ch(&ev)),
|
186
|
+
ULONG2NUM(caca_get_event_key_utf32(&ev)),
|
187
|
+
rb_str_new(utf8, 8));
|
188
|
+
break;
|
189
|
+
case CACA_EVENT_KEY_RELEASE:
|
190
|
+
caca_get_event_key_utf8(&ev, utf8);
|
191
|
+
e = rb_funcall(cEventKeyRelease, rb_intern("new"), 3,
|
192
|
+
UINT2NUM(caca_get_event_key_ch(&ev)),
|
193
|
+
ULONG2NUM(caca_get_event_key_utf32(&ev)),
|
194
|
+
rb_str_new(utf8, 8));
|
195
|
+
break;
|
196
|
+
case CACA_EVENT_MOUSE_PRESS:
|
197
|
+
e = rb_funcall(cEventMousePress, rb_intern("new"), 3,
|
198
|
+
UINT2NUM(caca_get_event_mouse_x(&ev)),
|
199
|
+
UINT2NUM(caca_get_event_mouse_y(&ev)),
|
200
|
+
UINT2NUM(caca_get_event_mouse_button(&ev)));
|
201
|
+
break;
|
202
|
+
case CACA_EVENT_MOUSE_RELEASE:
|
203
|
+
e = rb_funcall(cEventMouseRelease, rb_intern("new"), 3,
|
204
|
+
UINT2NUM(caca_get_event_mouse_x(&ev)),
|
205
|
+
UINT2NUM(caca_get_event_mouse_y(&ev)),
|
206
|
+
UINT2NUM(caca_get_event_mouse_button(&ev)));
|
207
|
+
break;
|
208
|
+
case CACA_EVENT_MOUSE_MOTION:
|
209
|
+
e = rb_funcall(cEventMouseMotion, rb_intern("new"), 3,
|
210
|
+
UINT2NUM(caca_get_event_mouse_x(&ev)),
|
211
|
+
UINT2NUM(caca_get_event_mouse_y(&ev)),
|
212
|
+
Qnil);
|
213
|
+
break;
|
214
|
+
case CACA_EVENT_RESIZE:
|
215
|
+
e = rb_funcall(cEventResize, rb_intern("new"), 2,
|
216
|
+
UINT2NUM(caca_get_event_resize_width(&ev)),
|
217
|
+
UINT2NUM(caca_get_event_resize_height(&ev)));
|
218
|
+
break;
|
219
|
+
case CACA_EVENT_QUIT:
|
220
|
+
e = rb_funcall(cEventQuit, rb_intern("new"), 0);
|
221
|
+
break;
|
222
|
+
default:
|
223
|
+
rb_raise(rb_eRuntimeError, "Invalid event received !");
|
224
|
+
}
|
225
|
+
|
226
|
+
return e;
|
227
|
+
}
|
228
|
+
|
229
|
+
static VALUE driver_list(void)
|
230
|
+
{
|
231
|
+
VALUE ary;
|
232
|
+
char const* const* list;
|
233
|
+
|
234
|
+
list = caca_get_display_driver_list();
|
235
|
+
|
236
|
+
ary = rb_hash_new();
|
237
|
+
while (*list != NULL && *(list+1) != NULL)
|
238
|
+
{
|
239
|
+
rb_hash_aset(ary, rb_str_new2(*list), rb_str_new2(*(list+1)));
|
240
|
+
list+=2;
|
241
|
+
}
|
242
|
+
|
243
|
+
return ary;
|
244
|
+
}
|
245
|
+
|
246
|
+
static VALUE get_driver(VALUE self)
|
247
|
+
{
|
248
|
+
return rb_str_new2(caca_get_display_driver(_SELF));
|
249
|
+
}
|
250
|
+
|
251
|
+
static VALUE set_driver(VALUE self, VALUE driver)
|
252
|
+
{
|
253
|
+
if(caca_set_display_driver(_SELF, StringValuePtr(driver))<0)
|
254
|
+
{
|
255
|
+
rb_raise(rb_eRuntimeError, "%s", strerror(errno));
|
256
|
+
}
|
257
|
+
return driver;
|
258
|
+
}
|
259
|
+
|
260
|
+
static VALUE set_driver2(VALUE self, VALUE driver)
|
261
|
+
{
|
262
|
+
set_driver(self, driver);
|
263
|
+
return self;
|
264
|
+
}
|
265
|
+
|
266
|
+
static VALUE set_cursor(VALUE self, VALUE flag)
|
267
|
+
{
|
268
|
+
if(caca_set_cursor(_SELF, flag)<0)
|
269
|
+
{
|
270
|
+
rb_raise(rb_eRuntimeError, "%s", strerror(errno));
|
271
|
+
}
|
272
|
+
return flag;
|
273
|
+
}
|
274
|
+
|
275
|
+
static VALUE set_cursor2(VALUE self, VALUE flag)
|
276
|
+
{
|
277
|
+
set_cursor(self, flag);
|
278
|
+
return self;
|
279
|
+
}
|
280
|
+
|
281
|
+
void Init_caca_display(VALUE mCaca)
|
282
|
+
{
|
283
|
+
cDisplay = rb_define_class_under(mCaca, "Display", rb_cObject);
|
284
|
+
rb_define_alloc_func(cDisplay, display_alloc);
|
285
|
+
|
286
|
+
rb_define_singleton_method(cDisplay, "driver_list", driver_list, 0);
|
287
|
+
|
288
|
+
rb_define_method(cDisplay, "initialize", display_initialize, -1);
|
289
|
+
rb_define_method(cDisplay, "refresh", display_refresh, 0);
|
290
|
+
rb_define_method(cDisplay, "time=", set_time, 1);
|
291
|
+
rb_define_method(cDisplay, "set_time", set_time2, 1);
|
292
|
+
rb_define_method(cDisplay, "time", get_time, 0);
|
293
|
+
rb_define_method(cDisplay, "width", get_width, 0);
|
294
|
+
rb_define_method(cDisplay, "height", get_height, 0);
|
295
|
+
rb_define_method(cDisplay, "title=", set_title, 1);
|
296
|
+
rb_define_method(cDisplay, "set_title", set_title2, 1);
|
297
|
+
rb_define_method(cDisplay, "mouse_x", get_mouse_x, 0);
|
298
|
+
rb_define_method(cDisplay, "mouse_y", get_mouse_y, 0);
|
299
|
+
rb_define_method(cDisplay, "mouse=", set_mouse, 1);
|
300
|
+
rb_define_method(cDisplay, "driver", get_driver, 0);
|
301
|
+
rb_define_method(cDisplay, "set_driver", set_driver2, 1);
|
302
|
+
rb_define_method(cDisplay, "driver=", set_driver, 1);
|
303
|
+
rb_define_method(cDisplay, "set_mouse", set_mouse2, 1);
|
304
|
+
rb_define_method(cDisplay, "get_event", get_event, 2);
|
305
|
+
rb_define_method(cDisplay, "cursor=", set_cursor, 1);
|
306
|
+
rb_define_method(cDisplay, "set_cursor", set_cursor2, 1);
|
307
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
/*
|
2
|
+
* libcaca Ruby bindings
|
3
|
+
* Copyright (c) 2007-2010 Pascal Terjan <pterjan@linuxfr.org>
|
4
|
+
* 2012 Sam Hocevar <sam@hocevar.net>
|
5
|
+
*
|
6
|
+
* This library 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
|
+
#ifndef __CACA_DISPLAY_H__
|
14
|
+
#define __CACA_DISPLAY_H__
|
15
|
+
|
16
|
+
#include <ruby.h>
|
17
|
+
|
18
|
+
extern VALUE cDisplay;
|
19
|
+
extern void Init_caca_display(VALUE);
|
20
|
+
|
21
|
+
#endif
|
@@ -0,0 +1,209 @@
|
|
1
|
+
/*
|
2
|
+
* libcaca Ruby bindings
|
3
|
+
* Copyright (c) 2007-2012 Pascal Terjan <pterjan@linuxfr.org>
|
4
|
+
*
|
5
|
+
* This library is free software. It comes without any warranty, to
|
6
|
+
* the extent permitted by applicable law. You can redistribute it
|
7
|
+
* and/or modify it under the terms of the Do What the Fuck You Want
|
8
|
+
* to Public License, Version 2, as published by Sam Hocevar. See
|
9
|
+
* http://www.wtfpl.net/ for more details.
|
10
|
+
*/
|
11
|
+
|
12
|
+
#include <ruby.h>
|
13
|
+
#include <caca.h>
|
14
|
+
#include <errno.h>
|
15
|
+
#include "common.h"
|
16
|
+
|
17
|
+
VALUE cDither;
|
18
|
+
|
19
|
+
void dither_free(void *dither)
|
20
|
+
{
|
21
|
+
caca_free_dither((caca_dither_t *)dither);
|
22
|
+
}
|
23
|
+
|
24
|
+
static VALUE dither_alloc(VALUE klass)
|
25
|
+
{
|
26
|
+
VALUE obj;
|
27
|
+
obj = Data_Wrap_Struct(klass, 0, dither_free, NULL);
|
28
|
+
return obj;
|
29
|
+
}
|
30
|
+
|
31
|
+
static VALUE dither_initialize(VALUE self, VALUE bpp, VALUE w, VALUE h, VALUE pitch, VALUE rmask, VALUE gmask, VALUE bmask, VALUE amask)
|
32
|
+
{
|
33
|
+
caca_dither_t *dither;
|
34
|
+
|
35
|
+
dither = caca_create_dither(NUM2UINT(bpp), NUM2UINT(w), NUM2UINT(h), NUM2UINT(pitch), NUM2ULONG(rmask), NUM2ULONG(gmask), NUM2ULONG(bmask), NUM2ULONG(amask));
|
36
|
+
if(dither == NULL)
|
37
|
+
{
|
38
|
+
rb_raise(rb_eRuntimeError, "%s", strerror(errno));
|
39
|
+
}
|
40
|
+
_SELF = dither;
|
41
|
+
return self;
|
42
|
+
}
|
43
|
+
|
44
|
+
static VALUE set_dither_palette(VALUE self, VALUE palette)
|
45
|
+
{
|
46
|
+
int i;
|
47
|
+
unsigned int *red, *blue, *green, *alpha;
|
48
|
+
VALUE v, r, g, b, a;
|
49
|
+
int error = 0;
|
50
|
+
|
51
|
+
if(RARRAY_LEN(palette) != 256)
|
52
|
+
{
|
53
|
+
rb_raise(rb_eArgError, "Palette must contain 256 elements");
|
54
|
+
}
|
55
|
+
|
56
|
+
red = ALLOC_N(unsigned int, 256);
|
57
|
+
if(!red)
|
58
|
+
rb_raise(rb_eNoMemError,"Out of memory");
|
59
|
+
|
60
|
+
green = ALLOC_N(unsigned int, 256);
|
61
|
+
if(!green)
|
62
|
+
{
|
63
|
+
free(red);
|
64
|
+
rb_raise(rb_eNoMemError,"Out of memory");
|
65
|
+
}
|
66
|
+
|
67
|
+
blue = ALLOC_N(unsigned int, 256);
|
68
|
+
if(!blue)
|
69
|
+
{
|
70
|
+
free(red);
|
71
|
+
free(green);
|
72
|
+
rb_raise(rb_eNoMemError,"Out of memory");
|
73
|
+
}
|
74
|
+
|
75
|
+
alpha = ALLOC_N(unsigned int, 256);
|
76
|
+
if(!alpha)
|
77
|
+
{
|
78
|
+
free(red);
|
79
|
+
free(green);
|
80
|
+
free(blue);
|
81
|
+
rb_raise(rb_eNoMemError,"Out of memory");
|
82
|
+
}
|
83
|
+
|
84
|
+
for(i=0; i<256; i++)
|
85
|
+
{
|
86
|
+
v = rb_ary_entry(palette, i);
|
87
|
+
if((TYPE(v) == T_ARRAY) && (RARRAY_LEN(v) == 4))
|
88
|
+
{
|
89
|
+
r = rb_ary_entry(v,0);
|
90
|
+
g = rb_ary_entry(v,1);
|
91
|
+
b = rb_ary_entry(v,2);
|
92
|
+
a = rb_ary_entry(v,3);
|
93
|
+
if(rb_obj_is_kind_of(r, rb_cInteger) &&
|
94
|
+
rb_obj_is_kind_of(g, rb_cInteger) &&
|
95
|
+
rb_obj_is_kind_of(b, rb_cInteger) &&
|
96
|
+
rb_obj_is_kind_of(a, rb_cInteger))
|
97
|
+
{
|
98
|
+
red[i] = NUM2INT(r);
|
99
|
+
green[i] = NUM2INT(g);
|
100
|
+
blue[i] = NUM2INT(b);
|
101
|
+
alpha[i] = NUM2INT(a);
|
102
|
+
} else
|
103
|
+
error = 1;
|
104
|
+
}
|
105
|
+
else
|
106
|
+
error = 1;
|
107
|
+
}
|
108
|
+
|
109
|
+
if(error)
|
110
|
+
{
|
111
|
+
free(red);
|
112
|
+
free(green);
|
113
|
+
free(blue);
|
114
|
+
free(alpha);
|
115
|
+
rb_raise(rb_eArgError, "Invalid palette");
|
116
|
+
}
|
117
|
+
|
118
|
+
if(caca_set_dither_palette(_SELF, red, green, blue, alpha)<0)
|
119
|
+
{
|
120
|
+
free(red);
|
121
|
+
free(green);
|
122
|
+
free(blue);
|
123
|
+
free(alpha);
|
124
|
+
rb_raise(rb_eRuntimeError, "%s", strerror(errno));
|
125
|
+
}
|
126
|
+
|
127
|
+
free(red);
|
128
|
+
free(green);
|
129
|
+
free(blue);
|
130
|
+
free(alpha);
|
131
|
+
|
132
|
+
return palette;
|
133
|
+
}
|
134
|
+
|
135
|
+
static VALUE set_dither_palette2(VALUE self, VALUE palette)
|
136
|
+
{
|
137
|
+
set_dither_palette(self, palette);
|
138
|
+
return self;
|
139
|
+
}
|
140
|
+
|
141
|
+
#define set_float(x) \
|
142
|
+
static VALUE set_##x(VALUE self, VALUE x) \
|
143
|
+
{ \
|
144
|
+
if(caca_set_dither_##x(_SELF, (float)NUM2DBL(x))<0) \
|
145
|
+
rb_raise(rb_eRuntimeError, "%s", strerror(errno)); \
|
146
|
+
\
|
147
|
+
return x; \
|
148
|
+
} \
|
149
|
+
\
|
150
|
+
static VALUE set_##x##2(VALUE self, VALUE x) \
|
151
|
+
{ \
|
152
|
+
set_##x(self, x); \
|
153
|
+
return self; \
|
154
|
+
}
|
155
|
+
|
156
|
+
set_float(brightness)
|
157
|
+
set_float(gamma)
|
158
|
+
set_float(contrast)
|
159
|
+
|
160
|
+
#define get_set_str_from_list(x) \
|
161
|
+
get_double_list(dither_##x) \
|
162
|
+
static VALUE set_dither_##x(VALUE self, VALUE x) \
|
163
|
+
{ \
|
164
|
+
if(caca_set_dither_##x(_SELF, StringValuePtr(x))<0) \
|
165
|
+
{ \
|
166
|
+
rb_raise(rb_eRuntimeError, "%s", strerror(errno)); \
|
167
|
+
} \
|
168
|
+
return x; \
|
169
|
+
} \
|
170
|
+
\
|
171
|
+
static VALUE set_dither_##x##2(VALUE self, VALUE x) \
|
172
|
+
{ \
|
173
|
+
set_dither_##x(self, x); \
|
174
|
+
return self; \
|
175
|
+
}
|
176
|
+
|
177
|
+
get_set_str_from_list(antialias)
|
178
|
+
get_set_str_from_list(color)
|
179
|
+
get_set_str_from_list(charset)
|
180
|
+
get_set_str_from_list(algorithm)
|
181
|
+
|
182
|
+
void Init_caca_dither(VALUE mCaca)
|
183
|
+
{
|
184
|
+
cDither = rb_define_class_under(mCaca, "Dither", rb_cObject);
|
185
|
+
rb_define_alloc_func(cDither, dither_alloc);
|
186
|
+
|
187
|
+
rb_define_method(cDither, "initialize", dither_initialize, 8);
|
188
|
+
rb_define_method(cDither, "palette=", set_dither_palette, 1);
|
189
|
+
rb_define_method(cDither, "set_palette", set_dither_palette2, 1);
|
190
|
+
rb_define_method(cDither, "brightness=", set_brightness, 1);
|
191
|
+
rb_define_method(cDither, "set_brightness", set_brightness2, 1);
|
192
|
+
rb_define_method(cDither, "gamma=", set_gamma, 1);
|
193
|
+
rb_define_method(cDither, "set_gamma", set_gamma2, 1);
|
194
|
+
rb_define_method(cDither, "contrast=", set_contrast, 1);
|
195
|
+
rb_define_method(cDither, "set_contrast", set_contrast2, 1);
|
196
|
+
rb_define_method(cDither, "antialias_list", dither_antialias_list, 0);
|
197
|
+
rb_define_method(cDither, "antialias=", set_dither_antialias, 1);
|
198
|
+
rb_define_method(cDither, "set_antialias", set_dither_antialias2, 1);
|
199
|
+
rb_define_method(cDither, "color_list", dither_color_list, 0);
|
200
|
+
rb_define_method(cDither, "color=", set_dither_color, 1);
|
201
|
+
rb_define_method(cDither, "set_color", set_dither_color2, 1);
|
202
|
+
rb_define_method(cDither, "charset_list", dither_charset_list, 0);
|
203
|
+
rb_define_method(cDither, "charset=", set_dither_charset, 1);
|
204
|
+
rb_define_method(cDither, "set_charset", set_dither_charset2, 1);
|
205
|
+
rb_define_method(cDither, "algorithm_list", dither_algorithm_list, 0);
|
206
|
+
rb_define_method(cDither, "algorithm=", set_dither_algorithm, 1);
|
207
|
+
rb_define_method(cDither, "set_algorithm", set_dither_algorithm2, 1);
|
208
|
+
}
|
209
|
+
|