diff options
| author | 2019-01-21 09:20:16 -0700 | |
|---|---|---|
| committer | 2019-01-21 09:20:16 -0700 | |
| commit | 3ca0af8bb3dfd7c67320a842db8eabe198058bd6 (patch) | |
| tree | 5c61bb08f161af8450000093f355e0f6462a80c8 /src | |
| parent | Set Minimum Size to the same as renderwindow (diff) | |
| download | yuzu-3ca0af8bb3dfd7c67320a842db8eabe198058bd6.tar.gz yuzu-3ca0af8bb3dfd7c67320a842db8eabe198058bd6.tar.xz yuzu-3ca0af8bb3dfd7c67320a842db8eabe198058bd6.zip | |
Add fade out effect to the loading screen
Diffstat (limited to 'src')
| -rw-r--r-- | src/yuzu/loading_screen.cpp | 27 | ||||
| -rw-r--r-- | src/yuzu/loading_screen.h | 12 | ||||
| -rw-r--r-- | src/yuzu/loading_screen.ui | 201 | ||||
| -rw-r--r-- | src/yuzu/main.cpp | 12 |
4 files changed, 158 insertions, 94 deletions
diff --git a/src/yuzu/loading_screen.cpp b/src/yuzu/loading_screen.cpp index 63c547b49..76ef86b8c 100644 --- a/src/yuzu/loading_screen.cpp +++ b/src/yuzu/loading_screen.cpp | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | #include <unordered_map> | 5 | #include <unordered_map> |
| 6 | #include <QBuffer> | 6 | #include <QBuffer> |
| 7 | #include <QByteArray> | 7 | #include <QByteArray> |
| 8 | #include <QGraphicsOpacityEffect> | ||
| 8 | #include <QHBoxLayout> | 9 | #include <QHBoxLayout> |
| 9 | #include <QIODevice> | 10 | #include <QIODevice> |
| 10 | #include <QImage> | 11 | #include <QImage> |
| @@ -13,6 +14,7 @@ | |||
| 13 | #include <QPalette> | 14 | #include <QPalette> |
| 14 | #include <QPixmap> | 15 | #include <QPixmap> |
| 15 | #include <QProgressBar> | 16 | #include <QProgressBar> |
| 17 | #include <QPropertyAnimation> | ||
| 16 | #include <QStyleOption> | 18 | #include <QStyleOption> |
| 17 | #include <QTime> | 19 | #include <QTime> |
| 18 | #include <QtConcurrent/QtConcurrentRun> | 20 | #include <QtConcurrent/QtConcurrentRun> |
| @@ -71,6 +73,25 @@ LoadingScreen::LoadingScreen(QWidget* parent) | |||
| 71 | ui->setupUi(this); | 73 | ui->setupUi(this); |
| 72 | setMinimumSize(1280, 720); | 74 | setMinimumSize(1280, 720); |
| 73 | 75 | ||
| 76 | // Create a fade out effect to hide this loading screen widget. | ||
| 77 | // When fading opacity, it will fade to the parent widgets background color, which is why we | ||
| 78 | // create an internal widget named fade_widget that we use the effect on, while keeping the | ||
| 79 | // loading screen widget's background color black. This way we can create a fade to black effect | ||
| 80 | opacity_effect = new QGraphicsOpacityEffect(this); | ||
| 81 | opacity_effect->setOpacity(1); | ||
| 82 | ui->fade_parent->setGraphicsEffect(opacity_effect); | ||
| 83 | fadeout_animation = std::make_unique<QPropertyAnimation>(opacity_effect, "opacity"); | ||
| 84 | fadeout_animation->setDuration(500); | ||
| 85 | fadeout_animation->setStartValue(1); | ||
| 86 | fadeout_animation->setEndValue(0); | ||
| 87 | fadeout_animation->setEasingCurve(QEasingCurve::OutBack); | ||
| 88 | |||
| 89 | // After the fade completes, hide the widget and reset the opacity | ||
| 90 | connect(fadeout_animation.get(), &QPropertyAnimation::finished, [this] { | ||
| 91 | hide(); | ||
| 92 | opacity_effect->setOpacity(1); | ||
| 93 | emit Hidden(); | ||
| 94 | }); | ||
| 74 | connect(this, &LoadingScreen::LoadProgress, this, &LoadingScreen::OnLoadProgress, | 95 | connect(this, &LoadingScreen::LoadProgress, this, &LoadingScreen::OnLoadProgress, |
| 75 | Qt::QueuedConnection); | 96 | Qt::QueuedConnection); |
| 76 | qRegisterMetaType<VideoCore::LoadCallbackStage>(); | 97 | qRegisterMetaType<VideoCore::LoadCallbackStage>(); |
| @@ -115,9 +136,14 @@ void LoadingScreen::Prepare(Loader::AppLoader& loader) { | |||
| 115 | ui->logo->setPixmap(map); | 136 | ui->logo->setPixmap(map); |
| 116 | } | 137 | } |
| 117 | 138 | ||
| 139 | slow_shader_compile_start = false; | ||
| 118 | OnLoadProgress(VideoCore::LoadCallbackStage::Prepare, 0, 0); | 140 | OnLoadProgress(VideoCore::LoadCallbackStage::Prepare, 0, 0); |
| 119 | } | 141 | } |
| 120 | 142 | ||
| 143 | void LoadingScreen::OnLoadComplete() { | ||
| 144 | fadeout_animation->start(QPropertyAnimation::KeepWhenStopped); | ||
| 145 | } | ||
| 146 | |||
| 121 | void LoadingScreen::OnLoadProgress(VideoCore::LoadCallbackStage stage, std::size_t value, | 147 | void LoadingScreen::OnLoadProgress(VideoCore::LoadCallbackStage stage, std::size_t value, |
| 122 | std::size_t total) { | 148 | std::size_t total) { |
| 123 | using namespace std::chrono; | 149 | using namespace std::chrono; |
| @@ -125,6 +151,7 @@ void LoadingScreen::OnLoadProgress(VideoCore::LoadCallbackStage stage, std::size | |||
| 125 | // reset the timer if the stage changes | 151 | // reset the timer if the stage changes |
| 126 | if (stage != previous_stage) { | 152 | if (stage != previous_stage) { |
| 127 | ui->progress_bar->setStyleSheet(progressbar_style[stage]); | 153 | ui->progress_bar->setStyleSheet(progressbar_style[stage]); |
| 154 | // Hide the progress bar during the prepare stage | ||
| 128 | if (stage == VideoCore::LoadCallbackStage::Prepare) { | 155 | if (stage == VideoCore::LoadCallbackStage::Prepare) { |
| 129 | ui->progress_bar->hide(); | 156 | ui->progress_bar->hide(); |
| 130 | } else { | 157 | } else { |
diff --git a/src/yuzu/loading_screen.h b/src/yuzu/loading_screen.h index 9370ede69..091e58eb7 100644 --- a/src/yuzu/loading_screen.h +++ b/src/yuzu/loading_screen.h | |||
| @@ -27,7 +27,9 @@ enum class LoadCallbackStage; | |||
| 27 | 27 | ||
| 28 | class QBuffer; | 28 | class QBuffer; |
| 29 | class QByteArray; | 29 | class QByteArray; |
| 30 | class QGraphicsOpacityEffect; | ||
| 30 | class QMovie; | 31 | class QMovie; |
| 32 | class QPropertyAnimation; | ||
| 31 | 33 | ||
| 32 | class LoadingScreen : public QWidget { | 34 | class LoadingScreen : public QWidget { |
| 33 | Q_OBJECT | 35 | Q_OBJECT |
| @@ -45,14 +47,21 @@ public: | |||
| 45 | /// used resources such as the logo and banner. | 47 | /// used resources such as the logo and banner. |
| 46 | void Clear(); | 48 | void Clear(); |
| 47 | 49 | ||
| 50 | /// Slot used to update the status of the progress bar | ||
| 48 | void OnLoadProgress(VideoCore::LoadCallbackStage stage, std::size_t value, std::size_t total); | 51 | void OnLoadProgress(VideoCore::LoadCallbackStage stage, std::size_t value, std::size_t total); |
| 49 | 52 | ||
| 53 | /// Hides the LoadingScreen with a fade out effect | ||
| 54 | void OnLoadComplete(); | ||
| 55 | |||
| 50 | // In order to use a custom widget with a stylesheet, you need to override the paintEvent | 56 | // In order to use a custom widget with a stylesheet, you need to override the paintEvent |
| 51 | // See https://wiki.qt.io/How_to_Change_the_Background_Color_of_QWidget | 57 | // See https://wiki.qt.io/How_to_Change_the_Background_Color_of_QWidget |
| 52 | void paintEvent(QPaintEvent* event) override; | 58 | void paintEvent(QPaintEvent* event) override; |
| 53 | 59 | ||
| 54 | signals: | 60 | signals: |
| 55 | void LoadProgress(VideoCore::LoadCallbackStage stage, std::size_t value, std::size_t total); | 61 | void LoadProgress(VideoCore::LoadCallbackStage stage, std::size_t value, std::size_t total); |
| 62 | /// Signals that this widget is completely hidden now and should be replaced with the other | ||
| 63 | /// widget | ||
| 64 | void Hidden(); | ||
| 56 | 65 | ||
| 57 | private: | 66 | private: |
| 58 | #ifndef YUZU_QT_MOVIE_MISSING | 67 | #ifndef YUZU_QT_MOVIE_MISSING |
| @@ -64,6 +73,9 @@ private: | |||
| 64 | std::size_t previous_total = 0; | 73 | std::size_t previous_total = 0; |
| 65 | VideoCore::LoadCallbackStage previous_stage; | 74 | VideoCore::LoadCallbackStage previous_stage; |
| 66 | 75 | ||
| 76 | QGraphicsOpacityEffect* opacity_effect = nullptr; | ||
| 77 | std::unique_ptr<QPropertyAnimation> fadeout_animation = nullptr; | ||
| 78 | |||
| 67 | // Definitions for the differences in text and styling for each stage | 79 | // Definitions for the differences in text and styling for each stage |
| 68 | std::unordered_map<VideoCore::LoadCallbackStage, const char*> progressbar_style; | 80 | std::unordered_map<VideoCore::LoadCallbackStage, const char*> progressbar_style; |
| 69 | std::unordered_map<VideoCore::LoadCallbackStage, QString> stage_translations; | 81 | std::unordered_map<VideoCore::LoadCallbackStage, QString> stage_translations; |
diff --git a/src/yuzu/loading_screen.ui b/src/yuzu/loading_screen.ui index 35d50741e..a67d273fd 100644 --- a/src/yuzu/loading_screen.ui +++ b/src/yuzu/loading_screen.ui | |||
| @@ -30,59 +30,77 @@ | |||
| 30 | <number>0</number> | 30 | <number>0</number> |
| 31 | </property> | 31 | </property> |
| 32 | <item> | 32 | <item> |
| 33 | <widget class="QLabel" name="logo"> | 33 | <widget class="QWidget" name="fade_parent" native="true"> |
| 34 | <property name="text"> | 34 | <layout class="QVBoxLayout" name="verticalLayout_2"> |
| 35 | <string/> | 35 | <property name="spacing"> |
| 36 | </property> | 36 | <number>0</number> |
| 37 | <property name="alignment"> | 37 | </property> |
| 38 | <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set> | 38 | <property name="leftMargin"> |
| 39 | </property> | 39 | <number>0</number> |
| 40 | <property name="margin"> | 40 | </property> |
| 41 | <number>30</number> | 41 | <property name="topMargin"> |
| 42 | </property> | 42 | <number>0</number> |
| 43 | </widget> | 43 | </property> |
| 44 | </item> | 44 | <property name="rightMargin"> |
| 45 | <item> | 45 | <number>0</number> |
| 46 | <layout class="QVBoxLayout" name="verticalLayout" stretch="1,0,1"> | 46 | </property> |
| 47 | <property name="spacing"> | 47 | <property name="bottomMargin"> |
| 48 | <number>15</number> | 48 | <number>0</number> |
| 49 | </property> | 49 | </property> |
| 50 | <property name="sizeConstraint"> | 50 | <item alignment="Qt::AlignLeft|Qt::AlignTop"> |
| 51 | <enum>QLayout::SetNoConstraint</enum> | 51 | <widget class="QLabel" name="logo"> |
| 52 | </property> | 52 | <property name="text"> |
| 53 | <item alignment="Qt::AlignHCenter|Qt::AlignBottom"> | 53 | <string/> |
| 54 | <widget class="QLabel" name="stage"> | 54 | </property> |
| 55 | <property name="sizePolicy"> | 55 | <property name="alignment"> |
| 56 | <sizepolicy hsizetype="Minimum" vsizetype="Minimum"> | 56 | <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set> |
| 57 | <horstretch>0</horstretch> | 57 | </property> |
| 58 | <verstretch>0</verstretch> | 58 | <property name="margin"> |
| 59 | </sizepolicy> | 59 | <number>30</number> |
| 60 | </property> | 60 | </property> |
| 61 | <property name="styleSheet"> | 61 | </widget> |
| 62 | <string notr="true">background-color: black; color: white; | 62 | </item> |
| 63 | <item> | ||
| 64 | <layout class="QVBoxLayout" name="verticalLayout" stretch="1,0,1"> | ||
| 65 | <property name="spacing"> | ||
| 66 | <number>15</number> | ||
| 67 | </property> | ||
| 68 | <property name="sizeConstraint"> | ||
| 69 | <enum>QLayout::SetNoConstraint</enum> | ||
| 70 | </property> | ||
| 71 | <item alignment="Qt::AlignHCenter|Qt::AlignBottom"> | ||
| 72 | <widget class="QLabel" name="stage"> | ||
| 73 | <property name="sizePolicy"> | ||
| 74 | <sizepolicy hsizetype="Minimum" vsizetype="Minimum"> | ||
| 75 | <horstretch>0</horstretch> | ||
| 76 | <verstretch>0</verstretch> | ||
| 77 | </sizepolicy> | ||
| 78 | </property> | ||
| 79 | <property name="styleSheet"> | ||
| 80 | <string notr="true">background-color: black; color: white; | ||
| 63 | font: 75 20pt "Arial";</string> | 81 | font: 75 20pt "Arial";</string> |
| 64 | </property> | 82 | </property> |
| 65 | <property name="text"> | 83 | <property name="text"> |
| 66 | <string>Loading Shaders 387 / 1628</string> | 84 | <string>Loading Shaders 387 / 1628</string> |
| 67 | </property> | 85 | </property> |
| 68 | </widget> | 86 | </widget> |
| 69 | </item> | 87 | </item> |
| 70 | <item alignment="Qt::AlignHCenter|Qt::AlignTop"> | 88 | <item alignment="Qt::AlignHCenter|Qt::AlignTop"> |
| 71 | <widget class="QProgressBar" name="progress_bar"> | 89 | <widget class="QProgressBar" name="progress_bar"> |
| 72 | <property name="sizePolicy"> | 90 | <property name="sizePolicy"> |
| 73 | <sizepolicy hsizetype="Expanding" vsizetype="Preferred"> | 91 | <sizepolicy hsizetype="Expanding" vsizetype="Preferred"> |
| 74 | <horstretch>0</horstretch> | 92 | <horstretch>0</horstretch> |
| 75 | <verstretch>0</verstretch> | 93 | <verstretch>0</verstretch> |
| 76 | </sizepolicy> | 94 | </sizepolicy> |
| 77 | </property> | 95 | </property> |
| 78 | <property name="minimumSize"> | 96 | <property name="minimumSize"> |
| 79 | <size> | 97 | <size> |
| 80 | <width>500</width> | 98 | <width>500</width> |
| 81 | <height>40</height> | 99 | <height>40</height> |
| 82 | </size> | 100 | </size> |
| 83 | </property> | 101 | </property> |
| 84 | <property name="styleSheet"> | 102 | <property name="styleSheet"> |
| 85 | <string notr="true">QProgressBar { | 103 | <string notr="true">QProgressBar { |
| 86 | color: white; | 104 | color: white; |
| 87 | border: 2px solid white; | 105 | border: 2px solid white; |
| 88 | outline-color: black; | 106 | outline-color: black; |
| @@ -92,45 +110,48 @@ QProgressBar::chunk { | |||
| 92 | background-color: white; | 110 | background-color: white; |
| 93 | border-radius: 15px; | 111 | border-radius: 15px; |
| 94 | }</string> | 112 | }</string> |
| 95 | </property> | 113 | </property> |
| 96 | <property name="value"> | 114 | <property name="value"> |
| 97 | <number>50</number> | 115 | <number>50</number> |
| 98 | </property> | 116 | </property> |
| 99 | <property name="textVisible"> | 117 | <property name="textVisible"> |
| 100 | <bool>false</bool> | 118 | <bool>false</bool> |
| 101 | </property> | 119 | </property> |
| 102 | <property name="format"> | 120 | <property name="format"> |
| 103 | <string>Loading Shaders %v out of %m</string> | 121 | <string>Loading Shaders %v out of %m</string> |
| 104 | </property> | 122 | </property> |
| 105 | </widget> | 123 | </widget> |
| 106 | </item> | 124 | </item> |
| 107 | <item alignment="Qt::AlignHCenter|Qt::AlignTop"> | 125 | <item alignment="Qt::AlignHCenter|Qt::AlignTop"> |
| 108 | <widget class="QLabel" name="value"> | 126 | <widget class="QLabel" name="value"> |
| 109 | <property name="toolTip"> | 127 | <property name="toolTip"> |
| 110 | <string notr="true"/> | 128 | <string notr="true"/> |
| 111 | </property> | 129 | </property> |
| 112 | <property name="styleSheet"> | 130 | <property name="styleSheet"> |
| 113 | <string notr="true">background-color: black; color: white; | 131 | <string notr="true">background-color: black; color: white; |
| 114 | font: 75 15pt "Arial";</string> | 132 | font: 75 15pt "Arial";</string> |
| 115 | </property> | 133 | </property> |
| 116 | <property name="text"> | 134 | <property name="text"> |
| 117 | <string>Stage 1 of 2. Estimate Time 5m 4s</string> | 135 | <string>Stage 1 of 2. Estimate Time 5m 4s</string> |
| 118 | </property> | 136 | </property> |
| 119 | </widget> | 137 | </widget> |
| 120 | </item> | 138 | </item> |
| 121 | </layout> | 139 | </layout> |
| 122 | </item> | 140 | </item> |
| 123 | <item alignment="Qt::AlignRight|Qt::AlignBottom"> | 141 | <item alignment="Qt::AlignRight|Qt::AlignBottom"> |
| 124 | <widget class="QLabel" name="banner"> | 142 | <widget class="QLabel" name="banner"> |
| 125 | <property name="styleSheet"> | 143 | <property name="styleSheet"> |
| 126 | <string notr="true">background-color: black;</string> | 144 | <string notr="true">background-color: black;</string> |
| 127 | </property> | 145 | </property> |
| 128 | <property name="text"> | 146 | <property name="text"> |
| 129 | <string/> | 147 | <string/> |
| 130 | </property> | 148 | </property> |
| 131 | <property name="margin"> | 149 | <property name="margin"> |
| 132 | <number>30</number> | 150 | <number>30</number> |
| 133 | </property> | 151 | </property> |
| 152 | </widget> | ||
| 153 | </item> | ||
| 154 | </layout> | ||
| 134 | </widget> | 155 | </widget> |
| 135 | </item> | 156 | </item> |
| 136 | </layout> | 157 | </layout> |
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index f1effb857..2c3e27c2e 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp | |||
| @@ -415,6 +415,13 @@ void GMainWindow::InitializeWidgets() { | |||
| 415 | loading_screen = new LoadingScreen(this); | 415 | loading_screen = new LoadingScreen(this); |
| 416 | loading_screen->hide(); | 416 | loading_screen->hide(); |
| 417 | ui.horizontalLayout->addWidget(loading_screen); | 417 | ui.horizontalLayout->addWidget(loading_screen); |
| 418 | connect(loading_screen, &LoadingScreen::Hidden, [&] { | ||
| 419 | loading_screen->Clear(); | ||
| 420 | if (emulation_running) { | ||
| 421 | render_window->show(); | ||
| 422 | render_window->setFocus(); | ||
| 423 | } | ||
| 424 | }); | ||
| 418 | 425 | ||
| 419 | // Create status bar | 426 | // Create status bar |
| 420 | message_label = new QLabel(); | 427 | message_label = new QLabel(); |
| @@ -1513,10 +1520,7 @@ void GMainWindow::OnStopGame() { | |||
| 1513 | } | 1520 | } |
| 1514 | 1521 | ||
| 1515 | void GMainWindow::OnLoadComplete() { | 1522 | void GMainWindow::OnLoadComplete() { |
| 1516 | loading_screen->hide(); | 1523 | loading_screen->OnLoadComplete(); |
| 1517 | loading_screen->Clear(); | ||
| 1518 | render_window->show(); | ||
| 1519 | render_window->setFocus(); | ||
| 1520 | } | 1524 | } |
| 1521 | 1525 | ||
| 1522 | void GMainWindow::OnMenuReportCompatibility() { | 1526 | void GMainWindow::OnMenuReportCompatibility() { |