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.
@@ -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_DITHER_H__
14
+ #define __CACA_DITHER_H__
15
+
16
+ #include <ruby.h>
17
+
18
+ extern VALUE cDither;
19
+ extern void Init_caca_dither(VALUE);
20
+
21
+ #endif
@@ -0,0 +1,73 @@
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
+ #include <ruby.h>
14
+ #include <caca.h>
15
+ #include <errno.h>
16
+ #include "common.h"
17
+
18
+ VALUE cEvent;
19
+ static VALUE cEventKey;
20
+ VALUE cEventKeyPress;
21
+ VALUE cEventKeyRelease;
22
+ static VALUE cEventMouse;
23
+ VALUE cEventMousePress;
24
+ VALUE cEventMouseRelease;
25
+ VALUE cEventMouseMotion;
26
+ VALUE cEventResize;
27
+ VALUE cEventQuit;
28
+
29
+ void Init_caca_event(VALUE mCaca)
30
+ {
31
+ cEvent = rb_define_class_under(mCaca, "Event", rb_cObject);
32
+ rb_define_const(cEvent, "TYPE", INT2FIX(CACA_EVENT_ANY));
33
+
34
+ cEventKey = rb_define_class_under(cEvent, "Key", cEvent);
35
+ rb_define_const(cEventKey, "TYPE",
36
+ INT2FIX(CACA_EVENT_KEY_PRESS|
37
+ CACA_EVENT_KEY_RELEASE));
38
+
39
+ cEventKeyPress = rb_define_class_under(cEventKey, "Press", cEventKey);
40
+ rb_define_const(cEventKeyPress, "TYPE",
41
+ INT2FIX(CACA_EVENT_KEY_PRESS));
42
+
43
+ cEventKeyRelease = rb_define_class_under(cEventKey, "Release", cEventKey);
44
+ rb_define_const(cEventKeyRelease, "TYPE",
45
+ INT2FIX(CACA_EVENT_KEY_RELEASE));
46
+
47
+ cEventMouse = rb_define_class_under(cEvent, "Mouse", cEvent);
48
+ rb_define_const(cEventMouse, "TYPE",
49
+ INT2FIX(CACA_EVENT_MOUSE_PRESS|
50
+ CACA_EVENT_MOUSE_RELEASE|
51
+ CACA_EVENT_MOUSE_MOTION));
52
+
53
+ cEventMousePress = rb_define_class_under(cEventMouse, "Press", cEventMouse);
54
+ rb_define_const(cEventMousePress, "TYPE",
55
+ INT2FIX(CACA_EVENT_MOUSE_PRESS));
56
+
57
+ cEventMouseRelease = rb_define_class_under(cEventMouse, "Release", cEventMouse);
58
+ rb_define_const(cEventMouseRelease, "TYPE",
59
+ INT2FIX(CACA_EVENT_MOUSE_RELEASE));
60
+
61
+ cEventMouseMotion = rb_define_class_under(cEventMouse, "Motion", cEventMouse);
62
+ rb_define_const(cEventMouseMotion, "TYPE",
63
+ INT2FIX(CACA_EVENT_MOUSE_MOTION));
64
+
65
+ cEventResize = rb_define_class_under(cEvent, "Resize", cEvent);
66
+ rb_define_const(cEventResize, "TYPE",
67
+ INT2FIX(CACA_EVENT_RESIZE));
68
+
69
+ cEventQuit = rb_define_class_under(cEvent, "Quit", cEvent);
70
+ rb_define_const(cEventQuit, "TYPE",
71
+ INT2FIX(CACA_EVENT_QUIT));
72
+
73
+ }
@@ -0,0 +1,29 @@
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_EVENT_H__
14
+ #define __CACA_EVENT_H__
15
+
16
+ #include <ruby.h>
17
+
18
+ extern VALUE cEvent;
19
+ extern VALUE cEventKeyPress;
20
+ extern VALUE cEventKeyRelease;
21
+ extern VALUE cEventMouse;
22
+ extern VALUE cEventMousePress;
23
+ extern VALUE cEventMouseRelease;
24
+ extern VALUE cEventMouseMotion;
25
+ extern VALUE cEventResize;
26
+ extern VALUE cEventQuit;
27
+ extern void Init_caca_event(VALUE);
28
+
29
+ #endif
@@ -0,0 +1,99 @@
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 cFont;
18
+
19
+ void font_free(void *font)
20
+ {
21
+ caca_free_font((caca_font_t *)font);
22
+ }
23
+
24
+ static VALUE font_alloc(VALUE klass)
25
+ {
26
+ VALUE obj;
27
+ obj = Data_Wrap_Struct(klass, 0, font_free, NULL);
28
+ return obj;
29
+ }
30
+
31
+ static VALUE font_initialize(VALUE self, VALUE name)
32
+ {
33
+ caca_font_t *font;
34
+
35
+ font = caca_load_font(StringValuePtr(name), 0);
36
+ if(font == NULL)
37
+ {
38
+ rb_raise(rb_eRuntimeError, "%s", strerror(errno));
39
+ }
40
+ _SELF = font;
41
+ return self;
42
+ }
43
+
44
+ static VALUE font_list(void)
45
+ {
46
+ VALUE ary;
47
+ char const* const* list;
48
+
49
+ list = caca_get_font_list();
50
+
51
+ ary = rb_ary_new();
52
+ while (*list != NULL)
53
+ {
54
+ rb_ary_push(ary, rb_str_new2(*list));
55
+ list++;
56
+ }
57
+
58
+ return ary;
59
+ }
60
+
61
+ static VALUE get_font_width(VALUE self)
62
+ {
63
+ return UINT2NUM(caca_get_font_width(_SELF));
64
+ }
65
+
66
+ static VALUE get_font_height(VALUE self)
67
+ {
68
+ return UINT2NUM(caca_get_font_height(_SELF));
69
+ }
70
+
71
+ static VALUE get_font_blocks(VALUE self)
72
+ {
73
+ VALUE ary;
74
+ uint32_t const *list;
75
+
76
+ list = caca_get_font_blocks(_SELF);
77
+
78
+ ary = rb_ary_new();
79
+ while (*list != 0L)
80
+ {
81
+ rb_ary_push(ary, ULONG2NUM(*list));
82
+ list++;
83
+ }
84
+
85
+ return ary;
86
+ }
87
+
88
+ void Init_caca_font(VALUE mCaca)
89
+ {
90
+ cFont = rb_define_class_under(mCaca, "Font", rb_cObject);
91
+ rb_define_alloc_func(cFont, font_alloc);
92
+
93
+ rb_define_method(cFont, "initialize", font_initialize, 1);
94
+ rb_define_method(cFont, "width", get_font_width, 0);
95
+ rb_define_method(cFont, "height", get_font_height, 0);
96
+ rb_define_method(cFont, "blocks", get_font_blocks, 0);
97
+ rb_define_singleton_method(cFont, "list", font_list, 0);
98
+ }
99
+
@@ -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_FONT_H__
14
+ #define __CACA_FONT_H__
15
+
16
+ #include <ruby.h>
17
+
18
+ extern VALUE cFont;
19
+ extern void Init_caca_font(VALUE);
20
+
21
+ #endif
@@ -0,0 +1,62 @@
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
+ #include <ruby.h>
14
+ #include <caca.h>
15
+
16
+ #include "caca-canvas.h"
17
+ #include "caca-dither.h"
18
+ #include "caca-font.h"
19
+ #include "caca-display.h"
20
+ #include "caca-event.h"
21
+
22
+ static VALUE get_version(VALUE self)
23
+ {
24
+ return rb_str_new2(caca_get_version());
25
+ }
26
+
27
+ void Init_caca()
28
+ {
29
+ VALUE mCaca = rb_define_module("Caca");
30
+
31
+ rb_define_singleton_method(mCaca, "version", get_version, 0);
32
+
33
+ rb_define_const(mCaca, "BLACK", INT2FIX(CACA_BLACK));
34
+ rb_define_const(mCaca, "BLUE", INT2FIX(CACA_BLUE));
35
+ rb_define_const(mCaca, "GREEN", INT2FIX(CACA_GREEN));
36
+ rb_define_const(mCaca, "CYAN", INT2FIX(CACA_CYAN));
37
+ rb_define_const(mCaca, "RED", INT2FIX(CACA_RED));
38
+ rb_define_const(mCaca, "MAGENTA", INT2FIX(CACA_MAGENTA));
39
+ rb_define_const(mCaca, "BROWN", INT2FIX(CACA_BROWN));
40
+ rb_define_const(mCaca, "LIGHTGRAY", INT2FIX(CACA_LIGHTGRAY));
41
+ rb_define_const(mCaca, "DARKGRAY", INT2FIX(CACA_DARKGRAY));
42
+ rb_define_const(mCaca, "LIGHTBLUE", INT2FIX(CACA_LIGHTBLUE));
43
+ rb_define_const(mCaca, "LIGHTGREEN", INT2FIX(CACA_LIGHTGREEN));
44
+ rb_define_const(mCaca, "LIGHTCYAN", INT2FIX(CACA_LIGHTCYAN));
45
+ rb_define_const(mCaca, "LIGHTRED", INT2FIX(CACA_LIGHTRED));
46
+ rb_define_const(mCaca, "LIGHTMAGENTA", INT2FIX(CACA_LIGHTMAGENTA));
47
+ rb_define_const(mCaca, "YELLOW", INT2FIX(CACA_YELLOW));
48
+ rb_define_const(mCaca, "WHITE", INT2FIX(CACA_WHITE));
49
+ rb_define_const(mCaca, "DEFAULT", INT2FIX(CACA_DEFAULT));
50
+ rb_define_const(mCaca, "TRANSPARENT", INT2FIX(CACA_TRANSPARENT));
51
+
52
+ rb_define_const(mCaca, "BOLD", INT2FIX(CACA_BOLD));
53
+ rb_define_const(mCaca, "ITALICS", INT2FIX(CACA_ITALICS));
54
+ rb_define_const(mCaca, "UNDERLINE", INT2FIX(CACA_UNDERLINE));
55
+ rb_define_const(mCaca, "BLINK", INT2FIX(CACA_BLINK));
56
+
57
+ Init_caca_canvas(mCaca);
58
+ Init_caca_dither(mCaca);
59
+ Init_caca_font(mCaca);
60
+ Init_caca_display(mCaca);
61
+ Init_caca_event(mCaca);
62
+ }
@@ -0,0 +1,60 @@
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 __COMMON_H__
14
+ #define __COMMON_H__
15
+
16
+ #define _SELF (DATA_PTR(self))
17
+
18
+ #define get_singleton_double_list(x) \
19
+ static VALUE x##_list(void) \
20
+ { \
21
+ VALUE ary, ary2; \
22
+ char const* const* list; \
23
+ \
24
+ list = caca_get_##x##_list(); \
25
+ ary = rb_ary_new(); \
26
+ while (*list != NULL) \
27
+ { \
28
+ ary2 = rb_ary_new(); \
29
+ rb_ary_push(ary2, rb_str_new2(*list)); \
30
+ list++; \
31
+ rb_ary_push(ary2, rb_str_new2(*list)); \
32
+ list++; \
33
+ rb_ary_push(ary, ary2); \
34
+ } \
35
+ \
36
+ return ary; \
37
+ }
38
+
39
+ #define get_double_list(x) \
40
+ static VALUE x##_list(VALUE self) \
41
+ { \
42
+ VALUE ary, ary2; \
43
+ char const* const* list; \
44
+ \
45
+ list = caca_get_##x##_list(_SELF); \
46
+ ary = rb_ary_new(); \
47
+ while (*list != NULL) \
48
+ { \
49
+ ary2 = rb_ary_new(); \
50
+ rb_ary_push(ary2, rb_str_new2(*list)); \
51
+ list++; \
52
+ rb_ary_push(ary2, rb_str_new2(*list)); \
53
+ list++; \
54
+ rb_ary_push(ary, ary2); \
55
+ } \
56
+ \
57
+ return ary; \
58
+ }
59
+
60
+ #endif
@@ -0,0 +1,43 @@
1
+ require 'mkmf'
2
+
3
+ LIBDIR = RbConfig::CONFIG['libdir']
4
+ INCLUDEDIR = RbConfig::CONFIG['includedir']
5
+
6
+ HEADER_DIRS = [
7
+ # First search /opt/local for macports
8
+ '/opt/local/include',
9
+
10
+ # Then search /usr/local for people that installed from source
11
+ '/usr/local/include',
12
+
13
+ # Check the ruby install locations
14
+ INCLUDEDIR,
15
+
16
+ # Finally fall back to /usr
17
+ '/usr/include',
18
+ ]
19
+
20
+ LIB_DIRS = [
21
+ # First search /opt/local for macports
22
+ '/opt/local/lib',
23
+
24
+ # Then search /usr/local for people that installed from source
25
+ '/usr/local/lib',
26
+
27
+ # Check the ruby install locations
28
+ LIBDIR,
29
+
30
+ # Finally fall back to /usr
31
+ '/usr/lib',
32
+ ]
33
+
34
+ dir_config('caca', HEADER_DIRS, LIB_DIRS)
35
+
36
+ unless find_header('caca.h')
37
+ abort "libcaca is missing. please install libcaca"
38
+ end
39
+
40
+ unless find_library('caca', 'caca_create_display')
41
+ abort "libcaca is missing. please install libcaca"
42
+ end
43
+ create_makefile('caca/caca')
@@ -0,0 +1,43 @@
1
+ require 'caca/caca.so'
2
+ require 'caca/version'
3
+
4
+ module Caca
5
+ class Display
6
+ attr_reader :canvas
7
+ end
8
+ class Event
9
+ def Event.to_i
10
+ const_get("TYPE")
11
+ end
12
+ def Event.|(i)
13
+ i = i.to_i
14
+ const_get("TYPE")|i
15
+ end
16
+ def quit?
17
+ false
18
+ end
19
+ class Key
20
+ attr_reader :ch, :utf32, :utf8
21
+ def initialize(ch, utf32, utf8)
22
+ @ch, @utf32, @utf8 = ch, utf32, utf8
23
+ end
24
+ end
25
+ class Mouse
26
+ attr_reader :x, :y, :button
27
+ def initialize(x, y, button)
28
+ @x, @y, @button = x, y, button
29
+ end
30
+ end
31
+ class Resize
32
+ attr_reader :w, :h
33
+ def initialize(w, h)
34
+ @w, @h = w, h
35
+ end
36
+ end
37
+ class Quit
38
+ def quit?
39
+ true
40
+ end
41
+ end
42
+ end
43
+ end