From 061ca415b08bbbf53f266b79e900c9f7ffead15b Mon Sep 17 00:00:00 2001 From: Pascal Terjan Date: Sun, 18 Nov 2007 13:37:24 +0000 Subject: [PATCH] * Add missing methods in Caca::Display and add empty Caca::Event --- ruby/Makefile.am | 4 +++- ruby/caca-display.c | 39 +++++++++++++++++++++++++++++++++++++++ ruby/caca-event.c | 22 ++++++++++++++++++++++ ruby/caca-event.h | 9 +++++++++ 4 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 ruby/caca-event.c create mode 100644 ruby/caca-event.h diff --git a/ruby/Makefile.am b/ruby/Makefile.am index b213b6f..0af3c9a 100644 --- a/ruby/Makefile.am +++ b/ruby/Makefile.am @@ -12,13 +12,15 @@ cucul_la_LDFLAGS = -module -avoid-version -shared -L$(RUBY_LIBDIR) -l$(RUBY_SO_N cucul_la_LIBADD = ../cucul/libcucul.la caca_la_CPPFLAGS = -I$(top_srcdir)/caca -I$(RUBY_ARCHDIR) -caca_la_SOURCES = caca.c caca-display.c +caca_la_SOURCES = caca.c caca-display.c caca-event.c caca_la_LDFLAGS = -module -avoid-version -shared -L$(RUBY_LIBDIR) -l$(RUBY_SO_NAME) caca_la_LIBADD = ../caca/libcaca.la EXTRA_DIST = cucul-canvas.h \ cucul-dither.h \ cucul-font.h \ + caca-display.h \ + caca-event.h \ common.h \ test.rb \ t/tc_canvas.rb \ diff --git a/ruby/caca-display.c b/ruby/caca-display.c index d02d523..ac20527 100644 --- a/ruby/caca-display.c +++ b/ruby/caca-display.c @@ -12,6 +12,7 @@ #include #include #include +#include "caca-event.h" #include "cucul-canvas.h" #include "common.h" @@ -97,6 +98,39 @@ static VALUE set_title2(VALUE self, VALUE t) return self; } +static VALUE get_mouse_x(VALUE self) +{ + return NUM2UINT(caca_get_mouse_x(_SELF)); +} + +static VALUE get_mouse_y(VALUE self) +{ + return NUM2UINT(caca_get_mouse_y(_SELF)); +} + +static VALUE set_mouse(VALUE self, VALUE visible) +{ + caca_set_display_time(_SELF, visible); + return visible; +} + +static VALUE set_mouse2(VALUE self, VALUE visible) +{ + set_mouse(self, visible); + return self; +} + +static VALUE get_event(VALUE self, VALUE event_mask, VALUE timeout) +{ + caca_event_t ev; + if(caca_get_event(_SELF, NUM2UINT(event_mask), &ev, NUM2INT(timeout)) == 0) + { + return Qnil; + } + //FIXME + return Qnil; +} + void Init_caca_display(VALUE mCaca) { cDisplay = rb_define_class_under(mCaca, "Display", rb_cObject); @@ -111,4 +145,9 @@ void Init_caca_display(VALUE mCaca) rb_define_method(cDisplay, "height", get_height, 0); rb_define_method(cDisplay, "title=", set_title, 1); rb_define_method(cDisplay, "set_title", set_title2, 1); + rb_define_method(cDisplay, "mouse_x", get_mouse_x, 0); + rb_define_method(cDisplay, "mouse_y", get_mouse_y, 0); + rb_define_method(cDisplay, "mouse=", set_mouse, 1); + rb_define_method(cDisplay, "set_mouse", set_mouse2, 1); + rb_define_method(cDisplay, "get_event", get_event, 3); } diff --git a/ruby/caca-event.c b/ruby/caca-event.c new file mode 100644 index 0000000..fbfe108 --- /dev/null +++ b/ruby/caca-event.c @@ -0,0 +1,22 @@ +/* + * libcaca Ruby bindings + * Copyright (c) 2007 Pascal Terjan + * + * This library is free software. It comes without any warranty, to + * the extent permitted by applicable law. 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 +#include +#include +#include "common.h" + +VALUE cEvent; + +void Init_caca_event(VALUE mCaca) +{ + cEvent = rb_define_class_under(mCaca, "Event", rb_cObject); +} diff --git a/ruby/caca-event.h b/ruby/caca-event.h new file mode 100644 index 0000000..5b11fca --- /dev/null +++ b/ruby/caca-event.h @@ -0,0 +1,9 @@ +#ifndef __CACA_DISPLAY_H__ +#define __CACA_DISPLAY_H__ + +#include + +extern VALUE cEvent; +extern void Init_caca_event(VALUE); + +#endif