Skip to content

Commit

Permalink
add convenience method to Window class for OSD messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Arisotura committed Dec 25, 2023
1 parent 6a1232b commit 80c6dd5
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/frontend/qt_sdl/OSD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
44 changes: 26 additions & 18 deletions src/frontend/qt_sdl/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -1438,27 +1450,23 @@ 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;
}

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();
Expand All @@ -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()
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -1559,7 +1567,7 @@ void MainWindow::onReset()

ROMManager::Reset(emuThread);

OSD::AddMessage(0, "Reset");
osdAddMessage(0, "Reset");
emuThread->emuRun();
}

Expand Down
59 changes: 59 additions & 0 deletions src/frontend/qt_sdl/Window.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -55,6 +112,8 @@ class MainWindow : public QMainWindow

void onAppStateChanged(Qt::ApplicationState state);

void osdAddMessage(unsigned int color, const char* fmt, ...);

protected:
void resizeEvent(QResizeEvent* event) override;
void changeEvent(QEvent* event) override;
Expand Down

0 comments on commit 80c6dd5

Please sign in to comment.