2013-09-01 14:27:21 +00:00
|
|
|
/*
|
|
|
|
** font-binding.cpp
|
|
|
|
**
|
|
|
|
** This file is part of mkxp.
|
|
|
|
**
|
|
|
|
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
|
|
|
**
|
|
|
|
** mkxp is free software: you can redistribute it and/or modify
|
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation, either version 2 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
|
|
|
** mkxp is distributed in the hope that it will be useful,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "font.h"
|
2014-09-05 20:53:19 +00:00
|
|
|
#include "sharedstate.h"
|
2013-09-01 14:27:21 +00:00
|
|
|
#include "binding-util.h"
|
|
|
|
#include "binding-types.h"
|
|
|
|
#include "exception.h"
|
|
|
|
|
2013-12-04 16:48:37 +00:00
|
|
|
#include <mruby/string.h>
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
DEF_TYPE(Font);
|
|
|
|
|
2013-09-03 09:06:01 +00:00
|
|
|
MRB_FUNCTION(fontDoesExist)
|
2013-09-01 14:27:21 +00:00
|
|
|
{
|
2014-08-09 15:18:42 +00:00
|
|
|
const char *name = 0;
|
|
|
|
mrb_value nameObj;
|
|
|
|
|
|
|
|
mrb_get_args(mrb, "o", &nameObj);
|
|
|
|
|
|
|
|
if (mrb_string_p(nameObj))
|
|
|
|
name = mrb_string_value_cstr(mrb, &nameObj);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
return mrb_bool_value(Font::doesExist(name));
|
|
|
|
}
|
|
|
|
|
|
|
|
MRB_METHOD(fontInitialize)
|
|
|
|
{
|
|
|
|
char *name = 0;
|
|
|
|
mrb_int size = 0;
|
|
|
|
|
|
|
|
mrb_get_args(mrb, "|zi", &name, &size);
|
|
|
|
|
2018-04-30 17:19:27 +00:00
|
|
|
Font *f;
|
|
|
|
|
|
|
|
std::vector<std::string> names;
|
|
|
|
names.push_back(name);
|
|
|
|
|
|
|
|
f = new Font(&names, size);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2014-08-09 08:38:42 +00:00
|
|
|
setPrivateData(self, f, FontType);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
/* Wrap property objects */
|
2014-09-05 20:53:19 +00:00
|
|
|
f->initDynAttribs();
|
|
|
|
|
2014-10-25 21:33:41 +00:00
|
|
|
wrapProperty(mrb, self, &f->getColor(), CScolor, ColorType);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2014-09-05 20:53:19 +00:00
|
|
|
if (rgssVer >= 3)
|
2014-10-25 21:33:41 +00:00
|
|
|
wrapProperty(mrb, self, &f->getOutColor(), CSout_color, ColorType);
|
2014-09-05 20:53:19 +00:00
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2014-08-09 18:12:06 +00:00
|
|
|
MRB_METHOD(fontInitializeCopy)
|
|
|
|
{
|
|
|
|
mrb_value origObj;
|
|
|
|
mrb_get_args(mrb, "o", &origObj);
|
|
|
|
|
|
|
|
Font *orig = getPrivateData<Font>(mrb, origObj);
|
|
|
|
Font *f = new Font(*orig);
|
|
|
|
setPrivateData(self, f, FontType);
|
|
|
|
|
|
|
|
/* Wrap property objects */
|
2014-09-05 20:53:19 +00:00
|
|
|
f->initDynAttribs();
|
|
|
|
|
2014-10-25 21:33:41 +00:00
|
|
|
wrapProperty(mrb, self, &f->getColor(), CScolor, ColorType);
|
2014-08-09 18:12:06 +00:00
|
|
|
|
2014-09-05 20:53:19 +00:00
|
|
|
if (rgssVer >= 3)
|
2014-10-25 21:33:41 +00:00
|
|
|
wrapProperty(mrb, self, &f->getOutColor(), CSout_color, ColorType);
|
2014-09-05 20:53:19 +00:00
|
|
|
|
2014-08-09 18:12:06 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
MRB_METHOD(FontGetName)
|
|
|
|
{
|
2018-04-30 17:19:27 +00:00
|
|
|
return mrb_iv_get(mrb, self, mrb_intern_cstr(mrb, "name"));
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MRB_METHOD(FontSetName)
|
|
|
|
{
|
|
|
|
Font *f = getPrivateData<Font>(mrb, self);
|
|
|
|
|
|
|
|
mrb_value name;
|
|
|
|
mrb_get_args(mrb, "S", &name);
|
|
|
|
|
2018-04-30 17:19:27 +00:00
|
|
|
std::vector<std::string> names;
|
|
|
|
names.push_back(RSTRING_PTR(name));
|
|
|
|
|
|
|
|
f->setName(names);
|
|
|
|
mrb_iv_set(mrb, self, mrb_intern_cstr(mrb, "name"), name);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2014-09-23 19:12:58 +00:00
|
|
|
template<class C>
|
|
|
|
static void checkDisposed(mrb_state *, mrb_value) {}
|
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
DEF_PROP_I(Font, Size)
|
|
|
|
DEF_PROP_B(Font, Bold)
|
|
|
|
DEF_PROP_B(Font, Italic)
|
2014-09-05 20:53:19 +00:00
|
|
|
DEF_PROP_B(Font, Outline)
|
|
|
|
DEF_PROP_B(Font, Shadow)
|
|
|
|
DEF_PROP_OBJ_VAL(Font, Color, Color, CScolor)
|
|
|
|
DEF_PROP_OBJ_VAL(Font, Color, OutColor, CSout_color)
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
#define DEF_KLASS_PROP(Klass, mrb_type, PropName, arg_type, conv_t) \
|
|
|
|
static mrb_value \
|
|
|
|
Klass##Get##PropName(mrb_state *, mrb_value) \
|
|
|
|
{ \
|
|
|
|
return mrb_##conv_t##_value(Klass::get##PropName()); \
|
|
|
|
} \
|
|
|
|
static mrb_value \
|
|
|
|
Klass##Set##PropName(mrb_state *mrb, mrb_value) \
|
|
|
|
{ \
|
|
|
|
mrb_type value; \
|
|
|
|
mrb_get_args(mrb, arg_type, &value); \
|
|
|
|
Klass::set##PropName(value); \
|
|
|
|
return mrb_##conv_t##_value(value); \
|
|
|
|
}
|
|
|
|
|
2014-09-05 20:53:19 +00:00
|
|
|
DEF_KLASS_PROP(Font, mrb_int, DefaultSize, "i", fixnum)
|
|
|
|
DEF_KLASS_PROP(Font, mrb_bool, DefaultBold, "b", bool)
|
|
|
|
DEF_KLASS_PROP(Font, mrb_bool, DefaultItalic, "b", bool)
|
|
|
|
DEF_KLASS_PROP(Font, mrb_bool, DefaultOutline, "b", bool)
|
|
|
|
DEF_KLASS_PROP(Font, mrb_bool, DefaultShadow, "b", bool)
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2018-04-30 17:19:27 +00:00
|
|
|
MRB_METHOD(FontGetDefaultName)
|
2013-09-01 14:27:21 +00:00
|
|
|
{
|
2018-04-30 17:19:27 +00:00
|
|
|
return mrb_iv_get(mrb, self, mrb_intern_cstr(mrb, "default_name"));
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
2018-04-30 17:19:27 +00:00
|
|
|
MRB_METHOD(FontSetDefaultName)
|
2013-09-01 14:27:21 +00:00
|
|
|
{
|
|
|
|
mrb_value nameObj;
|
|
|
|
mrb_get_args(mrb, "S", &nameObj);
|
|
|
|
|
2018-04-30 17:19:27 +00:00
|
|
|
std::vector<std::string> names;
|
|
|
|
names.push_back(RSTRING_PTR(nameObj));
|
|
|
|
|
|
|
|
Font::setDefaultName(names, shState->fontState());
|
|
|
|
mrb_iv_set(mrb, self, mrb_intern_cstr(mrb, "default_name"), nameObj);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
return nameObj;
|
|
|
|
}
|
|
|
|
|
|
|
|
MRB_METHOD(FontGetDefaultColor)
|
|
|
|
{
|
|
|
|
return getProperty(mrb, self, CSdefault_color);
|
|
|
|
}
|
|
|
|
|
|
|
|
MRB_METHOD(FontSetDefaultColor)
|
|
|
|
{
|
2014-09-05 20:53:19 +00:00
|
|
|
MRB_UNUSED_PARAM;
|
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
mrb_value colorObj;
|
|
|
|
mrb_get_args(mrb, "o", &colorObj);
|
|
|
|
|
|
|
|
Color *c = getPrivateDataCheck<Color>(mrb, colorObj, ColorType);
|
|
|
|
|
2014-10-25 21:33:41 +00:00
|
|
|
Font::setDefaultColor(*c);
|
2014-09-05 20:53:19 +00:00
|
|
|
|
|
|
|
return colorObj;
|
|
|
|
}
|
|
|
|
|
|
|
|
MRB_METHOD(FontGetDefaultOutColor)
|
|
|
|
{
|
|
|
|
return getProperty(mrb, self, CSdefault_out_color);
|
|
|
|
}
|
|
|
|
|
|
|
|
MRB_METHOD(FontSetDefaultOutColor)
|
|
|
|
{
|
|
|
|
MRB_UNUSED_PARAM;
|
|
|
|
|
|
|
|
mrb_value colorObj;
|
|
|
|
mrb_get_args(mrb, "o", &colorObj);
|
|
|
|
|
|
|
|
Color *c = getPrivateDataCheck<Color>(mrb, colorObj, ColorType);
|
|
|
|
|
2014-10-25 21:33:41 +00:00
|
|
|
Font::setDefaultOutColor(*c);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
return colorObj;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define INIT_KLASS_PROP_BIND(Klass, PropName, prop_name_s) \
|
|
|
|
{ \
|
|
|
|
mrb_define_class_method(mrb, klass, prop_name_s, Klass##Get##PropName, MRB_ARGS_NONE()); \
|
|
|
|
mrb_define_class_method(mrb, klass, prop_name_s "=", Klass##Set##PropName, MRB_ARGS_REQ(1)); \
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fontBindingInit(mrb_state *mrb)
|
|
|
|
{
|
2014-07-19 00:22:22 +00:00
|
|
|
RClass *klass = defineClass(mrb, "Font");
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2014-09-05 20:53:19 +00:00
|
|
|
Font::initDefaultDynAttribs();
|
2014-10-25 21:33:41 +00:00
|
|
|
wrapProperty(mrb, mrb_obj_value(klass), &Font::getDefaultColor(), CSdefault_color, ColorType);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
mrb_define_class_method(mrb, klass, "exist?", fontDoesExist, MRB_ARGS_REQ(1));
|
|
|
|
|
2014-09-05 20:53:19 +00:00
|
|
|
INIT_KLASS_PROP_BIND(Font, DefaultName, "default_name");
|
|
|
|
INIT_KLASS_PROP_BIND(Font, DefaultSize, "default_size");
|
|
|
|
INIT_KLASS_PROP_BIND(Font, DefaultBold, "default_bold");
|
|
|
|
INIT_KLASS_PROP_BIND(Font, DefaultItalic, "default_italic");
|
|
|
|
INIT_KLASS_PROP_BIND(Font, DefaultColor, "default_color");
|
|
|
|
|
|
|
|
if (rgssVer >= 2)
|
|
|
|
{
|
|
|
|
INIT_KLASS_PROP_BIND(Font, DefaultShadow, "default_shadow");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rgssVer >= 3)
|
|
|
|
{
|
|
|
|
INIT_KLASS_PROP_BIND(Font, DefaultOutline, "default_outline");
|
|
|
|
INIT_KLASS_PROP_BIND(Font, DefaultOutColor, "default_out_color");
|
2014-10-25 21:33:41 +00:00
|
|
|
wrapProperty(mrb, mrb_obj_value(klass), &Font::getDefaultOutColor(), CSdefault_out_color, ColorType);
|
2014-09-05 20:53:19 +00:00
|
|
|
}
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2014-08-09 18:12:06 +00:00
|
|
|
mrb_define_method(mrb, klass, "initialize", fontInitialize, MRB_ARGS_OPT(2));
|
|
|
|
mrb_define_method(mrb, klass, "initialize_copy", fontInitializeCopy, MRB_ARGS_REQ(1));
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2014-09-05 20:53:19 +00:00
|
|
|
INIT_PROP_BIND(Font, Name, "name");
|
|
|
|
INIT_PROP_BIND(Font, Size, "size");
|
|
|
|
INIT_PROP_BIND(Font, Bold, "bold");
|
|
|
|
INIT_PROP_BIND(Font, Italic, "italic");
|
|
|
|
INIT_PROP_BIND(Font, Color, "color");
|
|
|
|
|
|
|
|
if (rgssVer >= 2)
|
|
|
|
{
|
|
|
|
INIT_PROP_BIND(Font, Shadow, "shadow");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rgssVer >= 3)
|
|
|
|
{
|
|
|
|
INIT_PROP_BIND(Font, Outline, "outline");
|
|
|
|
INIT_PROP_BIND(Font, OutColor, "out_color");
|
|
|
|
}
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
mrb_define_method(mrb, klass, "inspect", inspectObject, MRB_ARGS_NONE());
|
|
|
|
}
|