|
23 | 23 | #include <QString>
|
24 | 24 | #include <QStringList>
|
25 | 25 |
|
| 26 | +#include <gfx/age_png.hpp> |
26 | 27 | #include <emulator/age_gb_emulator.hpp> // gb buttons
|
| 28 | +#include <QStandardPaths> |
27 | 29 |
|
28 | 30 | #include "age_ui_qt_emulation_runner.hpp"
|
29 | 31 | #include "age_ui_qt_main_window.hpp"
|
@@ -52,12 +54,13 @@ age::qt_main_window::qt_main_window(QWidget* parent, Qt::WindowFlags flags)
|
52 | 54 |
|
53 | 55 | m_settings = new qt_settings_dialog(m_user_value_store, this, Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
|
54 | 56 |
|
55 |
| - m_action_open = new QAction("open file", this); |
56 |
| - m_action_open_dmg = new QAction("open file as DMG", this); |
57 |
| - m_action_open_cgb_abcd = new QAction("open file as CGB A/B/C/D", this); |
58 |
| - m_action_open_cgb_e = new QAction("open file as CGB E", this); |
59 |
| - m_action_settings = new QAction("settings", this); |
60 |
| - m_action_fullscreen = new QAction("fullscreen", this); |
| 57 | + m_action_open = new QAction("open file", this); |
| 58 | + m_action_open_dmg = new QAction("open file as DMG", this); |
| 59 | + m_action_open_cgb_abcd = new QAction("open file as CGB A/B/C/D", this); |
| 60 | + m_action_open_cgb_e = new QAction("open file as CGB E", this); |
| 61 | + m_action_capture_gb_screen = new QAction("capture gb screen", this); |
| 62 | + m_action_settings = new QAction("settings", this); |
| 63 | + m_action_fullscreen = new QAction("fullscreen", this); |
61 | 64 | m_action_fullscreen->setCheckable(true);
|
62 | 65 | m_action_fullscreen->setChecked(false);
|
63 | 66 | m_action_exit = new QAction("exit", this);
|
@@ -92,6 +95,8 @@ age::qt_main_window::qt_main_window(QWidget* parent, Qt::WindowFlags flags)
|
92 | 95 | connect(emulation_runner, &qt_emulation_runner::emulator_speed, this, &qt_main_window::emulator_speed);
|
93 | 96 | connect(emulation_runner, &qt_emulation_runner::emulator_milliseconds, this, &qt_main_window::emulator_milliseconds);
|
94 | 97 |
|
| 98 | + connect(emulation_runner, &qt_emulation_runner::captured_emulator_screen, this, &qt_main_window::menu_emulator_captured_emulator_screen); |
| 99 | + |
95 | 100 | // connect video output signals
|
96 | 101 |
|
97 | 102 | connect(video_output, &qt_video_output::fps, this, &qt_main_window::fps);
|
@@ -120,6 +125,7 @@ age::qt_main_window::qt_main_window(QWidget* parent, Qt::WindowFlags flags)
|
120 | 125 | connect(m_action_open_dmg, &QAction::triggered, this, &qt_main_window::menu_emulator_open_dmg);
|
121 | 126 | connect(m_action_open_cgb_abcd, &QAction::triggered, this, &qt_main_window::menu_emulator_open_cgb_abcd);
|
122 | 127 | connect(m_action_open_cgb_e, &QAction::triggered, this, &qt_main_window::menu_emulator_open_cgb_e);
|
| 128 | + connect(m_action_capture_gb_screen, &QAction::triggered, emulation_runner, &qt_emulation_runner::capture_emulator_screen); |
123 | 129 | connect(m_action_settings, &QAction::triggered, this, &qt_main_window::menu_emulator_settings);
|
124 | 130 | connect(m_action_fullscreen, &QAction::triggered, this, &qt_main_window::menu_emulator_fullscreen);
|
125 | 131 | connect(m_action_exit, &QAction::triggered, this, &qt_main_window::menu_emulator_exit);
|
@@ -257,6 +263,8 @@ void age::qt_main_window::fill_menu(QMenu* menu)
|
257 | 263 | menu->addAction(m_action_open_cgb_abcd);
|
258 | 264 | menu->addAction(m_action_open_cgb_e);
|
259 | 265 | menu->addSeparator();
|
| 266 | + menu->addAction(m_action_capture_gb_screen); |
| 267 | + menu->addSeparator(); |
260 | 268 | menu->addAction(m_action_settings);
|
261 | 269 | menu->addAction(m_action_fullscreen);
|
262 | 270 | menu->addSeparator();
|
@@ -390,6 +398,40 @@ void age::qt_main_window::menu_emulator_open_cgb_e()
|
390 | 398 | m_settings->set_pause_emulator(false);
|
391 | 399 | }
|
392 | 400 |
|
| 401 | +void age::qt_main_window::menu_emulator_captured_emulator_screen(pixel_vector captured_screen, |
| 402 | + int screen_width, |
| 403 | + int screen_height) |
| 404 | +{ |
| 405 | + // no screen captured -> do nothing |
| 406 | + if (captured_screen.empty()) |
| 407 | + { |
| 408 | + return; |
| 409 | + } |
| 410 | + |
| 411 | + // screen captured -> select file to write |
| 412 | + QString file_name; |
| 413 | + QFileDialog dialog(this, |
| 414 | + "save screenshot", |
| 415 | + QStandardPaths::writableLocation(QStandardPaths::HomeLocation), |
| 416 | + "PNG files (*.png)"); |
| 417 | + dialog.setFileMode(QFileDialog::AnyFile); |
| 418 | + dialog.setAcceptMode(QFileDialog::AcceptSave); |
| 419 | + if (dialog.exec()) |
| 420 | + { |
| 421 | + QStringList files = dialog.selectedFiles(); |
| 422 | + if (!files.empty()) |
| 423 | + { |
| 424 | + file_name = files.at(0); |
| 425 | + } |
| 426 | + } |
| 427 | + |
| 428 | + // file selected -> write |
| 429 | + if (file_name.length() > 0) |
| 430 | + { |
| 431 | + write_png_file(captured_screen, screen_width, screen_height, file_name.toStdString()); |
| 432 | + } |
| 433 | +} |
| 434 | + |
393 | 435 | void age::qt_main_window::menu_emulator_settings()
|
394 | 436 | {
|
395 | 437 | m_settings->show();
|
|
0 commit comments