Font: Add missing RGSS2+ props basic plumbing (and bind most in MRI)

No core implementations yet for shadow and outline color.
This commit is contained in:
Jonas Kulla 2014-08-15 23:18:02 +02:00
parent 36eea09c7e
commit 9003f9a435
3 changed files with 124 additions and 22 deletions

View File

@ -61,6 +61,11 @@ RB_METHOD(fontInitialize)
f->setColor(new Color(*f->getColor())); f->setColor(new Color(*f->getColor()));
wrapProperty(self, f->getColor(), "color", ColorType); wrapProperty(self, f->getColor(), "color", ColorType);
#ifdef RGSS3
f->setOutColor(new Color(*f->getOutColor()));
wrapProperty(self, f->getOutColor(), "out_color", ColorType);
#endif
if (NIL_P(name)) if (NIL_P(name))
name = rb_iv_get(rb_obj_class(self), "default_name"); name = rb_iv_get(rb_obj_class(self), "default_name");
@ -87,6 +92,11 @@ RB_METHOD(fontInitializeCopy)
f->setColor(new Color(*f->getColor())); f->setColor(new Color(*f->getColor()));
wrapProperty(self, f->getColor(), "color", ColorType); wrapProperty(self, f->getColor(), "color", ColorType);
#ifdef RGSS3
f->setOutColor(new Color(*f->getOutColor()));
wrapProperty(self, f->getOutColor(), "out_color", ColorType);
#endif
return self; return self;
} }
@ -158,6 +168,15 @@ DEF_PROP_B(Font, Bold)
DEF_PROP_B(Font, Italic) DEF_PROP_B(Font, Italic)
DEF_PROP_OBJ(Font, Color, Color, "color") DEF_PROP_OBJ(Font, Color, Color, "color")
#ifdef RGSS2
DEF_PROP_B(Font, Shadow)
#endif
#ifdef RGSS3
DEF_PROP_B(Font, Outline)
DEF_PROP_OBJ(Font, Color, OutColor, "out_color")
#endif
#define DEF_KLASS_PROP(Klass, type, PropName, param_t_s, value_fun) \ #define DEF_KLASS_PROP(Klass, type, PropName, param_t_s, value_fun) \
RB_METHOD(Klass##Get##PropName) \ RB_METHOD(Klass##Get##PropName) \
{ \ { \
@ -177,6 +196,16 @@ DEF_KLASS_PROP(Font, int, DefaultSize, "i", rb_fix_new)
DEF_KLASS_PROP(Font, bool, DefaultBold, "b", rb_bool_new) DEF_KLASS_PROP(Font, bool, DefaultBold, "b", rb_bool_new)
DEF_KLASS_PROP(Font, bool, DefaultItalic, "b", rb_bool_new) DEF_KLASS_PROP(Font, bool, DefaultItalic, "b", rb_bool_new)
#ifdef RGSS2
DEF_KLASS_PROP(Font, bool, DefaultShadow, "b", rb_bool_new)
#endif
#ifdef RGSS3
DEF_KLASS_PROP(Font, bool, DefaultOutline, "b", rb_bool_new)
// TODO: impl Get/SetDefaultOutColor
#endif
RB_METHOD(FontGetDefaultName) RB_METHOD(FontGetDefaultName)
{ {
RB_UNUSED_PARAM; RB_UNUSED_PARAM;
@ -239,6 +268,14 @@ fontBindingInit()
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");
#ifdef RGSS2
INIT_KLASS_PROP_BIND(Font, DefaultShadow, "default_shadow");
#endif
#ifdef RGSS3
INIT_KLASS_PROP_BIND(Font, DefaultOutline, "default_outline");
#endif
rb_define_class_method(klass, "exist?", fontDoesExist); rb_define_class_method(klass, "exist?", fontDoesExist);
_rb_define_method(klass, "initialize", fontInitialize); _rb_define_method(klass, "initialize", fontInitialize);
@ -249,4 +286,13 @@ fontBindingInit()
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");
#ifdef RGSS2
INIT_PROP_BIND(Font, Shadow, "shadow");
#endif
#ifdef RGSS3
INIT_PROP_BIND(Font, Outline, "outline");
INIT_PROP_BIND(Font, OutColor, "out_color");
#endif
} }

View File

@ -198,17 +198,25 @@ struct FontPrivate
int size; int size;
bool bold; bool bold;
bool italic; bool italic;
bool outline;
bool shadow;
Color *color; Color *color;
Color *outColor;
Color colorTmp; Color colorTmp;
Color outColorTmp;
static std::string defaultName; static std::string defaultName;
static int defaultSize; static int defaultSize;
static bool defaultBold; static bool defaultBold;
static bool defaultItalic; static bool defaultItalic;
static bool defaultOutline;
static bool defaultShadow;
static Color *defaultColor; static Color *defaultColor;
static Color *defaultOutColor;
static Color defaultColorTmp; static Color defaultColorTmp;
static Color defaultOutColorTmp;
/* The actual font is opened as late as possible /* The actual font is opened as late as possible
* (when it is queried by a Bitmap), prior it is * (when it is queried by a Bitmap), prior it is
@ -221,8 +229,12 @@ struct FontPrivate
size(size ? size : defaultSize), size(size ? size : defaultSize),
bold(defaultBold), bold(defaultBold),
italic(defaultItalic), italic(defaultItalic),
outline(defaultOutline),
shadow(defaultShadow),
color(&colorTmp), color(&colorTmp),
outColor(&outColorTmp),
colorTmp(*defaultColor), colorTmp(*defaultColor),
outColorTmp(*defaultOutColor),
sdlFont(0) sdlFont(0)
{} {}
@ -231,8 +243,12 @@ struct FontPrivate
size(other.size), size(other.size),
bold(other.bold), bold(other.bold),
italic(other.italic), italic(other.italic),
outline(other.outline),
shadow(other.shadow),
color(&colorTmp), color(&colorTmp),
outColor(&outColorTmp),
colorTmp(*other.color), colorTmp(*other.color),
outColorTmp(*other.outColor),
sdlFont(other.sdlFont) sdlFont(other.sdlFont)
{} {}
}; };
@ -241,9 +257,13 @@ std::string FontPrivate::defaultName = "Arial";
int FontPrivate::defaultSize = 22; int FontPrivate::defaultSize = 22;
bool FontPrivate::defaultBold = false; bool FontPrivate::defaultBold = false;
bool FontPrivate::defaultItalic = false; bool FontPrivate::defaultItalic = false;
bool FontPrivate::defaultOutline = false;
bool FontPrivate::defaultShadow = true;
Color *FontPrivate::defaultColor = &FontPrivate::defaultColorTmp; Color *FontPrivate::defaultColor = &FontPrivate::defaultColorTmp;
Color *FontPrivate::defaultOutColor = &FontPrivate::defaultOutColorTmp;
Color FontPrivate::defaultColorTmp(255, 255, 255, 255); Color FontPrivate::defaultColorTmp(255, 255, 255, 255);
Color FontPrivate::defaultOutColorTmp(0, 0, 0, 128);
bool Font::doesExist(const char *name) bool Font::doesExist(const char *name)
{ {
@ -304,11 +324,29 @@ DEF_ATTR_SIMPLE(Font, Bold, bool, p->bold)
DEF_ATTR_SIMPLE(Font, Italic, bool, p->italic) DEF_ATTR_SIMPLE(Font, Italic, bool, p->italic)
DEF_ATTR_SIMPLE(Font, Color, Color*, p->color) DEF_ATTR_SIMPLE(Font, Color, Color*, p->color)
#ifdef RGSS2
DEF_ATTR_SIMPLE(Font, Shadow, bool, p->shadow)
#endif
#ifdef RGSS3
DEF_ATTR_SIMPLE(Font, Outline, bool, p->outline)
DEF_ATTR_SIMPLE(Font, OutColor, Color*, p->outColor)
#endif
DEF_ATTR_SIMPLE_STATIC(Font, DefaultSize, int, FontPrivate::defaultSize) DEF_ATTR_SIMPLE_STATIC(Font, DefaultSize, int, FontPrivate::defaultSize)
DEF_ATTR_SIMPLE_STATIC(Font, DefaultBold, bool, FontPrivate::defaultBold) DEF_ATTR_SIMPLE_STATIC(Font, DefaultBold, bool, FontPrivate::defaultBold)
DEF_ATTR_SIMPLE_STATIC(Font, DefaultItalic, bool, FontPrivate::defaultItalic) DEF_ATTR_SIMPLE_STATIC(Font, DefaultItalic, bool, FontPrivate::defaultItalic)
DEF_ATTR_SIMPLE_STATIC(Font, DefaultColor, Color*, FontPrivate::defaultColor) DEF_ATTR_SIMPLE_STATIC(Font, DefaultColor, Color*, FontPrivate::defaultColor)
#ifdef RGSS2
DEF_ATTR_SIMPLE_STATIC(Font, DefaultShadow, bool, FontPrivate::defaultShadow)
#endif
#ifdef RGSS3
DEF_ATTR_SIMPLE_STATIC(Font, DefaultOutline, bool, FontPrivate::defaultOutline)
DEF_ATTR_SIMPLE_STATIC(Font, DefaultOutColor, Color*, FontPrivate::defaultOutColor)
#endif
const char *Font::getDefaultName() const char *Font::getDefaultName()
{ {
return FontPrivate::defaultName.c_str(); return FontPrivate::defaultName.c_str();

View File

@ -90,12 +90,30 @@ public:
DECL_ATTR( Italic, bool ) DECL_ATTR( Italic, bool )
DECL_ATTR( Color, Color* ) DECL_ATTR( Color, Color* )
#ifdef RGSS2
DECL_ATTR( Shadow, bool )
#endif
#ifdef RGSS3
DECL_ATTR( Outline, bool )
DECL_ATTR( OutColor, Color* )
#endif
DECL_ATTR_STATIC( DefaultName, const char* ) DECL_ATTR_STATIC( DefaultName, const char* )
DECL_ATTR_STATIC( DefaultSize, int ) DECL_ATTR_STATIC( DefaultSize, int )
DECL_ATTR_STATIC( DefaultBold, bool ) DECL_ATTR_STATIC( DefaultBold, bool )
DECL_ATTR_STATIC( DefaultItalic, bool ) DECL_ATTR_STATIC( DefaultItalic, bool )
DECL_ATTR_STATIC( DefaultColor, Color* ) DECL_ATTR_STATIC( DefaultColor, Color* )
#ifdef RGSS2
DECL_ATTR_STATIC( DefaultShadow, bool )
#endif
#ifdef RGSS3
DECL_ATTR_STATIC( DefaultOutline, bool )
DECL_ATTR_STATIC( DefaultOutColor, Color* )
#endif
/* internal */ /* internal */
_TTF_Font *getSdlFont(); _TTF_Font *getSdlFont();