Resizing window on Qt (#556)
* Qt: Add screen resize * Qt: Allocate screen on heap for setCentralWidget * Fix header inclusion order * Switch to std::function for resize callback * rdeepfried
This commit is contained in:
@@ -18,7 +18,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);
|
||||
|
||||
@@ -35,6 +35,30 @@ ScreenWidget::ScreenWidget(QWidget* parent) : QWidget(parent) {
|
||||
}
|
||||
}
|
||||
|
||||
void ScreenWidget::resizeEvent(QResizeEvent* event) {
|
||||
previousWidth = surfaceWidth;
|
||||
previousHeight = surfaceHeight;
|
||||
QWidget::resizeEvent(event);
|
||||
|
||||
// Update surfaceWidth/surfaceHeight following the resize
|
||||
std::optional<WindowInfo> windowInfo = getWindowInfo();
|
||||
if (windowInfo) {
|
||||
this->windowInfo = *windowInfo;
|
||||
}
|
||||
|
||||
// This will call take care of calling resizeSurface from the emulator thread
|
||||
resizeCallback(surfaceWidth, surfaceHeight);
|
||||
}
|
||||
|
||||
// Note: This will run on the emulator thread, we don't want any Qt calls happening there.
|
||||
void ScreenWidget::resizeSurface(u32 width, u32 height) {
|
||||
if (previousWidth != width || previousHeight != height) {
|
||||
if (glContext) {
|
||||
glContext->ResizeSurface(width, height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool ScreenWidget::createGLContext() {
|
||||
// List of GL context versions we will try. Anything 4.1+ is good
|
||||
static constexpr std::array<GL::Context::Version, 6> versionsToTry = {
|
||||
@@ -45,6 +69,8 @@ bool ScreenWidget::createGLContext() {
|
||||
|
||||
std::optional<WindowInfo> windowInfo = getWindowInfo();
|
||||
if (windowInfo.has_value()) {
|
||||
this->windowInfo = *windowInfo;
|
||||
|
||||
glContext = GL::Context::Create(*getWindowInfo(), versionsToTry);
|
||||
glContext->DoneCurrent();
|
||||
}
|
||||
@@ -110,4 +136,4 @@ std::optional<WindowInfo> ScreenWidget::getWindowInfo() {
|
||||
|
||||
return wi;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user