Bitmap.snap_to_bitmap && Bitmap.each_frame

This commit is contained in:
Roza 2021-05-03 11:51:39 -04:00
parent 2a158f564a
commit c81c09b82e
3 changed files with 456 additions and 411 deletions

View file

@ -667,6 +667,48 @@ RB_METHOD(bitmapGetLooping){
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_UNUSED_PARAM;
@ -745,10 +787,12 @@ void bitmapBindingInit() {
_rb_define_method(klass, "remove_frame", bitmapRemoveFrame);
_rb_define_method(klass, "next_frame", bitmapNextFrame);
_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=", bitmapSetFPS);
_rb_define_method(klass, "looping", bitmapGetLooping);
_rb_define_method(klass, "looping=", bitmapSetLooping);
_rb_define_method(klass, "snap_to_bitmap", bitmapSnapToBitmap);
INIT_PROP_BIND(Bitmap, Font, "font");
}

View file

@ -645,13 +645,14 @@ Bitmap::Bitmap(void *pixeldata, int width, int height)
p->addTaintedArea(rect());
}
Bitmap::Bitmap(const Bitmap &other)
Bitmap::Bitmap(const Bitmap &other, bool copyAllFrames)
{
other.ensureNonMega();
p = new BitmapPrivate(this);
if (!other.isAnimated()) {
if (!other.isAnimated() || !copyAllFrames) {
other.ensureNotPlaying();
p->gl = shState->texPool().request(other.width(), other.height());
blt(0, 0, other, rect());
}

View file

@ -42,7 +42,7 @@ public:
Bitmap(int width, int height);
Bitmap(void *pixeldata, int width, int height);
/* Clone constructor */
Bitmap(const Bitmap &other);
Bitmap(const Bitmap &other, bool copyAllFrames = true);
~Bitmap();
int width() const;