Windows Event Handler - this is statically connected to the windows event system
| 6913 | |
| 6914 | // Windows Event Handler - this is statically connected to the windows event system |
| 6915 | static LRESULT CALLBACK olc_WindowEvent(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) |
| 6916 | { |
| 6917 | switch (uMsg) |
| 6918 | { |
| 6919 | case WM_MOUSEMOVE: |
| 6920 | { |
| 6921 | // Thanks @ForAbby (Discord) |
| 6922 | uint16_t x = lParam & 0xFFFF; uint16_t y = (lParam >> 16) & 0xFFFF; |
| 6923 | int16_t ix = *(int16_t*)&x; int16_t iy = *(int16_t*)&y; |
| 6924 | ptrPGE->olc_UpdateMouse(ix, iy); |
| 6925 | return 0; |
| 6926 | } |
| 6927 | case WM_MOVE: vWinPos = olc::vi2d(lParam & 0xFFFF, (lParam >> 16) & 0xFFFF); ptrPGE->olc_UpdateWindowPos(lParam & 0xFFFF, (lParam >> 16) & 0xFFFF); return 0; |
| 6928 | case WM_SIZE: vWinSize = olc::vi2d(lParam & 0xFFFF, (lParam >> 16) & 0xFFFF); ptrPGE->olc_UpdateWindowSize(lParam & 0xFFFF, (lParam >> 16) & 0xFFFF); return 0; |
| 6929 | case WM_MOUSEWHEEL: ptrPGE->olc_UpdateMouseWheel(GET_WHEEL_DELTA_WPARAM(wParam)); return 0; |
| 6930 | case WM_MOUSELEAVE: ptrPGE->olc_UpdateMouseFocus(false); return 0; |
| 6931 | case WM_SETFOCUS: ptrPGE->olc_UpdateKeyFocus(true); return 0; |
| 6932 | case WM_KILLFOCUS: ptrPGE->olc_UpdateKeyFocus(false); return 0; |
| 6933 | case WM_KEYDOWN: ptrPGE->olc_UpdateKeyState(int32_t(wParam), true); return 0; |
| 6934 | case WM_KEYUP: ptrPGE->olc_UpdateKeyState(int32_t(wParam), false); return 0; |
| 6935 | case WM_SYSKEYDOWN: ptrPGE->olc_UpdateKeyState(int32_t(wParam), true); return 0; |
| 6936 | case WM_SYSKEYUP: ptrPGE->olc_UpdateKeyState(int32_t(wParam), false); return 0; |
| 6937 | case WM_LBUTTONDOWN:ptrPGE->olc_UpdateMouseState(0, true); return 0; |
| 6938 | case WM_LBUTTONUP: ptrPGE->olc_UpdateMouseState(0, false); return 0; |
| 6939 | case WM_RBUTTONDOWN:ptrPGE->olc_UpdateMouseState(1, true); return 0; |
| 6940 | case WM_RBUTTONUP: ptrPGE->olc_UpdateMouseState(1, false); return 0; |
| 6941 | case WM_MBUTTONDOWN:ptrPGE->olc_UpdateMouseState(2, true); return 0; |
| 6942 | case WM_MBUTTONUP: ptrPGE->olc_UpdateMouseState(2, false); return 0; |
| 6943 | case WM_DROPFILES: |
| 6944 | { |
| 6945 | // This is all eww... |
| 6946 | HDROP drop = (HDROP)wParam; |
| 6947 | |
| 6948 | uint32_t nFiles = DragQueryFile(drop, 0xFFFFFFFF, nullptr, 0); |
| 6949 | std::vector<std::string> vFiles; |
| 6950 | for (uint32_t i = 0; i < nFiles; i++) |
| 6951 | { |
| 6952 | TCHAR dfbuffer[256]{}; |
| 6953 | uint32_t len = DragQueryFile(drop, i, nullptr, 0); |
| 6954 | DragQueryFile(drop, i, dfbuffer, 256); |
| 6955 | #ifdef UNICODE |
| 6956 | #ifdef __MINGW32__ |
| 6957 | char* buffer = new char[len + 1]; |
| 6958 | wcstombs(buffer, dfbuffer, len); |
| 6959 | buffer[len] = '\0'; |
| 6960 | #else |
| 6961 | int count = WideCharToMultiByte(CP_UTF8, 0, dfbuffer, -1, NULL, 0, NULL, NULL); |
| 6962 | char* buffer = new char[count]; |
| 6963 | WideCharToMultiByte(CP_UTF8, 0, dfbuffer, -1, buffer, count, NULL, NULL); |
| 6964 | #endif |
| 6965 | vFiles.push_back(std::string(buffer)); |
| 6966 | delete[] buffer; |
| 6967 | #else |
| 6968 | vFiles.push_back(std::string(dfbuffer)); |
| 6969 | #endif |
| 6970 | } |
| 6971 | |
| 6972 | // Even more eww... |
nothing calls this directly
no test coverage detected