Skip to content

Commit

Permalink
a bit of refactoring around ScreenHandler
Browse files Browse the repository at this point in the history
also gets rid of that annoying warning about const char* being converted to char*
  • Loading branch information
RSDuck committed Aug 5, 2022
1 parent 2ba7f96 commit 5baf5fe
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 56 deletions.
4 changes: 2 additions & 2 deletions src/frontend/qt_sdl/OSD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
79 changes: 32 additions & 47 deletions src/frontend/qt_sdl/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,15 +330,15 @@ 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()));
connect(this, SIGNAL(windowEmuPause()), mainWindow->actPause, SLOT(trigger()));
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()));

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -932,7 +944,7 @@ void ScreenHandler::screenHandleTouch(QTouchEvent* event)

void ScreenHandler::showCursor()
{
mainWindow->panel->setCursor(Qt::ArrowCursor);
mainWindow->panelWidget->setCursor(Qt::ArrowCursor);
mouseTimer->start();
}

Expand All @@ -946,25 +958,20 @@ 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);

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()
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -1776,25 +1773,22 @@ 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();
}

QOpenGLContext* MainWindow::getOGLContext()
{
if (!hasOGL) return nullptr;

QOpenGLWidget* glpanel = (QOpenGLWidget*)panel;
QOpenGLWidget* glpanel = dynamic_cast<QOpenGLWidget*>(panel);
return glpanel->context();
}

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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++)
Expand Down
14 changes: 7 additions & 7 deletions src/frontend/qt_sdl/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ class ScreenHandler
Q_GADGET

public:
virtual ~ScreenHandler() {}
ScreenHandler(QWidget* widget);
virtual ~ScreenHandler();
QTimer* setupMouseTimer();
void updateMouseTimer();
QTimer* mouseTimer;
Expand All @@ -121,7 +122,7 @@ class ScreenHandler
int screenKind[Frontend::MaxScreenTransforms];
int numScreens;

bool touching;
bool touching = false;

void showCursor();
};
Expand All @@ -133,7 +134,7 @@ class ScreenPanelNative : public QWidget, public ScreenHandler

public:
explicit ScreenPanelNative(QWidget* parent);
~ScreenPanelNative();
virtual ~ScreenPanelNative();

protected:
void paintEvent(QPaintEvent* event) override;
Expand Down Expand Up @@ -163,7 +164,7 @@ class ScreenPanelGL : public QOpenGLWidget, public ScreenHandler, protected QOpe

public:
explicit ScreenPanelGL(QWidget* parent);
~ScreenPanelGL();
virtual ~ScreenPanelGL();

protected:
void initializeGL() override;
Expand Down Expand Up @@ -316,9 +317,8 @@ private slots:
bool oldMax;

public:
QWidget* panel;
ScreenPanelGL* panelGL;
ScreenPanelNative* panelNative;
ScreenHandler* panel;
QWidget* panelWidget;

QAction* actOpenROM;
QAction* actBootFirmware;
Expand Down

0 comments on commit 5baf5fe

Please sign in to comment.