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

122 lines
3.1 KiB
C++
Raw Normal View History

2013-09-01 14:27:21 +00:00
/*
** graphics-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 "graphics.h"
#include "sharedstate.h"
2013-09-01 14:27:21 +00:00
#include "binding-util.h"
#include "exception.h"
MRB_FUNCTION(graphicsUpdate)
2013-09-01 14:27:21 +00:00
{
MRB_FUN_UNUSED_PARAM;
2013-09-01 14:27:21 +00:00
shState->graphics().update();
2013-09-01 14:27:21 +00:00
return mrb_nil_value();
}
MRB_FUNCTION(graphicsFreeze)
2013-09-01 14:27:21 +00:00
{
MRB_FUN_UNUSED_PARAM;
2013-09-01 14:27:21 +00:00
shState->graphics().freeze();
2013-09-01 14:27:21 +00:00
return mrb_nil_value();
}
MRB_FUNCTION(graphicsTransition)
2013-09-01 14:27:21 +00:00
{
mrb_int duration = 8;
const char *filename = 0;
mrb_int vague = 40;
mrb_get_args(mrb, "|izi", &duration, &filename, &vague);
GUARD_EXC( shState->graphics().transition(duration, filename, vague); )
2013-09-01 14:27:21 +00:00
return mrb_nil_value();
}
MRB_FUNCTION(graphicsFrameReset)
2013-09-01 14:27:21 +00:00
{
MRB_FUN_UNUSED_PARAM;
2013-09-01 14:27:21 +00:00
shState->graphics().frameReset();
2013-09-01 14:27:21 +00:00
return mrb_nil_value();
}
#define DEF_GRA_PROP_I(PropName) \
MRB_FUNCTION(graphics##Get##PropName) \
2013-09-01 14:27:21 +00:00
{ \
MRB_FUN_UNUSED_PARAM; \
return mrb_fixnum_value(shState->graphics().get##PropName()); \
2013-09-01 14:27:21 +00:00
} \
MRB_FUNCTION(graphics##Set##PropName) \
2013-09-01 14:27:21 +00:00
{ \
mrb_int value; \
mrb_get_args(mrb, "i", &value); \
shState->graphics().set##PropName(value); \
return mrb_fixnum_value(value); \
}
#define DEF_GRA_PROP_B(PropName) \
MRB_FUNCTION(graphics##Get##PropName) \
{ \
MRB_FUN_UNUSED_PARAM; \
return mrb_bool_value(shState->graphics().get##PropName()); \
} \
MRB_FUNCTION(graphics##Set##PropName) \
{ \
mrb_bool value; \
mrb_get_args(mrb, "b", &value); \
shState->graphics().set##PropName(value); \
return mrb_bool_value(value); \
2013-09-01 14:27:21 +00:00
}
DEF_GRA_PROP_I(FrameRate)
DEF_GRA_PROP_I(FrameCount)
DEF_GRA_PROP_B(Fullscreen)
DEF_GRA_PROP_B(ShowCursor)
2013-09-01 14:27:21 +00:00
#define INIT_GRA_PROP_BIND(PropName, prop_name_s) \
{ \
mrb_define_module_function(mrb, module, prop_name_s, graphics##Get##PropName, MRB_ARGS_NONE()); \
mrb_define_module_function(mrb, module, prop_name_s "=", graphics##Set##PropName, MRB_ARGS_REQ(1)); \
}
void graphicsBindingInit(mrb_state *mrb)
{
RClass *module = mrb_define_module(mrb, "Graphics");
mrb_define_module_function(mrb, module, "update", graphicsUpdate, MRB_ARGS_NONE());
mrb_define_module_function(mrb, module, "freeze", graphicsFreeze, MRB_ARGS_NONE());
mrb_define_module_function(mrb, module, "transition", graphicsTransition, MRB_ARGS_OPT(3));
mrb_define_module_function(mrb, module, "frame_reset", graphicsFrameReset, MRB_ARGS_NONE());
INIT_GRA_PROP_BIND( FrameRate, "frame_rate" );
INIT_GRA_PROP_BIND( FrameCount, "frame_count" );
INIT_GRA_PROP_BIND( Fullscreen, "fullscreen" );
INIT_GRA_PROP_BIND( ShowCursor, "show_cursor" );
2013-09-01 14:27:21 +00:00
}