From 0ceef907c0cc4bdc48695fb7e10f0955aa540f71 Mon Sep 17 00:00:00 2001 From: iProgramInCpp Date: Sat, 5 Aug 2023 16:13:11 +0300 Subject: [PATCH] * Allow handling of WM_CHAR in the case of Windows. --- platforms/windows/main.cpp | 11 +++++++++++ source/Minecraft.cpp | 8 ++++++-- source/Minecraft.hpp | 4 +--- source/client/gui/Screen.cpp | 8 ++++++-- source/client/gui/Screen.hpp | 1 + source/client/gui/components/TextInputBox.cpp | 16 ++++++++++++++++ windows_vs/minecraftcpp.vcxproj | 12 ++++++------ 7 files changed, 47 insertions(+), 13 deletions(-) diff --git a/platforms/windows/main.cpp b/platforms/windows/main.cpp index ff4a6da..f9d8b48 100644 --- a/platforms/windows/main.cpp +++ b/platforms/windows/main.cpp @@ -178,6 +178,17 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam) break; } + case WM_CHAR: + { + if (lParam & (1 << 31)) + break; + + if (wParam >= '~' && wParam < ' ') + break; + + g_pApp->handleCharInput(char(wParam)); + break; + } case WM_DESTROY: PostQuitMessage(0); return 0; diff --git a/source/Minecraft.cpp b/source/Minecraft.cpp index 065128e..a250d5b 100644 --- a/source/Minecraft.cpp +++ b/source/Minecraft.cpp @@ -478,7 +478,6 @@ void Minecraft::tickInput() Mouse::_index = -1; } -#ifndef ORIGINAL_CODE void Minecraft::tickMouse() { if (!m_bGrabbedMouse) @@ -486,7 +485,12 @@ void Minecraft::tickMouse() platform()->recenterMouse(); } -#endif + +void Minecraft::handleCharInput(char chr) +{ + if (field_D14) + field_D14->charInput(chr); +} void Minecraft::_levelGenerated() { diff --git a/source/Minecraft.hpp b/source/Minecraft.hpp index b6d3d3d..9d1212c 100644 --- a/source/Minecraft.hpp +++ b/source/Minecraft.hpp @@ -52,10 +52,8 @@ public: void joinMultiplayer(const PingedCompatibleServer& serverInfo); void cancelLocateMultiplayer(); void locateMultiplayer(); - -#ifndef ORIGINAL_CODE void tickMouse(); -#endif + void handleCharInput(char chr); virtual void onGraphicsReset(); virtual void update() override; diff --git a/source/client/gui/Screen.cpp b/source/client/gui/Screen.cpp index 89f2b59..3c893e9 100644 --- a/source/client/gui/Screen.cpp +++ b/source/client/gui/Screen.cpp @@ -98,12 +98,16 @@ void Screen::keyPressed(int key) #endif } -#ifndef ORIGINAL_CODE for (auto textInput : m_textInputs) { textInput->keyPressed(m_pMinecraft, key); } -#endif +} + +void Screen::charInput(char chr) +{ + for (auto textInput : m_textInputs) + textInput->charPressed(chr); } void Screen::mouseClicked(int xPos, int yPos, int d) // d = clicked? diff --git a/source/client/gui/Screen.hpp b/source/client/gui/Screen.hpp index 0b802e1..6ca9c44 100644 --- a/source/client/gui/Screen.hpp +++ b/source/client/gui/Screen.hpp @@ -44,6 +44,7 @@ public: virtual void mouseClicked(int, int, int); virtual void mouseReleased(int, int, int); virtual void keyPressed(int); + virtual void charInput(char); public: int m_width = 1; diff --git a/source/client/gui/components/TextInputBox.cpp b/source/client/gui/components/TextInputBox.cpp index 7523dbc..6fc77f7 100644 --- a/source/client/gui/components/TextInputBox.cpp +++ b/source/client/gui/components/TextInputBox.cpp @@ -53,6 +53,7 @@ void TextInputBox::keyPressed(Minecraft* minecraft, int key) bool bShiftPressed = minecraft->platform()->shiftPressed(); +#ifndef HANDLE_CHARS_SEPARATELY char chr = '\0'; if (key >= AKEYCODE_A && key <= AKEYCODE_Z) { @@ -114,6 +115,21 @@ void TextInputBox::keyPressed(Minecraft* minecraft, int key) chr = bShiftPressed ? '}' : ']'; break; } +#else + char chr = '\0'; + switch (key) + { + case AKEYCODE_FORWARD_DEL: + chr = '\001'; + break; + case AKEYCODE_ARROW_LEFT: + chr = '\002'; + break; + case AKEYCODE_ARROW_RIGHT: + chr = '\003'; + break; + } +#endif if (chr) charPressed(chr); diff --git a/windows_vs/minecraftcpp.vcxproj b/windows_vs/minecraftcpp.vcxproj index 0128664..d48dbcd 100644 --- a/windows_vs/minecraftcpp.vcxproj +++ b/windows_vs/minecraftcpp.vcxproj @@ -761,7 +761,7 @@ Level3 true - _USE_MATH_DEFINES;_WINSOCK_DEPRECATED_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + HANDLE_CHARS_SEPARATELY;_USE_MATH_DEFINES;_WINSOCK_DEPRECATED_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true true Precise @@ -777,7 +777,7 @@ Level3 true - _USE_MATH_DEFINES;_WINSOCK_DEPRECATED_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + HANDLE_CHARS_SEPARATELY;_USE_MATH_DEFINES;_WINSOCK_DEPRECATED_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true true Precise @@ -795,7 +795,7 @@ true true true - _USE_MATH_DEFINES;_WINSOCK_DEPRECATED_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + HANDLE_CHARS_SEPARATELY;_USE_MATH_DEFINES;_WINSOCK_DEPRECATED_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true true Precise @@ -813,7 +813,7 @@ Level3 true - _USE_MATH_DEFINES;_WINSOCK_DEPRECATED_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + HANDLE_CHARS_SEPARATELY;_USE_MATH_DEFINES;_WINSOCK_DEPRECATED_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true true Precise @@ -829,7 +829,7 @@ Level3 true - _USE_MATH_DEFINES;_WINSOCK_DEPRECATED_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + HANDLE_CHARS_SEPARATELY;_USE_MATH_DEFINES;_WINSOCK_DEPRECATED_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true true Precise @@ -847,7 +847,7 @@ true true true - _USE_MATH_DEFINES;_WINSOCK_DEPRECATED_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + HANDLE_CHARS_SEPARATELY;_USE_MATH_DEFINES;_WINSOCK_DEPRECATED_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true true Precise