add convenience method to Window class for OSD messages

This commit is contained in:
Arisotura 2023-12-25 16:34:29 +01:00
parent 6a1232b9a9
commit 80c6dd524b
3 changed files with 86 additions and 19 deletions

View File

@ -69,7 +69,7 @@ QMutex Rendering;
bool Init(bool openGL)
{
{printf("%d\n", sizeof(Item));
if (openGL)
{
OpenGL::BuildShaderProgram(kScreenVS_OSD, kScreenFS_OSD, Shader, "OSDShader");

View File

@ -685,6 +685,20 @@ MainWindow::~MainWindow()
delete[] actScreenAspectBot;
}
void MainWindow::osdAddMessage(unsigned int color, const char* fmt, ...)
{
if (fmt == nullptr)
return;
char msg[1024];
va_list args;
va_start(args, fmt);
vsnprintf(msg, 1024, fmt, args);
va_end(args);
OSD::AddMessage(color, msg);
}
void MainWindow::closeEvent(QCloseEvent* event)
{
if (hasOGL)
@ -1394,16 +1408,14 @@ void MainWindow::onSaveState()
if (ROMManager::SaveState(*emuThread->NDS, filename))
{
char msg[64];
if (slot > 0) sprintf(msg, "State saved to slot %d", slot);
else sprintf(msg, "State saved to file");
OSD::AddMessage(0, msg);
if (slot > 0) osdAddMessage(0, "State saved to slot %d", slot);
else osdAddMessage(0, "State saved to file");
actLoadState[slot]->setEnabled(true);
}
else
{
OSD::AddMessage(0xFFA0A0, "State save failed");
osdAddMessage(0xFFA0A0, "State save failed");
}
emuThread->emuUnpause();
@ -1438,10 +1450,8 @@ void MainWindow::onLoadState()
if (!Platform::FileExists(filename))
{
char msg[64];
if (slot > 0) sprintf(msg, "State slot %d is empty", slot);
else sprintf(msg, "State file does not exist");
OSD::AddMessage(0xFFA0A0, msg);
if (slot > 0) osdAddMessage(0xFFA0A0, "State slot %d is empty", slot);
else osdAddMessage(0xFFA0A0, "State file does not exist");
emuThread->emuUnpause();
return;
@ -1449,16 +1459,14 @@ void MainWindow::onLoadState()
if (ROMManager::LoadState(*emuThread->NDS, filename))
{
char msg[64];
if (slot > 0) sprintf(msg, "State loaded from slot %d", slot);
else sprintf(msg, "State loaded from file");
OSD::AddMessage(0, msg);
if (slot > 0) osdAddMessage(0, "State loaded from slot %d", slot);
else osdAddMessage(0, "State loaded from file");
actUndoStateLoad->setEnabled(true);
}
else
{
OSD::AddMessage(0xFFA0A0, "State load failed");
osdAddMessage(0xFFA0A0, "State load failed");
}
emuThread->emuUnpause();
@ -1470,7 +1478,7 @@ void MainWindow::onUndoStateLoad()
ROMManager::UndoStateLoad(*emuThread->NDS);
emuThread->emuUnpause();
OSD::AddMessage(0, "State load undone");
osdAddMessage(0, "State load undone");
}
void MainWindow::onImportSavefile()
@ -1538,13 +1546,13 @@ void MainWindow::onPause(bool checked)
if (checked)
{
emuThread->emuPause();
OSD::AddMessage(0, "Paused");
osdAddMessage(0, "Paused");
pausedManually = true;
}
else
{
emuThread->emuUnpause();
OSD::AddMessage(0, "Resumed");
osdAddMessage(0, "Resumed");
pausedManually = false;
}
}
@ -1559,7 +1567,7 @@ void MainWindow::onReset()
ROMManager::Reset(emuThread);
OSD::AddMessage(0, "Reset");
osdAddMessage(0, "Reset");
emuThread->emuRun();
}

View File

@ -38,6 +38,63 @@
class EmuThread;
/*
class WindowBase : public QMainWindow
{
Q_OBJECT
public:
explicit WindowBase(QWidget* parent = nullptr);
~WindowBase();
bool hasOGL;
GL::Context* getOGLContext();
//void onAppStateChanged(Qt::ApplicationState state);
protected:
void resizeEvent(QResizeEvent* event) override;
void changeEvent(QEvent* event) override;
void keyPressEvent(QKeyEvent* event) override;
void keyReleaseEvent(QKeyEvent* event) override;
void dragEnterEvent(QDragEnterEvent* event) override;
void dropEvent(QDropEvent* event) override;
void focusInEvent(QFocusEvent* event) override;
void focusOutEvent(QFocusEvent* event) override;
signals:
void screenLayoutChange();
private slots:
//void onQuit();
//void onTitleUpdate(QString title);
//void onEmuStart();
//void onEmuStop();
//void onUpdateVideoSettings(bool glchange);
void onFullscreenToggled();
void onScreenEmphasisToggled();
private:
virtual void closeEvent(QCloseEvent* event) override;
void createScreenPanel();
//bool pausedManually = false;
int oldW, oldH;
bool oldMax;
public:
ScreenHandler* panel;
QWidget* panelWidget;
};*/
class MainWindow : public QMainWindow
{
@ -55,6 +112,8 @@ public:
void onAppStateChanged(Qt::ApplicationState state);
void osdAddMessage(unsigned int color, const char* fmt, ...);
protected:
void resizeEvent(QResizeEvent* event) override;
void changeEvent(QEvent* event) override;