]> Shamusworld >> Repos - virtualjaguar/blob - src/gui/mainwin.cpp
Beginnings of UI goodness... ;-)
[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 //
12
13 // FIXED:
14 //
15 //
16 // STILL TO BE DONE:
17 //
18 //
19
20 // Uncomment this for debugging...
21 //#define DEBUG
22 //#define DEBUGFOO                      // Various tool debugging...
23 //#define DEBUGTP                               // Toolpalette debugging...
24
25 //#include <QtGui>
26 #include "mainwin.h"
27
28 //#include <QtOpenGL>
29 #include "glwidget.h"
30 //#include "editwindow.h"
31 //#include "charwindow.h"
32 //#include "ttedit.h"
33
34 MainWin::MainWin(): running(true)
35 {
36         // The way BSNES controls things is by setting a timer with a zero
37         // timeout, sleeping if not emulating anything. Seems there has to be a
38         // better way.
39
40         // It has a novel approach to plugging-in/using different video/audio/input
41         // methods, can we do something similar or should we just use the built-in
42         // QOpenGL?
43
44         // We're going to try to use the built-in OpenGL support and see how it goes.
45         // We'll make the VJ core modular so that it doesn't matter what GUI is in
46         // use, we can drop it in anywhere and use it as-is.
47
48 //      ((TTEdit *)qApp)->charWnd = new CharWindow(this);
49         videoWidget = new GLWidget(this);
50         setCentralWidget(videoWidget);
51         setWindowIcon(QIcon(":/res/vj.xpm"));
52         setWindowTitle("Virtual Jaguar v2.0.0");
53
54         QMenu * menu = menuBar()->addMenu(tr("&File"));
55         QToolBar * toolbar = addToolBar(tr("x1"));
56         /*QAction */ action = new QAction(tr("Toggle"), this);
57         action->setStatusTip(tr("Toggle running state"));
58         action->setCheckable(true);
59         toolbar->addAction(action);
60         connect(action, SIGNAL(triggered()), this, SLOT(ToggleRunState()));
61 #if 0
62 //      createActions();
63         newAct = new QAction(QIcon(":/images/new.png"), tr("&New"), this);
64         newAct->setShortcuts(QKeySequence::New);
65         newAct->setStatusTip(tr("Create a new file"));
66         connect(newAct, SIGNAL(triggered()), this, SLOT(newFile()));
67
68         openAct = new QAction(QIcon(":/images/open.png"), tr("&Open..."), this);
69         openAct->setShortcuts(QKeySequence::Open);
70         openAct->setStatusTip(tr("Open an existing file"));
71         connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
72
73         aboutQtAct = new QAction(tr("About &Qt"), this);
74         aboutQtAct->setStatusTip(tr("Show the Qt library's About box"));
75         connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
76
77 //      createMenus();
78         fileMenu = menuBar()->addMenu(tr("&File"));
79         fileMenu->addAction(newAct);
80         fileMenu->addAction(openAct);
81         fileMenu->addAction(saveAct);
82         fileMenu->addAction(saveAsAct);
83         fileMenu->addSeparator();
84         fileMenu->addAction(exitAct);
85
86         editMenu = menuBar()->addMenu(tr("&Edit"));
87         editMenu->addAction(cutAct);
88         editMenu->addAction(copyAct);
89         editMenu->addAction(pasteAct);
90
91         menuBar()->addSeparator();
92
93         helpMenu = menuBar()->addMenu(tr("&Help"));
94         helpMenu->addAction(aboutAct);
95         helpMenu->addAction(aboutQtAct);
96
97 //      createToolBars();
98         fileToolBar = addToolBar(tr("File"));
99         fileToolBar->addAction(newAct);
100         fileToolBar->addAction(openAct);
101         fileToolBar->addAction(saveAct);
102
103         editToolBar = addToolBar(tr("Edit"));
104         editToolBar->addAction(cutAct);
105         editToolBar->addAction(copyAct);
106         editToolBar->addAction(pasteAct);
107 #endif
108
109         //      Create status bar
110         statusBar()->showMessage(tr("Ready"));
111
112         ReadSettings();
113
114 //      connect(textEdit->document(), SIGNAL(contentsChanged()),
115 //                      this, SLOT(documentWasModified()));
116
117 //      setCurrentFile("");
118         setUnifiedTitleAndToolBarOnMac(true);
119
120         // Set up timer based loop for animation...
121         timer = new QTimer(this);
122         connect(timer, SIGNAL(timeout()), this, SLOT(Timer()));
123         timer->start(20);
124 }
125
126 void MainWin::closeEvent(QCloseEvent * event)
127 {
128         WriteSettings();
129         event->accept(); // ignore() if can't close for some reason
130 }
131
132 void MainWin::Open(void)
133 {
134 }
135
136 void MainWin::Timer(void)
137 {
138         if (!running)
139                 return;
140
141         // Random hash & trash
142         // We try to simulate an untuned tank circuit here... :-)
143         for(int x=0; x<videoWidget->rasterWidth; x++)
144         {
145                 for(int y=0; y<videoWidget->rasterHeight; y++)
146                 {
147                         videoWidget->buffer[(y * videoWidget->textureWidth) + x] = (rand() & 0xFF) << 8 | (rand() & 0xFF) << 16 | (rand() & 0xFF) << 24;// | (rand() & 0xFF);//0x000000FF;
148 //                      buffer[(y * textureWidth) + x] = x*y;
149                 }
150         }
151
152         videoWidget->updateGL();
153 }
154
155 void MainWin::ToggleRunState(void)
156 {
157         running = !running;
158 }
159
160 void MainWin::ReadSettings(void)
161 {
162         QSettings settings("Underground Software", "Virtual Jaguar");
163         QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
164         QSize size = settings.value("size", QSize(400, 400)).toSize();
165         resize(size);
166         move(pos);
167 //videoWidget->updateGL();
168 //      pos = settings.value("charWndPos", QPoint(0, 0)).toPoint();
169 //      size = settings.value("charWndSize", QSize(200, 200)).toSize();
170 //      ((TTEdit *)qApp)->charWnd->resize(size);
171 //      ((TTEdit *)qApp)->charWnd->move(pos);
172 }
173
174 void MainWin::WriteSettings(void)
175 {
176         QSettings settings("Underground Software", "Virtual Jaguar");
177         settings.setValue("pos", pos());
178         settings.setValue("size", size());
179 //      settings.setValue("charWndPos", ((TTEdit *)qApp)->charWnd->pos());
180 //      settings.setValue("charWndSize", ((TTEdit *)qApp)->charWnd->size());
181 }
182