.doc/ext/rays/font.cpp in rays-0.1.3 vs .doc/ext/rays/font.cpp in rays-0.1.4
- old
+ new
@@ -8,16 +8,17 @@
using namespace Rucy;
using Rays::coord;
+static Class cFont;
+
+
namespace Rays
{
- static Class cFont;
-
Class
font_class ()
{
return cFont;
}
@@ -29,96 +30,99 @@
namespace Rucy
{
Value
- value (const Rays::Font& font)
+ value (const Rays::Font& obj)
{
- return new_type<Rays::Font>(
- Rays::font_class(), new Rays::Font(font));
+ return new_type(cFont, new Rays::Font(obj));
}
+ Value
+ value (const Rays::Font* obj)
+ {
+ return obj ? value(*obj) : nil();
+ }
+
}// Rucy
-#define this to<Rays::Font*>(self)
+#define THIS to<Rays::Font*>(self)
-#define CHECK CHECK_OBJECT(self, Rays::Font, Rays::font_class())
+#define CHECK RUCY_CHECK_OBJECT(self, Rays::Font, cFont)
static
VALUE alloc(VALUE klass)
{
- return new_type<Rays::Font>(klass, new Rays::Font);
+ return new_type<Rays::Font>(klass);
}
static
VALUE initialize(VALUE self)
{
- CHECK_OBJ(self, Rays::Font, Rays::font_class());
+ RUCY_CHECK_OBJ(self, Rays::Font, cFont);
if (argc < 0 || 2 < argc)
arg_count_error("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 = Rays::Font(name, size);
return self;
}
static
VALUE name(VALUE self)
{
CHECK;
- return value(this->name().c_str());
+ return value(THIS->name().c_str());
}
static
VALUE size(VALUE self)
{
CHECK;
- return value(this->size());
+ return value(THIS->size());
}
static
VALUE width(VALUE self, VALUE str)
{
CHECK;
coord width = 0;
- if (!this->get_extent(&width, NULL, str.c_str()))
- error("Font#width(%s) failed.", str.inspect().c_str());
+ if (!THIS->get_width(&width, str.c_str()))
+ rays_error("Font#width(%s) failed.", str.inspect().c_str());
return value(width);
}
static
VALUE height(VALUE self)
{
CHECK;
coord height = 0;
- if (!this->get_extent(NULL, &height, NULL))
- error("Font#height() failed.");
+ if (!THIS->get_height(&height))
+ rays_error("Font#height() failed.");
return value(height);
}
void
Init_font ()
{
- Module m = rb_define_module("Rays");
+ Module mRays = rb_define_module("Rays");
- Class c = rb_define_class_under(m, "Font", rb_cObject);
- Rays::cFont = c;
-
- rb_define_alloc_func(c, alloc);
- rb_define_method(c, "initialize", RUBY_METHOD_FUNC(initialize), -1);
- rb_define_method(c, "name", RUBY_METHOD_FUNC(name), 0);
- rb_define_method(c, "size", RUBY_METHOD_FUNC(size), 0);
- rb_define_method(c, "width", RUBY_METHOD_FUNC(width), 1);
- rb_define_method(c, "height", RUBY_METHOD_FUNC(height), 0);
+ 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_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);
}