aboutsummaryrefslogtreecommitdiff
path: root/src/aoscene.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/aoscene.cpp')
-rw-r--r--src/aoscene.cpp88
1 files changed, 67 insertions, 21 deletions
diff --git a/src/aoscene.cpp b/src/aoscene.cpp
index fc686336..594013a1 100644
--- a/src/aoscene.cpp
+++ b/src/aoscene.cpp
@@ -14,30 +14,55 @@ void AOScene::set_image(QString p_image)
{
QString background_path =
ao_app->get_image_suffix(ao_app->get_background_path(p_image));
- if (!file_exists(background_path))
- background_path = ao_app->get_image_suffix(
- ao_app->get_default_background_path(p_image)); // Default path
+ if (!file_exists(background_path)) // If image is missing, clear current image
+ {
+ this->clear();
+ this->setMovie(nullptr);
- if (file_exists(background_path) && background_path == last_image)
+ m_movie->stop();
+ last_image = "";
return;
+ }
- int w = this->width();
- int h = this->height();
+ if (!file_exists(background_path) || background_path != last_image)
+ {
+ this->clear();
+ this->setMovie(nullptr);
- this->clear();
- this->setMovie(nullptr);
-
- m_movie->stop();
- m_movie->setFileName(background_path);
- m_movie->setScaledSize(QSize(w, h));
+ m_movie->stop();
+ m_movie->setFileName(background_path);
+ }
- if (m_movie->isValid()) {
- this->setMovie(m_movie);
- m_movie->start();
+ if (m_movie->isValid() && m_movie->frameCount() > 1) {
+ m_movie->jumpToNextFrame();
+ float scale_factor = static_cast<float>(f_h) /
+ static_cast<float>(m_movie->frameRect().height());
+ // preserve aspect ratio
+ int n_w = static_cast<int>(m_movie->frameRect().width() * scale_factor);
+ int n_h = static_cast<int>(m_movie->frameRect().height() * scale_factor);
+
+ m_movie->setScaledSize(QSize(n_w, n_h));
+ this->resize(m_movie->scaledSize());
+ if (!file_exists(background_path) || background_path != last_image)
+ {
+ this->setMovie(m_movie);
+ m_movie->start();
+ }
+ QLabel::move(x + (f_w - n_w) / 2, y + (f_h - n_h) / 2); // Center
}
else {
QPixmap background(background_path);
- this->setPixmap(background.scaled(w, h));
+ auto transform_mode = Qt::FastTransformation;
+ if (background.height() > f_h) // We are downscaling, use anti-aliasing.
+ transform_mode = Qt::SmoothTransformation;
+
+ background = background.scaledToHeight(f_h, transform_mode);
+ this->resize(background.size());
+ this->setPixmap(background);
+ QLabel::move(
+ x + (f_w - background.width()) / 2,
+ y + (f_h - background.height()) /
+ 2); // Always center horizontally, always center vertically
}
last_image = background_path;
}
@@ -47,17 +72,23 @@ void AOScene::set_legacy_desk(QString p_image)
QString desk_path =
ao_app->get_image_suffix(ao_app->get_background_path(p_image));
- if (!file_exists(desk_path))
- desk_path = ao_app->get_image_suffix(
- ao_app->get_default_background_path(p_image)); // Default path
+ if (!file_exists(desk_path)) // If image is missing, clear current image
+ {
+ this->clear();
+ this->setMovie(nullptr);
+
+ m_movie->stop();
+ last_image = "";
+ return;
+ }
if (file_exists(desk_path) && desk_path == last_image)
return;
+
QPixmap f_desk(desk_path);
// vanilla desks vary in both width and height. in order to make that work
// with viewport rescaling, some INTENSE math is needed.
-
int vp_width = m_parent->width();
int vp_height = m_parent->height();
@@ -73,7 +104,7 @@ void AOScene::set_legacy_desk(QString p_image)
m_movie->setScaledSize(QSize(vp_width, final_h));
- if (m_movie->isValid()) {
+ if (m_movie->isValid() && m_movie->frameCount() > 1) {
this->setMovie(m_movie);
m_movie->start();
}
@@ -83,3 +114,18 @@ void AOScene::set_legacy_desk(QString p_image)
}
last_image = desk_path;
}
+
+void AOScene::combo_resize(int w, int h)
+{
+ QSize f_size(w, h);
+ f_w = w;
+ f_h = h;
+ this->resize(f_size);
+}
+
+void AOScene::move(int ax, int ay)
+{
+ x = ax;
+ y = ay;
+ QLabel::move(x, y);
+}