From ffd5de60aa978a29c10c3411640c4787861e6195 Mon Sep 17 00:00:00 2001 From: mjbudd77 Date: Sun, 14 Mar 2021 14:02:10 -0400 Subject: [PATCH] Added logic to Qt GUI to allow for the shape of the viewport cursor to be selectable between an arrow, cross, or blank. Also added a viewport cursor visibility configuration parameter. Cursor visibility and shape can be set via the video config option window. --- src/drivers/Qt/ConsoleVideoConf.cpp | 91 +++++++++++++++++++++++++++++ src/drivers/Qt/ConsoleVideoConf.h | 4 ++ src/drivers/Qt/ConsoleWindow.cpp | 56 ++++++++++++++++++ src/drivers/Qt/ConsoleWindow.h | 3 + src/drivers/Qt/config.cpp | 2 + 5 files changed, 156 insertions(+) diff --git a/src/drivers/Qt/ConsoleVideoConf.cpp b/src/drivers/Qt/ConsoleVideoConf.cpp index bf3dc97c..d984e793 100644 --- a/src/drivers/Qt/ConsoleVideoConf.cpp +++ b/src/drivers/Qt/ConsoleVideoConf.cpp @@ -363,6 +363,30 @@ ConsoleVideoConfDialog_t::ConsoleVideoConfDialog_t(QWidget *parent) grid->addWidget( winSizeReadout, 0, 1, Qt::AlignLeft); grid->addWidget( vpSizeReadout, 1, 1, Qt::AlignLeft); + gbox = new QGroupBox( tr("Viewport Cursor") ); + grid = new QGridLayout(); + cursorSelect = new QComboBox(); + + cursorSelect->addItem( tr("Arrow"), 0 ); + cursorSelect->addItem( tr("Cross"), 1 ); + cursorSelect->addItem( tr("Blank"), 2 ); + + setComboBoxFromProperty( cursorSelect, "SDL.CursorType" ); + + connect(cursorSelect, SIGNAL(currentIndexChanged(int)), this, SLOT(cursorShapeChanged(int)) ); + + vbox2->addWidget( gbox, 1 ); + gbox->setLayout(grid); + + grid->addWidget( new QLabel( tr("Shape:") ), 0, 0, Qt::AlignLeft); + grid->addWidget( cursorSelect, 0, 1, Qt::AlignLeft); + + cursorVisCbx = new QCheckBox( tr("Visible") ); + setCheckBoxFromProperty( cursorVisCbx, "SDL.CursorVis" ); + grid->addWidget( cursorVisCbx, 1, 0, 2, 1, Qt::AlignLeft); + + connect(cursorVisCbx, SIGNAL(stateChanged(int)), this, SLOT(cursorVisChanged(int)) ); + vbox2->addStretch( 5 ); setLayout( main_vbox ); @@ -724,6 +748,73 @@ void ConsoleVideoConfDialog_t::regionChanged(int index) } } //---------------------------------------------------- +void ConsoleVideoConfDialog_t::cursorShapeChanged(int index) +{ + int cursorSel; + Qt::CursorShape s; + //printf("Scaler: %i : %i \n", index, scalerSelect->itemData(index).toInt() ); + + cursorSel = cursorSelect->itemData(index).toInt(); + + switch ( cursorSel ) + { + case 2: + s = Qt::BlankCursor; + break; + case 1: + s = Qt::CrossCursor; + break; + default: + case 0: + s = Qt::ArrowCursor; + cursorSel = 0; + break; + } + consoleWindow->setViewerCursor( s ); + + g_config->setOption ("SDL.CursorType", cursorSel); + + g_config->save (); +} +//---------------------------------------------------- +void ConsoleVideoConfDialog_t::cursorVisChanged( int value ) +{ + int vis; + + vis = (value != Qt::Unchecked); + + //printf("Value:%i \n", value ); + g_config->setOption("SDL.CursorVis", vis ); + g_config->save (); + + if ( vis ) + { + int opt; + Qt::CursorShape s; + + g_config->getOption("SDL.CursorType", &opt ); + + switch ( opt ) + { + case 2: + s = Qt::BlankCursor; + break; + case 1: + s = Qt::CrossCursor; + break; + default: + case 0: + s = Qt::ArrowCursor; + break; + } + consoleWindow->setViewerCursor( s ); + } + else + { + consoleWindow->setViewerCursor( Qt::BlankCursor ); + } +} +//---------------------------------------------------- QSize ConsoleVideoConfDialog_t::calcNewScreenSize(void) { QSize out( GL_NES_WIDTH, GL_NES_HEIGHT ); diff --git a/src/drivers/Qt/ConsoleVideoConf.h b/src/drivers/Qt/ConsoleVideoConf.h index 137fa73a..1dcd078b 100644 --- a/src/drivers/Qt/ConsoleVideoConf.h +++ b/src/drivers/Qt/ConsoleVideoConf.h @@ -33,6 +33,7 @@ class ConsoleVideoConfDialog_t : public QDialog QComboBox *driverSelect; QComboBox *scalerSelect; QComboBox *regionSelect; + QComboBox *cursorSelect; QCheckBox *autoRegion; QCheckBox *gl_LF_chkBox; QCheckBox *new_PPU_ena; @@ -42,6 +43,7 @@ class ConsoleVideoConfDialog_t : public QDialog QCheckBox *showFPS_cbx; QCheckBox *autoScaleCbx; QCheckBox *sqrPixCbx; + QCheckBox *cursorVisCbx; QDoubleSpinBox *xScaleBox; QDoubleSpinBox *yScaleBox; QLabel *xScaleLabel; @@ -78,6 +80,8 @@ class ConsoleVideoConfDialog_t : public QDialog void regionChanged(int index); void driverChanged(int index); void scalerChanged(int index); + void cursorShapeChanged(int index); + void cursorVisChanged(int value); void applyChanges( void ); void ntscStartScanLineChanged(const QString &); void ntscEndScanLineChanged(const QString &); diff --git a/src/drivers/Qt/ConsoleWindow.cpp b/src/drivers/Qt/ConsoleWindow.cpp index 984fdb43..fe5b3e51 100644 --- a/src/drivers/Qt/ConsoleWindow.cpp +++ b/src/drivers/Qt/ConsoleWindow.cpp @@ -90,6 +90,7 @@ consoleWin_t::consoleWin_t(QWidget *parent) int opt, xWinSize = 256, yWinSize = 240; int use_SDL_video = false; int setFullScreen = false; + int cursorVis = true; //QString libpath = QLibraryInfo::location(QLibraryInfo::PluginsPath); //printf("LibPath: '%s'\n", libpath.toStdString().c_str() ); @@ -190,6 +191,34 @@ consoleWin_t::consoleWin_t(QWidget *parent) updateCounter = 0; recentRomMenuReset = false; + + // Viewport Cursor Type and Visibility + g_config->getOption("SDL.CursorVis", &cursorVis ); + + if ( cursorVis ) + { + int cursorType; + + g_config->getOption("SDL.CursorType", &cursorType ); + + switch ( cursorType ) + { + case 2: + setViewerCursor( Qt::BlankCursor ); + break; + case 1: + setViewerCursor( Qt::CrossCursor ); + break; + default: + case 0: + setViewerCursor( Qt::ArrowCursor ); + break; + } + } + else + { + setViewerCursor( Qt::BlankCursor ); + } } consoleWin_t::~consoleWin_t(void) @@ -323,6 +352,33 @@ QSize consoleWin_t::calcRequiredSize(void) return out; } +void consoleWin_t::setViewerCursor( Qt::CursorShape s ) +{ + if ( viewport_GL ) + { + viewport_GL->setCursor(s); + } + else if ( viewport_SDL ) + { + viewport_SDL->setCursor(s); + } +} + +Qt::CursorShape consoleWin_t::getViewerCursor(void) +{ + Qt::CursorShape s; + + if ( viewport_GL ) + { + s = viewport_GL->cursor().shape(); + } + else if ( viewport_SDL ) + { + s = viewport_SDL->cursor().shape(); + } + return s; +} + void consoleWin_t::resizeEvent(QResizeEvent *event) { if ( firstResize ) diff --git a/src/drivers/Qt/ConsoleWindow.h b/src/drivers/Qt/ConsoleWindow.h index 6d17ac45..26ef4ce7 100644 --- a/src/drivers/Qt/ConsoleWindow.h +++ b/src/drivers/Qt/ConsoleWindow.h @@ -19,6 +19,7 @@ #include #include #include +#include #include "Qt/ConsoleViewerGL.h" #include "Qt/ConsoleViewerSDL.h" @@ -118,6 +119,8 @@ class consoleWin_t : public QMainWindow QSize calcRequiredSize(void); + void setViewerCursor( Qt::CursorShape s ); + Qt::CursorShape getViewerCursor(void); protected: consoleMenuBar *menubar; diff --git a/src/drivers/Qt/config.cpp b/src/drivers/Qt/config.cpp index 884dc514..10645443 100644 --- a/src/drivers/Qt/config.cpp +++ b/src/drivers/Qt/config.cpp @@ -270,6 +270,8 @@ InitConfig() config->addOption("special", "SDL.SpecialFilter", 0); config->addOption("showfps", "SDL.ShowFPS", 0); config->addOption("togglemenu", "SDL.ToggleMenu", 0); + config->addOption("cursorType", "SDL.CursorType", 0); + config->addOption("cursorVis" , "SDL.CursorVis", 1); // OpenGL options config->addOption("opengl", "SDL.OpenGL", 1);