mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-14 18:19:48 +12:00
Qt: Allocate screen on heap for setCentralWidget
This commit is contained in:
parent
2e5ab26b46
commit
020a29b577
3 changed files with 15 additions and 14 deletions
|
@ -101,7 +101,7 @@ class MainWindow : public QMainWindow {
|
||||||
|
|
||||||
QMenuBar* menuBar = nullptr;
|
QMenuBar* menuBar = nullptr;
|
||||||
InputMappings keyboardMappings;
|
InputMappings keyboardMappings;
|
||||||
ScreenWidget screen;
|
ScreenWidget* screen;
|
||||||
AboutWindow* aboutWindow;
|
AboutWindow* aboutWindow;
|
||||||
ConfigWindow* configWindow;
|
ConfigWindow* configWindow;
|
||||||
CheatsWindow* cheatsEditor;
|
CheatsWindow* cheatsEditor;
|
||||||
|
|
|
@ -11,14 +11,16 @@
|
||||||
#include "input_mappings.hpp"
|
#include "input_mappings.hpp"
|
||||||
#include "services/dsp.hpp"
|
#include "services/dsp.hpp"
|
||||||
|
|
||||||
MainWindow::MainWindow(QApplication* app, QWidget* parent) : QMainWindow(parent), keyboardMappings(InputMappings::defaultKeyboardMappings()), screen(this) {
|
MainWindow::MainWindow(QApplication* app, QWidget* parent) : QMainWindow(parent), keyboardMappings(InputMappings::defaultKeyboardMappings()) {
|
||||||
setWindowTitle("Alber");
|
setWindowTitle("Alber");
|
||||||
// Enable drop events for loading ROMs
|
// Enable drop events for loading ROMs
|
||||||
setAcceptDrops(true);
|
setAcceptDrops(true);
|
||||||
resize(800, 240 * 4);
|
resize(800, 240 * 4);
|
||||||
setCentralWidget(&screen);
|
|
||||||
screen.show();
|
|
||||||
|
|
||||||
|
screen = new ScreenWidget(this);
|
||||||
|
setCentralWidget(screen);
|
||||||
|
|
||||||
|
screen->show();
|
||||||
appRunning = true;
|
appRunning = true;
|
||||||
|
|
||||||
// Set our menu bar up
|
// Set our menu bar up
|
||||||
|
@ -70,7 +72,7 @@ MainWindow::MainWindow(QApplication* app, QWidget* parent) : QMainWindow(parent)
|
||||||
connect(aboutAction, &QAction::triggered, this, &MainWindow::showAboutMenu);
|
connect(aboutAction, &QAction::triggered, this, &MainWindow::showAboutMenu);
|
||||||
|
|
||||||
emu = new Emulator();
|
emu = new Emulator();
|
||||||
emu->setOutputSize(screen.surfaceWidth, screen.surfaceHeight);
|
emu->setOutputSize(screen->surfaceWidth, screen->surfaceHeight);
|
||||||
|
|
||||||
// Set up misc objects
|
// Set up misc objects
|
||||||
aboutWindow = new AboutWindow(nullptr);
|
aboutWindow = new AboutWindow(nullptr);
|
||||||
|
@ -102,7 +104,7 @@ MainWindow::MainWindow(QApplication* app, QWidget* parent) : QMainWindow(parent)
|
||||||
|
|
||||||
if (usingGL) {
|
if (usingGL) {
|
||||||
// Make GL context current for this thread, enable VSync
|
// Make GL context current for this thread, enable VSync
|
||||||
GL::Context* glContext = screen.getGLContext();
|
GL::Context* glContext = screen->getGLContext();
|
||||||
glContext->MakeCurrent();
|
glContext->MakeCurrent();
|
||||||
glContext->SetSwapInterval(emu->getConfig().vsyncEnabled ? 1 : 0);
|
glContext->SetSwapInterval(emu->getConfig().vsyncEnabled ? 1 : 0);
|
||||||
|
|
||||||
|
@ -146,13 +148,13 @@ void MainWindow::emuThreadMainLoop() {
|
||||||
|
|
||||||
// Unbind GL context if we're using GL, otherwise some setups seem to be unable to join this thread
|
// Unbind GL context if we're using GL, otherwise some setups seem to be unable to join this thread
|
||||||
if (usingGL) {
|
if (usingGL) {
|
||||||
screen.getGLContext()->DoneCurrent();
|
screen->getGLContext()->DoneCurrent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::swapEmuBuffer() {
|
void MainWindow::swapEmuBuffer() {
|
||||||
if (usingGL) {
|
if (usingGL) {
|
||||||
screen.getGLContext()->SwapBuffers();
|
screen->getGLContext()->SwapBuffers();
|
||||||
} else {
|
} else {
|
||||||
Helpers::panic("[Qt] Don't know how to swap buffers for the current rendering backend :(");
|
Helpers::panic("[Qt] Don't know how to swap buffers for the current rendering backend :(");
|
||||||
}
|
}
|
||||||
|
@ -367,7 +369,7 @@ void MainWindow::dispatchMessage(const EmulatorMessage& message) {
|
||||||
const u32 height = message.screenSize.height;
|
const u32 height = message.screenSize.height;
|
||||||
|
|
||||||
emu->setOutputSize(width, height);
|
emu->setOutputSize(width, height);
|
||||||
screen.resizeSurface(width, height);
|
screen->resizeSurface(width, height);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -433,13 +435,13 @@ void MainWindow::keyReleaseEvent(QKeyEvent* event) {
|
||||||
void MainWindow::mousePressEvent(QMouseEvent* event) {
|
void MainWindow::mousePressEvent(QMouseEvent* event) {
|
||||||
if (event->button() == Qt::MouseButton::LeftButton) {
|
if (event->button() == Qt::MouseButton::LeftButton) {
|
||||||
const QPointF clickPos = event->globalPosition();
|
const QPointF clickPos = event->globalPosition();
|
||||||
const QPointF widgetPos = screen.mapFromGlobal(clickPos);
|
const QPointF widgetPos = screen->mapFromGlobal(clickPos);
|
||||||
|
|
||||||
// Press is inside the screen area
|
// Press is inside the screen area
|
||||||
if (widgetPos.x() >= 0 && widgetPos.x() < screen.width() && widgetPos.y() >= 0 && widgetPos.y() < screen.height()) {
|
if (widgetPos.x() >= 0 && widgetPos.x() < screen->width() && widgetPos.y() >= 0 && widgetPos.y() < screen->height()) {
|
||||||
// Go from widget positions to [0, 400) for x and [0, 480) for y
|
// Go from widget positions to [0, 400) for x and [0, 480) for y
|
||||||
uint x = (uint)std::round(widgetPos.x() / screen.width() * 400.f);
|
uint x = (uint)std::round(widgetPos.x() / screen->width() * 400.f);
|
||||||
uint y = (uint)std::round(widgetPos.y() / screen.height() * 480.f);
|
uint y = (uint)std::round(widgetPos.y() / screen->height() * 480.f);
|
||||||
|
|
||||||
// Check if touch falls in the touch screen area
|
// Check if touch falls in the touch screen area
|
||||||
if (y >= 240 && y <= 480 && x >= 40 && x < 40 + 320) {
|
if (y >= 240 && y <= 480 && x >= 40 && x < 40 + 320) {
|
||||||
|
|
|
@ -39,7 +39,6 @@ ScreenWidget::ScreenWidget(QWidget* parent) : QWidget(parent) {
|
||||||
void ScreenWidget::resizeEvent(QResizeEvent* event) {
|
void ScreenWidget::resizeEvent(QResizeEvent* event) {
|
||||||
previousWidth = surfaceWidth;
|
previousWidth = surfaceWidth;
|
||||||
previousHeight = surfaceHeight;
|
previousHeight = surfaceHeight;
|
||||||
|
|
||||||
QWidget::resizeEvent(event);
|
QWidget::resizeEvent(event);
|
||||||
|
|
||||||
// Update surfaceWidth/surfaceHeight following the resize
|
// Update surfaceWidth/surfaceHeight following the resize
|
||||||
|
|
Loading…
Add table
Reference in a new issue