From: Shamus Hammons Date: Sat, 9 Mar 2013 22:48:09 +0000 (-0600) Subject: Fixes for fullscreen mode, initial stab at multiple controller configs X-Git-Tag: 2.1.1~33 X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=virtualjaguar;a=commitdiff_plain;h=94d59c2c8c14b9ac51dffd117ec507418b4d0881 Fixes for fullscreen mode, initial stab at multiple controller configs Who knew that you could attach QActions to the main window? Of course, you'd have to be a complete idiot not to see something so completely and blatantly obvoius! :-P The preceeding was a cheap dig at the kind folks who hang out on #qt on Freenode, who grudgingly provided that little tidbit of information as if it was the most obvious thing in the world. The upshot is that the toolbar is gone from top of the screen in full screen mode now, and that should make lots of people happy. :-) Also, the initial GUI implementation for multiple controller profiles is in. More to follow. --- diff --git a/src/gui/controllertab.cpp b/src/gui/controllertab.cpp index 1af9f45..6050dd7 100644 --- a/src/gui/controllertab.cpp +++ b/src/gui/controllertab.cpp @@ -16,21 +16,42 @@ #include "controllertab.h" #include "controllerwidget.h" +#include "gamepad.h" #include "joystick.h" #include "keygrabber.h" -ControllerTab::ControllerTab(QWidget * parent/*= 0*/): QWidget(parent) +ControllerTab::ControllerTab(QWidget * parent/*= 0*/): QWidget(parent), + label(new QLabel(tr("Controller:"))), + profile(new QComboBox(this)), + redefineAll(new QPushButton(tr("Define All Inputs"))), + controllerWidget(new ControllerWidget(this)) { - controllerWidget = new ControllerWidget(this); - redefineAll = new QPushButton(tr("Define All Inputs")); - QVBoxLayout * layout = new QVBoxLayout; + QHBoxLayout * top = new QHBoxLayout; + layout->addLayout(top); + top->addWidget(label); + top->addWidget(profile, 0, Qt::AlignLeft); layout->addWidget(controllerWidget); - layout->addWidget(redefineAll); + layout->addWidget(redefineAll, 0, Qt::AlignHCenter); +// layout->setFixedWidth(label->width()); +// layout->setSizeConstraint(QLayout::SetFixedSize); +// top->setSizeConstraint(QLayout::SetFixedSize); +//printf("cw width = %i, label width = %i (min=%i, sizehint=%i)\n", controllerWidget->width(), label->width(), label->minimumWidth(), label->sizeHint().width()); + // This is ugly, ugly, ugly. But it works. :-P It's a shame that Qt's + // layout system doesn't seem to allow for a nicer way to handle this. +// profile->setFixedWidth(controllerWidget->sizeHint().width() - label->sizeHint().width()); setLayout(layout); + setFixedWidth(sizeHint().width()); connect(redefineAll, SIGNAL(clicked()), this, SLOT(DefineAllKeys())); + +//this is the default. :-/ need to set it somewhere else i guess... +// profile->setSizeAdjustPolicy(QComboBox::AdjustToContentsOnFirstShow); + profile->addItem(tr("Keyboard")); + + for(int i=0; iaddItem(Gamepad::GetJoystickName(i)); } @@ -39,6 +60,12 @@ ControllerTab::~ControllerTab() } +//QSize ControllerTab::sizeHint(void) const +//{ +// return +//} + + void ControllerTab::DefineAllKeys(void) { // char jagButtonName[21][10] = { "Up", "Down", "Left", "Right", diff --git a/src/gui/controllertab.h b/src/gui/controllertab.h index 011eec2..9b4c525 100644 --- a/src/gui/controllertab.h +++ b/src/gui/controllertab.h @@ -13,11 +13,14 @@ class ControllerTab: public QWidget public: ControllerTab(QWidget * parent = 0); ~ControllerTab(); +// QSize sizeHint(void) const; protected slots: void DefineAllKeys(void); private: + QLabel * label; + QComboBox * profile; QPushButton * redefineAll; public: diff --git a/src/gui/controllerwidget.cpp b/src/gui/controllerwidget.cpp index 0386334..eb91c34 100644 --- a/src/gui/controllerwidget.cpp +++ b/src/gui/controllerwidget.cpp @@ -65,6 +65,8 @@ ControllerWidget::ControllerWidget(QWidget * parent/*= 0*/): QWidget(parent), widgetSize += QSize(4, 4); // We want to know when the mouse is moving over our widget... setMouseTracking(true); +//nope +//setFixedSize(widgetSize); } diff --git a/src/gui/gamepad.cpp b/src/gui/gamepad.cpp index 62a6d7a..8706e17 100644 --- a/src/gui/gamepad.cpp +++ b/src/gui/gamepad.cpp @@ -18,6 +18,7 @@ // Class member initialization /*static*/ int Gamepad::numJoysticks = 0; /*static*/ SDL_Joystick * Gamepad::pad[8]; +/*static*/ const char * Gamepad::padName[8]; /*static*/ int Gamepad::numButtons[8]; /*static*/ int Gamepad::numHats[8]; /*static*/ int Gamepad::numAxes[8]; @@ -50,6 +51,7 @@ void Gamepad::AllocateJoysticks(void) for(int i=0; i= 8) + return NULL; + + return padName[joystickID]; +} + + bool Gamepad::GetState(int joystickID, int buttonID) { uint8_t hatMask[8] = { 1, 2, 4, 8, 16, 32, 64, 128 }; diff --git a/src/gui/gamepad.h b/src/gui/gamepad.h index 43779c1..a7085a4 100644 --- a/src/gui/gamepad.h +++ b/src/gui/gamepad.h @@ -38,6 +38,7 @@ class Gamepad // Class methods... static void AllocateJoysticks(void); static void DeallocateJoysticks(void); + static const char * GetJoystickName(int joystickID); static bool GetState(int joystickID, int buttonID); static int CheckButtonPressed(void); static int GetButtonID(void); @@ -47,6 +48,7 @@ class Gamepad // Support up to 8 gamepads static int numJoysticks; static SDL_Joystick * pad[8]; + static const char * padName[8]; static int numButtons[8]; static int numAxes[8]; static int numHats[8]; diff --git a/src/gui/glwidget.cpp b/src/gui/glwidget.cpp index 2f95918..ead7268 100644 --- a/src/gui/glwidget.cpp +++ b/src/gui/glwidget.cpp @@ -144,20 +144,18 @@ void GLWidget::CreateTextures(void) } -//void GLWidget::HideMouseIfTimedOut(void) void GLWidget::HandleMouseHiding(void) { // Mouse watchdog timer handling. Basically, if the timeout value is - // greater than zero, decrement it. Otherwise, check for zero, if so, - // then hide the mouse and set the hideMouseTimeout value to -1 to - // signal that the mouse has been hidden. + // greater than zero, decrement it. Otherwise, check for zero, if so, then + // hide the mouse and set the hideMouseTimeout value to -1 to signal that + // the mouse has been hidden. if (hideMouseTimeout > 0) hideMouseTimeout--; else if (hideMouseTimeout == 0) { hideMouseTimeout--; qApp->setOverrideCursor(Qt::BlankCursor); -//printf("timer: hideMouseTimeout = %i, mouse hidden\n", hideMouseTimeout); } } diff --git a/src/gui/glwidget.h b/src/gui/glwidget.h index 40d2755..e7d7406 100644 --- a/src/gui/glwidget.h +++ b/src/gui/glwidget.h @@ -17,7 +17,6 @@ class GLWidget: public QGLWidget GLWidget(QWidget * parent = 0); ~GLWidget(); -// void HideMouseIfTimedOut(void); void HandleMouseHiding(void); void CheckAndRestoreMouseCursor(void); // QSize minimumSizeHint() const; diff --git a/src/gui/mainwin.cpp b/src/gui/mainwin.cpp index 782eb25..6becf8e 100644 --- a/src/gui/mainwin.cpp +++ b/src/gui/mainwin.cpp @@ -84,6 +84,8 @@ MainWin::MainWin(bool autoRun): running(true), powerButtonOn(false), showUntunedTankCircuit(true), cartridgeLoaded(false), CDActive(false), pauseForFileSelector(false), loadAndGo(autoRun), plzDontKillMyComputer(false) { + debugbar = NULL; + for(int i=0; i<8; i++) keyHeld[i] = false; @@ -118,6 +120,7 @@ MainWin::MainWin(bool autoRun): running(true), powerButtonOn(false), // quitAppAct->setShortcuts(QKeySequence::Quit); // quitAppAct->setShortcut(QKeySequence(tr("Alt+x"))); quitAppAct->setShortcut(QKeySequence(tr("Ctrl+q"))); + quitAppAct->setShortcutContext(Qt::ApplicationShortcut); quitAppAct->setStatusTip(tr("Quit Virtual Jaguar")); connect(quitAppAct, SIGNAL(triggered()), this, SLOT(close())); @@ -143,6 +146,7 @@ MainWin::MainWin(bool autoRun): running(true), powerButtonOn(false), pauseAct->setCheckable(true); pauseAct->setDisabled(true); pauseAct->setShortcut(QKeySequence(tr("Esc"))); + pauseAct->setShortcutContext(Qt::ApplicationShortcut); connect(pauseAct, SIGNAL(triggered()), this, SLOT(ToggleRunState())); zoomActs = new QActionGroup(this); @@ -190,11 +194,13 @@ MainWin::MainWin(bool autoRun): running(true), powerButtonOn(false), filePickAct = new QAction(QIcon(":/res/software.png"), tr("&Insert Cartridge..."), this); filePickAct->setStatusTip(tr("Insert a cartridge into Virtual Jaguar")); filePickAct->setShortcut(QKeySequence(tr("Ctrl+i"))); + filePickAct->setShortcutContext(Qt::ApplicationShortcut); connect(filePickAct, SIGNAL(triggered()), this, SLOT(InsertCart())); configAct = new QAction(QIcon(":/res/wrench.png"), tr("&Configure"), this); configAct->setStatusTip(tr("Configure options for Virtual Jaguar")); configAct->setShortcut(QKeySequence(tr("Ctrl+c"))); + configAct->setShortcutContext(Qt::ApplicationShortcut); connect(configAct, SIGNAL(triggered()), this, SLOT(Configure())); useCDAct = new QAction(QIcon(":/res/compact-disc.png"), tr("&Use CD Unit"), this); @@ -205,11 +211,13 @@ MainWin::MainWin(bool autoRun): running(true), powerButtonOn(false), frameAdvanceAct = new QAction(QIcon(":/res/frame-advance.png"), tr("&Frame Advance"), this); frameAdvanceAct->setShortcut(QKeySequence(tr("F7"))); + frameAdvanceAct->setShortcutContext(Qt::ApplicationShortcut); frameAdvanceAct->setDisabled(true); connect(frameAdvanceAct, SIGNAL(triggered()), this, SLOT(FrameAdvance())); fullScreenAct = new QAction(QIcon(":/res/fullscreen.png"), tr("F&ull Screen"), this); fullScreenAct->setShortcut(QKeySequence(tr("F9"))); + fullScreenAct->setShortcutContext(Qt::ApplicationShortcut); fullScreenAct->setCheckable(true); connect(fullScreenAct, SIGNAL(triggered()), this, SLOT(ToggleFullScreen())); @@ -295,6 +303,15 @@ MainWin::MainWin(bool autoRun): running(true), powerButtonOn(false), debugbar->addAction(riscDasmBrowseAct); } + // Add actions to the main window, as hiding widgets with them + // disables them :-P + addAction(fullScreenAct); + addAction(quitAppAct); + addAction(configAct); + addAction(pauseAct); + addAction(filePickAct); + addAction(frameAdvanceAct); + // Create status bar statusBar()->showMessage(tr("Ready")); @@ -653,7 +670,6 @@ void MainWin::Timer(void) // Otherwise, run the Jaguar simulation HandleGamepads(); JaguarExecuteNew(); -// videoWidget->HideMouseIfTimedOut(); videoWidget->HandleMouseHiding(); } @@ -678,14 +694,14 @@ void MainWin::TogglePowerState(void) pauseAct->setDisabled(true); showUntunedTankCircuit = true; DACPauseAudioThread(); - // This is just in case the ROM we were playing was in a narrow or wide field mode, - // so the untuned tank sim doesn't look wrong. :-) + // This is just in case the ROM we were playing was in a narrow or wide + // field mode, so the untuned tank sim doesn't look wrong. :-) TOMReset(); if (plzDontKillMyComputer) { - // We have to do it line by line, because the texture pitch is not the - // same as the picture buffer's pitch. + // We have to do it line by line, because the texture pitch is not + // the same as the picture buffer's pitch. for(uint32_t y=0; yrasterHeight; y++) { memcpy(videoWidget->buffer + (y * videoWidget->textureWidth), testPattern + (y * VIRTUAL_SCREEN_WIDTH), VIRTUAL_SCREEN_WIDTH * sizeof(uint32_t)); @@ -705,10 +721,10 @@ void MainWin::TogglePowerState(void) if (CDActive) { // Should check for cartridgeLoaded here as well...! -// We can clear it when toggling CDActive on, so that when we power cycle it does the -// expected thing. Otherwise, if we use the file picker to insert a cart, we expect -// to run the cart! Maybe have a RemoveCart function that only works if the CD unit -// is active? +// We can clear it when toggling CDActive on, so that when we power cycle it +// does the expected thing. Otherwise, if we use the file picker to insert a +// cart, we expect to run the cart! Maybe have a RemoveCart function that only +// works if the CD unit is active? setWindowTitle(QString("Virtual Jaguar " VJ_RELEASE_VERSION " - Now playing: Jaguar CD")); } @@ -902,14 +918,17 @@ void MainWin::SetFullScreen(bool state/*= true*/) mainWinPosition = pos(); menuBar()->hide(); statusBar()->hide(); - x1Act->setDisabled(true); - x2Act->setDisabled(true); - x3Act->setDisabled(true); + toolbar->hide(); + + if (debugbar) + debugbar->hide(); + showFullScreen(); // This is needed because the fullscreen may happen on a different // screen than screen 0: int screenNum = QApplication::desktop()->screenNumber(videoWidget); - QRect r = QApplication::desktop()->availableGeometry(screenNum); +// QRect r = QApplication::desktop()->availableGeometry(screenNum); + QRect r = QApplication::desktop()->screenGeometry(screenNum); double targetWidth = (double)VIRTUAL_SCREEN_WIDTH, targetHeight = (double)(vjs.hardwareTypeNTSC ? VIRTUAL_SCREEN_HEIGHT_NTSC : VIRTUAL_SCREEN_HEIGHT_PAL); double aspectRatio = targetWidth / targetHeight; @@ -927,21 +946,17 @@ void MainWin::SetFullScreen(bool state/*= true*/) // Reset the video widget to windowed mode videoWidget->offset = 0; videoWidget->fullscreen = false; - x1Act->setDisabled(false); - x2Act->setDisabled(false); - x3Act->setDisabled(false); menuBar()->show(); statusBar()->show(); + toolbar->show(); + + if (debugbar) + debugbar->show(); + showNormal(); ResizeMainWindow(); move(mainWinPosition); } - - // For some reason, this doesn't work: If the emu is paused, toggling from - // fullscreen to windowed (& vice versa) shows a white screen. - // (It was the ResizeGL() function in GLWidget: it was being called too - // much, causing the buffer to be deleted, remade & cleared.) -// videoWidget->updateGL(); }