.doc/ext/rays/font.cpp in rays-0.1.12 vs .doc/ext/rays/font.cpp in rays-0.1.13

- old
+ new

@@ -1,19 +1,13 @@ #include "rays/ruby/font.h" -#include <rucy.h> #include "defs.h" -using namespace Rucy; +RUCY_DEFINE_VALUE_OR_ARRAY_FROM_TO(Rays::Font) -using Rays::coord; - - -RUCY_DEFINE_VALUE_FROM_TO(Rays::Font) - #define THIS to<Rays::Font*>(self) #define CHECK RUCY_CHECK_OBJECT(Rays::Font, self) @@ -27,27 +21,15 @@ VALUE initialize(VALUE self) { RUCY_CHECK_OBJ(Rays::Font, self); check_arg_count(__FILE__, __LINE__, "Font#initialize", argc, 0, 1, 2); - const char* name = (argc >= 1) ? argv[0].c_str() : NULL; - float size = (argc >= 2) ? to<float>(argv[1]) : 0; - *THIS = Rays::Font(name, size); - + *THIS = to<Rays::Font>(argc, argv); return self; } static -VALUE initialize_copy(VALUE self, VALUE obj) -{ - RUCY_CHECK_OBJ(Rays::Font, self); - - *THIS = to<Rays::Font&>(obj).copy(); - return self; -} - -static VALUE name(VALUE self) { CHECK; return value(THIS->name().c_str()); } @@ -82,15 +64,51 @@ Module mRays = rb_define_module("Rays"); cFont = rb_define_class_under(mRays, "Font", rb_cObject); rb_define_alloc_func(cFont, alloc); rb_define_private_method(cFont, "initialize", RUBY_METHOD_FUNC(initialize), -1); - rb_define_private_method(cFont, "initialize_copy", RUBY_METHOD_FUNC(initialize_copy), 1); rb_define_method(cFont, "name", RUBY_METHOD_FUNC(name), 0); rb_define_method(cFont, "size", RUBY_METHOD_FUNC(size), 0); rb_define_method(cFont, "width", RUBY_METHOD_FUNC(width), 1); rb_define_method(cFont, "height", RUBY_METHOD_FUNC(height), 0); } + + +namespace Rucy +{ + + + template <> Rays::Font + value_to<Rays::Font> (int argc, const Value* argv, bool convert) + { + if (argc == 1 && argv->is_array()) + { + argc = argv->size(); + argv = argv->as_array(); + } + + assert(argc == 0 || (argc > 0 && argv)); + + if (convert) + { + if (argc == 0) + return Rays::default_font(); + + coord size = argc >= 2 ? to<coord>(argv[1]) : 0; + if (argv->is_nil()) + return Rays::Font(NULL, size); + else if (argv->is_s() || argv->is_sym()) + return Rays::Font(argv[0].c_str(), size); + } + + if (argc != 1) + argument_error(__FILE__, __LINE__); + + return value_to<Rays::Font&>(*argv, convert); + } + + +}// Rucy namespace Rays {