Resizing window on Qt ()

* 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:
wheremyfoodat 2024-07-23 20:13:14 +00:00 committed by GitHub
parent 7aa41d0b35
commit c319e59545
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 83 additions and 14 deletions

View file

@ -50,6 +50,7 @@ class MainWindow : public QMainWindow {
PressTouchscreen,
ReleaseTouchscreen,
ReloadUbershader,
SetScreenSize,
};
// Tagged union representing our message queue messages
@ -81,6 +82,11 @@ class MainWindow : public QMainWindow {
u16 x;
u16 y;
} touchscreen;
struct {
u32 width;
u32 height;
} screenSize;
};
};
@ -95,7 +101,7 @@ class MainWindow : public QMainWindow {
QMenuBar* menuBar = nullptr;
InputMappings keyboardMappings;
ScreenWidget screen;
ScreenWidget* screen;
AboutWindow* aboutWindow;
ConfigWindow* configWindow;
CheatsWindow* cheatsEditor;
@ -141,4 +147,6 @@ class MainWindow : public QMainWindow {
void loadLuaScript(const std::string& code);
void reloadShader(const std::string& shader);
void editCheat(u32 handle, const std::vector<uint8_t>& cheat, const std::function<void(u32)>& callback);
void handleScreenResize(u32 width, u32 height);
};

View file

@ -1,5 +1,6 @@
#pragma once
#include <QWidget>
#include <functional>
#include <memory>
#include "gl/context.h"
@ -10,15 +11,28 @@ 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);
GL::Context* getGLContext() { return glContext.get(); }
// Dimensions of our output surface
u32 surfaceWidth = 0;
u32 surfaceHeight = 0;
WindowInfo windowInfo;
// Cached "previous" dimensions, used when resizing our window
u32 previousWidth = 0;
u32 previousHeight = 0;
private:
std::unique_ptr<GL::Context> glContext = nullptr;
ResizeCallback resizeCallback;
bool createGLContext();
qreal devicePixelRatioFromScreen() const;