From 59c581b807d6d7516282bac079b4dd2f681bc864 Mon Sep 17 00:00:00 2001 From: Andrea Odetti Date: Wed, 13 Jan 2021 15:40:33 +0000 Subject: [PATCH] Add Qt Frame. Signed-off-by: Andrea Odetti --- source/frontends/qt/CMakeLists.txt | 2 + source/frontends/qt/emulator.cpp | 28 ++++++------ source/frontends/qt/emulator.h | 4 +- source/frontends/qt/qapple.cpp | 70 +++++++++++++----------------- source/frontends/qt/qapple.h | 4 +- source/frontends/qt/qtframe.cpp | 61 ++++++++++++++++++++++++++ source/frontends/qt/qtframe.h | 32 ++++++++++++++ source/frontends/qt/qvideo.cpp | 5 +++ source/frontends/qt/qvideo.h | 1 + 9 files changed, 149 insertions(+), 58 deletions(-) create mode 100644 source/frontends/qt/qtframe.cpp create mode 100644 source/frontends/qt/qtframe.h diff --git a/source/frontends/qt/CMakeLists.txt b/source/frontends/qt/CMakeLists.txt index fb34cfa9..81263b3f 100644 --- a/source/frontends/qt/CMakeLists.txt +++ b/source/frontends/qt/CMakeLists.txt @@ -24,6 +24,7 @@ set(SOURCE_FILES loggingcategory.cpp viewbuffer.cpp qdirectsound.cpp + qtframe.cpp ) set(HEADER_FILES @@ -39,6 +40,7 @@ set(HEADER_FILES loggingcategory.h viewbuffer.h qdirectsound.h + qtframe.h ) add_executable(qapple diff --git a/source/frontends/qt/emulator.cpp b/source/frontends/qt/emulator.cpp index 8ce36d62..272e9dc4 100644 --- a/source/frontends/qt/emulator.cpp +++ b/source/frontends/qt/emulator.cpp @@ -22,21 +22,16 @@ Emulator::~Emulator() delete ui; } -void Emulator::updateVideo() +void Emulator::refreshScreen(const bool force) { - ui->video->update(); -} - -void Emulator::redrawScreen() -{ - NTSC_SetVideoMode( GetVideo().GetVideoMode() ); - NTSC_VideoRedrawWholeScreen(); - refreshScreen(); -} - -void Emulator::refreshScreen() -{ - ui->video->repaint(); + if (force) + { + ui->video->repaint(); + } + else + { + ui->video->update(); + } } bool Emulator::saveScreen(const QString & filename) const @@ -49,6 +44,11 @@ void Emulator::loadVideoSettings() ui->video->loadVideoSettings(); } +void Emulator::unloadVideoSettings() +{ + ui->video->unloadVideoSettings(); +} + void Emulator::displayLogo() { ui->video->displayLogo(); diff --git a/source/frontends/qt/emulator.h b/source/frontends/qt/emulator.h index 3a554827..0ef42919 100644 --- a/source/frontends/qt/emulator.h +++ b/source/frontends/qt/emulator.h @@ -17,12 +17,12 @@ public: explicit Emulator(QWidget *parent = nullptr); ~Emulator(); - void updateVideo(); void redrawScreen(); // regenerate image and repaint - void refreshScreen(); // just repaint + void refreshScreen(const bool force); bool saveScreen(const QString & filename) const; void loadVideoSettings(); + void unloadVideoSettings(); void displayLogo(); void setZoom(QMdiSubWindow * window, const int x); diff --git a/source/frontends/qt/qapple.cpp b/source/frontends/qt/qapple.cpp index 9bd0bc40..21047028 100644 --- a/source/frontends/qt/qapple.cpp +++ b/source/frontends/qt/qapple.cpp @@ -29,6 +29,7 @@ #include "linux/version.h" #include "linux/paddle.h" #include "linux/interface.h" +#include "linux/context.h" #include "emulator.h" #include "memorycontainer.h" @@ -36,6 +37,7 @@ #include "gamepadpaddle.h" #include "preferences.h" #include "configuration.h" +#include "qtframe.h" #include #include @@ -73,17 +75,12 @@ namespace * */ - void loadEmulator(QWidget * window, Emulator * emulator, const GlobalOptions & options) + void loadEmulator(const std::shared_ptr & frame, const GlobalOptions & options) { LoadConfiguration(); CheckCpu(); - GetAppleWindowTitle(); - window->setWindowTitle(QString::fromStdString(g_pAppTitle)); - - GetFrame().FrameRefreshStatus(DRAW_LEDS | DRAW_BUTTON_DRIVES | DRAW_DISK_STATUS); - // ResetDefaultMachineMemTypes(); switch (options.slot0Card) { @@ -108,16 +105,13 @@ namespace MB_Initialize(); SpkrInitialize(); MemInitialize(); - GetFrame().Initialize(); - - emulator->loadVideoSettings(); - emulator->displayLogo(); + frame->Initialize(); GetCardMgr().GetDisk2CardMgr().Reset(); HD_Reset(); } - void unloadEmulator() + void unloadEmulator(const std::shared_ptr & frame) { CardManager & cardManager = GetCardMgr(); @@ -130,7 +124,7 @@ namespace PrintDestroy(); MemDestroy(); SpkrDestroy(); - GetVideo().Destroy(); + frame->Destroy(); MB_Destroy(); DSUninit(); CpuDestroy(); @@ -224,8 +218,11 @@ QApple::QApple(QWidget *parent) : myPreferences = new Preferences(this); - myEmulator = new Emulator(ui->mdiArea); - myEmulatorWindow = ui->mdiArea->addSubWindow(myEmulator, Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint); + Emulator * emulator = new Emulator(ui->mdiArea); + myEmulatorWindow = ui->mdiArea->addSubWindow(emulator, Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint); + + myFrame.reset(new QtFrame(emulator, myEmulatorWindow)); + SetFrame(myFrame); readSettings(); @@ -234,7 +231,7 @@ QApple::QApple(QWidget *parent) : on_actionPause_triggered(); initialiseEmulator(); - loadEmulator(myEmulatorWindow, myEmulator, myOptions); + loadEmulator(myFrame, myOptions); } QApple::~QApple() @@ -245,7 +242,7 @@ QApple::~QApple() void QApple::closeEvent(QCloseEvent * event) { stopTimer(); - unloadEmulator(); + unloadEmulator(myFrame); QSettings settings; settings.setValue("QApple/window/geometry", saveGeometry().toBase64()); @@ -328,7 +325,7 @@ void QApple::on_timer() // just repaint each time, to make it simpler // we run @ 60 fps anyway - myEmulator->updateVideo(); + myFrame->VideoPresentScreen(); if (count > 1) // 1 is the non-full speed case { @@ -375,17 +372,17 @@ void QApple::on_actionPause_triggered() void QApple::on_actionX1_triggered() { - myEmulator->setZoom(myEmulatorWindow, 1); + myFrame->SetZoom(1); } void QApple::on_actionX2_triggered() { - myEmulator->setZoom(myEmulatorWindow, 2); + myFrame->SetZoom(2); } void QApple::on_action4_3_triggered() { - myEmulator->set43AspectRatio(myEmulatorWindow); + myFrame->Set43Ratio(); } void QApple::on_actionReboot_triggered() @@ -394,10 +391,9 @@ void QApple::on_actionReboot_triggered() emit endEmulator(); mySaveStateLabel->clear(); - unloadEmulator(); - loadEmulator(myEmulatorWindow, myEmulator, myOptions); - myEmulatorWindow->setWindowTitle(QString::fromStdString(g_pAppTitle)); - myEmulator->updateVideo(); + unloadEmulator(myFrame); + loadEmulator(myFrame, myOptions); + myFrame->VideoPresentScreen(); } void QApple::on_actionBenchmark_triggered() @@ -405,7 +401,9 @@ void QApple::on_actionBenchmark_triggered() // call repaint as we really want to for a paintEvent() so we can time it properly // if video is based on OpenGLWidget, this is not enough though, // and benchmark results are bad. - VideoBenchmark([this]() { myEmulator->redrawScreen(); }, [this]() { myEmulator->refreshScreen(); }); + myFrame->SetForceRepaint(true); + VideoBenchmark([this]() { myFrame->VideoRedrawScreen(); }, [this]() { myFrame->VideoPresentScreen(); }); + myFrame->SetForceRepaint(false); on_actionReboot_triggered(); } @@ -448,13 +446,11 @@ void QApple::on_actionOptions_triggered() myOptions.setData(newData.options); reloadOptions(); } - } void QApple::reloadOptions() { - GetAppleWindowTitle(); - myEmulatorWindow->setWindowTitle(QString::fromStdString(g_pAppTitle)); + myFrame->FrameRefreshStatus(DRAW_TITLE); Paddle::instance = GamepadPaddle::fromName(myOptions.gamepadName); Paddle::setSquaring(myOptions.gamepadSquaring); @@ -481,11 +477,12 @@ void QApple::on_actionLoad_state_triggered() SetCurrentImageDir(path.toStdString().c_str()); Snapshot_LoadState(); - GetAppleWindowTitle(); - myEmulatorWindow->setWindowTitle(QString::fromStdString(g_pAppTitle)); + + myFrame->FrameRefreshStatus(DRAW_TITLE); + myFrame->VideoPresentScreen(); + QString message = QString("State file: %1").arg(file.filePath()); mySaveStateLabel->setText(message); - myEmulator->updateVideo(); } void QApple::on_actionAbout_Qt_triggered() @@ -527,7 +524,7 @@ void QApple::on_actionScreenshot_triggered() } else { - const bool ok = myEmulator->saveScreen(filename); + const bool ok = myFrame->saveScreen(filename); if (!ok) { const QString message = QString::fromUtf8("Cannot save screenshot to %1").arg(filename); @@ -567,14 +564,7 @@ void QApple::on_actionLoad_state_from_triggered() void QApple::on_actionNext_video_mode_triggered() { - Video & video = GetVideo(); - video.IncVideoType(); - - GetAppleWindowTitle(); - myEmulatorWindow->setWindowTitle(QString::fromStdString(g_pAppTitle)); - - video.VideoReinitialize(false); - video.Config_Save_Video(); + myFrame->CycleVideoType(); } void QApple::loadStateFile(const QString & filename) diff --git a/source/frontends/qt/qapple.h b/source/frontends/qt/qapple.h index cee56164..6af78ab8 100644 --- a/source/frontends/qt/qapple.h +++ b/source/frontends/qt/qapple.h @@ -12,8 +12,8 @@ class QMdiSubWindow; -class Emulator; class Preferences; +class QtFrame; namespace Ui { class QApple; @@ -106,9 +106,9 @@ private: QLabel * mySaveStateLabel; + std::shared_ptr myFrame; QElapsedTimer myElapsedTimer; QMdiSubWindow * myEmulatorWindow; - Emulator * myEmulator; qint64 myCpuTimeReference; GlobalOptions myOptions; diff --git a/source/frontends/qt/qtframe.cpp b/source/frontends/qt/qtframe.cpp new file mode 100644 index 00000000..ae777419 --- /dev/null +++ b/source/frontends/qt/qtframe.cpp @@ -0,0 +1,61 @@ +#include "StdAfx.h" +#include "qtframe.h" +#include "emulator.h" + +#include "Core.h" +#include "Utilities.h" + +#include + +QtFrame::QtFrame(Emulator * emulator, QMdiSubWindow * window) : myEmulator(emulator), myWindow(window), myForceRepaint(false) +{ + +} + +void QtFrame::SetForceRepaint(const bool force) +{ + myForceRepaint = force; +} + +void QtFrame::VideoPresentScreen() +{ + myEmulator->refreshScreen(myForceRepaint); +} + +void QtFrame::FrameRefreshStatus(int drawflags) +{ + if (drawflags & DRAW_TITLE) + { + GetAppleWindowTitle(); + myWindow->setWindowTitle(QString::fromStdString(g_pAppTitle)); + } +} + +void QtFrame::Initialize() +{ + LinuxFrame::Initialize(); + FrameRefreshStatus(DRAW_TITLE); + myEmulator->loadVideoSettings(); + myEmulator->displayLogo(); +} + +void QtFrame::Destroy() +{ + LinuxFrame::Destroy(); + myEmulator->unloadVideoSettings(); +} + +void QtFrame::SetZoom(const int x) +{ + myEmulator->setZoom(myWindow, x); +} + +void QtFrame::Set43Ratio() +{ + myEmulator->set43AspectRatio(myWindow); +} + +bool QtFrame::saveScreen(const QString & filename) const +{ + return myEmulator->saveScreen(filename); +} diff --git a/source/frontends/qt/qtframe.h b/source/frontends/qt/qtframe.h new file mode 100644 index 00000000..6607ab21 --- /dev/null +++ b/source/frontends/qt/qtframe.h @@ -0,0 +1,32 @@ +#ifndef QTFRAME_H +#define QTFRAME_H + +#include "linux/linuxframe.h" +#include +#include + +class Emulator; +class QMdiSubWindow; + +class QtFrame : public LinuxFrame +{ +public: + QtFrame(Emulator * emulator, QMdiSubWindow * window); + + virtual void VideoPresentScreen(); + virtual void FrameRefreshStatus(int drawflags); + virtual void Initialize(); + virtual void Destroy(); + + void SetForceRepaint(const bool force); + void SetZoom(const int x); + void Set43Ratio(); + bool saveScreen(const QString & filename) const; + +private: + Emulator * myEmulator; + QMdiSubWindow * myWindow; + bool myForceRepaint; +}; + +#endif // QTFRAME_H diff --git a/source/frontends/qt/qvideo.cpp b/source/frontends/qt/qvideo.cpp index 37a9bf21..76cc7149 100644 --- a/source/frontends/qt/qvideo.cpp +++ b/source/frontends/qt/qvideo.cpp @@ -34,6 +34,11 @@ void QVideo::loadVideoSettings() myFrameBuffer = video.GetFrameBuffer(); } +void QVideo::unloadVideoSettings() +{ + myFrameBuffer = nullptr; +} + QImage QVideo::getScreenImage() const { QImage frameBuffer(myFrameBuffer, myWidth, myHeight, QImage::Format_ARGB32_Premultiplied); diff --git a/source/frontends/qt/qvideo.h b/source/frontends/qt/qvideo.h index c6081717..4aad05e4 100644 --- a/source/frontends/qt/qvideo.h +++ b/source/frontends/qt/qvideo.h @@ -14,6 +14,7 @@ public: QImage getScreen() const; void loadVideoSettings(); + void unloadVideoSettings(); void displayLogo(); signals: