]> Shamusworld >> Repos - virtualjaguar/blob - src/gui/mainwin.cpp
Initial changeset to experimental branch
[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()
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 //      ((TTEdit *)qApp)->charWnd = new CharWindow(this);
45         videoWidget = new GLWidget(this);
46         setCentralWidget(videoWidget);
47         setWindowIcon(QIcon(":/res/vj.xpm"));
48         setWindowTitle("Virtual Jaguar v2.0.0");
49
50 #if 0
51 //      createActions();
52         newAct = new QAction(QIcon(":/images/new.png"), tr("&New"), this);
53         newAct->setShortcuts(QKeySequence::New);
54         newAct->setStatusTip(tr("Create a new file"));
55         connect(newAct, SIGNAL(triggered()), this, SLOT(newFile()));
56
57         openAct = new QAction(QIcon(":/images/open.png"), tr("&Open..."), this);
58         openAct->setShortcuts(QKeySequence::Open);
59         openAct->setStatusTip(tr("Open an existing file"));
60         connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
61
62         aboutQtAct = new QAction(tr("About &Qt"), this);
63         aboutQtAct->setStatusTip(tr("Show the Qt library's About box"));
64         connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
65
66 //      createMenus();
67         fileMenu = menuBar()->addMenu(tr("&File"));
68         fileMenu->addAction(newAct);
69         fileMenu->addAction(openAct);
70         fileMenu->addAction(saveAct);
71         fileMenu->addAction(saveAsAct);
72         fileMenu->addSeparator();
73         fileMenu->addAction(exitAct);
74
75         editMenu = menuBar()->addMenu(tr("&Edit"));
76         editMenu->addAction(cutAct);
77         editMenu->addAction(copyAct);
78         editMenu->addAction(pasteAct);
79
80         menuBar()->addSeparator();
81
82         helpMenu = menuBar()->addMenu(tr("&Help"));
83         helpMenu->addAction(aboutAct);
84         helpMenu->addAction(aboutQtAct);
85
86 //      createToolBars();
87         fileToolBar = addToolBar(tr("File"));
88         fileToolBar->addAction(newAct);
89         fileToolBar->addAction(openAct);
90         fileToolBar->addAction(saveAct);
91
92         editToolBar = addToolBar(tr("Edit"));
93         editToolBar->addAction(cutAct);
94         editToolBar->addAction(copyAct);
95         editToolBar->addAction(pasteAct);
96 #endif
97
98         //      Create status bar
99         statusBar()->showMessage(tr("Ready"));
100
101         ReadSettings();
102
103 //      connect(textEdit->document(), SIGNAL(contentsChanged()),
104 //                      this, SLOT(documentWasModified()));
105
106 //      setCurrentFile("");
107         setUnifiedTitleAndToolBarOnMac(true);
108
109         // Set up timer based loop for animation...
110         timer = new QTimer(this);
111         connect(timer, SIGNAL(timeout()), this, SLOT(Timer()));
112         timer->start(20);
113 }
114
115 void MainWin::closeEvent(QCloseEvent * event)
116 {
117         WriteSettings();
118         event->accept(); // ignore() if can't close for some reason
119 }
120
121 void MainWin::Open(void)
122 {
123 }
124
125 void MainWin::Timer(void)
126 {
127         // Random hash & trash
128         // We try to simulate an untuned tank circuit here... :-)
129         for(int x=0; x<videoWidget->rasterWidth; x++)
130         {
131                 for(int y=0; y<videoWidget->rasterHeight; y++)
132                 {
133                         videoWidget->buffer[(y * videoWidget->textureWidth) + x] = (rand() & 0xFF) << 8 | (rand() & 0xFF) << 16 | (rand() & 0xFF) << 24;// | (rand() & 0xFF);//0x000000FF;
134 //                      buffer[(y * textureWidth) + x] = x*y;
135                 }
136         }
137
138         videoWidget->updateGL();
139 }
140
141 void MainWin::ReadSettings(void)
142 {
143         QSettings settings("Underground Software", "Virtual Jaguar");
144         QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
145         QSize size = settings.value("size", QSize(400, 400)).toSize();
146         resize(size);
147         move(pos);
148 //videoWidget->updateGL();
149 //      pos = settings.value("charWndPos", QPoint(0, 0)).toPoint();
150 //      size = settings.value("charWndSize", QSize(200, 200)).toSize();
151 //      ((TTEdit *)qApp)->charWnd->resize(size);
152 //      ((TTEdit *)qApp)->charWnd->move(pos);
153 }
154
155 void MainWin::WriteSettings(void)
156 {
157         QSettings settings("Underground Software", "Virtual Jaguar");
158         settings.setValue("pos", pos());
159         settings.setValue("size", size());
160 //      settings.setValue("charWndPos", ((TTEdit *)qApp)->charWnd->pos());
161 //      settings.setValue("charWndSize", ((TTEdit *)qApp)->charWnd->size());
162 }
163