[ImGui] Use new key API
This commit is contained in:
parent
b641e39c4d
commit
da9c90835b
|
@ -184,24 +184,6 @@ void ImGuiDrawer::Initialize() {
|
|||
style.Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.00f, 1.00f, 0.00f, 0.21f);
|
||||
style.Colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.20f, 0.20f, 0.20f, 0.35f);
|
||||
|
||||
io.KeyMap[ImGuiKey_Tab] = int(ui::VirtualKey::kTab);
|
||||
io.KeyMap[ImGuiKey_LeftArrow] = int(ui::VirtualKey::kLeft);
|
||||
io.KeyMap[ImGuiKey_RightArrow] = int(ui::VirtualKey::kRight);
|
||||
io.KeyMap[ImGuiKey_UpArrow] = int(ui::VirtualKey::kUp);
|
||||
io.KeyMap[ImGuiKey_DownArrow] = int(ui::VirtualKey::kDown);
|
||||
io.KeyMap[ImGuiKey_Home] = int(ui::VirtualKey::kHome);
|
||||
io.KeyMap[ImGuiKey_End] = int(ui::VirtualKey::kEnd);
|
||||
io.KeyMap[ImGuiKey_Delete] = int(ui::VirtualKey::kDelete);
|
||||
io.KeyMap[ImGuiKey_Backspace] = int(ui::VirtualKey::kBack);
|
||||
io.KeyMap[ImGuiKey_Enter] = int(ui::VirtualKey::kReturn);
|
||||
io.KeyMap[ImGuiKey_Escape] = int(ui::VirtualKey::kEscape);
|
||||
io.KeyMap[ImGuiKey_A] = int(ui::VirtualKey::kA);
|
||||
io.KeyMap[ImGuiKey_C] = int(ui::VirtualKey::kC);
|
||||
io.KeyMap[ImGuiKey_V] = int(ui::VirtualKey::kV);
|
||||
io.KeyMap[ImGuiKey_X] = int(ui::VirtualKey::kX);
|
||||
io.KeyMap[ImGuiKey_Y] = int(ui::VirtualKey::kY);
|
||||
io.KeyMap[ImGuiKey_Z] = int(ui::VirtualKey::kZ);
|
||||
|
||||
frame_time_tick_frequency_ = double(Clock::QueryHostTickFrequency());
|
||||
last_frame_time_ticks_ = Clock::QueryHostTickCount();
|
||||
|
||||
|
@ -209,6 +191,33 @@ void ImGuiDrawer::Initialize() {
|
|||
reset_mouse_position_after_next_frame_ = false;
|
||||
}
|
||||
|
||||
std::optional<ImGuiKey> ImGuiDrawer::VirtualKeyToImGuiKey(VirtualKey vkey) {
|
||||
static const std::map<VirtualKey, ImGuiKey> map = {
|
||||
{ui::VirtualKey::kTab, ImGuiKey_Tab},
|
||||
{ui::VirtualKey::kLeft, ImGuiKey_LeftArrow},
|
||||
{ui::VirtualKey::kRight, ImGuiKey_RightArrow},
|
||||
{ui::VirtualKey::kUp, ImGuiKey_UpArrow},
|
||||
{ui::VirtualKey::kDown, ImGuiKey_DownArrow},
|
||||
{ui::VirtualKey::kHome, ImGuiKey_Home},
|
||||
{ui::VirtualKey::kEnd, ImGuiKey_End},
|
||||
{ui::VirtualKey::kDelete, ImGuiKey_Delete},
|
||||
{ui::VirtualKey::kBack, ImGuiKey_Backspace},
|
||||
{ui::VirtualKey::kReturn, ImGuiKey_Enter},
|
||||
{ui::VirtualKey::kEscape, ImGuiKey_Escape},
|
||||
{ui::VirtualKey::kA, ImGuiKey_A},
|
||||
{ui::VirtualKey::kC, ImGuiKey_C},
|
||||
{ui::VirtualKey::kV, ImGuiKey_V},
|
||||
{ui::VirtualKey::kX, ImGuiKey_X},
|
||||
{ui::VirtualKey::kY, ImGuiKey_Y},
|
||||
{ui::VirtualKey::kZ, ImGuiKey_Z},
|
||||
};
|
||||
if (auto search = map.find(vkey); search != map.end()) {
|
||||
return search->second;
|
||||
} else {
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
void ImGuiDrawer::SetupFontTexture() {
|
||||
if (font_texture_ || !immediate_drawer_) {
|
||||
return;
|
||||
|
@ -484,13 +493,7 @@ void ImGuiDrawer::ClearInput() {
|
|||
}
|
||||
io.MousePos = ImVec2(-FLT_MAX, -FLT_MAX);
|
||||
std::memset(io.MouseDown, 0, sizeof(io.MouseDown));
|
||||
io.MouseWheel = 0.0f;
|
||||
io.MouseWheelH = 0.0f;
|
||||
io.KeyCtrl = false;
|
||||
io.KeyShift = false;
|
||||
io.KeyAlt = false;
|
||||
io.KeySuper = false;
|
||||
std::memset(io.KeysDown, 0, sizeof(io.KeysDown));
|
||||
io.ClearInputKeys();
|
||||
io.ClearInputCharacters();
|
||||
touch_pointer_id_ = TouchEvent::kPointerIDNone;
|
||||
reset_mouse_position_after_next_frame_ = false;
|
||||
|
@ -498,9 +501,9 @@ void ImGuiDrawer::ClearInput() {
|
|||
|
||||
void ImGuiDrawer::OnKey(KeyEvent& e, bool is_down) {
|
||||
auto& io = GetIO();
|
||||
VirtualKey virtual_key = e.virtual_key();
|
||||
if (size_t(virtual_key) < xe::countof(io.KeysDown)) {
|
||||
io.KeysDown[size_t(virtual_key)] = is_down;
|
||||
const VirtualKey virtual_key = e.virtual_key();
|
||||
if (auto imGuiKey = VirtualKeyToImGuiKey(virtual_key); imGuiKey) {
|
||||
io.AddKeyEvent(*imGuiKey, is_down);
|
||||
}
|
||||
switch (virtual_key) {
|
||||
case VirtualKey::kShift:
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
struct ImDrawData;
|
||||
struct ImGuiContext;
|
||||
struct ImGuiIO;
|
||||
enum ImGuiKey : int;
|
||||
|
||||
namespace xe {
|
||||
namespace ui {
|
||||
|
@ -77,6 +78,8 @@ class ImGuiDrawer : public WindowInputListener, public UIDrawer {
|
|||
bool IsDrawingDialogs() const { return dialog_loop_next_index_ != SIZE_MAX; }
|
||||
void DetachIfLastDialogRemoved();
|
||||
|
||||
std::optional<ImGuiKey> VirtualKeyToImGuiKey(VirtualKey vkey);
|
||||
|
||||
Window* window_;
|
||||
size_t z_order_;
|
||||
|
||||
|
|
Loading…
Reference in New Issue