aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCrystalwarrior <varsash@gmail.com>2019-09-15 02:17:20 +0300
committerCrystalwarrior <varsash@gmail.com>2019-09-15 02:17:20 +0300
commit5419641c1ebe1e8749ad6e78b82c11cbd1bc13b7 (patch)
tree3eebe00721c27cc18a7a6b5a8e21754cecd7e274
parent14ced5ce156eec4974b424fc59e47da948aa080d (diff)
Revert "2.7.2 way of animating charmovie.cpp ported over"
This reverts commit 14ced5ce156eec4974b424fc59e47da948aa080d.
-rw-r--r--include/aocharmovie.h7
-rw-r--r--src/aocharmovie.cpp76
2 files changed, 29 insertions, 54 deletions
diff --git a/include/aocharmovie.h b/include/aocharmovie.h
index bc0e30a5..f54f5105 100644
--- a/include/aocharmovie.h
+++ b/include/aocharmovie.h
@@ -29,15 +29,12 @@ public:
void combo_resize(int w, int h);
- void set_frame(QImage image);
-
private:
AOApplication *ao_app;
QMovie *m_movie;
QVector<QImage> movie_frames;
QTimer *preanim_timer;
- QTimer *ticker;
const int time_mod = 60;
@@ -49,13 +46,11 @@ private:
bool play_once = true;
- bool preprocess = false;
-
signals:
void done();
private slots:
- void movie_ticker();
+ void frame_change(int n_frame);
void timer_done();
};
diff --git a/src/aocharmovie.cpp b/src/aocharmovie.cpp
index a0afc357..ac12f638 100644
--- a/src/aocharmovie.cpp
+++ b/src/aocharmovie.cpp
@@ -13,16 +13,12 @@ AOCharMovie::AOCharMovie(QWidget *p_parent, AOApplication *p_ao_app) : QLabel(p_
preanim_timer = new QTimer(this);
preanim_timer->setSingleShot(true);
- ticker = new QTimer(this);
- ticker->setSingleShot(true);
-
+ connect(m_movie, SIGNAL(frameChanged(int)), this, SLOT(frame_change(int)));
connect(preanim_timer, SIGNAL(timeout()), this, SLOT(timer_done()));
- connect(ticker, SIGNAL(timeout()), this, SLOT(movie_ticker()));
}
void AOCharMovie::play(QString p_char, QString p_emote, QString emote_prefix)
{
- preprocess = false;
QString emote_path;
QList<QString> pathlist;
pathlist = {
@@ -37,22 +33,30 @@ void AOCharMovie::play(QString p_char, QString p_emote, QString emote_prefix)
if (file_exists(path))
{
emote_path = path;
- if (emote_path.endsWith(".apng"))
- preprocess = true;
break;
}
}
- delete m_movie;
- m_movie = new QMovie(this);
m_movie->stop();
- this->clear();
m_movie->setFileName(emote_path);
- m_movie->jumpToFrame(0);
- this->set_frame(m_movie->currentImage());
- qDebug() << "playing file path: " << emote_path;
+
+ QImageReader *reader = new QImageReader(emote_path);
+
+ movie_frames.clear();
+ QImage f_image = reader->read();
+ while (!f_image.isNull())
+ {
+ if (m_flipped)
+ movie_frames.append(f_image.mirrored(true, false));
+ else
+ movie_frames.append(f_image);
+ f_image = reader->read();
+ }
+
+ delete reader;
+
this->show();
- ticker->start(m_movie->nextFrameDelay());
+ m_movie->start();
}
void AOCharMovie::play_pre(QString p_char, QString p_emote, int duration)
@@ -147,43 +151,12 @@ void AOCharMovie::move(int ax, int ay)
QLabel::move(x, y);
}
-void AOCharMovie::movie_ticker()
+void AOCharMovie::frame_change(int n_frame)
{
- if(preprocess)
- ticker->start(m_movie->nextFrameDelay());
- if(m_movie->currentFrameNumber() == m_movie->frameCount() - 1)
+ if (movie_frames.size() > n_frame)
{
- QString last_path = m_movie->fileName();
- delete m_movie;
- m_movie = new QMovie(this);
- m_movie->stop();
- this->clear();
- m_movie->setFileName(last_path);
- m_movie->jumpToFrame(0);
- if(play_once)
- {
- timer_done();
- }
- }
- else
- {
- m_movie->jumpToNextFrame();
- }
- this->set_frame(m_movie->currentImage());
-// this->play_frame_sfx();
- if(!preprocess){
- ticker->start(m_movie->nextFrameDelay());
- }
-}
-
-void AOCharMovie::set_frame(QImage image)
-{
- QPixmap f_pixmap;
- if(m_flipped)
- f_pixmap = QPixmap::fromImage(image.mirrored(true, false));
- else
- f_pixmap = QPixmap::fromImage(image);
+ QPixmap f_pixmap = QPixmap::fromImage(movie_frames.at(n_frame));
auto aspect_ratio = Qt::KeepAspectRatio;
if (f_pixmap.size().width() > f_pixmap.size().height())
@@ -195,6 +168,13 @@ void AOCharMovie::set_frame(QImage image)
this->setPixmap(f_pixmap.scaled(this->width(), this->height(), aspect_ratio, Qt::FastTransformation));
QLabel::move(x + (this->width() - this->pixmap()->width())/2, y);
+ }
+
+ if (m_movie->frameCount() - 1 == n_frame && play_once)
+ {
+ preanim_timer->start(m_movie->nextFrameDelay());
+ m_movie->stop();
+ }
}
void AOCharMovie::timer_done()