OSDN Git Service

[Draw][Qt] GLv3: Zoom size of temporally texture(s) to x4.Drawing to temporally textu...
[csp-qt/common_source_project-fm7.git] / source / src / qt / gui / menu_screen.cpp
1 /*
2  * Common Source code Project:
3  * Ui->Qt->gui->menu_main for generic.
4  * (C) 2015 K.Ohta <whatisthis.sowhat _at_ gmail.com>
5  *   License : GPLv2
6  *   History :
7  * Jan 14, 2015 : Initial, moved from qt/x1turboz/MainWindow.cpp .
8  */
9
10 #include <QtCore/QVariant>
11 #include <QtGui>
12 #include "commonclasses.h"
13 #include "mainwidget_base.h"
14 //#include "menuclasses.h"
15 #include "qt_main.h"
16 #include "qt_gldraw.h"
17 #include "menu_flags.h"
18
19 //extern USING_FLAGS *using_flags;
20 // WIP: Move another header.
21 #if (SCREEN_WIDTH > 320)
22 const static float screen_multiply_table[] = {0.5, 1.0, 1.5, 2.0, 2.25, 2.5, 3.0, 3.5, 4.0, 5.0, 6.0, 8.0, 0.0};
23 #else
24 const static float screen_multiply_table[] = {0.5, 1.0, 1.5, 2.0, 3.0, 4.0, 5.0, 6.0, 7.5, 10.0, 12.0, 15.0, 0.0};
25 #endif
26 void Object_Menu_Control::set_screen_aspect(void) {
27         int num = getValue1();
28         emit sig_screen_aspect(num);
29 }
30
31 void Object_Menu_Control::set_screen_size(void) {
32         int w, h;
33         double nd, ww, hh;
34         using_flags->get_config_ptr()->window_mode = getNumber();
35         nd = getDoubleValue();
36         ww = nd * (double)using_flags->get_screen_width();
37         hh = nd * (double)using_flags->get_screen_height();
38         if((using_flags->get_screen_height_aspect() != using_flags->get_screen_height()) ||
39            (using_flags->get_screen_width_aspect() != using_flags->get_screen_width())) {
40                 double par_w = (double)using_flags->get_screen_width_aspect() / (double)using_flags->get_screen_width();
41                 double par_h = (double)using_flags->get_screen_height_aspect() / (double)using_flags->get_screen_height();
42                 double par = par_h / par_w;
43                 if(using_flags->get_config_ptr()->window_stretch_type == 1) { // refer to X, scale Y.
44                         hh = hh * par_h;
45                 } else if(using_flags->get_config_ptr()->window_stretch_type == 2) { // refer to Y, scale X only
46                         ww = ww / par_h;
47                 } else if(using_flags->get_config_ptr()->window_stretch_type == 3) { // Scale both X, Y
48                         ww = ww * par_w;
49                         hh = hh * par_h;
50                 }
51         }
52         w = (int)ww;
53         h = (int)hh;
54         emit sig_screen_size(w, h);
55         emit sig_screen_multiply(nd);
56 }
57
58 void Object_Menu_Control::do_save_as_movie(void)
59 {
60         int fps = using_flags->get_config_ptr()->video_frame_rate;
61         emit sig_start_record_movie(fps);
62 }
63
64 void Object_Menu_Control::do_stop_saving_movie(void)
65 {
66         emit sig_stop_record_movie();
67 }
68
69
70 void Ui_MainWindowBase::do_stop_saving_movie(void)
71 {
72         emit sig_stop_saving_movie();
73 }
74
75 void Ui_MainWindowBase::do_start_saving_movie(void)
76 {
77         emit sig_start_saving_movie();
78 }
79
80 void Ui_MainWindowBase::do_set_render_mode_std(void)
81 {
82         using_flags->get_config_ptr()->rendering_type = CONFIG_RENDER_TYPE_STD;
83 }
84
85 void Ui_MainWindowBase::do_set_render_mode_tv(void)
86 {
87         using_flags->get_config_ptr()->rendering_type = CONFIG_RENDER_TYPE_TV;
88 }
89
90 void Ui_MainWindowBase::do_set_state_saving_movie(bool state)
91 {
92         actionStop_Record_Movie->setVisible(state);
93         actionStart_Record_Movie->setVisible(!state);
94 }       
95
96 void Ui_MainWindowBase::set_gl_scan_line_vert(bool f)
97 {
98         using_flags->get_config_ptr()->opengl_scanline_vert = f;
99 }
100
101 void Ui_MainWindowBase::set_gl_scan_line_horiz(bool f)
102 {
103         using_flags->get_config_ptr()->opengl_scanline_horiz = f;
104 }
105
106 void Ui_MainWindowBase::ConfigScreenMenu_List(void)
107 {
108         int w, h;
109         QString tmps;
110         int i;
111         
112         actionGroup_ScreenSize = new QActionGroup(this);
113         actionGroup_ScreenSize->setExclusive(true);
114         screen_mode_count = 0;
115         for(i = 0; i < using_flags->get_screen_mode_num(); i++) {
116                 w = (int)(screen_multiply_table[i] * (double)using_flags->get_screen_width());
117                 h = (int)(screen_multiply_table[i] * (double)using_flags->get_screen_height());
118                 if((w <= 0) || (h <= 0)) {
119                         break;
120                 }
121                 screen_mode_count++;
122                 tmps = QString::number(i);
123                 actionScreenSize[i] = new Action_Control(this, using_flags);
124                 actionScreenSize[i]->setObjectName(QString::fromUtf8("actionScreenSize", -1) + tmps);
125                 actionScreenSize[i]->setCheckable(true);
126                 actionScreenSize[i]->binds->setNumber(i);
127
128                 if(i == using_flags->get_config_ptr()->window_mode)  actionScreenSize[i]->setChecked(true);  // OK?
129
130                 actionGroup_ScreenSize->addAction(actionScreenSize[i]);
131                 actionScreenSize[i]->binds->setDoubleValue(screen_multiply_table[i]);
132                 
133                 connect(actionScreenSize[i], SIGNAL(triggered()),
134                         actionScreenSize[i]->binds, SLOT(set_screen_size()));
135
136                 connect(actionScreenSize[i]->binds, SIGNAL(sig_screen_size(int, int)),
137                         this, SLOT(set_screen_size(int, int)));
138         }
139         for(; i < using_flags->get_screen_mode_num(); i++) {
140                 actionScreenSize[i] = NULL;
141         }
142 }
143 void Ui_MainWindowBase::ConfigScreenMenu(void)
144 {
145         actionZoom = new Action_Control(this, using_flags);
146         actionZoom->setObjectName(QString::fromUtf8("actionZoom"));
147         actionDisplay_Mode = new Action_Control(this, using_flags);
148         actionDisplay_Mode->setObjectName(QString::fromUtf8("actionDisplay_Mode"));
149         
150         if(using_flags->is_use_scanline()) {
151                 actionScanLine = new Action_Control(this, using_flags);
152                 actionScanLine->setObjectName(QString::fromUtf8("actionScanLine"));
153                 actionScanLine->setCheckable(true);
154                 if(using_flags->get_config_ptr()->scan_line != 0) {
155                         actionScanLine->setChecked(true);
156                 } else {
157                         actionScanLine->setChecked(false);
158                 }
159                 connect(actionScanLine, SIGNAL(toggled(bool)),
160                         this, SLOT(set_scan_line(bool)));
161         }
162         if(!using_flags->is_use_one_board_computer() && (using_flags->get_max_button() <= 0)) {
163                 actionGLScanLineHoriz = new Action_Control(this, using_flags);
164                 actionGLScanLineHoriz->setObjectName(QString::fromUtf8("actionGLScanLineHoriz"));
165                 actionGLScanLineHoriz->setCheckable(true);
166                 if(using_flags->get_config_ptr()->opengl_scanline_horiz != 0) {
167                         actionGLScanLineHoriz->setChecked(true);
168                 } else {
169                         actionGLScanLineHoriz->setChecked(false);
170                 }
171                 connect(actionGLScanLineHoriz, SIGNAL(toggled(bool)),
172                                 this, SLOT(set_gl_scan_line_horiz(bool)));
173                 if(using_flags->is_use_vertical_pixel_lines()) {
174                         actionGLScanLineVert = new Action_Control(this, using_flags);
175                         actionGLScanLineVert->setObjectName(QString::fromUtf8("actionGLScanLineVert"));
176                         actionGLScanLineVert->setCheckable(true);
177                         if(using_flags->get_config_ptr()->opengl_scanline_vert != 0) {
178                                 actionGLScanLineVert->setChecked(true);
179                         } else {
180                                 actionGLScanLineVert->setChecked(false);
181                         }
182                         connect(actionGLScanLineVert, SIGNAL(toggled(bool)),
183                                         this, SLOT(set_gl_scan_line_vert(bool)));
184                 }
185         }
186         if(using_flags->is_use_screen_rotate()) {
187                 actionRotate = new Action_Control(this, using_flags);
188                 actionRotate->setObjectName(QString::fromUtf8("actionScanLine"));
189                 actionRotate->setCheckable(true);
190                 if(using_flags->get_config_ptr()->rotate_type) {
191                         actionRotate->setChecked(true);
192                 } else {
193                         actionRotate->setChecked(false);
194                 }
195                 connect(actionRotate, SIGNAL(toggled(bool)),
196                                 this, SLOT(set_screen_rotate(bool)));
197         }
198         if(using_flags->is_use_crt_filter()) {
199                 actionCRT_Filter = new Action_Control(this, using_flags);
200                 actionCRT_Filter->setObjectName(QString::fromUtf8("actionCRT_Filter"));
201                 actionCRT_Filter->setEnabled(true);
202                 actionCRT_Filter->setCheckable(true);
203                 if(using_flags->get_config_ptr()->crt_filter == 0) actionCRT_Filter->setChecked(true);
204                 connect(actionCRT_Filter, SIGNAL(toggled(bool)), this, SLOT(set_crt_filter(bool)));
205         }
206         actionOpenGL_Filter = new Action_Control(this, using_flags);
207         actionOpenGL_Filter->setObjectName(QString::fromUtf8("actionOpenGL_Filter"));
208         actionOpenGL_Filter->setEnabled(true);
209         actionOpenGL_Filter->setCheckable(true);
210         if(using_flags->get_config_ptr()->use_opengl_filters) actionOpenGL_Filter->setChecked(true);
211         connect(actionOpenGL_Filter, SIGNAL(toggled(bool)), this, SLOT(set_gl_crt_filter(bool)));
212
213         if((using_flags->get_screen_height_aspect() != using_flags->get_screen_height()) ||
214            (using_flags->get_screen_width_aspect() != using_flags->get_screen_width())) {
215                 actionDot_by_Dot = new Action_Control(this, using_flags);
216                 actionDot_by_Dot->setObjectName(QString::fromUtf8("actionDot_by_Dot"));
217                 actionDot_by_Dot->setCheckable(true);
218                 if(using_flags->get_config_ptr()->window_stretch_type == 0) actionDot_by_Dot->setChecked(true);
219                 actionDot_by_Dot->binds->setValue1(0);
220                 
221                 actionReferToX_Display = new Action_Control(this, using_flags);
222                 actionReferToX_Display->setObjectName(QString::fromUtf8("actionReferToX_Display"));
223                 actionReferToX_Display->setCheckable(true);
224                 actionReferToX_Display->binds->setValue1(1);
225                 if(using_flags->get_config_ptr()->window_stretch_type == 1) actionReferToX_Display->setChecked(true);
226                 
227                 actionReferToY_Display = new Action_Control(this, using_flags);
228                 actionReferToY_Display->setObjectName(QString::fromUtf8("actionReferToY_Display"));
229                 actionReferToY_Display->setCheckable(true);
230                 actionReferToY_Display->binds->setValue1(2);
231                 if(using_flags->get_config_ptr()->window_stretch_type == 2) actionReferToY_Display->setChecked(true);
232         
233                 actionFill_Display = new Action_Control(this, using_flags);
234                 actionFill_Display->setObjectName(QString::fromUtf8("actionFill_Display"));
235                 actionFill_Display->setCheckable(true);
236                 actionFill_Display->binds->setValue1(3);
237                 if(using_flags->get_config_ptr()->window_stretch_type == 3) actionFill_Display->setChecked(true);
238         
239                 actionGroup_Stretch = new QActionGroup(this);
240                 actionGroup_Stretch->setExclusive(true);
241                 actionGroup_Stretch->addAction(actionDot_by_Dot);
242                 actionGroup_Stretch->addAction(actionReferToX_Display);
243                 actionGroup_Stretch->addAction(actionReferToY_Display);
244                 actionGroup_Stretch->addAction(actionFill_Display);
245                 connect(actionDot_by_Dot,   SIGNAL(triggered()), actionDot_by_Dot->binds,   SLOT(set_screen_aspect()));
246                 connect(actionDot_by_Dot->binds,   SIGNAL(sig_screen_aspect(int)), this,    SLOT(set_screen_aspect(int)));
247                 
248                 connect(actionReferToX_Display,  SIGNAL(triggered()), actionReferToX_Display->binds,  SLOT(set_screen_aspect()));
249                 connect(actionReferToX_Display->binds,  SIGNAL(sig_screen_aspect(int)), this,    SLOT(set_screen_aspect(int)));
250                 
251                 connect(actionReferToY_Display,  SIGNAL(triggered()), actionReferToY_Display->binds,  SLOT(set_screen_aspect()));
252                 connect(actionReferToY_Display->binds,  SIGNAL(sig_screen_aspect(int)), this,    SLOT(set_screen_aspect(int)));
253                 
254                 connect(actionFill_Display, SIGNAL(triggered()), actionFill_Display->binds, SLOT(set_screen_aspect()));
255                 connect(actionFill_Display->binds, SIGNAL(sig_screen_aspect(int)), this, SLOT(set_screen_aspect(int)));
256         }
257         actionCapture_Screen = new Action_Control(this, using_flags);
258         actionCapture_Screen->setObjectName(QString::fromUtf8("actionCapture_Screen"));
259
260         actionStart_Record_Movie = new Action_Control(this, using_flags);
261         actionStart_Record_Movie->setObjectName(QString::fromUtf8("actionStart_Record_Movie"));
262         actionStart_Record_Movie->setCheckable(false);
263         
264         actionStop_Record_Movie = new Action_Control(this, using_flags);
265         actionStop_Record_Movie->setObjectName(QString::fromUtf8("actionStop_Record_Movie"));
266         actionStop_Record_Movie->setCheckable(false);
267
268         bool b_support_tv_render = using_flags->is_support_tv_render();
269         if(b_support_tv_render) {
270                 int ii = CONFIG_RENDER_TYPE_END;
271                 int i;
272                 
273                 if((ii >= 8) || (ii < 0)) ii = 8;
274                 actionGroup_RenderMode = new QActionGroup(this);
275                 actionGroup_RenderMode->setExclusive(true);
276                 
277                 for(i = 0; i < ii; i++) {
278                         action_SetRenderMode[i] = new Action_Control(this, using_flags);
279                         action_SetRenderMode[i]->setCheckable(true);
280                         action_SetRenderMode[i]->setEnabled(false);
281                         action_SetRenderMode[i]->setVisible(false);
282                         action_SetRenderMode[i]->binds->setValue1(i);
283                         
284                         if(i == using_flags->get_config_ptr()->rendering_type) action_SetRenderMode[i]->setChecked(true);
285                 
286                         if(i == CONFIG_RENDER_TYPE_STD) {
287                                 action_SetRenderMode[i]->setEnabled(true);
288                                 action_SetRenderMode[i]->setVisible(true);
289                                 actionGroup_RenderMode->addAction(action_SetRenderMode[i]);
290                                 connect(action_SetRenderMode[i], SIGNAL(triggered()), this, SLOT(do_set_render_mode_std()));
291                         }
292                         if(b_support_tv_render && (i == CONFIG_RENDER_TYPE_TV)) {
293                                 action_SetRenderMode[i]->setEnabled(true);
294                                 action_SetRenderMode[i]->setVisible(true);
295                                 actionGroup_RenderMode->addAction(action_SetRenderMode[i]);
296                                 connect(action_SetRenderMode[i], SIGNAL(triggered()), this, SLOT(do_set_render_mode_tv()));
297                         }
298                 }
299         }                               
300         ConfigScreenMenu_List();  
301 }
302
303 void Ui_MainWindowBase::CreateScreenMenu(void)
304 {
305         int i;
306         menuScreen = new QMenu(menubar);
307         menuScreen->setObjectName(QString::fromUtf8("menuScreen"));
308         if((using_flags->get_screen_height_aspect() != using_flags->get_screen_height()) ||
309            (using_flags->get_screen_width_aspect() != using_flags->get_screen_width())) {
310                 menuStretch_Mode = new QMenu(menuScreen);
311                 menuStretch_Mode->setObjectName(QString::fromUtf8("menuStretch_Mode"));
312         }
313         bool b_support_tv_render = using_flags->is_support_tv_render();
314         if(b_support_tv_render) {
315                 menuScreen_Render = new QMenu(menuScreen);
316                 menuScreen_Render->setObjectName(QString::fromUtf8("menuRender_Mode"));
317                 menuScreen_Render->addAction(action_SetRenderMode[CONFIG_RENDER_TYPE_STD]);
318                 if(b_support_tv_render) {
319                         menuScreen_Render->addAction(action_SetRenderMode[CONFIG_RENDER_TYPE_TV]);
320                 }
321                 menuScreen->addAction(menuScreen_Render->menuAction());
322         }
323         menuScreenSize = new QMenu(menuScreen);
324         menuScreenSize->setObjectName(QString::fromUtf8("menuScreen_Size"));
325         menuScreen->addSeparator();
326         menuRecord_as_movie = new QMenu(menuScreen);
327         menuRecord_as_movie->setObjectName(QString::fromUtf8("menuRecord_as_movie"));
328
329         menuScreen->addAction(actionZoom);
330         menuScreen->addAction(menuScreenSize->menuAction());
331         for(i = 0; i < using_flags->get_screen_mode_num(); i++) {
332                 if(actionScreenSize[i] == NULL) continue;
333                 menuScreenSize->addAction(actionScreenSize[i]);
334                 actionScreenSize[i]->setVisible(true);
335         }
336
337         if((using_flags->get_screen_height_aspect() != using_flags->get_screen_height()) ||
338            (using_flags->get_screen_width_aspect() != using_flags->get_screen_width())) {
339                 menuScreen->addSeparator();
340                 menuScreen->addAction(menuStretch_Mode->menuAction());
341
342                 menuStretch_Mode->addAction(actionDot_by_Dot);
343                 menuStretch_Mode->addAction(actionReferToX_Display);
344                 menuStretch_Mode->addAction(actionReferToY_Display);
345                 menuStretch_Mode->addAction(actionFill_Display);
346         }
347         menuScreen->addSeparator();
348
349         if(using_flags->is_use_scanline()) {
350                 menuScreen->addAction(actionScanLine);
351         }
352
353         if(!using_flags->is_use_one_board_computer() && (using_flags->get_max_button() <= 0)) {
354                 menuScreen->addAction(actionGLScanLineHoriz);
355                 if(using_flags->is_use_vertical_pixel_lines()) {
356                         menuScreen->addAction(actionGLScanLineVert);
357                 }
358         }
359         if(using_flags->is_use_screen_rotate()) {
360                 menuScreen->addAction(actionRotate);
361         }
362         if(using_flags->is_use_crt_filter()) {
363                 menuScreen->addAction(actionCRT_Filter);
364         }
365
366         menuScreen->addAction(actionOpenGL_Filter);
367         menuScreen->addAction(actionCapture_Screen);
368         menuScreen->addSeparator();
369         menuScreen->addAction(menuRecord_as_movie->menuAction());
370         menuRecord_as_movie->addAction(actionStart_Record_Movie);
371         menuRecord_as_movie->addAction(actionStop_Record_Movie);
372 }
373
374 void Ui_MainWindowBase::retranslateScreenMenu(void)
375 {
376         int i;
377         QString tmps;
378         int w, h;
379         actionZoom->setText(QApplication::translate("MainWindow", "Zoom Screen", 0));
380         actionDisplay_Mode->setText(QApplication::translate("MainWindow", "Display Mode", 0));
381
382         if(using_flags->is_use_scanline()) {
383                 actionScanLine->setText(QApplication::translate("MainWindow", "Software Scan Line", 0));
384         }
385         if(using_flags->is_use_screen_rotate()) {
386                 actionRotate->setText(QApplication::translate("MainWindow", "Rotate Screen", 0));
387         }
388         if(using_flags->is_use_crt_filter()) {
389                 actionCRT_Filter->setText(QApplication::translate("MainWindow", "Software Filter", 0));
390         }
391         if(!using_flags->is_use_one_board_computer() && (using_flags->get_max_button() <= 0)) {
392                 actionGLScanLineHoriz->setText(QApplication::translate("MainWindow", "OpenGL Scan Line", 0));
393                 if(using_flags->is_use_vertical_pixel_lines()) {
394                         actionGLScanLineVert->setText(QApplication::translate("MainWindow", "OpenGL Pixel Line", 0));
395                 }
396         }
397         
398         actionOpenGL_Filter->setText(QApplication::translate("MainWindow", "OpenGL Filter", 0));
399
400         if((using_flags->get_screen_height_aspect() != using_flags->get_screen_height()) ||
401            (using_flags->get_screen_width_aspect() != using_flags->get_screen_width())) {
402                 actionDot_by_Dot->setText(QApplication::translate("MainWindow", "Dot by Dot", 0));
403                 actionReferToX_Display->setText(QApplication::translate("MainWindow", "Keep Aspect: Refer to X", 0));
404                 actionReferToY_Display->setText(QApplication::translate("MainWindow", "Keep Aspect: Refer to Y", 0));
405                 actionFill_Display->setText(QApplication::translate("MainWindow", "Keep Aspect: Fill", 0));
406                 menuStretch_Mode->setTitle(QApplication::translate("MainWindow", "Stretch Mode", 0));
407         }
408
409         actionCapture_Screen->setText(QApplication::translate("MainWindow", "Capture Screen", 0));
410
411         menuScreen->setTitle(QApplication::translate("MainWindow", "Screen", 0));
412         actionStart_Record_Movie->setText(QApplication::translate("MainWindow", "Start Recording Movie", 0));
413         actionStop_Record_Movie->setText(QApplication::translate("MainWindow", "Stop Recording Movie", 0));
414
415         menuRecord_as_movie->setTitle(QApplication::translate("MainWindow", "Record as Movie", 0));
416
417
418         menuScreenSize->setTitle(QApplication::translate("MainWindow", "Screen Size", 0));
419         double s_mul;
420         for(i = 0; i < using_flags->get_screen_mode_num(); i++) {
421                 if(actionScreenSize[i] == NULL) continue;
422                 s_mul = screen_multiply_table[i];
423                 if(s_mul <= 0) break;
424                 tmps = QString::number(s_mul);
425                 tmps = QString::fromUtf8("x", -1) + tmps;
426                 actionScreenSize[i]->setText(tmps);
427         }
428         bool b_support_tv_render = using_flags->is_support_tv_render();
429         if(b_support_tv_render) {
430                 menuScreen_Render->setTitle(QApplication::translate("MainWindow", "Render Mode", 0));
431                 action_SetRenderMode[CONFIG_RENDER_TYPE_STD]->setText(QApplication::translate("MainWindow", "Standard", 0));
432                 if(b_support_tv_render) {
433                         action_SetRenderMode[CONFIG_RENDER_TYPE_TV]->setText(QApplication::translate("MainWindow", "TV", 0));
434                 }
435         }
436 }
437