diff --git a/src/drivers/Qt/ConsoleViewerGL.cpp b/src/drivers/Qt/ConsoleViewerGL.cpp index cebf9fe2..3cf9b3fa 100644 --- a/src/drivers/Qt/ConsoleViewerGL.cpp +++ b/src/drivers/Qt/ConsoleViewerGL.cpp @@ -30,6 +30,7 @@ #include #include +#include #include #if defined(QT_OPENGL_ES) || defined(QT_OPENGL_ES_2) @@ -72,13 +73,6 @@ ConsoleViewGL_t::ConsoleViewGL_t(QWidget *parent) setMinimumHeight( 224 ); setFocusPolicy(Qt::StrongFocus); - QScreen *screen = QGuiApplication::primaryScreen(); - - if ( screen != NULL ) - { - devPixRatio = screen->devicePixelRatio(); - //printf("Ratio: %f \n", screen->devicePixelRatio() ); - } localBufSize = (4 * GL_NES_WIDTH) * (4 * GL_NES_HEIGHT) * sizeof(uint32_t); localBuf = (uint32_t*)malloc( localBufSize ); @@ -116,8 +110,43 @@ ConsoleViewGL_t::~ConsoleViewGL_t(void) } } +void ConsoleViewGL_t::screenChanged( QScreen *screen ) +{ + int w,h; + + devPixRatio = screen->devicePixelRatio(); + + w = (int)(devPixRatio * width() ); + h = (int)(devPixRatio * height() ); + + view_width = w; + view_height = h; + + gui_draw_area_width = w; + gui_draw_area_height = h; + + buildTextures(); + + //printf("GL Ratio: %f %ix%i\n", screen->devicePixelRatio(), w, h ); +} + int ConsoleViewGL_t::init( void ) { + QScreen *screen = NULL; + + if ( window() != NULL ) + { + if ( window()->windowHandle() != NULL ) + { + screen = window()->windowHandle()->screen(); + } + } + + if ( screen != NULL ) + { + devPixRatio = screen->devicePixelRatio(); + printf("GL Ratio: %f \n", screen->devicePixelRatio() ); + } return 0; } diff --git a/src/drivers/Qt/ConsoleViewerGL.h b/src/drivers/Qt/ConsoleViewerGL.h index 42268d3a..002fd4cc 100644 --- a/src/drivers/Qt/ConsoleViewerGL.h +++ b/src/drivers/Qt/ConsoleViewerGL.h @@ -5,6 +5,7 @@ #include +#include #include #include @@ -36,6 +37,8 @@ class ConsoleViewGL_t : public QOpenGLWidget, protected QOpenGLFunctions void getAspectXY( double &x, double &y ); double getAspectRatio(void); + void screenChanged(QScreen *scr); + protected: void initializeGL(void); void resizeGL(int w, int h); diff --git a/src/drivers/Qt/ConsoleWindow.cpp b/src/drivers/Qt/ConsoleWindow.cpp index 38175613..8df52a64 100644 --- a/src/drivers/Qt/ConsoleWindow.cpp +++ b/src/drivers/Qt/ConsoleWindow.cpp @@ -221,6 +221,7 @@ consoleWin_t::consoleWin_t(QWidget *parent) // Create AVI Recording Disk Thread aviDiskThread = new AviRecordDiskThread_t(this); + scrHandlerConnected = false; } consoleWin_t::~consoleWin_t(void) @@ -334,6 +335,46 @@ void consoleWin_t::videoReset(void) return; } +void consoleWin_t::initScreenHandler(void) +{ + if ( !scrHandlerConnected ) + { + QWidget *w; + + w = this->window(); + + // This needs to be scheduled after window creation. + if ( w != NULL) + { + QWindow *hdl = w->windowHandle(); + + if (hdl != NULL) + { + //printf("Connecting to screenChanged Signal\n"); + connect( hdl, SIGNAL(screenChanged(QScreen*)), this, SLOT(winScreenChanged(QScreen*)) ); + scrHandlerConnected = true; + + winScreenChanged( hdl->screen() ); + } + } + } + +} + +void consoleWin_t::winScreenChanged(QScreen *scr) +{ + if ( scr == NULL ) + { + return; + } + + //printf("Screen Changed: %p\n", scr ); + if ( viewport_GL != NULL ) + { + viewport_GL->screenChanged( scr ); + } +} + QSize consoleWin_t::calcRequiredSize(void) { QSize out( GL_NES_WIDTH, GL_NES_HEIGHT ); @@ -644,6 +685,12 @@ void consoleWin_t::dropEvent(QDropEvent *event) } } +void consoleWin_t::showEvent(QShowEvent *event) +{ + //printf("Main Window Show Event\n"); + initScreenHandler(); +} + //--------------------------------------------------------------------------- void consoleWin_t::initHotKeys(void) { diff --git a/src/drivers/Qt/ConsoleWindow.h b/src/drivers/Qt/ConsoleWindow.h index 391d3ec9..beec99a4 100644 --- a/src/drivers/Qt/ConsoleWindow.h +++ b/src/drivers/Qt/ConsoleWindow.h @@ -248,6 +248,7 @@ class consoleWin_t : public QMainWindow bool mainMenuEmuPauseSet; bool mainMenuEmuWasPaused; bool mainMenuPauseWhenActv; + bool scrHandlerConnected; std::list romList; std::vector afActList; @@ -261,11 +262,13 @@ class consoleWin_t : public QMainWindow void keyReleaseEvent(QKeyEvent *event); void dragEnterEvent(QDragEnterEvent *event); void dropEvent(QDropEvent *event); + void showEvent(QShowEvent *event); void syncActionConfig( QAction *act, const char *property ); void showErrorMsgWindow(void); private: void initHotKeys(void); + void initScreenHandler(void); void createMainMenu(void); void buildRecentRomMenu(void); void saveRecentRomMenu(void); @@ -405,6 +408,7 @@ class consoleWin_t : public QMainWindow void wavRecordStart(void); void wavRecordAsStart(void); void wavRecordStop(void); + void winScreenChanged( QScreen *scr ); };