Add specific widget for splash and avoids any collision with OpenGL

stuff done by emulator
This commit is contained in:
LittleWhite 2015-08-28 17:41:03 +02:00
parent 5d89e31cf8
commit 679c1e38b6
3 changed files with 61 additions and 36 deletions

View file

@ -82,21 +82,10 @@ class GGLWidgetInternal : public QGLWidget
{ {
public: public:
GGLWidgetInternal(QGLFormat fmt, GRenderWindow* parent) GGLWidgetInternal(QGLFormat fmt, GRenderWindow* parent)
: QGLWidget(fmt, parent), splash(":/data/citra.svg"), parent(parent) { : QGLWidget(fmt, parent), parent(parent) {
} }
void paintEvent(QPaintEvent* ev) override { void paintEvent(QPaintEvent* ev) override {
if (do_painting) {
QPainter painter(this);
int scaled_width = width()/3;
int scaled_height = width()/3;
painter.drawImage(QRect(width()/2-scaled_width/2,
height()/2-scaled_height/2,
scaled_width,
scaled_height), splash);
}
} }
void resizeEvent(QResizeEvent* ev) override { void resizeEvent(QResizeEvent* ev) override {
@ -104,13 +93,31 @@ public:
parent->OnFramebufferSizeChanged(); parent->OnFramebufferSizeChanged();
} }
void DisablePainting() { do_painting = false; }
void EnablePainting() { do_painting = true; }
private: private:
GRenderWindow* parent; GRenderWindow* parent;
};
class GSplashWidgetInternal : public QWidget
{
public:
GSplashWidgetInternal(QWidget* parent)
: QWidget(parent), splash(":/data/citra.svg") {
}
void paintEvent(QPaintEvent* ev) override {
QPainter painter(this);
int scaled_width = width()/3;
int scaled_height = width()/3;
painter.drawImage(QRect(width()/2-scaled_width/2,
height()/2-scaled_height/2,
scaled_width,
scaled_height), splash);
}
private:
QImage splash; QImage splash;
bool do_painting;
}; };
GRenderWindow::GRenderWindow(QWidget* parent, EmuThread* emu_thread) : GRenderWindow::GRenderWindow(QWidget* parent, EmuThread* emu_thread) :
@ -125,22 +132,26 @@ GRenderWindow::GRenderWindow(QWidget* parent, EmuThread* emu_thread) :
// TODO: One of these flags might be interesting: WA_OpaquePaintEvent, WA_NoBackground, WA_DontShowOnScreen, WA_DeleteOnClose // TODO: One of these flags might be interesting: WA_OpaquePaintEvent, WA_NoBackground, WA_DontShowOnScreen, WA_DeleteOnClose
QGLFormat fmt; QGLFormat fmt;
fmt.setVersion(3,2); fmt.setVersion(3,2);
//fmt.setProfile(QGLFormat::CoreProfile); fmt.setProfile(QGLFormat::CoreProfile);
// Requests a forward-compatible context, which is required to get a 3.2+ context on OS X // Requests a forward-compatible context, which is required to get a 3.2+ context on OS X
fmt.setOption(QGL::NoDeprecatedFunctions); fmt.setOption(QGL::NoDeprecatedFunctions);
child = new GGLWidgetInternal(fmt, this); render_widget = new GGLWidgetInternal(fmt, this);
QBoxLayout* layout = new QHBoxLayout(this); splash_widget = new GSplashWidgetInternal(this);
layout = new QHBoxLayout(this);
resize(VideoCore::kScreenTopWidth, VideoCore::kScreenTopHeight + VideoCore::kScreenBottomHeight); resize(VideoCore::kScreenTopWidth, VideoCore::kScreenTopHeight + VideoCore::kScreenBottomHeight);
layout->addWidget(child); layout->addWidget(splash_widget);
layout->setMargin(0); layout->setMargin(0);
setLayout(layout); setLayout(layout);
active_widget = splash_widget;
render_widget->hide(); // By default, widget are shown. Hide the inactive one for the moment.
OnMinimalClientAreaChangeRequest(GetActiveConfig().min_client_area_size); OnMinimalClientAreaChangeRequest(GetActiveConfig().min_client_area_size);
OnFramebufferSizeChanged(); OnFramebufferSizeChanged();
NotifyClientAreaSizeChanged(std::pair<unsigned,unsigned>(child->width(), child->height())); NotifyClientAreaSizeChanged(std::pair<unsigned,unsigned>(active_widget->width(), active_widget->height()));
BackupGeometry(); BackupGeometry();
@ -156,7 +167,7 @@ void GRenderWindow::moveContext()
#if QT_VERSION > QT_VERSION_CHECK(5, 0, 0) #if QT_VERSION > QT_VERSION_CHECK(5, 0, 0)
// If the thread started running, move the GL Context to the new thread. Otherwise, move it back. // If the thread started running, move the GL Context to the new thread. Otherwise, move it back.
auto thread = (QThread::currentThread() == qApp->thread() && emu_thread != nullptr) ? emu_thread : qApp->thread(); auto thread = (QThread::currentThread() == qApp->thread() && emu_thread != nullptr) ? emu_thread : qApp->thread();
child->context()->moveToThread(thread); render_widget->context()->moveToThread(thread);
#endif #endif
} }
@ -167,19 +178,19 @@ void GRenderWindow::SwapBuffers()
// since the last time you called swapBuffers. This presumably means something if you're using // since the last time you called swapBuffers. This presumably means something if you're using
// QGLWidget the "regular" way, but in our multi-threaded use case is harmless since we never // QGLWidget the "regular" way, but in our multi-threaded use case is harmless since we never
// call doneCurrent in this thread. // call doneCurrent in this thread.
child->makeCurrent(); render_widget->makeCurrent();
#endif #endif
child->swapBuffers(); render_widget->swapBuffers();
} }
void GRenderWindow::MakeCurrent() void GRenderWindow::MakeCurrent()
{ {
child->makeCurrent(); render_widget->makeCurrent();
} }
void GRenderWindow::DoneCurrent() void GRenderWindow::DoneCurrent()
{ {
child->doneCurrent(); render_widget->doneCurrent();
} }
void GRenderWindow::PollEvents() { void GRenderWindow::PollEvents() {
@ -197,11 +208,11 @@ void GRenderWindow::OnFramebufferSizeChanged()
// windowHandle() might not be accessible until the window is displayed to screen. // windowHandle() might not be accessible until the window is displayed to screen.
auto pixel_ratio = windowHandle() ? (windowHandle()->screen()->devicePixelRatio()) : 1.0; auto pixel_ratio = windowHandle() ? (windowHandle()->screen()->devicePixelRatio()) : 1.0;
unsigned width = child->QPaintDevice::width() * pixel_ratio; unsigned width = active_widget->QPaintDevice::width() * pixel_ratio;
unsigned height = child->QPaintDevice::height() * pixel_ratio; unsigned height = active_widget->QPaintDevice::height() * pixel_ratio;
#else #else
unsigned width = child->QPaintDevice::width(); unsigned width = active_widget->QPaintDevice::width();
unsigned height = child->QPaintDevice::height(); unsigned height = active_widget->QPaintDevice::height();
#endif #endif
NotifyFramebufferLayoutChanged(EmuWindow::FramebufferLayout::DefaultScreenLayout(width, height)); NotifyFramebufferLayoutChanged(EmuWindow::FramebufferLayout::DefaultScreenLayout(width, height));
@ -284,10 +295,22 @@ void GRenderWindow::OnMinimalClientAreaChangeRequest(const std::pair<unsigned,un
void GRenderWindow::OnEmulationStarting(EmuThread* emu_thread) { void GRenderWindow::OnEmulationStarting(EmuThread* emu_thread) {
this->emu_thread = emu_thread; this->emu_thread = emu_thread;
child->DisablePainting();
// Swaps to put in front the render widget
active_widget=render_widget;
layout->removeWidget(splash_widget);
layout->addWidget(render_widget);
render_widget->show();
splash_widget->hide();
} }
void GRenderWindow::OnEmulationStopping() { void GRenderWindow::OnEmulationStopping() {
emu_thread = nullptr; emu_thread = nullptr;
child->EnablePainting();
// Swaps back the splash widget
active_widget=splash_widget;
layout->removeWidget(render_widget);
layout->addWidget(splash_widget);
splash_widget->show();
render_widget->hide();
} }

View file

@ -12,10 +12,10 @@
#include "common/emu_window.h" #include "common/emu_window.h"
#include "common/thread.h" #include "common/thread.h"
class QBoxLayout;
class QKeyEvent; class QKeyEvent;
class QScreen; class QScreen;
class GGLWidgetInternal;
class GMainWindow; class GMainWindow;
class GRenderWindow; class GRenderWindow;
@ -133,7 +133,11 @@ public slots:
private: private:
void OnMinimalClientAreaChangeRequest(const std::pair<unsigned,unsigned>& minimal_size) override; void OnMinimalClientAreaChangeRequest(const std::pair<unsigned,unsigned>& minimal_size) override;
GGLWidgetInternal* child; QBoxLayout* layout;
QWidget* active_widget;
QGLWidget* render_widget;
QWidget* splash_widget;
QByteArray geometry; QByteArray geometry;

View file

@ -59,7 +59,6 @@ GMainWindow::GMainWindow() : emu_thread(nullptr)
statusBar()->hide(); statusBar()->hide();
render_window = new GRenderWindow(this, emu_thread.get()); render_window = new GRenderWindow(this, emu_thread.get());
render_window->hide();
profilerWidget = new ProfilerWidget(this); profilerWidget = new ProfilerWidget(this);
addDockWidget(Qt::BottomDockWidgetArea, profilerWidget); addDockWidget(Qt::BottomDockWidgetArea, profilerWidget);
@ -291,7 +290,6 @@ void GMainWindow::ShutdownGame() {
ui.action_Start->setText(tr("Start")); ui.action_Start->setText(tr("Start"));
ui.action_Pause->setEnabled(false); ui.action_Pause->setEnabled(false);
ui.action_Stop->setEnabled(false); ui.action_Stop->setEnabled(false);
render_window->hide();
} }
void GMainWindow::StoreRecentFile(const QString& filename) void GMainWindow::StoreRecentFile(const QString& filename)