diff options
author | Arisotura <thetotalworm@gmail.com> | 2023-12-25 16:34:29 +0100 |
---|---|---|
committer | Arisotura <thetotalworm@gmail.com> | 2023-12-25 16:34:29 +0100 |
commit | 80c6dd524b04b9d94a362037fad140bbc1455d15 (patch) | |
tree | caff2b3fea5f57fb3c8bb6fca699f2b03887ab27 | |
parent | 6a1232b9a9791f7cb54d0bbde6b7d5bb06399c59 (diff) |
add convenience method to Window class for OSD messages
-rw-r--r-- | src/frontend/qt_sdl/OSD.cpp | 2 | ||||
-rw-r--r-- | src/frontend/qt_sdl/Window.cpp | 44 | ||||
-rw-r--r-- | src/frontend/qt_sdl/Window.h | 59 |
3 files changed, 86 insertions, 19 deletions
diff --git a/src/frontend/qt_sdl/OSD.cpp b/src/frontend/qt_sdl/OSD.cpp index 25072df..f845412 100644 --- a/src/frontend/qt_sdl/OSD.cpp +++ b/src/frontend/qt_sdl/OSD.cpp @@ -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"); diff --git a/src/frontend/qt_sdl/Window.cpp b/src/frontend/qt_sdl/Window.cpp index 2a8f00c..f373450 100644 --- a/src/frontend/qt_sdl/Window.cpp +++ b/src/frontend/qt_sdl/Window.cpp @@ -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(); } diff --git a/src/frontend/qt_sdl/Window.h b/src/frontend/qt_sdl/Window.h index a84bc1d..445d5e2 100644 --- a/src/frontend/qt_sdl/Window.h +++ b/src/frontend/qt_sdl/Window.h @@ -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; |