Fixing keyboard input in imgui.
This commit is contained in:
parent
f013fde7b6
commit
0f1e870d99
|
@ -83,6 +83,8 @@ void Control::OnKeyDown(KeyEvent& e) { on_key_down(e); }
|
||||||
|
|
||||||
void Control::OnKeyUp(KeyEvent& e) { on_key_up(e); }
|
void Control::OnKeyUp(KeyEvent& e) { on_key_up(e); }
|
||||||
|
|
||||||
|
void Control::OnKeyChar(KeyEvent& e) { on_key_char(e); }
|
||||||
|
|
||||||
void Control::OnMouseDown(MouseEvent& e) { on_mouse_down(e); }
|
void Control::OnMouseDown(MouseEvent& e) { on_mouse_down(e); }
|
||||||
|
|
||||||
void Control::OnMouseMove(MouseEvent& e) { on_mouse_move(e); }
|
void Control::OnMouseMove(MouseEvent& e) { on_mouse_move(e); }
|
||||||
|
|
|
@ -77,6 +77,7 @@ class Control {
|
||||||
|
|
||||||
poly::Delegate<KeyEvent> on_key_down;
|
poly::Delegate<KeyEvent> on_key_down;
|
||||||
poly::Delegate<KeyEvent> on_key_up;
|
poly::Delegate<KeyEvent> on_key_up;
|
||||||
|
poly::Delegate<KeyEvent> on_key_char;
|
||||||
|
|
||||||
poly::Delegate<MouseEvent> on_mouse_down;
|
poly::Delegate<MouseEvent> on_mouse_down;
|
||||||
poly::Delegate<MouseEvent> on_mouse_move;
|
poly::Delegate<MouseEvent> on_mouse_move;
|
||||||
|
@ -107,6 +108,7 @@ class Control {
|
||||||
|
|
||||||
virtual void OnKeyDown(KeyEvent& e);
|
virtual void OnKeyDown(KeyEvent& e);
|
||||||
virtual void OnKeyUp(KeyEvent& e);
|
virtual void OnKeyUp(KeyEvent& e);
|
||||||
|
virtual void OnKeyChar(KeyEvent& e);
|
||||||
|
|
||||||
virtual void OnMouseDown(MouseEvent& e);
|
virtual void OnMouseDown(MouseEvent& e);
|
||||||
virtual void OnMouseMove(MouseEvent& e);
|
virtual void OnMouseMove(MouseEvent& e);
|
||||||
|
|
|
@ -356,6 +356,9 @@ bool Win32Control::HandleKeyboard(UINT message, WPARAM wParam, LPARAM lParam) {
|
||||||
case WM_KEYUP:
|
case WM_KEYUP:
|
||||||
OnKeyUp(e);
|
OnKeyUp(e);
|
||||||
break;
|
break;
|
||||||
|
case WM_CHAR:
|
||||||
|
OnKeyChar(e);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return e.is_handled();
|
return e.is_handled();
|
||||||
}
|
}
|
||||||
|
|
|
@ -318,6 +318,7 @@ int trace_viewer_main(std::vector<std::wstring>& args) {
|
||||||
window->set_title(std::wstring(L"Xenia GPU Trace Viewer: ") + file_name);
|
window->set_title(std::wstring(L"Xenia GPU Trace Viewer: ") + file_name);
|
||||||
|
|
||||||
auto graphics_system = emulator->graphics_system();
|
auto graphics_system = emulator->graphics_system();
|
||||||
|
Profiler::set_display(nullptr);
|
||||||
|
|
||||||
TracePlayer player(loop, emulator->graphics_system());
|
TracePlayer player(loop, emulator->graphics_system());
|
||||||
if (!player.Open(abs_path)) {
|
if (!player.Open(abs_path)) {
|
||||||
|
@ -326,8 +327,13 @@ int trace_viewer_main(std::vector<std::wstring>& args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto control = window->child(0);
|
auto control = window->child(0);
|
||||||
control->on_key_down.AddListener([](poly::ui::KeyEvent& e) {});
|
control->on_key_char.AddListener([](poly::ui::KeyEvent& e) {
|
||||||
control->on_key_up.AddListener([](poly::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);
|
||||||
|
});
|
||||||
control->on_mouse_down.AddListener([](poly::ui::MouseEvent& e) {
|
control->on_mouse_down.AddListener([](poly::ui::MouseEvent& e) {
|
||||||
auto& io = ImGui::GetIO();
|
auto& io = ImGui::GetIO();
|
||||||
io.MousePos = ImVec2(float(e.x()), float(e.y()));
|
io.MousePos = ImVec2(float(e.x()), float(e.y()));
|
||||||
|
@ -378,6 +384,12 @@ int trace_viewer_main(std::vector<std::wstring>& args) {
|
||||||
io.DisplaySize =
|
io.DisplaySize =
|
||||||
ImVec2(float(e.control()->width()), float(e.control()->height()));
|
ImVec2(float(e.control()->width()), float(e.control()->height()));
|
||||||
|
|
||||||
|
BYTE keystate[256];
|
||||||
|
GetKeyboardState(keystate);
|
||||||
|
for (int i = 0; i < 256; i++) io.KeysDown[i] = (keystate[i] & 0x80) != 0;
|
||||||
|
io.KeyCtrl = (keystate[VK_CONTROL] & 0x80) != 0;
|
||||||
|
io.KeyShift = (keystate[VK_SHIFT] & 0x80) != 0;
|
||||||
|
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
DrawUI(window, player);
|
DrawUI(window, player);
|
||||||
|
@ -546,6 +558,24 @@ void ImImpl_Setup() {
|
||||||
ImVec4(1.00f, 0.60f, 0.00f, 1.00f);
|
ImVec4(1.00f, 0.60f, 0.00f, 1.00f);
|
||||||
style.Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.00f, 0.00f, 1.00f, 0.35f);
|
style.Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.00f, 0.00f, 1.00f, 0.35f);
|
||||||
style.Colors[ImGuiCol_TooltipBg] = ImVec4(0.05f, 0.05f, 0.10f, 0.90f);
|
style.Colors[ImGuiCol_TooltipBg] = ImVec4(0.05f, 0.05f, 0.10f, 0.90f);
|
||||||
|
|
||||||
|
io.KeyMap[ImGuiKey_Tab] = VK_TAB;
|
||||||
|
io.KeyMap[ImGuiKey_LeftArrow] = VK_LEFT;
|
||||||
|
io.KeyMap[ImGuiKey_RightArrow] = VK_RIGHT;
|
||||||
|
io.KeyMap[ImGuiKey_UpArrow] = VK_UP;
|
||||||
|
io.KeyMap[ImGuiKey_DownArrow] = VK_UP;
|
||||||
|
io.KeyMap[ImGuiKey_Home] = VK_HOME;
|
||||||
|
io.KeyMap[ImGuiKey_End] = VK_END;
|
||||||
|
io.KeyMap[ImGuiKey_Delete] = VK_DELETE;
|
||||||
|
io.KeyMap[ImGuiKey_Backspace] = VK_BACK;
|
||||||
|
io.KeyMap[ImGuiKey_Enter] = VK_RETURN;
|
||||||
|
io.KeyMap[ImGuiKey_Escape] = VK_ESCAPE;
|
||||||
|
io.KeyMap[ImGuiKey_A] = 'A';
|
||||||
|
io.KeyMap[ImGuiKey_C] = 'C';
|
||||||
|
io.KeyMap[ImGuiKey_V] = 'V';
|
||||||
|
io.KeyMap[ImGuiKey_X] = 'X';
|
||||||
|
io.KeyMap[ImGuiKey_Y] = 'Y';
|
||||||
|
io.KeyMap[ImGuiKey_Z] = 'Z';
|
||||||
}
|
}
|
||||||
void ImImpl_Shutdown() {
|
void ImImpl_Shutdown() {
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
|
Loading…
Reference in New Issue