2 // mainwin.cpp - Qt-based GUI for Virtual Jaguar: Main Application Window
4 // (C) 2009 Underground Software
6 // JLH = James L. Hammons <jlhamm@acm.org>
9 // --- ---------- -------------------------------------------------------------
10 // JLH 12/23/2009 Created this file
11 // JLH 12/20/2010 Added settings, menus & toolbars
21 // Uncomment this for debugging...
23 //#define DEBUGFOO // Various tool debugging...
24 //#define DEBUGTP // Toolpalette debugging...
33 // The way BSNES controls things is by setting a timer with a zero
34 // timeout, sleeping if not emulating anything. Seems there has to be a
37 // It has a novel approach to plugging-in/using different video/audio/input
38 // methods, can we do something similar or should we just use the built-in
41 // We're going to try to use the built-in OpenGL support and see how it goes.
42 // We'll make the VJ core modular so that it doesn't matter what GUI is in
43 // use, we can drop it in anywhere and use it as-is.
47 videoWidget = new GLWidget(this);
48 setCentralWidget(videoWidget);
49 setWindowIcon(QIcon(":/res/vj.xpm"));
50 setWindowTitle("Virtual Jaguar v2.0.0");
54 quitAppAct = new QAction(tr("E&xit"), this);
55 quitAppAct->setShortcuts(QKeySequence::Quit);
56 quitAppAct->setStatusTip(tr("Quit Virtual Jaguar"));
57 connect(quitAppAct, SIGNAL(triggered()), this, SLOT(close()));
59 action = new QAction(QIcon(":/res/power.png"), tr("&Power"), this);
60 action->setStatusTip(tr("Toggle running state"));
61 action->setCheckable(true);
62 connect(action, SIGNAL(triggered()), this, SLOT(ToggleRunState()));
64 zoomActs = new QActionGroup(this);
66 x1Act = new QAction(QIcon(":/res/zoom100.png"), tr("Zoom 100%"), zoomActs);
67 x1Act->setStatusTip(tr("Set window zoom to 100%"));
68 x1Act->setCheckable(true);
69 // connect(x1Act, SIGNAL(triggered()), this, SLOT(???()));
71 x2Act = new QAction(QIcon(":/res/zoom200.png"), tr("Zoom 200%"), zoomActs);
72 x2Act->setStatusTip(tr("Set window zoom to 200%"));
73 x2Act->setCheckable(true);
74 // connect(x2Act, SIGNAL(triggered()), this, SLOT(???()));
76 x3Act = new QAction(QIcon(":/res/zoom300.png"), tr("Zoom 300%"), zoomActs);
77 x3Act->setStatusTip(tr("Set window zoom to 300%"));
78 x3Act->setCheckable(true);
79 // connect(x3Act, SIGNAL(triggered()), this, SLOT(???()));
81 blurAct = new QAction(QIcon(":/res/generic.png"), tr("Blur"), this);
82 blurAct->setStatusTip(tr("Sets OpenGL rendering to GL_NEAREST"));
83 blurAct->setCheckable(true);
84 connect(blurAct, SIGNAL(triggered()), this, SLOT(ToggleBlur()));
86 // Create menus & toolbars
88 QMenu * fileMenu = menuBar()->addMenu(tr("&File"));
89 fileMenu->addAction(action);
90 fileMenu->addAction(quitAppAct);
92 QToolBar * toolbar = addToolBar(tr("Stuff"));
93 toolbar->addAction(action);
94 toolbar->addAction(x1Act);
95 toolbar->addAction(x2Act);
96 toolbar->addAction(x3Act);
97 toolbar->addAction(blurAct);
100 newAct = new QAction(QIcon(":/images/new.png"), tr("&New"), this);
101 newAct->setShortcuts(QKeySequence::New);
102 newAct->setStatusTip(tr("Create a new file"));
103 connect(newAct, SIGNAL(triggered()), this, SLOT(newFile()));
105 openAct = new QAction(QIcon(":/images/open.png"), tr("&Open..."), this);
106 openAct->setShortcuts(QKeySequence::Open);
107 openAct->setStatusTip(tr("Open an existing file"));
108 connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
110 aboutQtAct = new QAction(tr("About &Qt"), this);
111 aboutQtAct->setStatusTip(tr("Show the Qt library's About box"));
112 connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
115 fileMenu = menuBar()->addMenu(tr("&File"));
116 fileMenu->addAction(newAct);
117 fileMenu->addAction(openAct);
118 fileMenu->addAction(saveAct);
119 fileMenu->addAction(saveAsAct);
120 fileMenu->addSeparator();
121 fileMenu->addAction(exitAct);
123 editMenu = menuBar()->addMenu(tr("&Edit"));
124 editMenu->addAction(cutAct);
125 editMenu->addAction(copyAct);
126 editMenu->addAction(pasteAct);
128 menuBar()->addSeparator();
130 helpMenu = menuBar()->addMenu(tr("&Help"));
131 helpMenu->addAction(aboutAct);
132 helpMenu->addAction(aboutQtAct);
135 fileToolBar = addToolBar(tr("File"));
136 fileToolBar->addAction(newAct);
137 fileToolBar->addAction(openAct);
138 fileToolBar->addAction(saveAct);
140 editToolBar = addToolBar(tr("Edit"));
141 editToolBar->addAction(cutAct);
142 editToolBar->addAction(copyAct);
143 editToolBar->addAction(pasteAct);
147 statusBar()->showMessage(tr("Ready"));
150 setUnifiedTitleAndToolBarOnMac(true);
152 // Set toolbar button based on setting read in (sync the UI)...
153 blurAct->setChecked(vjs.glFilter);
154 x1Act->setChecked(true);
155 running = action->isChecked();
157 // Set up timer based loop for animation...
158 timer = new QTimer(this);
159 connect(timer, SIGNAL(timeout()), this, SLOT(Timer()));
163 void MainWin::closeEvent(QCloseEvent * event)
166 event->accept(); // ignore() if can't close for some reason
169 void MainWin::Open(void)
173 void MainWin::Timer(void)
178 // Random hash & trash
179 // We try to simulate an untuned tank circuit here... :-)
180 for(uint32_t x=0; x<videoWidget->rasterWidth; x++)
182 for(uint32_t y=0; y<videoWidget->rasterHeight; y++)
184 videoWidget->buffer[(y * videoWidget->textureWidth) + x] = (rand() & 0xFF) << 8 | (rand() & 0xFF) << 16 | (rand() & 0xFF) << 24;// | (rand() & 0xFF);//0x000000FF;
185 // buffer[(y * textureWidth) + x] = x*y;
189 videoWidget->updateGL();
192 void MainWin::ToggleRunState(void)
198 for(uint32_t x=0; x<videoWidget->rasterWidth; x++)
199 for(uint32_t y=0; y<videoWidget->rasterHeight; y++)
200 videoWidget->buffer[(y * videoWidget->textureWidth) + x] = 0x00000000;
202 videoWidget->updateGL();
206 void MainWin::SetZoom100(void)
210 void MainWin::SetZoom200(void)
214 void MainWin::SetZoom300(void)
218 void MainWin::ToggleBlur(void)
220 vjs.glFilter = !vjs.glFilter;
223 void MainWin::ReadSettings(void)
225 QSettings settings("Underground Software", "Virtual Jaguar");
226 QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
227 QSize size = settings.value("size", QSize(400, 400)).toSize();
231 vjs.useJoystick = settings.value("useJoystick", false).toBool();
232 vjs.joyport = settings.value("joyport", 0).toInt();
233 vjs.hardwareTypeNTSC = settings.value("hardwareTypeNTSC", true).toBool();
234 vjs.frameSkip = settings.value("frameSkip", 0).toInt();
235 vjs.useJaguarBIOS = settings.value("useJaguarBIOS", false).toBool();
236 vjs.DSPEnabled = settings.value("DSPEnabled", false).toBool();
237 vjs.usePipelinedDSP = settings.value("usePipelinedDSP", false).toBool();
238 vjs.fullscreen = settings.value("fullscreen", false).toBool();
239 vjs.useOpenGL = settings.value("useOpenGL", true).toBool();
240 vjs.glFilter = settings.value("glFilterType", 0).toInt();
241 vjs.renderType = settings.value("renderType", 0).toInt();
244 void MainWin::WriteSettings(void)
246 QSettings settings("Underground Software", "Virtual Jaguar");
247 settings.setValue("pos", pos());
248 settings.setValue("size", size());
250 settings.setValue("useJoystick", vjs.useJoystick);
251 settings.setValue("joyport", vjs.joyport);
252 settings.setValue("hardwareTypeNTSC", vjs.hardwareTypeNTSC);
253 settings.setValue("frameSkip", vjs.frameSkip);
254 settings.setValue("useJaguarBIOS", vjs.useJaguarBIOS);
255 settings.setValue("DSPEnabled", vjs.DSPEnabled);
256 settings.setValue("usePipelinedDSP", vjs.usePipelinedDSP);
257 settings.setValue("fullscreen", vjs.fullscreen);
258 settings.setValue("useOpenGL", vjs.useOpenGL);
259 settings.setValue("glFilterType", vjs.glFilter);
260 settings.setValue("renderType", vjs.renderType);