Moving imgui input to a shared place.
This commit is contained in:
parent
1d9f73ad13
commit
b26f4a5719
|
@ -121,74 +121,7 @@ bool DebugWindow::Initialize() {
|
|||
|
||||
// Setup ImGui.
|
||||
imgui_drawer_ = std::make_unique<xe::ui::ImGuiDrawer>(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<float>(e->x()), static_cast<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(static_cast<float>(e->x()), static_cast<float>(e->y()));
|
||||
});
|
||||
window_->on_mouse_up.AddListener([](xe::ui::MouseEvent* e) {
|
||||
auto& io = ImGui::GetIO();
|
||||
io.MousePos =
|
||||
ImVec2(static_cast<float>(e->x()), static_cast<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(static_cast<float>(e->x()), static_cast<float>(e->y()));
|
||||
io.MouseWheel += e->dy() / 120.0f;
|
||||
});
|
||||
imgui_drawer_->SetupDefaultInput();
|
||||
|
||||
window_->on_painting.AddListener([this](UIEvent* e) { DrawFrame(); });
|
||||
|
||||
|
|
|
@ -2238,6 +2238,7 @@ int trace_viewer_main(const std::vector<std::wstring>& args) {
|
|||
auto graphics_system = emulator->graphics_system();
|
||||
|
||||
imgui_drawer_ = std::make_unique<xe::ui::ImGuiDrawer>(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<std::wstring>& 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) {
|
||||
|
|
|
@ -67,76 +67,12 @@ int hid_demo_main(const std::vector<std::wstring>& args) {
|
|||
|
||||
// Initialize the ImGui renderer we'll use.
|
||||
imgui_drawer_ = std::make_unique<xe::ui::ImGuiDrawer>(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();
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -27,6 +27,8 @@ class ImGuiDrawer {
|
|||
ImGuiDrawer(Window* window);
|
||||
~ImGuiDrawer();
|
||||
|
||||
void SetupDefaultInput();
|
||||
|
||||
protected:
|
||||
void Initialize();
|
||||
void SetupFont();
|
||||
|
|
|
@ -91,78 +91,19 @@ int window_demo_main(const std::vector<std::wstring>& args) {
|
|||
|
||||
// Initialize the ImGui renderer we'll use.
|
||||
imgui_drawer_ = std::make_unique<xe::ui::ImGuiDrawer>(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();
|
||||
|
|
Loading…
Reference in New Issue