Moving imgui input to a shared place.

This commit is contained in:
Ben Vanik 2015-11-07 12:42:44 -08:00
parent 1d9f73ad13
commit b26f4a5719
6 changed files with 76 additions and 234 deletions

View File

@ -121,74 +121,7 @@ bool DebugWindow::Initialize() {
// Setup ImGui. // Setup ImGui.
imgui_drawer_ = std::make_unique<xe::ui::ImGuiDrawer>(window_.get()); imgui_drawer_ = std::make_unique<xe::ui::ImGuiDrawer>(window_.get());
window_->on_key_char.AddListener([](xe::ui::KeyEvent* e) { imgui_drawer_->SetupDefaultInput();
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;
});
window_->on_painting.AddListener([this](UIEvent* e) { DrawFrame(); }); window_->on_painting.AddListener([this](UIEvent* e) { DrawFrame(); });

View File

@ -2238,6 +2238,7 @@ int trace_viewer_main(const std::vector<std::wstring>& args) {
auto graphics_system = emulator->graphics_system(); auto graphics_system = emulator->graphics_system();
imgui_drawer_ = std::make_unique<xe::ui::ImGuiDrawer>(window.get()); imgui_drawer_ = std::make_unique<xe::ui::ImGuiDrawer>(window.get());
imgui_drawer_->SetupDefaultInput();
TracePlayer player(loop.get(), graphics_system); TracePlayer player(loop.get(), graphics_system);
if (!player.Open(abs_path)) { 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) { window->on_key_char.AddListener([graphics_system](xe::ui::KeyEvent* e) {
auto& io = ImGui::GetIO(); if (e->key_code() == 0x74 /* VK_F5 */) {
if (e->key_code() > 0 && e->key_code() < 0x10000) { graphics_system->ClearCaches();
if (e->key_code() == 0x74 /* VK_F5 */) { e->set_handled(true);
graphics_system->ClearCaches();
} else {
io.AddInputCharacter(e->key_code());
}
} }
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) { window->on_painting.AddListener([&](xe::ui::UIEvent* e) {

View File

@ -67,76 +67,12 @@ int hid_demo_main(const std::vector<std::wstring>& args) {
// Initialize the ImGui renderer we'll use. // Initialize the ImGui renderer we'll use.
imgui_drawer_ = std::make_unique<xe::ui::ImGuiDrawer>(window.get()); imgui_drawer_ = std::make_unique<xe::ui::ImGuiDrawer>(window.get());
imgui_drawer_->SetupDefaultInput();
// Initialize input system and all drivers. // Initialize input system and all drivers.
input_system_ = xe::hid::InputSystem::Create(window.get()); 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) { window->on_painting.AddListener([&](xe::ui::UIEvent* e) {
auto& io = ImGui::GetIO(); auto& io = ImGui::GetIO();
auto current_tick_count = Clock::QueryHostTickCount(); auto current_tick_count = Clock::QueryHostTickCount();

View File

@ -196,5 +196,72 @@ void ImGuiDrawer::RenderDrawLists(ImDrawData* data) {
drawer->End(); 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 ui
} // namespace xe } // namespace xe

View File

@ -27,6 +27,8 @@ class ImGuiDrawer {
ImGuiDrawer(Window* window); ImGuiDrawer(Window* window);
~ImGuiDrawer(); ~ImGuiDrawer();
void SetupDefaultInput();
protected: protected:
void Initialize(); void Initialize();
void SetupFont(); void SetupFont();

View File

@ -91,78 +91,19 @@ int window_demo_main(const std::vector<std::wstring>& args) {
// Initialize the ImGui renderer we'll use. // Initialize the ImGui renderer we'll use.
imgui_drawer_ = std::make_unique<xe::ui::ImGuiDrawer>(window.get()); 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. // Show the elemental-forms debug UI so we can see it working.
el::util::ShowDebugInfoSettingsForm(window->root_element()); 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) { window->on_key_down.AddListener([](xe::ui::KeyEvent* e) {
auto& io = ImGui::GetIO();
io.KeysDown[e->key_code()] = true;
switch (e->key_code()) { switch (e->key_code()) {
case 0x72: { // F3 case 0x72: { // F3
Profiler::ToggleDisplay(); Profiler::ToggleDisplay();
} break; } 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) { window->on_painting.AddListener([&](xe::ui::UIEvent* e) {
auto& io = ImGui::GetIO(); auto& io = ImGui::GetIO();