mkxp-freebird/binding-mruby/viewport-binding.cpp

96 lines
2.5 KiB
C++
Raw Permalink Normal View History

2013-09-01 14:27:21 +00:00
/*
** viewport-binding.cpp
**
** This file is part of mkxp.
**
2021-09-06 18:50:44 +00:00
** Copyright (C) 2021 Amaryllis Kulla <amaryllis.kulla@protonmail.com>
2013-09-01 14:27:21 +00:00
**
** 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 "viewport.h"
#include "disposable-binding.h"
#include "flashable-binding.h"
#include "sceneelement-binding.h"
#include "binding-util.h"
#include "binding-types.h"
DEF_TYPE(Viewport);
MRB_METHOD(viewportInitialize)
{
Viewport *v;
if (mrb->c->ci->argc == 1)
{
/* The rect arg is only used to init the viewport,
* and does NOT replace its 'rect' property */
mrb_value rectObj;
Rect *rect;
mrb_get_args(mrb, "o", &rectObj);
rect = getPrivateDataCheck<Rect>(mrb, rectObj, RectType);
v = new Viewport(rect);
}
else
{
mrb_int x, y, width, height;
mrb_get_args(mrb, "iiii", &x, &y, &width, &height);
v = new Viewport(x, y, width, height);
}
setPrivateData(self, v, ViewportType);
2013-09-01 14:27:21 +00:00
/* Wrap property objects */
v->initDynAttribs();
2013-09-01 14:27:21 +00:00
wrapProperty(mrb, self, &v->getRect(), CSrect, RectType);
wrapProperty(mrb, self, &v->getColor(), CScolor, ColorType);
wrapProperty(mrb, self, &v->getTone(), CStone, ToneType);
2013-09-01 14:27:21 +00:00
return self;
}
DEF_PROP_OBJ_VAL(Viewport, Rect, Rect, CSrect)
DEF_PROP_OBJ_VAL(Viewport, Color, Color, CScolor)
DEF_PROP_OBJ_VAL(Viewport, Tone, Tone, CStone)
2013-09-01 14:27:21 +00:00
DEF_PROP_I(Viewport, OX)
DEF_PROP_I(Viewport, OY)
void
viewportBindingInit(mrb_state *mrb)
{
RClass *klass = defineClass(mrb, "Viewport");
2013-09-01 14:27:21 +00:00
disposableBindingInit <Viewport>(mrb, klass);
flashableBindingInit <Viewport>(mrb, klass);
sceneElementBindingInit<Viewport>(mrb, klass);
mrb_define_method(mrb, klass, "initialize", viewportInitialize, MRB_ARGS_REQ(1) | MRB_ARGS_OPT(3));
INIT_PROP_BIND( Viewport, Rect, "rect" );
INIT_PROP_BIND( Viewport, OX, "ox" );
INIT_PROP_BIND( Viewport, OY, "oy" );
INIT_PROP_BIND( Viewport, Color, "color" );
INIT_PROP_BIND( Viewport, Tone, "tone" );
mrb_define_method(mrb, klass, "inspect", inspectObject, MRB_ARGS_NONE());
}