MRuby: Fix handling of Etc/Font properties

Port of f8c26fc515.
This commit is contained in:
Jonas Kulla 2014-09-05 22:53:19 +02:00
parent 7f41b9cc45
commit 9461449cc9
9 changed files with 117 additions and 55 deletions

View File

@ -37,6 +37,7 @@ struct
SYMD(viewport), SYMD(viewport),
SYMD(bitmap), SYMD(bitmap),
SYMD(color), SYMD(color),
SYMD(out_color),
SYMD(tone), SYMD(tone),
SYMD(rect), SYMD(rect),
SYMD(src_rect), SYMD(src_rect),
@ -51,6 +52,7 @@ struct
SYMD(path), SYMD(path),
SYMD(array), SYMD(array),
SYMD(default_color), SYMD(default_color),
SYMD(default_out_color),
SYMD(children), SYMD(children),
SYMD(dispose) SYMD(dispose)
}; };

View File

@ -38,6 +38,7 @@ enum CommonSymbol
CSviewport, CSviewport,
CSbitmap, CSbitmap,
CScolor, CScolor,
CSout_color,
CStone, CStone,
CSrect, CSrect,
CSsrc_rect, CSsrc_rect,
@ -52,6 +53,7 @@ enum CommonSymbol
CSpath, CSpath,
CSarray, CSarray,
CSdefault_color, CSdefault_color,
CSdefault_out_color,
CSchildren, CSchildren,
CSdispose, CSdispose,
@ -149,7 +151,8 @@ defineClass(mrb_state *mrb, const char *name)
#define MRB_FUN_UNUSED_PARAM { (void) mrb; } #define MRB_FUN_UNUSED_PARAM { (void) mrb; }
#define DEF_PROP_OBJ(Klass, PropKlass, PropName, prop_iv) \ /* Object property which is copied by value, not reference */
#define DEF_PROP_OBJ_VAL(Klass, PropKlass, PropName, prop_iv) \
MRB_METHOD(Klass##Get##PropName) \ MRB_METHOD(Klass##Get##PropName) \
{ \ { \
checkDisposed(mrb, self); \ checkDisposed(mrb, self); \
@ -163,12 +166,11 @@ defineClass(mrb_state *mrb, const char *name)
mrb_get_args(mrb, "o", &propObj); \ mrb_get_args(mrb, "o", &propObj); \
prop = getPrivateDataCheck<PropKlass>(mrb, propObj, PropKlass##Type); \ prop = getPrivateDataCheck<PropKlass>(mrb, propObj, PropKlass##Type); \
GUARD_EXC( k->set##PropName(prop); ) \ GUARD_EXC( k->set##PropName(prop); ) \
setProperty(mrb, self, prop_iv, propObj); \
return propObj; \ return propObj; \
} }
/* Object property with allowed NIL */ /* Object property which is copied by reference, with allowed NIL */
#define DEF_PROP_OBJ_NIL(Klass, PropKlass, PropName, prop_iv) \ #define DEF_PROP_OBJ_REF(Klass, PropKlass, PropName, prop_iv) \
MRB_METHOD(Klass##Get##PropName) \ MRB_METHOD(Klass##Get##PropName) \
{ \ { \
return getProperty(mrb, self, prop_iv); \ return getProperty(mrb, self, prop_iv); \
@ -300,7 +302,7 @@ wrapObject(mrb_state *mrb, void *p, const mrb_data_type &type)
return obj; return obj;
} }
inline void inline mrb_value
wrapProperty(mrb_state *mrb, mrb_value self, wrapProperty(mrb_state *mrb, mrb_value self,
void *prop, CommonSymbol iv, const mrb_data_type &type) void *prop, CommonSymbol iv, const mrb_data_type &type)
{ {
@ -310,6 +312,8 @@ wrapProperty(mrb_state *mrb, mrb_value self,
mrb_obj_ptr(self), mrb_obj_ptr(self),
getSym(mrb, iv), getSym(mrb, iv),
propObj); propObj);
return propObj;
} }
inline mrb_value inline mrb_value

View File

@ -22,6 +22,7 @@
#include "bitmap.h" #include "bitmap.h"
#include "font.h" #include "font.h"
#include "exception.h" #include "exception.h"
#include "sharedstate.h"
#include "disposable-binding.h" #include "disposable-binding.h"
#include "binding-util.h" #include "binding-util.h"
#include "binding-types.h" #include "binding-types.h"
@ -51,11 +52,15 @@ MRB_METHOD(bitmapInitialize)
/* Wrap properties */ /* Wrap properties */
Font *font = new Font(); Font *font = new Font();
b->setFont(font); b->setInitFont(font);
font->setColor(new Color(*font->getColor())); font->initDynAttribs();
wrapProperty(mrb, self, font, CSfont, FontType); mrb_value fontProp = wrapProperty(mrb, self, font, CSfont, FontType);
wrapProperty(mrb, getProperty(mrb, self, CSfont), font->getColor(), CScolor, ColorType);
wrapProperty(mrb, fontProp, font->getColor(), CScolor, ColorType);
if (rgssVer >= 3)
wrapProperty(mrb, fontProp, font->getOutColor(), CSout_color, ColorType);
return self; return self;
} }
@ -292,7 +297,6 @@ MRB_METHOD(bitmapSetFont)
font = getPrivateDataCheck<Font>(mrb, fontObj, FontType); font = getPrivateDataCheck<Font>(mrb, fontObj, FontType);
GUARD_EXC( b->setFont(font); ) GUARD_EXC( b->setFont(font); )
setProperty(mrb, self, CSfont, fontObj);
return mrb_nil_value(); return mrb_nil_value();
} }

View File

@ -20,6 +20,7 @@
*/ */
#include "font.h" #include "font.h"
#include "sharedstate.h"
#include "binding-util.h" #include "binding-util.h"
#include "binding-types.h" #include "binding-types.h"
#include "exception.h" #include "exception.h"
@ -53,9 +54,13 @@ MRB_METHOD(fontInitialize)
setPrivateData(self, f, FontType); setPrivateData(self, f, FontType);
/* Wrap property objects */ /* Wrap property objects */
f->setColor(new Color(*f->getColor())); f->initDynAttribs();
wrapProperty(mrb, self, f->getColor(), CScolor, ColorType); wrapProperty(mrb, self, f->getColor(), CScolor, ColorType);
if (rgssVer >= 3)
wrapProperty(mrb, self, f->getOutColor(), CSout_color, ColorType);
return self; return self;
} }
@ -69,9 +74,13 @@ MRB_METHOD(fontInitializeCopy)
setPrivateData(self, f, FontType); setPrivateData(self, f, FontType);
/* Wrap property objects */ /* Wrap property objects */
f->setColor(new Color(*f->getColor())); f->initDynAttribs();
wrapProperty(mrb, self, f->getColor(), CScolor, ColorType); wrapProperty(mrb, self, f->getColor(), CScolor, ColorType);
if (rgssVer >= 3)
wrapProperty(mrb, self, f->getOutColor(), CSout_color, ColorType);
return self; return self;
} }
@ -97,7 +106,10 @@ MRB_METHOD(FontSetName)
DEF_PROP_I(Font, Size) DEF_PROP_I(Font, Size)
DEF_PROP_B(Font, Bold) DEF_PROP_B(Font, Bold)
DEF_PROP_B(Font, Italic) DEF_PROP_B(Font, Italic)
DEF_PROP_OBJ(Font, Color, Color, CScolor) 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)
#define DEF_KLASS_PROP(Klass, mrb_type, PropName, arg_type, conv_t) \ #define DEF_KLASS_PROP(Klass, mrb_type, PropName, arg_type, conv_t) \
static mrb_value \ static mrb_value \
@ -114,9 +126,11 @@ DEF_PROP_OBJ(Font, Color, Color, CScolor)
return mrb_##conv_t##_value(value); \ return mrb_##conv_t##_value(value); \
} }
DEF_KLASS_PROP(Font, mrb_int, DefaultSize, "i", fixnum) DEF_KLASS_PROP(Font, mrb_int, DefaultSize, "i", fixnum)
DEF_KLASS_PROP(Font, mrb_bool, DefaultBold, "b", bool) DEF_KLASS_PROP(Font, mrb_bool, DefaultBold, "b", bool)
DEF_KLASS_PROP(Font, mrb_bool, DefaultItalic, "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)
MRB_FUNCTION(FontGetDefaultName) MRB_FUNCTION(FontGetDefaultName)
{ {
@ -140,13 +154,33 @@ MRB_METHOD(FontGetDefaultColor)
MRB_METHOD(FontSetDefaultColor) MRB_METHOD(FontSetDefaultColor)
{ {
MRB_UNUSED_PARAM;
mrb_value colorObj; mrb_value colorObj;
mrb_get_args(mrb, "o", &colorObj); mrb_get_args(mrb, "o", &colorObj);
Color *c = getPrivateDataCheck<Color>(mrb, colorObj, ColorType); Color *c = getPrivateDataCheck<Color>(mrb, colorObj, ColorType);
Font::setDefaultColor(c); Font::setDefaultColor(c);
setProperty(mrb, self, CSdefault_color, colorObj);
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);
Font::setDefaultOutColor(c);
return colorObj; return colorObj;
} }
@ -162,25 +196,48 @@ fontBindingInit(mrb_state *mrb)
{ {
RClass *klass = defineClass(mrb, "Font"); RClass *klass = defineClass(mrb, "Font");
Font::setDefaultColor(new Color(*Font::getDefaultColor())); Font::initDefaultDynAttribs();
wrapProperty(mrb, mrb_obj_value(klass), Font::getDefaultColor(), CSdefault_color, ColorType); wrapProperty(mrb, mrb_obj_value(klass), Font::getDefaultColor(), CSdefault_color, ColorType);
mrb_define_class_method(mrb, klass, "exist?", fontDoesExist, MRB_ARGS_REQ(1)); mrb_define_class_method(mrb, klass, "exist?", fontDoesExist, MRB_ARGS_REQ(1));
INIT_KLASS_PROP_BIND(Font, DefaultName, "default_name"); INIT_KLASS_PROP_BIND(Font, DefaultName, "default_name");
INIT_KLASS_PROP_BIND(Font, DefaultSize, "default_size"); INIT_KLASS_PROP_BIND(Font, DefaultSize, "default_size");
INIT_KLASS_PROP_BIND(Font, DefaultBold, "default_bold"); INIT_KLASS_PROP_BIND(Font, DefaultBold, "default_bold");
INIT_KLASS_PROP_BIND(Font, DefaultItalic, "default_italic"); INIT_KLASS_PROP_BIND(Font, DefaultItalic, "default_italic");
INIT_KLASS_PROP_BIND(Font, DefaultColor, "default_color"); 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");
wrapProperty(mrb, mrb_obj_value(klass), Font::getDefaultOutColor(), CSdefault_out_color, ColorType);
}
mrb_define_method(mrb, klass, "initialize", fontInitialize, MRB_ARGS_OPT(2)); mrb_define_method(mrb, klass, "initialize", fontInitialize, MRB_ARGS_OPT(2));
mrb_define_method(mrb, klass, "initialize_copy", fontInitializeCopy, MRB_ARGS_REQ(1)); mrb_define_method(mrb, klass, "initialize_copy", fontInitializeCopy, MRB_ARGS_REQ(1));
INIT_PROP_BIND(Font, Name, "name"); INIT_PROP_BIND(Font, Name, "name");
INIT_PROP_BIND(Font, Size, "size"); INIT_PROP_BIND(Font, Size, "size");
INIT_PROP_BIND(Font, Bold, "bold"); INIT_PROP_BIND(Font, Bold, "bold");
INIT_PROP_BIND(Font, Italic, "italic"); INIT_PROP_BIND(Font, Italic, "italic");
INIT_PROP_BIND(Font, Color, "color"); 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");
}
mrb_define_method(mrb, klass, "inspect", inspectObject, MRB_ARGS_NONE()); mrb_define_method(mrb, klass, "inspect", inspectObject, MRB_ARGS_NONE());
} }

View File

@ -33,18 +33,17 @@ MRB_METHOD(planeInitialize)
setPrivateData(self, p, PlaneType); setPrivateData(self, p, PlaneType);
p->setColor(new Color); p->initDynAttribs();
p->setTone(new Tone);
wrapProperty(mrb, self, p->getColor(), CScolor, ColorType); wrapProperty(mrb, self, p->getColor(), CScolor, ColorType);
wrapProperty(mrb, self, p->getTone(), CStone, ToneType); wrapProperty(mrb, self, p->getTone(), CStone, ToneType);
return self; return self;
} }
DEF_PROP_OBJ(Plane, Bitmap, Bitmap, CSbitmap) DEF_PROP_OBJ_REF(Plane, Bitmap, Bitmap, CSbitmap)
DEF_PROP_OBJ(Plane, Color, Color, CScolor) DEF_PROP_OBJ_VAL(Plane, Color, Color, CScolor)
DEF_PROP_OBJ(Plane, Tone, Tone, CStone) DEF_PROP_OBJ_VAL(Plane, Tone, Tone, CStone)
DEF_PROP_I(Plane, OX) DEF_PROP_I(Plane, OX)
DEF_PROP_I(Plane, OY) DEF_PROP_I(Plane, OY)

View File

@ -36,9 +36,7 @@ MRB_METHOD(spriteInitialize)
setPrivateData(self, s, SpriteType); setPrivateData(self, s, SpriteType);
/* Wrap property objects */ /* Wrap property objects */
s->setSrcRect(new Rect); s->initDynAttribs();
s->setColor(new Color);
s->setTone(new Tone);
wrapProperty(mrb, self, s->getSrcRect(), CSsrc_rect, RectType); wrapProperty(mrb, self, s->getSrcRect(), CSsrc_rect, RectType);
wrapProperty(mrb, self, s->getColor(), CScolor, ColorType); wrapProperty(mrb, self, s->getColor(), CScolor, ColorType);
@ -47,10 +45,10 @@ MRB_METHOD(spriteInitialize)
return self; return self;
} }
DEF_PROP_OBJ_NIL(Sprite, Bitmap, Bitmap, CSbitmap) DEF_PROP_OBJ_REF(Sprite, Bitmap, Bitmap, CSbitmap)
DEF_PROP_OBJ(Sprite, Rect, SrcRect, CSsrc_rect) DEF_PROP_OBJ_VAL(Sprite, Rect, SrcRect, CSsrc_rect)
DEF_PROP_OBJ(Sprite, Color, Color, CScolor) DEF_PROP_OBJ_VAL(Sprite, Color, Color, CScolor)
DEF_PROP_OBJ(Sprite, Tone, Tone, CStone) DEF_PROP_OBJ_VAL(Sprite, Tone, Tone, CStone)
DEF_PROP_I(Sprite, X) DEF_PROP_I(Sprite, X)
DEF_PROP_I(Sprite, Y) DEF_PROP_I(Sprite, Y)

View File

@ -125,10 +125,10 @@ MRB_METHOD(tilemapGetViewport)
return getProperty(mrb, self, CSviewport); return getProperty(mrb, self, CSviewport);
} }
DEF_PROP_OBJ(Tilemap, Bitmap, Tileset, CStileset) DEF_PROP_OBJ_REF(Tilemap, Bitmap, Tileset, CStileset)
DEF_PROP_OBJ(Tilemap, Table, MapData, CSmap_data) DEF_PROP_OBJ_REF(Tilemap, Table, MapData, CSmap_data)
DEF_PROP_OBJ(Tilemap, Table, FlashData, CSflash_data) DEF_PROP_OBJ_REF(Tilemap, Table, FlashData, CSflash_data)
DEF_PROP_OBJ(Tilemap, Table, Priorities, CSpriorities) DEF_PROP_OBJ_REF(Tilemap, Table, Priorities, CSpriorities)
DEF_PROP_B(Tilemap, Visible) DEF_PROP_B(Tilemap, Visible)

View File

@ -57,9 +57,7 @@ MRB_METHOD(viewportInitialize)
setPrivateData(self, v, ViewportType); setPrivateData(self, v, ViewportType);
/* Wrap property objects */ /* Wrap property objects */
v->setRect(new Rect(*v->getRect())); v->initDynAttribs();
v->setColor(new Color);
v->setTone(new Tone);
wrapProperty(mrb, self, v->getRect(), CSrect, RectType); wrapProperty(mrb, self, v->getRect(), CSrect, RectType);
wrapProperty(mrb, self, v->getColor(), CScolor, ColorType); wrapProperty(mrb, self, v->getColor(), CScolor, ColorType);
@ -68,9 +66,9 @@ MRB_METHOD(viewportInitialize)
return self; return self;
} }
DEF_PROP_OBJ(Viewport, Rect, Rect, CSrect) DEF_PROP_OBJ_VAL(Viewport, Rect, Rect, CSrect)
DEF_PROP_OBJ(Viewport, Color, Color, CScolor) DEF_PROP_OBJ_VAL(Viewport, Color, Color, CScolor)
DEF_PROP_OBJ(Viewport, Tone, Tone, CStone) DEF_PROP_OBJ_VAL(Viewport, Tone, Tone, CStone)
DEF_PROP_I(Viewport, OX) DEF_PROP_I(Viewport, OX)
DEF_PROP_I(Viewport, OY) DEF_PROP_I(Viewport, OY)

View File

@ -32,7 +32,7 @@ MRB_METHOD(windowInitialize)
setPrivateData(self, w, WindowType); setPrivateData(self, w, WindowType);
w->setCursorRect(new Rect); w->initDynAttribs();
wrapProperty(mrb, self, w->getCursorRect(), CScursor_rect, RectType); wrapProperty(mrb, self, w->getCursorRect(), CScursor_rect, RectType);
return self; return self;
@ -47,9 +47,9 @@ MRB_METHOD(windowUpdate)
return mrb_nil_value(); return mrb_nil_value();
} }
DEF_PROP_OBJ_NIL(Window, Bitmap, Windowskin, CSwindowskin) DEF_PROP_OBJ_REF(Window, Bitmap, Windowskin, CSwindowskin)
DEF_PROP_OBJ_NIL(Window, Bitmap, Contents, CScontents) DEF_PROP_OBJ_REF(Window, Bitmap, Contents, CScontents)
DEF_PROP_OBJ(Window, Rect, CursorRect, CScursor_rect) DEF_PROP_OBJ_VAL(Window, Rect, CursorRect, CScursor_rect)
DEF_PROP_B(Window, Stretch) DEF_PROP_B(Window, Stretch)
DEF_PROP_B(Window, Active) DEF_PROP_B(Window, Active)