aboutsummaryrefslogtreecommitdiff
path: root/src/frontend/qt_sdl
diff options
context:
space:
mode:
authorRSDuck <RSDuck@users.noreply.github.com>2022-08-05 20:22:10 +0200
committerRSDuck <RSDuck@users.noreply.github.com>2022-08-05 20:22:10 +0200
commit5baf5fe77b15451055300fcd235197f47fbf154a (patch)
treec8874dca4908f98dab76acb419102700fe15b768 /src/frontend/qt_sdl
parent2ba7f961a6050ad3d60b9edf42d094d9596661ff (diff)
a bit of refactoring around ScreenHandler
also gets rid of that annoying warning about const char* being converted to char*
Diffstat (limited to 'src/frontend/qt_sdl')
-rw-r--r--src/frontend/qt_sdl/OSD.cpp4
-rw-r--r--src/frontend/qt_sdl/main.cpp79
-rw-r--r--src/frontend/qt_sdl/main.h14
3 files changed, 41 insertions, 56 deletions
diff --git a/src/frontend/qt_sdl/OSD.cpp b/src/frontend/qt_sdl/OSD.cpp
index 68b1b78..6f060a9 100644
--- a/src/frontend/qt_sdl/OSD.cpp
+++ b/src/frontend/qt_sdl/OSD.cpp
@@ -146,7 +146,7 @@ void LayoutText(const char* text, u32* width, u32* height, int* breaks)
u32 w = 0;
u32 h = 14;
u32 totalw = 0;
- u32 maxw = mainWindow->panel->width() - (kOSDMargin*2);
+ u32 maxw = mainWindow->panelWidget->width() - (kOSDMargin*2);
int lastbreak = -1;
int numbrk = 0;
u16* ptr;
@@ -236,7 +236,7 @@ void RenderText(u32 color, const char* text, Item* item)
memset(item->Bitmap, 0, w*h*sizeof(u32));
u32 x = 0, y = 1;
- u32 maxw = mainWindow->panel->width() - (kOSDMargin*2);
+ u32 maxw = mainWindow->panelWidget->width() - (kOSDMargin*2);
int curline = 0;
u16* ptr;
diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp
index c6eebf2..150803a 100644
--- a/src/frontend/qt_sdl/main.cpp
+++ b/src/frontend/qt_sdl/main.cpp
@@ -330,7 +330,7 @@ EmuThread::EmuThread(QObject* parent) : QThread(parent)
EmuPause = 0;
RunningSomething = false;
- connect(this, SIGNAL(windowUpdate()), mainWindow->panel, SLOT(repaint()));
+ connect(this, SIGNAL(windowUpdate()), mainWindow->panelWidget, SLOT(repaint()));
connect(this, SIGNAL(windowTitleChange(QString)), mainWindow, SLOT(onTitleUpdate(QString)));
connect(this, SIGNAL(windowEmuStart()), mainWindow, SLOT(onEmuStart()));
connect(this, SIGNAL(windowEmuStop()), mainWindow, SLOT(onEmuStop()));
@@ -338,7 +338,7 @@ EmuThread::EmuThread(QObject* parent) : QThread(parent)
connect(this, SIGNAL(windowEmuReset()), mainWindow->actReset, SLOT(trigger()));
connect(this, SIGNAL(windowEmuFrameStep()), mainWindow->actFrameStep, SLOT(trigger()));
connect(this, SIGNAL(windowLimitFPSChange()), mainWindow->actLimitFramerate, SLOT(trigger()));
- connect(this, SIGNAL(screenLayoutChange()), mainWindow->panel, SLOT(onScreenLayoutChanged()));
+ connect(this, SIGNAL(screenLayoutChange()), mainWindow->panelWidget, SLOT(onScreenLayoutChanged()));
connect(this, SIGNAL(windowFullscreenToggle()), mainWindow, SLOT(onFullscreenToggled()));
connect(this, SIGNAL(swapScreensToggle()), mainWindow->actScreenSwap, SLOT(trigger()));
@@ -749,6 +749,18 @@ bool EmuThread::emuIsActive()
return (RunningSomething == 1);
}
+ScreenHandler::ScreenHandler(QWidget* widget)
+{
+ widget->setMouseTracking(true);
+ widget->setAttribute(Qt::WA_AcceptTouchEvents);
+ QTimer* mouseTimer = setupMouseTimer();
+ widget->connect(mouseTimer, &QTimer::timeout, [=] { if (Config::MouseHide) widget->setCursor(Qt::BlankCursor);});
+}
+
+ScreenHandler::~ScreenHandler()
+{
+ mouseTimer->stop();
+}
void ScreenHandler::screenSetupLayout(int w, int h)
{
@@ -932,7 +944,7 @@ void ScreenHandler::screenHandleTouch(QTouchEvent* event)
void ScreenHandler::showCursor()
{
- mainWindow->panel->setCursor(Qt::ArrowCursor);
+ mainWindow->panelWidget->setCursor(Qt::ArrowCursor);
mouseTimer->start();
}
@@ -946,7 +958,7 @@ QTimer* ScreenHandler::setupMouseTimer()
return mouseTimer;
}
-ScreenPanelNative::ScreenPanelNative(QWidget* parent) : QWidget(parent)
+ScreenPanelNative::ScreenPanelNative(QWidget* parent) : QWidget(parent), ScreenHandler(this)
{
screen[0] = QImage(256, 192, QImage::Format_RGB32);
screen[1] = QImage(256, 192, QImage::Format_RGB32);
@@ -954,17 +966,12 @@ ScreenPanelNative::ScreenPanelNative(QWidget* parent) : QWidget(parent)
screenTrans[0].reset();
screenTrans[1].reset();
- touching = false;
-
- setAttribute(Qt::WA_AcceptTouchEvents);
-
OSD::Init(nullptr);
}
ScreenPanelNative::~ScreenPanelNative()
{
OSD::DeInit(nullptr);
- mouseTimer->stop();
}
void ScreenPanelNative::setupScreenLayout()
@@ -1063,17 +1070,11 @@ void ScreenPanelNative::onScreenLayoutChanged()
}
-ScreenPanelGL::ScreenPanelGL(QWidget* parent) : QOpenGLWidget(parent)
-{
- touching = false;
-
- setAttribute(Qt::WA_AcceptTouchEvents);
-}
+ScreenPanelGL::ScreenPanelGL(QWidget* parent) : QOpenGLWidget(parent), ScreenHandler(this)
+{}
ScreenPanelGL::~ScreenPanelGL()
{
- mouseTimer->stop();
-
makeCurrent();
OSD::DeInit(this);
@@ -1749,17 +1750,13 @@ void MainWindow::createScreenPanel()
{
hasOGL = (Config::ScreenUseGL != 0) || (Config::_3DRenderer != 0);
- QTimer* mouseTimer;
-
if (hasOGL)
{
- panelGL = new ScreenPanelGL(this);
+ ScreenPanelGL* panelGL = new ScreenPanelGL(this);
panelGL->show();
panel = panelGL;
- panelGL->setMouseTracking(true);
- mouseTimer = panelGL->setupMouseTimer();
- connect(mouseTimer, &QTimer::timeout, [=] { if (Config::MouseHide) panelGL->setCursor(Qt::BlankCursor);});
+ panelWidget = panelGL;
if (!panelGL->isValid())
hasOGL = false;
@@ -1776,17 +1773,14 @@ void MainWindow::createScreenPanel()
if (!hasOGL)
{
- panelNative = new ScreenPanelNative(this);
+ ScreenPanelNative* panelNative = new ScreenPanelNative(this);
panel = panelNative;
- panel->show();
-
- panelNative->setMouseTracking(true);
- mouseTimer = panelNative->setupMouseTimer();
- connect(mouseTimer, &QTimer::timeout, [=] { if (Config::MouseHide) panelNative->setCursor(Qt::BlankCursor);});
+ panelWidget = panelNative;
+ panelWidget->show();
}
- setCentralWidget(panel);
+ setCentralWidget(panelWidget);
- connect(this, SIGNAL(screenLayoutChange()), panel, SLOT(onScreenLayoutChanged()));
+ connect(this, SIGNAL(screenLayoutChange()), panelWidget, SLOT(onScreenLayoutChanged()));
emit screenLayoutChange();
}
@@ -1794,7 +1788,7 @@ QOpenGLContext* MainWindow::getOGLContext()
{
if (!hasOGL) return nullptr;
- QOpenGLWidget* glpanel = (QOpenGLWidget*)panel;
+ QOpenGLWidget* glpanel = dynamic_cast<QOpenGLWidget*>(panel);
return glpanel->context();
}
@@ -2777,10 +2771,7 @@ void MainWindow::onOpenInterfaceSettings()
void MainWindow::onUpdateMouseTimer()
{
- if (hasOGL)
- panelGL->mouseTimer->setInterval(Config::MouseHideSeconds*1000);
- else
- panelNative->mouseTimer->setInterval(Config::MouseHideSeconds*1000);
+ panel->mouseTimer->setInterval(Config::MouseHideSeconds*1000);
}
void MainWindow::onInterfaceSettingsFinished(int res)
@@ -2796,8 +2787,8 @@ void MainWindow::onChangeSavestateSRAMReloc(bool checked)
void MainWindow::onChangeScreenSize()
{
int factor = ((QAction*)sender())->data().toInt();
- QSize diff = size() - panel->size();
- resize(dynamic_cast<ScreenHandler*>(panel)->screenGetMinSize(factor) + diff);
+ QSize diff = size() - panelWidget->size();
+ resize(panel->screenGetMinSize(factor) + diff);
}
void MainWindow::onChangeScreenRotation(QAction* act)
@@ -2970,16 +2961,10 @@ void MainWindow::onUpdateVideoSettings(bool glchange)
emuThread->emuPause();
if (hasOGL)
- {
emuThread->deinitOpenGL();
- delete panelGL;
- }
- else
- {
- delete panelNative;
- }
+ delete panel;
createScreenPanel();
- connect(emuThread, SIGNAL(windowUpdate()), panel, SLOT(repaint()));
+ connect(emuThread, SIGNAL(windowUpdate()), panelWidget, SLOT(repaint()));
if (hasOGL) emuThread->initOpenGL();
}
@@ -3180,7 +3165,7 @@ int CALLBACK WinMain(HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int cmdsho
{
int argc = 0;
wchar_t** argv_w = CommandLineToArgvW(GetCommandLineW(), &argc);
- char* nullarg = "";
+ char nullarg[] = {'\0'};
char** argv = new char*[argc];
for (int i = 0; i < argc; i++)
diff --git a/src/frontend/qt_sdl/main.h b/src/frontend/qt_sdl/main.h
index 531cd2a..45d1da0 100644
--- a/src/frontend/qt_sdl/main.h
+++ b/src/frontend/qt_sdl/main.h
@@ -101,7 +101,8 @@ class ScreenHandler
Q_GADGET
public:
- virtual ~ScreenHandler() {}
+ ScreenHandler(QWidget* widget);
+ virtual ~ScreenHandler();
QTimer* setupMouseTimer();
void updateMouseTimer();
QTimer* mouseTimer;
@@ -121,7 +122,7 @@ protected:
int screenKind[Frontend::MaxScreenTransforms];
int numScreens;
- bool touching;
+ bool touching = false;
void showCursor();
};
@@ -133,7 +134,7 @@ class ScreenPanelNative : public QWidget, public ScreenHandler
public:
explicit ScreenPanelNative(QWidget* parent);
- ~ScreenPanelNative();
+ virtual ~ScreenPanelNative();
protected:
void paintEvent(QPaintEvent* event) override;
@@ -163,7 +164,7 @@ class ScreenPanelGL : public QOpenGLWidget, public ScreenHandler, protected QOpe
public:
explicit ScreenPanelGL(QWidget* parent);
- ~ScreenPanelGL();
+ virtual ~ScreenPanelGL();
protected:
void initializeGL() override;
@@ -316,9 +317,8 @@ private:
bool oldMax;
public:
- QWidget* panel;
- ScreenPanelGL* panelGL;
- ScreenPanelNative* panelNative;
+ ScreenHandler* panel;
+ QWidget* panelWidget;
QAction* actOpenROM;
QAction* actBootFirmware;