mirror of
https://github.com/mkxp-z/mkxp-z.git
synced 2025-04-22 06:02:04 +02:00
Bitmap.snap_to_bitmap && Bitmap.each_frame
This commit is contained in:
parent
2a158f564a
commit
c81c09b82e
3 changed files with 456 additions and 411 deletions
|
@ -1,23 +1,23 @@
|
||||||
/*
|
/*
|
||||||
** bitmap-binding.cpp
|
** bitmap-binding.cpp
|
||||||
**
|
**
|
||||||
** This file is part of mkxp.
|
** This file is part of mkxp.
|
||||||
**
|
**
|
||||||
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
||||||
**
|
**
|
||||||
** mkxp is free software: you can redistribute it and/or modify
|
** mkxp is free software: you can redistribute it and/or modify
|
||||||
** it under the terms of the GNU General Public License as published by
|
** it under the terms of the GNU General Public License as published by
|
||||||
** the Free Software Foundation, either version 2 of the License, or
|
** the Free Software Foundation, either version 2 of the License, or
|
||||||
** (at your option) any later version.
|
** (at your option) any later version.
|
||||||
**
|
**
|
||||||
** mkxp is distributed in the hope that it will be useful,
|
** mkxp is distributed in the hope that it will be useful,
|
||||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
** GNU General Public License for more details.
|
** GNU General Public License for more details.
|
||||||
**
|
**
|
||||||
** You should have received a copy of the GNU General Public License
|
** You should have received a copy of the GNU General Public License
|
||||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "binding-types.h"
|
#include "binding-types.h"
|
||||||
#include "binding-util.h"
|
#include "binding-util.h"
|
||||||
|
@ -34,406 +34,406 @@ 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;
|
int width, height;
|
||||||
rb_get_args(argc, argv, "ii", &width, &height RB_ARG_END);
|
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,
|
rb_get_args(argc, argv, "iioo|i", &x, &y, &srcObj, &srcRectObj,
|
||||||
&opacity RB_ARG_END);
|
&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,
|
rb_get_args(argc, argv, "ooo|i", &destRectObj, &srcObj, &srcRectObj,
|
||||||
&opacity RB_ARG_END);
|
&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(),
|
GUARD_EXC(b->stretchBlt(destRect->toIntRect(), *src, srcRect->toIntRect(),
|
||||||
opacity););
|
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,
|
rb_get_args(argc, argv, "iiiio", &x, &y, &width, &height,
|
||||||
&colorObj RB_ARG_END);
|
&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 {
|
||||||
|
rb_get_args(argc, argv, "oz|i", &rectObj, &str, &align RB_ARG_END);
|
||||||
|
}
|
||||||
|
|
||||||
|
rect = getPrivateDataCheck<Rect>(rectObj, RectType);
|
||||||
|
|
||||||
|
GUARD_EXC(b->drawText(rect->toIntRect(), str, align););
|
||||||
} else {
|
} else {
|
||||||
rb_get_args(argc, argv, "oz|i", &rectObj, &str, &align RB_ARG_END);
|
int x, y, width, height;
|
||||||
|
|
||||||
|
if (rgssVer >= 2) {
|
||||||
|
VALUE strObj;
|
||||||
|
rb_get_args(argc, argv, "iiiio|i", &x, &y, &width, &height, &strObj,
|
||||||
|
&align RB_ARG_END);
|
||||||
|
|
||||||
|
str = objAsStringPtr(strObj);
|
||||||
|
} else {
|
||||||
|
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););
|
||||||
}
|
}
|
||||||
|
|
||||||
rect = getPrivateDataCheck<Rect>(rectObj, RectType);
|
return self;
|
||||||
|
|
||||||
GUARD_EXC(b->drawText(rect->toIntRect(), str, align););
|
|
||||||
} else {
|
|
||||||
int x, y, width, height;
|
|
||||||
|
|
||||||
if (rgssVer >= 2) {
|
|
||||||
VALUE strObj;
|
|
||||||
rb_get_args(argc, argv, "iiiio|i", &x, &y, &width, &height, &strObj,
|
|
||||||
&align RB_ARG_END);
|
|
||||||
|
|
||||||
str = objAsStringPtr(strObj);
|
|
||||||
} else {
|
|
||||||
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););
|
|
||||||
}
|
|
||||||
|
|
||||||
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, &color1Obj, &color2Obj,
|
rb_get_args(argc, argv, "ooo|b", &rectObj, &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,
|
GUARD_EXC(b->gradientFillRect(rect->toIntRect(), color1->norm, color2->norm,
|
||||||
vertical););
|
vertical););
|
||||||
} else {
|
} else {
|
||||||
int x, y, width, height;
|
int x, y, width, height;
|
||||||
|
|
||||||
rb_get_args(argc, argv, "iiiioo|b", &x, &y, &width, &height, &color1Obj,
|
rb_get_args(argc, argv, "iiiioo|b", &x, &y, &width, &height, &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,
|
GUARD_EXC(b->gradientFillRect(x, y, width, height, color1->norm,
|
||||||
color2->norm, vertical););
|
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);
|
Bitmap *b = getPrivateData<Bitmap>(self);
|
||||||
int size = b->width() * b->height() * 4;
|
int size = b->width() * b->height() * 4;
|
||||||
VALUE ret = rb_str_new(0, size);
|
VALUE ret = rb_str_new(0, size);
|
||||||
|
|
||||||
GUARD_EXC(b->getRaw(RSTRING_PTR(ret), size););
|
GUARD_EXC(b->getRaw(RSTRING_PTR(ret), size););
|
||||||
|
|
||||||
return ret;
|
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;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(bitmapSaveToFile) {
|
RB_METHOD(bitmapSaveToFile) {
|
||||||
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);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
b->saveToFile(RSTRING_PTR(str));
|
b->saveToFile(RSTRING_PTR(str));
|
||||||
} catch (const Exception &e) {
|
} catch (const Exception &e) {
|
||||||
raiseRbExc(e);
|
raiseRbExc(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return RUBY_Qnil;
|
return RUBY_Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(bitmapGetMega){
|
RB_METHOD(bitmapGetMega){
|
||||||
RB_UNUSED_PARAM;
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
rb_check_argc(argc, 0);
|
rb_check_argc(argc, 0);
|
||||||
|
|
||||||
Bitmap *b = getPrivateData<Bitmap>(self);
|
Bitmap *b = getPrivateData<Bitmap>(self);
|
||||||
|
|
||||||
return rb_bool_new(b->isMega());
|
return rb_bool_new(b->isMega());
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(bitmapGetAnimated){
|
RB_METHOD(bitmapGetAnimated){
|
||||||
|
@ -618,13 +618,13 @@ RB_METHOD(bitmapSetFPS){
|
||||||
Bitmap *b = getPrivateData<Bitmap>(self);
|
Bitmap *b = getPrivateData<Bitmap>(self);
|
||||||
|
|
||||||
GUARD_EXC(
|
GUARD_EXC(
|
||||||
if (RB_TYPE_P(fps, RUBY_T_FLOAT)) {
|
if (RB_TYPE_P(fps, RUBY_T_FLOAT)) {
|
||||||
b->setAnimationFPS(RFLOAT_VALUE(fps));
|
b->setAnimationFPS(RFLOAT_VALUE(fps));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
b->setAnimationFPS(NUM2INT(fps));
|
b->setAnimationFPS(NUM2INT(fps));
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
return RUBY_Qnil;
|
return RUBY_Qnil;
|
||||||
}
|
}
|
||||||
|
@ -667,70 +667,112 @@ RB_METHOD(bitmapGetLooping){
|
||||||
return rb_bool_new(ret);
|
return rb_bool_new(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Captures the Bitmap's current frame data to a new Bitmap
|
||||||
|
RB_METHOD(bitmapSnapToBitmap) {
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
rb_check_argc(argc, 0);
|
||||||
|
|
||||||
|
Bitmap *b = getPrivateData<Bitmap>(self);
|
||||||
|
|
||||||
|
Bitmap *newbitmap = 0;
|
||||||
|
GUARD_EXC(newbitmap = new Bitmap(*b, false););
|
||||||
|
|
||||||
|
VALUE ret = rb_obj_alloc(rb_class_of(self));
|
||||||
|
|
||||||
|
bitmapInitProps(newbitmap, ret);
|
||||||
|
setPrivateData(ret, newbitmap);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(bitmapEachFrame) {
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
rb_check_argc(argc, 0);
|
||||||
|
|
||||||
|
Bitmap *b = getPrivateData<Bitmap>(self);
|
||||||
|
|
||||||
|
if (!rb_block_given_p()) return RUBY_Qnil;
|
||||||
|
|
||||||
|
GUARD_EXC
|
||||||
|
(
|
||||||
|
b->ensureNotPlaying();
|
||||||
|
int cur_frame = b->currentFrameI();
|
||||||
|
for (int i = 0; i < b->numFrames(); i++) {
|
||||||
|
b->gotoAndStop(i);
|
||||||
|
rb_yield_values(2, self, INT2NUM(i));
|
||||||
|
}
|
||||||
|
b->gotoAndStop(cur_frame);
|
||||||
|
);
|
||||||
|
|
||||||
|
return RUBY_Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
RB_METHOD(bitmapGetMaxSize){
|
RB_METHOD(bitmapGetMaxSize){
|
||||||
RB_UNUSED_PARAM;
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
rb_check_argc(argc, 0);
|
rb_check_argc(argc, 0);
|
||||||
|
|
||||||
return INT2NUM(Bitmap::maxSize());
|
return INT2NUM(Bitmap::maxSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(bitmapInitializeCopy) {
|
RB_METHOD(bitmapInitializeCopy) {
|
||||||
rb_check_argc(argc, 1);
|
rb_check_argc(argc, 1);
|
||||||
VALUE origObj = argv[0];
|
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);
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void bitmapBindingInit() {
|
void bitmapBindingInit() {
|
||||||
VALUE klass = rb_define_class("Bitmap", rb_cObject);
|
VALUE klass = rb_define_class("Bitmap", rb_cObject);
|
||||||
#if RAPI_FULL > 187
|
#if RAPI_FULL > 187
|
||||||
rb_define_alloc_func(klass, classAllocate<&BitmapType>);
|
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", bitmapGetRawData);
|
||||||
_rb_define_method(klass, "raw_data=", bitmapSetRawData);
|
_rb_define_method(klass, "raw_data=", bitmapSetRawData);
|
||||||
_rb_define_method(klass, "to_file", bitmapSaveToFile);
|
_rb_define_method(klass, "to_file", bitmapSaveToFile);
|
||||||
|
|
||||||
_rb_define_method(klass, "gradient_fill_rect", bitmapGradientFillRect);
|
_rb_define_method(klass, "gradient_fill_rect", bitmapGradientFillRect);
|
||||||
_rb_define_method(klass, "clear_rect", bitmapClearRect);
|
_rb_define_method(klass, "clear_rect", bitmapClearRect);
|
||||||
_rb_define_method(klass, "blur", bitmapBlur);
|
_rb_define_method(klass, "blur", bitmapBlur);
|
||||||
_rb_define_method(klass, "radial_blur", bitmapRadialBlur);
|
_rb_define_method(klass, "radial_blur", bitmapRadialBlur);
|
||||||
|
|
||||||
_rb_define_method(klass, "mega?", bitmapGetMega);
|
_rb_define_method(klass, "mega?", bitmapGetMega);
|
||||||
rb_define_singleton_method(klass, "max_size", RUBY_METHOD_FUNC(bitmapGetMaxSize), -1);
|
rb_define_singleton_method(klass, "max_size", RUBY_METHOD_FUNC(bitmapGetMaxSize), -1);
|
||||||
|
|
||||||
_rb_define_method(klass, "animated?", bitmapGetAnimated);
|
_rb_define_method(klass, "animated?", bitmapGetAnimated);
|
||||||
_rb_define_method(klass, "playing", bitmapGetPlaying);
|
_rb_define_method(klass, "playing", bitmapGetPlaying);
|
||||||
|
@ -745,10 +787,12 @@ void bitmapBindingInit() {
|
||||||
_rb_define_method(klass, "remove_frame", bitmapRemoveFrame);
|
_rb_define_method(klass, "remove_frame", bitmapRemoveFrame);
|
||||||
_rb_define_method(klass, "next_frame", bitmapNextFrame);
|
_rb_define_method(klass, "next_frame", bitmapNextFrame);
|
||||||
_rb_define_method(klass, "previous_frame", bitmapPreviousFrame);
|
_rb_define_method(klass, "previous_frame", bitmapPreviousFrame);
|
||||||
|
_rb_define_method(klass, "each_frame", bitmapEachFrame);
|
||||||
_rb_define_method(klass, "frame_rate", bitmapGetFPS);
|
_rb_define_method(klass, "frame_rate", bitmapGetFPS);
|
||||||
_rb_define_method(klass, "frame_rate=", bitmapSetFPS);
|
_rb_define_method(klass, "frame_rate=", bitmapSetFPS);
|
||||||
_rb_define_method(klass, "looping", bitmapGetLooping);
|
_rb_define_method(klass, "looping", bitmapGetLooping);
|
||||||
_rb_define_method(klass, "looping=", bitmapSetLooping);
|
_rb_define_method(klass, "looping=", bitmapSetLooping);
|
||||||
|
_rb_define_method(klass, "snap_to_bitmap", bitmapSnapToBitmap);
|
||||||
|
|
||||||
INIT_PROP_BIND(Bitmap, Font, "font");
|
INIT_PROP_BIND(Bitmap, Font, "font");
|
||||||
}
|
}
|
||||||
|
|
|
@ -645,13 +645,14 @@ Bitmap::Bitmap(void *pixeldata, int width, int height)
|
||||||
p->addTaintedArea(rect());
|
p->addTaintedArea(rect());
|
||||||
}
|
}
|
||||||
|
|
||||||
Bitmap::Bitmap(const Bitmap &other)
|
Bitmap::Bitmap(const Bitmap &other, bool copyAllFrames)
|
||||||
{
|
{
|
||||||
other.ensureNonMega();
|
other.ensureNonMega();
|
||||||
|
|
||||||
p = new BitmapPrivate(this);
|
p = new BitmapPrivate(this);
|
||||||
|
|
||||||
if (!other.isAnimated()) {
|
if (!other.isAnimated() || !copyAllFrames) {
|
||||||
|
other.ensureNotPlaying();
|
||||||
p->gl = shState->texPool().request(other.width(), other.height());
|
p->gl = shState->texPool().request(other.width(), other.height());
|
||||||
blt(0, 0, other, rect());
|
blt(0, 0, other, rect());
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ public:
|
||||||
Bitmap(int width, int height);
|
Bitmap(int width, int height);
|
||||||
Bitmap(void *pixeldata, int width, int height);
|
Bitmap(void *pixeldata, int width, int height);
|
||||||
/* Clone constructor */
|
/* Clone constructor */
|
||||||
Bitmap(const Bitmap &other);
|
Bitmap(const Bitmap &other, bool copyAllFrames = true);
|
||||||
~Bitmap();
|
~Bitmap();
|
||||||
|
|
||||||
int width() const;
|
int width() const;
|
||||||
|
|
Loading…
Add table
Reference in a new issue