]> Shamusworld >> Repos - virtualjaguar/blob - src/gui/mainwin.cpp
Added some icons, reconnected settings, added start of GUI control over
[virtualjaguar] / src / gui / mainwin.cpp
1 //
2 // mainwin.cpp - Qt-based GUI for Virtual Jaguar: Main Application Window
3 // by James L. Hammons
4 // (C) 2009 Underground Software
5 //
6 // JLH = James L. Hammons <jlhamm@acm.org>
7 //
8 // Who  When        What
9 // ---  ----------  -------------------------------------------------------------
10 // JLH  12/23/2009  Created this file
11 // JLH  12/20/2010  Added settings, menus & toolbars
12 //
13
14 // FIXED:
15 //
16 //
17 // STILL TO BE DONE:
18 //
19 //
20
21 // Uncomment this for debugging...
22 //#define DEBUG
23 //#define DEBUGFOO                      // Various tool debugging...
24 //#define DEBUGTP                               // Toolpalette debugging...
25
26 #include "mainwin.h"
27
28 //#include <QtGui>
29 //#include <QtOpenGL>
30 #include "glwidget.h"
31 #include "settings.h"
32
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
35 // better way.
36
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
39 // QOpenGL?
40
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.
44
45 MainWin::MainWin()
46 {
47         videoWidget = new GLWidget(this);
48         setCentralWidget(videoWidget);
49         setWindowIcon(QIcon(":/res/vj.xpm"));
50         setWindowTitle("Virtual Jaguar v2.0.0");
51
52         // Create actions
53
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()));
58
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()));
63
64         zoomActs = new QActionGroup(this);
65
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(???()));
70
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(???()));
75
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(???()));
80
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()));
85
86         // Create menus & toolbars
87
88         QMenu * fileMenu = menuBar()->addMenu(tr("&File"));
89         fileMenu->addAction(action);
90         fileMenu->addAction(quitAppAct);
91
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);
98 #if 0
99 //      createActions();
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()));
104
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()));
109
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()));
113
114 //      createMenus();
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);
122
123         editMenu = menuBar()->addMenu(tr("&Edit"));
124         editMenu->addAction(cutAct);
125         editMenu->addAction(copyAct);
126         editMenu->addAction(pasteAct);
127
128         menuBar()->addSeparator();
129
130         helpMenu = menuBar()->addMenu(tr("&Help"));
131         helpMenu->addAction(aboutAct);
132         helpMenu->addAction(aboutQtAct);
133
134 //      createToolBars();
135         fileToolBar = addToolBar(tr("File"));
136         fileToolBar->addAction(newAct);
137         fileToolBar->addAction(openAct);
138         fileToolBar->addAction(saveAct);
139
140         editToolBar = addToolBar(tr("Edit"));
141         editToolBar->addAction(cutAct);
142         editToolBar->addAction(copyAct);
143         editToolBar->addAction(pasteAct);
144 #endif
145
146         //      Create status bar
147         statusBar()->showMessage(tr("Ready"));
148
149         ReadSettings();
150         setUnifiedTitleAndToolBarOnMac(true);
151
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();
156
157         // Set up timer based loop for animation...
158         timer = new QTimer(this);
159         connect(timer, SIGNAL(timeout()), this, SLOT(Timer()));
160         timer->start(20);
161 }
162
163 void MainWin::closeEvent(QCloseEvent * event)
164 {
165         WriteSettings();
166         event->accept(); // ignore() if can't close for some reason
167 }
168
169 void MainWin::Open(void)
170 {
171 }
172
173 void MainWin::Timer(void)
174 {
175         if (!running)
176                 return;
177
178         // Random hash & trash
179         // We try to simulate an untuned tank circuit here... :-)
180         for(uint32_t x=0; x<videoWidget->rasterWidth; x++)
181         {
182                 for(uint32_t y=0; y<videoWidget->rasterHeight; y++)
183                 {
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;
186                 }
187         }
188
189         videoWidget->updateGL();
190 }
191
192 void MainWin::ToggleRunState(void)
193 {
194         running = !running;
195
196         if (!running)
197         {
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;
201
202                 videoWidget->updateGL();
203         }
204 }
205
206 void MainWin::SetZoom100(void)
207 {
208 }
209
210 void MainWin::SetZoom200(void)
211 {
212 }
213
214 void MainWin::SetZoom300(void)
215 {
216 }
217
218 void MainWin::ToggleBlur(void)
219 {
220         vjs.glFilter = !vjs.glFilter;
221 }
222
223 void MainWin::ReadSettings(void)
224 {
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();
228         resize(size);
229         move(pos);
230
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();
242 }
243
244 void MainWin::WriteSettings(void)
245 {
246         QSettings settings("Underground Software", "Virtual Jaguar");
247         settings.setValue("pos", pos());
248         settings.setValue("size", size());
249
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);
261 }
262