Duckstation/src/duckstation-qt/qthostinterface.h

127 lines
3.1 KiB
C
Raw Normal View History

2019-12-31 06:17:17 +00:00
#pragma once
#include "core/host_interface.h"
#include "opengldisplaywindow.h"
#include <QtCore/QObject>
#include <QtCore/QSettings>
#include <QtCore/QThread>
#include <atomic>
#include <functional>
#include <map>
#include <memory>
2020-01-05 02:46:03 +00:00
#include <vector>
#include <utility>
2019-12-31 06:17:17 +00:00
class QWidget;
class GameList;
class QtHostInterface : public QObject, private HostInterface
{
Q_OBJECT
public:
explicit QtHostInterface(QObject* parent = nullptr);
~QtHostInterface();
void ReportError(const char* message) override;
void ReportMessage(const char* message) override;
const QSettings& getQSettings() const { return m_qsettings; }
QSettings& getQSettings() { return m_qsettings; }
void setDefaultSettings();
2020-01-01 04:01:58 +00:00
void updateQSettings();
2019-12-31 06:17:17 +00:00
void applySettings();
2020-01-01 04:01:58 +00:00
const Settings& GetCoreSettings() const { return m_settings; }
Settings& GetCoreSettings() { return m_settings; }
// void UpdateCoreSettingsGPU();
2020-01-01 04:01:58 +00:00
2019-12-31 06:17:17 +00:00
const GameList* getGameList() const { return m_game_list.get(); }
GameList* getGameList() { return m_game_list.get(); }
void updateGameListDatabase(bool refresh_list = true);
void refreshGameList(bool invalidate_cache = false);
bool isOnWorkerThread() const { return QThread::currentThread() == m_worker_thread; }
QWidget* createDisplayWidget(QWidget* parent);
void destroyDisplayWidget();
void bootSystem(QString initial_filename, QString initial_save_state_filename);
void updateInputMap();
void handleKeyEvent(int key, bool pressed);
2020-01-05 02:46:03 +00:00
struct HotkeyInfo
{
QString name;
QString display_name;
QString category;
};
std::vector<HotkeyInfo> getHotkeyList() const;
2019-12-31 06:17:17 +00:00
Q_SIGNALS:
void emulationStarting();
void emulationStarted();
void emulationStopped();
void emulationPaused(bool paused);
void gameListRefreshed();
public Q_SLOTS:
void powerOffSystem();
void resetSystem();
void pauseSystem(bool paused);
void changeDisc(QString new_disc_filename);
2020-01-05 02:46:03 +00:00
void toggleFullscreen();
2019-12-31 06:17:17 +00:00
private Q_SLOTS:
void doStopThread();
void doBootSystem(QString initial_filename, QString initial_save_state_filename);
void doUpdateInputMap();
void doHandleKeyEvent(int key, bool pressed);
2020-01-02 09:14:16 +00:00
void onDisplayWindowResized(int width, int height);
2019-12-31 06:17:17 +00:00
private:
2020-01-05 02:46:03 +00:00
using InputButtonHandler = std::function<void(bool)>;
enum : u32
{
NUM_SAVE_STATE_HOTKEYS = 8
};
2019-12-31 06:17:17 +00:00
class Thread : public QThread
{
public:
Thread(QtHostInterface* parent);
~Thread();
protected:
void run() override;
private:
QtHostInterface* m_parent;
};
void checkSettings();
void createGameList();
2020-01-05 02:46:03 +00:00
void updateControllerInputMap();
void updateHotkeyInputMap();
void addButtonToInputMap(const QString& binding, InputButtonHandler handler);
void updateFullscreen();
2019-12-31 06:17:17 +00:00
void createThread();
void stopThread();
void threadEntryPoint();
QSettings m_qsettings;
std::unique_ptr<GameList> m_game_list;
QtDisplayWindow* m_display_window = nullptr;
2019-12-31 06:17:17 +00:00
QThread* m_original_thread = nullptr;
Thread* m_worker_thread = nullptr;
std::atomic_bool m_shutdown_flag{false};
2019-12-31 06:17:17 +00:00
// input key maps, todo hotkeys
2020-01-05 02:46:03 +00:00
std::map<int, InputButtonHandler> m_keyboard_input_handlers;
};