#include "rays/ruby/font.h" #include #include "defs.h" using namespace Rucy; using Rays::coord; static Class cFont; namespace Rays { Class font_class () { return cFont; } }// Rays namespace Rucy { Value value (const Rays::Font& obj) { return new_type(cFont, new Rays::Font(obj)); } Value value (const Rays::Font* obj) { return obj ? value(*obj) : nil(); } }// Rucy #define THIS to(self) #define CHECK RUCY_CHECK_OBJECT(self, Rays::Font, cFont) static RUBY_DEF_ALLOC(alloc, klass) { return new_type(klass); } RUBY_END static RUBY_DEFN(initialize) { 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(argv[1]) : 0; *THIS = Rays::Font(name, size); return self; } RUBY_END static RUBY_DEF0(name) { CHECK; return value(THIS->name().c_str()); } RUBY_END static RUBY_DEF0(size) { CHECK; return value(THIS->size()); } RUBY_END static RUBY_DEF1(width, str) { CHECK; coord width = 0; if (!THIS->get_width(&width, str.c_str())) rays_error("Font#width(%s) failed.", str.inspect().c_str()); return value(width); } RUBY_END static RUBY_DEF0(height) { CHECK; coord height = 0; if (!THIS->get_height(&height)) rays_error("Font#height() failed."); return value(height); } RUBY_END void Init_font () { Module mRays = define_module("Rays"); cFont = mRays.define_class("Font"); cFont.define_alloc_func(alloc); cFont.define_private_method("initialize", initialize); cFont.define_method("name", name); cFont.define_method("size", size); cFont.define_method("width", width); cFont.define_method("height", height); }