#include "reflex/ruby/shape.h" #include #include "reflex/exception.h" #include "reflex/ruby/view.h" #include "defs.h" #include "selector.h" RUCY_DEFINE_WRAPPER_VALUE_FROM_TO(Reflex::Shape) #define THIS to(self) #define CHECK RUCY_CHECK_OBJ(Reflex::Shape, self) #define CALL(fun) RUCY_CALL_SUPER(THIS, fun) static VALUE alloc(VALUE klass) { Reflex::reflex_error(__FILE__, __LINE__, "can not instantiate Shape class."); } static VALUE owner(VALUE self) { CHECK; return value(THIS->owner()); } static VALUE set_frame(VALUE self) { CHECK; THIS->set_frame(to(argc, argv)); return value(THIS->frame()); } static VALUE get_frame(VALUE self) { CHECK; return value(THIS->frame()); } static VALUE set_density(VALUE self, VALUE density) { CHECK; THIS->set_density(to(density)); return density; } static VALUE get_density(VALUE self) { CHECK; return value(THIS->density()); } static VALUE set_friction(VALUE self, VALUE friction) { CHECK; THIS->set_friction(to(friction)); return friction; } static VALUE get_friction(VALUE self) { CHECK; return value(THIS->friction()); } static VALUE set_restitution(VALUE self, VALUE restitution) { CHECK; THIS->set_restitution(to(restitution)); return restitution; } static VALUE get_restitution(VALUE self) { CHECK; return value(THIS->restitution()); } static VALUE set_sensor(VALUE self, VALUE state) { CHECK; THIS->set_sensor(state); return state; } static VALUE is_sensor(VALUE self) { CHECK; return value(THIS->is_sensor()); } static VALUE on_draw(VALUE self, VALUE event) { CHECK; CALL(on_draw(to(event))); } static VALUE will_contact(VALUE self, VALUE shape) { CHECK; return value(CALL(will_contact(to(shape)))); } static VALUE on_contact(VALUE self, VALUE event) { CHECK; CALL(on_contact(to(event))); } static VALUE on_contact_begin(VALUE self, VALUE event) { CHECK; CALL(on_contact_begin(to(event))); } static VALUE on_contact_end(VALUE self, VALUE event) { CHECK; CALL(on_contact_end(to(event))); } static Class cShape; void Init_reflex_shape () { Module mReflex = rb_define_module("Reflex"); cShape = rb_define_class_under(mReflex, "Shape", rb_cObject); rb_define_alloc_func(cShape, alloc); rb_define_method(cShape, "owner", RUBY_METHOD_FUNC(owner), 0); rb_define_method(cShape, "frame=", RUBY_METHOD_FUNC(set_frame), -1); rb_define_method(cShape, "frame", RUBY_METHOD_FUNC(get_frame), 0); rb_define_method(cShape, "density=", RUBY_METHOD_FUNC(set_density), 1); rb_define_method(cShape, "density", RUBY_METHOD_FUNC(get_density), 0); rb_define_method(cShape, "friction=", RUBY_METHOD_FUNC(set_friction), 1); rb_define_method(cShape, "friction", RUBY_METHOD_FUNC(get_friction), 0); rb_define_method(cShape, "restitution=", RUBY_METHOD_FUNC(set_restitution), 1); rb_define_method(cShape, "restitution", RUBY_METHOD_FUNC(get_restitution), 0); rb_define_method(cShape, "sensor=", RUBY_METHOD_FUNC(set_sensor), 1); rb_define_method(cShape, "sensor", RUBY_METHOD_FUNC(is_sensor), 0); rb_define_method(cShape, "on_draw", RUBY_METHOD_FUNC(on_draw), 1); cShape.define_method( "will_contact?", will_contact); cShape.define_private_method("call_contact!", on_contact); cShape.define_private_method("call_contact_begin!", on_contact_begin); cShape.define_private_method("call_contact_end!", on_contact_end); define_selector_methods(cShape); } namespace Reflex { Class shape_class () { return cShape; } }// Reflex