Skip to content

Commit d3693f2

Browse files
authored
Merge pull request #962 from justarandomguyintheinternet/master
Added back ImGui Input functions
2 parents 5549f67 + caa0ce5 commit d3693f2

File tree

3 files changed

+191
-0
lines changed

3 files changed

+191
-0
lines changed

Diff for: src/imgui_impl/win32.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,19 @@ bool ImGui_ImplWin32_Init(HWND ahWnd)
9292
io.KeyMap[ImGuiKey_Enter] = VK_RETURN;
9393
io.KeyMap[ImGuiKey_Escape] = VK_ESCAPE;
9494
io.KeyMap[ImGuiKey_KeyPadEnter] = VK_RETURN;
95+
io.KeyMap[ImGuiKey_LeftCtrl] = VK_CONTROL;
96+
io.KeyMap[ImGuiKey_LeftShift] = VK_SHIFT;
9597
io.KeyMap[ImGuiKey_A] = 'A';
9698
io.KeyMap[ImGuiKey_C] = 'C';
9799
io.KeyMap[ImGuiKey_V] = 'V';
98100
io.KeyMap[ImGuiKey_X] = 'X';
99101
io.KeyMap[ImGuiKey_Y] = 'Y';
100102
io.KeyMap[ImGuiKey_Z] = 'Z';
103+
io.KeyMap[ImGuiKey_G] = 'G';
104+
io.KeyMap[ImGuiKey_S] = 'S';
105+
io.KeyMap[ImGuiKey_D] = 'D';
106+
io.KeyMap[ImGuiKey_R] = 'R';
107+
io.KeyMap[ImGuiKey_H] = 'H';
101108

102109
return true;
103110
}

Diff for: src/sol_imgui/README.md

+76
Original file line numberDiff line numberDiff line change
@@ -1424,14 +1424,76 @@ selected, activated = ImGui.MenuItem("Label", "ALT+F4", selected, true)
14241424
color_u32 = ImGui.ColorConvertFloat4ToU32({0.4, 0.2, 0, 1})
14251425
```
14261426

1427+
## Inputs Utilities: Keyboard
1428+
```lua
1429+
-- ImGui.GetKeyIndex(...)
1430+
-- Parameters: ImGuiKey (key)
1431+
-- Returns: int (index)
1432+
index = ImGui.GetKeyIndex(ImGuiKey.Tab)
1433+
1434+
-- ImGui.IsKeyDown(...)
1435+
-- Parameters: int (key_index)
1436+
-- Returns: bool (down)
1437+
down = ImGui.IsKeyDown(0)
1438+
1439+
-- ImGui.IsKeyPressed(...)
1440+
-- Parameters: int (key_index), bool (repeat) [O]
1441+
-- Returns: bool (pressed)
1442+
-- Overloads
1443+
pressed = ImGui.IsKeyPressed(0)
1444+
pressed = ImGui.IsKeyPressed(0, true)
1445+
1446+
-- ImGui.IsKeyReleased(...)
1447+
-- Parameters: int (key_index)
1448+
-- Returns: bool (released)
1449+
released = ImGui.IsKeyReleased(0)
1450+
1451+
-- ImGui.GetKeyPressedAmount(...)
1452+
-- Parameters: int (key_index), float (repeat_delay), float (rate)
1453+
-- Returns: int (pressed_amount)
1454+
pressed_amount = ImGui.GetKeyPressedAmount(0, 0.5, 5)
1455+
1456+
-- ImGui.CaptureKeyboardFromApp(...)
1457+
-- Parameters: bool (want_capture_keyboard_value) [O]
1458+
-- Overloads
1459+
ImGui.CaptureKeyboardFromApp()
1460+
ImGui.CaptureKeyboardFromApp(false)
1461+
```
1462+
14271463
## Inputs Utilities: Mouse
14281464
```lua
1465+
-- ImGui.IsMouseDown(...)
1466+
-- Parameters: ImGuiMouseButton (button)
1467+
-- Returns: bool (down)
1468+
down = ImGui.IsMouseDown(ImGuiMouseButton.Right)
1469+
1470+
-- ImGui.IsMouseClicked(...)
1471+
-- Parameters: ImGuiMouseButton (button), bool (repeat) [O]
1472+
-- Returns: bool (clicked)
1473+
-- Overloads
1474+
clicked = ImGui.IsMouseClicked(ImGuiMouseButton.Right)
1475+
clicked = ImGui.IsMouseClicked(ImGuiMouseButton.Right, false)
1476+
1477+
-- ImGui.IsMouseReleased(...)
1478+
-- Parameters: ImGuiMouseButton (button)
1479+
-- Returns: bool (released)
1480+
released = ImGui.IsMouseReleased(ImGuiMouseButton.Right)
1481+
1482+
-- ImGui.IsMouseDoubleClicked(...)
1483+
-- Parameters: ImGuiMouseButton (button)
1484+
-- Returns: bool (double_clicked)
1485+
double_clicked = ImGui.IsMouseDoubleClicked(ImGuiMouseButton.Right)
1486+
14291487
-- ImGui.IsMouseHoveringRect(...)
14301488
-- Parameters: float (min_x), float (min_y), float(max_x), float(max_y), bool (clip) [O]
14311489
-- Returns: bool (hovered)
14321490
hovered = ImGui.IsMouseHoveringRect(0, 0, 100, 100)
14331491
hovered = ImGui.IsMouseHoveringRect(0, 0, 100, 100, true)
14341492

1493+
-- ImGui.IsAnyMouseDown()
1494+
-- Returns: bool (any_mouse_down)
1495+
any_mouse_down = ImGui.IsAnyMouseDown()
1496+
14351497
-- ImGui.GetMousePos()
14361498
-- Returns: float (x), float (y)
14371499
x, y = ImGui.GetMousePos()
@@ -1460,6 +1522,20 @@ selected, activated = ImGui.MenuItem("Label", "ALT+F4", selected, true)
14601522
-- Overloads
14611523
ImGui.ResetMouseDragDelta()
14621524
ImGui.ResetMouseDragDelta(ImGuiMouseButton.Middle)
1525+
1526+
-- ImGui.GetMouseCursor()
1527+
-- Returns: ImGuiMouseCursor (cursor)
1528+
cursor = ImGui.GetMouseCursor()
1529+
1530+
-- ImGui.SetMouseCursor(...)
1531+
-- Parameters: ImGuiMouseCursor (cursor_type)
1532+
ImGui.SetMouseCursor(ImGuiMouseCursor.Hand)
1533+
1534+
-- ImGui.CaptureMouseFromApp()
1535+
-- Parameters: bool (want_capture_mouse_value) [O]
1536+
-- Overloads
1537+
ImGui.CaptureMouseFromApp()
1538+
ImGui.CaptureMouseFromApp(true)
14631539
```
14641540

14651541
## Clipboard Utilities

Diff for: src/sol_imgui/sol_imgui.h

+108
Original file line numberDiff line numberDiff line change
@@ -2600,7 +2600,63 @@ inline std::tuple<float, float, float> ColorConvertHSVtoRGB(float h, float s, fl
26002600
return std::make_tuple(r, g, b);
26012601
}
26022602

2603+
// Inputs Utilities: Keyboard
2604+
inline int GetKeyIndex(int imgui_key)
2605+
{
2606+
return ImGui::GetKeyIndex(static_cast<ImGuiKey>(imgui_key));
2607+
}
2608+
inline bool IsKeyDown(int user_key_index)
2609+
{
2610+
return ImGui::IsKeyDown(user_key_index);
2611+
}
2612+
inline bool IsKeyPressed(int user_key_index)
2613+
{
2614+
return ImGui::IsKeyPressed(user_key_index);
2615+
}
2616+
inline bool IsKeyPressed(int user_key_index, bool repeat)
2617+
{
2618+
return ImGui::IsKeyPressed(user_key_index, repeat);
2619+
}
2620+
inline bool IsKeyReleased(int user_key_index)
2621+
{
2622+
return ImGui::IsKeyReleased(user_key_index);
2623+
}
2624+
inline int GetKeyPressedAmount(int key_index, float repeat_delay, float rate)
2625+
{
2626+
return ImGui::GetKeyPressedAmount(key_index, repeat_delay, rate);
2627+
}
2628+
inline void CaptureKeyboardFromApp()
2629+
{
2630+
ImGui::CaptureKeyboardFromApp();
2631+
}
2632+
inline void CaptureKeyboardFromApp(bool want_capture_keyboard_value)
2633+
{
2634+
ImGui::CaptureKeyboardFromApp(want_capture_keyboard_value);
2635+
}
2636+
26032637
// Inputs Utilities: Mouse
2638+
2639+
inline bool IsMouseDown(int button)
2640+
{
2641+
return ImGui::IsMouseDown(static_cast<ImGuiMouseButton>(button));
2642+
}
2643+
inline bool IsMouseClicked(int button)
2644+
{
2645+
return ImGui::IsMouseClicked(static_cast<ImGuiMouseButton>(button));
2646+
}
2647+
inline bool IsMouseClicked(int button, bool repeat)
2648+
{
2649+
return ImGui::IsMouseClicked(static_cast<ImGuiMouseButton>(button), repeat);
2650+
}
2651+
inline bool IsMouseReleased(int button)
2652+
{
2653+
return ImGui::IsMouseReleased(static_cast<ImGuiMouseButton>(button));
2654+
}
2655+
inline bool IsMouseDoubleClicked(int button)
2656+
{
2657+
return ImGui::IsMouseDoubleClicked(static_cast<ImGuiMouseButton>(button));
2658+
}
2659+
26042660
inline bool IsMouseHoveringRect(float min_x, float min_y, float max_x, float max_y)
26052661
{
26062662
return ImGui::IsMouseHoveringRect({min_x, min_y}, {max_x, max_y});
@@ -2609,6 +2665,10 @@ inline bool IsMouseHoveringRect(float min_x, float min_y, float max_x, float max
26092665
{
26102666
return ImGui::IsMouseHoveringRect({min_x, min_y}, {max_x, max_y}, clip);
26112667
}
2668+
inline bool IsAnyMouseDown()
2669+
{
2670+
return ImGui::IsAnyMouseDown();
2671+
}
26122672
inline std::tuple<float, float> GetMousePos()
26132673
{
26142674
const auto vec2{ImGui::GetMousePos()};
@@ -2650,6 +2710,22 @@ inline void ResetMouseDragDelta(int button)
26502710
{
26512711
ImGui::ResetMouseDragDelta(static_cast<ImGuiMouseButton>(button));
26522712
}
2713+
inline int GetMouseCursor()
2714+
{
2715+
return ImGui::GetMouseCursor();
2716+
}
2717+
inline void SetMouseCursor(int cursor_type)
2718+
{
2719+
ImGui::SetMouseCursor(static_cast<ImGuiMouseCursor>(cursor_type));
2720+
}
2721+
inline void CaptureMouseFromApp()
2722+
{
2723+
ImGui::CaptureMouseFromApp();
2724+
}
2725+
inline void CaptureMouseFromApp(bool want_capture_mouse_value)
2726+
{
2727+
ImGui::CaptureMouseFromApp(want_capture_mouse_value);
2728+
}
26532729

26542730
// Clipboard Utilities
26552731
inline std::string GetClipboardText()
@@ -3048,6 +3124,22 @@ inline void InitEnums(sol::table luaGlobals)
30483124
luaGlobals.new_enum("ImGuiMouseButton", "Left", ImGuiMouseButton_Left, "Right", ImGuiMouseButton_Right, "Middle", ImGuiMouseButton_Middle, "COUNT", ImGuiMouseButton_COUNT);
30493125
#pragma endregion MouseButton
30503126

3127+
#pragma region Key
3128+
luaGlobals.new_enum(
3129+
"ImGuiKey", "Tab", ImGuiKey_Tab, "LeftArrow", ImGuiKey_LeftArrow, "RightArrow", ImGuiKey_RightArrow, "UpArrow", ImGuiKey_UpArrow, "DownArrow", ImGuiKey_DownArrow, "PageUp",
3130+
ImGuiKey_PageUp, "PageDown", ImGuiKey_PageDown, "Home", ImGuiKey_Home, "End", ImGuiKey_End, "Insert", ImGuiKey_Insert, "Delete", ImGuiKey_Delete, "Backspace",
3131+
ImGuiKey_Backspace, "Space", ImGuiKey_Space, "Enter", ImGuiKey_Enter, "Escape", ImGuiKey_Escape, "KeyPadEnter", ImGuiKey_KeyPadEnter, "A", ImGuiKey_A, "C", ImGuiKey_C, "V",
3132+
ImGuiKey_V, "X", ImGuiKey_X, "Y", ImGuiKey_Y, "Z", ImGuiKey_Z, "COUNT", ImGuiKey_COUNT, "LeftCtrl", ImGuiKey_LeftCtrl, "LeftShift", ImGuiKey_LeftShift, "G", ImGuiKey_G,
3133+
"S", ImGuiKey_S, "D", ImGuiKey_D, "R", ImGuiKey_R, "H", ImGuiKey_H);
3134+
#pragma endregion Key
3135+
3136+
#pragma region MouseCursor
3137+
luaGlobals.new_enum(
3138+
"ImGuiMouseCursor", "None", ImGuiMouseCursor_None, "Arrow", ImGuiMouseCursor_Arrow, "TextInput", ImGuiMouseCursor_TextInput, "ResizeAll", ImGuiMouseCursor_ResizeAll,
3139+
"ResizeNS", ImGuiMouseCursor_ResizeNS, "ResizeEW", ImGuiMouseCursor_ResizeEW, "ResizeNESW", ImGuiMouseCursor_ResizeNESW, "ResizeNWSE", ImGuiMouseCursor_ResizeNWSE, "Hand",
3140+
ImGuiMouseCursor_Hand, "NotAllowed", ImGuiMouseCursor_NotAllowed, "COUNT", ImGuiMouseCursor_COUNT);
3141+
#pragma endregion MouseCursor
3142+
30513143
#pragma region ImDrawCorner Flags
30523144
luaGlobals.new_enum(
30533145
"ImDrawCornerFlags", "None", ImDrawCornerFlags_None, "TopLeft", ImDrawCornerFlags_TopLeft, "TopRight", ImDrawCornerFlags_TopRight, "BotLeft", ImDrawCornerFlags_BotLeft,
@@ -3684,10 +3776,23 @@ inline void InitBindings(sol::state& lua, sol::table luaGlobals)
36843776
ImGui.set_function("ColorConvertHSVtoRGB", ColorConvertHSVtoRGB);
36853777
#pragma endregion Color Utilities
36863778

3779+
#pragma region Inputs Utilities: Keyboard
3780+
ImGui.set_function("GetKeyIndex", GetKeyIndex);
3781+
ImGui.set_function("IsKeyDown", IsKeyDown);
3782+
ImGui.set_function("IsKeyPressed", sol::overload(sol::resolve<bool(int)>(IsKeyPressed), sol::resolve<bool(int, bool)>(IsKeyPressed)));
3783+
ImGui.set_function("IsKeyReleased", IsKeyReleased);
3784+
ImGui.set_function("CaptureKeyboardFromApp", sol::overload(sol::resolve<void()>(CaptureKeyboardFromApp), sol::resolve<void(bool)>(CaptureKeyboardFromApp)));
3785+
#pragma endregion Inputs Utilities : Keyboard
3786+
36873787
#pragma region Inputs Utilities : Mouse
3788+
ImGui.set_function("IsMouseDown", IsMouseDown);
3789+
ImGui.set_function("IsMouseClicked", sol::overload(sol::resolve<bool(int)>(IsMouseClicked), sol::resolve<bool(int, bool)>(IsMouseClicked)));
3790+
ImGui.set_function("IsMouseReleased", IsMouseReleased);
3791+
ImGui.set_function("IsMouseDoubleClicked", IsMouseDoubleClicked);
36883792
ImGui.set_function(
36893793
"IsMouseHoveringRect",
36903794
sol::overload(sol::resolve<bool(float, float, float, float)>(IsMouseHoveringRect), sol::resolve<bool(float, float, float, float, bool)>(IsMouseHoveringRect)));
3795+
ImGui.set_function("IsAnyMouseDown", IsAnyMouseDown);
36913796
ImGui.set_function("GetMousePos", GetMousePos);
36923797
ImGui.set_function("GetMousePosOnOpeningCurrentPopup", GetMousePosOnOpeningCurrentPopup);
36933798
ImGui.set_function("IsMouseDragging", sol::overload(sol::resolve<bool(int)>(IsMouseDragging), sol::resolve<bool(int, float)>(IsMouseDragging)));
@@ -3696,6 +3801,9 @@ inline void InitBindings(sol::state& lua, sol::table luaGlobals)
36963801
sol::resolve<std::tuple<float, float>()>(GetMouseDragDelta), sol::resolve<std::tuple<float, float>(int)>(GetMouseDragDelta),
36973802
sol::resolve<std::tuple<float, float>(int, float)>(GetMouseDragDelta)));
36983803
ImGui.set_function("ResetMouseDragDelta", sol::overload(sol::resolve<void()>(ResetMouseDragDelta), sol::resolve<void(int)>(ResetMouseDragDelta)));
3804+
ImGui.set_function("GetMouseCursor", GetMouseCursor);
3805+
ImGui.set_function("SetMouseCursor", SetMouseCursor);
3806+
ImGui.set_function("CaptureMouseFromApp", sol::overload(sol::resolve<void()>(CaptureMouseFromApp), sol::resolve<void(bool)>(CaptureMouseFromApp)));
36993807
#pragma endregion Inputs Utilities : Mouse
37003808

37013809
#pragma region Clipboard Utilities

0 commit comments

Comments
 (0)