Add Qt Frame.

Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
This commit is contained in:
Andrea Odetti 2021-01-13 15:40:33 +00:00
parent 8a41ed4d73
commit 59c581b807
9 changed files with 149 additions and 58 deletions

View file

@ -24,6 +24,7 @@ set(SOURCE_FILES
loggingcategory.cpp loggingcategory.cpp
viewbuffer.cpp viewbuffer.cpp
qdirectsound.cpp qdirectsound.cpp
qtframe.cpp
) )
set(HEADER_FILES set(HEADER_FILES
@ -39,6 +40,7 @@ set(HEADER_FILES
loggingcategory.h loggingcategory.h
viewbuffer.h viewbuffer.h
qdirectsound.h qdirectsound.h
qtframe.h
) )
add_executable(qapple add_executable(qapple

View file

@ -22,21 +22,16 @@ Emulator::~Emulator()
delete ui; 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()
{ {
if (force)
{
ui->video->repaint(); ui->video->repaint();
}
else
{
ui->video->update();
}
} }
bool Emulator::saveScreen(const QString & filename) const bool Emulator::saveScreen(const QString & filename) const
@ -49,6 +44,11 @@ void Emulator::loadVideoSettings()
ui->video->loadVideoSettings(); ui->video->loadVideoSettings();
} }
void Emulator::unloadVideoSettings()
{
ui->video->unloadVideoSettings();
}
void Emulator::displayLogo() void Emulator::displayLogo()
{ {
ui->video->displayLogo(); ui->video->displayLogo();

View file

@ -17,12 +17,12 @@ public:
explicit Emulator(QWidget *parent = nullptr); explicit Emulator(QWidget *parent = nullptr);
~Emulator(); ~Emulator();
void updateVideo();
void redrawScreen(); // regenerate image and repaint void redrawScreen(); // regenerate image and repaint
void refreshScreen(); // just repaint void refreshScreen(const bool force);
bool saveScreen(const QString & filename) const; bool saveScreen(const QString & filename) const;
void loadVideoSettings(); void loadVideoSettings();
void unloadVideoSettings();
void displayLogo(); void displayLogo();
void setZoom(QMdiSubWindow * window, const int x); void setZoom(QMdiSubWindow * window, const int x);

View file

@ -29,6 +29,7 @@
#include "linux/version.h" #include "linux/version.h"
#include "linux/paddle.h" #include "linux/paddle.h"
#include "linux/interface.h" #include "linux/interface.h"
#include "linux/context.h"
#include "emulator.h" #include "emulator.h"
#include "memorycontainer.h" #include "memorycontainer.h"
@ -36,6 +37,7 @@
#include "gamepadpaddle.h" #include "gamepadpaddle.h"
#include "preferences.h" #include "preferences.h"
#include "configuration.h" #include "configuration.h"
#include "qtframe.h"
#include <QMdiSubWindow> #include <QMdiSubWindow>
#include <QMessageBox> #include <QMessageBox>
@ -73,17 +75,12 @@ namespace
* *
*/ */
void loadEmulator(QWidget * window, Emulator * emulator, const GlobalOptions & options) void loadEmulator(const std::shared_ptr<QtFrame> & frame, const GlobalOptions & options)
{ {
LoadConfiguration(); LoadConfiguration();
CheckCpu(); CheckCpu();
GetAppleWindowTitle();
window->setWindowTitle(QString::fromStdString(g_pAppTitle));
GetFrame().FrameRefreshStatus(DRAW_LEDS | DRAW_BUTTON_DRIVES | DRAW_DISK_STATUS);
// ResetDefaultMachineMemTypes(); // ResetDefaultMachineMemTypes();
switch (options.slot0Card) { switch (options.slot0Card) {
@ -108,16 +105,13 @@ namespace
MB_Initialize(); MB_Initialize();
SpkrInitialize(); SpkrInitialize();
MemInitialize(); MemInitialize();
GetFrame().Initialize(); frame->Initialize();
emulator->loadVideoSettings();
emulator->displayLogo();
GetCardMgr().GetDisk2CardMgr().Reset(); GetCardMgr().GetDisk2CardMgr().Reset();
HD_Reset(); HD_Reset();
} }
void unloadEmulator() void unloadEmulator(const std::shared_ptr<QtFrame> & frame)
{ {
CardManager & cardManager = GetCardMgr(); CardManager & cardManager = GetCardMgr();
@ -130,7 +124,7 @@ namespace
PrintDestroy(); PrintDestroy();
MemDestroy(); MemDestroy();
SpkrDestroy(); SpkrDestroy();
GetVideo().Destroy(); frame->Destroy();
MB_Destroy(); MB_Destroy();
DSUninit(); DSUninit();
CpuDestroy(); CpuDestroy();
@ -224,8 +218,11 @@ QApple::QApple(QWidget *parent) :
myPreferences = new Preferences(this); myPreferences = new Preferences(this);
myEmulator = new Emulator(ui->mdiArea); Emulator * emulator = new Emulator(ui->mdiArea);
myEmulatorWindow = ui->mdiArea->addSubWindow(myEmulator, Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint); myEmulatorWindow = ui->mdiArea->addSubWindow(emulator, Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint);
myFrame.reset(new QtFrame(emulator, myEmulatorWindow));
SetFrame(myFrame);
readSettings(); readSettings();
@ -234,7 +231,7 @@ QApple::QApple(QWidget *parent) :
on_actionPause_triggered(); on_actionPause_triggered();
initialiseEmulator(); initialiseEmulator();
loadEmulator(myEmulatorWindow, myEmulator, myOptions); loadEmulator(myFrame, myOptions);
} }
QApple::~QApple() QApple::~QApple()
@ -245,7 +242,7 @@ QApple::~QApple()
void QApple::closeEvent(QCloseEvent * event) void QApple::closeEvent(QCloseEvent * event)
{ {
stopTimer(); stopTimer();
unloadEmulator(); unloadEmulator(myFrame);
QSettings settings; QSettings settings;
settings.setValue("QApple/window/geometry", saveGeometry().toBase64()); settings.setValue("QApple/window/geometry", saveGeometry().toBase64());
@ -328,7 +325,7 @@ void QApple::on_timer()
// just repaint each time, to make it simpler // just repaint each time, to make it simpler
// we run @ 60 fps anyway // we run @ 60 fps anyway
myEmulator->updateVideo(); myFrame->VideoPresentScreen();
if (count > 1) // 1 is the non-full speed case if (count > 1) // 1 is the non-full speed case
{ {
@ -375,17 +372,17 @@ void QApple::on_actionPause_triggered()
void QApple::on_actionX1_triggered() void QApple::on_actionX1_triggered()
{ {
myEmulator->setZoom(myEmulatorWindow, 1); myFrame->SetZoom(1);
} }
void QApple::on_actionX2_triggered() void QApple::on_actionX2_triggered()
{ {
myEmulator->setZoom(myEmulatorWindow, 2); myFrame->SetZoom(2);
} }
void QApple::on_action4_3_triggered() void QApple::on_action4_3_triggered()
{ {
myEmulator->set43AspectRatio(myEmulatorWindow); myFrame->Set43Ratio();
} }
void QApple::on_actionReboot_triggered() void QApple::on_actionReboot_triggered()
@ -394,10 +391,9 @@ void QApple::on_actionReboot_triggered()
emit endEmulator(); emit endEmulator();
mySaveStateLabel->clear(); mySaveStateLabel->clear();
unloadEmulator(); unloadEmulator(myFrame);
loadEmulator(myEmulatorWindow, myEmulator, myOptions); loadEmulator(myFrame, myOptions);
myEmulatorWindow->setWindowTitle(QString::fromStdString(g_pAppTitle)); myFrame->VideoPresentScreen();
myEmulator->updateVideo();
} }
void QApple::on_actionBenchmark_triggered() 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 // 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, // if video is based on OpenGLWidget, this is not enough though,
// and benchmark results are bad. // 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(); on_actionReboot_triggered();
} }
@ -448,13 +446,11 @@ void QApple::on_actionOptions_triggered()
myOptions.setData(newData.options); myOptions.setData(newData.options);
reloadOptions(); reloadOptions();
} }
} }
void QApple::reloadOptions() void QApple::reloadOptions()
{ {
GetAppleWindowTitle(); myFrame->FrameRefreshStatus(DRAW_TITLE);
myEmulatorWindow->setWindowTitle(QString::fromStdString(g_pAppTitle));
Paddle::instance = GamepadPaddle::fromName(myOptions.gamepadName); Paddle::instance = GamepadPaddle::fromName(myOptions.gamepadName);
Paddle::setSquaring(myOptions.gamepadSquaring); Paddle::setSquaring(myOptions.gamepadSquaring);
@ -481,11 +477,12 @@ void QApple::on_actionLoad_state_triggered()
SetCurrentImageDir(path.toStdString().c_str()); SetCurrentImageDir(path.toStdString().c_str());
Snapshot_LoadState(); Snapshot_LoadState();
GetAppleWindowTitle();
myEmulatorWindow->setWindowTitle(QString::fromStdString(g_pAppTitle)); myFrame->FrameRefreshStatus(DRAW_TITLE);
myFrame->VideoPresentScreen();
QString message = QString("State file: %1").arg(file.filePath()); QString message = QString("State file: %1").arg(file.filePath());
mySaveStateLabel->setText(message); mySaveStateLabel->setText(message);
myEmulator->updateVideo();
} }
void QApple::on_actionAbout_Qt_triggered() void QApple::on_actionAbout_Qt_triggered()
@ -527,7 +524,7 @@ void QApple::on_actionScreenshot_triggered()
} }
else else
{ {
const bool ok = myEmulator->saveScreen(filename); const bool ok = myFrame->saveScreen(filename);
if (!ok) if (!ok)
{ {
const QString message = QString::fromUtf8("Cannot save screenshot to %1").arg(filename); 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() void QApple::on_actionNext_video_mode_triggered()
{ {
Video & video = GetVideo(); myFrame->CycleVideoType();
video.IncVideoType();
GetAppleWindowTitle();
myEmulatorWindow->setWindowTitle(QString::fromStdString(g_pAppTitle));
video.VideoReinitialize(false);
video.Config_Save_Video();
} }
void QApple::loadStateFile(const QString & filename) void QApple::loadStateFile(const QString & filename)

View file

@ -12,8 +12,8 @@
class QMdiSubWindow; class QMdiSubWindow;
class Emulator;
class Preferences; class Preferences;
class QtFrame;
namespace Ui { namespace Ui {
class QApple; class QApple;
@ -106,9 +106,9 @@ private:
QLabel * mySaveStateLabel; QLabel * mySaveStateLabel;
std::shared_ptr<QtFrame> myFrame;
QElapsedTimer myElapsedTimer; QElapsedTimer myElapsedTimer;
QMdiSubWindow * myEmulatorWindow; QMdiSubWindow * myEmulatorWindow;
Emulator * myEmulator;
qint64 myCpuTimeReference; qint64 myCpuTimeReference;
GlobalOptions myOptions; GlobalOptions myOptions;

View file

@ -0,0 +1,61 @@
#include "StdAfx.h"
#include "qtframe.h"
#include "emulator.h"
#include "Core.h"
#include "Utilities.h"
#include <QMdiSubWindow>
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);
}

View file

@ -0,0 +1,32 @@
#ifndef QTFRAME_H
#define QTFRAME_H
#include "linux/linuxframe.h"
#include <memory>
#include <QString>
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

View file

@ -34,6 +34,11 @@ void QVideo::loadVideoSettings()
myFrameBuffer = video.GetFrameBuffer(); myFrameBuffer = video.GetFrameBuffer();
} }
void QVideo::unloadVideoSettings()
{
myFrameBuffer = nullptr;
}
QImage QVideo::getScreenImage() const QImage QVideo::getScreenImage() const
{ {
QImage frameBuffer(myFrameBuffer, myWidth, myHeight, QImage::Format_ARGB32_Premultiplied); QImage frameBuffer(myFrameBuffer, myWidth, myHeight, QImage::Format_ARGB32_Premultiplied);

View file

@ -14,6 +14,7 @@ public:
QImage getScreen() const; QImage getScreen() const;
void loadVideoSettings(); void loadVideoSettings();
void unloadVideoSettings();
void displayLogo(); void displayLogo();
signals: signals: