]> Shamusworld >> Repos - virtualjaguar/commitdiff
More GUI fill in, new About box
authorShamus Hammons <jlhamm@acm.org>
Thu, 21 Jan 2010 22:09:01 +0000 (22:09 +0000)
committerShamus Hammons <jlhamm@acm.org>
Thu, 21 Jan 2010 22:09:01 +0000 (22:09 +0000)
Makefile
src/gui/about.cpp [new file with mode: 0644]
src/gui/about.h [new file with mode: 0644]
src/gui/glwidget.cpp
src/gui/mainwin.cpp
src/gui/mainwin.h
src/gui/vj.pro
src/gui/vj.qrc

index ab65a75a600f41c7c5780a1aac4133577a7c2c5f..ebce4f7425f8253908e227118e60345c323cd61f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -72,6 +72,7 @@ OBJS = \
        obj/m68kopnz.o      \
        obj/m68kdasm.o      \
 \
+       obj/about.o         \
        obj/app.o           \
        obj/mainwin.o       \
        obj/moc_mainwin.o   \
diff --git a/src/gui/about.cpp b/src/gui/about.cpp
new file mode 100644 (file)
index 0000000..c354307
--- /dev/null
@@ -0,0 +1,73 @@
+//
+// about.cpp - Credits
+//
+// by James L. Hammons
+// (C) 2010 Underground Software
+//
+// JLH = James L. Hammons <jlhamm@acm.org>
+//
+// Who  When        What
+// ---  ----------  -------------------------------------------------------------
+// JLH  01/21/2010  Created this file
+//
+
+#include "about.h"
+
+AboutWindow::AboutWindow(QWidget * parent/*= 0*/): QWidget()
+{
+       layout = new QVBoxLayout();
+       layout->setSizeConstraint(QLayout::SetFixedSize);
+//     layout->setMargin(Style::WindowMargin);
+//     layout->setSpacing(Style::WidgetSpacing);
+       setLayout(layout);
+
+//  logo = new Logo;
+//  logo->setFixedSize(600, 106);
+//  layout->addWidget(logo);
+
+       text = new QLabel(tr(
+               "<table>"
+               "<tr><td align='right'><b>Version: </b></td><td>2.0.0</td></tr>"
+               "<tr><td align='right'><b>Author: </b></td><td>byuu</td></tr>"
+               "<tr><td align='right'><b>Homepage: </b></td><td>http://byuu.org/</td></tr>"
+               "</table>"
+       ));
+       layout->addWidget(text);
+}
+
+
+// Byuu's version...
+#if 0
+#include "about.moc"
+AboutWindow *aboutWindow;
+
+AboutWindow::AboutWindow() : QbWindow(config().geometry.aboutWindow) {
+  setObjectName("about-window");
+  setWindowTitle("About bsnes ...");
+
+  layout = new QVBoxLayout;
+  layout->setSizeConstraint(QLayout::SetFixedSize);
+  layout->setMargin(Style::WindowMargin);
+  layout->setSpacing(Style::WidgetSpacing);
+  setLayout(layout);
+
+  logo = new Logo;
+  logo->setFixedSize(600, 106);
+  layout->addWidget(logo);
+
+  info = new QLabel(string() <<
+    "<table>"
+    "<tr><td align='right'><b>Version: </b></td><td>" << bsnesVersion << "</td></tr>"
+    "<tr><td align='right'><b>Author: </b></td><td>byuu</td></tr>"
+    "<tr><td align='right'><b>Homepage: </b></td><td>http://byuu.org/</td></tr>"
+    "</table>"
+  );
+  layout->addWidget(info);
+}
+
+void AboutWindow::Logo::paintEvent(QPaintEvent*) {
+  QPainter painter(this);
+  QPixmap pixmap(":/logo.png");
+  painter.drawPixmap(0, 0, pixmap);
+}
+#endif
diff --git a/src/gui/about.h b/src/gui/about.h
new file mode 100644 (file)
index 0000000..c448651
--- /dev/null
@@ -0,0 +1,41 @@
+//
+// about.h: Credits where credits are due ;-)
+//
+// by James L. Hammons
+// (C) 2010 Underground Software
+//
+
+#ifndef __ABOUT_H__
+#define __ABOUT_H__
+
+#include <QtGui>
+
+class AboutWindow: public QWidget
+{
+       public:
+               AboutWindow(QWidget * parent = 0);
+
+       private:
+               QVBoxLayout * layout;
+               QLabel * text;
+};
+
+#endif // __ABOUT_H__
+
+
+#if 0
+class AboutWindow : public QbWindow {
+  Q_OBJECT
+
+public:
+  QVBoxLayout *layout;
+  struct Logo : public QWidget {
+    void paintEvent(QPaintEvent*);
+  } *logo;
+  QLabel *info;
+
+  AboutWindow();
+};
+
+extern AboutWindow *aboutWindow;
+#endif
index d4a65ec59568986c4555ad9cbe767bbbba9692ef..e32dde3682aa65c4b6d842e6d960313803e669ae 100644 (file)
@@ -16,8 +16,7 @@
 #include "settings.h"
 
 GLWidget::GLWidget(QWidget * parent/*= 0*/): QGLWidget(parent), texture(0),
-       textureWidth(0), textureHeight(0), buffer(0), rasterWidth(64), rasterHeight(64)
-//     textureWidth(0), textureHeight(0), buffer(0), rasterWidth(256), rasterHeight(256)
+       textureWidth(0), textureHeight(0), buffer(0), rasterWidth(320), rasterHeight(240)
 {
 }
 
@@ -42,6 +41,9 @@ void GLWidget::initializeGL()
 
 void GLWidget::paintGL()
 {
+//kludge
+rasterHeight = (vjs.hardwareTypeNTSC ? 240 : 256);
+
        unsigned outputWidth  = width();
        unsigned outputHeight = height();
 
index deef6b4a7f5995cc91ed6014020c8f3090851729..40af9eb4b1ad31e6820a7aa8c5ca266a2c7d6c1a 100644 (file)
@@ -28,6 +28,7 @@
 //#include <QtGui>
 //#include <QtOpenGL>
 #include "glwidget.h"
+#include "about.h"
 #include "settings.h"
 
 // The way BSNES controls things is by setting a timer with a zero
@@ -49,6 +50,11 @@ MainWin::MainWin()
        setWindowIcon(QIcon(":/res/vj.xpm"));
        setWindowTitle("Virtual Jaguar v2.0.0");
 
+       aboutWin = new AboutWindow(this);
+
+    videoWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+    setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+
        // Create actions
 
        quitAppAct = new QAction(tr("E&xit"), this);
@@ -56,92 +62,67 @@ MainWin::MainWin()
        quitAppAct->setStatusTip(tr("Quit Virtual Jaguar"));
        connect(quitAppAct, SIGNAL(triggered()), this, SLOT(close()));
 
-       action = new QAction(QIcon(":/res/power.png"), tr("&Power"), this);
-       action->setStatusTip(tr("Toggle running state"));
-       action->setCheckable(true);
-       connect(action, SIGNAL(triggered()), this, SLOT(ToggleRunState()));
+       powerAct = new QAction(QIcon(":/res/power.png"), tr("&Power"), this);
+       powerAct->setStatusTip(tr("Toggle running state"));
+       powerAct->setCheckable(true);
+       connect(powerAct, SIGNAL(triggered()), this, SLOT(ToggleRunState()));
 
        zoomActs = new QActionGroup(this);
 
        x1Act = new QAction(QIcon(":/res/zoom100.png"), tr("Zoom 100%"), zoomActs);
        x1Act->setStatusTip(tr("Set window zoom to 100%"));
        x1Act->setCheckable(true);
-//     connect(x1Act, SIGNAL(triggered()), this, SLOT(???()));
+       connect(x1Act, SIGNAL(triggered()), this, SLOT(SetZoom100()));
 
        x2Act = new QAction(QIcon(":/res/zoom200.png"), tr("Zoom 200%"), zoomActs);
        x2Act->setStatusTip(tr("Set window zoom to 200%"));
        x2Act->setCheckable(true);
-//     connect(x2Act, SIGNAL(triggered()), this, SLOT(???()));
+       connect(x2Act, SIGNAL(triggered()), this, SLOT(SetZoom200()));
 
        x3Act = new QAction(QIcon(":/res/zoom300.png"), tr("Zoom 300%"), zoomActs);
        x3Act->setStatusTip(tr("Set window zoom to 300%"));
        x3Act->setCheckable(true);
-//     connect(x3Act, SIGNAL(triggered()), this, SLOT(???()));
+       connect(x3Act, SIGNAL(triggered()), this, SLOT(SetZoom300()));
+
+       tvTypeActs = new QActionGroup(this);
+
+       ntscAct = new QAction(QIcon(":/res/generic.png"), tr("NTSC"), tvTypeActs);
+       ntscAct->setStatusTip(tr("Sets OpenGL rendering to GL_NEAREST"));
+       ntscAct->setCheckable(true);
+       connect(ntscAct, SIGNAL(triggered()), this, SLOT(SetNTSC()));
+
+       palAct = new QAction(QIcon(":/res/generic.png"), tr("PAL"), tvTypeActs);
+       palAct->setStatusTip(tr("Sets OpenGL rendering to GL_NEAREST"));
+       palAct->setCheckable(true);
+       connect(palAct, SIGNAL(triggered()), this, SLOT(SetPAL()));
 
        blurAct = new QAction(QIcon(":/res/generic.png"), tr("Blur"), this);
        blurAct->setStatusTip(tr("Sets OpenGL rendering to GL_NEAREST"));
        blurAct->setCheckable(true);
        connect(blurAct, SIGNAL(triggered()), this, SLOT(ToggleBlur()));
 
+       aboutAct = new QAction(QIcon(":/res/generic.png"), tr("&About..."), this);
+       aboutAct->setStatusTip(tr("Shows self-serving credits"));
+//     aboutAct->setCheckable(true);
+       connect(aboutAct, SIGNAL(triggered()), this, SLOT(ShowAboutWin()));
+
        // Create menus & toolbars
 
-       QMenu * fileMenu = menuBar()->addMenu(tr("&File"));
-       fileMenu->addAction(action);
+       fileMenu = menuBar()->addMenu(tr("&File"));
+       fileMenu->addAction(powerAct);
        fileMenu->addAction(quitAppAct);
 
+       fileMenu = menuBar()->addMenu(tr("&Help"));
+       fileMenu->addAction(aboutAct);
+
        QToolBar * toolbar = addToolBar(tr("Stuff"));
-       toolbar->addAction(action);
+       toolbar->addAction(powerAct);
        toolbar->addAction(x1Act);
        toolbar->addAction(x2Act);
        toolbar->addAction(x3Act);
+       toolbar->addAction(ntscAct);
+       toolbar->addAction(palAct);
        toolbar->addAction(blurAct);
-#if 0
-//     createActions();
-       newAct = new QAction(QIcon(":/images/new.png"), tr("&New"), this);
-       newAct->setShortcuts(QKeySequence::New);
-       newAct->setStatusTip(tr("Create a new file"));
-       connect(newAct, SIGNAL(triggered()), this, SLOT(newFile()));
-
-       openAct = new QAction(QIcon(":/images/open.png"), tr("&Open..."), this);
-       openAct->setShortcuts(QKeySequence::Open);
-       openAct->setStatusTip(tr("Open an existing file"));
-       connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
-
-       aboutQtAct = new QAction(tr("About &Qt"), this);
-       aboutQtAct->setStatusTip(tr("Show the Qt library's About box"));
-       connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
-
-//     createMenus();
-       fileMenu = menuBar()->addMenu(tr("&File"));
-       fileMenu->addAction(newAct);
-       fileMenu->addAction(openAct);
-       fileMenu->addAction(saveAct);
-       fileMenu->addAction(saveAsAct);
-       fileMenu->addSeparator();
-       fileMenu->addAction(exitAct);
-
-       editMenu = menuBar()->addMenu(tr("&Edit"));
-       editMenu->addAction(cutAct);
-       editMenu->addAction(copyAct);
-       editMenu->addAction(pasteAct);
-
-       menuBar()->addSeparator();
-
-       helpMenu = menuBar()->addMenu(tr("&Help"));
-       helpMenu->addAction(aboutAct);
-       helpMenu->addAction(aboutQtAct);
-
-//     createToolBars();
-       fileToolBar = addToolBar(tr("File"));
-       fileToolBar->addAction(newAct);
-       fileToolBar->addAction(openAct);
-       fileToolBar->addAction(saveAct);
-
-       editToolBar = addToolBar(tr("Edit"));
-       editToolBar->addAction(cutAct);
-       editToolBar->addAction(copyAct);
-       editToolBar->addAction(pasteAct);
-#endif
 
        //      Create status bar
        statusBar()->showMessage(tr("Ready"));
@@ -151,8 +132,15 @@ MainWin::MainWin()
 
        // Set toolbar button based on setting read in (sync the UI)...
        blurAct->setChecked(vjs.glFilter);
-       x1Act->setChecked(true);
-       running = action->isChecked();
+       x1Act->setChecked(zoomLevel == 1);
+       x2Act->setChecked(zoomLevel == 2);
+       x3Act->setChecked(zoomLevel == 3);
+       running = powerAct->isChecked();
+       ntscAct->setChecked(vjs.hardwareTypeNTSC);
+       palAct->setChecked(!vjs.hardwareTypeNTSC);
+
+       // Do this in case original size isn't correct
+       ResizeMainWindow();
 
        // Set up timer based loop for animation...
        timer = new QTimer(this);
@@ -205,14 +193,32 @@ void MainWin::ToggleRunState(void)
 
 void MainWin::SetZoom100(void)
 {
+       zoomLevel = 1;
+       ResizeMainWindow();
 }
 
 void MainWin::SetZoom200(void)
 {
+       zoomLevel = 2;
+       ResizeMainWindow();
 }
 
 void MainWin::SetZoom300(void)
 {
+       zoomLevel = 3;
+       ResizeMainWindow();
+}
+
+void MainWin::SetNTSC(void)
+{
+       vjs.hardwareTypeNTSC = true;
+       ResizeMainWindow();
+}
+
+void MainWin::SetPAL(void)
+{
+       vjs.hardwareTypeNTSC = false;
+       ResizeMainWindow();
 }
 
 void MainWin::ToggleBlur(void)
@@ -220,6 +226,28 @@ void MainWin::ToggleBlur(void)
        vjs.glFilter = !vjs.glFilter;
 }
 
+void MainWin::ShowAboutWin(void)
+{
+       aboutWin->show();
+//     QMessageBox::about(this, tr("About Application"),
+//             tr("The <b>Application</b> example demonstrates how to "
+//             "write modern GUI applications using Qt, with a menu bar, "
+//             "toolbars, and a status bar."));
+}
+
+void MainWin::ResizeMainWindow(void)
+{
+       videoWidget->setFixedSize(zoomLevel * 320, zoomLevel * (vjs.hardwareTypeNTSC ? 240 : 256));
+       show();
+
+       for(int i=0; i<2; i++)
+       {
+               resize(0, 0);
+               usleep(2000);
+               QApplication::processEvents();
+       }
+}
+
 void MainWin::ReadSettings(void)
 {
        QSettings settings("Underground Software", "Virtual Jaguar");
@@ -228,6 +256,8 @@ void MainWin::ReadSettings(void)
        resize(size);
        move(pos);
 
+       zoomLevel = settings.value("zoom", 1).toInt();
+
        vjs.useJoystick      = settings.value("useJoystick", false).toBool();
        vjs.joyport          = settings.value("joyport", 0).toInt();
        vjs.hardwareTypeNTSC = settings.value("hardwareTypeNTSC", true).toBool();
@@ -247,6 +277,8 @@ void MainWin::WriteSettings(void)
        settings.setValue("pos", pos());
        settings.setValue("size", size());
 
+       settings.setValue("zoom", zoomLevel);
+
        settings.setValue("useJoystick", vjs.useJoystick);
        settings.setValue("joyport", vjs.joyport);
        settings.setValue("hardwareTypeNTSC", vjs.hardwareTypeNTSC);
@@ -260,3 +292,89 @@ void MainWin::WriteSettings(void)
        settings.setValue("renderType", vjs.renderType);
 }
 
+// Here's how Byuu does it...
+// I think I have it working now... :-)
+#if 0
+void Utility::resizeMainWindow()
+{
+  unsigned region = config().video.context->region;
+  unsigned multiplier = config().video.context->multiplier;
+  unsigned width = 256 * multiplier;
+  unsigned height = (region == 0 ? 224 : 239) * multiplier;
+
+  if(config().video.context->correctAspectRatio)
+  {
+    if(region == 0)
+       {
+      width = (double)width * config().video.ntscAspectRatio + 0.5;  //NTSC adjust
+    }
+       else
+       {
+      width = (double)width * config().video.palAspectRatio  + 0.5;  //PAL adjust
+    }
+  }
+
+  if(config().video.isFullscreen == false)
+  {
+    //get effective desktop work area region (ignore Windows taskbar, OS X dock, etc.)
+    QRect deskRect = QApplication::desktop()->availableGeometry(mainWindow);
+
+    //ensure window size will not be larger than viewable desktop area
+    constrainSize(height, width, deskRect.height()); //- frameHeight);
+    constrainSize(width, height, deskRect.width());  //- frameWidth );
+
+    mainWindow->canvas->setFixedSize(width, height);
+    mainWindow->show();
+  }
+  else
+  {
+    for(unsigned i = 0; i < 2; i++)
+       {
+      unsigned iWidth = width, iHeight = height;
+
+      constrainSize(iHeight, iWidth, mainWindow->canvasContainer->size().height());
+      constrainSize(iWidth, iHeight, mainWindow->canvasContainer->size().width());
+
+      //center canvas onscreen; ensure it is not larger than viewable area
+      mainWindow->canvas->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+      mainWindow->canvas->setFixedSize(iWidth, iHeight);
+      mainWindow->canvas->setMinimumSize(0, 0);
+
+      usleep(2000);
+      QApplication::processEvents();
+    }
+  }
+
+  //workaround for Qt/Xlib bug:
+  //if window resize occurs with cursor over it, Qt shows Qt::Size*DiagCursor;
+  //so force it to show Qt::ArrowCursor, as expected
+  mainWindow->setCursor(Qt::ArrowCursor);
+  mainWindow->canvasContainer->setCursor(Qt::ArrowCursor);
+  mainWindow->canvas->setCursor(Qt::ArrowCursor);
+
+  //workaround for DirectSound(?) bug:
+  //window resizing sometimes breaks audio sync, this call re-initializes it
+  updateAvSync();
+}
+
+void Utility::setScale(unsigned scale)
+{
+  config().video.context->multiplier = scale;
+  resizeMainWindow();
+  mainWindow->shrink();
+  mainWindow->syncUi();
+}
+
+void QbWindow::shrink()
+{
+  if(config().video.isFullscreen == false)
+  {
+    for(unsigned i = 0; i < 2; i++)
+       {
+      resize(0, 0);
+      usleep(2000);
+      QApplication::processEvents();
+    }
+  }
+}
+#endif
index 781ac29fcd6ea6e2f43e724e23927374e0f1b882..a3a26cccf95b2ebb3624fa4d680a6f452dbc4476 100644 (file)
@@ -14,6 +14,7 @@
 // Forward declarations
 
 class GLWidget;
+class AboutWindow;
 //class EditWindow;
 //class CharWindow;
 
@@ -35,26 +36,38 @@ class MainWin: public QMainWindow
                void SetZoom100(void);
                void SetZoom200(void);
                void SetZoom300(void);
+               void SetNTSC(void);
+               void SetPAL(void);
                void ToggleBlur(void);
+               void ShowAboutWin(void);
 
        private:
+               void ResizeMainWindow(void);
                void ReadSettings(void);
                void WriteSettings(void);
 
 //     public:
                GLWidget * videoWidget;
+               AboutWindow * aboutWin;
                QTimer * timer;
                bool running;
-//             EditWindow * editWnd;
-//             CharWindow * charWnd;
+               int zoomLevel;
+
+               QMenu * fileMenu;
+               QMenu * helpMenu;
+
                QActionGroup * zoomActs;
+               QActionGroup * tvTypeActs;
 
-               QAction * action;
                QAction * quitAppAct;
+               QAction * powerAct;
                QAction * x1Act;
                QAction * x2Act;
                QAction * x3Act;
+               QAction * ntscAct;
+               QAction * palAct;
                QAction * blurAct;
+               QAction * aboutAct;
 };
 
 #endif // __MAINWIN_H__
index 106f79b0af2186a5aaebe008a03937ac6cbca117..f95b90e9a67b88136706e9e24398b4dcef53b70c 100644 (file)
@@ -9,10 +9,12 @@ QT += opengl
 HEADERS += app.h
 HEADERS += mainwin.h
 HEADERS += glwidget.h
+HEADERS += about.h
 
 SOURCES += app.cpp
 SOURCES += mainwin.cpp
 SOURCES += glwidget.cpp
+SOURCES += about.cpp
 
 RESOURCES += vj.qrc
 
index 159f89017637c496258dc92b0bbaf5fa79261db6..4a23d8c9ed98e08acb4f67e8d487b10ed3e90a30 100644 (file)
@@ -6,5 +6,6 @@
        <file>../../res/zoom200.png</file>
        <file>../../res/zoom300.png</file>
        <file>../../res/generic.png</file>
+       <file>../../res/vj_title_small.png</file>
 </qresource>
 </RCC>