]> Shamusworld >> Repos - virtualjaguar/commitdiff
Fixes for fullscreen mode, initial stab at multiple controller configs
authorShamus Hammons <jlhamm@acm.org>
Sat, 9 Mar 2013 22:48:09 +0000 (16:48 -0600)
committerShamus Hammons <jlhamm@acm.org>
Sat, 9 Mar 2013 22:48:09 +0000 (16:48 -0600)
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.

src/gui/controllertab.cpp
src/gui/controllertab.h
src/gui/controllerwidget.cpp
src/gui/gamepad.cpp
src/gui/gamepad.h
src/gui/glwidget.cpp
src/gui/glwidget.h
src/gui/mainwin.cpp

index 1af9f45572fc6801efcbcf481ba0e89709d0fa30..6050dd733a7125ed4bd34b969771b57d3cfcf59c 100644 (file)
 #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; i<Gamepad::numJoysticks; i++)
+               profile->addItem(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",
index 011eec2b00785b27fc876a29bb074aba81bcca48..9b4c5259e9cee51de69650f5defc9688488474a2 100644 (file)
@@ -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:
index 0386334a92846cfc21e781c808b21f858101227e..eb91c34274ea28666dbd020a8e7e74e522de395d 100644 (file)
@@ -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);
 }
 
 
index 62a6d7a9bef851d932aba79f87c305fc3a2aa36b..8706e17643667499b39d8fe78caed6190898181a 100644 (file)
@@ -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<numJoysticks; i++)
        {
                pad[i] = SDL_JoystickOpen(i);
+               padName[i] = SDL_JoystickName(i);
                numButtons[i] = numHats[i] = 0;
 
                if (pad[i])
@@ -71,6 +73,16 @@ void Gamepad::DeallocateJoysticks(void)
 }
 
 
+const char * Gamepad::GetJoystickName(int joystickID)
+{
+       // Sanity check
+       if (joystickID >= 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 };
index 43779c150464c4c19f2c92cf87d8dac07adfd48f..a7085a416e12af6bdd108db1842bdfe2b9d14e08 100644 (file)
@@ -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];
index 2f959186914834bd0bf5cbb54ac03cfb97943263..ead7268ccd45f9615daedb2324270b72c68a5e7c 100644 (file)
@@ -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);
        }
 }
 
index 40d27556e6f619b96a2884f0f82b77c064f08e82..e7d7406811410168c4c5eefd3d82eb7d7d445e1b 100644 (file)
@@ -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;
index 782eb25834af46fdd89608e843d6b1416f96cbdf..6becf8eb13816b1b7eae77d4ec568ce2155a36a0 100644 (file)
@@ -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; y<videoWidget->rasterHeight; 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();
 }