mirror of
https://github.com/mkxp-z/mkxp-z.git
synced 2025-09-10 03:52:55 +02:00
Copy all frames of animated bitmaps
This commit is contained in:
parent
66de7c1d14
commit
09e68345f4
2 changed files with 50 additions and 12 deletions
|
@ -651,9 +651,41 @@ Bitmap::Bitmap(const Bitmap &other)
|
||||||
|
|
||||||
p = new BitmapPrivate(this);
|
p = new BitmapPrivate(this);
|
||||||
|
|
||||||
p->gl = shState->texPool().request(other.width(), other.height());
|
if (!other.isAnimated()) {
|
||||||
|
p->gl = shState->texPool().request(other.width(), other.height());
|
||||||
|
blt(0, 0, other, rect());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
p->animation.enabled = true;
|
||||||
|
p->animation.fps = other.getAnimationFPS();
|
||||||
|
p->animation.width = other.width();
|
||||||
|
p->animation.height = other.height();
|
||||||
|
p->animation.lastFrame = 0;
|
||||||
|
p->animation.loop = other.getLooping();
|
||||||
|
|
||||||
blt(0, 0, other, rect());
|
char *tmp = new char[p->animation.width * p->animation.height * 4];
|
||||||
|
for (const TEXFBO &frame : other.getFrames()) {
|
||||||
|
TEXFBO copyframe;
|
||||||
|
try {
|
||||||
|
copyframe = shState->texPool().request(p->animation.width, p->animation.height);
|
||||||
|
} catch(const Exception &e) {
|
||||||
|
for (TEXFBO &f : p->animation.frames)
|
||||||
|
shState->texPool().release(f);
|
||||||
|
delete tmp;
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: gotta see if I can copy textures directly from one TEXFBO to the other
|
||||||
|
// I'm an idiot so I don't already know
|
||||||
|
FBO::bind(frame.fbo);
|
||||||
|
gl.ReadPixels(0,0,p->animation.width,p->animation.height,GL_RGBA,GL_UNSIGNED_BYTE,tmp);
|
||||||
|
TEX::bind(copyframe.tex);
|
||||||
|
TEX::uploadImage(p->animation.width, p->animation.height, tmp, GL_RGBA);
|
||||||
|
|
||||||
|
p->animation.frames.push_back(copyframe);
|
||||||
|
}
|
||||||
|
delete tmp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Bitmap::~Bitmap()
|
Bitmap::~Bitmap()
|
||||||
|
@ -1797,7 +1829,7 @@ void Bitmap::play()
|
||||||
p->animation.play();
|
p->animation.play();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Bitmap::isPlaying()
|
bool Bitmap::isPlaying() const
|
||||||
{
|
{
|
||||||
if (!p->animation.playing)
|
if (!p->animation.playing)
|
||||||
return false;
|
return false;
|
||||||
|
@ -1824,7 +1856,7 @@ void Bitmap::gotoAndPlay(int frame)
|
||||||
p->animation.play();
|
p->animation.play();
|
||||||
}
|
}
|
||||||
|
|
||||||
int Bitmap::numFrames()
|
int Bitmap::numFrames() const
|
||||||
{
|
{
|
||||||
if (!p->animation.enabled) return 1;
|
if (!p->animation.enabled) return 1;
|
||||||
return p->animation.frames.size();
|
return p->animation.frames.size();
|
||||||
|
@ -1964,7 +1996,12 @@ void Bitmap::setAnimationFPS(float FPS)
|
||||||
if (restart) p->animation.play();
|
if (restart) p->animation.play();
|
||||||
}
|
}
|
||||||
|
|
||||||
float Bitmap::getAnimationFPS()
|
std::vector<TEXFBO> &Bitmap::getFrames() const
|
||||||
|
{
|
||||||
|
return p->animation.frames;
|
||||||
|
}
|
||||||
|
|
||||||
|
float Bitmap::getAnimationFPS() const
|
||||||
{
|
{
|
||||||
GUARD_MEGA;
|
GUARD_MEGA;
|
||||||
|
|
||||||
|
@ -1978,7 +2015,7 @@ void Bitmap::setLooping(bool loop)
|
||||||
p->animation.loop = loop;
|
p->animation.loop = loop;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Bitmap::getLooping()
|
bool Bitmap::getLooping() const
|
||||||
{
|
{
|
||||||
GUARD_MEGA;
|
GUARD_MEGA;
|
||||||
|
|
||||||
|
|
|
@ -123,10 +123,10 @@ public:
|
||||||
// Animation functions
|
// Animation functions
|
||||||
void stop();
|
void stop();
|
||||||
void play();
|
void play();
|
||||||
bool isPlaying();
|
bool isPlaying() const;
|
||||||
void gotoAndStop(int frame);
|
void gotoAndStop(int frame);
|
||||||
void gotoAndPlay(int frame);
|
void gotoAndPlay(int frame);
|
||||||
int numFrames();
|
int numFrames() const;
|
||||||
int currentFrameI() const;
|
int currentFrameI() const;
|
||||||
|
|
||||||
int addFrame(Bitmap &source, int position = -1);
|
int addFrame(Bitmap &source, int position = -1);
|
||||||
|
@ -134,12 +134,13 @@ public:
|
||||||
|
|
||||||
void nextFrame();
|
void nextFrame();
|
||||||
void previousFrame();
|
void previousFrame();
|
||||||
|
std::vector<TEXFBO> &getFrames() const;
|
||||||
|
|
||||||
void setAnimationFPS(float FPS);
|
void setAnimationFPS(float FPS);
|
||||||
float getAnimationFPS();
|
float getAnimationFPS() const;
|
||||||
|
|
||||||
void setLooping(bool loop);
|
void setLooping(bool loop);
|
||||||
bool getLooping();
|
bool getLooping() const;
|
||||||
|
|
||||||
void ensureNotPlaying() const;
|
void ensureNotPlaying() const;
|
||||||
// ----------
|
// ----------
|
||||||
|
|
Loading…
Add table
Reference in a new issue