mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-07 14:45:41 +12:00
Switch to std::function for resize callback
This commit is contained in:
parent
65d7b9d886
commit
c1fe8e9cd1
3 changed files with 10 additions and 4 deletions
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
#include <QWidget>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
#include "gl/context.h"
|
||||
|
@ -10,7 +11,9 @@ class ScreenWidget : public QWidget {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ScreenWidget(QWidget* parent = nullptr);
|
||||
using ResizeCallback = std::function<void(u32, u32)>;
|
||||
|
||||
ScreenWidget(ResizeCallback resizeCallback, QWidget* parent = nullptr);
|
||||
void resizeEvent(QResizeEvent* event) override;
|
||||
// Called by the emulator thread for resizing the actual GL surface, since the emulator thread owns the GL context
|
||||
void resizeSurface(u32 width, u32 height);
|
||||
|
@ -28,6 +31,8 @@ class ScreenWidget : public QWidget {
|
|||
|
||||
private:
|
||||
std::unique_ptr<GL::Context> glContext = nullptr;
|
||||
ResizeCallback resizeCallback;
|
||||
|
||||
bool createGLContext();
|
||||
|
||||
qreal devicePixelRatioFromScreen() const;
|
||||
|
|
|
@ -17,7 +17,8 @@ MainWindow::MainWindow(QApplication* app, QWidget* parent) : QMainWindow(parent)
|
|||
setAcceptDrops(true);
|
||||
resize(800, 240 * 4);
|
||||
|
||||
screen = new ScreenWidget(this);
|
||||
// We pass a callback to the screen widget that will be triggered every time we resize the screen
|
||||
screen = new ScreenWidget([this](u32 width, u32 height) { handleScreenResize(width, height); }, this);
|
||||
setCentralWidget(screen);
|
||||
|
||||
screen->show();
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
// and https://github.com/melonDS-emu/melonDS/blob/master/src/frontend/qt_sdl/main.cpp
|
||||
|
||||
#ifdef PANDA3DS_ENABLE_OPENGL
|
||||
ScreenWidget::ScreenWidget(QWidget* parent) : QWidget(parent) {
|
||||
ScreenWidget::ScreenWidget(ResizeCallback resizeCallback, QWidget* parent) : QWidget(parent), resizeCallback(resizeCallback) {
|
||||
// Create a native window for use with our graphics API of choice
|
||||
resize(800, 240 * 4);
|
||||
|
||||
|
@ -49,7 +49,7 @@ void ScreenWidget::resizeEvent(QResizeEvent* event) {
|
|||
}
|
||||
|
||||
// This will call take care of calling resizeSurface from the emulator thread
|
||||
static_cast<MainWindow*>(parentWidget())->handleScreenResize(surfaceWidth, surfaceHeight);
|
||||
resizeCallback(surfaceWidth, surfaceHeight);
|
||||
}
|
||||
|
||||
// Note: This will run on the emulator thread, we don't want any Qt calls happening there.
|
||||
|
|
Loading…
Add table
Reference in a new issue