-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
312 lines (248 loc) · 7.58 KB
/
mainwindow.cpp
File metadata and controls
312 lines (248 loc) · 7.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QWaitCondition>
#include <QMutex>
#include "Joy/Gamepad.h"
int joyIndex(Gamepad_device * device)
{
for(int i = 0; i < Gamepad_numDevices(); i++)
{
if(device==Gamepad_deviceAtIndex(i))return i;
}
return -1;
}
bool onButtonDown(void * sender, const char * eventID, void * eventData, void * context)
{
struct Gamepad_buttonEvent * event;
MainWindow *mw=(MainWindow*)context;
event = (Gamepad_buttonEvent *) eventData;
mw->PressJoyButton(joyIndex(event->device),event->buttonID);
return true;
}
bool onButtonUp(void * sender, const char * eventID, void * eventData, void * context)
{
return true;
}
bool onAxisMoved(void * sender, const char * eventID, void * eventData, void * context)
{
MainWindow *mw=(MainWindow*)context;
static int direct=0;
static int dev=-1,ind=-1;
struct Gamepad_axisEvent * event;
int curr_dev, curr_ind, curr_dir;
event = (Gamepad_axisEvent *) eventData;
curr_dev=joyIndex(event->device);
curr_ind=event->axisID;
if(event->value<-0.5)curr_dir=-1;
else if(event->value>0.5)curr_dir=1;
else
{
direct=0;
return true;
}
if(dev!=curr_dev || ind!=curr_ind || direct!=curr_dir)
{
dev=curr_dev;
ind=curr_ind;
direct=curr_dir;
mw->PressJoyAxis(dev,ind,direct);
}
return true;
}
bool onDeviceAttached(void * sender, const char * eventID, void * eventData, void * context)
{
struct Gamepad_device * device;
device = (Gamepad_device *)eventData;
device->eventDispatcher->registerForEvent(device->eventDispatcher, GAMEPAD_EVENT_BUTTON_DOWN, onButtonDown, context);
device->eventDispatcher->registerForEvent(device->eventDispatcher, GAMEPAD_EVENT_BUTTON_UP, onButtonUp, context);
device->eventDispatcher->registerForEvent(device->eventDispatcher, GAMEPAD_EVENT_AXIS_MOVED, onAxisMoved, context);
return true;
}
bool onDeviceRemoved(void * sender, const char * eventID, void * eventData, void * context)
{
struct Gamepad_device * device;
device = (Gamepad_device *)eventData;
return true;
}
void Sleep(int ms)
{
QWaitCondition sleep;
QMutex mutex;
mutex.lock();
sleep.wait(&mutex, ms);
mutex.unlock();
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
glout=new GLWidget(this);
setCentralWidget(glout);
joyconf=new InputConf(this);
_emulator_init();
_emulator_key_state_reset();
emu=new EmuThread;
connect(emu,SIGNAL(SendPaintMess()),glout,SLOT(BuffRedraw()));
connect(glout,SIGNAL(UpdateFrameComplited()),emu,SLOT(UpdateFrameComplited()));
connect(this,SIGNAL(SelectGame(QString)),emu,SLOT(SelectGame(QString)));
connect(this,SIGNAL(SelectBios(QString,int)),emu,SLOT(SelectBios(QString,int)));
emu->start();
Gamepad_eventDispatcher()->registerForEvent(Gamepad_eventDispatcher(), GAMEPAD_EVENT_DEVICE_ATTACHED, onDeviceAttached, this);
Gamepad_eventDispatcher()->registerForEvent(Gamepad_eventDispatcher(), GAMEPAD_EVENT_DEVICE_REMOVED, onDeviceRemoved, this);
Gamepad_init();
up_joy_devices=new QTimer(this);
connect(up_joy_devices, SIGNAL(timeout()), this, SLOT(updateDevices()));
up_joy_devices->start(1000);
up_joy_inputs=new QTimer(this);
connect(up_joy_inputs, SIGNAL(timeout()), this, SLOT(updateJoyGadgets()));
up_joy_inputs->start(20);
opt=new QSettings("freedo.cfg",QSettings::IniFormat);
joyconf->cfg=opt;
joyconf->UpdateInputList();
//инициализация иконки
setWindowIcon(QIcon(":/pics/logo.png"));
emit SelectGame(opt->value("Game","").toString());
emit SelectBios(opt->value("BIOS/Main","").toString(),0);
emit SelectBios(opt->value("BIOS/Lang","").toString(),1);
glout->keep_aspect=opt->value("Video/KeepAspect",true).toBool();
ui->actionKeep_Aspect->setChecked(glout->keep_aspect);
}
void MainWindow::PressJoyAxis(int dev, int ind, int dir)
{
joyconf->PressJoyAxis(dev, ind, dir);
}
void MainWindow::PressJoyButton(int dev, int ind)
{
joyconf->PressJoyButton(dev,ind);
}
void MainWindow::updateDevices()
{
Gamepad_detectDevices();
}
void MainWindow::updateJoyGadgets()
{
Gamepad_processEvents();
_emulator_fill_pbus(joyconf->GetInputList());
}
MainWindow::~MainWindow()
{
up_joy_devices->stop();
up_joy_inputs->stop();
delete up_joy_devices;
delete up_joy_inputs;
Gamepad_shutdown();
emu->stop();
while(!emu->isFinished())
{
Sleep(10);
}
delete glout;
delete ui;
_emulator_exit();
delete opt;
}
void MainWindow::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void MainWindow::on_actionAbout_triggered()
{
QMessageBox::about(this,
tr("About FreeDO"),
tr("Copyright (C) 2011 FreeDO Team."
"<p>Original project site: www.freedo.org"
));
}
void MainWindow::on_actionExit_triggered()
{
this->close();
}
void MainWindow::on_actionStart_triggered()
{
emu->RunStopCPU();
_emulator_key_state_reset();
}
void MainWindow::keyPressEvent(QKeyEvent* event)
{
_emulator_key_state(event->key(),true);
if(event->key()==Qt::Key_F9)
{
ui->actionFullscreen->setChecked(!ui->actionFullscreen->isChecked());
on_actionFullscreen_triggered();
}
else if(event->key()==Qt::Key_F4)
{
on_actionScreenshot_triggered();
}
}
void MainWindow::keyReleaseEvent(QKeyEvent* event)
{
_emulator_key_state(event->key(),false);
}
void MainWindow::on_actionInput_triggered()
{
joyconf->show();
}
void MainWindow::on_actionOpen_ISO_triggered()
{
QString game=QFileDialog::getOpenFileName(this,"Open game image",opt->value("Game","").toString());
emit SelectGame(game);
opt->setValue("Game",game);
}
void MainWindow::on_actionPause_Resume_triggered()
{
emu->PauseResumeCPU();
}
void MainWindow::on_actionSelect_BIOS_triggered()
{
QString name=QFileDialog::getOpenFileName(this,"Open main BIOS ROM",opt->value("BIOS/Main","").toString());
emit SelectBios(name,0);
opt->setValue("BIOS/Main",name);
}
void MainWindow::on_actionSelect_Lang_BIOS_triggered()
{
QString name=QFileDialog::getOpenFileName(this,"Open lang BIOS ROM",opt->value("BIOS/Lang","").toString());
emit SelectBios(name,1);
opt->setValue("BIOS/Lang",name);
}
void MainWindow::on_actionFullscreen_triggered()
{
if(ui->actionFullscreen->isChecked())
{
this->showFullScreen();
this->statusBar()->setVisible(false);
this->menuBar()->setVisible(false);
this->setCursor(QCursor(Qt::BlankCursor));
}
else
{
this->showNormal();
this->statusBar()->setVisible(true);
this->menuBar()->setVisible(true);
this->setCursor(QCursor(Qt::ArrowCursor));
}
}
void MainWindow::on_actionScreenshot_triggered()
{
QString str;
QDateTime time;
time=time.currentDateTime();
str=opt->value("Game","").toString();
str+="_"+time.toString("dd-MM-yyyy-hh-mm-ss-zzz");
str+=".png";
glout->ScreenShot(str);
}
void MainWindow::on_actionKeep_Aspect_triggered()
{
glout->keep_aspect=ui->actionKeep_Aspect->isChecked();
opt->setValue("Video/KeepAspect",glout->keep_aspect);
glout->BuffRedraw();
}