diff options
| author | Crystalwarrior <varsash@gmail.com> | 2019-09-20 17:03:49 +0300 |
|---|---|---|
| committer | Crystalwarrior <varsash@gmail.com> | 2019-09-20 17:03:49 +0300 |
| commit | 6dd0845f1c732e9c07afaaffb9163ba736a2ae25 (patch) | |
| tree | 6d02ad40dcb1bbb45e8cb2e9e80c510421d423a7 | |
| parent | d3f23708c43bc132c322b778b2aa8d31a68d1c0c (diff) | |
Better scaling algorithm for characters of variable size
| -rw-r--r-- | include/aocharmovie.h | 3 | ||||
| -rw-r--r-- | src/aocharmovie.cpp | 23 |
2 files changed, 19 insertions, 7 deletions
diff --git a/include/aocharmovie.h b/include/aocharmovie.h index adfa7b88..8aed1eb8 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 b795847a..89d832df 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) |
