diff --git a/src/xenia/debug/ui/debug_window.cc b/src/xenia/debug/ui/debug_window.cc index 31873095a..5711de711 100644 --- a/src/xenia/debug/ui/debug_window.cc +++ b/src/xenia/debug/ui/debug_window.cc @@ -121,74 +121,7 @@ bool DebugWindow::Initialize() { // Setup ImGui. imgui_drawer_ = std::make_unique(window_.get()); - window_->on_key_char.AddListener([](xe::ui::KeyEvent* e) { - auto& io = ImGui::GetIO(); - if (e->key_code() > 0 && e->key_code() < 0x10000) { - io.AddInputCharacter(e->key_code()); - } - e->set_handled(true); - }); - window_->on_key_down.AddListener([](xe::ui::KeyEvent* e) { - auto& io = ImGui::GetIO(); - io.KeysDown[e->key_code()] = true; - switch (e->key_code()) { - case 16: - io.KeyShift = true; - break; - case 17: - io.KeyCtrl = true; - break; - } - }); - window_->on_key_up.AddListener([](xe::ui::KeyEvent* e) { - auto& io = ImGui::GetIO(); - io.KeysDown[e->key_code()] = false; - switch (e->key_code()) { - case 16: - io.KeyShift = false; - break; - case 17: - io.KeyCtrl = false; - break; - } - }); - window_->on_mouse_down.AddListener([](xe::ui::MouseEvent* e) { - auto& io = ImGui::GetIO(); - io.MousePos = - ImVec2(static_cast(e->x()), static_cast(e->y())); - switch (e->button()) { - case xe::ui::MouseEvent::Button::kLeft: - io.MouseDown[0] = true; - break; - case xe::ui::MouseEvent::Button::kRight: - io.MouseDown[1] = true; - break; - } - }); - window_->on_mouse_move.AddListener([](xe::ui::MouseEvent* e) { - auto& io = ImGui::GetIO(); - io.MousePos = - ImVec2(static_cast(e->x()), static_cast(e->y())); - }); - window_->on_mouse_up.AddListener([](xe::ui::MouseEvent* e) { - auto& io = ImGui::GetIO(); - io.MousePos = - ImVec2(static_cast(e->x()), static_cast(e->y())); - switch (e->button()) { - case xe::ui::MouseEvent::Button::kLeft: - io.MouseDown[0] = false; - break; - case xe::ui::MouseEvent::Button::kRight: - io.MouseDown[1] = false; - break; - } - }); - window_->on_mouse_wheel.AddListener([](xe::ui::MouseEvent* e) { - auto& io = ImGui::GetIO(); - io.MousePos = - ImVec2(static_cast(e->x()), static_cast(e->y())); - io.MouseWheel += e->dy() / 120.0f; - }); + imgui_drawer_->SetupDefaultInput(); window_->on_painting.AddListener([this](UIEvent* e) { DrawFrame(); }); diff --git a/src/xenia/gpu/gl4/trace_viewer_main.cc b/src/xenia/gpu/gl4/trace_viewer_main.cc index e1289c69a..73874f00a 100644 --- a/src/xenia/gpu/gl4/trace_viewer_main.cc +++ b/src/xenia/gpu/gl4/trace_viewer_main.cc @@ -2238,6 +2238,7 @@ int trace_viewer_main(const std::vector& args) { auto graphics_system = emulator->graphics_system(); imgui_drawer_ = std::make_unique(window.get()); + imgui_drawer_->SetupDefaultInput(); TracePlayer player(loop.get(), graphics_system); if (!player.Open(abs_path)) { @@ -2246,48 +2247,10 @@ int trace_viewer_main(const std::vector& args) { } window->on_key_char.AddListener([graphics_system](xe::ui::KeyEvent* e) { - auto& io = ImGui::GetIO(); - if (e->key_code() > 0 && e->key_code() < 0x10000) { - if (e->key_code() == 0x74 /* VK_F5 */) { - graphics_system->ClearCaches(); - } else { - io.AddInputCharacter(e->key_code()); - } + if (e->key_code() == 0x74 /* VK_F5 */) { + graphics_system->ClearCaches(); + e->set_handled(true); } - e->set_handled(true); - }); - window->on_mouse_down.AddListener([](xe::ui::MouseEvent* e) { - auto& io = ImGui::GetIO(); - io.MousePos = ImVec2(float(e->x()), float(e->y())); - switch (e->button()) { - case xe::ui::MouseEvent::Button::kLeft: - io.MouseDown[0] = true; - break; - case xe::ui::MouseEvent::Button::kRight: - io.MouseDown[1] = true; - break; - } - }); - window->on_mouse_move.AddListener([](xe::ui::MouseEvent* e) { - auto& io = ImGui::GetIO(); - io.MousePos = ImVec2(float(e->x()), float(e->y())); - }); - window->on_mouse_up.AddListener([](xe::ui::MouseEvent* e) { - auto& io = ImGui::GetIO(); - io.MousePos = ImVec2(float(e->x()), float(e->y())); - switch (e->button()) { - case xe::ui::MouseEvent::Button::kLeft: - io.MouseDown[0] = false; - break; - case xe::ui::MouseEvent::Button::kRight: - io.MouseDown[1] = false; - break; - } - }); - window->on_mouse_wheel.AddListener([](xe::ui::MouseEvent* e) { - auto& io = ImGui::GetIO(); - io.MousePos = ImVec2(float(e->x()), float(e->y())); - io.MouseWheel += float(e->dy() / 120.0f); }); window->on_painting.AddListener([&](xe::ui::UIEvent* e) { diff --git a/src/xenia/hid/hid_demo.cc b/src/xenia/hid/hid_demo.cc index c543f047f..90694e97d 100644 --- a/src/xenia/hid/hid_demo.cc +++ b/src/xenia/hid/hid_demo.cc @@ -67,76 +67,12 @@ int hid_demo_main(const std::vector& args) { // Initialize the ImGui renderer we'll use. imgui_drawer_ = std::make_unique(window.get()); + imgui_drawer_->SetupDefaultInput(); // Initialize input system and all drivers. input_system_ = xe::hid::InputSystem::Create(window.get()); }); - window->on_key_char.AddListener([](xe::ui::KeyEvent* e) { - auto& io = ImGui::GetIO(); - if (e->key_code() > 0 && e->key_code() < 0x10000) { - io.AddInputCharacter(e->key_code()); - } - e->set_handled(true); - }); - window->on_key_down.AddListener([](xe::ui::KeyEvent* e) { - auto& io = ImGui::GetIO(); - io.KeysDown[e->key_code()] = true; - switch (e->key_code()) { - case 16: { - io.KeyShift = true; - } break; - case 17: { - io.KeyCtrl = true; - } break; - } - }); - window->on_key_up.AddListener([](xe::ui::KeyEvent* e) { - auto& io = ImGui::GetIO(); - io.KeysDown[e->key_code()] = false; - switch (e->key_code()) { - case 16: { - io.KeyShift = false; - } break; - case 17: { - io.KeyCtrl = false; - } break; - } - }); - window->on_mouse_down.AddListener([](xe::ui::MouseEvent* e) { - auto& io = ImGui::GetIO(); - io.MousePos = ImVec2(float(e->x()), float(e->y())); - switch (e->button()) { - case xe::ui::MouseEvent::Button::kLeft: { - io.MouseDown[0] = true; - } break; - case xe::ui::MouseEvent::Button::kRight: { - io.MouseDown[1] = true; - } break; - } - }); - window->on_mouse_move.AddListener([](xe::ui::MouseEvent* e) { - auto& io = ImGui::GetIO(); - io.MousePos = ImVec2(float(e->x()), float(e->y())); - }); - window->on_mouse_up.AddListener([](xe::ui::MouseEvent* e) { - auto& io = ImGui::GetIO(); - io.MousePos = ImVec2(float(e->x()), float(e->y())); - switch (e->button()) { - case xe::ui::MouseEvent::Button::kLeft: { - io.MouseDown[0] = false; - } break; - case xe::ui::MouseEvent::Button::kRight: { - io.MouseDown[1] = false; - } break; - } - }); - window->on_mouse_wheel.AddListener([](xe::ui::MouseEvent* e) { - auto& io = ImGui::GetIO(); - io.MousePos = ImVec2(float(e->x()), float(e->y())); - io.MouseWheel += float(e->dy() / 120.0f); - }); - window->on_painting.AddListener([&](xe::ui::UIEvent* e) { auto& io = ImGui::GetIO(); auto current_tick_count = Clock::QueryHostTickCount(); diff --git a/src/xenia/ui/imgui_drawer.cc b/src/xenia/ui/imgui_drawer.cc index b03994d9d..5c6105a08 100644 --- a/src/xenia/ui/imgui_drawer.cc +++ b/src/xenia/ui/imgui_drawer.cc @@ -196,5 +196,72 @@ void ImGuiDrawer::RenderDrawLists(ImDrawData* data) { drawer->End(); } +void ImGuiDrawer::SetupDefaultInput() { + window_->on_key_char.AddListener([](xe::ui::KeyEvent* e) { + auto& io = ImGui::GetIO(); + if (e->key_code() > 0 && e->key_code() < 0x10000) { + io.AddInputCharacter(e->key_code()); + e->set_handled(true); + } + }); + window_->on_key_down.AddListener([](xe::ui::KeyEvent* e) { + auto& io = ImGui::GetIO(); + io.KeysDown[e->key_code()] = true; + switch (e->key_code()) { + case 16: { + io.KeyShift = true; + } break; + case 17: { + io.KeyCtrl = true; + } break; + } + }); + window_->on_key_up.AddListener([](xe::ui::KeyEvent* e) { + auto& io = ImGui::GetIO(); + io.KeysDown[e->key_code()] = false; + switch (e->key_code()) { + case 16: { + io.KeyShift = false; + } break; + case 17: { + io.KeyCtrl = false; + } break; + } + }); + window_->on_mouse_down.AddListener([](xe::ui::MouseEvent* e) { + auto& io = ImGui::GetIO(); + io.MousePos = ImVec2(float(e->x()), float(e->y())); + switch (e->button()) { + case xe::ui::MouseEvent::Button::kLeft: { + io.MouseDown[0] = true; + } break; + case xe::ui::MouseEvent::Button::kRight: { + io.MouseDown[1] = true; + } break; + } + }); + window_->on_mouse_move.AddListener([](xe::ui::MouseEvent* e) { + auto& io = ImGui::GetIO(); + io.MousePos = ImVec2(float(e->x()), float(e->y())); + }); + window_->on_mouse_up.AddListener([](xe::ui::MouseEvent* e) { + auto& io = ImGui::GetIO(); + io.MousePos = ImVec2(float(e->x()), float(e->y())); + switch (e->button()) { + case xe::ui::MouseEvent::Button::kLeft: { + io.MouseDown[0] = false; + } break; + case xe::ui::MouseEvent::Button::kRight: { + io.MouseDown[1] = false; + } break; + } + }); + window_->on_mouse_wheel.AddListener([](xe::ui::MouseEvent* e) { + auto& io = ImGui::GetIO(); + io.MousePos = ImVec2(float(e->x()), float(e->y())); + io.MouseWheel += float(e->dy() / 120.0f); + }); +} + } // namespace ui } // namespace xe diff --git a/src/xenia/ui/imgui_drawer.h b/src/xenia/ui/imgui_drawer.h index c6853a69f..af00f02a0 100644 --- a/src/xenia/ui/imgui_drawer.h +++ b/src/xenia/ui/imgui_drawer.h @@ -27,6 +27,8 @@ class ImGuiDrawer { ImGuiDrawer(Window* window); ~ImGuiDrawer(); + void SetupDefaultInput(); + protected: void Initialize(); void SetupFont(); diff --git a/src/xenia/ui/window_demo.cc b/src/xenia/ui/window_demo.cc index 1b1ebcbc2..61f07d0bf 100644 --- a/src/xenia/ui/window_demo.cc +++ b/src/xenia/ui/window_demo.cc @@ -91,78 +91,19 @@ int window_demo_main(const std::vector& args) { // Initialize the ImGui renderer we'll use. imgui_drawer_ = std::make_unique(window.get()); + imgui_drawer_->SetupDefaultInput(); // Show the elemental-forms debug UI so we can see it working. el::util::ShowDebugInfoSettingsForm(window->root_element()); }); - window->on_key_char.AddListener([](xe::ui::KeyEvent* e) { - auto& io = ImGui::GetIO(); - if (e->key_code() > 0 && e->key_code() < 0x10000) { - io.AddInputCharacter(e->key_code()); - } - e->set_handled(true); - }); window->on_key_down.AddListener([](xe::ui::KeyEvent* e) { - auto& io = ImGui::GetIO(); - io.KeysDown[e->key_code()] = true; switch (e->key_code()) { case 0x72: { // F3 Profiler::ToggleDisplay(); } break; - case 16: { - io.KeyShift = true; - } break; - case 17: { - io.KeyCtrl = true; - } break; } }); - window->on_key_up.AddListener([](xe::ui::KeyEvent* e) { - auto& io = ImGui::GetIO(); - io.KeysDown[e->key_code()] = false; - switch (e->key_code()) { - case 16: { - io.KeyShift = false; - } break; - case 17: { - io.KeyCtrl = false; - } break; - } - }); - window->on_mouse_down.AddListener([](xe::ui::MouseEvent* e) { - auto& io = ImGui::GetIO(); - io.MousePos = ImVec2(float(e->x()), float(e->y())); - switch (e->button()) { - case xe::ui::MouseEvent::Button::kLeft: { - io.MouseDown[0] = true; - } break; - case xe::ui::MouseEvent::Button::kRight: { - io.MouseDown[1] = true; - } break; - } - }); - window->on_mouse_move.AddListener([](xe::ui::MouseEvent* e) { - auto& io = ImGui::GetIO(); - io.MousePos = ImVec2(float(e->x()), float(e->y())); - }); - window->on_mouse_up.AddListener([](xe::ui::MouseEvent* e) { - auto& io = ImGui::GetIO(); - io.MousePos = ImVec2(float(e->x()), float(e->y())); - switch (e->button()) { - case xe::ui::MouseEvent::Button::kLeft: { - io.MouseDown[0] = false; - } break; - case xe::ui::MouseEvent::Button::kRight: { - io.MouseDown[1] = false; - } break; - } - }); - window->on_mouse_wheel.AddListener([](xe::ui::MouseEvent* e) { - auto& io = ImGui::GetIO(); - io.MousePos = ImVec2(float(e->x()), float(e->y())); - io.MouseWheel += float(e->dy() / 120.0f); - }); window->on_painting.AddListener([&](xe::ui::UIEvent* e) { auto& io = ImGui::GetIO();