Browse Source
Merge pull request #2034 from jroweboy/loading-widget
Merge pull request #2034 from jroweboy/loading-widget
QT Frontend: Add a Loading screen with progressbarnce_cpp
committed by
GitHub
9 changed files with 262 additions and 11 deletions
-
5CMakeModules/CopyYuzuQt5Deps.cmake
-
5src/yuzu/CMakeLists.txt
-
11src/yuzu/bootmanager.cpp
-
3src/yuzu/bootmanager.h
-
84src/yuzu/loading_screen.cpp
-
56src/yuzu/loading_screen.h
-
79src/yuzu/loading_screen.ui
-
26src/yuzu/main.cpp
-
4src/yuzu/main.h
@ -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
|
||||
|
} |
||||
@ -0,0 +1,56 @@ |
|||||
|
// Copyright 2019 yuzu Emulator Project |
||||
|
// Licensed under GPLv2 or any later version |
||||
|
// Refer to the license.txt file included. |
||||
|
|
||||
|
#pragma once |
||||
|
|
||||
|
#include <memory> |
||||
|
#include <QWidget> |
||||
|
|
||||
|
#if !QT_CONFIG(movie) |
||||
|
#define YUZU_QT_MOVIE_MISSING 1 |
||||
|
#endif |
||||
|
|
||||
|
namespace Loader { |
||||
|
class AppLoader; |
||||
|
} |
||||
|
|
||||
|
namespace Ui { |
||||
|
class LoadingScreen; |
||||
|
} |
||||
|
|
||||
|
class QBuffer; |
||||
|
class QByteArray; |
||||
|
class QMovie; |
||||
|
|
||||
|
class LoadingScreen : public QWidget { |
||||
|
Q_OBJECT |
||||
|
|
||||
|
public: |
||||
|
explicit LoadingScreen(QWidget* parent = nullptr); |
||||
|
|
||||
|
~LoadingScreen(); |
||||
|
|
||||
|
/// Call before showing the loading screen to load the widgets with the logo and banner for the |
||||
|
/// currently loaded application. |
||||
|
void Prepare(Loader::AppLoader& loader); |
||||
|
|
||||
|
/// After the loading screen is hidden, the owner of this class can call this to clean up any |
||||
|
/// used resources such as the logo and banner. |
||||
|
void Clear(); |
||||
|
|
||||
|
// In order to use a custom widget with a stylesheet, you need to override the paintEvent |
||||
|
// See https://wiki.qt.io/How_to_Change_the_Background_Color_of_QWidget |
||||
|
void paintEvent(QPaintEvent* event) override; |
||||
|
|
||||
|
void OnLoadProgress(std::size_t value, std::size_t total); |
||||
|
|
||||
|
private: |
||||
|
#ifndef YUZU_QT_MOVIE_MISSING |
||||
|
std::unique_ptr<QMovie> animation; |
||||
|
std::unique_ptr<QBuffer> backing_buf; |
||||
|
std::unique_ptr<QByteArray> backing_mem; |
||||
|
#endif |
||||
|
std::unique_ptr<Ui::LoadingScreen> ui; |
||||
|
std::size_t previous_total = 0; |
||||
|
}; |
||||
@ -0,0 +1,79 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<ui version="4.0"> |
||||
|
<class>LoadingScreen</class> |
||||
|
<widget class="QWidget" name="LoadingScreen"> |
||||
|
<property name="geometry"> |
||||
|
<rect> |
||||
|
<x>0</x> |
||||
|
<y>0</y> |
||||
|
<width>746</width> |
||||
|
<height>495</height> |
||||
|
</rect> |
||||
|
</property> |
||||
|
<property name="styleSheet"> |
||||
|
<string notr="true">background-color: rgb(0, 0, 0);</string> |
||||
|
</property> |
||||
|
<layout class="QVBoxLayout"> |
||||
|
<property name="spacing"> |
||||
|
<number>0</number> |
||||
|
</property> |
||||
|
<property name="leftMargin"> |
||||
|
<number>0</number> |
||||
|
</property> |
||||
|
<property name="topMargin"> |
||||
|
<number>0</number> |
||||
|
</property> |
||||
|
<property name="rightMargin"> |
||||
|
<number>0</number> |
||||
|
</property> |
||||
|
<property name="bottomMargin"> |
||||
|
<number>0</number> |
||||
|
</property> |
||||
|
<item> |
||||
|
<widget class="QLabel" name="logo"> |
||||
|
<property name="text"> |
||||
|
<string/> |
||||
|
</property> |
||||
|
<property name="alignment"> |
||||
|
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set> |
||||
|
</property> |
||||
|
<property name="margin"> |
||||
|
<number>30</number> |
||||
|
</property> |
||||
|
</widget> |
||||
|
</item> |
||||
|
<item> |
||||
|
<layout class="QHBoxLayout" name="horizontalLayout"> |
||||
|
<item> |
||||
|
<widget class="QProgressBar" name="progress_bar"> |
||||
|
<property name="styleSheet"> |
||||
|
<string notr="true">font-size: 26px;</string> |
||||
|
</property> |
||||
|
<property name="value"> |
||||
|
<number>0</number> |
||||
|
</property> |
||||
|
<property name="format"> |
||||
|
<string>Loading Shaders %v out of %m</string> |
||||
|
</property> |
||||
|
</widget> |
||||
|
</item> |
||||
|
</layout> |
||||
|
</item> |
||||
|
<item alignment="Qt::AlignRight|Qt::AlignBottom"> |
||||
|
<widget class="QLabel" name="banner"> |
||||
|
<property name="styleSheet"> |
||||
|
<string notr="true">background-color: black;</string> |
||||
|
</property> |
||||
|
<property name="text"> |
||||
|
<string/> |
||||
|
</property> |
||||
|
<property name="margin"> |
||||
|
<number>30</number> |
||||
|
</property> |
||||
|
</widget> |
||||
|
</item> |
||||
|
</layout> |
||||
|
</widget> |
||||
|
<resources/> |
||||
|
<connections/> |
||||
|
</ui> |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue