diff --git a/include/aocharmovie.h b/include/aocharmovie.h index adfa7b8..8aed1eb 100644 --- a/include/aocharmovie.h +++ b/include/aocharmovie.h @@ -73,6 +73,9 @@ private: // These are the X and Y values before they are fixed based on the sprite's width. int x = 0; int y = 0; + // These are the width and height values before they are fixed based on the sprite's width. + int f_w = 0; + int f_h = 0; int frame = 0; int max_frames = 0; diff --git a/src/aocharmovie.cpp b/src/aocharmovie.cpp index b795847..89d832d 100644 --- a/src/aocharmovie.cpp +++ b/src/aocharmovie.cpp @@ -232,14 +232,22 @@ QPixmap AOCharMovie::get_pixmap(QImage image) else f_pixmap = QPixmap::fromImage(image); auto aspect_ratio = Qt::KeepAspectRatio; + auto transform_mode = Qt::SmoothTransformation; - if (f_pixmap.size().width() > f_pixmap.size().height()) - aspect_ratio = Qt::KeepAspectRatioByExpanding; - - if (f_pixmap.size().width() > this->size().width() || f_pixmap.size().height() > this->size().height()) - f_pixmap = f_pixmap.scaled(this->width(), this->height(), aspect_ratio, Qt::SmoothTransformation); + if (f_pixmap.size().width() > this->size().width() && f_pixmap.size().height() <= this->size().height()) + { + f_pixmap = f_pixmap.scaledToHeight(this->height(), transform_mode); + } + else if (f_pixmap.size().height() > this->size().height()) + { + f_pixmap = f_pixmap.scaledToWidth(this->width(), transform_mode); + } else - f_pixmap = f_pixmap.scaled(this->width(), this->height(), aspect_ratio, Qt::FastTransformation); + { + f_pixmap = f_pixmap.scaled(this->width(), this->height(), aspect_ratio, transform_mode); + } + this->move((f_w - f_pixmap.width())/2, (f_h - f_pixmap.height())/2); + this->resize(f_pixmap.size()); return f_pixmap; } @@ -253,8 +261,9 @@ void AOCharMovie::set_frame(QPixmap f_pixmap) void AOCharMovie::combo_resize(int w, int h) { QSize f_size(w, h); + f_w = w; + f_h = h; this->resize(f_size); -// m_reader->setScaledSize(f_size); } int AOCharMovie::get_frame_delay(int delay)