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"
|
2013-10-09 10:30:33 +00:00
|
|
|
#include "sharedstate.h"
|
2013-09-01 14:27:21 +00:00
|
|
|
#include "binding-util.h"
|
2014-07-15 10:34:58 +00:00
|
|
|
#include "binding-types.h"
|
2013-09-01 14:27:21 +00:00
|
|
|
#include "exception.h"
|
|
|
|
|
2019-05-29 17:56:04 +00:00
|
|
|
#ifdef __ANDROID__
|
|
|
|
extern "C" {
|
|
|
|
void sendMessageJNI(int, int);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
RB_METHOD(graphicsUpdate)
|
|
|
|
{
|
|
|
|
RB_UNUSED_PARAM;
|
|
|
|
|
2013-10-09 10:30:33 +00:00
|
|
|
shState->graphics().update();
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
RB_METHOD(graphicsFreeze)
|
|
|
|
{
|
|
|
|
RB_UNUSED_PARAM;
|
|
|
|
|
2013-10-09 10:30:33 +00:00
|
|
|
shState->graphics().freeze();
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
RB_METHOD(graphicsTransition)
|
|
|
|
{
|
|
|
|
RB_UNUSED_PARAM;
|
|
|
|
|
|
|
|
int duration = 8;
|
2015-06-10 11:23:39 +00:00
|
|
|
const char *filename = "";
|
2013-09-01 14:27:21 +00:00
|
|
|
int vague = 40;
|
|
|
|
|
2013-12-20 10:29:12 +00:00
|
|
|
rb_get_args(argc, argv, "|izi", &duration, &filename, &vague RB_ARG_END);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2013-10-09 10:30:33 +00:00
|
|
|
GUARD_EXC( shState->graphics().transition(duration, filename, vague); )
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
RB_METHOD(graphicsFrameReset)
|
|
|
|
{
|
|
|
|
RB_UNUSED_PARAM;
|
|
|
|
|
2013-10-09 10:30:33 +00:00
|
|
|
shState->graphics().frameReset();
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DEF_GRA_PROP_I(PropName) \
|
|
|
|
RB_METHOD(graphics##Get##PropName) \
|
|
|
|
{ \
|
|
|
|
RB_UNUSED_PARAM; \
|
2013-10-09 10:30:33 +00:00
|
|
|
return rb_fix_new(shState->graphics().get##PropName()); \
|
2013-09-01 14:27:21 +00:00
|
|
|
} \
|
|
|
|
RB_METHOD(graphics##Set##PropName) \
|
|
|
|
{ \
|
|
|
|
RB_UNUSED_PARAM; \
|
|
|
|
int value; \
|
2013-12-20 10:29:12 +00:00
|
|
|
rb_get_args(argc, argv, "i", &value RB_ARG_END); \
|
2013-10-09 10:30:33 +00:00
|
|
|
shState->graphics().set##PropName(value); \
|
2013-09-01 14:27:21 +00:00
|
|
|
return rb_fix_new(value); \
|
|
|
|
}
|
|
|
|
|
2013-09-24 20:52:42 +00:00
|
|
|
#define DEF_GRA_PROP_B(PropName) \
|
|
|
|
RB_METHOD(graphics##Get##PropName) \
|
|
|
|
{ \
|
|
|
|
RB_UNUSED_PARAM; \
|
2013-10-09 10:30:33 +00:00
|
|
|
return rb_bool_new(shState->graphics().get##PropName()); \
|
2013-09-24 20:52:42 +00:00
|
|
|
} \
|
|
|
|
RB_METHOD(graphics##Set##PropName) \
|
|
|
|
{ \
|
|
|
|
RB_UNUSED_PARAM; \
|
|
|
|
bool value; \
|
2013-12-20 10:29:12 +00:00
|
|
|
rb_get_args(argc, argv, "b", &value RB_ARG_END); \
|
2013-10-09 10:30:33 +00:00
|
|
|
shState->graphics().set##PropName(value); \
|
2013-09-24 20:52:42 +00:00
|
|
|
return rb_bool_new(value); \
|
|
|
|
}
|
|
|
|
|
2014-04-11 11:34:19 +00:00
|
|
|
RB_METHOD(graphicsWidth)
|
|
|
|
{
|
|
|
|
RB_UNUSED_PARAM;
|
|
|
|
|
|
|
|
return rb_fix_new(shState->graphics().width());
|
|
|
|
}
|
|
|
|
|
|
|
|
RB_METHOD(graphicsHeight)
|
|
|
|
{
|
|
|
|
RB_UNUSED_PARAM;
|
|
|
|
|
|
|
|
return rb_fix_new(shState->graphics().height());
|
|
|
|
}
|
|
|
|
|
2014-07-15 10:34:58 +00:00
|
|
|
RB_METHOD(graphicsWait)
|
|
|
|
{
|
|
|
|
RB_UNUSED_PARAM;
|
|
|
|
|
|
|
|
int duration;
|
|
|
|
rb_get_args(argc, argv, "i", &duration RB_ARG_END);
|
|
|
|
|
|
|
|
shState->graphics().wait(duration);
|
|
|
|
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
RB_METHOD(graphicsFadeout)
|
|
|
|
{
|
|
|
|
RB_UNUSED_PARAM;
|
|
|
|
|
|
|
|
int duration;
|
|
|
|
rb_get_args(argc, argv, "i", &duration RB_ARG_END);
|
|
|
|
|
|
|
|
shState->graphics().fadeout(duration);
|
|
|
|
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
RB_METHOD(graphicsFadein)
|
|
|
|
{
|
|
|
|
RB_UNUSED_PARAM;
|
|
|
|
|
|
|
|
int duration;
|
|
|
|
rb_get_args(argc, argv, "i", &duration RB_ARG_END);
|
|
|
|
|
|
|
|
shState->graphics().fadein(duration);
|
|
|
|
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2014-07-16 03:27:16 +00:00
|
|
|
void bitmapInitProps(Bitmap *b, VALUE self);
|
|
|
|
|
2014-07-15 10:34:58 +00:00
|
|
|
RB_METHOD(graphicsSnapToBitmap)
|
|
|
|
{
|
|
|
|
RB_UNUSED_PARAM;
|
|
|
|
|
|
|
|
Bitmap *result = 0;
|
|
|
|
GUARD_EXC( result = shState->graphics().snapToBitmap(); );
|
|
|
|
|
2014-07-16 03:27:16 +00:00
|
|
|
VALUE obj = wrapObject(result, BitmapType);
|
|
|
|
bitmapInitProps(result, obj);
|
|
|
|
|
|
|
|
return obj;
|
2014-07-15 10:34:58 +00:00
|
|
|
}
|
|
|
|
|
2014-08-24 05:20:44 +00:00
|
|
|
RB_METHOD(graphicsResizeScreen)
|
|
|
|
{
|
|
|
|
RB_UNUSED_PARAM;
|
|
|
|
|
|
|
|
int width, height;
|
|
|
|
rb_get_args(argc, argv, "ii", &width, &height RB_ARG_END);
|
|
|
|
|
|
|
|
shState->graphics().resizeScreen(width, height);
|
|
|
|
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2014-08-24 05:36:19 +00:00
|
|
|
RB_METHOD(graphicsReset)
|
|
|
|
{
|
|
|
|
RB_UNUSED_PARAM;
|
|
|
|
|
|
|
|
shState->graphics().reset();
|
|
|
|
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2015-10-30 15:01:36 +00:00
|
|
|
RB_METHOD(graphicsPlayMovie)
|
|
|
|
{
|
|
|
|
RB_UNUSED_PARAM;
|
|
|
|
|
|
|
|
const char *filename;
|
|
|
|
rb_get_args(argc, argv, "z", &filename RB_ARG_END);
|
|
|
|
|
|
|
|
shState->graphics().playMovie(filename);
|
|
|
|
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2014-08-28 21:11:10 +00:00
|
|
|
DEF_GRA_PROP_I(FrameRate)
|
|
|
|
DEF_GRA_PROP_I(FrameCount)
|
2014-08-15 21:01:25 +00:00
|
|
|
DEF_GRA_PROP_I(Brightness)
|
|
|
|
|
2013-09-24 20:52:42 +00:00
|
|
|
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) \
|
|
|
|
{ \
|
|
|
|
_rb_define_module_function(module, prop_name_s, graphics##Get##PropName); \
|
|
|
|
_rb_define_module_function(module, prop_name_s "=", graphics##Set##PropName); \
|
|
|
|
}
|
|
|
|
|
2019-05-29 17:56:04 +00:00
|
|
|
#ifdef __ANDROID__
|
|
|
|
RB_METHOD(graphicsSendMessage)
|
|
|
|
{
|
|
|
|
RB_UNUSED_PARAM;
|
|
|
|
|
|
|
|
int typ = 0;
|
|
|
|
int msg = 0;
|
|
|
|
|
|
|
|
rb_get_args(argc, argv, "ii", &typ, &msg RB_ARG_END);
|
|
|
|
|
|
|
|
sendMessageJNI(typ, msg);
|
|
|
|
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
RB_METHOD(graphicsSetOverlay)
|
|
|
|
{
|
|
|
|
RB_UNUSED_PARAM;
|
|
|
|
|
|
|
|
int id = 0;
|
|
|
|
|
|
|
|
rb_get_args(argc, argv, "i", &id RB_ARG_END);
|
|
|
|
|
|
|
|
shState->graphics().setOverlay(id);
|
|
|
|
|
|
|
|
sendMessageJNI(705, id);
|
|
|
|
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
void graphicsBindingInit()
|
|
|
|
{
|
|
|
|
VALUE module = rb_define_module("Graphics");
|
|
|
|
|
|
|
|
_rb_define_module_function(module, "update", graphicsUpdate);
|
|
|
|
_rb_define_module_function(module, "freeze", graphicsFreeze);
|
|
|
|
_rb_define_module_function(module, "transition", graphicsTransition);
|
|
|
|
_rb_define_module_function(module, "frame_reset", graphicsFrameReset);
|
|
|
|
|
2014-08-24 05:36:19 +00:00
|
|
|
_rb_define_module_function(module, "__reset__", graphicsReset);
|
|
|
|
|
2019-05-29 17:56:04 +00:00
|
|
|
#ifdef __ANDROID__
|
|
|
|
_rb_define_module_function(module, "send_message", graphicsSendMessage);
|
|
|
|
_rb_define_module_function(module, "set_overlay", graphicsSetOverlay);
|
|
|
|
#endif
|
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
INIT_GRA_PROP_BIND( FrameRate, "frame_rate" );
|
|
|
|
INIT_GRA_PROP_BIND( FrameCount, "frame_count" );
|
|
|
|
|
2014-08-28 21:11:10 +00:00
|
|
|
if (rgssVer >= 2)
|
|
|
|
{
|
2014-07-15 10:34:58 +00:00
|
|
|
_rb_define_module_function(module, "width", graphicsWidth);
|
2014-04-11 11:34:19 +00:00
|
|
|
_rb_define_module_function(module, "height", graphicsHeight);
|
2014-07-15 10:34:58 +00:00
|
|
|
_rb_define_module_function(module, "wait", graphicsWait);
|
|
|
|
_rb_define_module_function(module, "fadeout", graphicsFadeout);
|
|
|
|
_rb_define_module_function(module, "fadein", graphicsFadein);
|
|
|
|
_rb_define_module_function(module, "snap_to_bitmap", graphicsSnapToBitmap);
|
2014-08-24 05:20:44 +00:00
|
|
|
_rb_define_module_function(module, "resize_screen", graphicsResizeScreen);
|
2014-08-15 21:01:25 +00:00
|
|
|
|
|
|
|
INIT_GRA_PROP_BIND( Brightness, "brightness" );
|
2014-08-28 21:11:10 +00:00
|
|
|
}
|
2014-04-11 11:34:19 +00:00
|
|
|
|
2015-10-30 15:01:36 +00:00
|
|
|
if (rgssVer >= 3)
|
|
|
|
{
|
|
|
|
_rb_define_module_function(module, "play_movie", graphicsPlayMovie);
|
|
|
|
}
|
|
|
|
|
2013-09-24 20:52:42 +00:00
|
|
|
INIT_GRA_PROP_BIND( Fullscreen, "fullscreen" );
|
|
|
|
INIT_GRA_PROP_BIND( ShowCursor, "show_cursor" );
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|