aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCrystalwarrior <varsash@gmail.com>2020-03-26 14:41:56 +0300
committerCrystalwarrior <varsash@gmail.com>2020-03-26 14:41:56 +0300
commit1634db78641526ddb88f844a46b1bdc615a89e59 (patch)
tree58767eeff7b6a58bc257bf3db0f4b9f6f9e5a92c
parentf668d70ac5e5ed7dff8ddb4508e2b8adfcba7d66 (diff)
Make backgrounds preserve aspect ratio when used with different aspect ratio themes
(e.g. a 16:9 theme would not stretch a 4:3 bg and instead have a letterboxing effect. A 4:3 theme using a 16:9 BG will not stretch the BG but instead center it, making it look like the BG is 4:3 all along.)
-rw-r--r--include/aoscene.h11
-rw-r--r--src/aoscene.cpp39
-rw-r--r--src/courtroom.cpp4
3 files changed, 45 insertions, 9 deletions
diff --git a/include/aoscene.h b/include/aoscene.h
index ddbefe08..46d8c3b8 100644
--- a/include/aoscene.h
+++ b/include/aoscene.h
@@ -17,12 +17,23 @@ public:
void set_image(QString p_image);
void set_legacy_desk(QString p_image);
+ //Move the label itself around
+ void move(int ax, int ay);
+
+ //This is somewhat pointless now as there's no "QMovie" object to resize, aka no "combo" to speak of
+ void combo_resize(int w, int h);
private:
QWidget *m_parent;
QMovie *m_movie;
AOApplication *ao_app;
QString last_image;
+ // 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;
};
#endif // AOSCENE_H
diff --git a/src/aoscene.cpp b/src/aoscene.cpp
index 32e5c350..45eadd54 100644
--- a/src/aoscene.cpp
+++ b/src/aoscene.cpp
@@ -26,25 +26,35 @@ void AOScene::set_image(QString p_image)
if (file_exists(background_path) && background_path == last_image)
return;
- int w = this->width();
- int h = this->height();
-
this->clear();
this->setMovie(nullptr);
m_movie->stop();
m_movie->setFileName(background_path);
- m_movie->setScaledSize(QSize(w, h));
if (m_movie->isValid() && m_movie->frameCount() > 1)
{
+ float scale_factor = f_h / m_movie->frameRect().height();
+ //preserve aspect ratio
+ int n_w = static_cast<int>(static_cast<float>(m_movie->frameRect().width()) * scale_factor);
+ int n_h = static_cast<int>(static_cast<float>(m_movie->frameRect().height()) * scale_factor);
+ m_movie->setScaledSize(QSize(n_w, n_h));
+ this->resize(m_movie->scaledSize());
this->setMovie(m_movie);
+ QLabel::move(x + (f_w - n_w)/2, y + (f_h - n_h)); //Always center horizontally, always put at the bottom vertically
m_movie->start();
}
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;
}
@@ -92,8 +102,23 @@ void AOScene::set_legacy_desk(QString p_image)
}
else
{
- this->resize(vp_width, final_h);
- this->setPixmap(f_desk.scaled(vp_width, final_h));
+ this->resize(vp_width, final_h);
+ this->setPixmap(f_desk.scaled(vp_width, final_h));
}
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);
+}
diff --git a/src/courtroom.cpp b/src/courtroom.cpp
index 8cf5751e..dbe53236 100644
--- a/src/courtroom.cpp
+++ b/src/courtroom.cpp
@@ -487,7 +487,7 @@ void Courtroom::set_widgets()
ui_settings->show();
ui_vp_background->move(0, 0);
- ui_vp_background->resize(ui_viewport->width(), ui_viewport->height());
+ ui_vp_background->combo_resize(ui_viewport->width(), ui_viewport->height());
ui_vp_speedlines->move(0, 0);
ui_vp_speedlines->combo_resize(ui_viewport->width(), ui_viewport->height());
@@ -500,7 +500,7 @@ void Courtroom::set_widgets()
//the AO2 desk element
ui_vp_desk->move(0, 0);
- ui_vp_desk->resize(ui_viewport->width(), ui_viewport->height());
+ ui_vp_desk->combo_resize(ui_viewport->width(), ui_viewport->height());
//the size of the ui_vp_legacy_desk element relies on various factors and is set in set_scene()