2019-09-09 07:01:26 +00:00
|
|
|
#pragma once
|
2019-11-03 05:22:37 +00:00
|
|
|
#include "common/gl/program.h"
|
|
|
|
#include "common/gl/texture.h"
|
2019-11-03 14:39:48 +00:00
|
|
|
#include "core/host_display.h"
|
2019-12-14 14:17:43 +00:00
|
|
|
#include "core/host_interface.h"
|
2020-04-10 14:00:44 +00:00
|
|
|
#include "frontend-common/common_host_interface.h"
|
2019-09-12 14:18:13 +00:00
|
|
|
#include <SDL.h>
|
2019-09-09 07:01:26 +00:00
|
|
|
#include <array>
|
|
|
|
#include <deque>
|
2019-10-23 11:39:48 +00:00
|
|
|
#include <map>
|
2019-09-20 06:47:41 +00:00
|
|
|
#include <memory>
|
2019-10-20 14:38:04 +00:00
|
|
|
#include <mutex>
|
2020-01-10 03:31:12 +00:00
|
|
|
#include <string>
|
2019-09-09 07:01:26 +00:00
|
|
|
|
2019-10-10 16:20:21 +00:00
|
|
|
class AudioStream;
|
2019-09-09 07:01:26 +00:00
|
|
|
|
2020-04-10 14:00:44 +00:00
|
|
|
class INISettingsInterface;
|
2019-12-14 14:17:43 +00:00
|
|
|
|
2020-04-10 14:00:44 +00:00
|
|
|
class SDLHostInterface final : public CommonHostInterface
|
2019-09-09 07:01:26 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-11-03 14:39:48 +00:00
|
|
|
SDLHostInterface();
|
|
|
|
~SDLHostInterface();
|
2019-09-09 07:01:26 +00:00
|
|
|
|
2020-02-15 15:14:28 +00:00
|
|
|
static std::unique_ptr<SDLHostInterface> Create();
|
2019-09-14 10:28:47 +00:00
|
|
|
|
2020-04-13 12:13:46 +00:00
|
|
|
const char* GetFrontendName() const override;
|
|
|
|
|
2019-11-16 05:27:57 +00:00
|
|
|
void ReportError(const char* message) override;
|
2019-09-12 14:18:13 +00:00
|
|
|
void ReportMessage(const char* message) override;
|
2020-02-26 09:25:57 +00:00
|
|
|
bool ConfirmMessage(const char* message) override;
|
2019-09-09 07:01:26 +00:00
|
|
|
|
2020-04-06 02:18:33 +00:00
|
|
|
bool Initialize() override;
|
2020-04-05 12:59:06 +00:00
|
|
|
void Shutdown() override;
|
|
|
|
|
2020-07-21 09:49:04 +00:00
|
|
|
std::string GetStringSettingValue(const char* section, const char* key, const char* default_value = "") override;
|
|
|
|
bool GetBoolSettingValue(const char* section, const char* key, bool default_value = false) override;
|
|
|
|
int GetIntSettingValue(const char* section, const char* key, int default_value = 0) override;
|
|
|
|
float GetFloatSettingValue(const char* section, const char* key, float default_value = 0.0f) override;
|
2020-06-30 14:33:45 +00:00
|
|
|
|
2019-09-09 07:01:26 +00:00
|
|
|
void Run();
|
|
|
|
|
2020-02-15 15:14:28 +00:00
|
|
|
protected:
|
2020-04-06 02:18:33 +00:00
|
|
|
void LoadSettings() override;
|
|
|
|
|
2020-02-15 15:14:28 +00:00
|
|
|
bool AcquireHostDisplay() override;
|
|
|
|
void ReleaseHostDisplay() override;
|
|
|
|
std::unique_ptr<AudioStream> CreateAudioStream(AudioBackend backend) override;
|
|
|
|
|
|
|
|
void OnSystemCreated() override;
|
|
|
|
void OnSystemPaused(bool paused) override;
|
2020-04-06 02:18:33 +00:00
|
|
|
void OnSystemDestroyed() override;
|
2020-04-10 14:00:44 +00:00
|
|
|
void OnRunningGameChanged() override;
|
2020-02-15 15:14:28 +00:00
|
|
|
|
2020-04-13 12:13:46 +00:00
|
|
|
void RequestExit() override;
|
2020-04-30 15:01:50 +00:00
|
|
|
void PollAndUpdate() override;
|
2020-04-13 12:13:46 +00:00
|
|
|
|
2020-04-10 14:00:44 +00:00
|
|
|
std::optional<HostKeyCode> GetHostKeyCode(const std::string_view key_code) const override;
|
|
|
|
void UpdateInputMap() override;
|
2019-12-15 13:24:34 +00:00
|
|
|
|
2020-04-10 14:00:44 +00:00
|
|
|
private:
|
2019-09-12 14:18:13 +00:00
|
|
|
bool CreateSDLWindow();
|
2019-11-17 09:37:10 +00:00
|
|
|
void DestroySDLWindow();
|
2019-11-03 14:39:48 +00:00
|
|
|
bool CreateDisplay();
|
2019-11-17 09:37:10 +00:00
|
|
|
void DestroyDisplay();
|
2019-11-07 15:07:39 +00:00
|
|
|
void CreateImGuiContext();
|
2020-02-28 06:59:48 +00:00
|
|
|
void UpdateFramebufferScale();
|
2019-09-12 14:18:13 +00:00
|
|
|
|
2020-02-15 15:33:43 +00:00
|
|
|
/// Executes a callback later, after the UI has finished rendering. Needed to boot while rendering ImGui.
|
|
|
|
void RunLater(std::function<void()> callback);
|
|
|
|
|
2020-04-30 15:01:50 +00:00
|
|
|
void SaveAndUpdateSettings();
|
2019-11-07 15:07:39 +00:00
|
|
|
|
2020-04-10 14:00:44 +00:00
|
|
|
bool IsFullscreen() const override;
|
|
|
|
bool SetFullscreen(bool enabled) override;
|
2019-10-20 14:38:04 +00:00
|
|
|
|
2019-09-09 07:01:26 +00:00
|
|
|
// We only pass mouse input through if it's grabbed
|
2020-03-21 13:05:04 +00:00
|
|
|
void DrawImGuiWindows() override;
|
2019-10-20 10:37:21 +00:00
|
|
|
void DoStartDisc();
|
2019-10-28 07:34:59 +00:00
|
|
|
void DoChangeDisc();
|
2020-08-16 13:20:36 +00:00
|
|
|
void DoDumpRAM();
|
2019-09-09 07:01:26 +00:00
|
|
|
|
2019-10-23 11:39:48 +00:00
|
|
|
void HandleSDLEvent(const SDL_Event* event);
|
2020-04-10 14:00:44 +00:00
|
|
|
void ProcessEvents();
|
2019-12-14 14:17:43 +00:00
|
|
|
|
2019-10-04 12:27:18 +00:00
|
|
|
void DrawMainMenuBar();
|
2019-11-07 15:07:39 +00:00
|
|
|
void DrawQuickSettingsMenu();
|
|
|
|
void DrawDebugMenu();
|
2019-10-20 10:37:21 +00:00
|
|
|
void DrawPoweredOffWindow();
|
2019-11-07 13:52:19 +00:00
|
|
|
void DrawSettingsWindow();
|
2019-10-20 11:18:11 +00:00
|
|
|
void DrawAboutWindow();
|
2019-11-07 13:52:19 +00:00
|
|
|
bool DrawFileChooser(const char* label, std::string* path, const char* filter = nullptr);
|
2020-02-15 15:14:28 +00:00
|
|
|
void ClearImGuiFocus();
|
2019-09-09 07:01:26 +00:00
|
|
|
|
2019-09-12 14:18:13 +00:00
|
|
|
SDL_Window* m_window = nullptr;
|
2019-11-03 14:39:48 +00:00
|
|
|
std::unique_ptr<HostDisplayTexture> m_app_icon_texture;
|
2020-04-10 14:00:44 +00:00
|
|
|
std::unique_ptr<INISettingsInterface> m_settings_interface;
|
2020-02-15 15:33:43 +00:00
|
|
|
u32 m_run_later_event_id = 0;
|
2019-11-17 09:37:10 +00:00
|
|
|
|
2020-02-28 06:59:46 +00:00
|
|
|
bool m_fullscreen = false;
|
2019-10-27 11:22:33 +00:00
|
|
|
bool m_quit_request = false;
|
2019-11-07 13:52:19 +00:00
|
|
|
bool m_settings_window_open = false;
|
2019-10-20 11:18:11 +00:00
|
|
|
bool m_about_window_open = false;
|
2020-02-28 06:59:44 +00:00
|
|
|
|
|
|
|
// this copy of the settings is modified by imgui
|
|
|
|
Settings m_settings_copy;
|
2019-09-09 07:01:26 +00:00
|
|
|
};
|