mirror of
https://github.com/open-goal/jak-project
synced 2026-08-21 14:54:53 -04:00
Toggle Cpp openGL with F12 / Alt + Enter / Anything else (#3901)
This is a successor to #3230 --------- Co-authored-by: Hat Kid <6624576+Hat-Kid@users.noreply.github.com>
This commit is contained in:
@@ -349,6 +349,17 @@ GLDisplay::GLDisplay(SDL_Window* window, SDL_GLContext gl_context, bool is_main)
|
||||
m_input_manager->register_command(
|
||||
CommandBinding::Source::KEYBOARD,
|
||||
CommandBinding(SDLK_F2, [&]() { m_take_screenshot_next_frame = true; }));
|
||||
|
||||
const auto& bind = Gfx::g_debug_settings.toggle_fullscreen_key;
|
||||
|
||||
m_input_manager->register_command(
|
||||
CommandBinding::Source::KEYBOARD,
|
||||
CommandBinding(bind.key, bind.modifiers, [&](const SDL_Event& event) {
|
||||
if (event.type == SDL_EVENT_KEY_DOWN && event.key.repeat == 0 &&
|
||||
bind.modifiers.has_necessary_modifiers(SDL_GetModState())) {
|
||||
m_display_manager->toggle_display_mode();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
GLDisplay::~GLDisplay() {
|
||||
|
||||
@@ -18,6 +18,7 @@ void to_json(json& j, const DebugSettings& obj) {
|
||||
json_serialize(text_check_range);
|
||||
json_serialize(text_max_range);
|
||||
json_serialize(hide_imgui_key);
|
||||
j["toggle_fullscreen_key"] = obj.toggle_fullscreen_key;
|
||||
}
|
||||
|
||||
void from_json(const json& j, DebugSettings& obj) {
|
||||
@@ -31,10 +32,11 @@ void from_json(const json& j, DebugSettings& obj) {
|
||||
json_deserialize_if_exists(text_check_range);
|
||||
json_deserialize_if_exists(text_max_range);
|
||||
json_deserialize_if_exists(hide_imgui_key);
|
||||
if (j.contains("toggle_fullscreen_key")) {
|
||||
j.at("toggle_fullscreen_key").get_to(obj.toggle_fullscreen_key);
|
||||
}
|
||||
}
|
||||
|
||||
DebugSettings::DebugSettings() {}
|
||||
|
||||
void DebugSettings::load_settings() {
|
||||
try {
|
||||
std::string file_path =
|
||||
|
||||
@@ -3,13 +3,25 @@
|
||||
#include "common/util/FileUtil.h"
|
||||
#include "common/util/json_util.h"
|
||||
|
||||
#include "SDL3/SDL.h"
|
||||
#include "game/system/hid/input_bindings.h"
|
||||
#include "game/system/hid/sdl_util.h"
|
||||
#include "game/tools/filter_menu/filter_menu.h"
|
||||
|
||||
namespace game_settings {
|
||||
|
||||
struct KeyWithModifiers {
|
||||
u32 key;
|
||||
InputModifiers modifiers;
|
||||
|
||||
KeyWithModifiers() = default;
|
||||
KeyWithModifiers(u32 k, const InputModifiers& m) : key(k), modifiers(m) {}
|
||||
};
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(KeyWithModifiers, key, modifiers)
|
||||
|
||||
struct DebugSettings {
|
||||
DebugSettings();
|
||||
DebugSettings() = default;
|
||||
|
||||
std::string current_version = "1.2";
|
||||
std::string version = current_version;
|
||||
@@ -24,11 +36,16 @@ struct DebugSettings {
|
||||
std::vector<DebugTextFilter> text_filters = {};
|
||||
bool text_check_range = false;
|
||||
float text_max_range = 0;
|
||||
|
||||
u32 hide_imgui_key = SDLK_LALT;
|
||||
|
||||
KeyWithModifiers toggle_fullscreen_key =
|
||||
KeyWithModifiers(SDLK_RETURN, InputModifiers(SDL_KMOD_ALT));
|
||||
|
||||
void load_settings();
|
||||
void save_settings();
|
||||
};
|
||||
|
||||
void to_json(json& j, const DebugSettings& obj);
|
||||
void from_json(const json& j, DebugSettings& obj);
|
||||
|
||||
|
||||
@@ -222,7 +222,13 @@ void GameController::process_event(const SDL_Event& event,
|
||||
if (event.type == SDL_EVENT_GAMEPAD_BUTTON_DOWN &&
|
||||
commands.controller_binds.find(event.gbutton.button) != commands.controller_binds.end()) {
|
||||
for (const auto& command : commands.controller_binds.at(event.gbutton.button)) {
|
||||
command.command();
|
||||
if (command.event_command) {
|
||||
command.event_command(event);
|
||||
} else if (command.command) {
|
||||
command.command();
|
||||
} else {
|
||||
lg::warn("CommandBinding has no valid callback for controller bind");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (SDL_EVENT_JOYSTICK_AXIS_MOTION && m_has_pressure_sensitive_buttons) {
|
||||
|
||||
@@ -169,7 +169,13 @@ void KeyboardDevice::process_event(const SDL_Event& event,
|
||||
commands.keyboard_binds.find(key_event.key) != commands.keyboard_binds.end()) {
|
||||
for (const auto& command : commands.keyboard_binds.at(key_event.key)) {
|
||||
if (command.modifiers.has_necessary_modifiers(key_event.mod)) {
|
||||
command.command();
|
||||
if (command.event_command) {
|
||||
command.event_command(event);
|
||||
} else if (command.command) {
|
||||
command.command();
|
||||
} else {
|
||||
lg::warn("CommandBinding has no valid callback for keyboard bind");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,7 +213,13 @@ void MouseDevice::process_event(const SDL_Event& event,
|
||||
commands.mouse_binds.find(button_event.button) != commands.mouse_binds.end()) {
|
||||
for (const auto& command : commands.mouse_binds.at(button_event.button)) {
|
||||
if (command.modifiers.has_necessary_modifiers(SDL_GetModState())) {
|
||||
command.command();
|
||||
if (command.event_command) {
|
||||
command.event_command(event);
|
||||
} else if (command.command) {
|
||||
command.command();
|
||||
} else {
|
||||
lg::warn("CommandBinding has no valid callback for mouse bind");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -300,6 +300,41 @@ void DisplayManager::set_display_mode(game_settings::DisplaySettings::DisplayMod
|
||||
}
|
||||
}
|
||||
|
||||
void DisplayManager::toggle_display_mode() {
|
||||
const auto current_mode = m_display_settings.display_mode;
|
||||
// Store the current prefered fullscreen mode
|
||||
if (current_mode != game_settings::DisplaySettings::DisplayMode::Windowed) {
|
||||
m_previous_fullscreen_display_mode = current_mode;
|
||||
}
|
||||
lg::info("Current display mode: ");
|
||||
switch (current_mode) {
|
||||
case game_settings::DisplaySettings::DisplayMode::Fullscreen:
|
||||
case game_settings::DisplaySettings::DisplayMode::Borderless:
|
||||
lg::info("Fullscreen/Borderless\n");
|
||||
lg::info("Switching to Windowed mode...\n");
|
||||
enqueue_set_window_display_mode(game_settings::DisplaySettings::DisplayMode::Windowed);
|
||||
break;
|
||||
|
||||
case game_settings::DisplaySettings::DisplayMode::Windowed:
|
||||
lg::info("Windowed\n");
|
||||
if (m_previous_fullscreen_display_mode ==
|
||||
game_settings::DisplaySettings::DisplayMode::Fullscreen) {
|
||||
lg::info("Switching to Fullscreen mode...\n");
|
||||
} else if (m_previous_fullscreen_display_mode ==
|
||||
game_settings::DisplaySettings::DisplayMode::Borderless) {
|
||||
lg::info("Switching to Borderless mode...\n");
|
||||
} else {
|
||||
lg::info("Switching to unknown preferred mode...\n");
|
||||
}
|
||||
enqueue_set_window_display_mode(m_previous_fullscreen_display_mode);
|
||||
break;
|
||||
|
||||
default:
|
||||
lg::info("Unknown display mode!\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void DisplayManager::enqueue_set_display_id(int display_id) {
|
||||
const std::lock_guard<std::mutex> lock(event_queue_mtx);
|
||||
ee_event_queue.push({EEDisplayEventType::SET_DISPLAY_ID, display_id, {}});
|
||||
|
||||
@@ -47,7 +47,8 @@ struct Resolution {
|
||||
class DisplayManager {
|
||||
private:
|
||||
enum class EEDisplayEventType { SET_WINDOW_SIZE, SET_DISPLAY_MODE, SET_DISPLAY_ID };
|
||||
|
||||
game_settings::DisplaySettings::DisplayMode m_previous_fullscreen_display_mode =
|
||||
game_settings::DisplaySettings::DisplayMode::Fullscreen;
|
||||
struct EEDisplayEvent {
|
||||
EEDisplayEventType type;
|
||||
std::variant<bool, int, game_settings::DisplaySettings::DisplayMode> param1;
|
||||
@@ -88,6 +89,7 @@ class DisplayManager {
|
||||
// Mutators
|
||||
void enqueue_set_window_size(int width, int height);
|
||||
void enqueue_set_window_display_mode(game_settings::DisplaySettings::DisplayMode mode);
|
||||
void toggle_display_mode();
|
||||
void enqueue_set_display_id(int display_id);
|
||||
|
||||
void set_game_size(int width, int height) {
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
#include "common/log/log.h"
|
||||
#include "common/util/json_util.h"
|
||||
|
||||
#include "SDL3/SDL.h"
|
||||
|
||||
#define GET_PRESSURE_BUTTON_DATA(button_name) \
|
||||
{button_data.at(ButtonIndex::button_name), \
|
||||
pressure_data.at(PressureIndex::button_name##_PRESSURE)};
|
||||
@@ -391,11 +393,23 @@ extern const InputBindingGroups DEFAULT_MOUSE_BINDS;
|
||||
struct CommandBinding {
|
||||
enum Source { CONTROLLER, KEYBOARD, MOUSE };
|
||||
|
||||
CommandBinding(const u32 _host_key, std::function<void()> _command)
|
||||
: host_key(_host_key), command(_command) {};
|
||||
u32 host_key;
|
||||
std::function<void()> command;
|
||||
InputModifiers modifiers;
|
||||
|
||||
// Three types of callbacks: one with SDL_Event, one without, and one with input modifiers
|
||||
std::function<void()> command = nullptr;
|
||||
std::function<void(const SDL_Event&)> event_command = nullptr;
|
||||
|
||||
CommandBinding(u32 _host_key, std::function<void()> _command)
|
||||
: host_key(_host_key), command(std::move(_command)) {}
|
||||
|
||||
CommandBinding(u32 _host_key, std::function<void(const SDL_Event&)> _command)
|
||||
: host_key(_host_key), event_command(std::move(_command)) {}
|
||||
|
||||
CommandBinding(u32 _host_key,
|
||||
const InputModifiers& _modifiers,
|
||||
std::function<void(const SDL_Event&)> _command)
|
||||
: host_key(_host_key), modifiers(_modifiers), event_command(std::move(_command)) {}
|
||||
};
|
||||
|
||||
struct CommandBindingGroups {
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
||||
!.gitignore
|
||||
Reference in New Issue
Block a user