Skip to content

Commit

Permalink
Make still and animated screenshots consistent, support screenshot sa…
Browse files Browse the repository at this point in the history
…ving via IPC
  • Loading branch information
calc84maniac committed Jan 11, 2024
1 parent b5e0e01 commit e422d8b
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ gui/qt/capture/libpng*
# more build stuff
gui/qt/CEmu.build/
gui/qt/cmake-build-*/
gui/qt/out/
1 change: 1 addition & 0 deletions gui/qt/cemuopts.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct CEmuOpts {
QString imageFile;
QString launchPrgm;
QString debugFile;
QString screenshotFile;
QString idString;
QString pidString;
QStringList sendFiles;
Expand Down
22 changes: 15 additions & 7 deletions gui/qt/lcdwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand All @@ -114,7 +118,7 @@ void LCDWidget::mouseMoveEvent(QMouseEvent *e) {
mimeData->setImageData(image);
mimeData->setUrls(QList<QUrl>() << 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:
Expand Down Expand Up @@ -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());
Expand Down
13 changes: 11 additions & 2 deletions gui/qt/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <File> (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);
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down
9 changes: 7 additions & 2 deletions gui/qt/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2597,7 +2597,8 @@ bool MainWindow::ipcSetup() {
<< opts.sendRAMFiles
<< opts.restoreOnOpen
<< opts.speed
<< opts.launchPrgm;
<< opts.launchPrgm
<< opts.screenshotFile;

// blocking call
com.send(byteArray);
Expand All @@ -2620,14 +2621,18 @@ void MainWindow::ipcCli(QDataStream &stream) {
>> o.sendRAMFiles
>> o.restoreOnOpen
>> o.speed
>> o.launchPrgm;
>> o.launchPrgm
>> o.screenshotFile;

optLoadFiles(o);
optAttemptLoad(o);
optSend(o);
if (o.speed != -1) {
setEmuSpeed(o.speed);
}
if (!o.screenshotFile.isEmpty()) {
ui->lcd->getImage().save(o.screenshotFile, "PNG", 0);
}
}

void MainWindow::ipcCloseConnected() {
Expand Down

0 comments on commit e422d8b

Please sign in to comment.