From e422d8b515bcb6f703bd0e672c657f61f4050569 Mon Sep 17 00:00:00 2001 From: Brendan Fletcher Date: Thu, 11 Jan 2024 15:53:30 -0500 Subject: [PATCH] Make still and animated screenshots consistent, support screenshot saving via IPC --- .gitignore | 1 + gui/qt/cemuopts.h | 1 + gui/qt/lcdwidget.cpp | 22 +++++++++++++++------- gui/qt/main.cpp | 13 +++++++++++-- gui/qt/mainwindow.cpp | 9 +++++++-- 5 files changed, 35 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 2e508f8d6..a85267d9e 100644 --- a/.gitignore +++ b/.gitignore @@ -64,3 +64,4 @@ gui/qt/capture/libpng* # more build stuff gui/qt/CEmu.build/ gui/qt/cmake-build-*/ +gui/qt/out/ diff --git a/gui/qt/cemuopts.h b/gui/qt/cemuopts.h index 7f55a1564..47b40c6f3 100644 --- a/gui/qt/cemuopts.h +++ b/gui/qt/cemuopts.h @@ -20,6 +20,7 @@ struct CEmuOpts { QString imageFile; QString launchPrgm; QString debugFile; + QString screenshotFile; QString idString; QString pidString; QStringList sendFiles; diff --git a/gui/qt/lcdwidget.cpp b/gui/qt/lcdwidget.cpp index 6b43ea755..a0130ac1d 100644 --- a/gui/qt/lcdwidget.cpp +++ b/gui/qt/lcdwidget.cpp @@ -38,9 +38,6 @@ void LCDWidget::paintEvent(QPaintEvent*) { m_mutex.lock(); c.drawImage(cw, m_image); m_mutex.unlock(); - if (backlight.factor < 1) { - c.fillRect(cw, QColor(0, 0, 0, (1 - backlight.factor) * 255)); - } } else { c.fillRect(cw, Qt::black); c.setPen(Qt::white); @@ -88,9 +85,16 @@ void LCDWidget::dragLeaveEvent(QDragLeaveEvent *e) { } QImage LCDWidget::getImage() { - QPixmap pixmap(size()); - render(&pixmap); - return pixmap.toImage(); + QImage image; + if ((control.ports[5] & 1 << 4) && (lcd.control & 1 << 11)) { + m_mutex.lock(); + image = m_image.copy(); + m_mutex.unlock(); + } else { + image = QImage(LCD_WIDTH, LCD_HEIGHT, QImage::Format_RGBX8888); + image.fill(Qt::black); + } + return image; } void LCDWidget::mousePressEvent(QMouseEvent *e) { @@ -114,7 +118,7 @@ void LCDWidget::mouseMoveEvent(QMouseEvent *e) { mimeData->setImageData(image); mimeData->setUrls(QList() << QUrl::fromLocalFile(path)); drag->setMimeData(mimeData); - drag->setHotSpot(e->pos()); + drag->setHotSpot(e->pos() * ((double)image.rect().width() / rect().width())); drag->setPixmap(mymap); switch (drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::MoveAction)) { case Qt::IgnoreAction: @@ -164,6 +168,10 @@ void LCDWidget::draw() { m_skip = m_frameskip; m_mutex.lock(); emu_lcd_drawframe(m_image.bits()); + if (backlight.factor < 1) { + QPainter c(&m_image); + c.fillRect(c.window(), QColor(0, 0, 0, (1 - backlight.factor) * 255)); + } m_mutex.unlock(); #ifdef PNG_WRITE_APNG_SUPPORTED apng_add_frame(m_image.constBits()); diff --git a/gui/qt/main.cpp b/gui/qt/main.cpp index c96f68f67..856b8f5e2 100644 --- a/gui/qt/main.cpp +++ b/gui/qt/main.cpp @@ -102,6 +102,11 @@ int main(int argc, char *argv[]) { QCoreApplication::translate("main", "id")); parser.addOption(procID); + QCommandLineOption screenshotFile(QStringList() << QStringLiteral("screenshot"), + QCoreApplication::translate("main", "Saves a screenshot to (only usable as a sent command)"), + QCoreApplication::translate("main", "screenshot")); + parser.addOption(screenshotFile); + QCommandLineOption deforceReset(QStringList() << QStringLiteral("no-reset"), QCoreApplication::translate("main", "Does not reset when sending")); parser.addOption(deforceReset); @@ -150,6 +155,7 @@ int main(int argc, char *argv[]) { opts.launchPrgm = parser.value(launchPrgm); opts.imageFile = parser.value(imageFile); opts.debugFile = parser.value(debugFile); + opts.screenshotFile = parser.value(screenshotFile); opts.sendFiles = parser.values(sendFiles); opts.sendArchFiles = parser.values(sendArchFiles); opts.sendRAMFiles = parser.values(sendRAMFiles); @@ -162,10 +168,13 @@ int main(int argc, char *argv[]) { opts.speed = -1; } if (parser.isSet(loadTestFile)) { - opts.autotesterFile = QDir::currentPath() + QDir::separator() + parser.value(loadTestFile); + opts.autotesterFile = QFileInfo(parser.value(loadTestFile)).absoluteFilePath(); + } + if (parser.isSet(screenshotFile)) { + opts.screenshotFile = QFileInfo(parser.value(screenshotFile)).absoluteFilePath(); } if (parser.isSet(fullscreenOption)) { - int value = parser.value(loadRomFile).toInt(); + int value = parser.value(fullscreenOption).toInt(); switch (value) { case 0: case 1: case 2: break; diff --git a/gui/qt/mainwindow.cpp b/gui/qt/mainwindow.cpp index 794b34ab9..9cc8b98ae 100644 --- a/gui/qt/mainwindow.cpp +++ b/gui/qt/mainwindow.cpp @@ -2597,7 +2597,8 @@ bool MainWindow::ipcSetup() { << opts.sendRAMFiles << opts.restoreOnOpen << opts.speed - << opts.launchPrgm; + << opts.launchPrgm + << opts.screenshotFile; // blocking call com.send(byteArray); @@ -2620,7 +2621,8 @@ void MainWindow::ipcCli(QDataStream &stream) { >> o.sendRAMFiles >> o.restoreOnOpen >> o.speed - >> o.launchPrgm; + >> o.launchPrgm + >> o.screenshotFile; optLoadFiles(o); optAttemptLoad(o); @@ -2628,6 +2630,9 @@ void MainWindow::ipcCli(QDataStream &stream) { if (o.speed != -1) { setEmuSpeed(o.speed); } + if (!o.screenshotFile.isEmpty()) { + ui->lcd->getImage().save(o.screenshotFile, "PNG", 0); + } } void MainWindow::ipcCloseConnected() {