ext/rays/font.cpp in rays-0.1.12 vs 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)
@@ -28,29 +22,16 @@
RUCY_DEFN(initialize)
{
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;
}
RUCY_END
static
-RUCY_DEF1(initialize_copy, obj)
-{
- RUCY_CHECK_OBJ(Rays::Font, self);
-
- *THIS = to<Rays::Font&>(obj).copy();
- return self;
-}
-RUCY_END
-
-static
RUCY_DEF0(name)
{
CHECK;
return value(THIS->name().c_str());
}
@@ -89,15 +70,51 @@
Module mRays = define_module("Rays");
cFont = mRays.define_class("Font");
cFont.define_alloc_func(alloc);
cFont.define_private_method("initialize", initialize);
- cFont.define_private_method("initialize_copy", initialize_copy);
cFont.define_method("name", name);
cFont.define_method("size", size);
cFont.define_method("width", width);
cFont.define_method("height", height);
}
+
+
+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
{