a bit of refactoring around ScreenHandler

also gets rid of that annoying warning about const char* being converted to char*
This commit is contained in:
RSDuck 2022-08-05 20:22:10 +02:00
parent 2ba7f961a6
commit 5baf5fe77b
3 changed files with 41 additions and 56 deletions

View File

@ -146,7 +146,7 @@ void LayoutText(const char* text, u32* width, u32* height, int* breaks)
u32 w = 0; u32 w = 0;
u32 h = 14; u32 h = 14;
u32 totalw = 0; u32 totalw = 0;
u32 maxw = mainWindow->panel->width() - (kOSDMargin*2); u32 maxw = mainWindow->panelWidget->width() - (kOSDMargin*2);
int lastbreak = -1; int lastbreak = -1;
int numbrk = 0; int numbrk = 0;
u16* ptr; u16* ptr;
@ -236,7 +236,7 @@ void RenderText(u32 color, const char* text, Item* item)
memset(item->Bitmap, 0, w*h*sizeof(u32)); memset(item->Bitmap, 0, w*h*sizeof(u32));
u32 x = 0, y = 1; u32 x = 0, y = 1;
u32 maxw = mainWindow->panel->width() - (kOSDMargin*2); u32 maxw = mainWindow->panelWidget->width() - (kOSDMargin*2);
int curline = 0; int curline = 0;
u16* ptr; u16* ptr;

View File

@ -330,7 +330,7 @@ EmuThread::EmuThread(QObject* parent) : QThread(parent)
EmuPause = 0; EmuPause = 0;
RunningSomething = false; 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(windowTitleChange(QString)), mainWindow, SLOT(onTitleUpdate(QString)));
connect(this, SIGNAL(windowEmuStart()), mainWindow, SLOT(onEmuStart())); connect(this, SIGNAL(windowEmuStart()), mainWindow, SLOT(onEmuStart()));
connect(this, SIGNAL(windowEmuStop()), mainWindow, SLOT(onEmuStop())); 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(windowEmuReset()), mainWindow->actReset, SLOT(trigger()));
connect(this, SIGNAL(windowEmuFrameStep()), mainWindow->actFrameStep, SLOT(trigger())); connect(this, SIGNAL(windowEmuFrameStep()), mainWindow->actFrameStep, SLOT(trigger()));
connect(this, SIGNAL(windowLimitFPSChange()), mainWindow->actLimitFramerate, 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(windowFullscreenToggle()), mainWindow, SLOT(onFullscreenToggled()));
connect(this, SIGNAL(swapScreensToggle()), mainWindow->actScreenSwap, SLOT(trigger())); connect(this, SIGNAL(swapScreensToggle()), mainWindow->actScreenSwap, SLOT(trigger()));
@ -749,6 +749,18 @@ bool EmuThread::emuIsActive()
return (RunningSomething == 1); 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) void ScreenHandler::screenSetupLayout(int w, int h)
{ {
@ -932,7 +944,7 @@ void ScreenHandler::screenHandleTouch(QTouchEvent* event)
void ScreenHandler::showCursor() void ScreenHandler::showCursor()
{ {
mainWindow->panel->setCursor(Qt::ArrowCursor); mainWindow->panelWidget->setCursor(Qt::ArrowCursor);
mouseTimer->start(); mouseTimer->start();
} }
@ -946,7 +958,7 @@ QTimer* ScreenHandler::setupMouseTimer()
return mouseTimer; 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[0] = QImage(256, 192, QImage::Format_RGB32);
screen[1] = 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[0].reset();
screenTrans[1].reset(); screenTrans[1].reset();
touching = false;
setAttribute(Qt::WA_AcceptTouchEvents);
OSD::Init(nullptr); OSD::Init(nullptr);
} }
ScreenPanelNative::~ScreenPanelNative() ScreenPanelNative::~ScreenPanelNative()
{ {
OSD::DeInit(nullptr); OSD::DeInit(nullptr);
mouseTimer->stop();
} }
void ScreenPanelNative::setupScreenLayout() void ScreenPanelNative::setupScreenLayout()
@ -1063,17 +1070,11 @@ void ScreenPanelNative::onScreenLayoutChanged()
} }
ScreenPanelGL::ScreenPanelGL(QWidget* parent) : QOpenGLWidget(parent) ScreenPanelGL::ScreenPanelGL(QWidget* parent) : QOpenGLWidget(parent), ScreenHandler(this)
{ {}
touching = false;
setAttribute(Qt::WA_AcceptTouchEvents);
}
ScreenPanelGL::~ScreenPanelGL() ScreenPanelGL::~ScreenPanelGL()
{ {
mouseTimer->stop();
makeCurrent(); makeCurrent();
OSD::DeInit(this); OSD::DeInit(this);
@ -1749,17 +1750,13 @@ void MainWindow::createScreenPanel()
{ {
hasOGL = (Config::ScreenUseGL != 0) || (Config::_3DRenderer != 0); hasOGL = (Config::ScreenUseGL != 0) || (Config::_3DRenderer != 0);
QTimer* mouseTimer;
if (hasOGL) if (hasOGL)
{ {
panelGL = new ScreenPanelGL(this); ScreenPanelGL* panelGL = new ScreenPanelGL(this);
panelGL->show(); panelGL->show();
panel = panelGL; panel = panelGL;
panelGL->setMouseTracking(true); panelWidget = panelGL;
mouseTimer = panelGL->setupMouseTimer();
connect(mouseTimer, &QTimer::timeout, [=] { if (Config::MouseHide) panelGL->setCursor(Qt::BlankCursor);});
if (!panelGL->isValid()) if (!panelGL->isValid())
hasOGL = false; hasOGL = false;
@ -1776,17 +1773,14 @@ void MainWindow::createScreenPanel()
if (!hasOGL) if (!hasOGL)
{ {
panelNative = new ScreenPanelNative(this); ScreenPanelNative* panelNative = new ScreenPanelNative(this);
panel = panelNative; panel = panelNative;
panel->show(); panelWidget = panelNative;
panelWidget->show();
panelNative->setMouseTracking(true);
mouseTimer = panelNative->setupMouseTimer();
connect(mouseTimer, &QTimer::timeout, [=] { if (Config::MouseHide) panelNative->setCursor(Qt::BlankCursor);});
} }
setCentralWidget(panel); setCentralWidget(panelWidget);
connect(this, SIGNAL(screenLayoutChange()), panel, SLOT(onScreenLayoutChanged())); connect(this, SIGNAL(screenLayoutChange()), panelWidget, SLOT(onScreenLayoutChanged()));
emit screenLayoutChange(); emit screenLayoutChange();
} }
@ -1794,7 +1788,7 @@ QOpenGLContext* MainWindow::getOGLContext()
{ {
if (!hasOGL) return nullptr; if (!hasOGL) return nullptr;
QOpenGLWidget* glpanel = (QOpenGLWidget*)panel; QOpenGLWidget* glpanel = dynamic_cast<QOpenGLWidget*>(panel);
return glpanel->context(); return glpanel->context();
} }
@ -2777,10 +2771,7 @@ void MainWindow::onOpenInterfaceSettings()
void MainWindow::onUpdateMouseTimer() void MainWindow::onUpdateMouseTimer()
{ {
if (hasOGL) panel->mouseTimer->setInterval(Config::MouseHideSeconds*1000);
panelGL->mouseTimer->setInterval(Config::MouseHideSeconds*1000);
else
panelNative->mouseTimer->setInterval(Config::MouseHideSeconds*1000);
} }
void MainWindow::onInterfaceSettingsFinished(int res) void MainWindow::onInterfaceSettingsFinished(int res)
@ -2796,8 +2787,8 @@ void MainWindow::onChangeSavestateSRAMReloc(bool checked)
void MainWindow::onChangeScreenSize() void MainWindow::onChangeScreenSize()
{ {
int factor = ((QAction*)sender())->data().toInt(); int factor = ((QAction*)sender())->data().toInt();
QSize diff = size() - panel->size(); QSize diff = size() - panelWidget->size();
resize(dynamic_cast<ScreenHandler*>(panel)->screenGetMinSize(factor) + diff); resize(panel->screenGetMinSize(factor) + diff);
} }
void MainWindow::onChangeScreenRotation(QAction* act) void MainWindow::onChangeScreenRotation(QAction* act)
@ -2970,16 +2961,10 @@ void MainWindow::onUpdateVideoSettings(bool glchange)
emuThread->emuPause(); emuThread->emuPause();
if (hasOGL) if (hasOGL)
{
emuThread->deinitOpenGL(); emuThread->deinitOpenGL();
delete panelGL; delete panel;
}
else
{
delete panelNative;
}
createScreenPanel(); createScreenPanel();
connect(emuThread, SIGNAL(windowUpdate()), panel, SLOT(repaint())); connect(emuThread, SIGNAL(windowUpdate()), panelWidget, SLOT(repaint()));
if (hasOGL) emuThread->initOpenGL(); if (hasOGL) emuThread->initOpenGL();
} }
@ -3180,7 +3165,7 @@ int CALLBACK WinMain(HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int cmdsho
{ {
int argc = 0; int argc = 0;
wchar_t** argv_w = CommandLineToArgvW(GetCommandLineW(), &argc); wchar_t** argv_w = CommandLineToArgvW(GetCommandLineW(), &argc);
char* nullarg = ""; char nullarg[] = {'\0'};
char** argv = new char*[argc]; char** argv = new char*[argc];
for (int i = 0; i < argc; i++) for (int i = 0; i < argc; i++)

View File

@ -101,7 +101,8 @@ class ScreenHandler
Q_GADGET Q_GADGET
public: public:
virtual ~ScreenHandler() {} ScreenHandler(QWidget* widget);
virtual ~ScreenHandler();
QTimer* setupMouseTimer(); QTimer* setupMouseTimer();
void updateMouseTimer(); void updateMouseTimer();
QTimer* mouseTimer; QTimer* mouseTimer;
@ -121,7 +122,7 @@ protected:
int screenKind[Frontend::MaxScreenTransforms]; int screenKind[Frontend::MaxScreenTransforms];
int numScreens; int numScreens;
bool touching; bool touching = false;
void showCursor(); void showCursor();
}; };
@ -133,7 +134,7 @@ class ScreenPanelNative : public QWidget, public ScreenHandler
public: public:
explicit ScreenPanelNative(QWidget* parent); explicit ScreenPanelNative(QWidget* parent);
~ScreenPanelNative(); virtual ~ScreenPanelNative();
protected: protected:
void paintEvent(QPaintEvent* event) override; void paintEvent(QPaintEvent* event) override;
@ -163,7 +164,7 @@ class ScreenPanelGL : public QOpenGLWidget, public ScreenHandler, protected QOpe
public: public:
explicit ScreenPanelGL(QWidget* parent); explicit ScreenPanelGL(QWidget* parent);
~ScreenPanelGL(); virtual ~ScreenPanelGL();
protected: protected:
void initializeGL() override; void initializeGL() override;
@ -316,9 +317,8 @@ private:
bool oldMax; bool oldMax;
public: public:
QWidget* panel; ScreenHandler* panel;
ScreenPanelGL* panelGL; QWidget* panelWidget;
ScreenPanelNative* panelNative;
QAction* actOpenROM; QAction* actOpenROM;
QAction* actBootFirmware; QAction* actBootFirmware;