diff options
author | bunnei <bunneidev@gmail.com> | 2019-01-20 15:45:07 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-20 15:45:07 -0500 |
commit | 1c733bf175253bbe3f2f7747fe5344e654eff6e0 (patch) | |
tree | 5caf78c0e37fd6e158211301c10514f09eac7a77 /src/yuzu/loading_screen.cpp | |
parent | 197d0d9d2408e608909b32dfa057791215d42c77 (diff) | |
parent | 69da26754003cb4695380738f5a837c9a93b5eaa (diff) |
Merge pull request #2034 from jroweboy/loading-widget
QT Frontend: Add a Loading screen with progressbar
Diffstat (limited to 'src/yuzu/loading_screen.cpp')
-rw-r--r-- | src/yuzu/loading_screen.cpp | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/yuzu/loading_screen.cpp b/src/yuzu/loading_screen.cpp new file mode 100644 index 000000000..0f3c4bb6c --- /dev/null +++ b/src/yuzu/loading_screen.cpp @@ -0,0 +1,84 @@ +// Copyright 2019 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include <QBuffer> +#include <QByteArray> +#include <QHBoxLayout> +#include <QIODevice> +#include <QImage> +#include <QLabel> +#include <QPainter> +#include <QPalette> +#include <QPixmap> +#include <QProgressBar> +#include <QStyleOption> +#include <QWindow> +#include "common/logging/log.h" +#include "core/loader/loader.h" +#include "ui_loading_screen.h" +#include "yuzu/loading_screen.h" + +// Mingw seems to not have QMovie at all. If QMovie is missing then use a single frame instead of an +// showing the full animation +#if !YUZU_QT_MOVIE_MISSING +#include <QMovie> +#endif + +LoadingScreen::LoadingScreen(QWidget* parent) + : QWidget(parent), ui(std::make_unique<Ui::LoadingScreen>()) { + ui->setupUi(this); + // Progress bar is hidden until we have a use for it. + ui->progress_bar->hide(); +} + +LoadingScreen::~LoadingScreen() = default; + +void LoadingScreen::Prepare(Loader::AppLoader& loader) { + std::vector<u8> buffer; + if (loader.ReadBanner(buffer) == Loader::ResultStatus::Success) { +#ifdef YUZU_QT_MOVIE_MISSING + QPixmap map; + map.loadFromData(buffer.data(), buffer.size()); + ui->banner->setPixmap(map); +#else + backing_mem = + std::make_unique<QByteArray>(reinterpret_cast<char*>(buffer.data()), buffer.size()); + backing_buf = std::make_unique<QBuffer>(backing_mem.get()); + backing_buf->open(QIODevice::ReadOnly); + animation = std::make_unique<QMovie>(backing_buf.get(), QByteArray("GIF")); + animation->start(); + ui->banner->setMovie(animation.get()); +#endif + buffer.clear(); + } + if (loader.ReadLogo(buffer) == Loader::ResultStatus::Success) { + QPixmap map; + map.loadFromData(buffer.data(), buffer.size()); + ui->logo->setPixmap(map); + } +} + +void LoadingScreen::OnLoadProgress(std::size_t value, std::size_t total) { + if (total != previous_total) { + ui->progress_bar->setMaximum(total); + previous_total = total; + } + ui->progress_bar->setValue(value); +} + +void LoadingScreen::paintEvent(QPaintEvent* event) { + QStyleOption opt; + opt.init(this); + QPainter p(this); + style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); + QWidget::paintEvent(event); +} + +void LoadingScreen::Clear() { +#ifndef YUZU_QT_MOVIE_MISSING + animation.reset(); + backing_buf.reset(); + backing_mem.reset(); +#endif +} |