mirror of
https://github.com/mkxp-z/mkxp-z.git
synced 2025-04-21 21:52:04 +02:00
OLD_RUBY -> RAPI_MAJOR/RAPI_MINOR/RAPI_TEENY/RAPI_FULL
This commit is contained in:
parent
41e604b992
commit
1434e9e313
20 changed files with 1950 additions and 2199 deletions
|
@ -38,7 +38,7 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <ruby.h>
|
#include <ruby.h>
|
||||||
|
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_FULL >= 190
|
||||||
#include <ruby/encoding.h>
|
#include <ruby/encoding.h>
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -369,7 +369,7 @@ RB_METHOD(mriRgssMain) {
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
VALUE exc = Qnil;
|
VALUE exc = Qnil;
|
||||||
#if RUBYCOMPAT < 270
|
#if RAPI_FULL < 270
|
||||||
rb_rescue2((VALUE(*)(ANYARGS))rgssMainCb, rb_block_proc(),
|
rb_rescue2((VALUE(*)(ANYARGS))rgssMainCb, rb_block_proc(),
|
||||||
(VALUE(*)(ANYARGS))rgssMainRescue, (VALUE)&exc, rb_eException,
|
(VALUE(*)(ANYARGS))rgssMainRescue, (VALUE)&exc, rb_eException,
|
||||||
(VALUE)0);
|
(VALUE)0);
|
||||||
|
@ -431,7 +431,7 @@ RB_METHOD(_kernelCaller) {
|
||||||
return trace;
|
return trace;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_FULL > 187
|
||||||
static VALUE newStringUTF8(const char *string, long length) {
|
static VALUE newStringUTF8(const char *string, long length) {
|
||||||
return rb_enc_str_new(string, length, rb_utf8_encoding());
|
return rb_enc_str_new(string, length, rb_utf8_encoding());
|
||||||
}
|
}
|
||||||
|
@ -571,7 +571,7 @@ static void runRMXPScripts(BacktraceData &btData) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
#if defined(OLD_RUBY) && defined(NO_CONSOLE)
|
#if RAPI_FULL < 200 && defined(NO_CONSOLE)
|
||||||
VALUE iostr = rb_str_new2(NULL_IO);
|
VALUE iostr = rb_str_new2(NULL_IO);
|
||||||
// Sysinit isn't a thing yet, so send io to /dev/null instead
|
// Sysinit isn't a thing yet, so send io to /dev/null instead
|
||||||
rb_funcall(rb_gv_get("$stderr"), rb_intern("reopen"), 1, iostr);
|
rb_funcall(rb_gv_get("$stderr"), rb_intern("reopen"), 1, iostr);
|
||||||
|
@ -694,7 +694,7 @@ static void showExc(VALUE exc, const BacktraceData &btData) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mriBindingExecute() {
|
static void mriBindingExecute() {
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_FULL > 200
|
||||||
/* Normally only a ruby executable would do a sysinit,
|
/* Normally only a ruby executable would do a sysinit,
|
||||||
* but not doing it will lead to crashes due to closed
|
* but not doing it will lead to crashes due to closed
|
||||||
* stdio streams on some platforms (eg. Windows) */
|
* stdio streams on some platforms (eg. Windows) */
|
||||||
|
@ -750,7 +750,7 @@ static void mriBindingExecute() {
|
||||||
runRMXPScripts(btData);
|
runRMXPScripts(btData);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_FULL > 187
|
||||||
VALUE exc = rb_errinfo();
|
VALUE exc = rb_errinfo();
|
||||||
#else
|
#else
|
||||||
VALUE exc = rb_gv_get("$!");
|
VALUE exc = rb_gv_get("$!");
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
#include "binding-util.h"
|
#include "binding-util.h"
|
||||||
|
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_FULL > 187
|
||||||
DECL_TYPE(Table);
|
DECL_TYPE(Table);
|
||||||
DECL_TYPE(Rect);
|
DECL_TYPE(Rect);
|
||||||
DECL_TYPE(Color);
|
DECL_TYPE(Color);
|
||||||
|
@ -59,7 +59,7 @@ DECL_TYPE(MiniFFI);
|
||||||
|
|
||||||
#ifdef HAVE_DISCORDSDK
|
#ifdef HAVE_DISCORDSDK
|
||||||
|
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_FULL > 187
|
||||||
DECL_TYPE(DCActivity);
|
DECL_TYPE(DCActivity);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -21,305 +21,275 @@
|
||||||
|
|
||||||
#include "binding-util.h"
|
#include "binding-util.h"
|
||||||
|
|
||||||
#include "sharedstate.h"
|
|
||||||
#include "exception.h"
|
#include "exception.h"
|
||||||
|
#include "sharedstate.h"
|
||||||
#include "src/util.h"
|
#include "src/util.h"
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
RbData *getRbData()
|
RbData *getRbData() { return static_cast<RbData *>(shState->bindingData()); }
|
||||||
{
|
|
||||||
return static_cast<RbData*>(shState->bindingData());
|
struct {
|
||||||
|
RbException id;
|
||||||
|
const char *name;
|
||||||
|
} static customExc[] = {
|
||||||
|
{MKXP, "MKXPError"}, {PHYSFS, "PHYSFSError"}, {SDL, "SDLError"}};
|
||||||
|
|
||||||
|
RbData::RbData() {
|
||||||
|
for (size_t i = 0; i < ARRAY_SIZE(customExc); ++i)
|
||||||
|
exc[customExc[i].id] = rb_define_class(customExc[i].name, rb_eException);
|
||||||
|
|
||||||
|
exc[RGSS] = rb_define_class("RGSSError", rb_eStandardError);
|
||||||
|
exc[Reset] =
|
||||||
|
rb_define_class(rgssVer >= 3 ? "RGSSReset" : "Reset", rb_eException);
|
||||||
|
|
||||||
|
exc[ErrnoENOENT] = rb_const_get(rb_const_get(rb_cObject, rb_intern("Errno")),
|
||||||
|
rb_intern("ENOENT"));
|
||||||
|
exc[IOError] = rb_eIOError;
|
||||||
|
exc[TypeError] = rb_eTypeError;
|
||||||
|
exc[ArgumentError] = rb_eArgError;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct
|
RbData::~RbData() {}
|
||||||
{
|
|
||||||
RbException id;
|
|
||||||
const char *name;
|
|
||||||
} static customExc[] =
|
|
||||||
{
|
|
||||||
{ MKXP, "MKXPError" },
|
|
||||||
{ PHYSFS, "PHYSFSError" },
|
|
||||||
{ SDL, "SDLError" }
|
|
||||||
};
|
|
||||||
|
|
||||||
RbData::RbData()
|
|
||||||
{
|
|
||||||
for (size_t i = 0; i < ARRAY_SIZE(customExc); ++i)
|
|
||||||
exc[customExc[i].id] = rb_define_class(customExc[i].name, rb_eException);
|
|
||||||
|
|
||||||
exc[RGSS] = rb_define_class("RGSSError", rb_eStandardError);
|
|
||||||
exc[Reset] = rb_define_class(rgssVer >= 3 ? "RGSSReset" : "Reset", rb_eException);
|
|
||||||
|
|
||||||
exc[ErrnoENOENT] = rb_const_get(rb_const_get(rb_cObject, rb_intern("Errno")), rb_intern("ENOENT"));
|
|
||||||
exc[IOError] = rb_eIOError;
|
|
||||||
exc[TypeError] = rb_eTypeError;
|
|
||||||
exc[ArgumentError] = rb_eArgError;
|
|
||||||
}
|
|
||||||
|
|
||||||
RbData::~RbData()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Indexed with Exception::Type */
|
/* Indexed with Exception::Type */
|
||||||
static const RbException excToRbExc[] =
|
static const RbException excToRbExc[] = {
|
||||||
{
|
|
||||||
RGSS, /* RGSSError */
|
RGSS, /* RGSSError */
|
||||||
ErrnoENOENT, /* NoFileError */
|
ErrnoENOENT, /* NoFileError */
|
||||||
IOError,
|
IOError,
|
||||||
|
|
||||||
TypeError,
|
TypeError, ArgumentError,
|
||||||
ArgumentError,
|
|
||||||
|
|
||||||
PHYSFS, /* PHYSFSError */
|
PHYSFS, /* PHYSFSError */
|
||||||
SDL, /* SDLError */
|
SDL, /* SDLError */
|
||||||
MKXP /* MKXPError */
|
MKXP /* MKXPError */
|
||||||
};
|
};
|
||||||
|
|
||||||
void raiseRbExc(const Exception &exc)
|
void raiseRbExc(const Exception &exc) {
|
||||||
{
|
RbData *data = getRbData();
|
||||||
RbData *data = getRbData();
|
VALUE excClass = data->exc[excToRbExc[exc.type]];
|
||||||
VALUE excClass = data->exc[excToRbExc[exc.type]];
|
|
||||||
|
|
||||||
rb_raise(excClass, "%s", exc.msg.c_str());
|
rb_raise(excClass, "%s", exc.msg.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void raiseDisposedAccess(VALUE self) {
|
||||||
raiseDisposedAccess(VALUE self)
|
#if RAPI_FULL > 187
|
||||||
{
|
const char *klassName = RTYPEDDATA_TYPE(self)->wrap_struct_name;
|
||||||
#ifndef OLD_RUBY
|
|
||||||
const char *klassName = RTYPEDDATA_TYPE(self)->wrap_struct_name;
|
|
||||||
#else
|
#else
|
||||||
const char *klassName = rb_obj_classname(self);
|
const char *klassName = rb_obj_classname(self);
|
||||||
#endif
|
#endif
|
||||||
char buf[32];
|
char buf[32];
|
||||||
|
|
||||||
strncpy(buf, klassName, sizeof(buf));
|
strncpy(buf, klassName, sizeof(buf));
|
||||||
buf[0] = tolower(buf[0]);
|
buf[0] = tolower(buf[0]);
|
||||||
|
|
||||||
rb_raise(getRbData()->exc[RGSS], "disposed %s", buf);
|
rb_raise(getRbData()->exc[RGSS], "disposed %s", buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int rb_get_args(int argc, VALUE *argv, const char *format, ...) {
|
||||||
rb_get_args(int argc, VALUE *argv, const char *format, ...)
|
char c;
|
||||||
{
|
VALUE *arg = argv;
|
||||||
char c;
|
va_list ap;
|
||||||
VALUE *arg = argv;
|
bool opt = false;
|
||||||
va_list ap;
|
int argI = 0;
|
||||||
bool opt = false;
|
|
||||||
int argI = 0;
|
|
||||||
|
|
||||||
va_start(ap, format);
|
va_start(ap, format);
|
||||||
|
|
||||||
while ((c = *format++))
|
while ((c = *format++)) {
|
||||||
{
|
switch (c) {
|
||||||
switch (c)
|
case '|':
|
||||||
{
|
break;
|
||||||
case '|' :
|
default:
|
||||||
break;
|
// FIXME print num of needed args vs provided
|
||||||
default:
|
if (argc <= argI && !opt)
|
||||||
// FIXME print num of needed args vs provided
|
rb_raise(rb_eArgError, "wrong number of arguments");
|
||||||
if (argc <= argI && !opt)
|
|
||||||
rb_raise(rb_eArgError, "wrong number of arguments");
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argI >= argc)
|
if (argI >= argc)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
switch (c)
|
switch (c) {
|
||||||
{
|
case 'o': {
|
||||||
case 'o' :
|
if (argI >= argc)
|
||||||
{
|
break;
|
||||||
if (argI >= argc)
|
|
||||||
break;
|
|
||||||
|
|
||||||
VALUE *obj = va_arg(ap, VALUE*);
|
VALUE *obj = va_arg(ap, VALUE *);
|
||||||
|
|
||||||
*obj = *arg++;
|
*obj = *arg++;
|
||||||
++argI;
|
++argI;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'S' :
|
case 'S': {
|
||||||
{
|
if (argI >= argc)
|
||||||
if (argI >= argc)
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
VALUE *str = va_arg(ap, VALUE*);
|
VALUE *str = va_arg(ap, VALUE *);
|
||||||
VALUE tmp = *arg;
|
VALUE tmp = *arg;
|
||||||
|
|
||||||
if (!RB_TYPE_P(tmp, RUBY_T_STRING))
|
if (!RB_TYPE_P(tmp, RUBY_T_STRING))
|
||||||
rb_raise(rb_eTypeError, "Argument %d: Expected string", argI);
|
rb_raise(rb_eTypeError, "Argument %d: Expected string", argI);
|
||||||
|
|
||||||
*str = tmp;
|
*str = tmp;
|
||||||
++argI;
|
++argI;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 's' :
|
case 's': {
|
||||||
{
|
if (argI >= argc)
|
||||||
if (argI >= argc)
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
const char **s = va_arg(ap, const char**);
|
const char **s = va_arg(ap, const char **);
|
||||||
int *len = va_arg(ap, int*);
|
int *len = va_arg(ap, int *);
|
||||||
|
|
||||||
VALUE tmp = *arg;
|
VALUE tmp = *arg;
|
||||||
|
|
||||||
if (!RB_TYPE_P(tmp, RUBY_T_STRING))
|
if (!RB_TYPE_P(tmp, RUBY_T_STRING))
|
||||||
rb_raise(rb_eTypeError, "Argument %d: Expected string", argI);
|
rb_raise(rb_eTypeError, "Argument %d: Expected string", argI);
|
||||||
|
|
||||||
*s = RSTRING_PTR(tmp);
|
*s = RSTRING_PTR(tmp);
|
||||||
*len = RSTRING_LEN(tmp);
|
*len = RSTRING_LEN(tmp);
|
||||||
++argI;
|
++argI;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'z' :
|
case 'z': {
|
||||||
{
|
if (argI >= argc)
|
||||||
if (argI >= argc)
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
const char **s = va_arg(ap, const char**);
|
const char **s = va_arg(ap, const char **);
|
||||||
|
|
||||||
VALUE tmp = *arg++;
|
VALUE tmp = *arg++;
|
||||||
|
|
||||||
if (!RB_TYPE_P(tmp, RUBY_T_STRING))
|
if (!RB_TYPE_P(tmp, RUBY_T_STRING))
|
||||||
rb_raise(rb_eTypeError, "Argument %d: Expected string", argI);
|
rb_raise(rb_eTypeError, "Argument %d: Expected string", argI);
|
||||||
|
|
||||||
*s = RSTRING_PTR(tmp);
|
*s = RSTRING_PTR(tmp);
|
||||||
++argI;
|
++argI;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'f' :
|
case 'f': {
|
||||||
{
|
if (argI >= argc)
|
||||||
if (argI >= argc)
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
double *f = va_arg(ap, double*);
|
double *f = va_arg(ap, double *);
|
||||||
VALUE fVal = *arg++;
|
VALUE fVal = *arg++;
|
||||||
|
|
||||||
rb_float_arg(fVal, f, argI);
|
rb_float_arg(fVal, f, argI);
|
||||||
|
|
||||||
++argI;
|
++argI;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'i' :
|
case 'i': {
|
||||||
{
|
if (argI >= argc)
|
||||||
if (argI >= argc)
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
int *i = va_arg(ap, int*);
|
int *i = va_arg(ap, int *);
|
||||||
VALUE iVal = *arg++;
|
VALUE iVal = *arg++;
|
||||||
|
|
||||||
rb_int_arg(iVal, i, argI);
|
rb_int_arg(iVal, i, argI);
|
||||||
|
|
||||||
++argI;
|
++argI;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'b' :
|
case 'b': {
|
||||||
{
|
if (argI >= argc)
|
||||||
if (argI >= argc)
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
bool *b = va_arg(ap, bool*);
|
bool *b = va_arg(ap, bool *);
|
||||||
VALUE bVal = *arg++;
|
VALUE bVal = *arg++;
|
||||||
|
|
||||||
rb_bool_arg(bVal, b, argI);
|
rb_bool_arg(bVal, b, argI);
|
||||||
|
|
||||||
++argI;
|
++argI;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'n' :
|
case 'n': {
|
||||||
{
|
if (argI >= argc)
|
||||||
if (argI >= argc)
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
ID *sym = va_arg(ap, ID*);
|
ID *sym = va_arg(ap, ID *);
|
||||||
|
|
||||||
VALUE symVal = *arg++;
|
VALUE symVal = *arg++;
|
||||||
|
|
||||||
if (!SYMBOL_P(symVal))
|
if (!SYMBOL_P(symVal))
|
||||||
rb_raise(rb_eTypeError, "Argument %d: Expected symbol", argI);
|
rb_raise(rb_eTypeError, "Argument %d: Expected symbol", argI);
|
||||||
|
|
||||||
*sym = SYM2ID(symVal);
|
*sym = SYM2ID(symVal);
|
||||||
++argI;
|
++argI;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case '|' :
|
case '|':
|
||||||
opt = true;
|
opt = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
rb_raise(rb_eFatal, "invalid argument specifier %c", c);
|
rb_raise(rb_eFatal, "invalid argument specifier %c", c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
|
|
||||||
/* Pop remaining arg pointers off
|
/* Pop remaining arg pointers off
|
||||||
* the stack to check for RB_ARG_END */
|
* the stack to check for RB_ARG_END */
|
||||||
format--;
|
format--;
|
||||||
|
|
||||||
while ((c = *format++))
|
while ((c = *format++)) {
|
||||||
{
|
switch (c) {
|
||||||
switch (c)
|
case 'o':
|
||||||
{
|
case 'S':
|
||||||
case 'o' :
|
va_arg(ap, VALUE *);
|
||||||
case 'S' :
|
break;
|
||||||
va_arg(ap, VALUE*);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 's' :
|
case 's':
|
||||||
va_arg(ap, const char**);
|
va_arg(ap, const char **);
|
||||||
va_arg(ap, int*);
|
va_arg(ap, int *);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'z' :
|
case 'z':
|
||||||
va_arg(ap, const char**);
|
va_arg(ap, const char **);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'f' :
|
case 'f':
|
||||||
va_arg(ap, double*);
|
va_arg(ap, double *);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'i' :
|
case 'i':
|
||||||
va_arg(ap, int*);
|
va_arg(ap, int *);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'b' :
|
case 'b':
|
||||||
va_arg(ap, bool*);
|
va_arg(ap, bool *);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME print num of needed args vs provided
|
// FIXME print num of needed args vs provided
|
||||||
if (!c && argc > argI)
|
if (!c && argc > argI)
|
||||||
rb_raise(rb_eArgError, "wrong number of arguments");
|
rb_raise(rb_eArgError, "wrong number of arguments");
|
||||||
|
|
||||||
/* Verify correct termination */
|
/* Verify correct termination */
|
||||||
void *argEnd = va_arg(ap, void*);
|
void *argEnd = va_arg(ap, void *);
|
||||||
(void) argEnd;
|
(void)argEnd;
|
||||||
assert(argEnd == RB_ARG_END_VAL);
|
assert(argEnd == RB_ARG_END_VAL);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
return argI;
|
return argI;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,9 +23,25 @@
|
||||||
#define BINDING_UTIL_H
|
#define BINDING_UTIL_H
|
||||||
|
|
||||||
#include <ruby.h>
|
#include <ruby.h>
|
||||||
|
#ifndef LEGACY_RUBY
|
||||||
|
#include <ruby/version.h>
|
||||||
|
#else
|
||||||
|
#include <version.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "exception.h"
|
#include "exception.h"
|
||||||
|
|
||||||
|
#ifdef RUBY_API_VERSION_MAJOR
|
||||||
|
#define RAPI_MAJOR RUBY_API_VERSION_MAJOR
|
||||||
|
#define RAPI_MINOR RUBY_API_VERSION_MINOR
|
||||||
|
#define RAPI_TEENY RUBY_API_VERSION_TEENY
|
||||||
|
#else
|
||||||
|
#define RAPI_MAJOR RUBY_VERSION_MAJOR
|
||||||
|
#define RAPI_MINOR RUBY_VERSION_MINOR
|
||||||
|
#define RAPI_TEENY RUBY_VERSION_TEENY
|
||||||
|
#endif
|
||||||
|
#define RAPI_FULL ((RAPI_MAJOR * 100) + (RAPI_MINOR * 10) + RAPI_TEENY)
|
||||||
|
|
||||||
enum RbException {
|
enum RbException {
|
||||||
RGSS = 0,
|
RGSS = 0,
|
||||||
Reset,
|
Reset,
|
||||||
|
@ -59,12 +75,11 @@ struct Exception;
|
||||||
|
|
||||||
void raiseRbExc(const Exception &exc);
|
void raiseRbExc(const Exception &exc);
|
||||||
|
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_FULL > 187
|
||||||
#define DECL_TYPE(Klass) extern rb_data_type_t Klass##Type
|
#define DECL_TYPE(Klass) extern rb_data_type_t Klass##Type
|
||||||
|
|
||||||
/* 2.1 has added a new field (flags) to rb_data_type_t */
|
/* 2.1 has added a new field (flags) to rb_data_type_t */
|
||||||
#include <ruby/version.h>
|
#if RAPI_FULL >= 210
|
||||||
#if RUBY_API_VERSION_MAJOR >= 2 && RUBY_API_VERSION_MINOR >= 1
|
|
||||||
/* TODO: can mkxp use RUBY_TYPED_FREE_IMMEDIATELY here? */
|
/* TODO: can mkxp use RUBY_TYPED_FREE_IMMEDIATELY here? */
|
||||||
#define DEF_TYPE_FLAGS 0
|
#define DEF_TYPE_FLAGS 0
|
||||||
#else
|
#else
|
||||||
|
@ -72,15 +87,14 @@ void raiseRbExc(const Exception &exc);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_MAJOR > 1
|
||||||
#if RUBYCOMPAT < 270
|
#if RAPI_FULL < 270
|
||||||
#define DEF_TYPE_CUSTOMNAME_AND_FREE(Klass, Name, Free) \
|
#define DEF_TYPE_CUSTOMNAME_AND_FREE(Klass, Name, Free) \
|
||||||
rb_data_type_t Klass##Type = { \
|
rb_data_type_t Klass##Type = { \
|
||||||
Name, {0, Free, 0, {0, 0}}, 0, 0, DEF_TYPE_FLAGS}
|
Name, {0, Free, 0, {0, 0}}, 0, 0, DEF_TYPE_FLAGS}
|
||||||
#else
|
#else
|
||||||
#define DEF_TYPE_CUSTOMNAME_AND_FREE(Klass, Name, Free) \
|
#define DEF_TYPE_CUSTOMNAME_AND_FREE(Klass, Name, Free) \
|
||||||
rb_data_type_t Klass##Type = { \
|
rb_data_type_t Klass##Type = {Name, {0, Free, 0, 0, 0}, 0, 0, DEF_TYPE_FLAGS}
|
||||||
Name, {0, Free, 0, 0, 0}, 0, 0, DEF_TYPE_FLAGS}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define DEF_TYPE_CUSTOMFREE(Klass, Free) \
|
#define DEF_TYPE_CUSTOMFREE(Klass, Free) \
|
||||||
|
@ -93,7 +107,7 @@ void raiseRbExc(const Exception &exc);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Ruby 1.8 helper stuff
|
// Ruby 1.8 helper stuff
|
||||||
#ifdef OLD_RUBY
|
#if RAPI_FULL <= 187
|
||||||
|
|
||||||
#define RUBY_T_FIXNUM T_FIXNUM
|
#define RUBY_T_FIXNUM T_FIXNUM
|
||||||
#define RUBY_T_TRUE T_TRUE
|
#define RUBY_T_TRUE T_TRUE
|
||||||
|
@ -144,10 +158,10 @@ void raiseRbExc(const Exception &exc);
|
||||||
#endif
|
#endif
|
||||||
// end
|
// end
|
||||||
|
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_FULL > 187
|
||||||
template <rb_data_type_t *rbType> static VALUE classAllocate(VALUE klass) {
|
template <rb_data_type_t *rbType> static VALUE classAllocate(VALUE klass) {
|
||||||
/* 2.3 has changed the name of this function */
|
/* 2.3 has changed the name of this function */
|
||||||
#if RUBY_API_VERSION_MAJOR >= 2 && RUBY_API_VERSION_MINOR >= 3
|
#if RAPI_FULL >= 230
|
||||||
return rb_data_typed_object_wrap(klass, 0, rbType);
|
return rb_data_typed_object_wrap(klass, 0, rbType);
|
||||||
#else
|
#else
|
||||||
return rb_data_typed_object_alloc(klass, 0, rbType);
|
return rb_data_typed_object_alloc(klass, 0, rbType);
|
||||||
|
@ -162,7 +176,7 @@ template <class C> static void freeInstance(void *inst) {
|
||||||
void raiseDisposedAccess(VALUE self);
|
void raiseDisposedAccess(VALUE self);
|
||||||
|
|
||||||
template <class C> inline C *getPrivateData(VALUE self) {
|
template <class C> inline C *getPrivateData(VALUE self) {
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_FULL > 187
|
||||||
C *c = static_cast<C *>(RTYPEDDATA_DATA(self));
|
C *c = static_cast<C *>(RTYPEDDATA_DATA(self));
|
||||||
#else
|
#else
|
||||||
C *c = static_cast<C *>(DATA_PTR(self));
|
C *c = static_cast<C *>(DATA_PTR(self));
|
||||||
|
@ -172,13 +186,13 @@ template <class C> inline C *getPrivateData(VALUE self) {
|
||||||
|
|
||||||
template <class C>
|
template <class C>
|
||||||
static inline C *
|
static inline C *
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_FULL > 187
|
||||||
getPrivateDataCheck(VALUE self, const rb_data_type_t &type)
|
getPrivateDataCheck(VALUE self, const rb_data_type_t &type)
|
||||||
#else
|
#else
|
||||||
getPrivateDataCheck(VALUE self, const char *type)
|
getPrivateDataCheck(VALUE self, const char *type)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
#ifdef OLD_RUBY
|
#if RAPI_FULL <= 187
|
||||||
rb_check_type(self, T_DATA);
|
rb_check_type(self, T_DATA);
|
||||||
VALUE otherObj = rb_const_get(rb_cObject, rb_intern(type));
|
VALUE otherObj = rb_const_get(rb_cObject, rb_intern(type));
|
||||||
#else
|
#else
|
||||||
|
@ -197,7 +211,7 @@ getPrivateDataCheck(VALUE self, const char *type)
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void setPrivateData(VALUE self, void *p) {
|
static inline void setPrivateData(VALUE self, void *p) {
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_FULL > 187
|
||||||
RTYPEDDATA_DATA(self) = p;
|
RTYPEDDATA_DATA(self) = p;
|
||||||
#else
|
#else
|
||||||
DATA_PTR(self) = p;
|
DATA_PTR(self) = p;
|
||||||
|
@ -205,13 +219,13 @@ static inline void setPrivateData(VALUE self, void *p) {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline VALUE
|
inline VALUE
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_FULL > 187
|
||||||
wrapObject(void *p, const rb_data_type_t &type, VALUE underKlass = rb_cObject)
|
wrapObject(void *p, const rb_data_type_t &type, VALUE underKlass = rb_cObject)
|
||||||
#else
|
#else
|
||||||
wrapObject(void *p, const char *type, VALUE underKlass = rb_cObject)
|
wrapObject(void *p, const char *type, VALUE underKlass = rb_cObject)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_FULL > 187
|
||||||
VALUE klass = rb_const_get(underKlass, rb_intern(type.wrap_struct_name));
|
VALUE klass = rb_const_get(underKlass, rb_intern(type.wrap_struct_name));
|
||||||
#else
|
#else
|
||||||
VALUE klass = rb_const_get(underKlass, rb_intern(type));
|
VALUE klass = rb_const_get(underKlass, rb_intern(type));
|
||||||
|
@ -224,7 +238,7 @@ wrapObject(void *p, const char *type, VALUE underKlass = rb_cObject)
|
||||||
}
|
}
|
||||||
|
|
||||||
inline VALUE wrapProperty(VALUE self, void *prop, const char *iv,
|
inline VALUE wrapProperty(VALUE self, void *prop, const char *iv,
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_FULL > 187
|
||||||
const rb_data_type_t &type,
|
const rb_data_type_t &type,
|
||||||
#else
|
#else
|
||||||
const char *type,
|
const char *type,
|
||||||
|
@ -346,7 +360,7 @@ inline void rb_check_argc(int actual, int expected) {
|
||||||
expected);
|
expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef OLD_RUBY
|
#if RAPI_FULL <= 187
|
||||||
static inline void rb_error_arity(int argc, int min, int max) {
|
static inline void rb_error_arity(int argc, int min, int max) {
|
||||||
if (argc > max || argc < min)
|
if (argc > max || argc < min)
|
||||||
rb_raise(rb_eArgError, "Finish me! rb_error_arity()"); // TODO
|
rb_raise(rb_eArgError, "Finish me! rb_error_arity()"); // TODO
|
||||||
|
@ -395,7 +409,7 @@ static inline VALUE rb_file_open_str(VALUE filename, const char *mode) {
|
||||||
* FIXME: Getter assumes prop is disposable,
|
* FIXME: Getter assumes prop is disposable,
|
||||||
* because self.disposed? is not checked in this case.
|
* because self.disposed? is not checked in this case.
|
||||||
* Should make this more clear */
|
* Should make this more clear */
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_FULL > 187
|
||||||
#define DEF_PROP_OBJ_REF(Klass, PropKlass, PropName, prop_iv) \
|
#define DEF_PROP_OBJ_REF(Klass, PropKlass, PropName, prop_iv) \
|
||||||
RB_METHOD(Klass##Get##PropName) { \
|
RB_METHOD(Klass##Get##PropName) { \
|
||||||
RB_UNUSED_PARAM; \
|
RB_UNUSED_PARAM; \
|
||||||
|
@ -438,7 +452,7 @@ static inline VALUE rb_file_open_str(VALUE filename, const char *mode) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Object property which is copied by value, not reference */
|
/* Object property which is copied by value, not reference */
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_FULL > 187
|
||||||
#define DEF_PROP_OBJ_VAL(Klass, PropKlass, PropName, prop_iv) \
|
#define DEF_PROP_OBJ_VAL(Klass, PropKlass, PropName, prop_iv) \
|
||||||
RB_METHOD(Klass##Get##PropName) { \
|
RB_METHOD(Klass##Get##PropName) { \
|
||||||
RB_UNUSED_PARAM; \
|
RB_UNUSED_PARAM; \
|
||||||
|
|
|
@ -19,508 +19,466 @@
|
||||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "bitmap.h"
|
|
||||||
#include "font.h"
|
|
||||||
#include "exception.h"
|
|
||||||
#include "sharedstate.h"
|
|
||||||
#include "disposable-binding.h"
|
|
||||||
#include "binding-util.h"
|
|
||||||
#include "binding-types.h"
|
#include "binding-types.h"
|
||||||
|
#include "binding-util.h"
|
||||||
|
#include "bitmap.h"
|
||||||
|
#include "disposable-binding.h"
|
||||||
|
#include "exception.h"
|
||||||
|
#include "font.h"
|
||||||
|
#include "sharedstate.h"
|
||||||
|
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_FULL > 187
|
||||||
DEF_TYPE(Bitmap);
|
DEF_TYPE(Bitmap);
|
||||||
#else
|
#else
|
||||||
DEF_ALLOCFUNC(Bitmap);
|
DEF_ALLOCFUNC(Bitmap);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const char *objAsStringPtr(VALUE obj)
|
static const char *objAsStringPtr(VALUE obj) {
|
||||||
{
|
VALUE str = rb_obj_as_string(obj);
|
||||||
VALUE str = rb_obj_as_string(obj);
|
return RSTRING_PTR(str);
|
||||||
return RSTRING_PTR(str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void bitmapInitProps(Bitmap *b, VALUE self)
|
void bitmapInitProps(Bitmap *b, VALUE self) {
|
||||||
{
|
/* Wrap properties */
|
||||||
/* Wrap properties */
|
VALUE fontKlass = rb_const_get(rb_cObject, rb_intern("Font"));
|
||||||
VALUE fontKlass = rb_const_get(rb_cObject, rb_intern("Font"));
|
VALUE fontObj = rb_obj_alloc(fontKlass);
|
||||||
VALUE fontObj = rb_obj_alloc(fontKlass);
|
rb_obj_call_init(fontObj, 0, 0);
|
||||||
rb_obj_call_init(fontObj, 0, 0);
|
|
||||||
|
|
||||||
Font *font = getPrivateData<Font>(fontObj);
|
Font *font = getPrivateData<Font>(fontObj);
|
||||||
b->setInitFont(font);
|
b->setInitFont(font);
|
||||||
|
|
||||||
rb_iv_set(self, "font", fontObj);
|
rb_iv_set(self, "font", fontObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(bitmapInitialize)
|
RB_METHOD(bitmapInitialize) {
|
||||||
{
|
Bitmap *b = 0;
|
||||||
Bitmap *b = 0;
|
|
||||||
|
|
||||||
if (argc == 1)
|
if (argc == 1) {
|
||||||
{
|
char *filename;
|
||||||
char *filename;
|
rb_get_args(argc, argv, "z", &filename RB_ARG_END);
|
||||||
rb_get_args(argc, argv, "z", &filename RB_ARG_END);
|
|
||||||
|
|
||||||
GUARD_EXC( b = new Bitmap(filename); )
|
GUARD_EXC(b = new Bitmap(filename);)
|
||||||
}
|
} else {
|
||||||
else
|
int width, height;
|
||||||
{
|
rb_get_args(argc, argv, "ii", &width, &height RB_ARG_END);
|
||||||
int width, height;
|
|
||||||
rb_get_args(argc, argv, "ii", &width, &height RB_ARG_END);
|
|
||||||
|
|
||||||
GUARD_EXC( b = new Bitmap(width, height); )
|
GUARD_EXC(b = new Bitmap(width, height);)
|
||||||
}
|
}
|
||||||
|
|
||||||
setPrivateData(self, b);
|
setPrivateData(self, b);
|
||||||
bitmapInitProps(b, self);
|
bitmapInitProps(b, self);
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(bitmapWidth)
|
RB_METHOD(bitmapWidth) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
|
||||||
Bitmap *b = getPrivateData<Bitmap>(self);
|
Bitmap *b = getPrivateData<Bitmap>(self);
|
||||||
|
|
||||||
int value = 0;
|
int value = 0;
|
||||||
GUARD_EXC( value = b->width(); );
|
GUARD_EXC(value = b->width(););
|
||||||
|
|
||||||
return INT2FIX(value);
|
return INT2FIX(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(bitmapHeight)
|
RB_METHOD(bitmapHeight) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
|
||||||
Bitmap *b = getPrivateData<Bitmap>(self);
|
Bitmap *b = getPrivateData<Bitmap>(self);
|
||||||
|
|
||||||
int value = 0;
|
int value = 0;
|
||||||
GUARD_EXC( value = b->height(); );
|
GUARD_EXC(value = b->height(););
|
||||||
|
|
||||||
return INT2FIX(value);
|
return INT2FIX(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(bitmapRect)
|
RB_METHOD(bitmapRect) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
|
||||||
Bitmap *b = getPrivateData<Bitmap>(self);
|
Bitmap *b = getPrivateData<Bitmap>(self);
|
||||||
|
|
||||||
IntRect rect;
|
IntRect rect;
|
||||||
GUARD_EXC( rect = b->rect(); );
|
GUARD_EXC(rect = b->rect(););
|
||||||
|
|
||||||
Rect *r = new Rect(rect);
|
Rect *r = new Rect(rect);
|
||||||
|
|
||||||
return wrapObject(r, RectType);
|
return wrapObject(r, RectType);
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(bitmapBlt)
|
RB_METHOD(bitmapBlt) {
|
||||||
{
|
Bitmap *b = getPrivateData<Bitmap>(self);
|
||||||
Bitmap *b = getPrivateData<Bitmap>(self);
|
|
||||||
|
|
||||||
int x, y;
|
int x, y;
|
||||||
VALUE srcObj;
|
VALUE srcObj;
|
||||||
VALUE srcRectObj;
|
VALUE srcRectObj;
|
||||||
int opacity = 255;
|
int opacity = 255;
|
||||||
|
|
||||||
Bitmap *src;
|
Bitmap *src;
|
||||||
Rect *srcRect;
|
Rect *srcRect;
|
||||||
|
|
||||||
rb_get_args(argc, argv, "iioo|i", &x, &y, &srcObj, &srcRectObj, &opacity RB_ARG_END);
|
rb_get_args(argc, argv, "iioo|i", &x, &y, &srcObj, &srcRectObj,
|
||||||
|
&opacity RB_ARG_END);
|
||||||
|
|
||||||
src = getPrivateDataCheck<Bitmap>(srcObj, BitmapType);
|
src = getPrivateDataCheck<Bitmap>(srcObj, BitmapType);
|
||||||
srcRect = getPrivateDataCheck<Rect>(srcRectObj, RectType);
|
srcRect = getPrivateDataCheck<Rect>(srcRectObj, RectType);
|
||||||
|
|
||||||
GUARD_EXC( b->blt(x, y, *src, srcRect->toIntRect(), opacity); );
|
GUARD_EXC(b->blt(x, y, *src, srcRect->toIntRect(), opacity););
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(bitmapStretchBlt)
|
RB_METHOD(bitmapStretchBlt) {
|
||||||
{
|
Bitmap *b = getPrivateData<Bitmap>(self);
|
||||||
Bitmap *b = getPrivateData<Bitmap>(self);
|
|
||||||
|
|
||||||
VALUE destRectObj;
|
VALUE destRectObj;
|
||||||
VALUE srcObj;
|
VALUE srcObj;
|
||||||
VALUE srcRectObj;
|
VALUE srcRectObj;
|
||||||
int opacity = 255;
|
int opacity = 255;
|
||||||
|
|
||||||
Bitmap *src;
|
Bitmap *src;
|
||||||
Rect *destRect, *srcRect;
|
Rect *destRect, *srcRect;
|
||||||
|
|
||||||
rb_get_args(argc, argv, "ooo|i", &destRectObj, &srcObj, &srcRectObj, &opacity RB_ARG_END);
|
rb_get_args(argc, argv, "ooo|i", &destRectObj, &srcObj, &srcRectObj,
|
||||||
|
&opacity RB_ARG_END);
|
||||||
|
|
||||||
src = getPrivateDataCheck<Bitmap>(srcObj, BitmapType);
|
src = getPrivateDataCheck<Bitmap>(srcObj, BitmapType);
|
||||||
destRect = getPrivateDataCheck<Rect>(destRectObj, RectType);
|
destRect = getPrivateDataCheck<Rect>(destRectObj, RectType);
|
||||||
srcRect = getPrivateDataCheck<Rect>(srcRectObj, RectType);
|
srcRect = getPrivateDataCheck<Rect>(srcRectObj, RectType);
|
||||||
|
|
||||||
GUARD_EXC( b->stretchBlt(destRect->toIntRect(), *src, srcRect->toIntRect(), opacity); );
|
GUARD_EXC(b->stretchBlt(destRect->toIntRect(), *src, srcRect->toIntRect(),
|
||||||
|
opacity););
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(bitmapFillRect)
|
RB_METHOD(bitmapFillRect) {
|
||||||
{
|
Bitmap *b = getPrivateData<Bitmap>(self);
|
||||||
Bitmap *b = getPrivateData<Bitmap>(self);
|
|
||||||
|
|
||||||
VALUE colorObj;
|
VALUE colorObj;
|
||||||
Color *color;
|
Color *color;
|
||||||
|
|
||||||
if (argc == 2)
|
if (argc == 2) {
|
||||||
{
|
VALUE rectObj;
|
||||||
VALUE rectObj;
|
Rect *rect;
|
||||||
Rect *rect;
|
|
||||||
|
|
||||||
rb_get_args(argc, argv, "oo", &rectObj, &colorObj RB_ARG_END);
|
rb_get_args(argc, argv, "oo", &rectObj, &colorObj RB_ARG_END);
|
||||||
|
|
||||||
rect = getPrivateDataCheck<Rect>(rectObj, RectType);
|
rect = getPrivateDataCheck<Rect>(rectObj, RectType);
|
||||||
color = getPrivateDataCheck<Color>(colorObj, ColorType);
|
color = getPrivateDataCheck<Color>(colorObj, ColorType);
|
||||||
|
|
||||||
GUARD_EXC( b->fillRect(rect->toIntRect(), color->norm); );
|
GUARD_EXC(b->fillRect(rect->toIntRect(), color->norm););
|
||||||
}
|
} else {
|
||||||
else
|
int x, y, width, height;
|
||||||
{
|
|
||||||
int x, y, width, height;
|
|
||||||
|
|
||||||
rb_get_args(argc, argv, "iiiio", &x, &y, &width, &height, &colorObj RB_ARG_END);
|
rb_get_args(argc, argv, "iiiio", &x, &y, &width, &height,
|
||||||
|
&colorObj RB_ARG_END);
|
||||||
|
|
||||||
color = getPrivateDataCheck<Color>(colorObj, ColorType);
|
color = getPrivateDataCheck<Color>(colorObj, ColorType);
|
||||||
|
|
||||||
GUARD_EXC( b->fillRect(x, y, width, height, color->norm); );
|
GUARD_EXC(b->fillRect(x, y, width, height, color->norm););
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(bitmapClear)
|
RB_METHOD(bitmapClear) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
|
||||||
Bitmap *b = getPrivateData<Bitmap>(self);
|
Bitmap *b = getPrivateData<Bitmap>(self);
|
||||||
|
|
||||||
GUARD_EXC( b->clear(); )
|
GUARD_EXC(b->clear();)
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(bitmapGetPixel)
|
RB_METHOD(bitmapGetPixel) {
|
||||||
{
|
Bitmap *b = getPrivateData<Bitmap>(self);
|
||||||
Bitmap *b = getPrivateData<Bitmap>(self);
|
|
||||||
|
|
||||||
int x, y;
|
int x, y;
|
||||||
|
|
||||||
rb_get_args(argc, argv, "ii", &x, &y RB_ARG_END);
|
rb_get_args(argc, argv, "ii", &x, &y RB_ARG_END);
|
||||||
|
|
||||||
Color value;
|
Color value;
|
||||||
GUARD_EXC( value = b->getPixel(x, y); );
|
GUARD_EXC(value = b->getPixel(x, y););
|
||||||
|
|
||||||
Color *color = new Color(value);
|
Color *color = new Color(value);
|
||||||
|
|
||||||
return wrapObject(color, ColorType);
|
return wrapObject(color, ColorType);
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(bitmapSetPixel)
|
RB_METHOD(bitmapSetPixel) {
|
||||||
{
|
Bitmap *b = getPrivateData<Bitmap>(self);
|
||||||
Bitmap *b = getPrivateData<Bitmap>(self);
|
|
||||||
|
|
||||||
int x, y;
|
int x, y;
|
||||||
VALUE colorObj;
|
VALUE colorObj;
|
||||||
|
|
||||||
Color *color;
|
Color *color;
|
||||||
|
|
||||||
rb_get_args(argc, argv, "iio", &x, &y, &colorObj RB_ARG_END);
|
rb_get_args(argc, argv, "iio", &x, &y, &colorObj RB_ARG_END);
|
||||||
|
|
||||||
color = getPrivateDataCheck<Color>(colorObj, ColorType);
|
color = getPrivateDataCheck<Color>(colorObj, ColorType);
|
||||||
|
|
||||||
GUARD_EXC( b->setPixel(x, y, *color); );
|
GUARD_EXC(b->setPixel(x, y, *color););
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(bitmapHueChange)
|
RB_METHOD(bitmapHueChange) {
|
||||||
{
|
Bitmap *b = getPrivateData<Bitmap>(self);
|
||||||
Bitmap *b = getPrivateData<Bitmap>(self);
|
|
||||||
|
|
||||||
int hue;
|
int hue;
|
||||||
|
|
||||||
rb_get_args(argc, argv, "i", &hue RB_ARG_END);
|
rb_get_args(argc, argv, "i", &hue RB_ARG_END);
|
||||||
|
|
||||||
GUARD_EXC( b->hueChange(hue); );
|
GUARD_EXC(b->hueChange(hue););
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(bitmapDrawText)
|
RB_METHOD(bitmapDrawText) {
|
||||||
{
|
Bitmap *b = getPrivateData<Bitmap>(self);
|
||||||
Bitmap *b = getPrivateData<Bitmap>(self);
|
|
||||||
|
|
||||||
const char *str;
|
const char *str;
|
||||||
int align = Bitmap::Left;
|
int align = Bitmap::Left;
|
||||||
|
|
||||||
if (argc == 2 || argc == 3)
|
if (argc == 2 || argc == 3) {
|
||||||
{
|
VALUE rectObj;
|
||||||
VALUE rectObj;
|
Rect *rect;
|
||||||
Rect *rect;
|
|
||||||
|
|
||||||
if (rgssVer >= 2)
|
if (rgssVer >= 2) {
|
||||||
{
|
VALUE strObj;
|
||||||
VALUE strObj;
|
rb_get_args(argc, argv, "oo|i", &rectObj, &strObj, &align RB_ARG_END);
|
||||||
rb_get_args(argc, argv, "oo|i", &rectObj, &strObj, &align RB_ARG_END);
|
|
||||||
|
|
||||||
str = objAsStringPtr(strObj);
|
str = objAsStringPtr(strObj);
|
||||||
}
|
} else {
|
||||||
else
|
rb_get_args(argc, argv, "oz|i", &rectObj, &str, &align RB_ARG_END);
|
||||||
{
|
}
|
||||||
rb_get_args(argc, argv, "oz|i", &rectObj, &str, &align RB_ARG_END);
|
|
||||||
}
|
|
||||||
|
|
||||||
rect = getPrivateDataCheck<Rect>(rectObj, RectType);
|
rect = getPrivateDataCheck<Rect>(rectObj, RectType);
|
||||||
|
|
||||||
GUARD_EXC( b->drawText(rect->toIntRect(), str, align); );
|
GUARD_EXC(b->drawText(rect->toIntRect(), str, align););
|
||||||
}
|
} else {
|
||||||
else
|
int x, y, width, height;
|
||||||
{
|
|
||||||
int x, y, width, height;
|
|
||||||
|
|
||||||
if (rgssVer >= 2)
|
if (rgssVer >= 2) {
|
||||||
{
|
VALUE strObj;
|
||||||
VALUE strObj;
|
rb_get_args(argc, argv, "iiiio|i", &x, &y, &width, &height, &strObj,
|
||||||
rb_get_args(argc, argv, "iiiio|i", &x, &y, &width, &height, &strObj, &align RB_ARG_END);
|
&align RB_ARG_END);
|
||||||
|
|
||||||
str = objAsStringPtr(strObj);
|
str = objAsStringPtr(strObj);
|
||||||
}
|
} else {
|
||||||
else
|
rb_get_args(argc, argv, "iiiiz|i", &x, &y, &width, &height, &str,
|
||||||
{
|
&align RB_ARG_END);
|
||||||
rb_get_args(argc, argv, "iiiiz|i", &x, &y, &width, &height, &str, &align RB_ARG_END);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
GUARD_EXC( b->drawText(x, y, width, height, str, align); );
|
GUARD_EXC(b->drawText(x, y, width, height, str, align););
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(bitmapTextSize)
|
RB_METHOD(bitmapTextSize) {
|
||||||
{
|
Bitmap *b = getPrivateData<Bitmap>(self);
|
||||||
Bitmap *b = getPrivateData<Bitmap>(self);
|
|
||||||
|
|
||||||
const char *str;
|
const char *str;
|
||||||
|
|
||||||
if (rgssVer >= 2)
|
if (rgssVer >= 2) {
|
||||||
{
|
VALUE strObj;
|
||||||
VALUE strObj;
|
rb_get_args(argc, argv, "o", &strObj RB_ARG_END);
|
||||||
rb_get_args(argc, argv, "o", &strObj RB_ARG_END);
|
|
||||||
|
|
||||||
str = objAsStringPtr(strObj);
|
str = objAsStringPtr(strObj);
|
||||||
}
|
} else {
|
||||||
else
|
rb_get_args(argc, argv, "z", &str RB_ARG_END);
|
||||||
{
|
}
|
||||||
rb_get_args(argc, argv, "z", &str RB_ARG_END);
|
|
||||||
}
|
|
||||||
|
|
||||||
IntRect value;
|
IntRect value;
|
||||||
GUARD_EXC( value = b->textSize(str); );
|
GUARD_EXC(value = b->textSize(str););
|
||||||
|
|
||||||
Rect *rect = new Rect(value);
|
Rect *rect = new Rect(value);
|
||||||
|
|
||||||
return wrapObject(rect, RectType);
|
return wrapObject(rect, RectType);
|
||||||
}
|
}
|
||||||
|
|
||||||
DEF_PROP_OBJ_VAL(Bitmap, Font, Font, "font")
|
DEF_PROP_OBJ_VAL(Bitmap, Font, Font, "font")
|
||||||
|
|
||||||
RB_METHOD(bitmapGradientFillRect)
|
RB_METHOD(bitmapGradientFillRect) {
|
||||||
{
|
Bitmap *b = getPrivateData<Bitmap>(self);
|
||||||
Bitmap *b = getPrivateData<Bitmap>(self);
|
|
||||||
|
|
||||||
VALUE color1Obj, color2Obj;
|
VALUE color1Obj, color2Obj;
|
||||||
Color *color1, *color2;
|
Color *color1, *color2;
|
||||||
bool vertical = false;
|
bool vertical = false;
|
||||||
|
|
||||||
if (argc == 3 || argc == 4)
|
if (argc == 3 || argc == 4) {
|
||||||
{
|
VALUE rectObj;
|
||||||
VALUE rectObj;
|
Rect *rect;
|
||||||
Rect *rect;
|
|
||||||
|
|
||||||
rb_get_args(argc, argv, "ooo|b", &rectObj,
|
rb_get_args(argc, argv, "ooo|b", &rectObj, &color1Obj, &color2Obj,
|
||||||
&color1Obj, &color2Obj, &vertical RB_ARG_END);
|
&vertical RB_ARG_END);
|
||||||
|
|
||||||
rect = getPrivateDataCheck<Rect>(rectObj, RectType);
|
rect = getPrivateDataCheck<Rect>(rectObj, RectType);
|
||||||
color1 = getPrivateDataCheck<Color>(color1Obj, ColorType);
|
color1 = getPrivateDataCheck<Color>(color1Obj, ColorType);
|
||||||
color2 = getPrivateDataCheck<Color>(color2Obj, ColorType);
|
color2 = getPrivateDataCheck<Color>(color2Obj, ColorType);
|
||||||
|
|
||||||
GUARD_EXC( b->gradientFillRect(rect->toIntRect(), color1->norm, color2->norm, vertical); );
|
GUARD_EXC(b->gradientFillRect(rect->toIntRect(), color1->norm, color2->norm,
|
||||||
}
|
vertical););
|
||||||
else
|
} else {
|
||||||
{
|
int x, y, width, height;
|
||||||
int x, y, width, height;
|
|
||||||
|
|
||||||
rb_get_args(argc, argv, "iiiioo|b", &x, &y, &width, &height,
|
rb_get_args(argc, argv, "iiiioo|b", &x, &y, &width, &height, &color1Obj,
|
||||||
&color1Obj, &color2Obj, &vertical RB_ARG_END);
|
&color2Obj, &vertical RB_ARG_END);
|
||||||
|
|
||||||
color1 = getPrivateDataCheck<Color>(color1Obj, ColorType);
|
color1 = getPrivateDataCheck<Color>(color1Obj, ColorType);
|
||||||
color2 = getPrivateDataCheck<Color>(color2Obj, ColorType);
|
color2 = getPrivateDataCheck<Color>(color2Obj, ColorType);
|
||||||
|
|
||||||
GUARD_EXC( b->gradientFillRect(x, y, width, height, color1->norm, color2->norm, vertical); );
|
GUARD_EXC(b->gradientFillRect(x, y, width, height, color1->norm,
|
||||||
}
|
color2->norm, vertical););
|
||||||
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(bitmapClearRect)
|
RB_METHOD(bitmapClearRect) {
|
||||||
{
|
Bitmap *b = getPrivateData<Bitmap>(self);
|
||||||
Bitmap *b = getPrivateData<Bitmap>(self);
|
|
||||||
|
|
||||||
if (argc == 1)
|
if (argc == 1) {
|
||||||
{
|
VALUE rectObj;
|
||||||
VALUE rectObj;
|
Rect *rect;
|
||||||
Rect *rect;
|
|
||||||
|
|
||||||
rb_get_args(argc, argv, "o", &rectObj RB_ARG_END);
|
rb_get_args(argc, argv, "o", &rectObj RB_ARG_END);
|
||||||
|
|
||||||
rect = getPrivateDataCheck<Rect>(rectObj, RectType);
|
rect = getPrivateDataCheck<Rect>(rectObj, RectType);
|
||||||
|
|
||||||
GUARD_EXC( b->clearRect(rect->toIntRect()); );
|
GUARD_EXC(b->clearRect(rect->toIntRect()););
|
||||||
}
|
} else {
|
||||||
else
|
int x, y, width, height;
|
||||||
{
|
|
||||||
int x, y, width, height;
|
|
||||||
|
|
||||||
rb_get_args(argc, argv, "iiii", &x, &y, &width, &height RB_ARG_END);
|
rb_get_args(argc, argv, "iiii", &x, &y, &width, &height RB_ARG_END);
|
||||||
|
|
||||||
GUARD_EXC( b->clearRect(x, y, width, height); );
|
GUARD_EXC(b->clearRect(x, y, width, height););
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(bitmapBlur)
|
RB_METHOD(bitmapBlur) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
|
||||||
Bitmap *b = getPrivateData<Bitmap>(self);
|
Bitmap *b = getPrivateData<Bitmap>(self);
|
||||||
|
|
||||||
b->blur();
|
b->blur();
|
||||||
|
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(bitmapRadialBlur)
|
RB_METHOD(bitmapRadialBlur) {
|
||||||
{
|
Bitmap *b = getPrivateData<Bitmap>(self);
|
||||||
Bitmap *b = getPrivateData<Bitmap>(self);
|
|
||||||
|
|
||||||
int angle, divisions;
|
int angle, divisions;
|
||||||
rb_get_args(argc, argv, "ii", &angle, &divisions RB_ARG_END);
|
rb_get_args(argc, argv, "ii", &angle, &divisions RB_ARG_END);
|
||||||
|
|
||||||
b->radialBlur(angle, divisions);
|
b->radialBlur(angle, divisions);
|
||||||
|
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(bitmapGetRawData)
|
RB_METHOD(bitmapGetRawData) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
|
||||||
Bitmap *b = getPrivateData<Bitmap>(self);
|
|
||||||
int size = b->width()*b->height()*4;
|
|
||||||
VALUE ret = rb_str_new(0, size);
|
|
||||||
|
|
||||||
GUARD_EXC ( b->getRaw(RSTRING_PTR(ret), size); );
|
Bitmap *b = getPrivateData<Bitmap>(self);
|
||||||
|
int size = b->width() * b->height() * 4;
|
||||||
return ret;
|
VALUE ret = rb_str_new(0, size);
|
||||||
|
|
||||||
|
GUARD_EXC(b->getRaw(RSTRING_PTR(ret), size););
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(bitmapSetRawData)
|
RB_METHOD(bitmapSetRawData) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
|
||||||
VALUE str;
|
VALUE str;
|
||||||
rb_scan_args(argc, argv, "1", &str);
|
rb_scan_args(argc, argv, "1", &str);
|
||||||
SafeStringValue(str);
|
SafeStringValue(str);
|
||||||
|
|
||||||
Bitmap *b = getPrivateData<Bitmap>(self);
|
Bitmap *b = getPrivateData<Bitmap>(self);
|
||||||
|
|
||||||
GUARD_EXC( b->replaceRaw(RSTRING_PTR(str), RSTRING_LEN(str)); );
|
GUARD_EXC(b->replaceRaw(RSTRING_PTR(str), RSTRING_LEN(str)););
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(bitmapSaveToFile) {
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
VALUE str;
|
||||||
|
rb_scan_args(argc, argv, "1", &str);
|
||||||
|
SafeStringValue(str);
|
||||||
|
|
||||||
|
Bitmap *b = getPrivateData<Bitmap>(self);
|
||||||
|
|
||||||
|
try {
|
||||||
|
b->saveToFile(RSTRING_PTR(str));
|
||||||
|
} catch (const Exception &e) {
|
||||||
|
raiseRbExc(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return RUBY_Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(bitmapInitializeCopy) {
|
||||||
|
rb_check_argc(argc, 1);
|
||||||
|
VALUE origObj = argv[0];
|
||||||
|
|
||||||
|
if (!OBJ_INIT_COPY(self, origObj))
|
||||||
return self;
|
return self;
|
||||||
|
|
||||||
|
Bitmap *orig = getPrivateData<Bitmap>(origObj);
|
||||||
|
Bitmap *b = 0;
|
||||||
|
GUARD_EXC(b = new Bitmap(*orig););
|
||||||
|
|
||||||
|
bitmapInitProps(b, self);
|
||||||
|
b->setFont(orig->getFont());
|
||||||
|
|
||||||
|
setPrivateData(self, b);
|
||||||
|
|
||||||
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(bitmapSaveToFile)
|
void bitmapBindingInit() {
|
||||||
{
|
VALUE klass = rb_define_class("Bitmap", rb_cObject);
|
||||||
RB_UNUSED_PARAM;
|
#if RAPI_FULL > 187
|
||||||
|
rb_define_alloc_func(klass, classAllocate<&BitmapType>);
|
||||||
VALUE str;
|
|
||||||
rb_scan_args(argc, argv, "1", &str);
|
|
||||||
SafeStringValue(str);
|
|
||||||
|
|
||||||
Bitmap *b = getPrivateData<Bitmap>(self);
|
|
||||||
|
|
||||||
try {
|
|
||||||
b->saveToFile(RSTRING_PTR(str));
|
|
||||||
} catch (const Exception &e) {
|
|
||||||
raiseRbExc(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return RUBY_Qnil;
|
|
||||||
}
|
|
||||||
|
|
||||||
RB_METHOD(bitmapInitializeCopy)
|
|
||||||
{
|
|
||||||
rb_check_argc(argc, 1);
|
|
||||||
VALUE origObj = argv[0];
|
|
||||||
|
|
||||||
if (!OBJ_INIT_COPY(self, origObj))
|
|
||||||
return self;
|
|
||||||
|
|
||||||
Bitmap *orig = getPrivateData<Bitmap>(origObj);
|
|
||||||
Bitmap *b = 0;
|
|
||||||
GUARD_EXC( b = new Bitmap(*orig); );
|
|
||||||
|
|
||||||
bitmapInitProps(b, self);
|
|
||||||
b->setFont(orig->getFont());
|
|
||||||
|
|
||||||
setPrivateData(self, b);
|
|
||||||
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
bitmapBindingInit()
|
|
||||||
{
|
|
||||||
VALUE klass = rb_define_class("Bitmap", rb_cObject);
|
|
||||||
#ifndef OLD_RUBY
|
|
||||||
rb_define_alloc_func(klass, classAllocate<&BitmapType>);
|
|
||||||
#else
|
#else
|
||||||
rb_define_alloc_func(klass, BitmapAllocate);
|
rb_define_alloc_func(klass, BitmapAllocate);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
disposableBindingInit<Bitmap>(klass);
|
disposableBindingInit<Bitmap>(klass);
|
||||||
|
|
||||||
_rb_define_method(klass, "initialize", bitmapInitialize);
|
_rb_define_method(klass, "initialize", bitmapInitialize);
|
||||||
_rb_define_method(klass, "initialize_copy", bitmapInitializeCopy);
|
_rb_define_method(klass, "initialize_copy", bitmapInitializeCopy);
|
||||||
|
|
||||||
_rb_define_method(klass, "width", bitmapWidth);
|
_rb_define_method(klass, "width", bitmapWidth);
|
||||||
_rb_define_method(klass, "height", bitmapHeight);
|
_rb_define_method(klass, "height", bitmapHeight);
|
||||||
_rb_define_method(klass, "rect", bitmapRect);
|
_rb_define_method(klass, "rect", bitmapRect);
|
||||||
_rb_define_method(klass, "blt", bitmapBlt);
|
_rb_define_method(klass, "blt", bitmapBlt);
|
||||||
_rb_define_method(klass, "stretch_blt", bitmapStretchBlt);
|
_rb_define_method(klass, "stretch_blt", bitmapStretchBlt);
|
||||||
_rb_define_method(klass, "fill_rect", bitmapFillRect);
|
_rb_define_method(klass, "fill_rect", bitmapFillRect);
|
||||||
_rb_define_method(klass, "clear", bitmapClear);
|
_rb_define_method(klass, "clear", bitmapClear);
|
||||||
_rb_define_method(klass, "get_pixel", bitmapGetPixel);
|
_rb_define_method(klass, "get_pixel", bitmapGetPixel);
|
||||||
_rb_define_method(klass, "set_pixel", bitmapSetPixel);
|
_rb_define_method(klass, "set_pixel", bitmapSetPixel);
|
||||||
_rb_define_method(klass, "hue_change", bitmapHueChange);
|
_rb_define_method(klass, "hue_change", bitmapHueChange);
|
||||||
_rb_define_method(klass, "draw_text", bitmapDrawText);
|
_rb_define_method(klass, "draw_text", bitmapDrawText);
|
||||||
_rb_define_method(klass, "text_size", bitmapTextSize);
|
_rb_define_method(klass, "text_size", bitmapTextSize);
|
||||||
|
|
||||||
_rb_define_method(klass, "raw_data", bitmapGetRawData);
|
|
||||||
_rb_define_method(klass, "raw_data=", bitmapSetRawData);
|
|
||||||
_rb_define_method(klass, "to_file", bitmapSaveToFile);
|
|
||||||
|
|
||||||
_rb_define_method(klass, "gradient_fill_rect", bitmapGradientFillRect);
|
_rb_define_method(klass, "raw_data", bitmapGetRawData);
|
||||||
_rb_define_method(klass, "clear_rect", bitmapClearRect);
|
_rb_define_method(klass, "raw_data=", bitmapSetRawData);
|
||||||
_rb_define_method(klass, "blur", bitmapBlur);
|
_rb_define_method(klass, "to_file", bitmapSaveToFile);
|
||||||
_rb_define_method(klass, "radial_blur", bitmapRadialBlur);
|
|
||||||
|
|
||||||
INIT_PROP_BIND(Bitmap, Font, "font");
|
_rb_define_method(klass, "gradient_fill_rect", bitmapGradientFillRect);
|
||||||
|
_rb_define_method(klass, "clear_rect", bitmapClearRect);
|
||||||
|
_rb_define_method(klass, "blur", bitmapBlur);
|
||||||
|
_rb_define_method(klass, "radial_blur", bitmapRadialBlur);
|
||||||
|
|
||||||
|
INIT_PROP_BIND(Bitmap, Font, "font");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,251 +1,226 @@
|
||||||
#include <discord_game_sdk.h>
|
#include <discord_game_sdk.h>
|
||||||
|
|
||||||
|
#include "binding-types.h"
|
||||||
|
#include "binding-util.h"
|
||||||
#include "discordstate.h"
|
#include "discordstate.h"
|
||||||
#include "sharedstate.h"
|
#include "sharedstate.h"
|
||||||
#include "binding-util.h"
|
|
||||||
#include "binding-types.h"
|
|
||||||
|
|
||||||
//NYI
|
// NYI
|
||||||
void discordResultCb(void *callback_data, enum EDiscordResult result)
|
void discordResultCb(void *callback_data, enum EDiscordResult result) {}
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_FULL > 187
|
||||||
DEF_TYPE_CUSTOMFREE(DCActivity, free);
|
DEF_TYPE_CUSTOMFREE(DCActivity, free);
|
||||||
#else
|
#else
|
||||||
DEF_ALLOCFUNC_CUSTOMFREE(DCActivity, free);
|
DEF_ALLOCFUNC_CUSTOMFREE(DCActivity, free);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
RB_METHOD(DiscordConnected)
|
RB_METHOD(DiscordConnected) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
// Checking to make sure callbacks have actually fired
|
||||||
// Checking to make sure callbacks have actually fired
|
return rb_bool_new(shState->discord().userId());
|
||||||
return rb_bool_new(shState->discord().userId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(DiscordGetUsername)
|
RB_METHOD(DiscordGetUsername) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
return rb_str_new_cstr(shState->discord().userName().c_str());
|
||||||
return rb_str_new_cstr(shState->discord().userName().c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(DiscordGetDiscriminator)
|
RB_METHOD(DiscordGetDiscriminator) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
return rb_str_new_cstr(shState->discord().userDiscrim().c_str());
|
||||||
return rb_str_new_cstr(shState->discord().userDiscrim().c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(DiscordGetUserId)
|
RB_METHOD(DiscordGetUserId) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
return LL2NUM(shState->discord().userId());
|
||||||
return LL2NUM(shState->discord().userId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void bitmapInitProps(Bitmap *b, VALUE self);
|
void bitmapInitProps(Bitmap *b, VALUE self);
|
||||||
|
|
||||||
RB_METHOD(DiscordGetUserAvatar)
|
RB_METHOD(DiscordGetUserAvatar) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
int size = 32;
|
||||||
int size = 32;
|
rb_get_args(argc, argv, "|i", &size RB_ARG_END);
|
||||||
rb_get_args(argc, argv, "|i", &size RB_ARG_END);
|
|
||||||
|
Bitmap *result = shState->discord().userAvatar(size);
|
||||||
Bitmap *result = shState->discord().userAvatar(size);
|
if (!result)
|
||||||
if (!result) return RUBY_Qnil;
|
return RUBY_Qnil;
|
||||||
|
|
||||||
VALUE ret = wrapObject(result, BitmapType);
|
VALUE ret = wrapObject(result, BitmapType);
|
||||||
bitmapInitProps(result, ret);
|
bitmapInitProps(result, ret);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(DiscordActivitySend)
|
RB_METHOD(DiscordActivitySend) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
IDiscordActivityManager *am = shState->discord().activityManager();
|
||||||
IDiscordActivityManager *am = shState->discord().activityManager();
|
|
||||||
|
DiscordActivity *activity = getPrivateData<DiscordActivity>(self);
|
||||||
DiscordActivity *activity = getPrivateData<DiscordActivity>(self);
|
|
||||||
|
if (am)
|
||||||
if (am) am->update_activity(am, activity, 0, discordResultCb);
|
am->update_activity(am, activity, 0, discordResultCb);
|
||||||
|
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(DiscordActivityInitialize)
|
RB_METHOD(DiscordActivityInitialize) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
DiscordActivity *activity = ALLOC(DiscordActivity);
|
||||||
DiscordActivity *activity = ALLOC(DiscordActivity);
|
setPrivateData(self, activity);
|
||||||
setPrivateData(self, activity);
|
|
||||||
|
memset(activity, 0, sizeof(DiscordActivity));
|
||||||
memset(activity, 0, sizeof(DiscordActivity));
|
|
||||||
|
activity->type = DiscordActivityType_Playing;
|
||||||
activity->type = DiscordActivityType_Playing;
|
|
||||||
|
if (rb_block_given_p()) {
|
||||||
if (rb_block_given_p())
|
rb_yield(self);
|
||||||
{
|
DiscordActivitySend(0, 0, self);
|
||||||
rb_yield(self);
|
};
|
||||||
DiscordActivitySend(0, 0, self);
|
return self;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
RB_METHOD(DiscordActivityInitializeCopy) {
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
rb_check_argc(argc, 1);
|
||||||
|
VALUE origObj = argv[0];
|
||||||
|
|
||||||
|
if (!OBJ_INIT_COPY(self, origObj))
|
||||||
return self;
|
return self;
|
||||||
|
|
||||||
|
DiscordActivity *orig = getPrivateData<DiscordActivity>(origObj);
|
||||||
|
DiscordActivity *s = ALLOC(DiscordActivity);
|
||||||
|
|
||||||
|
memcpy(s, orig, sizeof(DiscordActivity));
|
||||||
|
|
||||||
|
setPrivateData(self, s);
|
||||||
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(DiscordActivityInitializeCopy)
|
RB_METHOD(DiscordActivityClear) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
IDiscordActivityManager *am = shState->discord().activityManager();
|
||||||
|
if (am)
|
||||||
rb_check_argc(argc, 1);
|
am->clear_activity(am, 0, discordResultCb);
|
||||||
VALUE origObj = argv[0];
|
|
||||||
|
return Qnil;
|
||||||
if (!OBJ_INIT_COPY(self, origObj))
|
|
||||||
return self;
|
|
||||||
|
|
||||||
DiscordActivity *orig = getPrivateData<DiscordActivity>(origObj);
|
|
||||||
DiscordActivity *s = ALLOC(DiscordActivity);
|
|
||||||
|
|
||||||
memcpy(s, orig, sizeof(DiscordActivity));
|
|
||||||
|
|
||||||
setPrivateData(self, s);
|
|
||||||
return self;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(DiscordActivityClear)
|
#define DEF_DCPROP_ACTPARTYSZ(n) \
|
||||||
{
|
RB_METHOD(DiscordActivityGetParty##n) { \
|
||||||
RB_UNUSED_PARAM;
|
RB_UNUSED_PARAM; \
|
||||||
IDiscordActivityManager *am = shState->discord().activityManager();
|
DiscordActivity *p = getPrivateData<DiscordActivity>(self); \
|
||||||
if (am) am->clear_activity(am, 0, discordResultCb);
|
return INT2NUM(p->party.size.n); \
|
||||||
|
} \
|
||||||
return Qnil;
|
RB_METHOD(DiscordActivitySetParty##n) { \
|
||||||
}
|
RB_UNUSED_PARAM; \
|
||||||
|
int num; \
|
||||||
#define DEF_DCPROP_ACTPARTYSZ(n) \
|
rb_get_args(argc, argv, "i", &num); \
|
||||||
RB_METHOD(DiscordActivityGetParty##n) \
|
DiscordActivity *p = getPrivateData<DiscordActivity>(self); \
|
||||||
{ \
|
p->party.size.n = num; \
|
||||||
RB_UNUSED_PARAM; \
|
return INT2NUM(num); \
|
||||||
DiscordActivity *p = getPrivateData<DiscordActivity>(self); \
|
}
|
||||||
return INT2NUM(p->party.size.n); \
|
|
||||||
} \
|
|
||||||
RB_METHOD(DiscordActivitySetParty##n) \
|
|
||||||
{ \
|
|
||||||
RB_UNUSED_PARAM; \
|
|
||||||
int num; \
|
|
||||||
rb_get_args(argc, argv, "i", &num); \
|
|
||||||
DiscordActivity *p = getPrivateData<DiscordActivity>(self); \
|
|
||||||
p->party.size.n = num; \
|
|
||||||
return INT2NUM(num); \
|
|
||||||
}
|
|
||||||
|
|
||||||
DEF_DCPROP_ACTPARTYSZ(current_size);
|
DEF_DCPROP_ACTPARTYSZ(current_size);
|
||||||
DEF_DCPROP_ACTPARTYSZ(max_size);
|
DEF_DCPROP_ACTPARTYSZ(max_size);
|
||||||
|
|
||||||
#define DEF_DCPROP_S(basename, propname, maxsz) \
|
#define DEF_DCPROP_S(basename, propname, maxsz) \
|
||||||
RB_METHOD(Discord##basename##Get##propname) \
|
RB_METHOD(Discord##basename##Get##propname) { \
|
||||||
{ \
|
RB_UNUSED_PARAM; \
|
||||||
RB_UNUSED_PARAM; \
|
Discord##basename *p = getPrivateData<Discord##basename>(self); \
|
||||||
Discord##basename *p = getPrivateData<Discord##basename>(self); \
|
return rb_str_new_cstr(p->propname); \
|
||||||
return rb_str_new_cstr(p->propname); \
|
} \
|
||||||
} \
|
RB_METHOD(Discord##basename##Set##propname) { \
|
||||||
RB_METHOD(Discord##basename##Set##propname) \
|
RB_UNUSED_PARAM; \
|
||||||
{ \
|
VALUE str; \
|
||||||
RB_UNUSED_PARAM; \
|
rb_scan_args(argc, argv, "1", &str); \
|
||||||
VALUE str; \
|
SafeStringValue(str); \
|
||||||
rb_scan_args(argc, argv, "1", &str); \
|
Discord##basename *p = getPrivateData<Discord##basename>(self); \
|
||||||
SafeStringValue(str); \
|
strncpy(p->propname, RSTRING_PTR(str), maxsz); \
|
||||||
Discord##basename *p = getPrivateData<Discord##basename>(self); \
|
return str; \
|
||||||
strncpy(p->propname, RSTRING_PTR(str), maxsz); \
|
}
|
||||||
return str; \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define DEF_DCPROP_S_SUB(basename, subname, propname, maxsz) \
|
#define DEF_DCPROP_S_SUB(basename, subname, propname, maxsz) \
|
||||||
RB_METHOD(Discord##basename##Get##subname##_##propname) \
|
RB_METHOD(Discord##basename##Get##subname##_##propname) { \
|
||||||
{ \
|
RB_UNUSED_PARAM; \
|
||||||
RB_UNUSED_PARAM; \
|
Discord##basename *p = getPrivateData<Discord##basename>(self); \
|
||||||
Discord##basename *p = getPrivateData<Discord##basename>(self); \
|
return rb_str_new_cstr(p->subname.propname); \
|
||||||
return rb_str_new_cstr(p->subname.propname); \
|
} \
|
||||||
} \
|
RB_METHOD(Discord##basename##Set##subname##_##propname) { \
|
||||||
RB_METHOD(Discord##basename##Set##subname##_##propname) \
|
RB_UNUSED_PARAM; \
|
||||||
{ \
|
VALUE str; \
|
||||||
RB_UNUSED_PARAM; \
|
rb_scan_args(argc, argv, "1", &str); \
|
||||||
VALUE str; \
|
SafeStringValue(str); \
|
||||||
rb_scan_args(argc, argv, "1", &str); \
|
Discord##basename *p = getPrivateData<Discord##basename>(self); \
|
||||||
SafeStringValue(str); \
|
strncpy(p->subname.propname, RSTRING_PTR(str), maxsz); \
|
||||||
Discord##basename *p = getPrivateData<Discord##basename>(self); \
|
return str; \
|
||||||
strncpy(p->subname.propname, RSTRING_PTR(str), maxsz); \
|
}
|
||||||
return str; \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define DEF_DCPROP_I(basename, propname, convtype, cast) \
|
#define DEF_DCPROP_I(basename, propname, convtype, cast) \
|
||||||
RB_METHOD(Discord##basename##Get##propname) \
|
RB_METHOD(Discord##basename##Get##propname) { \
|
||||||
{ \
|
RB_UNUSED_PARAM; \
|
||||||
RB_UNUSED_PARAM; \
|
Discord##basename *p = getPrivateData<Discord##basename>(self); \
|
||||||
Discord##basename *p = getPrivateData<Discord##basename>(self); \
|
return convtype##2NUM(p->propname); \
|
||||||
return convtype##2NUM(p->propname); \
|
} \
|
||||||
} \
|
RB_METHOD(Discord##basename##Set##propname) { \
|
||||||
RB_METHOD(Discord##basename##Set##propname) \
|
RB_UNUSED_PARAM; \
|
||||||
{ \
|
VALUE num; \
|
||||||
RB_UNUSED_PARAM; \
|
rb_scan_args(argc, argv, "1", &num); \
|
||||||
VALUE num; \
|
Discord##basename *p = getPrivateData<Discord##basename>(self); \
|
||||||
rb_scan_args(argc, argv, "1", &num); \
|
p->propname = (cast)NUM2##convtype(num); \
|
||||||
Discord##basename *p = getPrivateData<Discord##basename>(self); \
|
return num; \
|
||||||
p->propname = (cast)NUM2##convtype(num); \
|
}
|
||||||
return num; \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define DEF_DCPROP_I_SUB(basename, subname, propname, convtype, cast) \
|
#define DEF_DCPROP_I_SUB(basename, subname, propname, convtype, cast) \
|
||||||
RB_METHOD(Discord##basename##Get##subname##_##propname) \
|
RB_METHOD(Discord##basename##Get##subname##_##propname) { \
|
||||||
{ \
|
RB_UNUSED_PARAM; \
|
||||||
RB_UNUSED_PARAM; \
|
Discord##basename *p = getPrivateData<Discord##basename>(self); \
|
||||||
Discord##basename *p = getPrivateData<Discord##basename>(self); \
|
return convtype##2NUM(p->subname.propname); \
|
||||||
return convtype##2NUM(p->subname.propname); \
|
} \
|
||||||
} \
|
RB_METHOD(Discord##basename##Set##subname##_##propname) { \
|
||||||
RB_METHOD(Discord##basename##Set##subname##_##propname) \
|
RB_UNUSED_PARAM; \
|
||||||
{ \
|
VALUE num; \
|
||||||
RB_UNUSED_PARAM; \
|
rb_scan_args(argc, argv, "1", &num); \
|
||||||
VALUE num; \
|
Discord##basename *p = getPrivateData<Discord##basename>(self); \
|
||||||
rb_scan_args(argc, argv, "1", &num); \
|
p->subname.propname = (cast)NUM2##convtype(num); \
|
||||||
Discord##basename *p = getPrivateData<Discord##basename>(self); \
|
return num; \
|
||||||
p->subname.propname = (cast)NUM2##convtype(num); \
|
}
|
||||||
return num; \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define DEF_DCPROP_B(basename, propname) \
|
#define DEF_DCPROP_B(basename, propname) \
|
||||||
RB_METHOD(Discord##basename##Get##propname) \
|
RB_METHOD(Discord##basename##Get##propname) { \
|
||||||
{ \
|
RB_UNUSED_PARAM; \
|
||||||
RB_UNUSED_PARAM; \
|
Discord##basename *p = getPrivateData<Discord##basename>(self); \
|
||||||
Discord##basename *p = getPrivateData<Discord##basename>(self); \
|
return rb_bool_new(p->propname); \
|
||||||
return rb_bool_new(p->propname); \
|
} \
|
||||||
} \
|
RB_METHOD(Discord##basename##Set##propname) { \
|
||||||
RB_METHOD(Discord##basename##Set##propname) \
|
RB_UNUSED_PARAM; \
|
||||||
{ \
|
bool b; \
|
||||||
RB_UNUSED_PARAM; \
|
rb_get_args(argc, argv, "b", &b RB_ARG_END); \
|
||||||
bool b; \
|
Discord##basename *p = getPrivateData<Discord##basename>(self); \
|
||||||
rb_get_args(argc, argv, "b", &b RB_ARG_END); \
|
p->propname = b; \
|
||||||
Discord##basename *p = getPrivateData<Discord##basename>(self); \
|
return rb_bool_new(b); \
|
||||||
p->propname = b; \
|
}
|
||||||
return rb_bool_new(b); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define DEF_DCPROP_B_SUB(basename, propname, subname) \
|
#define DEF_DCPROP_B_SUB(basename, propname, subname) \
|
||||||
RB_METHOD(Discord##basename##Get##propname) \
|
RB_METHOD(Discord##basename##Get##propname) { \
|
||||||
{ \
|
RB_UNUSED_PARAM; \
|
||||||
RB_UNUSED_PARAM; \
|
Discord##basename *p = getPrivateData<Discord##basename>(self); \
|
||||||
Discord##basename *p = getPrivateData<Discord##basename>(self); \
|
return rb_bool_new(p->subname.propname); \
|
||||||
return rb_bool_new(p->subname.propname); \
|
} \
|
||||||
} \
|
RB_METHOD(Discord##basename##Set##propname) { \
|
||||||
RB_METHOD(Discord##basename##Set##propname) \
|
RB_UNUSED_PARAM; \
|
||||||
{ \
|
bool b; \
|
||||||
RB_UNUSED_PARAM; \
|
rb_get_args(argc, argv, "b", &b RB_ARG_END); \
|
||||||
bool b; \
|
Discord##basename *p = getPrivateData<Discord##basename>(self); \
|
||||||
rb_get_args(argc, argv, "b", &b RB_ARG_END); \
|
p->subname.propname = b; \
|
||||||
Discord##basename *p = getPrivateData<Discord##basename>(self); \
|
return rb_bool_new(b); \
|
||||||
p->subname.propname = b; \
|
}
|
||||||
return rb_bool_new(b); \
|
|
||||||
}
|
|
||||||
|
|
||||||
DEF_DCPROP_S(Activity, state, 128);
|
DEF_DCPROP_S(Activity, state, 128);
|
||||||
DEF_DCPROP_S(Activity, details, 128);
|
DEF_DCPROP_S(Activity, details, 128);
|
||||||
|
@ -260,47 +235,46 @@ DEF_DCPROP_I_SUB(Activity, timestamps, start, LL, DiscordTimestamp);
|
||||||
DEF_DCPROP_I_SUB(Activity, timestamps, end, LL, DiscordTimestamp);
|
DEF_DCPROP_I_SUB(Activity, timestamps, end, LL, DiscordTimestamp);
|
||||||
DEF_DCPROP_B(Activity, instance);
|
DEF_DCPROP_B(Activity, instance);
|
||||||
|
|
||||||
#define BIND_DCPROP(basename, b, f) \
|
#define BIND_DCPROP(basename, b, f) \
|
||||||
_rb_define_method(activityClass, b, Discord##basename##Get##f); \
|
_rb_define_method(activityClass, b, Discord##basename##Get##f); \
|
||||||
_rb_define_method(activityClass, b "=", Discord##basename##Set##f);
|
_rb_define_method(activityClass, b "=", Discord##basename##Set##f);
|
||||||
|
|
||||||
|
void DiscordBindingInit() {
|
||||||
|
VALUE mod = rb_define_module("Discord");
|
||||||
|
_rb_define_module_function(mod, "connected?", DiscordConnected);
|
||||||
|
_rb_define_module_function(mod, "user_name", DiscordGetUsername);
|
||||||
|
_rb_define_module_function(mod, "user_discriminator",
|
||||||
|
DiscordGetDiscriminator);
|
||||||
|
_rb_define_module_function(mod, "user_id", DiscordGetUserId);
|
||||||
|
_rb_define_module_function(mod, "user_avatar", DiscordGetUserAvatar);
|
||||||
|
|
||||||
void DiscordBindingInit()
|
VALUE activityClass = rb_define_class_under(mod, "Activity", rb_cObject);
|
||||||
{
|
#if RAPI_FULL > 187
|
||||||
VALUE mod = rb_define_module("Discord");
|
rb_define_alloc_func(activityClass, classAllocate<&DCActivityType>);
|
||||||
_rb_define_module_function(mod, "connected?", DiscordConnected);
|
|
||||||
_rb_define_module_function(mod, "user_name", DiscordGetUsername);
|
|
||||||
_rb_define_module_function(mod, "user_discriminator", DiscordGetDiscriminator);
|
|
||||||
_rb_define_module_function(mod, "user_id", DiscordGetUserId);
|
|
||||||
_rb_define_module_function(mod, "user_avatar", DiscordGetUserAvatar);
|
|
||||||
|
|
||||||
VALUE activityClass = rb_define_class_under(mod, "Activity", rb_cObject);
|
|
||||||
#ifndef OLD_RUBY
|
|
||||||
rb_define_alloc_func(activityClass, classAllocate<&DCActivityType>);
|
|
||||||
#else
|
#else
|
||||||
rb_define_alloc_func(activityClass, DCActivityAllocate);
|
rb_define_alloc_func(activityClass, DCActivityAllocate);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
_rb_define_method(activityClass, "initialize", DiscordActivityInitialize);
|
_rb_define_method(activityClass, "initialize", DiscordActivityInitialize);
|
||||||
_rb_define_method(activityClass, "initialize_copy", DiscordActivityInitializeCopy);
|
_rb_define_method(activityClass, "initialize_copy",
|
||||||
|
DiscordActivityInitializeCopy);
|
||||||
rb_define_class_method(activityClass, "clear", DiscordActivityClear);
|
|
||||||
|
rb_define_class_method(activityClass, "clear", DiscordActivityClear);
|
||||||
_rb_define_method(activityClass, "send", DiscordActivitySend);
|
|
||||||
|
_rb_define_method(activityClass, "send", DiscordActivitySend);
|
||||||
BIND_DCPROP(Activity, "state", state);
|
|
||||||
BIND_DCPROP(Activity, "details", details);
|
BIND_DCPROP(Activity, "state", state);
|
||||||
BIND_DCPROP(Activity, "large_image", assets_large_image);
|
BIND_DCPROP(Activity, "details", details);
|
||||||
BIND_DCPROP(Activity, "large_text", assets_large_text);
|
BIND_DCPROP(Activity, "large_image", assets_large_image);
|
||||||
BIND_DCPROP(Activity, "small_image", assets_small_image);
|
BIND_DCPROP(Activity, "large_text", assets_large_text);
|
||||||
BIND_DCPROP(Activity, "small_text", assets_small_text);
|
BIND_DCPROP(Activity, "small_image", assets_small_image);
|
||||||
BIND_DCPROP(Activity, "party_id", party_id);
|
BIND_DCPROP(Activity, "small_text", assets_small_text);
|
||||||
BIND_DCPROP(Activity, "party_currentsize", Partycurrent_size);
|
BIND_DCPROP(Activity, "party_id", party_id);
|
||||||
BIND_DCPROP(Activity, "party_maxsize", Partymax_size);
|
BIND_DCPROP(Activity, "party_currentsize", Partycurrent_size);
|
||||||
|
BIND_DCPROP(Activity, "party_maxsize", Partymax_size);
|
||||||
BIND_DCPROP(Activity, "type", type);
|
|
||||||
BIND_DCPROP(Activity, "start_time", timestamps_start);
|
BIND_DCPROP(Activity, "type", type);
|
||||||
BIND_DCPROP(Activity, "end_time", timestamps_end);
|
BIND_DCPROP(Activity, "start_time", timestamps_start);
|
||||||
BIND_DCPROP(Activity, "instance", instance);
|
BIND_DCPROP(Activity, "end_time", timestamps_end);
|
||||||
|
BIND_DCPROP(Activity, "instance", instance);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,12 +19,12 @@
|
||||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "etc.h"
|
|
||||||
#include "binding-util.h"
|
#include "binding-util.h"
|
||||||
|
#include "etc.h"
|
||||||
#include "serializable-binding.h"
|
#include "serializable-binding.h"
|
||||||
#include "sharedstate.h"
|
#include "sharedstate.h"
|
||||||
|
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_FULL > 187
|
||||||
DEF_TYPE(Color);
|
DEF_TYPE(Color);
|
||||||
DEF_TYPE(Tone);
|
DEF_TYPE(Tone);
|
||||||
DEF_TYPE(Rect);
|
DEF_TYPE(Rect);
|
||||||
|
@ -34,24 +34,23 @@ DEF_ALLOCFUNC(Tone);
|
||||||
DEF_ALLOCFUNC(Rect);
|
DEF_ALLOCFUNC(Rect);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define ATTR_RW(Klass, Attr, arg_type, arg_t_s, value_fun) \
|
#define ATTR_RW(Klass, Attr, arg_type, arg_t_s, value_fun) \
|
||||||
RB_METHOD(Klass##Get##Attr) \
|
RB_METHOD(Klass##Get##Attr) { \
|
||||||
{ \
|
RB_UNUSED_PARAM \
|
||||||
RB_UNUSED_PARAM \
|
Klass *p = getPrivateData<Klass>(self); \
|
||||||
Klass *p = getPrivateData<Klass>(self); \
|
return value_fun(p->get##Attr()); \
|
||||||
return value_fun(p->get##Attr()); \
|
} \
|
||||||
} \
|
RB_METHOD(Klass##Set##Attr) { \
|
||||||
RB_METHOD(Klass##Set##Attr) \
|
Klass *p = getPrivateData<Klass>(self); \
|
||||||
{ \
|
arg_type arg; \
|
||||||
Klass *p = getPrivateData<Klass>(self); \
|
rb_get_args(argc, argv, arg_t_s, &arg RB_ARG_END); \
|
||||||
arg_type arg; \
|
p->set##Attr(arg); \
|
||||||
rb_get_args(argc, argv, arg_t_s, &arg RB_ARG_END); \
|
return *argv; \
|
||||||
p->set##Attr(arg); \
|
}
|
||||||
return *argv; \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define ATTR_DOUBLE_RW(Klass, Attr) ATTR_RW(Klass, Attr, double, "f", rb_float_new)
|
#define ATTR_DOUBLE_RW(Klass, Attr) \
|
||||||
#define ATTR_INT_RW(Klass, Attr) ATTR_RW(Klass, Attr, int, "i", rb_fix_new)
|
ATTR_RW(Klass, Attr, double, "f", rb_float_new)
|
||||||
|
#define ATTR_INT_RW(Klass, Attr) ATTR_RW(Klass, Attr, int, "i", rb_fix_new)
|
||||||
|
|
||||||
ATTR_DOUBLE_RW(Color, Red)
|
ATTR_DOUBLE_RW(Color, Red)
|
||||||
ATTR_DOUBLE_RW(Color, Green)
|
ATTR_DOUBLE_RW(Color, Green)
|
||||||
|
@ -68,161 +67,137 @@ ATTR_INT_RW(Rect, Y)
|
||||||
ATTR_INT_RW(Rect, Width)
|
ATTR_INT_RW(Rect, Width)
|
||||||
ATTR_INT_RW(Rect, Height)
|
ATTR_INT_RW(Rect, Height)
|
||||||
|
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_FULL > 187
|
||||||
#define EQUAL_FUN(Klass) \
|
#define EQUAL_FUN(Klass) \
|
||||||
RB_METHOD(Klass##Equal) \
|
RB_METHOD(Klass##Equal) { \
|
||||||
{ \
|
Klass *p = getPrivateData<Klass>(self); \
|
||||||
Klass *p = getPrivateData<Klass>(self); \
|
VALUE otherObj; \
|
||||||
VALUE otherObj; \
|
Klass *other; \
|
||||||
Klass *other; \
|
rb_get_args(argc, argv, "o", &otherObj RB_ARG_END); \
|
||||||
rb_get_args(argc, argv, "o", &otherObj RB_ARG_END); \
|
if (rgssVer >= 3) \
|
||||||
if (rgssVer >= 3) \
|
if (!rb_typeddata_is_kind_of(otherObj, &Klass##Type)) \
|
||||||
if (!rb_typeddata_is_kind_of(otherObj, &Klass##Type)) \
|
return Qfalse; \
|
||||||
return Qfalse; \
|
other = getPrivateDataCheck<Klass>(otherObj, Klass##Type); \
|
||||||
other = getPrivateDataCheck<Klass>(otherObj, Klass##Type); \
|
return rb_bool_new(*p == *other); \
|
||||||
return rb_bool_new(*p == *other); \
|
}
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
#define EQUAL_FUN(Klass) \
|
#define EQUAL_FUN(Klass) \
|
||||||
RB_METHOD(Klass##Equal) \
|
RB_METHOD(Klass##Equal) { \
|
||||||
{ \
|
Klass *p = getPrivateData<Klass>(self); \
|
||||||
Klass *p = getPrivateData<Klass>(self); \
|
VALUE otherObj; \
|
||||||
VALUE otherObj; \
|
Klass *other; \
|
||||||
Klass *other; \
|
rb_get_args(argc, argv, "o", &otherObj RB_ARG_END); \
|
||||||
rb_get_args(argc, argv, "o", &otherObj RB_ARG_END); \
|
return Qfalse; \
|
||||||
return Qfalse; \
|
other = getPrivateDataCheck<Klass>(otherObj, #Klass); \
|
||||||
other = getPrivateDataCheck<Klass>(otherObj, #Klass); \
|
return rb_bool_new(*p == *other); \
|
||||||
return rb_bool_new(*p == *other); \
|
}
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
EQUAL_FUN(Color)
|
EQUAL_FUN(Color)
|
||||||
EQUAL_FUN(Tone)
|
EQUAL_FUN(Tone)
|
||||||
EQUAL_FUN(Rect)
|
EQUAL_FUN(Rect)
|
||||||
|
|
||||||
#define INIT_FUN(Klass, param_type, param_t_s, last_param_def) \
|
#define INIT_FUN(Klass, param_type, param_t_s, last_param_def) \
|
||||||
RB_METHOD(Klass##Initialize) \
|
RB_METHOD(Klass##Initialize) { \
|
||||||
{ \
|
Klass *k; \
|
||||||
Klass *k; \
|
if (argc == 0) { \
|
||||||
if (argc == 0) \
|
k = new Klass(); \
|
||||||
{ \
|
} else { \
|
||||||
k = new Klass(); \
|
param_type p1, p2, p3, p4 = last_param_def; \
|
||||||
} \
|
rb_get_args(argc, argv, param_t_s, &p1, &p2, &p3, &p4 RB_ARG_END); \
|
||||||
else \
|
k = new Klass(p1, p2, p3, p4); \
|
||||||
{ \
|
} \
|
||||||
param_type p1, p2, p3, p4 = last_param_def; \
|
setPrivateData(self, k); \
|
||||||
rb_get_args(argc, argv, param_t_s, &p1, &p2, &p3, &p4 RB_ARG_END); \
|
return self; \
|
||||||
k = new Klass(p1, p2, p3, p4); \
|
}
|
||||||
} \
|
|
||||||
setPrivateData(self, k); \
|
|
||||||
return self; \
|
|
||||||
}
|
|
||||||
|
|
||||||
INIT_FUN(Color, double, "fff|f", 255)
|
INIT_FUN(Color, double, "fff|f", 255)
|
||||||
INIT_FUN(Tone, double, "fff|f", 0)
|
INIT_FUN(Tone, double, "fff|f", 0)
|
||||||
INIT_FUN(Rect, int, "iiii", 0)
|
INIT_FUN(Rect, int, "iiii", 0)
|
||||||
|
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_FULL > 187
|
||||||
#define SET_FUN(Klass, param_type, param_t_s, last_param_def) \
|
#define SET_FUN(Klass, param_type, param_t_s, last_param_def) \
|
||||||
RB_METHOD(Klass##Set) \
|
RB_METHOD(Klass##Set) { \
|
||||||
{ \
|
Klass *k = getPrivateData<Klass>(self); \
|
||||||
Klass *k = getPrivateData<Klass>(self); \
|
if (argc == 1) { \
|
||||||
if (argc == 1) \
|
VALUE otherObj = argv[0]; \
|
||||||
{ \
|
Klass *other = getPrivateDataCheck<Klass>(otherObj, Klass##Type); \
|
||||||
VALUE otherObj = argv[0]; \
|
*k = *other; \
|
||||||
Klass *other = getPrivateDataCheck<Klass>(otherObj, Klass##Type); \
|
} else { \
|
||||||
*k = *other; \
|
param_type p1, p2, p3, p4 = last_param_def; \
|
||||||
} \
|
rb_get_args(argc, argv, param_t_s, &p1, &p2, &p3, &p4 RB_ARG_END); \
|
||||||
else \
|
k->set(p1, p2, p3, p4); \
|
||||||
{ \
|
} \
|
||||||
param_type p1, p2, p3, p4 = last_param_def; \
|
return self; \
|
||||||
rb_get_args(argc, argv, param_t_s, &p1, &p2, &p3, &p4 RB_ARG_END); \
|
}
|
||||||
k->set(p1, p2, p3, p4); \
|
|
||||||
} \
|
|
||||||
return self; \
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
#define SET_FUN(Klass, param_type, param_t_s, last_param_def) \
|
#define SET_FUN(Klass, param_type, param_t_s, last_param_def) \
|
||||||
RB_METHOD(Klass##Set) \
|
RB_METHOD(Klass##Set) { \
|
||||||
{ \
|
Klass *k = getPrivateData<Klass>(self); \
|
||||||
Klass *k = getPrivateData<Klass>(self); \
|
if (argc == 1) { \
|
||||||
if (argc == 1) \
|
VALUE otherObj = argv[0]; \
|
||||||
{ \
|
Klass *other = getPrivateDataCheck<Klass>(otherObj, #Klass); \
|
||||||
VALUE otherObj = argv[0]; \
|
*k = *other; \
|
||||||
Klass *other = getPrivateDataCheck<Klass>(otherObj, #Klass); \
|
} else { \
|
||||||
*k = *other; \
|
param_type p1, p2, p3, p4 = last_param_def; \
|
||||||
} \
|
rb_get_args(argc, argv, param_t_s, &p1, &p2, &p3, &p4 RB_ARG_END); \
|
||||||
else \
|
k->set(p1, p2, p3, p4); \
|
||||||
{ \
|
} \
|
||||||
param_type p1, p2, p3, p4 = last_param_def; \
|
return self; \
|
||||||
rb_get_args(argc, argv, param_t_s, &p1, &p2, &p3, &p4 RB_ARG_END); \
|
}
|
||||||
k->set(p1, p2, p3, p4); \
|
|
||||||
} \
|
|
||||||
return self; \
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SET_FUN(Color, double, "fff|f", 255)
|
SET_FUN(Color, double, "fff|f", 255)
|
||||||
SET_FUN(Tone, double, "fff|f", 0)
|
SET_FUN(Tone, double, "fff|f", 0)
|
||||||
SET_FUN(Rect, int, "iiii", 0)
|
SET_FUN(Rect, int, "iiii", 0)
|
||||||
|
|
||||||
RB_METHOD(rectEmpty)
|
RB_METHOD(rectEmpty) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
Rect *r = getPrivateData<Rect>(self);
|
||||||
Rect *r = getPrivateData<Rect>(self);
|
r->empty();
|
||||||
r->empty();
|
return self;
|
||||||
return self;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(ColorStringify)
|
RB_METHOD(ColorStringify) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
|
||||||
Color *c = getPrivateData<Color>(self);
|
Color *c = getPrivateData<Color>(self);
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_FULL > 187
|
||||||
return rb_sprintf("(%f, %f, %f, %f)",
|
return rb_sprintf("(%f, %f, %f, %f)", c->red, c->green, c->blue, c->alpha);
|
||||||
c->red, c->green, c->blue, c->alpha);
|
|
||||||
#else
|
#else
|
||||||
char buf[50] = {0};
|
char buf[50] = {0};
|
||||||
sprintf((char*)&buf, "(%f, %f, %f, %f)",
|
sprintf((char *)&buf, "(%f, %f, %f, %f)", c->red, c->green, c->blue,
|
||||||
c->red, c->green, c->blue, c->alpha);
|
c->alpha);
|
||||||
return rb_str_new2(buf);
|
return rb_str_new2(buf);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(ToneStringify)
|
RB_METHOD(ToneStringify) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
|
||||||
Tone *t = getPrivateData<Tone>(self);
|
Tone *t = getPrivateData<Tone>(self);
|
||||||
|
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_FULL > 187
|
||||||
return rb_sprintf("(%f, %f, %f, %f)",
|
return rb_sprintf("(%f, %f, %f, %f)", t->red, t->green, t->blue, t->gray);
|
||||||
t->red, t->green, t->blue, t->gray);
|
|
||||||
#else
|
#else
|
||||||
char buf[50] = {0};
|
char buf[50] = {0};
|
||||||
sprintf((char*)&buf, "(%f, %f, %f, %f)",
|
sprintf((char *)&buf, "(%f, %f, %f, %f)", t->red, t->green, t->blue, t->gray);
|
||||||
t->red, t->green, t->blue, t->gray);
|
return rb_str_new2(buf);
|
||||||
return rb_str_new2(buf);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(RectStringify)
|
RB_METHOD(RectStringify) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
|
||||||
Rect *r = getPrivateData<Rect>(self);
|
Rect *r = getPrivateData<Rect>(self);
|
||||||
|
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_FULL > 187
|
||||||
return rb_sprintf("(%d, %d, %d, %d)",
|
return rb_sprintf("(%d, %d, %d, %d)", r->x, r->y, r->width, r->height);
|
||||||
r->x, r->y, r->width, r->height);
|
|
||||||
#else
|
#else
|
||||||
char buf[50] = {0};
|
char buf[50] = {0};
|
||||||
sprintf((char*)&buf, "(%d, %d, %d, %d)",
|
sprintf((char *)&buf, "(%d, %d, %d, %d)", r->x, r->y, r->width, r->height);
|
||||||
r->x, r->y, r->width, r->height);
|
return rb_str_new2(buf);
|
||||||
return rb_str_new2(buf);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MARSH_LOAD_FUN(Color)
|
MARSH_LOAD_FUN(Color)
|
||||||
|
@ -233,73 +208,82 @@ INITCOPY_FUN(Tone)
|
||||||
INITCOPY_FUN(Color)
|
INITCOPY_FUN(Color)
|
||||||
INITCOPY_FUN(Rect)
|
INITCOPY_FUN(Rect)
|
||||||
|
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_FULL > 187
|
||||||
#define INIT_BIND(Klass) \
|
#define INIT_BIND(Klass) \
|
||||||
{ \
|
{ \
|
||||||
klass = rb_define_class(#Klass, rb_cObject); \
|
klass = rb_define_class(#Klass, rb_cObject); \
|
||||||
rb_define_alloc_func(klass, classAllocate<&Klass##Type>); \
|
rb_define_alloc_func(klass, classAllocate<&Klass##Type>); \
|
||||||
rb_define_class_method(klass, "_load", Klass##Load); \
|
rb_define_class_method(klass, "_load", Klass##Load); \
|
||||||
serializableBindingInit<Klass>(klass); \
|
serializableBindingInit<Klass>(klass); \
|
||||||
_rb_define_method(klass, "initialize", Klass##Initialize); \
|
_rb_define_method(klass, "initialize", Klass##Initialize); \
|
||||||
_rb_define_method(klass, "initialize_copy", Klass##InitializeCopy); \
|
_rb_define_method(klass, "initialize_copy", Klass##InitializeCopy); \
|
||||||
_rb_define_method(klass, "set", Klass##Set); \
|
_rb_define_method(klass, "set", Klass##Set); \
|
||||||
_rb_define_method(klass, "==", Klass##Equal); \
|
_rb_define_method(klass, "==", Klass##Equal); \
|
||||||
_rb_define_method(klass, "===", Klass##Equal); \
|
_rb_define_method(klass, "===", Klass##Equal); \
|
||||||
_rb_define_method(klass, "eql?", Klass##Equal); \
|
_rb_define_method(klass, "eql?", Klass##Equal); \
|
||||||
_rb_define_method(klass, "to_s", Klass##Stringify); \
|
_rb_define_method(klass, "to_s", Klass##Stringify); \
|
||||||
_rb_define_method(klass, "inspect", Klass##Stringify); \
|
_rb_define_method(klass, "inspect", Klass##Stringify); \
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#define INIT_BIND(Klass) \
|
#define INIT_BIND(Klass) \
|
||||||
{ \
|
{ \
|
||||||
klass = rb_define_class(#Klass, rb_cObject); \
|
klass = rb_define_class(#Klass, rb_cObject); \
|
||||||
rb_define_alloc_func(klass, Klass##Allocate); \
|
rb_define_alloc_func(klass, Klass##Allocate); \
|
||||||
rb_define_class_method(klass, "_load", Klass##Load); \
|
rb_define_class_method(klass, "_load", Klass##Load); \
|
||||||
serializableBindingInit<Klass>(klass); \
|
serializableBindingInit<Klass>(klass); \
|
||||||
_rb_define_method(klass, "initialize", Klass##Initialize); \
|
_rb_define_method(klass, "initialize", Klass##Initialize); \
|
||||||
_rb_define_method(klass, "initialize_copy", Klass##InitializeCopy); \
|
_rb_define_method(klass, "initialize_copy", Klass##InitializeCopy); \
|
||||||
_rb_define_method(klass, "set", Klass##Set); \
|
_rb_define_method(klass, "set", Klass##Set); \
|
||||||
_rb_define_method(klass, "==", Klass##Equal); \
|
_rb_define_method(klass, "==", Klass##Equal); \
|
||||||
_rb_define_method(klass, "===", Klass##Equal); \
|
_rb_define_method(klass, "===", Klass##Equal); \
|
||||||
_rb_define_method(klass, "eql?", Klass##Equal); \
|
_rb_define_method(klass, "eql?", Klass##Equal); \
|
||||||
_rb_define_method(klass, "to_s", Klass##Stringify); \
|
_rb_define_method(klass, "to_s", Klass##Stringify); \
|
||||||
_rb_define_method(klass, "inspect", Klass##Stringify); \
|
_rb_define_method(klass, "inspect", Klass##Stringify); \
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define MRB_ATTR_R(Class, attr) mrb_define_method(mrb, klass, #attr, Class##Get_##attr, MRB_ARGS_NONE())
|
#define MRB_ATTR_R(Class, attr) \
|
||||||
#define MRB_ATTR_W(Class, attr) mrb_define_method(mrb, klass, #attr "=", Class##Set_##attr, MRB_ARGS_REQ(1))
|
mrb_define_method(mrb, klass, #attr, Class##Get_##attr, MRB_ARGS_NONE())
|
||||||
#define MRB_ATTR_RW(Class, attr) { MRB_ATTR_R(Class, attr); MRB_ATTR_W(Class, attr); }
|
#define MRB_ATTR_W(Class, attr) \
|
||||||
|
mrb_define_method(mrb, klass, #attr "=", Class##Set_##attr, MRB_ARGS_REQ(1))
|
||||||
|
#define MRB_ATTR_RW(Class, attr) \
|
||||||
|
{ \
|
||||||
|
MRB_ATTR_R(Class, attr); \
|
||||||
|
MRB_ATTR_W(Class, attr); \
|
||||||
|
}
|
||||||
|
|
||||||
#define RB_ATTR_R(Klass, Attr, attr) _rb_define_method(klass, #attr, Klass##Get##Attr)
|
#define RB_ATTR_R(Klass, Attr, attr) \
|
||||||
#define RB_ATTR_W(Klass, Attr, attr) _rb_define_method(klass, #attr "=", Klass##Set##Attr)
|
_rb_define_method(klass, #attr, Klass##Get##Attr)
|
||||||
#define RB_ATTR_RW(Klass, Attr, attr) \
|
#define RB_ATTR_W(Klass, Attr, attr) \
|
||||||
{ RB_ATTR_R(Klass, Attr, attr); RB_ATTR_W(Klass, Attr, attr); }
|
_rb_define_method(klass, #attr "=", Klass##Set##Attr)
|
||||||
|
#define RB_ATTR_RW(Klass, Attr, attr) \
|
||||||
|
{ \
|
||||||
|
RB_ATTR_R(Klass, Attr, attr); \
|
||||||
|
RB_ATTR_W(Klass, Attr, attr); \
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void etcBindingInit() {
|
||||||
etcBindingInit()
|
VALUE klass;
|
||||||
{
|
|
||||||
VALUE klass;
|
|
||||||
|
|
||||||
INIT_BIND(Color);
|
INIT_BIND(Color);
|
||||||
|
|
||||||
RB_ATTR_RW(Color, Red, red);
|
RB_ATTR_RW(Color, Red, red);
|
||||||
RB_ATTR_RW(Color, Green, green);
|
RB_ATTR_RW(Color, Green, green);
|
||||||
RB_ATTR_RW(Color, Blue, blue);
|
RB_ATTR_RW(Color, Blue, blue);
|
||||||
RB_ATTR_RW(Color, Alpha, alpha);
|
RB_ATTR_RW(Color, Alpha, alpha);
|
||||||
|
|
||||||
INIT_BIND(Tone);
|
INIT_BIND(Tone);
|
||||||
|
|
||||||
RB_ATTR_RW(Tone, Red, red);
|
RB_ATTR_RW(Tone, Red, red);
|
||||||
RB_ATTR_RW(Tone, Green, green);
|
RB_ATTR_RW(Tone, Green, green);
|
||||||
RB_ATTR_RW(Tone, Blue, blue);
|
RB_ATTR_RW(Tone, Blue, blue);
|
||||||
RB_ATTR_RW(Tone, Gray, gray);
|
RB_ATTR_RW(Tone, Gray, gray);
|
||||||
|
|
||||||
INIT_BIND(Rect);
|
INIT_BIND(Rect);
|
||||||
|
|
||||||
RB_ATTR_RW(Rect, X, x);
|
RB_ATTR_RW(Rect, X, x);
|
||||||
RB_ATTR_RW(Rect, Y, y);
|
RB_ATTR_RW(Rect, Y, y);
|
||||||
RB_ATTR_RW(Rect, Width, width);
|
RB_ATTR_RW(Rect, Width, width);
|
||||||
RB_ATTR_RW(Rect, Height, height);
|
RB_ATTR_RW(Rect, Height, height);
|
||||||
_rb_define_method(klass, "empty", rectEmpty);
|
_rb_define_method(klass, "empty", rectEmpty);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
#include "src/config.h"
|
#include "src/config.h"
|
||||||
#include "src/util.h"
|
#include "src/util.h"
|
||||||
|
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_FULL > 187
|
||||||
#include "ruby/encoding.h"
|
#include "ruby/encoding.h"
|
||||||
#include "ruby/intern.h"
|
#include "ruby/intern.h"
|
||||||
#else
|
#else
|
||||||
|
@ -40,7 +40,7 @@ static void fileIntFreeInstance(void *inst) {
|
||||||
SDL_FreeRW(ops);
|
SDL_FreeRW(ops);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_FULL > 187
|
||||||
DEF_TYPE_CUSTOMFREE(FileInt, fileIntFreeInstance);
|
DEF_TYPE_CUSTOMFREE(FileInt, fileIntFreeInstance);
|
||||||
#else
|
#else
|
||||||
DEF_ALLOCFUNC_CUSTOMFREE(FileInt, fileIntFreeInstance);
|
DEF_ALLOCFUNC_CUSTOMFREE(FileInt, fileIntFreeInstance);
|
||||||
|
@ -200,8 +200,8 @@ RB_METHOD(kernelSaveData) {
|
||||||
|
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_FULL > 187
|
||||||
#if RUBYCOMPAT < 270
|
#if RAPI_FULL < 270
|
||||||
static VALUE stringForceUTF8(VALUE arg)
|
static VALUE stringForceUTF8(VALUE arg)
|
||||||
#else
|
#else
|
||||||
static VALUE stringForceUTF8(RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, arg))
|
static VALUE stringForceUTF8(RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, arg))
|
||||||
|
@ -213,7 +213,7 @@ static VALUE stringForceUTF8(RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, arg))
|
||||||
return arg;
|
return arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if RUBYCOMPAT < 270
|
#if RAPI_FULL < 270
|
||||||
static VALUE customProc(VALUE arg, VALUE proc) {
|
static VALUE customProc(VALUE arg, VALUE proc) {
|
||||||
VALUE obj = stringForceUTF8(arg);
|
VALUE obj = stringForceUTF8(arg);
|
||||||
obj = rb_funcall2(proc, rb_intern("call"), 1, &obj);
|
obj = rb_funcall2(proc, rb_intern("call"), 1, &obj);
|
||||||
|
@ -224,16 +224,16 @@ static VALUE customProc(VALUE arg, VALUE proc) {
|
||||||
|
|
||||||
RB_METHOD(_marshalLoad) {
|
RB_METHOD(_marshalLoad) {
|
||||||
RB_UNUSED_PARAM;
|
RB_UNUSED_PARAM;
|
||||||
#if RUBYCOMPAT < 270
|
#if RAPI_FULL < 270
|
||||||
VALUE port, proc = Qnil;
|
VALUE port, proc = Qnil;
|
||||||
rb_get_args(argc, argv, "o|o", &port, &proc RB_ARG_END);
|
rb_get_args(argc, argv, "o|o", &port, &proc RB_ARG_END);
|
||||||
#else
|
#else
|
||||||
VALUE port;
|
VALUE port;
|
||||||
rb_get_args(argc, argv, "o", &port RB_ARG_END);
|
rb_get_args(argc, argv, "o", &port RB_ARG_END);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
VALUE utf8Proc;
|
VALUE utf8Proc;
|
||||||
#if RUBYCOMPAT < 270
|
#if RAPI_FULL < 270
|
||||||
if (NIL_P(proc))
|
if (NIL_P(proc))
|
||||||
|
|
||||||
utf8Proc = rb_proc_new(RUBY_METHOD_FUNC(stringForceUTF8), Qnil);
|
utf8Proc = rb_proc_new(RUBY_METHOD_FUNC(stringForceUTF8), Qnil);
|
||||||
|
@ -250,35 +250,35 @@ RB_METHOD(_marshalLoad) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void fileIntBindingInit() {
|
void fileIntBindingInit() {
|
||||||
VALUE klass = rb_define_class("FileInt", rb_cIO);
|
VALUE klass = rb_define_class("FileInt", rb_cIO);
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_FULL > 187
|
||||||
rb_define_alloc_func(klass, classAllocate<&FileIntType>);
|
rb_define_alloc_func(klass, classAllocate<&FileIntType>);
|
||||||
#else
|
#else
|
||||||
rb_define_alloc_func(klass, FileIntAllocate);
|
rb_define_alloc_func(klass, FileIntAllocate);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
_rb_define_method(klass, "read", fileIntRead);
|
_rb_define_method(klass, "read", fileIntRead);
|
||||||
_rb_define_method(klass, "getbyte", fileIntGetByte);
|
_rb_define_method(klass, "getbyte", fileIntGetByte);
|
||||||
#ifdef OLD_RUBY
|
#if RAPI_FULL <= 187
|
||||||
// Ruby doesn't see this as an initialized stream,
|
// Ruby doesn't see this as an initialized stream,
|
||||||
// so either that has to be fixed or necessary
|
// so either that has to be fixed or necessary
|
||||||
// IO functions have to be overridden
|
// IO functions have to be overridden
|
||||||
rb_define_alias(klass, "getc", "getbyte");
|
rb_define_alias(klass, "getc", "getbyte");
|
||||||
_rb_define_method(klass, "pos", fileIntPos);
|
_rb_define_method(klass, "pos", fileIntPos);
|
||||||
#endif
|
#endif
|
||||||
_rb_define_method(klass, "binmode", fileIntBinmode);
|
_rb_define_method(klass, "binmode", fileIntBinmode);
|
||||||
_rb_define_method(klass, "close", fileIntClose);
|
_rb_define_method(klass, "close", fileIntClose);
|
||||||
|
|
||||||
_rb_define_module_function(rb_mKernel, "load_data", kernelLoadData);
|
_rb_define_module_function(rb_mKernel, "load_data", kernelLoadData);
|
||||||
_rb_define_module_function(rb_mKernel, "save_data", kernelSaveData);
|
_rb_define_module_function(rb_mKernel, "save_data", kernelSaveData);
|
||||||
|
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_FULL > 187
|
||||||
/* We overload the built-in 'Marshal::load()' function to silently
|
/* We overload the built-in 'Marshal::load()' function to silently
|
||||||
* insert our utf8proc that ensures all read strings will be
|
* insert our utf8proc that ensures all read strings will be
|
||||||
* UTF-8 encoded */
|
* UTF-8 encoded */
|
||||||
VALUE marsh = rb_const_get(rb_cObject, rb_intern("Marshal"));
|
VALUE marsh = rb_const_get(rb_cObject, rb_intern("Marshal"));
|
||||||
rb_define_alias(rb_singleton_class(marsh), "_mkxp_load_alias", "load");
|
rb_define_alias(rb_singleton_class(marsh), "_mkxp_load_alias", "load");
|
||||||
_rb_define_module_function(marsh, "load", _marshalLoad);
|
_rb_define_module_function(marsh, "load", _marshalLoad);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,149 +19,133 @@
|
||||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "font.h"
|
|
||||||
#include "binding-util.h"
|
|
||||||
#include "binding-types.h"
|
#include "binding-types.h"
|
||||||
|
#include "binding-util.h"
|
||||||
#include "exception.h"
|
#include "exception.h"
|
||||||
|
#include "font.h"
|
||||||
#include "sharedstate.h"
|
#include "sharedstate.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
static void collectStrings(VALUE obj, std::vector<std::string> &out) {
|
||||||
|
if (RB_TYPE_P(obj, RUBY_T_STRING)) {
|
||||||
|
out.push_back(RSTRING_PTR(obj));
|
||||||
|
} else if (RB_TYPE_P(obj, RUBY_T_ARRAY)) {
|
||||||
|
for (long i = 0; i < RARRAY_LEN(obj); ++i) {
|
||||||
|
VALUE str = rb_ary_entry(obj, i);
|
||||||
|
|
||||||
static void
|
/* Non-string objects are tolerated (ignored) */
|
||||||
collectStrings(VALUE obj, std::vector<std::string> &out)
|
if (!RB_TYPE_P(str, RUBY_T_STRING))
|
||||||
{
|
continue;
|
||||||
if (RB_TYPE_P(obj, RUBY_T_STRING))
|
|
||||||
{
|
|
||||||
out.push_back(RSTRING_PTR(obj));
|
|
||||||
}
|
|
||||||
else if (RB_TYPE_P(obj, RUBY_T_ARRAY))
|
|
||||||
{
|
|
||||||
for (long i = 0; i < RARRAY_LEN(obj); ++i)
|
|
||||||
{
|
|
||||||
VALUE str = rb_ary_entry(obj, i);
|
|
||||||
|
|
||||||
/* Non-string objects are tolerated (ignored) */
|
out.push_back(RSTRING_PTR(str));
|
||||||
if (!RB_TYPE_P(str, RUBY_T_STRING))
|
}
|
||||||
continue;
|
}
|
||||||
|
|
||||||
out.push_back(RSTRING_PTR(str));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_FULL > 187
|
||||||
DEF_TYPE(Font);
|
DEF_TYPE(Font);
|
||||||
#else
|
#else
|
||||||
DEF_ALLOCFUNC(Font);
|
DEF_ALLOCFUNC(Font);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
RB_METHOD(fontDoesExist)
|
RB_METHOD(fontDoesExist) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
|
||||||
const char *name = 0;
|
const char *name = 0;
|
||||||
VALUE nameObj;
|
VALUE nameObj;
|
||||||
|
|
||||||
rb_get_args(argc, argv, "o", &nameObj RB_ARG_END);
|
rb_get_args(argc, argv, "o", &nameObj RB_ARG_END);
|
||||||
|
|
||||||
if (RB_TYPE_P(nameObj, RUBY_T_STRING))
|
if (RB_TYPE_P(nameObj, RUBY_T_STRING))
|
||||||
name = rb_string_value_cstr(&nameObj);
|
name = rb_string_value_cstr(&nameObj);
|
||||||
|
|
||||||
return rb_bool_new(Font::doesExist(name));
|
return rb_bool_new(Font::doesExist(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(FontSetName);
|
RB_METHOD(FontSetName);
|
||||||
|
|
||||||
RB_METHOD(fontInitialize)
|
RB_METHOD(fontInitialize) {
|
||||||
{
|
VALUE namesObj = Qnil;
|
||||||
VALUE namesObj = Qnil;
|
int size = 0;
|
||||||
int size = 0;
|
|
||||||
|
|
||||||
rb_get_args(argc, argv, "|oi", &namesObj, &size RB_ARG_END);
|
rb_get_args(argc, argv, "|oi", &namesObj, &size RB_ARG_END);
|
||||||
|
|
||||||
Font *f;
|
Font *f;
|
||||||
|
|
||||||
if (NIL_P(namesObj))
|
if (NIL_P(namesObj)) {
|
||||||
{
|
namesObj = rb_iv_get(rb_obj_class(self), "default_name");
|
||||||
namesObj = rb_iv_get(rb_obj_class(self), "default_name");
|
f = new Font(0, size);
|
||||||
f = new Font(0, size);
|
} else {
|
||||||
}
|
std::vector<std::string> names;
|
||||||
else
|
collectStrings(namesObj, names);
|
||||||
{
|
|
||||||
std::vector<std::string> names;
|
|
||||||
collectStrings(namesObj, names);
|
|
||||||
|
|
||||||
f = new Font(&names, size);
|
f = new Font(&names, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This is semantically wrong; the new Font object should take
|
/* This is semantically wrong; the new Font object should take
|
||||||
* a dup'ed object here in case of an array. Ditto for the setters.
|
* a dup'ed object here in case of an array. Ditto for the setters.
|
||||||
* However the same bug/behavior exists in all RM versions. */
|
* However the same bug/behavior exists in all RM versions. */
|
||||||
rb_iv_set(self, "name", namesObj);
|
rb_iv_set(self, "name", namesObj);
|
||||||
|
|
||||||
setPrivateData(self, f);
|
setPrivateData(self, f);
|
||||||
|
|
||||||
/* Wrap property objects */
|
/* Wrap property objects */
|
||||||
f->initDynAttribs();
|
f->initDynAttribs();
|
||||||
|
|
||||||
wrapProperty(self, &f->getColor(), "color", ColorType);
|
wrapProperty(self, &f->getColor(), "color", ColorType);
|
||||||
|
|
||||||
if (rgssVer >= 3)
|
if (rgssVer >= 3)
|
||||||
wrapProperty(self, &f->getOutColor(), "out_color", ColorType);
|
wrapProperty(self, &f->getOutColor(), "out_color", ColorType);
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(fontInitializeCopy)
|
RB_METHOD(fontInitializeCopy) {
|
||||||
{
|
VALUE origObj;
|
||||||
VALUE origObj;
|
rb_get_args(argc, argv, "o", &origObj RB_ARG_END);
|
||||||
rb_get_args(argc, argv, "o", &origObj RB_ARG_END);
|
|
||||||
|
|
||||||
if (!OBJ_INIT_COPY(self, origObj))
|
if (!OBJ_INIT_COPY(self, origObj))
|
||||||
return self;
|
return self;
|
||||||
|
|
||||||
Font *orig = getPrivateData<Font>(origObj);
|
Font *orig = getPrivateData<Font>(origObj);
|
||||||
Font *f = new Font(*orig);
|
Font *f = new Font(*orig);
|
||||||
setPrivateData(self, f);
|
setPrivateData(self, f);
|
||||||
|
|
||||||
/* Wrap property objects */
|
/* Wrap property objects */
|
||||||
f->initDynAttribs();
|
f->initDynAttribs();
|
||||||
|
|
||||||
wrapProperty(self, &f->getColor(), "color", ColorType);
|
wrapProperty(self, &f->getColor(), "color", ColorType);
|
||||||
|
|
||||||
if (rgssVer >= 3)
|
if (rgssVer >= 3)
|
||||||
wrapProperty(self, &f->getOutColor(), "out_color", ColorType);
|
wrapProperty(self, &f->getOutColor(), "out_color", ColorType);
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(FontGetName)
|
RB_METHOD(FontGetName) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
|
||||||
return rb_iv_get(self, "name");
|
return rb_iv_get(self, "name");
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(FontSetName)
|
RB_METHOD(FontSetName) {
|
||||||
{
|
Font *f = getPrivateData<Font>(self);
|
||||||
Font *f = getPrivateData<Font>(self);
|
|
||||||
|
|
||||||
rb_check_argc(argc, 1);
|
rb_check_argc(argc, 1);
|
||||||
|
|
||||||
std::vector<std::string> namesObj;
|
std::vector<std::string> namesObj;
|
||||||
collectStrings(argv[0], namesObj);
|
collectStrings(argv[0], namesObj);
|
||||||
|
|
||||||
f->setName(namesObj);
|
f->setName(namesObj);
|
||||||
rb_iv_set(self, "name", argv[0]);
|
rb_iv_set(self, "name", argv[0]);
|
||||||
|
|
||||||
return argv[0];
|
return argv[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class C>
|
template <class C> static void checkDisposed(VALUE) {}
|
||||||
static void checkDisposed(VALUE) {}
|
|
||||||
|
|
||||||
DEF_PROP_OBJ_VAL(Font, Color, Color, "color")
|
DEF_PROP_OBJ_VAL(Font, Color, Color, "color")
|
||||||
DEF_PROP_OBJ_VAL(Font, Color, OutColor, "out_color")
|
DEF_PROP_OBJ_VAL(Font, Color, OutColor, "out_color")
|
||||||
|
|
||||||
DEF_PROP_I(Font, Size)
|
DEF_PROP_I(Font, Size)
|
||||||
|
@ -171,166 +155,149 @@ DEF_PROP_B(Font, Italic)
|
||||||
DEF_PROP_B(Font, Shadow)
|
DEF_PROP_B(Font, Shadow)
|
||||||
DEF_PROP_B(Font, Outline)
|
DEF_PROP_B(Font, Outline)
|
||||||
|
|
||||||
#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) { \
|
||||||
{ \
|
RB_UNUSED_PARAM; \
|
||||||
RB_UNUSED_PARAM; \
|
return value_fun(Klass::get##PropName()); \
|
||||||
return value_fun(Klass::get##PropName()); \
|
} \
|
||||||
} \
|
RB_METHOD(Klass##Set##PropName) { \
|
||||||
RB_METHOD(Klass##Set##PropName) \
|
RB_UNUSED_PARAM; \
|
||||||
{ \
|
type value; \
|
||||||
RB_UNUSED_PARAM; \
|
rb_get_args(argc, argv, param_t_s, &value RB_ARG_END); \
|
||||||
type value; \
|
Klass::set##PropName(value); \
|
||||||
rb_get_args(argc, argv, param_t_s, &value RB_ARG_END); \
|
return value_fun(value); \
|
||||||
Klass::set##PropName(value); \
|
}
|
||||||
return value_fun(value); \
|
|
||||||
}
|
|
||||||
|
|
||||||
DEF_KLASS_PROP(Font, int, DefaultSize, "i", rb_fix_new)
|
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)
|
||||||
DEF_KLASS_PROP(Font, bool, DefaultShadow, "b", rb_bool_new)
|
DEF_KLASS_PROP(Font, bool, DefaultShadow, "b", rb_bool_new)
|
||||||
DEF_KLASS_PROP(Font, bool, DefaultOutline, "b", rb_bool_new)
|
DEF_KLASS_PROP(Font, bool, DefaultOutline, "b", rb_bool_new)
|
||||||
|
|
||||||
RB_METHOD(FontGetDefaultOutColor)
|
RB_METHOD(FontGetDefaultOutColor) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
return rb_iv_get(self, "default_out_color");
|
||||||
return rb_iv_get(self, "default_out_color");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(FontSetDefaultOutColor)
|
RB_METHOD(FontSetDefaultOutColor) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
|
||||||
VALUE colorObj;
|
VALUE colorObj;
|
||||||
rb_get_args(argc, argv, "o", &colorObj RB_ARG_END);
|
rb_get_args(argc, argv, "o", &colorObj RB_ARG_END);
|
||||||
|
|
||||||
Color *c = getPrivateDataCheck<Color>(colorObj, ColorType);
|
Color *c = getPrivateDataCheck<Color>(colorObj, ColorType);
|
||||||
|
|
||||||
Font::setDefaultOutColor(*c);
|
Font::setDefaultOutColor(*c);
|
||||||
|
|
||||||
return colorObj;
|
return colorObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(FontGetDefaultName)
|
RB_METHOD(FontGetDefaultName) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
|
||||||
return rb_iv_get(self, "default_name");
|
return rb_iv_get(self, "default_name");
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(FontSetDefaultName)
|
RB_METHOD(FontSetDefaultName) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
|
||||||
rb_check_argc(argc, 1);
|
rb_check_argc(argc, 1);
|
||||||
|
|
||||||
std::vector<std::string> namesObj;
|
std::vector<std::string> namesObj;
|
||||||
collectStrings(argv[0], namesObj);
|
collectStrings(argv[0], namesObj);
|
||||||
|
|
||||||
Font::setDefaultName(namesObj, shState->fontState());
|
Font::setDefaultName(namesObj, shState->fontState());
|
||||||
rb_iv_set(self, "default_name", argv[0]);
|
rb_iv_set(self, "default_name", argv[0]);
|
||||||
|
|
||||||
return argv[0];
|
return argv[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(FontGetDefaultColor)
|
RB_METHOD(FontGetDefaultColor) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
return rb_iv_get(self, "default_color");
|
||||||
return rb_iv_get(self, "default_color");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RB_METHOD(FontSetDefaultColor) {
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
RB_METHOD(FontSetDefaultColor)
|
VALUE colorObj;
|
||||||
{
|
rb_get_args(argc, argv, "o", &colorObj RB_ARG_END);
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
|
||||||
VALUE colorObj;
|
Color *c = getPrivateDataCheck<Color>(colorObj, ColorType);
|
||||||
rb_get_args(argc, argv, "o", &colorObj RB_ARG_END);
|
|
||||||
|
|
||||||
Color *c = getPrivateDataCheck<Color>(colorObj, ColorType);
|
Font::setDefaultColor(*c);
|
||||||
|
|
||||||
Font::setDefaultColor(*c);
|
return colorObj;
|
||||||
|
|
||||||
return colorObj;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define INIT_KLASS_PROP_BIND(Klass, PropName, prop_name_s) \
|
#define INIT_KLASS_PROP_BIND(Klass, PropName, prop_name_s) \
|
||||||
{ \
|
{ \
|
||||||
rb_define_class_method(klass, prop_name_s, Klass##Get##PropName); \
|
rb_define_class_method(klass, prop_name_s, Klass##Get##PropName); \
|
||||||
rb_define_class_method(klass, prop_name_s "=", Klass##Set##PropName); \
|
rb_define_class_method(klass, prop_name_s "=", Klass##Set##PropName); \
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void fontBindingInit() {
|
||||||
fontBindingInit()
|
VALUE klass = rb_define_class("Font", rb_cObject);
|
||||||
{
|
#if RAPI_FULL > 187
|
||||||
VALUE klass = rb_define_class("Font", rb_cObject);
|
rb_define_alloc_func(klass, classAllocate<&FontType>);
|
||||||
#ifndef OLD_RUBY
|
|
||||||
rb_define_alloc_func(klass, classAllocate<&FontType>);
|
|
||||||
#else
|
#else
|
||||||
rb_define_alloc_func(klass, FontAllocate);
|
rb_define_alloc_func(klass, FontAllocate);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Font::initDefaultDynAttribs();
|
Font::initDefaultDynAttribs();
|
||||||
wrapProperty(klass, &Font::getDefaultColor(), "default_color", ColorType);
|
wrapProperty(klass, &Font::getDefaultColor(), "default_color", ColorType);
|
||||||
|
|
||||||
/* Initialize default names */
|
/* Initialize default names */
|
||||||
const std::vector<std::string> &defNames = Font::getInitialDefaultNames();
|
const std::vector<std::string> &defNames = Font::getInitialDefaultNames();
|
||||||
VALUE defNamesObj;
|
VALUE defNamesObj;
|
||||||
|
|
||||||
if (defNames.size() == 1)
|
if (defNames.size() == 1) {
|
||||||
{
|
defNamesObj = rb_str_new_cstr(defNames[0].c_str());
|
||||||
defNamesObj = rb_str_new_cstr(defNames[0].c_str());
|
} else {
|
||||||
}
|
defNamesObj = rb_ary_new2(defNames.size());
|
||||||
else
|
|
||||||
{
|
|
||||||
defNamesObj = rb_ary_new2(defNames.size());
|
|
||||||
|
|
||||||
for (size_t i = 0; i < defNames.size(); ++i)
|
for (size_t i = 0; i < defNames.size(); ++i)
|
||||||
rb_ary_push(defNamesObj, rb_str_new_cstr(defNames[i].c_str()));
|
rb_ary_push(defNamesObj, rb_str_new_cstr(defNames[i].c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
rb_iv_set(klass, "default_name", defNamesObj);
|
rb_iv_set(klass, "default_name", defNamesObj);
|
||||||
|
|
||||||
if (rgssVer >= 3)
|
if (rgssVer >= 3)
|
||||||
wrapProperty(klass, &Font::getDefaultOutColor(), "default_out_color", ColorType);
|
wrapProperty(klass, &Font::getDefaultOutColor(), "default_out_color",
|
||||||
|
ColorType);
|
||||||
|
|
||||||
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)
|
if (rgssVer >= 2) {
|
||||||
{
|
INIT_KLASS_PROP_BIND(Font, DefaultShadow, "default_shadow");
|
||||||
INIT_KLASS_PROP_BIND(Font, DefaultShadow, "default_shadow");
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (rgssVer >= 3)
|
if (rgssVer >= 3) {
|
||||||
{
|
INIT_KLASS_PROP_BIND(Font, DefaultOutline, "default_outline");
|
||||||
INIT_KLASS_PROP_BIND(Font, DefaultOutline, "default_outline");
|
INIT_KLASS_PROP_BIND(Font, DefaultOutColor, "default_out_color");
|
||||||
INIT_KLASS_PROP_BIND(Font, DefaultOutColor, "default_out_color");
|
}
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
||||||
_rb_define_method(klass, "initialize_copy", fontInitializeCopy);
|
_rb_define_method(klass, "initialize_copy", fontInitializeCopy);
|
||||||
|
|
||||||
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)
|
if (rgssVer >= 2) {
|
||||||
{
|
INIT_PROP_BIND(Font, Shadow, "shadow");
|
||||||
INIT_PROP_BIND(Font, Shadow, "shadow");
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (rgssVer >= 3)
|
if (rgssVer >= 3) {
|
||||||
{
|
INIT_PROP_BIND(Font, Outline, "outline");
|
||||||
INIT_PROP_BIND(Font, Outline, "outline");
|
INIT_PROP_BIND(Font, OutColor, "out_color");
|
||||||
INIT_PROP_BIND(Font, OutColor, "out_color");
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,408 +19,364 @@
|
||||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "binding-util.h"
|
||||||
|
#include "exception.h"
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include "sharedstate.h"
|
#include "sharedstate.h"
|
||||||
#include "exception.h"
|
|
||||||
#include "binding-util.h"
|
|
||||||
#include "src/util.h"
|
#include "src/util.h"
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <SDL_joystick.h>
|
#include <SDL_joystick.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
RB_METHOD(inputUpdate)
|
RB_METHOD(inputUpdate) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
|
||||||
shState->input().update();
|
shState->input().update();
|
||||||
|
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int getButtonArg(VALUE *argv)
|
static int getButtonArg(VALUE *argv) {
|
||||||
{
|
int num;
|
||||||
int num;
|
|
||||||
|
if (FIXNUM_P(*argv)) {
|
||||||
if (FIXNUM_P(*argv))
|
num = FIX2INT(*argv);
|
||||||
{
|
} else if (SYMBOL_P(*argv) && rgssVer >= 3) {
|
||||||
num = FIX2INT(*argv);
|
VALUE symHash = getRbData()->buttoncodeHash;
|
||||||
}
|
#if RAPI_FULL > 187
|
||||||
else if (SYMBOL_P(*argv) && rgssVer >= 3)
|
num = FIX2INT(rb_hash_lookup2(symHash, *argv, INT2FIX(Input::None)));
|
||||||
{
|
|
||||||
VALUE symHash = getRbData()->buttoncodeHash;
|
|
||||||
#ifndef OLD_RUBY
|
|
||||||
num = FIX2INT(rb_hash_lookup2(symHash, *argv, INT2FIX(Input::None)));
|
|
||||||
#else
|
#else
|
||||||
VALUE res = rb_hash_aref(symHash, *argv);
|
VALUE res = rb_hash_aref(symHash, *argv);
|
||||||
if (!NIL_P(res))
|
if (!NIL_P(res))
|
||||||
num = FIX2INT(res);
|
num = FIX2INT(res);
|
||||||
else
|
else
|
||||||
num = Input::None;
|
num = Input::None;
|
||||||
#endif
|
#endif
|
||||||
}
|
} else {
|
||||||
else
|
// FIXME: RMXP allows only few more types that
|
||||||
{
|
// don't make sense (symbols in pre 3, floats)
|
||||||
// FIXME: RMXP allows only few more types that
|
num = 0;
|
||||||
// don't make sense (symbols in pre 3, floats)
|
}
|
||||||
num = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int getScancodeArg(VALUE *argv)
|
static int getScancodeArg(VALUE *argv) {
|
||||||
{
|
const char *scancode = rb_id2name(SYM2ID(*argv));
|
||||||
const char *scancode = rb_id2name(SYM2ID(*argv));
|
int code{};
|
||||||
int code{};
|
try {
|
||||||
try
|
code = strToScancode[scancode];
|
||||||
{
|
} catch (...) {
|
||||||
code = strToScancode[scancode];
|
rb_raise(rb_eRuntimeError, "%s is not a valid key.", scancode);
|
||||||
}
|
}
|
||||||
catch (...)
|
|
||||||
{
|
return code;
|
||||||
rb_raise(rb_eRuntimeError, "%s is not a valid key.", scancode);
|
|
||||||
}
|
|
||||||
|
|
||||||
return code;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(inputPress)
|
RB_METHOD(inputPress) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
|
||||||
rb_check_argc(argc, 1);
|
|
||||||
|
|
||||||
VALUE button;
|
|
||||||
rb_scan_args(argc, argv, "1", &button);
|
|
||||||
|
|
||||||
int num{};
|
|
||||||
|
|
||||||
if (SYMBOL_P(button))
|
|
||||||
{
|
|
||||||
num = getScancodeArg(&button);
|
|
||||||
return rb_bool_new(shState->input().isPressedEx(num, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
num = getButtonArg(&button);
|
|
||||||
|
|
||||||
return rb_bool_new(shState->input().isPressed(num));
|
rb_check_argc(argc, 1);
|
||||||
|
|
||||||
|
VALUE button;
|
||||||
|
rb_scan_args(argc, argv, "1", &button);
|
||||||
|
|
||||||
|
int num{};
|
||||||
|
|
||||||
|
if (SYMBOL_P(button)) {
|
||||||
|
num = getScancodeArg(&button);
|
||||||
|
return rb_bool_new(shState->input().isPressedEx(num, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
num = getButtonArg(&button);
|
||||||
|
|
||||||
|
return rb_bool_new(shState->input().isPressed(num));
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(inputTrigger)
|
RB_METHOD(inputTrigger) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
|
||||||
rb_check_argc(argc, 1);
|
|
||||||
|
|
||||||
VALUE button;
|
rb_check_argc(argc, 1);
|
||||||
rb_scan_args(argc, argv, "1", &button);
|
|
||||||
|
|
||||||
int num{};
|
|
||||||
|
|
||||||
if (SYMBOL_P(button))
|
|
||||||
{
|
|
||||||
num = getScancodeArg(&button);
|
|
||||||
return rb_bool_new(shState->input().isTriggeredEx(num, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
num = getButtonArg(&button);
|
|
||||||
|
|
||||||
return rb_bool_new(shState->input().isTriggered(num));
|
VALUE button;
|
||||||
|
rb_scan_args(argc, argv, "1", &button);
|
||||||
|
|
||||||
|
int num{};
|
||||||
|
|
||||||
|
if (SYMBOL_P(button)) {
|
||||||
|
num = getScancodeArg(&button);
|
||||||
|
return rb_bool_new(shState->input().isTriggeredEx(num, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
num = getButtonArg(&button);
|
||||||
|
|
||||||
|
return rb_bool_new(shState->input().isTriggered(num));
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(inputRepeat)
|
RB_METHOD(inputRepeat) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
|
||||||
rb_check_argc(argc, 1);
|
|
||||||
|
|
||||||
VALUE button;
|
|
||||||
rb_scan_args(argc, argv, "1", &button);
|
|
||||||
|
|
||||||
int num{};
|
|
||||||
|
|
||||||
if (SYMBOL_P(button))
|
|
||||||
{
|
|
||||||
num = getScancodeArg(&button);
|
|
||||||
return rb_bool_new(shState->input().isRepeatedEx(num, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
num = getButtonArg(&button);
|
|
||||||
|
|
||||||
return rb_bool_new(shState->input().isRepeated(num));
|
rb_check_argc(argc, 1);
|
||||||
|
|
||||||
|
VALUE button;
|
||||||
|
rb_scan_args(argc, argv, "1", &button);
|
||||||
|
|
||||||
|
int num{};
|
||||||
|
|
||||||
|
if (SYMBOL_P(button)) {
|
||||||
|
num = getScancodeArg(&button);
|
||||||
|
return rb_bool_new(shState->input().isRepeatedEx(num, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
num = getButtonArg(&button);
|
||||||
|
|
||||||
|
return rb_bool_new(shState->input().isRepeated(num));
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(inputPressEx)
|
RB_METHOD(inputPressEx) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
int num;
|
||||||
int num;
|
rb_get_args(argc, argv, "i", &num RB_ARG_END);
|
||||||
rb_get_args(argc, argv, "i", &num RB_ARG_END);
|
|
||||||
|
return rb_bool_new(shState->input().isPressedEx(num, 1));
|
||||||
return rb_bool_new(shState->input().isPressedEx(num, 1));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(inputTriggerEx)
|
RB_METHOD(inputTriggerEx) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
int num;
|
||||||
int num;
|
rb_get_args(argc, argv, "i", &num RB_ARG_END);
|
||||||
rb_get_args(argc, argv, "i", &num RB_ARG_END);
|
|
||||||
|
return rb_bool_new(shState->input().isTriggeredEx(num, 1));
|
||||||
return rb_bool_new(shState->input().isTriggeredEx(num, 1));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(inputRepeatEx)
|
RB_METHOD(inputRepeatEx) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
int num;
|
||||||
int num;
|
rb_get_args(argc, argv, "i", &num RB_ARG_END);
|
||||||
rb_get_args(argc, argv, "i", &num RB_ARG_END);
|
|
||||||
|
return rb_bool_new(shState->input().isRepeatedEx(num, 1));
|
||||||
return rb_bool_new(shState->input().isRepeatedEx(num, 1));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(inputDir4)
|
RB_METHOD(inputDir4) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
|
||||||
return rb_fix_new(shState->input().dir4Value());
|
return rb_fix_new(shState->input().dir4Value());
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(inputDir8)
|
RB_METHOD(inputDir8) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
|
||||||
return rb_fix_new(shState->input().dir8Value());
|
return rb_fix_new(shState->input().dir8Value());
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Non-standard extensions */
|
/* Non-standard extensions */
|
||||||
RB_METHOD(inputMouseX)
|
RB_METHOD(inputMouseX) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
|
||||||
return rb_fix_new(shState->input().mouseX());
|
return rb_fix_new(shState->input().mouseX());
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(inputMouseY)
|
RB_METHOD(inputMouseY) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
|
||||||
return rb_fix_new(shState->input().mouseY());
|
return rb_fix_new(shState->input().mouseY());
|
||||||
}
|
}
|
||||||
|
|
||||||
#define M_SYMBOL(x) ID2SYM(rb_intern(x))
|
#define M_SYMBOL(x) ID2SYM(rb_intern(x))
|
||||||
#define POWERCASE(v,c) \
|
#define POWERCASE(v, c) \
|
||||||
case SDL_JOYSTICK_POWER_##c: \
|
case SDL_JOYSTICK_POWER_##c: \
|
||||||
v = M_SYMBOL(#c); \
|
v = M_SYMBOL(#c); \
|
||||||
break;
|
break;
|
||||||
|
|
||||||
RB_METHOD(inputJoystickInfo)
|
RB_METHOD(inputJoystickInfo) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
if (!shState->input().getJoystickConnected())
|
||||||
if (!shState->input().getJoystickConnected())
|
return RUBY_Qnil;
|
||||||
return RUBY_Qnil;
|
|
||||||
|
VALUE ret = rb_hash_new();
|
||||||
VALUE ret = rb_hash_new();
|
|
||||||
|
rb_hash_aset(ret, M_SYMBOL("name"),
|
||||||
rb_hash_aset(ret, M_SYMBOL("name"), rb_str_new_cstr(shState->input().getJoystickName()));
|
rb_str_new_cstr(shState->input().getJoystickName()));
|
||||||
|
|
||||||
VALUE power;
|
VALUE power;
|
||||||
|
|
||||||
switch (shState->input().getJoystickPowerLevel()) {
|
switch (shState->input().getJoystickPowerLevel()) {
|
||||||
POWERCASE(power, MAX);
|
POWERCASE(power, MAX);
|
||||||
POWERCASE(power, WIRED);
|
POWERCASE(power, WIRED);
|
||||||
POWERCASE(power, FULL);
|
POWERCASE(power, FULL);
|
||||||
POWERCASE(power, MEDIUM);
|
POWERCASE(power, MEDIUM);
|
||||||
POWERCASE(power, LOW);
|
POWERCASE(power, LOW);
|
||||||
POWERCASE(power, EMPTY);
|
POWERCASE(power, EMPTY);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
power = M_SYMBOL("UNKNOWN");
|
power = M_SYMBOL("UNKNOWN");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
rb_hash_aset(ret, M_SYMBOL("power"), power);
|
rb_hash_aset(ret, M_SYMBOL("power"), power);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
}
|
}
|
||||||
#undef POWERCASE
|
#undef POWERCASE
|
||||||
#undef M_SYMBOL
|
#undef M_SYMBOL
|
||||||
|
|
||||||
RB_METHOD(inputRumble)
|
RB_METHOD(inputRumble) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
VALUE duration, strength, attack, fade;
|
||||||
VALUE duration, strength, attack, fade;
|
rb_scan_args(argc, argv, "13", &duration, &strength, &attack, &fade);
|
||||||
rb_scan_args(argc, argv, "13", &duration, &strength, &attack, &fade);
|
|
||||||
|
int dur = NUM2INT(duration);
|
||||||
int dur = NUM2INT(duration);
|
int str = (NIL_P(strength)) ? 1 : NUM2INT(strength);
|
||||||
int str = (NIL_P(strength)) ? 1 : NUM2INT(strength);
|
int att = (NIL_P(attack)) ? 0 : NUM2INT(attack);
|
||||||
int att = (NIL_P(attack)) ? 0 : NUM2INT(attack);
|
int fad = (NIL_P(fade)) ? 0 : NUM2INT(fade);
|
||||||
int fad = (NIL_P(fade)) ? 0 : NUM2INT(fade);
|
|
||||||
|
shState->input().rumble(dur, str, att, fad);
|
||||||
shState->input().rumble(dur, str, att, fad);
|
|
||||||
|
return Qnil;
|
||||||
return Qnil;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(inputGetMode)
|
RB_METHOD(inputGetMode) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
return rb_bool_new(shState->input().getTextInputMode());
|
||||||
return rb_bool_new(shState->input().getTextInputMode());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(inputSetMode)
|
RB_METHOD(inputSetMode) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
bool mode;
|
||||||
bool mode;
|
rb_get_args(argc, argv, "b", &mode RB_ARG_END);
|
||||||
rb_get_args(argc, argv, "b", &mode RB_ARG_END);
|
|
||||||
|
shState->input().setTextInputMode(mode);
|
||||||
shState->input().setTextInputMode(mode);
|
|
||||||
|
return mode;
|
||||||
return mode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(inputGets)
|
RB_METHOD(inputGets) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
VALUE ret = rb_str_new_cstr(shState->input().getText());
|
||||||
VALUE ret = rb_str_new_cstr(shState->input().getText());
|
shState->input().clearText();
|
||||||
shState->input().clearText();
|
|
||||||
|
return ret;
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(inputGetClipboard)
|
RB_METHOD(inputGetClipboard) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
VALUE ret;
|
||||||
VALUE ret;
|
try {
|
||||||
try {
|
ret = rb_str_new_cstr(shState->input().getClipboardText());
|
||||||
ret = rb_str_new_cstr(shState->input().getClipboardText());
|
} catch (const Exception &e) {
|
||||||
} catch (const Exception &e) {
|
raiseRbExc(e);
|
||||||
raiseRbExc(e);
|
}
|
||||||
}
|
return ret;
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(inputSetClipboard)
|
RB_METHOD(inputSetClipboard) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
VALUE str;
|
||||||
VALUE str;
|
rb_scan_args(argc, argv, "1", &str);
|
||||||
rb_scan_args(argc, argv, "1", &str);
|
|
||||||
|
SafeStringValue(str);
|
||||||
SafeStringValue(str);
|
|
||||||
|
try {
|
||||||
try {
|
shState->input().setClipboardText(RSTRING_PTR(str));
|
||||||
shState->input().setClipboardText(RSTRING_PTR(str));
|
} catch (const Exception &e) {
|
||||||
} catch (const Exception &e) {
|
raiseRbExc(e);
|
||||||
raiseRbExc(e);
|
}
|
||||||
}
|
return str;
|
||||||
return str;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct {
|
||||||
|
const char *str;
|
||||||
|
Input::ButtonCode val;
|
||||||
|
} static buttonCodes[] = {{"DOWN", Input::Down},
|
||||||
|
{"LEFT", Input::Left},
|
||||||
|
{"RIGHT", Input::Right},
|
||||||
|
{"UP", Input::Up},
|
||||||
|
|
||||||
struct
|
|
||||||
{
|
|
||||||
const char *str;
|
|
||||||
Input::ButtonCode val;
|
|
||||||
}
|
|
||||||
static buttonCodes[] =
|
|
||||||
{
|
|
||||||
{ "DOWN", Input::Down },
|
|
||||||
{ "LEFT", Input::Left },
|
|
||||||
{ "RIGHT", Input::Right },
|
|
||||||
{ "UP", Input::Up },
|
|
||||||
|
|
||||||
#ifdef MARIN
|
#ifdef MARIN
|
||||||
{ "ZL", Input::ZL },
|
{"ZL", Input::ZL},
|
||||||
{ "ZR", Input::ZR },
|
{"ZR", Input::ZR},
|
||||||
#else
|
#else
|
||||||
{ "C", Input::ZL },
|
{"C", Input::ZL},
|
||||||
{ "Z", Input::ZR },
|
{"Z", Input::ZR},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
{ "A", Input::A },
|
{"A", Input::A},
|
||||||
{ "B", Input::B },
|
{"B", Input::B},
|
||||||
{ "X", Input::X },
|
{"X", Input::X},
|
||||||
{ "Y", Input::Y },
|
{"Y", Input::Y},
|
||||||
{ "L", Input::L },
|
{"L", Input::L},
|
||||||
{ "R", Input::R },
|
{"R", Input::R},
|
||||||
|
|
||||||
{ "SHIFT", Input::Shift },
|
{"SHIFT", Input::Shift},
|
||||||
{ "CTRL", Input::Ctrl },
|
{"CTRL", Input::Ctrl},
|
||||||
{ "ALT", Input::Alt },
|
{"ALT", Input::Alt},
|
||||||
|
|
||||||
{ "F5", Input::F5 },
|
{"F5", Input::F5},
|
||||||
{ "F6", Input::F6 },
|
{"F6", Input::F6},
|
||||||
{ "F7", Input::F7 },
|
{"F7", Input::F7},
|
||||||
{ "F8", Input::F8 },
|
{"F8", Input::F8},
|
||||||
{ "F9", Input::F9 },
|
{"F9", Input::F9},
|
||||||
|
|
||||||
{ "MOUSELEFT", Input::MouseLeft },
|
{"MOUSELEFT", Input::MouseLeft},
|
||||||
{ "MOUSEMIDDLE", Input::MouseMiddle },
|
{"MOUSEMIDDLE", Input::MouseMiddle},
|
||||||
{ "MOUSERIGHT", Input::MouseRight }
|
{"MOUSERIGHT", Input::MouseRight}};
|
||||||
};
|
|
||||||
|
|
||||||
static elementsN(buttonCodes);
|
static elementsN(buttonCodes);
|
||||||
|
|
||||||
void
|
void inputBindingInit() {
|
||||||
inputBindingInit()
|
VALUE module = rb_define_module("Input");
|
||||||
{
|
|
||||||
VALUE module = rb_define_module("Input");
|
|
||||||
|
|
||||||
_rb_define_module_function(module, "update", inputUpdate);
|
_rb_define_module_function(module, "update", inputUpdate);
|
||||||
_rb_define_module_function(module, "press?", inputPress);
|
_rb_define_module_function(module, "press?", inputPress);
|
||||||
_rb_define_module_function(module, "trigger?", inputTrigger);
|
_rb_define_module_function(module, "trigger?", inputTrigger);
|
||||||
_rb_define_module_function(module, "repeat?", inputRepeat);
|
_rb_define_module_function(module, "repeat?", inputRepeat);
|
||||||
_rb_define_module_function(module, "pressex?", inputPressEx);
|
_rb_define_module_function(module, "pressex?", inputPressEx);
|
||||||
_rb_define_module_function(module, "triggerex?", inputTriggerEx);
|
_rb_define_module_function(module, "triggerex?", inputTriggerEx);
|
||||||
_rb_define_module_function(module, "repeatex?", inputRepeatEx);
|
_rb_define_module_function(module, "repeatex?", inputRepeatEx);
|
||||||
_rb_define_module_function(module, "dir4", inputDir4);
|
_rb_define_module_function(module, "dir4", inputDir4);
|
||||||
_rb_define_module_function(module, "dir8", inputDir8);
|
_rb_define_module_function(module, "dir8", inputDir8);
|
||||||
|
|
||||||
_rb_define_module_function(module, "mouse_x", inputMouseX);
|
_rb_define_module_function(module, "mouse_x", inputMouseX);
|
||||||
_rb_define_module_function(module, "mouse_y", inputMouseY);
|
_rb_define_module_function(module, "mouse_y", inputMouseY);
|
||||||
|
|
||||||
_rb_define_module_function(module, "joystick", inputJoystickInfo);
|
|
||||||
_rb_define_module_function(module, "rumble", inputRumble);
|
|
||||||
|
|
||||||
_rb_define_module_function(module, "text_input", inputGetMode);
|
|
||||||
_rb_define_module_function(module, "text_input=", inputSetMode);
|
|
||||||
_rb_define_module_function(module, "gets", inputGets);
|
|
||||||
|
|
||||||
_rb_define_module_function(module, "clipboard", inputGetClipboard);
|
|
||||||
_rb_define_module_function(module, "clipboard=", inputSetClipboard);
|
|
||||||
|
|
||||||
if (rgssVer >= 3)
|
_rb_define_module_function(module, "joystick", inputJoystickInfo);
|
||||||
{
|
_rb_define_module_function(module, "rumble", inputRumble);
|
||||||
VALUE symHash = rb_hash_new();
|
|
||||||
|
|
||||||
for (size_t i = 0; i < buttonCodesN; ++i)
|
_rb_define_module_function(module, "text_input", inputGetMode);
|
||||||
{
|
_rb_define_module_function(module, "text_input=", inputSetMode);
|
||||||
ID sym = rb_intern(buttonCodes[i].str);
|
_rb_define_module_function(module, "gets", inputGets);
|
||||||
VALUE val = INT2FIX(buttonCodes[i].val);
|
|
||||||
|
|
||||||
/* In RGSS3 all Input::XYZ constants are equal to :XYZ symbols,
|
_rb_define_module_function(module, "clipboard", inputGetClipboard);
|
||||||
* to be compatible with the previous convention */
|
_rb_define_module_function(module, "clipboard=", inputSetClipboard);
|
||||||
rb_const_set(module, sym, ID2SYM(sym));
|
|
||||||
rb_hash_aset(symHash, ID2SYM(sym), val);
|
|
||||||
}
|
|
||||||
|
|
||||||
rb_iv_set(module, "buttoncodes", symHash);
|
if (rgssVer >= 3) {
|
||||||
getRbData()->buttoncodeHash = symHash;
|
VALUE symHash = rb_hash_new();
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (size_t i = 0; i < buttonCodesN; ++i)
|
|
||||||
{
|
|
||||||
ID sym = rb_intern(buttonCodes[i].str);
|
|
||||||
VALUE val = INT2FIX(buttonCodes[i].val);
|
|
||||||
|
|
||||||
rb_const_set(module, sym, val);
|
for (size_t i = 0; i < buttonCodesN; ++i) {
|
||||||
}
|
ID sym = rb_intern(buttonCodes[i].str);
|
||||||
}
|
VALUE val = INT2FIX(buttonCodes[i].val);
|
||||||
|
|
||||||
|
/* In RGSS3 all Input::XYZ constants are equal to :XYZ symbols,
|
||||||
|
* to be compatible with the previous convention */
|
||||||
|
rb_const_set(module, sym, ID2SYM(sym));
|
||||||
|
rb_hash_aset(symHash, ID2SYM(sym), val);
|
||||||
|
}
|
||||||
|
|
||||||
|
rb_iv_set(module, "buttoncodes", symHash);
|
||||||
|
getRbData()->buttoncodeHash = symHash;
|
||||||
|
} else {
|
||||||
|
for (size_t i = 0; i < buttonCodesN; ++i) {
|
||||||
|
ID sym = rb_intern(buttonCodes[i].str);
|
||||||
|
VALUE val = INT2FIX(buttonCodes[i].val);
|
||||||
|
|
||||||
|
rb_const_set(module, sym, val);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
|
|
||||||
if get_option('mri_includes') == ''
|
if get_option('mri_includes') == ''
|
||||||
ver = get_option('mri_version')
|
ver = get_option('mri_version')
|
||||||
if ver.version_compare('>1.8') == false
|
if ver.version_compare('<=1.9')
|
||||||
add_project_arguments('-DOLD_RUBY', language: ['cpp','objc','objcpp'])
|
global_args += '-DLEGACY_RUBY'
|
||||||
endif
|
|
||||||
if ver.version_compare('>=2.7') == true
|
|
||||||
add_project_arguments('-DRUBYCOMPAT=270', language: ['cpp', 'objc', 'objcpp'])
|
|
||||||
endif
|
endif
|
||||||
global_dependencies += dependency('ruby-' + ver)
|
global_dependencies += dependency('ruby-' + ver)
|
||||||
else
|
else
|
||||||
|
|
|
@ -36,7 +36,7 @@ typedef PREFABI void *(*MINIFFI_FUNC)(unsigned long, unsigned long,
|
||||||
// MiniFFI class, also named Win32API on Windows
|
// MiniFFI class, also named Win32API on Windows
|
||||||
// Uses LoadLibrary/GetProcAddress on Windows, dlopen/dlsym everywhere else
|
// Uses LoadLibrary/GetProcAddress on Windows, dlopen/dlsym everywhere else
|
||||||
|
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_FULL > 187
|
||||||
DEF_TYPE_CUSTOMFREE(MiniFFI, SDL_UnloadObject);
|
DEF_TYPE_CUSTOMFREE(MiniFFI, SDL_UnloadObject);
|
||||||
#else
|
#else
|
||||||
DEF_ALLOCFUNC_CUSTOMFREE(MiniFFI, SDL_UnloadObject);
|
DEF_ALLOCFUNC_CUSTOMFREE(MiniFFI, SDL_UnloadObject);
|
||||||
|
@ -308,7 +308,7 @@ RB_METHOD(MiniFFI_call) {
|
||||||
|
|
||||||
void MiniFFIBindingInit() {
|
void MiniFFIBindingInit() {
|
||||||
VALUE cMiniFFI = rb_define_class("MiniFFI", rb_cObject);
|
VALUE cMiniFFI = rb_define_class("MiniFFI", rb_cObject);
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_FULL > 187
|
||||||
rb_define_alloc_func(cMiniFFI, classAllocate<&MiniFFIType>);
|
rb_define_alloc_func(cMiniFFI, classAllocate<&MiniFFIType>);
|
||||||
#else
|
#else
|
||||||
rb_define_alloc_func(cMiniFFI, MiniFFIAllocate);
|
rb_define_alloc_func(cMiniFFI, MiniFFIAllocate);
|
||||||
|
|
|
@ -19,35 +19,34 @@
|
||||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "plane.h"
|
|
||||||
#include "disposable-binding.h"
|
|
||||||
#include "viewportelement-binding.h"
|
|
||||||
#include "binding-util.h"
|
|
||||||
#include "binding-types.h"
|
#include "binding-types.h"
|
||||||
|
#include "binding-util.h"
|
||||||
|
#include "disposable-binding.h"
|
||||||
|
#include "plane.h"
|
||||||
|
#include "viewportelement-binding.h"
|
||||||
|
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_FULL > 187
|
||||||
DEF_TYPE(Plane);
|
DEF_TYPE(Plane);
|
||||||
#else
|
#else
|
||||||
DEF_ALLOCFUNC(Plane);
|
DEF_ALLOCFUNC(Plane);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
RB_METHOD(planeInitialize)
|
RB_METHOD(planeInitialize) {
|
||||||
{
|
Plane *p = viewportElementInitialize<Plane>(argc, argv, self);
|
||||||
Plane *p = viewportElementInitialize<Plane>(argc, argv, self);
|
|
||||||
|
|
||||||
setPrivateData(self, p);
|
setPrivateData(self, p);
|
||||||
|
|
||||||
p->initDynAttribs();
|
p->initDynAttribs();
|
||||||
|
|
||||||
wrapProperty(self, &p->getColor(), "color", ColorType);
|
wrapProperty(self, &p->getColor(), "color", ColorType);
|
||||||
wrapProperty(self, &p->getTone(), "tone", ToneType);
|
wrapProperty(self, &p->getTone(), "tone", ToneType);
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
DEF_PROP_OBJ_REF(Plane, Bitmap, Bitmap, "bitmap")
|
DEF_PROP_OBJ_REF(Plane, Bitmap, Bitmap, "bitmap")
|
||||||
DEF_PROP_OBJ_VAL(Plane, Color, Color, "color")
|
DEF_PROP_OBJ_VAL(Plane, Color, Color, "color")
|
||||||
DEF_PROP_OBJ_VAL(Plane, Tone, Tone, "tone")
|
DEF_PROP_OBJ_VAL(Plane, Tone, Tone, "tone")
|
||||||
|
|
||||||
DEF_PROP_I(Plane, OX)
|
DEF_PROP_I(Plane, OX)
|
||||||
DEF_PROP_I(Plane, OY)
|
DEF_PROP_I(Plane, OY)
|
||||||
|
@ -57,29 +56,26 @@ DEF_PROP_I(Plane, BlendType)
|
||||||
DEF_PROP_F(Plane, ZoomX)
|
DEF_PROP_F(Plane, ZoomX)
|
||||||
DEF_PROP_F(Plane, ZoomY)
|
DEF_PROP_F(Plane, ZoomY)
|
||||||
|
|
||||||
|
void planeBindingInit() {
|
||||||
void
|
VALUE klass = rb_define_class("Plane", rb_cObject);
|
||||||
planeBindingInit()
|
#if RAPI_FULL > 187
|
||||||
{
|
rb_define_alloc_func(klass, classAllocate<&PlaneType>);
|
||||||
VALUE klass = rb_define_class("Plane", rb_cObject);
|
|
||||||
#ifndef OLD_RUBY
|
|
||||||
rb_define_alloc_func(klass, classAllocate<&PlaneType>);
|
|
||||||
#else
|
#else
|
||||||
rb_define_alloc_func(klass, PlaneAllocate);
|
rb_define_alloc_func(klass, PlaneAllocate);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
disposableBindingInit<Plane> (klass);
|
disposableBindingInit<Plane>(klass);
|
||||||
viewportElementBindingInit<Plane>(klass);
|
viewportElementBindingInit<Plane>(klass);
|
||||||
|
|
||||||
_rb_define_method(klass, "initialize", planeInitialize);
|
_rb_define_method(klass, "initialize", planeInitialize);
|
||||||
|
|
||||||
INIT_PROP_BIND( Plane, Bitmap, "bitmap" );
|
INIT_PROP_BIND(Plane, Bitmap, "bitmap");
|
||||||
INIT_PROP_BIND( Plane, OX, "ox" );
|
INIT_PROP_BIND(Plane, OX, "ox");
|
||||||
INIT_PROP_BIND( Plane, OY, "oy" );
|
INIT_PROP_BIND(Plane, OY, "oy");
|
||||||
INIT_PROP_BIND( Plane, ZoomX, "zoom_x" );
|
INIT_PROP_BIND(Plane, ZoomX, "zoom_x");
|
||||||
INIT_PROP_BIND( Plane, ZoomY, "zoom_y" );
|
INIT_PROP_BIND(Plane, ZoomY, "zoom_y");
|
||||||
INIT_PROP_BIND( Plane, Opacity, "opacity" );
|
INIT_PROP_BIND(Plane, Opacity, "opacity");
|
||||||
INIT_PROP_BIND( Plane, BlendType, "blend_type" );
|
INIT_PROP_BIND(Plane, BlendType, "blend_type");
|
||||||
INIT_PROP_BIND( Plane, Color, "color" );
|
INIT_PROP_BIND(Plane, Color, "color");
|
||||||
INIT_PROP_BIND( Plane, Tone, "tone" );
|
INIT_PROP_BIND(Plane, Tone, "tone");
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,41 +19,40 @@
|
||||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "sprite.h"
|
#include "binding-types.h"
|
||||||
#include "sharedstate.h"
|
#include "binding-util.h"
|
||||||
#include "disposable-binding.h"
|
#include "disposable-binding.h"
|
||||||
#include "flashable-binding.h"
|
#include "flashable-binding.h"
|
||||||
#include "sceneelement-binding.h"
|
#include "sceneelement-binding.h"
|
||||||
|
#include "sharedstate.h"
|
||||||
|
#include "sprite.h"
|
||||||
#include "viewportelement-binding.h"
|
#include "viewportelement-binding.h"
|
||||||
#include "binding-util.h"
|
|
||||||
#include "binding-types.h"
|
|
||||||
|
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_FULL > 187
|
||||||
DEF_TYPE(Sprite);
|
DEF_TYPE(Sprite);
|
||||||
#else
|
#else
|
||||||
DEF_ALLOCFUNC(Sprite);
|
DEF_ALLOCFUNC(Sprite);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
RB_METHOD(spriteInitialize)
|
RB_METHOD(spriteInitialize) {
|
||||||
{
|
Sprite *s = viewportElementInitialize<Sprite>(argc, argv, self);
|
||||||
Sprite *s = viewportElementInitialize<Sprite>(argc, argv, self);
|
|
||||||
|
|
||||||
setPrivateData(self, s);
|
setPrivateData(self, s);
|
||||||
|
|
||||||
/* Wrap property objects */
|
/* Wrap property objects */
|
||||||
s->initDynAttribs();
|
s->initDynAttribs();
|
||||||
|
|
||||||
wrapProperty(self, &s->getSrcRect(), "src_rect", RectType);
|
wrapProperty(self, &s->getSrcRect(), "src_rect", RectType);
|
||||||
wrapProperty(self, &s->getColor(), "color", ColorType);
|
wrapProperty(self, &s->getColor(), "color", ColorType);
|
||||||
wrapProperty(self, &s->getTone(), "tone", ToneType);
|
wrapProperty(self, &s->getTone(), "tone", ToneType);
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
DEF_PROP_OBJ_REF(Sprite, Bitmap, Bitmap, "bitmap")
|
DEF_PROP_OBJ_REF(Sprite, Bitmap, Bitmap, "bitmap")
|
||||||
DEF_PROP_OBJ_VAL(Sprite, Rect, SrcRect, "src_rect")
|
DEF_PROP_OBJ_VAL(Sprite, Rect, SrcRect, "src_rect")
|
||||||
DEF_PROP_OBJ_VAL(Sprite, Color, Color, "color")
|
DEF_PROP_OBJ_VAL(Sprite, Color, Color, "color")
|
||||||
DEF_PROP_OBJ_VAL(Sprite, Tone, Tone, "tone")
|
DEF_PROP_OBJ_VAL(Sprite, Tone, Tone, "tone")
|
||||||
|
|
||||||
DEF_PROP_I(Sprite, X)
|
DEF_PROP_I(Sprite, X)
|
||||||
DEF_PROP_I(Sprite, Y)
|
DEF_PROP_I(Sprite, Y)
|
||||||
|
@ -74,72 +73,67 @@ DEF_PROP_F(Sprite, WavePhase)
|
||||||
|
|
||||||
DEF_PROP_B(Sprite, Mirror)
|
DEF_PROP_B(Sprite, Mirror)
|
||||||
|
|
||||||
RB_METHOD(spriteWidth)
|
RB_METHOD(spriteWidth) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
|
||||||
Sprite *s = getPrivateData<Sprite>(self);
|
Sprite *s = getPrivateData<Sprite>(self);
|
||||||
|
|
||||||
int value = 0;
|
int value = 0;
|
||||||
GUARD_EXC( value = s->getWidth(); )
|
GUARD_EXC(value = s->getWidth();)
|
||||||
|
|
||||||
return rb_fix_new(value);
|
return rb_fix_new(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(spriteHeight)
|
RB_METHOD(spriteHeight) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
|
||||||
Sprite *s = getPrivateData<Sprite>(self);
|
Sprite *s = getPrivateData<Sprite>(self);
|
||||||
|
|
||||||
int value = 0;
|
int value = 0;
|
||||||
GUARD_EXC( value = s->getHeight(); )
|
GUARD_EXC(value = s->getHeight();)
|
||||||
|
|
||||||
return rb_fix_new(value);
|
return rb_fix_new(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void spriteBindingInit() {
|
||||||
spriteBindingInit()
|
VALUE klass = rb_define_class("Sprite", rb_cObject);
|
||||||
{
|
#if RAPI_FULL > 187
|
||||||
VALUE klass = rb_define_class("Sprite", rb_cObject);
|
rb_define_alloc_func(klass, classAllocate<&SpriteType>);
|
||||||
#ifndef OLD_RUBY
|
|
||||||
rb_define_alloc_func(klass, classAllocate<&SpriteType>);
|
|
||||||
#else
|
#else
|
||||||
rb_define_alloc_func(klass, SpriteAllocate);
|
rb_define_alloc_func(klass, SpriteAllocate);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
disposableBindingInit <Sprite>(klass);
|
disposableBindingInit<Sprite>(klass);
|
||||||
flashableBindingInit <Sprite>(klass);
|
flashableBindingInit<Sprite>(klass);
|
||||||
viewportElementBindingInit<Sprite>(klass);
|
viewportElementBindingInit<Sprite>(klass);
|
||||||
|
|
||||||
_rb_define_method(klass, "initialize", spriteInitialize);
|
_rb_define_method(klass, "initialize", spriteInitialize);
|
||||||
|
|
||||||
INIT_PROP_BIND( Sprite, Bitmap, "bitmap" );
|
INIT_PROP_BIND(Sprite, Bitmap, "bitmap");
|
||||||
INIT_PROP_BIND( Sprite, SrcRect, "src_rect" );
|
INIT_PROP_BIND(Sprite, SrcRect, "src_rect");
|
||||||
INIT_PROP_BIND( Sprite, X, "x" );
|
INIT_PROP_BIND(Sprite, X, "x");
|
||||||
INIT_PROP_BIND( Sprite, Y, "y" );
|
INIT_PROP_BIND(Sprite, Y, "y");
|
||||||
INIT_PROP_BIND( Sprite, OX, "ox" );
|
INIT_PROP_BIND(Sprite, OX, "ox");
|
||||||
INIT_PROP_BIND( Sprite, OY, "oy" );
|
INIT_PROP_BIND(Sprite, OY, "oy");
|
||||||
INIT_PROP_BIND( Sprite, ZoomX, "zoom_x" );
|
INIT_PROP_BIND(Sprite, ZoomX, "zoom_x");
|
||||||
INIT_PROP_BIND( Sprite, ZoomY, "zoom_y" );
|
INIT_PROP_BIND(Sprite, ZoomY, "zoom_y");
|
||||||
INIT_PROP_BIND( Sprite, Angle, "angle" );
|
INIT_PROP_BIND(Sprite, Angle, "angle");
|
||||||
INIT_PROP_BIND( Sprite, Mirror, "mirror" );
|
INIT_PROP_BIND(Sprite, Mirror, "mirror");
|
||||||
INIT_PROP_BIND( Sprite, BushDepth, "bush_depth" );
|
INIT_PROP_BIND(Sprite, BushDepth, "bush_depth");
|
||||||
INIT_PROP_BIND( Sprite, Opacity, "opacity" );
|
INIT_PROP_BIND(Sprite, Opacity, "opacity");
|
||||||
INIT_PROP_BIND( Sprite, BlendType, "blend_type" );
|
INIT_PROP_BIND(Sprite, BlendType, "blend_type");
|
||||||
INIT_PROP_BIND( Sprite, Color, "color" );
|
INIT_PROP_BIND(Sprite, Color, "color");
|
||||||
INIT_PROP_BIND( Sprite, Tone, "tone" );
|
INIT_PROP_BIND(Sprite, Tone, "tone");
|
||||||
|
|
||||||
if (rgssVer >= 2)
|
if (rgssVer >= 2) {
|
||||||
{
|
_rb_define_method(klass, "width", spriteWidth);
|
||||||
_rb_define_method(klass, "width", spriteWidth);
|
_rb_define_method(klass, "height", spriteHeight);
|
||||||
_rb_define_method(klass, "height", spriteHeight);
|
|
||||||
|
|
||||||
INIT_PROP_BIND( Sprite, BushOpacity, "bush_opacity" );
|
INIT_PROP_BIND(Sprite, BushOpacity, "bush_opacity");
|
||||||
|
|
||||||
INIT_PROP_BIND( Sprite, WaveAmp, "wave_amp" );
|
INIT_PROP_BIND(Sprite, WaveAmp, "wave_amp");
|
||||||
INIT_PROP_BIND( Sprite, WaveLength, "wave_length" );
|
INIT_PROP_BIND(Sprite, WaveLength, "wave_length");
|
||||||
INIT_PROP_BIND( Sprite, WaveSpeed, "wave_speed" );
|
INIT_PROP_BIND(Sprite, WaveSpeed, "wave_speed");
|
||||||
INIT_PROP_BIND( Sprite, WavePhase, "wave_phase" );
|
INIT_PROP_BIND(Sprite, WavePhase, "wave_phase");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,169 +19,155 @@
|
||||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include "table.h"
|
|
||||||
#include "binding-util.h"
|
#include "binding-util.h"
|
||||||
#include "serializable-binding.h"
|
#include "serializable-binding.h"
|
||||||
|
#include "table.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
static int num2TableSize(VALUE v)
|
static int num2TableSize(VALUE v) {
|
||||||
{
|
int i = NUM2INT(v);
|
||||||
int i = NUM2INT(v);
|
return std::max(0, i);
|
||||||
return std::max(0, i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parseArgsTableSizes(int argc, VALUE *argv, int *x, int *y, int *z)
|
static void parseArgsTableSizes(int argc, VALUE *argv, int *x, int *y, int *z) {
|
||||||
{
|
*y = *z = 1;
|
||||||
*y = *z = 1;
|
|
||||||
|
|
||||||
switch (argc)
|
switch (argc) {
|
||||||
{
|
case 3:
|
||||||
case 3:
|
*z = num2TableSize(argv[2]);
|
||||||
*z = num2TableSize(argv[2]);
|
/* fall through */
|
||||||
/* fall through */
|
case 2:
|
||||||
case 2:
|
*y = num2TableSize(argv[1]);
|
||||||
*y = num2TableSize(argv[1]);
|
/* fall through */
|
||||||
/* fall through */
|
case 1:
|
||||||
case 1:
|
*x = num2TableSize(argv[0]);
|
||||||
*x = num2TableSize(argv[0]);
|
break;
|
||||||
break;
|
default:
|
||||||
default:
|
rb_error_arity(argc, 1, 3);
|
||||||
rb_error_arity(argc, 1, 3);
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_FULL > 187
|
||||||
DEF_TYPE(Table);
|
DEF_TYPE(Table);
|
||||||
#else
|
#else
|
||||||
DEF_ALLOCFUNC(Table);
|
DEF_ALLOCFUNC(Table);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
RB_METHOD(tableInitialize)
|
RB_METHOD(tableInitialize) {
|
||||||
{
|
int x, y, z;
|
||||||
int x, y, z;
|
|
||||||
|
|
||||||
parseArgsTableSizes(argc, argv, &x, &y, &z);
|
parseArgsTableSizes(argc, argv, &x, &y, &z);
|
||||||
|
|
||||||
Table *t = new Table(x, y, z);
|
Table *t = new Table(x, y, z);
|
||||||
|
|
||||||
setPrivateData(self, t);
|
setPrivateData(self, t);
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(tableResize)
|
RB_METHOD(tableResize) {
|
||||||
{
|
Table *t = getPrivateData<Table>(self);
|
||||||
Table *t = getPrivateData<Table>(self);
|
|
||||||
|
|
||||||
int x, y, z;
|
int x, y, z;
|
||||||
parseArgsTableSizes(argc, argv, &x, &y, &z);
|
parseArgsTableSizes(argc, argv, &x, &y, &z);
|
||||||
|
|
||||||
t->resize(x, y, z);
|
t->resize(x, y, z);
|
||||||
|
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define TABLE_SIZE(d, D) \
|
#define TABLE_SIZE(d, D) \
|
||||||
RB_METHOD(table##D##Size) \
|
RB_METHOD(table##D##Size) { \
|
||||||
{ \
|
RB_UNUSED_PARAM \
|
||||||
RB_UNUSED_PARAM \
|
Table *t = getPrivateData<Table>(self); \
|
||||||
Table *t = getPrivateData<Table>(self); \
|
return INT2NUM(t->d##Size()); \
|
||||||
return INT2NUM(t->d##Size()); \
|
}
|
||||||
}
|
|
||||||
|
|
||||||
TABLE_SIZE(x, X)
|
TABLE_SIZE(x, X)
|
||||||
TABLE_SIZE(y, Y)
|
TABLE_SIZE(y, Y)
|
||||||
TABLE_SIZE(z, Z)
|
TABLE_SIZE(z, Z)
|
||||||
|
|
||||||
RB_METHOD(tableGetAt)
|
RB_METHOD(tableGetAt) {
|
||||||
{
|
Table *t = getPrivateData<Table>(self);
|
||||||
Table *t = getPrivateData<Table>(self);
|
|
||||||
|
|
||||||
int x, y, z;
|
int x, y, z;
|
||||||
x = y = z = 0;
|
x = y = z = 0;
|
||||||
|
|
||||||
x = NUM2INT(argv[0]);
|
x = NUM2INT(argv[0]);
|
||||||
if (argc > 1)
|
if (argc > 1)
|
||||||
y = NUM2INT(argv[1]);
|
y = NUM2INT(argv[1]);
|
||||||
if (argc > 2)
|
if (argc > 2)
|
||||||
z = NUM2INT(argv[2]);
|
z = NUM2INT(argv[2]);
|
||||||
|
|
||||||
if (argc > 3)
|
if (argc > 3)
|
||||||
rb_raise(rb_eArgError, "wrong number of arguments");
|
rb_raise(rb_eArgError, "wrong number of arguments");
|
||||||
|
|
||||||
if (x < 0 || x >= t->xSize()
|
if (x < 0 || x >= t->xSize() || y < 0 || y >= t->ySize() || z < 0 ||
|
||||||
|| y < 0 || y >= t->ySize()
|
z >= t->zSize()) {
|
||||||
|| z < 0 || z >= t->zSize())
|
return Qnil;
|
||||||
{
|
}
|
||||||
return Qnil;
|
|
||||||
}
|
|
||||||
|
|
||||||
short result = t->get(x, y, z);
|
short result = t->get(x, y, z);
|
||||||
|
|
||||||
return INT2FIX(result); /* short always fits in a Fixnum */
|
return INT2FIX(result); /* short always fits in a Fixnum */
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(tableSetAt)
|
RB_METHOD(tableSetAt) {
|
||||||
{
|
Table *t = getPrivateData<Table>(self);
|
||||||
Table *t = getPrivateData<Table>(self);
|
|
||||||
|
|
||||||
int x, y, z, value;
|
int x, y, z, value;
|
||||||
x = y = z = 0;
|
x = y = z = 0;
|
||||||
|
|
||||||
if (argc < 2)
|
if (argc < 2)
|
||||||
rb_raise(rb_eArgError, "wrong number of arguments");
|
rb_raise(rb_eArgError, "wrong number of arguments");
|
||||||
|
|
||||||
switch (argc)
|
switch (argc) {
|
||||||
{
|
default:
|
||||||
default:
|
case 2:
|
||||||
case 2 :
|
x = NUM2INT(argv[0]);
|
||||||
x = NUM2INT(argv[0]);
|
value = NUM2INT(argv[1]);
|
||||||
value = NUM2INT(argv[1]);
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 3 :
|
case 3:
|
||||||
x = NUM2INT(argv[0]);
|
x = NUM2INT(argv[0]);
|
||||||
y = NUM2INT(argv[1]);
|
y = NUM2INT(argv[1]);
|
||||||
value = NUM2INT(argv[2]);
|
value = NUM2INT(argv[2]);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 4 :
|
case 4:
|
||||||
x = NUM2INT(argv[0]);
|
x = NUM2INT(argv[0]);
|
||||||
y = NUM2INT(argv[1]);
|
y = NUM2INT(argv[1]);
|
||||||
z = NUM2INT(argv[2]);
|
z = NUM2INT(argv[2]);
|
||||||
value = NUM2INT(argv[3]);
|
value = NUM2INT(argv[3]);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
t->set(value, x, y, z);
|
t->set(value, x, y, z);
|
||||||
|
|
||||||
return argv[argc - 1];
|
return argv[argc - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
MARSH_LOAD_FUN(Table)
|
MARSH_LOAD_FUN(Table)
|
||||||
INITCOPY_FUN(Table)
|
INITCOPY_FUN(Table)
|
||||||
|
|
||||||
void
|
void tableBindingInit() {
|
||||||
tableBindingInit()
|
VALUE klass = rb_define_class("Table", rb_cObject);
|
||||||
{
|
#if RAPI_FULL > 187
|
||||||
VALUE klass = rb_define_class("Table", rb_cObject);
|
rb_define_alloc_func(klass, classAllocate<&TableType>);
|
||||||
#ifndef OLD_RUBY
|
|
||||||
rb_define_alloc_func(klass, classAllocate<&TableType>);
|
|
||||||
#else
|
#else
|
||||||
rb_define_alloc_func(klass, TableAllocate);
|
rb_define_alloc_func(klass, TableAllocate);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
serializableBindingInit<Table>(klass);
|
serializableBindingInit<Table>(klass);
|
||||||
|
|
||||||
rb_define_class_method(klass, "_load", TableLoad);
|
rb_define_class_method(klass, "_load", TableLoad);
|
||||||
|
|
||||||
_rb_define_method(klass, "initialize", tableInitialize);
|
|
||||||
_rb_define_method(klass, "initialize_copy", TableInitializeCopy);
|
|
||||||
_rb_define_method(klass, "resize", tableResize);
|
|
||||||
_rb_define_method(klass, "xsize", tableXSize);
|
|
||||||
_rb_define_method(klass, "ysize", tableYSize);
|
|
||||||
_rb_define_method(klass, "zsize", tableZSize);
|
|
||||||
_rb_define_method(klass, "[]", tableGetAt);
|
|
||||||
_rb_define_method(klass, "[]=", tableSetAt);
|
|
||||||
|
|
||||||
|
_rb_define_method(klass, "initialize", tableInitialize);
|
||||||
|
_rb_define_method(klass, "initialize_copy", TableInitializeCopy);
|
||||||
|
_rb_define_method(klass, "resize", tableResize);
|
||||||
|
_rb_define_method(klass, "xsize", tableXSize);
|
||||||
|
_rb_define_method(klass, "ysize", tableYSize);
|
||||||
|
_rb_define_method(klass, "zsize", tableZSize);
|
||||||
|
_rb_define_method(klass, "[]", tableGetAt);
|
||||||
|
_rb_define_method(klass, "[]=", tableSetAt);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,166 +19,158 @@
|
||||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "tilemap.h"
|
|
||||||
#include "viewport.h"
|
|
||||||
#include "bitmap.h"
|
#include "bitmap.h"
|
||||||
#include "table.h"
|
#include "table.h"
|
||||||
|
#include "tilemap.h"
|
||||||
|
#include "viewport.h"
|
||||||
|
|
||||||
#include "disposable-binding.h"
|
|
||||||
#include "binding-util.h"
|
|
||||||
#include "binding-types.h"
|
#include "binding-types.h"
|
||||||
|
#include "binding-util.h"
|
||||||
|
#include "disposable-binding.h"
|
||||||
|
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_FULL > 187
|
||||||
DEF_TYPE_CUSTOMFREE(TilemapAutotiles, RUBY_TYPED_NEVER_FREE);
|
DEF_TYPE_CUSTOMFREE(TilemapAutotiles, RUBY_TYPED_NEVER_FREE);
|
||||||
#else
|
#else
|
||||||
#define TilemapAutotilesType "TilemapAutotiles"
|
#define TilemapAutotilesType "TilemapAutotiles"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
RB_METHOD(tilemapAutotilesSet)
|
RB_METHOD(tilemapAutotilesSet) {
|
||||||
{
|
Tilemap::Autotiles *a = getPrivateData<Tilemap::Autotiles>(self);
|
||||||
Tilemap::Autotiles *a = getPrivateData<Tilemap::Autotiles>(self);
|
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
VALUE bitmapObj;
|
VALUE bitmapObj;
|
||||||
|
|
||||||
rb_get_args(argc, argv, "io", &i, &bitmapObj RB_ARG_END);
|
rb_get_args(argc, argv, "io", &i, &bitmapObj RB_ARG_END);
|
||||||
|
|
||||||
Bitmap *bitmap = getPrivateDataCheck<Bitmap>(bitmapObj, BitmapType);
|
Bitmap *bitmap = getPrivateDataCheck<Bitmap>(bitmapObj, BitmapType);
|
||||||
|
|
||||||
a->set(i, bitmap);
|
a->set(i, bitmap);
|
||||||
|
|
||||||
VALUE ary = rb_iv_get(self, "array");
|
VALUE ary = rb_iv_get(self, "array");
|
||||||
rb_ary_store(ary, i, bitmapObj);
|
rb_ary_store(ary, i, bitmapObj);
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(tilemapAutotilesGet)
|
RB_METHOD(tilemapAutotilesGet) {
|
||||||
{
|
int i;
|
||||||
int i;
|
rb_get_args(argc, argv, "i", &i RB_ARG_END);
|
||||||
rb_get_args (argc, argv, "i", &i RB_ARG_END);
|
|
||||||
|
|
||||||
if (i < 0 || i > 6)
|
if (i < 0 || i > 6)
|
||||||
return Qnil;
|
return Qnil;
|
||||||
|
|
||||||
VALUE ary = rb_iv_get(self, "array");
|
VALUE ary = rb_iv_get(self, "array");
|
||||||
|
|
||||||
return rb_ary_entry(ary, i);
|
return rb_ary_entry(ary, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_FULL > 187
|
||||||
DEF_TYPE(Tilemap);
|
DEF_TYPE(Tilemap);
|
||||||
#else
|
#else
|
||||||
DEF_ALLOCFUNC(Tilemap);
|
DEF_ALLOCFUNC(Tilemap);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
RB_METHOD(tilemapInitialize)
|
RB_METHOD(tilemapInitialize) {
|
||||||
{
|
Tilemap *t;
|
||||||
Tilemap *t;
|
|
||||||
|
|
||||||
/* Get parameters */
|
/* Get parameters */
|
||||||
VALUE viewportObj = Qnil;
|
VALUE viewportObj = Qnil;
|
||||||
Viewport *viewport = 0;
|
Viewport *viewport = 0;
|
||||||
|
|
||||||
rb_get_args(argc, argv, "|o", &viewportObj RB_ARG_END);
|
rb_get_args(argc, argv, "|o", &viewportObj RB_ARG_END);
|
||||||
|
|
||||||
if (!NIL_P(viewportObj))
|
if (!NIL_P(viewportObj))
|
||||||
viewport = getPrivateDataCheck<Viewport>(viewportObj, ViewportType);
|
viewport = getPrivateDataCheck<Viewport>(viewportObj, ViewportType);
|
||||||
|
|
||||||
/* Construct object */
|
/* Construct object */
|
||||||
t = new Tilemap(viewport);
|
t = new Tilemap(viewport);
|
||||||
|
|
||||||
setPrivateData(self, t);
|
setPrivateData(self, t);
|
||||||
|
|
||||||
rb_iv_set(self, "viewport", viewportObj);
|
rb_iv_set(self, "viewport", viewportObj);
|
||||||
|
|
||||||
wrapProperty(self, &t->getAutotiles(), "autotiles", TilemapAutotilesType);
|
wrapProperty(self, &t->getAutotiles(), "autotiles", TilemapAutotilesType);
|
||||||
|
|
||||||
VALUE autotilesObj = rb_iv_get(self, "autotiles");
|
VALUE autotilesObj = rb_iv_get(self, "autotiles");
|
||||||
|
|
||||||
VALUE ary = rb_ary_new2(7);
|
VALUE ary = rb_ary_new2(7);
|
||||||
for (int i = 0; i < 7; ++i)
|
for (int i = 0; i < 7; ++i)
|
||||||
rb_ary_push(ary, Qnil);
|
rb_ary_push(ary, Qnil);
|
||||||
|
|
||||||
rb_iv_set(autotilesObj, "array", ary);
|
rb_iv_set(autotilesObj, "array", ary);
|
||||||
|
|
||||||
/* Circular reference so both objects are always
|
/* Circular reference so both objects are always
|
||||||
* alive at the same time */
|
* alive at the same time */
|
||||||
rb_iv_set(autotilesObj, "tilemap", self);
|
rb_iv_set(autotilesObj, "tilemap", self);
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(tilemapGetAutotiles)
|
RB_METHOD(tilemapGetAutotiles) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
|
||||||
checkDisposed<Tilemap>(self);
|
checkDisposed<Tilemap>(self);
|
||||||
|
|
||||||
return rb_iv_get(self, "autotiles");
|
return rb_iv_get(self, "autotiles");
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(tilemapUpdate)
|
RB_METHOD(tilemapUpdate) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
|
||||||
Tilemap *t = getPrivateData<Tilemap>(self);
|
Tilemap *t = getPrivateData<Tilemap>(self);
|
||||||
|
|
||||||
t->update();
|
t->update();
|
||||||
|
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(tilemapGetViewport)
|
RB_METHOD(tilemapGetViewport) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
|
||||||
checkDisposed<Tilemap>(self);
|
checkDisposed<Tilemap>(self);
|
||||||
|
|
||||||
return rb_iv_get(self, "viewport");
|
return rb_iv_get(self, "viewport");
|
||||||
}
|
}
|
||||||
|
|
||||||
DEF_PROP_OBJ_REF(Tilemap, Bitmap, Tileset, "tileset")
|
DEF_PROP_OBJ_REF(Tilemap, Bitmap, Tileset, "tileset")
|
||||||
DEF_PROP_OBJ_REF(Tilemap, Table, MapData, "map_data")
|
DEF_PROP_OBJ_REF(Tilemap, Table, MapData, "map_data")
|
||||||
DEF_PROP_OBJ_REF(Tilemap, Table, FlashData, "flash_data")
|
DEF_PROP_OBJ_REF(Tilemap, Table, FlashData, "flash_data")
|
||||||
DEF_PROP_OBJ_REF(Tilemap, Table, Priorities, "priorities")
|
DEF_PROP_OBJ_REF(Tilemap, Table, Priorities, "priorities")
|
||||||
|
|
||||||
DEF_PROP_B(Tilemap, Visible)
|
DEF_PROP_B(Tilemap, Visible)
|
||||||
|
|
||||||
DEF_PROP_I(Tilemap, OX)
|
DEF_PROP_I(Tilemap, OX)
|
||||||
DEF_PROP_I(Tilemap, OY)
|
DEF_PROP_I(Tilemap, OY)
|
||||||
|
|
||||||
void
|
void tilemapBindingInit() {
|
||||||
tilemapBindingInit()
|
VALUE klass = rb_define_class("TilemapAutotiles", rb_cObject);
|
||||||
{
|
#if RAPI_FULL > 187
|
||||||
VALUE klass = rb_define_class("TilemapAutotiles", rb_cObject);
|
rb_define_alloc_func(klass, classAllocate<&TilemapAutotilesType>);
|
||||||
#ifndef OLD_RUBY
|
|
||||||
rb_define_alloc_func(klass, classAllocate<&TilemapAutotilesType>);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
_rb_define_method(klass, "[]=", tilemapAutotilesSet);
|
_rb_define_method(klass, "[]=", tilemapAutotilesSet);
|
||||||
_rb_define_method(klass, "[]", tilemapAutotilesGet);
|
_rb_define_method(klass, "[]", tilemapAutotilesGet);
|
||||||
|
|
||||||
klass = rb_define_class("Tilemap", rb_cObject);
|
klass = rb_define_class("Tilemap", rb_cObject);
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_FULL > 187
|
||||||
rb_define_alloc_func(klass, classAllocate<&TilemapType>);
|
rb_define_alloc_func(klass, classAllocate<&TilemapType>);
|
||||||
#else
|
#else
|
||||||
rb_define_alloc_func(klass, TilemapAllocate);
|
rb_define_alloc_func(klass, TilemapAllocate);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
disposableBindingInit<Tilemap>(klass);
|
disposableBindingInit<Tilemap>(klass);
|
||||||
|
|
||||||
_rb_define_method(klass, "initialize", tilemapInitialize);
|
_rb_define_method(klass, "initialize", tilemapInitialize);
|
||||||
_rb_define_method(klass, "autotiles", tilemapGetAutotiles);
|
_rb_define_method(klass, "autotiles", tilemapGetAutotiles);
|
||||||
_rb_define_method(klass, "update", tilemapUpdate);
|
_rb_define_method(klass, "update", tilemapUpdate);
|
||||||
|
|
||||||
_rb_define_method(klass, "viewport", tilemapGetViewport);
|
_rb_define_method(klass, "viewport", tilemapGetViewport);
|
||||||
|
|
||||||
INIT_PROP_BIND( Tilemap, Tileset, "tileset" );
|
INIT_PROP_BIND(Tilemap, Tileset, "tileset");
|
||||||
INIT_PROP_BIND( Tilemap, MapData, "map_data" );
|
INIT_PROP_BIND(Tilemap, MapData, "map_data");
|
||||||
INIT_PROP_BIND( Tilemap, FlashData, "flash_data" );
|
INIT_PROP_BIND(Tilemap, FlashData, "flash_data");
|
||||||
INIT_PROP_BIND( Tilemap, Priorities, "priorities" );
|
INIT_PROP_BIND(Tilemap, Priorities, "priorities");
|
||||||
INIT_PROP_BIND( Tilemap, Visible, "visible" );
|
INIT_PROP_BIND(Tilemap, Visible, "visible");
|
||||||
INIT_PROP_BIND( Tilemap, OX, "ox" );
|
INIT_PROP_BIND(Tilemap, OX, "ox");
|
||||||
INIT_PROP_BIND( Tilemap, OY, "oy" );
|
INIT_PROP_BIND(Tilemap, OY, "oy");
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,17 +19,17 @@
|
||||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "bitmap.h"
|
||||||
|
#include "sharedstate.h"
|
||||||
|
#include "table.h"
|
||||||
#include "tilemapvx.h"
|
#include "tilemapvx.h"
|
||||||
#include "viewport.h"
|
#include "viewport.h"
|
||||||
#include "bitmap.h"
|
|
||||||
#include "table.h"
|
|
||||||
#include "sharedstate.h"
|
|
||||||
|
|
||||||
#include "disposable-binding.h"
|
|
||||||
#include "binding-util.h"
|
|
||||||
#include "binding-types.h"
|
#include "binding-types.h"
|
||||||
|
#include "binding-util.h"
|
||||||
|
#include "disposable-binding.h"
|
||||||
|
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_FULL > 187
|
||||||
DEF_TYPE_CUSTOMNAME(TilemapVX, "Tilemap");
|
DEF_TYPE_CUSTOMNAME(TilemapVX, "Tilemap");
|
||||||
|
|
||||||
DEF_TYPE_CUSTOMFREE(BitmapArray, RUBY_TYPED_NEVER_FREE);
|
DEF_TYPE_CUSTOMFREE(BitmapArray, RUBY_TYPED_NEVER_FREE);
|
||||||
|
@ -38,143 +38,133 @@ DEF_ALLOCFUNC(TilemapVX);
|
||||||
#define BitmapArrayType "BitmapArray"
|
#define BitmapArrayType "BitmapArray"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
RB_METHOD(tilemapVXInitialize)
|
RB_METHOD(tilemapVXInitialize) {
|
||||||
{
|
TilemapVX *t;
|
||||||
TilemapVX *t;
|
|
||||||
|
|
||||||
/* Get parameters */
|
/* Get parameters */
|
||||||
VALUE viewportObj = Qnil;
|
VALUE viewportObj = Qnil;
|
||||||
Viewport *viewport = 0;
|
Viewport *viewport = 0;
|
||||||
|
|
||||||
rb_get_args(argc, argv, "|o", &viewportObj RB_ARG_END);
|
rb_get_args(argc, argv, "|o", &viewportObj RB_ARG_END);
|
||||||
|
|
||||||
if (!NIL_P(viewportObj))
|
if (!NIL_P(viewportObj))
|
||||||
viewport = getPrivateDataCheck<Viewport>(viewportObj, ViewportType);
|
viewport = getPrivateDataCheck<Viewport>(viewportObj, ViewportType);
|
||||||
|
|
||||||
/* Construct object */
|
/* Construct object */
|
||||||
t = new TilemapVX(viewport);
|
t = new TilemapVX(viewport);
|
||||||
|
|
||||||
setPrivateData(self, t);
|
setPrivateData(self, t);
|
||||||
|
|
||||||
rb_iv_set(self, "viewport", viewportObj);
|
rb_iv_set(self, "viewport", viewportObj);
|
||||||
|
|
||||||
wrapProperty(self, &t->getBitmapArray(), "bitmap_array", BitmapArrayType,
|
wrapProperty(self, &t->getBitmapArray(), "bitmap_array", BitmapArrayType,
|
||||||
rb_const_get(rb_cObject, rb_intern("Tilemap")));
|
rb_const_get(rb_cObject, rb_intern("Tilemap")));
|
||||||
|
|
||||||
VALUE autotilesObj = rb_iv_get(self, "bitmap_array");
|
VALUE autotilesObj = rb_iv_get(self, "bitmap_array");
|
||||||
|
|
||||||
VALUE ary = rb_ary_new2(9);
|
VALUE ary = rb_ary_new2(9);
|
||||||
for (int i = 0; i < 9; ++i)
|
for (int i = 0; i < 9; ++i)
|
||||||
rb_ary_push(ary, Qnil);
|
rb_ary_push(ary, Qnil);
|
||||||
|
|
||||||
rb_iv_set(autotilesObj, "array", ary);
|
rb_iv_set(autotilesObj, "array", ary);
|
||||||
|
|
||||||
/* Circular reference so both objects are always
|
/* Circular reference so both objects are always
|
||||||
* alive at the same time */
|
* alive at the same time */
|
||||||
rb_iv_set(autotilesObj, "tilemap", self);
|
rb_iv_set(autotilesObj, "tilemap", self);
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(tilemapVXGetBitmapArray)
|
RB_METHOD(tilemapVXGetBitmapArray) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
|
||||||
checkDisposed<TilemapVX>(self);
|
checkDisposed<TilemapVX>(self);
|
||||||
|
|
||||||
return rb_iv_get(self, "bitmap_array");
|
return rb_iv_get(self, "bitmap_array");
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(tilemapVXUpdate)
|
RB_METHOD(tilemapVXUpdate) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
|
||||||
TilemapVX *t = getPrivateData<TilemapVX>(self);
|
TilemapVX *t = getPrivateData<TilemapVX>(self);
|
||||||
|
|
||||||
t->update();
|
t->update();
|
||||||
|
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
DEF_PROP_OBJ_REF(TilemapVX, Viewport, Viewport, "viewport")
|
DEF_PROP_OBJ_REF(TilemapVX, Viewport, Viewport, "viewport")
|
||||||
DEF_PROP_OBJ_REF(TilemapVX, Table, MapData, "map_data")
|
DEF_PROP_OBJ_REF(TilemapVX, Table, MapData, "map_data")
|
||||||
DEF_PROP_OBJ_REF(TilemapVX, Table, FlashData, "flash_data")
|
DEF_PROP_OBJ_REF(TilemapVX, Table, FlashData, "flash_data")
|
||||||
DEF_PROP_OBJ_REF(TilemapVX, Table, Flags, "flags")
|
DEF_PROP_OBJ_REF(TilemapVX, Table, Flags, "flags")
|
||||||
|
|
||||||
DEF_PROP_B(TilemapVX, Visible)
|
DEF_PROP_B(TilemapVX, Visible)
|
||||||
|
|
||||||
DEF_PROP_I(TilemapVX, OX)
|
DEF_PROP_I(TilemapVX, OX)
|
||||||
DEF_PROP_I(TilemapVX, OY)
|
DEF_PROP_I(TilemapVX, OY)
|
||||||
|
|
||||||
RB_METHOD(tilemapVXBitmapsSet)
|
RB_METHOD(tilemapVXBitmapsSet) {
|
||||||
{
|
TilemapVX::BitmapArray *a = getPrivateData<TilemapVX::BitmapArray>(self);
|
||||||
TilemapVX::BitmapArray *a = getPrivateData<TilemapVX::BitmapArray>(self);
|
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
VALUE bitmapObj;
|
VALUE bitmapObj;
|
||||||
|
|
||||||
rb_get_args(argc, argv, "io", &i, &bitmapObj RB_ARG_END);
|
rb_get_args(argc, argv, "io", &i, &bitmapObj RB_ARG_END);
|
||||||
|
|
||||||
Bitmap *bitmap = getPrivateDataCheck<Bitmap>(bitmapObj, BitmapType);
|
Bitmap *bitmap = getPrivateDataCheck<Bitmap>(bitmapObj, BitmapType);
|
||||||
|
|
||||||
a->set(i, bitmap);
|
a->set(i, bitmap);
|
||||||
|
|
||||||
VALUE ary = rb_iv_get(self, "array");
|
VALUE ary = rb_iv_get(self, "array");
|
||||||
rb_ary_store(ary, i, bitmapObj);
|
rb_ary_store(ary, i, bitmapObj);
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(tilemapVXBitmapsGet)
|
RB_METHOD(tilemapVXBitmapsGet) {
|
||||||
{
|
int i;
|
||||||
int i;
|
rb_get_args(argc, argv, "i", &i RB_ARG_END);
|
||||||
rb_get_args (argc, argv, "i", &i RB_ARG_END);
|
|
||||||
|
|
||||||
if (i < 0 || i > 8)
|
if (i < 0 || i > 8)
|
||||||
return Qnil;
|
return Qnil;
|
||||||
|
|
||||||
VALUE ary = rb_iv_get(self, "array");
|
VALUE ary = rb_iv_get(self, "array");
|
||||||
|
|
||||||
return rb_ary_entry(ary, i);
|
return rb_ary_entry(ary, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void tilemapVXBindingInit() {
|
||||||
tilemapVXBindingInit()
|
VALUE klass = rb_define_class("Tilemap", rb_cObject);
|
||||||
{
|
#if RAPI_FULL > 187
|
||||||
VALUE klass = rb_define_class("Tilemap", rb_cObject);
|
rb_define_alloc_func(klass, classAllocate<&TilemapVXType>);
|
||||||
#ifndef OLD_RUBY
|
|
||||||
rb_define_alloc_func(klass, classAllocate<&TilemapVXType>);
|
|
||||||
#else
|
#else
|
||||||
rb_define_alloc_func(klass, TilemapVXAllocate);
|
rb_define_alloc_func(klass, TilemapVXAllocate);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
disposableBindingInit<TilemapVX>(klass);
|
disposableBindingInit<TilemapVX>(klass);
|
||||||
|
|
||||||
_rb_define_method(klass, "initialize", tilemapVXInitialize);
|
_rb_define_method(klass, "initialize", tilemapVXInitialize);
|
||||||
_rb_define_method(klass, "bitmaps", tilemapVXGetBitmapArray);
|
_rb_define_method(klass, "bitmaps", tilemapVXGetBitmapArray);
|
||||||
_rb_define_method(klass, "update", tilemapVXUpdate);
|
_rb_define_method(klass, "update", tilemapVXUpdate);
|
||||||
|
|
||||||
INIT_PROP_BIND( TilemapVX, Viewport, "viewport" );
|
INIT_PROP_BIND(TilemapVX, Viewport, "viewport");
|
||||||
INIT_PROP_BIND( TilemapVX, MapData, "map_data" );
|
INIT_PROP_BIND(TilemapVX, MapData, "map_data");
|
||||||
INIT_PROP_BIND( TilemapVX, FlashData, "flash_data" );
|
INIT_PROP_BIND(TilemapVX, FlashData, "flash_data");
|
||||||
INIT_PROP_BIND( TilemapVX, Visible, "visible" );
|
INIT_PROP_BIND(TilemapVX, Visible, "visible");
|
||||||
INIT_PROP_BIND( TilemapVX, OX, "ox" );
|
INIT_PROP_BIND(TilemapVX, OX, "ox");
|
||||||
INIT_PROP_BIND( TilemapVX, OY, "oy" );
|
INIT_PROP_BIND(TilemapVX, OY, "oy");
|
||||||
|
|
||||||
if (rgssVer == 3)
|
if (rgssVer == 3) {
|
||||||
{
|
INIT_PROP_BIND(TilemapVX, Flags, "flags");
|
||||||
INIT_PROP_BIND( TilemapVX, Flags, "flags" );
|
} else {
|
||||||
}
|
INIT_PROP_BIND(TilemapVX, Flags, "passages");
|
||||||
else
|
}
|
||||||
{
|
|
||||||
INIT_PROP_BIND( TilemapVX, Flags, "passages" );
|
|
||||||
}
|
|
||||||
|
|
||||||
klass = rb_define_class_under(klass, "BitmapArray", rb_cObject);
|
klass = rb_define_class_under(klass, "BitmapArray", rb_cObject);
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_FULL > 187
|
||||||
rb_define_alloc_func(klass, classAllocate<&BitmapArrayType>);
|
rb_define_alloc_func(klass, classAllocate<&BitmapArrayType>);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
_rb_define_method(klass, "[]=", tilemapVXBitmapsSet);
|
_rb_define_method(klass, "[]=", tilemapVXBitmapsSet);
|
||||||
_rb_define_method(klass, "[]", tilemapVXBitmapsGet);
|
_rb_define_method(klass, "[]", tilemapVXBitmapsGet);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,95 +19,85 @@
|
||||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "viewport.h"
|
#include "binding-types.h"
|
||||||
#include "sharedstate.h"
|
#include "binding-util.h"
|
||||||
#include "disposable-binding.h"
|
#include "disposable-binding.h"
|
||||||
#include "flashable-binding.h"
|
#include "flashable-binding.h"
|
||||||
#include "sceneelement-binding.h"
|
#include "sceneelement-binding.h"
|
||||||
#include "binding-util.h"
|
#include "sharedstate.h"
|
||||||
#include "binding-types.h"
|
#include "viewport.h"
|
||||||
|
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_FULL > 187
|
||||||
DEF_TYPE(Viewport);
|
DEF_TYPE(Viewport);
|
||||||
#else
|
#else
|
||||||
DEF_ALLOCFUNC(Viewport);
|
DEF_ALLOCFUNC(Viewport);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
RB_METHOD(viewportInitialize)
|
RB_METHOD(viewportInitialize) {
|
||||||
{
|
Viewport *v;
|
||||||
Viewport *v;
|
|
||||||
|
|
||||||
if (argc == 0 && rgssVer >= 3)
|
if (argc == 0 && rgssVer >= 3) {
|
||||||
{
|
v = new Viewport();
|
||||||
v = new Viewport();
|
} else if (argc == 1) {
|
||||||
}
|
/* The rect arg is only used to init the viewport,
|
||||||
else if (argc == 1)
|
* and does NOT replace its 'rect' property */
|
||||||
{
|
VALUE rectObj;
|
||||||
/* The rect arg is only used to init the viewport,
|
Rect *rect;
|
||||||
* and does NOT replace its 'rect' property */
|
|
||||||
VALUE rectObj;
|
|
||||||
Rect *rect;
|
|
||||||
|
|
||||||
rb_get_args(argc, argv, "o", &rectObj RB_ARG_END);
|
rb_get_args(argc, argv, "o", &rectObj RB_ARG_END);
|
||||||
|
|
||||||
rect = getPrivateDataCheck<Rect>(rectObj, RectType);
|
rect = getPrivateDataCheck<Rect>(rectObj, RectType);
|
||||||
|
|
||||||
v = new Viewport(rect);
|
v = new Viewport(rect);
|
||||||
}
|
} else {
|
||||||
else
|
int x, y, width, height;
|
||||||
{
|
|
||||||
int x, y, width, height;
|
|
||||||
|
|
||||||
rb_get_args(argc, argv, "iiii", &x, &y, &width, &height RB_ARG_END);
|
rb_get_args(argc, argv, "iiii", &x, &y, &width, &height RB_ARG_END);
|
||||||
|
|
||||||
v = new Viewport(x, y, width, height);
|
v = new Viewport(x, y, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
setPrivateData(self, v);
|
setPrivateData(self, v);
|
||||||
|
|
||||||
/* Wrap property objects */
|
/* Wrap property objects */
|
||||||
v->initDynAttribs();
|
v->initDynAttribs();
|
||||||
|
|
||||||
wrapProperty(self, &v->getRect(), "rect", RectType);
|
wrapProperty(self, &v->getRect(), "rect", RectType);
|
||||||
wrapProperty(self, &v->getColor(), "color", ColorType);
|
wrapProperty(self, &v->getColor(), "color", ColorType);
|
||||||
wrapProperty(self, &v->getTone(), "tone", ToneType);
|
wrapProperty(self, &v->getTone(), "tone", ToneType);
|
||||||
|
|
||||||
/* 'elements' holds all SceneElements that become children
|
/* 'elements' holds all SceneElements that become children
|
||||||
* of this viewport, so we can dispose them when the viewport
|
* of this viewport, so we can dispose them when the viewport
|
||||||
* is disposed */
|
* is disposed */
|
||||||
rb_iv_set(self, "elements", rb_ary_new());
|
rb_iv_set(self, "elements", rb_ary_new());
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
DEF_PROP_OBJ_VAL(Viewport, Rect, Rect, "rect")
|
DEF_PROP_OBJ_VAL(Viewport, Rect, Rect, "rect")
|
||||||
DEF_PROP_OBJ_VAL(Viewport, Color, Color, "color")
|
DEF_PROP_OBJ_VAL(Viewport, Color, Color, "color")
|
||||||
DEF_PROP_OBJ_VAL(Viewport, Tone, Tone, "tone")
|
DEF_PROP_OBJ_VAL(Viewport, Tone, Tone, "tone")
|
||||||
|
|
||||||
DEF_PROP_I(Viewport, OX)
|
DEF_PROP_I(Viewport, OX)
|
||||||
DEF_PROP_I(Viewport, OY)
|
DEF_PROP_I(Viewport, OY)
|
||||||
|
|
||||||
|
void viewportBindingInit() {
|
||||||
void
|
VALUE klass = rb_define_class("Viewport", rb_cObject);
|
||||||
viewportBindingInit()
|
#if RAPI_FULL > 187
|
||||||
{
|
rb_define_alloc_func(klass, classAllocate<&ViewportType>);
|
||||||
VALUE klass = rb_define_class("Viewport", rb_cObject);
|
|
||||||
#ifndef OLD_RUBY
|
|
||||||
rb_define_alloc_func(klass, classAllocate<&ViewportType>);
|
|
||||||
#else
|
#else
|
||||||
rb_define_alloc_func(klass, ViewportAllocate);
|
rb_define_alloc_func(klass, ViewportAllocate);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
disposableBindingInit <Viewport>(klass);
|
disposableBindingInit<Viewport>(klass);
|
||||||
flashableBindingInit <Viewport>(klass);
|
flashableBindingInit<Viewport>(klass);
|
||||||
sceneElementBindingInit<Viewport>(klass);
|
sceneElementBindingInit<Viewport>(klass);
|
||||||
|
|
||||||
_rb_define_method(klass, "initialize", viewportInitialize);
|
_rb_define_method(klass, "initialize", viewportInitialize);
|
||||||
|
|
||||||
INIT_PROP_BIND( Viewport, Rect, "rect" );
|
INIT_PROP_BIND(Viewport, Rect, "rect");
|
||||||
INIT_PROP_BIND( Viewport, OX, "ox" );
|
INIT_PROP_BIND(Viewport, OX, "ox");
|
||||||
INIT_PROP_BIND( Viewport, OY, "oy" );
|
INIT_PROP_BIND(Viewport, OY, "oy");
|
||||||
INIT_PROP_BIND( Viewport, Color, "color" );
|
INIT_PROP_BIND(Viewport, Color, "color");
|
||||||
INIT_PROP_BIND( Viewport, Tone, "tone" );
|
INIT_PROP_BIND(Viewport, Tone, "tone");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,44 +19,42 @@
|
||||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "window.h"
|
#include "binding-util.h"
|
||||||
#include "disposable-binding.h"
|
#include "disposable-binding.h"
|
||||||
#include "viewportelement-binding.h"
|
#include "viewportelement-binding.h"
|
||||||
#include "binding-util.h"
|
#include "window.h"
|
||||||
|
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_FULL > 187
|
||||||
DEF_TYPE(Window);
|
DEF_TYPE(Window);
|
||||||
#else
|
#else
|
||||||
DEF_ALLOCFUNC(Window);
|
DEF_ALLOCFUNC(Window);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
RB_METHOD(windowInitialize)
|
RB_METHOD(windowInitialize) {
|
||||||
{
|
Window *w = viewportElementInitialize<Window>(argc, argv, self);
|
||||||
Window *w = viewportElementInitialize<Window>(argc, argv, self);
|
|
||||||
|
|
||||||
setPrivateData(self, w);
|
setPrivateData(self, w);
|
||||||
|
|
||||||
w->initDynAttribs();
|
w->initDynAttribs();
|
||||||
|
|
||||||
wrapProperty(self, &w->getCursorRect(), "cursor_rect", RectType);
|
wrapProperty(self, &w->getCursorRect(), "cursor_rect", RectType);
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(windowUpdate)
|
RB_METHOD(windowUpdate) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
|
||||||
Window *w = getPrivateData<Window>(self);
|
Window *w = getPrivateData<Window>(self);
|
||||||
|
|
||||||
w->update();
|
w->update();
|
||||||
|
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
DEF_PROP_OBJ_REF(Window, Bitmap, Windowskin, "windowskin")
|
DEF_PROP_OBJ_REF(Window, Bitmap, Windowskin, "windowskin")
|
||||||
DEF_PROP_OBJ_REF(Window, Bitmap, Contents, "contents")
|
DEF_PROP_OBJ_REF(Window, Bitmap, Contents, "contents")
|
||||||
DEF_PROP_OBJ_VAL(Window, Rect, CursorRect, "cursor_rect")
|
DEF_PROP_OBJ_VAL(Window, Rect, CursorRect, "cursor_rect")
|
||||||
|
|
||||||
DEF_PROP_B(Window, Stretch)
|
DEF_PROP_B(Window, Stretch)
|
||||||
DEF_PROP_B(Window, Active)
|
DEF_PROP_B(Window, Active)
|
||||||
|
@ -72,37 +70,33 @@ DEF_PROP_I(Window, Opacity)
|
||||||
DEF_PROP_I(Window, BackOpacity)
|
DEF_PROP_I(Window, BackOpacity)
|
||||||
DEF_PROP_I(Window, ContentsOpacity)
|
DEF_PROP_I(Window, ContentsOpacity)
|
||||||
|
|
||||||
|
void windowBindingInit() {
|
||||||
void
|
VALUE klass = rb_define_class("Window", rb_cObject);
|
||||||
windowBindingInit()
|
#if RAPI_FULL > 187
|
||||||
{
|
rb_define_alloc_func(klass, classAllocate<&WindowType>);
|
||||||
VALUE klass = rb_define_class("Window", rb_cObject);
|
|
||||||
#ifndef OLD_RUBY
|
|
||||||
rb_define_alloc_func(klass, classAllocate<&WindowType>);
|
|
||||||
#else
|
#else
|
||||||
rb_define_alloc_func(klass, WindowAllocate);
|
rb_define_alloc_func(klass, WindowAllocate);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
disposableBindingInit <Window>(klass);
|
disposableBindingInit<Window>(klass);
|
||||||
viewportElementBindingInit<Window>(klass);
|
viewportElementBindingInit<Window>(klass);
|
||||||
|
|
||||||
_rb_define_method(klass, "initialize", windowInitialize);
|
_rb_define_method(klass, "initialize", windowInitialize);
|
||||||
_rb_define_method(klass, "update", windowUpdate);
|
_rb_define_method(klass, "update", windowUpdate);
|
||||||
|
|
||||||
INIT_PROP_BIND( Window, Windowskin, "windowskin" );
|
INIT_PROP_BIND(Window, Windowskin, "windowskin");
|
||||||
INIT_PROP_BIND( Window, Contents, "contents" );
|
INIT_PROP_BIND(Window, Contents, "contents");
|
||||||
INIT_PROP_BIND( Window, Stretch, "stretch" );
|
INIT_PROP_BIND(Window, Stretch, "stretch");
|
||||||
INIT_PROP_BIND( Window, CursorRect, "cursor_rect" );
|
INIT_PROP_BIND(Window, CursorRect, "cursor_rect");
|
||||||
INIT_PROP_BIND( Window, Active, "active" );
|
INIT_PROP_BIND(Window, Active, "active");
|
||||||
INIT_PROP_BIND( Window, Pause, "pause" );
|
INIT_PROP_BIND(Window, Pause, "pause");
|
||||||
INIT_PROP_BIND( Window, X, "x" );
|
INIT_PROP_BIND(Window, X, "x");
|
||||||
INIT_PROP_BIND( Window, Y, "y" );
|
INIT_PROP_BIND(Window, Y, "y");
|
||||||
INIT_PROP_BIND( Window, Width, "width" );
|
INIT_PROP_BIND(Window, Width, "width");
|
||||||
INIT_PROP_BIND( Window, Height, "height" );
|
INIT_PROP_BIND(Window, Height, "height");
|
||||||
INIT_PROP_BIND( Window, OX, "ox" );
|
INIT_PROP_BIND(Window, OX, "ox");
|
||||||
INIT_PROP_BIND( Window, OY, "oy" );
|
INIT_PROP_BIND(Window, OY, "oy");
|
||||||
INIT_PROP_BIND( Window, Opacity, "opacity" );
|
INIT_PROP_BIND(Window, Opacity, "opacity");
|
||||||
INIT_PROP_BIND( Window, BackOpacity, "back_opacity" );
|
INIT_PROP_BIND(Window, BackOpacity, "back_opacity");
|
||||||
INIT_PROP_BIND( Window, ContentsOpacity, "contents_opacity" );
|
INIT_PROP_BIND(Window, ContentsOpacity, "contents_opacity");
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,14 +19,14 @@
|
||||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "windowvx.h"
|
#include "binding-util.h"
|
||||||
#include "disposable-binding.h"
|
#include "disposable-binding.h"
|
||||||
#include "viewportelement-binding.h"
|
#include "viewportelement-binding.h"
|
||||||
#include "binding-util.h"
|
#include "windowvx.h"
|
||||||
|
|
||||||
#include "bitmap.h"
|
#include "bitmap.h"
|
||||||
|
|
||||||
#ifndef OLD_RUBY
|
#if RAPI_FULL > 187
|
||||||
DEF_TYPE_CUSTOMNAME(WindowVX, "Window");
|
DEF_TYPE_CUSTOMNAME(WindowVX, "Window");
|
||||||
#else
|
#else
|
||||||
DEF_ALLOCFUNC(WindowVX);
|
DEF_ALLOCFUNC(WindowVX);
|
||||||
|
@ -34,88 +34,80 @@ DEF_ALLOCFUNC(WindowVX);
|
||||||
|
|
||||||
void bitmapInitProps(Bitmap *b, VALUE self);
|
void bitmapInitProps(Bitmap *b, VALUE self);
|
||||||
|
|
||||||
RB_METHOD(windowVXInitialize)
|
RB_METHOD(windowVXInitialize) {
|
||||||
{
|
WindowVX *w;
|
||||||
WindowVX *w;
|
|
||||||
|
|
||||||
if (rgssVer >= 3)
|
if (rgssVer >= 3) {
|
||||||
{
|
int x, y, width, height;
|
||||||
int x, y, width, height;
|
x = y = width = height = 0;
|
||||||
x = y = width = height = 0;
|
|
||||||
|
|
||||||
if (argc == 4)
|
if (argc == 4)
|
||||||
rb_get_args(argc, argv, "iiii", &x, &y, &width, &height RB_ARG_END);
|
rb_get_args(argc, argv, "iiii", &x, &y, &width, &height RB_ARG_END);
|
||||||
|
|
||||||
w = new WindowVX(x, y, width, height);
|
w = new WindowVX(x, y, width, height);
|
||||||
}
|
} else {
|
||||||
else
|
w = viewportElementInitialize<WindowVX>(argc, argv, self);
|
||||||
{
|
}
|
||||||
w = viewportElementInitialize<WindowVX>(argc, argv, self);
|
|
||||||
}
|
|
||||||
|
|
||||||
setPrivateData(self, w);
|
setPrivateData(self, w);
|
||||||
|
|
||||||
w->initDynAttribs();
|
w->initDynAttribs();
|
||||||
|
|
||||||
wrapProperty(self, &w->getCursorRect(), "cursor_rect", RectType);
|
wrapProperty(self, &w->getCursorRect(), "cursor_rect", RectType);
|
||||||
|
|
||||||
if (rgssVer >= 3)
|
if (rgssVer >= 3)
|
||||||
wrapProperty(self, &w->getTone(), "tone", ToneType);
|
wrapProperty(self, &w->getTone(), "tone", ToneType);
|
||||||
|
|
||||||
Bitmap *contents = new Bitmap(1, 1);
|
Bitmap *contents = new Bitmap(1, 1);
|
||||||
VALUE contentsObj = wrapObject(contents, BitmapType);
|
VALUE contentsObj = wrapObject(contents, BitmapType);
|
||||||
bitmapInitProps(contents, contentsObj);
|
bitmapInitProps(contents, contentsObj);
|
||||||
rb_iv_set(self, "contents", contentsObj);
|
rb_iv_set(self, "contents", contentsObj);
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(windowVXUpdate)
|
RB_METHOD(windowVXUpdate) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
|
||||||
WindowVX *w = getPrivateData<WindowVX>(self);
|
WindowVX *w = getPrivateData<WindowVX>(self);
|
||||||
|
|
||||||
w->update();
|
w->update();
|
||||||
|
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(windowVXMove)
|
RB_METHOD(windowVXMove) {
|
||||||
{
|
WindowVX *w = getPrivateData<WindowVX>(self);
|
||||||
WindowVX *w = getPrivateData<WindowVX>(self);
|
|
||||||
|
|
||||||
int x, y, width, height;
|
int x, y, width, height;
|
||||||
rb_get_args(argc, argv, "iiii", &x, &y, &width, &height RB_ARG_END);
|
rb_get_args(argc, argv, "iiii", &x, &y, &width, &height RB_ARG_END);
|
||||||
|
|
||||||
w->move(x, y, width, height);
|
w->move(x, y, width, height);
|
||||||
|
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(windowVXIsOpen)
|
RB_METHOD(windowVXIsOpen) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
|
||||||
WindowVX *w = getPrivateData<WindowVX>(self);
|
WindowVX *w = getPrivateData<WindowVX>(self);
|
||||||
|
|
||||||
return rb_bool_new(w->isOpen());
|
return rb_bool_new(w->isOpen());
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(windowVXIsClosed)
|
RB_METHOD(windowVXIsClosed) {
|
||||||
{
|
RB_UNUSED_PARAM;
|
||||||
RB_UNUSED_PARAM;
|
|
||||||
|
|
||||||
WindowVX *w = getPrivateData<WindowVX>(self);
|
WindowVX *w = getPrivateData<WindowVX>(self);
|
||||||
|
|
||||||
return rb_bool_new(w->isClosed());
|
return rb_bool_new(w->isClosed());
|
||||||
}
|
}
|
||||||
|
|
||||||
DEF_PROP_OBJ_REF(WindowVX, Bitmap, Windowskin, "windowskin")
|
DEF_PROP_OBJ_REF(WindowVX, Bitmap, Windowskin, "windowskin")
|
||||||
DEF_PROP_OBJ_REF(WindowVX, Bitmap, Contents, "contents")
|
DEF_PROP_OBJ_REF(WindowVX, Bitmap, Contents, "contents")
|
||||||
|
|
||||||
DEF_PROP_OBJ_VAL(WindowVX, Rect, CursorRect, "cursor_rect")
|
DEF_PROP_OBJ_VAL(WindowVX, Rect, CursorRect, "cursor_rect")
|
||||||
DEF_PROP_OBJ_VAL(WindowVX, Tone, Tone, "tone")
|
DEF_PROP_OBJ_VAL(WindowVX, Tone, Tone, "tone")
|
||||||
|
|
||||||
DEF_PROP_I(WindowVX, X)
|
DEF_PROP_I(WindowVX, X)
|
||||||
DEF_PROP_I(WindowVX, Y)
|
DEF_PROP_I(WindowVX, Y)
|
||||||
|
@ -134,47 +126,44 @@ DEF_PROP_B(WindowVX, Active)
|
||||||
DEF_PROP_B(WindowVX, ArrowsVisible)
|
DEF_PROP_B(WindowVX, ArrowsVisible)
|
||||||
DEF_PROP_B(WindowVX, Pause)
|
DEF_PROP_B(WindowVX, Pause)
|
||||||
|
|
||||||
void
|
void windowVXBindingInit() {
|
||||||
windowVXBindingInit()
|
VALUE klass = rb_define_class("Window", rb_cObject);
|
||||||
{
|
#if RAPI_FULL > 187
|
||||||
VALUE klass = rb_define_class("Window", rb_cObject);
|
rb_define_alloc_func(klass, classAllocate<&WindowVXType>);
|
||||||
#ifndef OLD_RUBY
|
|
||||||
rb_define_alloc_func(klass, classAllocate<&WindowVXType>);
|
|
||||||
#else
|
#else
|
||||||
rb_define_alloc_func(klass, WindowVXAllocate);
|
rb_define_alloc_func(klass, WindowVXAllocate);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
disposableBindingInit <WindowVX>(klass);
|
disposableBindingInit<WindowVX>(klass);
|
||||||
viewportElementBindingInit<WindowVX>(klass);
|
viewportElementBindingInit<WindowVX>(klass);
|
||||||
|
|
||||||
_rb_define_method(klass, "initialize", windowVXInitialize);
|
_rb_define_method(klass, "initialize", windowVXInitialize);
|
||||||
_rb_define_method(klass, "update", windowVXUpdate);
|
_rb_define_method(klass, "update", windowVXUpdate);
|
||||||
|
|
||||||
INIT_PROP_BIND( WindowVX, Windowskin, "windowskin" );
|
INIT_PROP_BIND(WindowVX, Windowskin, "windowskin");
|
||||||
INIT_PROP_BIND( WindowVX, Contents, "contents" );
|
INIT_PROP_BIND(WindowVX, Contents, "contents");
|
||||||
INIT_PROP_BIND( WindowVX, CursorRect, "cursor_rect" );
|
INIT_PROP_BIND(WindowVX, CursorRect, "cursor_rect");
|
||||||
INIT_PROP_BIND( WindowVX, Active, "active" );
|
INIT_PROP_BIND(WindowVX, Active, "active");
|
||||||
INIT_PROP_BIND( WindowVX, Pause, "pause" );
|
INIT_PROP_BIND(WindowVX, Pause, "pause");
|
||||||
INIT_PROP_BIND( WindowVX, X, "x" );
|
INIT_PROP_BIND(WindowVX, X, "x");
|
||||||
INIT_PROP_BIND( WindowVX, Y, "y" );
|
INIT_PROP_BIND(WindowVX, Y, "y");
|
||||||
INIT_PROP_BIND( WindowVX, Width, "width" );
|
INIT_PROP_BIND(WindowVX, Width, "width");
|
||||||
INIT_PROP_BIND( WindowVX, Height, "height" );
|
INIT_PROP_BIND(WindowVX, Height, "height");
|
||||||
INIT_PROP_BIND( WindowVX, OX, "ox" );
|
INIT_PROP_BIND(WindowVX, OX, "ox");
|
||||||
INIT_PROP_BIND( WindowVX, OY, "oy" );
|
INIT_PROP_BIND(WindowVX, OY, "oy");
|
||||||
INIT_PROP_BIND( WindowVX, Opacity, "opacity" );
|
INIT_PROP_BIND(WindowVX, Opacity, "opacity");
|
||||||
INIT_PROP_BIND( WindowVX, BackOpacity, "back_opacity" );
|
INIT_PROP_BIND(WindowVX, BackOpacity, "back_opacity");
|
||||||
INIT_PROP_BIND( WindowVX, ContentsOpacity, "contents_opacity" );
|
INIT_PROP_BIND(WindowVX, ContentsOpacity, "contents_opacity");
|
||||||
INIT_PROP_BIND( WindowVX, Openness, "openness" );
|
INIT_PROP_BIND(WindowVX, Openness, "openness");
|
||||||
|
|
||||||
if (rgssVer >= 3)
|
if (rgssVer >= 3) {
|
||||||
{
|
_rb_define_method(klass, "move", windowVXMove);
|
||||||
_rb_define_method(klass, "move", windowVXMove);
|
_rb_define_method(klass, "open?", windowVXIsOpen);
|
||||||
_rb_define_method(klass, "open?", windowVXIsOpen);
|
_rb_define_method(klass, "close?", windowVXIsClosed);
|
||||||
_rb_define_method(klass, "close?", windowVXIsClosed);
|
|
||||||
|
|
||||||
INIT_PROP_BIND( WindowVX, ArrowsVisible, "arrows_visible" );
|
INIT_PROP_BIND(WindowVX, ArrowsVisible, "arrows_visible");
|
||||||
INIT_PROP_BIND( WindowVX, Padding, "padding" );
|
INIT_PROP_BIND(WindowVX, Padding, "padding");
|
||||||
INIT_PROP_BIND( WindowVX, PaddingBottom, "padding_bottom" );
|
INIT_PROP_BIND(WindowVX, PaddingBottom, "padding_bottom");
|
||||||
INIT_PROP_BIND( WindowVX, Tone, "tone" );
|
INIT_PROP_BIND(WindowVX, Tone, "tone");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue