Duckstation/src/duckstation-sdl/sdl_host_interface.h

141 lines
3.4 KiB
C
Raw Normal View History

2019-09-09 07:01:26 +00:00
#pragma once
#include "common/gl/program.h"
#include "common/gl/texture.h"
#include "core/host_display.h"
#include "core/host_interface.h"
#include "frontend-common/sdl_controller_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>
#include <memory>
#include <mutex>
2020-01-10 03:31:12 +00:00
#include <string>
2019-09-09 07:01:26 +00:00
class System;
2019-10-10 16:20:21 +00:00
class AudioStream;
2019-09-09 07:01:26 +00:00
class Controller;
class SDLHostInterface final : public HostInterface
2019-09-09 07:01:26 +00:00
{
public:
SDLHostInterface();
~SDLHostInterface();
2019-09-09 07:01:26 +00:00
static std::unique_ptr<SDLHostInterface> Create();
2019-09-14 10:28:47 +00:00
void ReportError(const char* message) override;
2019-09-12 14:18:13 +00:00
void ReportMessage(const char* message) override;
bool ConfirmMessage(const char* message) override;
2019-09-09 07:01:26 +00:00
bool Initialize();
void Shutdown() override;
2019-09-09 07:01:26 +00:00
void Run();
protected:
bool AcquireHostDisplay() override;
void ReleaseHostDisplay() override;
std::unique_ptr<AudioStream> CreateAudioStream(AudioBackend backend) override;
void OnSystemCreated() override;
void OnSystemPaused(bool paused) override;
void OnSystemDestroyed();
void OnControllerTypeChanged(u32 slot) override;
2019-09-12 14:18:13 +00:00
private:
enum class KeyboardControllerAction
{
Up,
Down,
Left,
Right,
Triangle,
Cross,
Square,
Circle,
L1,
R1,
L2,
R2,
Start,
Select,
Count
};
using KeyboardControllerActionMap = std::array<s32, static_cast<int>(KeyboardControllerAction::Count)>;
2019-12-15 13:24:34 +00:00
struct ControllerData
{
SDL_GameController* controller;
SDL_Haptic* haptic;
u32 controller_index;
float last_rumble_strength;
};
bool HasSystem() const { return static_cast<bool>(m_system); }
#ifdef WIN32
bool UseOpenGLRenderer() const { return m_settings.gpu_renderer == GPURenderer::HardwareOpenGL; }
#else
bool UseOpenGLRenderer() const { return true; }
#endif
2020-02-28 06:59:48 +00:00
static float GetDPIScaleFactor(SDL_Window* window);
2019-09-12 14:18:13 +00:00
bool CreateSDLWindow();
void DestroySDLWindow();
bool CreateDisplay();
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-02-28 06:59:44 +00:00
void SaveSettings();
void UpdateSettings();
2019-11-07 15:07:39 +00:00
bool IsFullscreen() const { return m_fullscreen; }
void SetFullscreen(bool enabled);
2019-09-09 07:01:26 +00:00
// We only pass mouse input through if it's grabbed
void DrawImGuiWindows() override;
void DoStartDisc();
void DoChangeDisc();
void DoFrameStep();
2019-09-09 07:01:26 +00:00
2019-10-23 11:39:48 +00:00
void HandleSDLEvent(const SDL_Event* event);
void HandleSDLKeyEvent(const SDL_Event* event);
void UpdateKeyboardControllerMapping();
bool HandleSDLKeyEventForController(const SDL_Event* event);
void DrawMainMenuBar();
2019-11-07 15:07:39 +00:00
void DrawQuickSettingsMenu();
void DrawDebugMenu();
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);
void ClearImGuiFocus();
2019-09-09 07:01:26 +00:00
2019-09-12 14:18:13 +00:00
SDL_Window* m_window = nullptr;
std::unique_ptr<HostDisplayTexture> m_app_icon_texture;
2019-09-09 07:01:26 +00:00
KeyboardControllerActionMap m_keyboard_button_mapping;
2020-02-15 15:33:43 +00:00
u32 m_run_later_event_id = 0;
bool m_fullscreen = false;
2019-10-27 11:22:33 +00:00
bool m_quit_request = false;
bool m_frame_step_request = false;
bool m_focus_main_menu_bar = 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
};