# HG changeset patch # User unc0rr # Date 1553285172 -3600 # Node ID 57293f34ce592341012ef68f00472249da4e4a65 # Parent 40809bfd44af70eb4137e439d8451f5947f8c48d Detect and handle resize diff -r 40809bfd44af -r 57293f34ce59 qmlfrontend/game_view.cpp --- a/qmlfrontend/game_view.cpp Fri Mar 22 22:26:41 2019 +0300 +++ b/qmlfrontend/game_view.cpp Fri Mar 22 21:06:12 2019 +0100 @@ -58,11 +58,13 @@ &GameViewRenderer::paint, Qt::DirectConnection); } - if (m_windowChanged) { - QSize windowSize = window()->size(); - m_renderer->setViewportSize(windowSize * window()->devicePixelRatio()); - m_centerX = windowSize.width() / 2; - m_centerY = windowSize.height() / 2; + if (m_windowChanged || (m_viewportSize != window()->size())) { + m_windowChanged = false; + + if (m_engineInstance) + m_engineInstance->setOpenGLContext(window()->openglContext()); + + m_viewportSize = window()->size(); } // QPoint mousePos = mapFromGlobal(QCursor::pos()).toPoint(); @@ -80,10 +82,6 @@ void GameViewRenderer::tick(quint32 delta) { m_delta = delta; } -void GameViewRenderer::setViewportSize(const QSize& size) { - // flibResizeWindow(size.width(), size.height()); -} - void GameViewRenderer::setEngineInstance(EngineInstance* engineInstance) { m_engineInstance = engineInstance; } @@ -98,3 +96,8 @@ // m_window->resetOpenGLState(); } + +void GameViewRenderer::onViewportSizeChanged(QQuickWindow* window) { + if (m_engineInstance) + m_engineInstance->setOpenGLContext(window->openglContext()); +} diff -r 40809bfd44af -r 57293f34ce59 qmlfrontend/game_view.h --- a/qmlfrontend/game_view.h Fri Mar 22 22:26:41 2019 +0300 +++ b/qmlfrontend/game_view.h Fri Mar 22 21:06:12 2019 +0100 @@ -13,15 +13,15 @@ class GameViewRenderer : public QObject, protected QOpenGLFunctions { Q_OBJECT public: - GameViewRenderer(); - ~GameViewRenderer(); + explicit GameViewRenderer(); + ~GameViewRenderer() override; void tick(quint32 delta); - void setViewportSize(const QSize& size); void setEngineInstance(EngineInstance* engineInstance); public slots: void paint(); + void onViewportSizeChanged(QQuickWindow* window); private: quint32 m_delta; @@ -35,7 +35,7 @@ setEngineInstance NOTIFY engineInstanceChanged) public: - GameView(); + explicit GameView(); Q_INVOKABLE void tick(quint32 delta); @@ -56,9 +56,8 @@ quint32 m_delta; QScopedPointer m_renderer; bool m_windowChanged; - qint32 m_centerX; - qint32 m_centerY; QPointer m_engineInstance; + QSize m_viewportSize; }; #endif // GAMEVIEW_H