diff --git a/include/recomp_ui.h b/include/recomp_ui.h index b8e4f85..a41f6a1 100644 --- a/include/recomp_ui.h +++ b/include/recomp_ui.h @@ -49,7 +49,8 @@ namespace recompui { void hide_context(ContextId context); void hide_all_contexts(); bool is_context_shown(ContextId context); - bool is_context_taking_input(); + bool is_context_capturing_input(); + bool is_context_capturing_mouse(); bool is_any_context_shown(); ContextId get_launcher_context_id(); diff --git a/src/game/input.cpp b/src/game/input.cpp index 8d59e0c..7384e37 100644 --- a/src/game/input.cpp +++ b/src/game/input.cpp @@ -103,7 +103,7 @@ bool sdl_event_filter(void* userdata, SDL_Event* event) { SDL_KeyboardEvent* keyevent = &event->key; // Skip repeated events when not in the menu - if (!recompui::is_context_taking_input() && + if (!recompui::is_context_capturing_input() && event->key.repeat) { break; } @@ -713,7 +713,7 @@ void recomp::set_right_analog_suppressed(bool suppressed) { bool recomp::game_input_disabled() { // Disable input if any menu that blocks input is open. - return recompui::is_context_taking_input(); + return recompui::is_context_capturing_input(); } bool recomp::all_input_disabled() { diff --git a/src/ui/core/ui_context.cpp b/src/ui/core/ui_context.cpp index ff457b8..ce1b38c 100644 --- a/src/ui/core/ui_context.cpp +++ b/src/ui/core/ui_context.cpp @@ -34,6 +34,8 @@ namespace recompui { Element root_element; std::vector loose_elements; std::unordered_set to_update; + bool captures_input = true; + bool captures_mouse = true; Context(Rml::ElementDocument* document) : document(document), root_element(document) {} }; } // namespace recompui @@ -371,6 +373,47 @@ void recompui::ContextId::process_updates() { } } +bool recompui::ContextId::captures_input() { + std::lock_guard lock{ context_state.all_contexts_lock }; + + Context* ctx = context_state.all_contexts.get(context_slotmap::key{ slot_id }); + if (ctx == nullptr) { + return false; + } + return ctx->captures_input; + +} + +bool recompui::ContextId::captures_mouse() { + std::lock_guard lock{ context_state.all_contexts_lock }; + + Context* ctx = context_state.all_contexts.get(context_slotmap::key{ slot_id }); + if (ctx == nullptr) { + return false; + } + return ctx->captures_mouse; +} + +void recompui::ContextId::set_captures_input(bool captures_input) { + std::lock_guard lock{ context_state.all_contexts_lock }; + + Context* ctx = context_state.all_contexts.get(context_slotmap::key{ slot_id }); + if (ctx == nullptr) { + return; + } + ctx->captures_input = captures_input; +} + +void recompui::ContextId::set_captures_mouse(bool captures_mouse) { + std::lock_guard lock{ context_state.all_contexts_lock }; + + Context* ctx = context_state.all_contexts.get(context_slotmap::key{ slot_id }); + if (ctx == nullptr) { + return; + } + ctx->captures_mouse = captures_mouse; +} + recompui::Style* recompui::ContextId::add_resource_impl(std::unique_ptr