OSDN Git Service

[VM][FM7][Qt][GL] Add option to src/vm/{$VMNAME}/${VMNAME}.h USE_CRT_MONITOR_4_3.
[csp-qt/common_source_project-fm7.git] / source / src / qt / gui / mainwindow_utils.cpp
1 /*
2  * UI->Qt->MainWindow : Some Utils.
3  * (C) 2015 K.Ohta <whatisthis.sowhat _at_ gmail.com>
4  * License: GPLv2
5  *
6  * History:
7  * Jan 24, 2014 : Moved from some files.
8  */
9
10 #include "commonclasses.h"
11 #include "mainwidget.h"
12 #include "qt_gldraw.h"
13
14 //#include "menuclasses.h"
15 #include "qt_dialogs.h"
16 #include "emu.h"
17 #include "agar_logger.h"
18
19 QT_BEGIN_NAMESPACE
20
21 extern const int s_freq_table[];
22 extern const double s_late_table[];
23
24 void Ui_MainWindow::set_latency(int num)
25 {
26         if((num < 0) || (num > 4)) return;
27         config.sound_latency = num;
28         emit sig_emu_update_config();
29 }
30
31 void Ui_MainWindow::set_freq(int num)
32 {
33         if((num < 0) || (num > 7)) return;
34         config.sound_frequency = num;
35         emit sig_emu_update_config();
36 }
37
38 void Ui_MainWindow::set_sound_device(int num)
39 {
40 #ifdef USE_SOUND_DEVICE_TYPE
41         if((num < 0) || (num >7)) return;
42         config.sound_device_type = num;
43         emit sig_emu_update_config();
44 #endif
45 }
46
47
48
49 void Ui_MainWindow::start_record_sound(bool start)
50 {
51         if(start) {
52                 emit sig_emu_start_rec_sound();
53         } else {
54                 emit sig_emu_stop_rec_sound();
55         }
56 }
57
58 void Ui_MainWindow::set_monitor_type(int num)
59 {
60 #ifdef USE_MONITOR_TYPE
61         if((num < 0) || (num >7)) return;
62         config.monitor_type = num;
63         emit sig_emu_update_config();
64 #endif
65 }
66
67 #if defined(USE_SCANLINE)
68 void Ui_MainWindow::set_scan_line(bool flag)
69 {
70         if(flag) {
71                 config.scan_line = ~0;
72         } else {
73                 config.scan_line = 0;
74         }
75         emit sig_emu_update_config();
76 }
77 #endif
78
79 #if defined(USE_SCREEN_ROTATE)
80 void Ui_MainWindow::set_screen_rotate(bool flag)
81 {
82         config.rotate_type = flag;
83         if(config.window_mode >= _SCREEN_MODE_NUM) config.window_mode = _SCREEN_MODE_NUM - 1;
84         if(config.window_mode < 0) config.window_mode = 0;
85         if(actionScreenSize[config.window_mode] != NULL) {
86                 actionScreenSize[config.window_mode]->binds->set_screen_size();
87         }
88 }
89 #endif
90 #if defined(USE_CRT_FILTER)
91 void Ui_MainWindow::set_crt_filter(bool flag)
92 {
93         config.crt_filter = flag;
94 }
95 #endif
96
97 void Ui_MainWindow::set_gl_crt_filter(bool flag)
98 {
99         config.use_opengl_filters = flag;
100 }
101
102 #ifdef DATAREC_SOUND
103 void Ui_MainWindow::set_cmt_sound(bool flag)
104 {
105         config.tape_sound = flag;
106         emit sig_emu_update_config();
107 }
108 #endif
109 #ifdef USE_DEVICE_TYPE
110 void Ui_MainWindow::set_device_type(int num)
111 {
112         if((num < USE_DEVICE_TYPE) && (num >= 0)) {
113                 config.device_type = num;
114                 emit sig_emu_update_config();
115         }
116 }
117 #endif
118
119 #ifdef USE_DRIVE_TYPE
120 void Ui_MainWindow::set_drive_type(int num)
121 {
122         if((num < USE_DRIVE_TYPE) && (num >= 0)) {
123                 config.drive_type = num;
124                 emit sig_emu_update_config();
125         }
126 }
127 #endif
128    
129
130 void Ui_MainWindow::set_screen_size(int w, int h)
131 {
132         if((w <= 0) || (h <= 0)) return;
133 #if defined(USE_SCREEN_ROTATE)
134         if(config.rotate_type) {
135                 this->graphicsView->setFixedSize(h, w);
136         } else
137 #endif     
138         {
139                 this->graphicsView->setFixedSize(w, h);
140         }
141         this->resize_statusbar(w, h);
142    
143         MainWindow->centralWidget()->adjustSize();
144         MainWindow->adjustSize();
145 }
146
147 void Ui_MainWindow::set_screen_aspect(int num)
148 {
149         if((num < 0) || (num >= 3)) return;
150         // 0 = DOT
151         // 1 = ASPECT
152         // 2 = FILL
153         // On Common Sourcecode Project / Agar,
154         // Scaling is done by Agar Widget.
155         // So, does need below action?
156         // Maybe, needs Agar's changing action. 
157         
158         config.stretch_type = num;
159         
160         if(emu) {
161                 int w, h, n;
162                 double nd;
163                 n = config.window_mode;
164                 if(n < 0) n = 1;
165                 nd = actionScreenSize[n]->binds->getDoubleValue();
166                 w = (int)(nd * (double)SCREEN_WIDTH);
167                 h = (int)(nd * (double)SCREEN_HEIGHT);
168 #if defined(USE_CRT_MONITOR_4_3)
169                 if(config.stretch_type == 1) {
170                         h = (int)((double)h * ((double)SCREEN_WIDTH / (double)SCREEN_HEIGHT * 3.0 / 4.0));
171                 } else if(config.stretch_type == 2) {
172                         w = (int)((double)w * (4.0 / (3.0 * (double)SCREEN_WIDTH / (double)SCREEN_HEIGHT)));
173                 }
174                 //printf("%d x %d\n", w, h);
175 #endif
176                 this->set_screen_size(w, h);
177         }
178         
179 }
180
181
182 void Ui_MainWindow::ConfigDeviceType(void)
183 {
184 #if defined(USE_DEVICE_TYPE)
185         {
186                 int ii;
187                 menuDeviceType = new QMenu(menuMachine);
188                 menuDeviceType->setObjectName(QString::fromUtf8("menuDeviceType"));
189                 menuMachine->addAction(menuDeviceType->menuAction());
190       
191                 actionGroup_DeviceType = new QActionGroup(this);
192                 actionGroup_DeviceType->setExclusive(true);
193                 for(ii = 0; ii < USE_DEVICE_TYPE; ii++) {
194                         actionDeviceType[ii] = new Action_Control(this);
195                         actionGroup_DeviceType->addAction(actionDeviceType[ii]);
196                         actionDeviceType[ii]->setCheckable(true);
197                         actionDeviceType[ii]->setVisible(true);
198                         actionDeviceType[ii]->binds->setValue1(ii);
199                         if(config.device_type == ii) actionDeviceType[ii]->setChecked(true);
200                         menuDeviceType->addAction(actionDeviceType[ii]);
201                         connect(actionDeviceType[ii], SIGNAL(triggered()),
202                                 actionDeviceType[ii]->binds, SLOT(do_set_device_type()));
203                         connect(actionDeviceType[ii]->binds, SIGNAL(sig_device_type(int)),
204                                 this, SLOT(set_device_type(int)));
205                 }
206         }
207 #endif
208 }
209
210 void Ui_MainWindow::ConfigDriveType(void)
211 {
212         int i;
213 #ifdef USE_DRIVE_TYPE
214         menuDriveType = new QMenu(menuMachine);
215         menuDriveType->setObjectName(QString::fromUtf8("menu_DriveType"));
216    
217         actionGroup_DriveType = new QActionGroup(this);
218         actionGroup_DriveType->setObjectName(QString::fromUtf8("actionGroup_DriveType"));
219         actionGroup_DriveType->setExclusive(true);
220         menuMachine->addAction(menuDriveType->menuAction());
221         for(i = 0; i < USE_DRIVE_TYPE; i++) {
222                 actionDriveType[i] = new Action_Control(this);
223                 actionDriveType[i]->setCheckable(true);
224                 actionDriveType[i]->setVisible(true);
225                 actionDriveType[i]->binds->setValue1(i);
226                 if(i == config.drive_type) actionDriveType[i]->setChecked(true); // Need to write configure
227                 actionGroup_DriveType->addAction(actionDriveType[i]);
228                 menuDriveType->addAction(actionDriveType[i]);
229                 connect(actionDriveType[i], SIGNAL(triggered()),
230                         actionDriveType[i]->binds, SLOT(do_set_drive_type()));
231                 connect(actionDriveType[i]->binds, SIGNAL(sig_drive_type(int)),
232                         this, SLOT(set_drive_type(int)));
233         }
234 #endif
235 }
236
237 void Ui_MainWindow::ConfigSoundDeviceType(void)
238 {
239 #ifdef USE_SOUND_DEVICE_TYPE
240         int i;
241         QString tmps;
242         menuSoundDevice = new QMenu(menuMachine);
243         menuSoundDevice->setObjectName(QString::fromUtf8("menu_SoundDevice"));
244    
245         actionGroup_SoundDevice = new QActionGroup(this);
246         actionGroup_SoundDevice->setObjectName(QString::fromUtf8("actionGroup_SoundDevice"));
247         actionGroup_SoundDevice->setExclusive(true);
248         menuMachine->addAction(menuSoundDevice->menuAction());   
249         for(i = 0; i < USE_SOUND_DEVICE_TYPE; i++) {
250                 actionSoundDevice[i] = new Action_Control(this);
251                 actionSoundDevice[i]->setCheckable(true);
252                 actionSoundDevice[i]->binds->setValue1(i);
253                 if(i == config.sound_device_type) actionSoundDevice[i]->setChecked(true); // Need to write configure
254                 tmps = QString::fromUtf8("actionSoundDevice_");
255                 actionSoundDevice[i]->setObjectName(tmps + QString::number(i));
256                 menuSoundDevice->addAction(actionSoundDevice[i]);
257                 actionGroup_SoundDevice->addAction(actionSoundDevice[i]);
258                 connect(actionSoundDevice[i], SIGNAL(triggered()),
259                         actionSoundDevice[i]->binds, SLOT(do_set_sound_device()));
260                 connect(actionSoundDevice[i]->binds, SIGNAL(sig_sound_device(int)),
261                         this, SLOT(set_sound_device(int)));
262         }
263 #endif
264 }
265
266 void Ui_MainWindow::ConfigPrinterType(void)
267 {
268 #if defined(USE_PRINTER)
269         int i;
270         QString tmps;
271         int ilim = 2;
272   #if defined(USE_PRINTER_TYPE)
273         ilim = USE_PRINTER_TYPE;
274   #endif        
275         menuPrintDevice = new QMenu(menuMachine);
276         menuPrintDevice->setObjectName(QString::fromUtf8("menu_PrintDevice"));
277    
278         actionGroup_PrintDevice = new QActionGroup(this);
279         actionGroup_PrintDevice->setObjectName(QString::fromUtf8("actionGroup_PrintDevice"));
280         actionGroup_PrintDevice->setExclusive(true);
281         menuMachine->addAction(menuPrintDevice->menuAction());   
282         for(i = 0; i < ilim; i++) {
283                 actionPrintDevice[i] = new Action_Control(this);
284                 actionPrintDevice[i]->setCheckable(true);
285                 actionPrintDevice[i]->binds->setValue1(i);
286                 if(i == config.printer_device_type) actionPrintDevice[i]->setChecked(true); // Need to write configure
287                 tmps = QString::fromUtf8("actionPrintDevice_");
288                 actionPrintDevice[i]->setObjectName(tmps + QString::number(i));
289                 menuPrintDevice->addAction(actionPrintDevice[i]);
290                 actionGroup_PrintDevice->addAction(actionPrintDevice[i]);
291                 connect(actionPrintDevice[i], SIGNAL(triggered()),
292                         actionPrintDevice[i]->binds, SLOT(do_set_printer_device()));
293                 connect(actionPrintDevice[i]->binds, SIGNAL(sig_printer_device(int)),
294                         this, SLOT(set_printer_device(int)));
295         }
296 #endif
297 }
298
299
300 #if defined(USE_PRINTER)
301 void Ui_MainWindow::set_printer_device(int p_type)
302 {
303         // 0 = PRNFILE
304         if(p_type < 0) p_type = 0; // OK?
305 #if defined(USE_PRINTER_TYPE)
306         if(p_type >= USE_PRINTER_TYPE) p_type = USE_PRINTER_TYPE - 1;
307 #else
308         if(p_type >= 2) p_type = 1;
309 #endif  
310         config.printer_device_type = p_type;
311 }
312 #endif
313 QT_END_NAMESPACE