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
|
@ -667,6 +667,48 @@ 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;
|
||||||
|
|
||||||
|
@ -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