Add Bitmap.raw_data property

This commit is contained in:
Inori 2019-09-06 15:09:03 -04:00 committed by Inori
parent 0295b6459d
commit 3b714579a8
6 changed files with 59 additions and 11 deletions

View file

@ -145,6 +145,15 @@ To smooth over cross-platform compatibility, functionality that you won't find i
* RGSS2 Graphics functions and properties are now bound in RGSS1 mode. * RGSS2 Graphics functions and properties are now bound in RGSS1 mode.
* The `Graphics` module has three additional properties: `fullscreen` represents the current fullscreen mode (`true` = fullscreen, `false` = windowed), `show_cursor` hides the system cursor inside the game window when `false`. `scale` represents the current scale factor of the screen, and can be set from `0.5` to `2`. * The `Graphics` module has three additional properties: `fullscreen` represents the current fullscreen mode (`true` = fullscreen, `false` = windowed), `show_cursor` hides the system cursor inside the game window when `false`. `scale` represents the current scale factor of the screen, and can be set from `0.5` to `2`.
* The `Graphics` module has two additional functions: `#screenshot(path)` will save a screenshot to `path` in BMP format. `#center` will move the window to the center of the screen. * The `Graphics` module has two additional functions: `#screenshot(path)` will save a screenshot to `path` in BMP format. `#center` will move the window to the center of the screen.
### Bitmap
* The `Bitmap` class has one additional property: `raw_data` gets and sets the raw pixel data of a Bitmap in the form of a string. The string must be the size of the bitmap's `width*height*4`. If it is not, no error is raised, but the Bitmap will not be updated.
### Audio
* RGSS2 Audio functions and properties are now bound in RGSS1 mode.
### Discord ### Discord
* This module is only included if the `discord_sdk_path` option is set to the location of the Discord GameSDK when building. * This module is only included if the `discord_sdk_path` option is set to the location of the Discord GameSDK when building.

View file

@ -137,13 +137,10 @@ audioBindingInit()
BIND_PLAY_STOP_FADE( bgs ); BIND_PLAY_STOP_FADE( bgs );
BIND_PLAY_STOP_FADE( me ); BIND_PLAY_STOP_FADE( me );
if (rgssVer >= 3)
{
BIND_POS( bgm ); BIND_POS( bgm );
BIND_POS( bgs ); BIND_POS( bgs );
_rb_define_module_function(module, "setup_midi", audioSetupMidi); _rb_define_module_function(module, "setup_midi", audioSetupMidi);
}
BIND_PLAY_STOP( se ) BIND_PLAY_STOP( se )

View file

@ -417,6 +417,36 @@ RB_METHOD(bitmapRadialBlur)
return Qnil; return Qnil;
} }
RB_METHOD(bitmapGetRawData)
{
RB_UNUSED_PARAM;
Bitmap *b = getPrivateData<Bitmap>(self);
char *pixels{};
int size{};
GUARD_EXC( pixels = (char*)b->getRaw(); );
GUARD_EXC( size = b->width()*b->height()*4; );
return rb_str_new(pixels, size);
}
RB_METHOD(bitmapSetRawData)
{
RB_UNUSED_PARAM;
VALUE str;
rb_get_args(argc, argv, "1", &str);
SafeStringValue(str);
Bitmap *b = getPrivateData<Bitmap>(self);
GUARD_EXC( b->replaceRaw(RSTRING_PTR(str), RSTRING_LEN(str)); );
return self;
}
RB_METHOD(bitmapInitializeCopy) RB_METHOD(bitmapInitializeCopy)
{ {
rb_check_argc(argc, 1); rb_check_argc(argc, 1);
@ -465,14 +495,14 @@ bitmapBindingInit()
_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);
if (rgssVer >= 2)
{
_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);
}
INIT_PROP_BIND(Bitmap, Font, "font"); INIT_PROP_BIND(Bitmap, Font, "font");
} }

View file

@ -883,10 +883,21 @@ void Bitmap::setPixel(int x, int y, const Color &color)
p->onModified(false); p->onModified(false);
} }
void Bitmap::replaceRaw(void *pixel_data, int w, int h) void *Bitmap::getRaw()
{ {
guardDisposed(); guardDisposed();
if (w != width() || h != height()) return;
GUARD_MEGA;
return p->surface->pixels;
}
void Bitmap::replaceRaw(void *pixel_data, int size)
{
guardDisposed();
int w = width();
int h = height();
if (size != w*h*4) return;
GUARD_MEGA; GUARD_MEGA;

View file

@ -82,7 +82,8 @@ public:
Color getPixel(int x, int y) const; Color getPixel(int x, int y) const;
void setPixel(int x, int y, const Color &color); void setPixel(int x, int y, const Color &color);
void replaceRaw(void *pixel_data, int width, int height); void *getRaw();
void replaceRaw(void *pixel_data, int size);
void hueChange(int hue); void hueChange(int hue);

View file

@ -84,7 +84,7 @@ void onActivityInviteRequestCb(void *event_data, enum EDiscordActivityActionType
void discordLogHook(void *hook_data, enum EDiscordLogLevel level, const char *message) void discordLogHook(void *hook_data, enum EDiscordLogLevel level, const char *message)
{ {
Debug() << "DISCORD:" << message; Debug() << "Discord:" << message;
} }
int discordTryConnect(DiscordStatePrivate *p) int discordTryConnect(DiscordStatePrivate *p)
@ -238,7 +238,7 @@ Bitmap *DiscordState::getAvatar(DiscordUserId userId, int size)
int sz = data->bmp->width()*data->bmp->height()*4; int sz = data->bmp->width()*data->bmp->height()*4;
uint8_t *buf = new uint8_t[sz]; uint8_t *buf = new uint8_t[sz];
data->pri->app.images->get_data(data->pri->app.images, handle_result, buf, sz); data->pri->app.images->get_data(data->pri->app.images, handle_result, buf, sz);
data->bmp->replaceRaw(buf, data->bmp->width(), data->bmp->height()); data->bmp->replaceRaw(buf, sz);
delete[] buf; delete[] buf;
delete data; delete data;
} }