feat(console): hardware detection et cetera

This commit is contained in:
phaneron 2025-04-12 04:35:49 -04:00
parent 97bbe2ea66
commit 31f215ea14
118 changed files with 4059 additions and 1931 deletions

View file

@ -1,32 +1,11 @@
file(GLOB PRIVATE_SOURCES "*.cpp")
if (WHOA_SYSTEM_WIN)
file(GLOB WIN_SOURCES
"win/*.cpp"
)
list(APPEND PRIVATE_SOURCES ${WIN_SOURCES})
endif ()
if (WHOA_SYSTEM_MAC)
if(WHOA_SYSTEM_MAC)
file(GLOB MAC_SOURCES
"mac/*.cpp"
"mac/*.mm"
)
list(APPEND PRIVATE_SOURCES ${MAC_SOURCES})
endif ()
if (WHOA_SYSTEM_LINUX)
file(GLOB LINUX_SOURCES
"linux/*.cpp"
)
list(APPEND PRIVATE_SOURCES ${LINUX_SOURCES})
endif ()
# SDL has its own input event processing
if (WHOA_BUILD_GLSDL)
file(GLOB SDL_SOURCES "sdl/*.cpp")
list(APPEND PRIVATE_SOURCES ${SDL_SOURCES})
endif ()
endif()
add_library(event STATIC
${PRIVATE_SOURCES}
@ -41,15 +20,10 @@ target_link_libraries(event
PRIVATE
client
gx
os
PUBLIC
bc
common
storm
tempest
)
if (WHOA_BUILD_GLSDL)
target_link_libraries(event
PRIVATE
SDL2::SDL2-static)
endif ()

View file

@ -3,6 +3,7 @@
#include "event/EvtContext.hpp"
#include "event/Queue.hpp"
#include "gx/Window.hpp"
#include "os/Input.hpp"
#include <common/Time.hpp>
#include <storm/String.hpp>
#include <storm/Unicode.hpp>
@ -19,7 +20,6 @@
namespace Input {
CRect s_boundingRect;
OSEVENT s_queue[32];
MOUSEBUTTON s_buttonConversion[16] = {
MOUSE_BUTTON_NONE,
@ -46,22 +46,8 @@ uint32_t Input::s_buttonState;
C2iVector Input::s_currentMouse;
uint32_t Input::s_mouseHoldButton;
MOUSEMODE Input::s_mouseMode;
int32_t Input::s_numlockState;
uint32_t Input::s_osButtonState;
OS_MOUSE_MODE Input::s_osMouseMode;
int32_t Input::s_simulatedRightButtonClick;
uint32_t Input::s_metaKeyState;
int32_t Input::s_queueHead;
int32_t Input::s_queueTail;
int32_t Input::s_windowFocused;
#if defined(WHOA_SYSTEM_WIN)
int32_t Input::s_savedMouseSpeed;
#endif
#if defined(WHOA_SYSTEM_MAC)
double Input::s_savedMouseSpeed;
#endif
void PostChar(EvtContext* context, int32_t ch, int32_t repeat) {
EVENT_DATA_CHAR data;
@ -632,95 +618,3 @@ const char* KeyCodeToString(KEY key) {
return "UNKNOWN";
}
void OsInputInitialize() {
#if defined(WHOA_SYSTEM_WIN)
Input::s_numlockState = GetAsyncKeyState(144);
int32_t mouseSpeed = 10;
SystemParametersInfoA(SPI_GETMOUSESPEED, 0, &mouseSpeed, 0);
Input::s_savedMouseSpeed = mouseSpeed;
#endif
#if defined(WHOA_SYSTEM_MAC)
// Legacy Carbon input handling
// if (!byte_143EFE0) {
// Carbon_OsInputRegisterHICommandHandler(0x71756974, sub_A4F230);
// }
MacClient::SetMouseCoalescingEnabled(true);
Input::s_savedMouseSpeed = MacClient::GetMouseSpeed();
#endif
}
bool OsInputIsUsingCocoaEventLoop() {
// TODO
return true;
}
void OsInputPostEvent(OSINPUT id, int32_t param0, int32_t param1, int32_t param2, int32_t param3) {
// TODO
}
int32_t OsQueueGet(OSINPUT* id, int32_t* param0, int32_t* param1, int32_t* param2, int32_t* param3) {
if (Input::s_queueTail == Input::s_queueHead) {
return 0;
}
OSEVENT event = Input::s_queue[Input::s_queueTail];
*id = event.id;
*param0 = event.param[0];
*param1 = event.param[1];
*param2 = event.param[2];
*param3 = event.param[3];
if (Input::s_queueTail == OS_QUEUE_SIZE - 1) {
Input:: s_queueTail = 0;
} else {
++Input::s_queueTail;
}
return 1;
}
void OsQueuePut(OSINPUT id, int32_t param0, int32_t param1, int32_t param2, int32_t param3) {
int32_t nextTail = 0;
int32_t nextHead = 0;
if (Input::s_queueHead != OS_QUEUE_SIZE - 1) {
nextHead = Input::s_queueHead + 1;
}
if (nextHead == Input::s_queueTail) {
if (nextHead != OS_QUEUE_SIZE - 1) {
nextTail = nextHead + 1;
}
Input::s_queueTail = nextTail;
}
OSEVENT* event = &Input::s_queue[Input::s_queueHead];
event->id = id;
event->param[0] = param0;
event->param[1] = param1;
event->param[2] = param2;
event->param[3] = param3;
Input::s_queueHead = nextHead;
}
void OsQueueSetParam(int32_t index, int32_t param) {
int32_t pos = Input::s_queueTail;
while (pos != Input::s_queueHead) {
OSEVENT* event = &Input::s_queue[pos];
event->param[index] = param;
if (pos == OS_QUEUE_SIZE - 1) {
pos = 0;
} else {
++pos;
}
}
}

View file

@ -4,8 +4,6 @@
#include "event/Types.hpp"
#include <cstdint>
#define OS_QUEUE_SIZE 32
class C2iVector;
class CRect;
class EvtContext;
@ -16,22 +14,8 @@ namespace Input {
extern C2iVector s_currentMouse;
extern uint32_t s_mouseHoldButton;
extern MOUSEMODE s_mouseMode;
extern uint32_t s_osButtonState;
extern OS_MOUSE_MODE s_osMouseMode;
extern int32_t s_numlockState;
extern int32_t s_simulatedRightButtonClick;
extern uint32_t s_metaKeyState;
extern int32_t s_queueHead;
extern int32_t s_queueTail;
extern int32_t s_windowFocused;
#if defined(WHOA_SYSTEM_WIN)
extern int32_t s_savedMouseSpeed;
#endif
#if defined(WHOA_SYSTEM_MAC)
extern double s_savedMouseSpeed;
#endif
}
void CheckMouseModeState();
@ -54,24 +38,4 @@ void IEvtInputSetMouseMode(EvtContext* context, MOUSEMODE mode, uint32_t holdBut
const char* KeyCodeToString(KEY key);
int32_t OsInputGet(OSINPUT* id, int32_t* param0, int32_t* param1, int32_t* param2, int32_t* param3);
void OsInputInitialize();
bool OsInputIsUsingCocoaEventLoop();
void OsInputPostEvent(OSINPUT id, int32_t param0, int32_t param1, int32_t param2, int32_t param3);
void OsInputSetMouseMode(OS_MOUSE_MODE mode);
void OsInputGetMousePosition(int32_t* x, int32_t* y);
int32_t OsQueueGet(OSINPUT* id, int32_t* param0, int32_t* param1, int32_t* param2, int32_t* param3);
void OsQueuePut(OSINPUT id, int32_t param0, int32_t param1, int32_t param2, int32_t param3);
void OsQueueSetParam(int32_t index, int32_t param);
int32_t OsWindowProc(void* window, uint32_t message, uintptr_t wparam, intptr_t lparam);
#endif

View file

@ -186,40 +186,6 @@ enum MOUSEMODE {
MOUSE_MODES = 0x2
};
enum OSINPUT {
OS_INPUT_CAPTURE_CHANGED = 0,
OS_INPUT_CHAR = 1,
OS_INPUT_STRING = 2,
OS_INPUT_IME = 3,
OS_INPUT_SIZE = 4,
OS_INPUT_CLOSE = 5,
OS_INPUT_FOCUS = 6,
OS_INPUT_KEY_DOWN = 7,
OS_INPUT_KEY_UP = 8,
OS_INPUT_MOUSE_DOWN = 9,
OS_INPUT_MOUSE_MOVE = 10,
OS_INPUT_MOUSE_WHEEL = 11,
OS_INPUT_MOUSE_MOVE_RELATIVE = 12,
OS_INPUT_MOUSE_UP = 13,
OS_INPUT_14 = 14,
OS_INPUT_15 = 15,
OS_INPUT_16 = 16,
OS_INPUT_17 = 17,
OS_INPUT_18 = 18,
OS_INPUT_SHUTDOWN = 19
};
enum OS_MOUSE_MODE {
OS_MOUSE_MODE_NORMAL = 0,
OS_MOUSE_MODE_RELATIVE = 1,
OS_MOUSE_MODES = 2,
};
struct OSEVENT {
OSINPUT id;
int32_t param[4];
};
struct EVENT_DATA_CHAR {
int32_t ch;
uint32_t metaKeyState;

View file

@ -1,46 +0,0 @@
#include <common/Time.hpp>
#include "event/Input.hpp"
#if defined(WHOA_BUILD_GLSDL)
#include "event/sdl/Input.hpp"
#endif
int32_t OsInputGet(OSINPUT* id, int32_t* param0, int32_t* param1, int32_t* param2, int32_t* param3) {
#if defined(WHOA_BUILD_GLSDL)
if (SDLInputActive()) {
return SDLInputGet(id, param0, param1, param2, param3);
}
#endif
if (Input::s_queueTail == Input::s_queueHead) {
return 0;
}
OsQueueSetParam(3, OsGetAsyncTimeMs());
return OsQueueGet(id, param0, param1, param2, param3);
}
void OsInputSetMouseMode(OS_MOUSE_MODE mode) {
// TODO
}
int32_t OsWindowProc(void* window, uint32_t message, uintptr_t wparam, intptr_t lparam) {
return 0;
}
void OsInputGetMousePosition(int32_t* x, int32_t* y) {
#if defined(WHOA_BUILD_GLSDL)
if (SDLInputActive()) {
SDLInputGetMousePosition(x, y);
return;
}
#endif
if (x) {
*x = 0;
}
if (y) {
*y = 0;
}
}

View file

@ -1,6 +0,0 @@
#ifndef EVENT_MAC_EVENT_H
#define EVENT_MAC_EVENT_H
void RunCocoaEventLoop();
#endif

6
src/event/mac/Event.hpp Normal file
View file

@ -0,0 +1,6 @@
#ifndef EVENT_MAC_EVENT_HPP
#define EVENT_MAC_EVENT_HPP
void RunCocoaEventLoop();
#endif

View file

@ -1,4 +1,4 @@
#include "event/mac/Event.h"
#include "event/mac/Event.hpp"
#include "event/Event.hpp"
#include <AppKit/AppKit.h>

View file

@ -1,52 +0,0 @@
#include "event/Input.hpp"
#include <common/Time.hpp>
#include <tempest/Vector.hpp>
static C2iVector s_mousePos;
int32_t OsInputGet(OSINPUT* id, int32_t* param0, int32_t* param1, int32_t* param2, int32_t* param3) {
// TODO
// Unknown logic
if (!OsInputIsUsingCocoaEventLoop()) {
// Legacy Carbon input handling
return 0;
}
// TODO
// Steelseries WoW Mouse logic
if (Input::s_queueTail == Input::s_queueHead) {
return 0;
}
OsQueueSetParam(3, OsGetAsyncTimeMs());
auto queue_result = OsQueueGet(id, param0, param1, param2, param3);
if (queue_result) {
if (*id == OS_INPUT_MOUSE_MOVE) {
s_mousePos.x = *param1;
s_mousePos.y = *param2;
}
}
return queue_result;
}
void OsInputSetMouseMode(OS_MOUSE_MODE mode) {
// TODO
}
void OsInputGetMousePosition(int32_t* x, int32_t* y) {
if (x) {
*x = s_mousePos.x;
}
if (y) {
*y = s_mousePos.y;
}
}
int32_t OsWindowProc(void* window, uint32_t message, uintptr_t wparam, intptr_t lparam) {
return 0;
}

View file

@ -1,304 +0,0 @@
#include <unordered_map>
#include "event/sdl/Input.hpp"
#include "client/Gui.hpp"
#include "gx/Device.hpp"
#include "gx/Window.hpp"
#include <storm/Unicode.hpp>
#include <SDL2/SDL.h>
static const std::unordered_map<SDL_Scancode, KEY> s_keyConversion = {
{ SDL_SCANCODE_LSHIFT, KEY_LSHIFT },
{ SDL_SCANCODE_RSHIFT, KEY_RSHIFT },
{ SDL_SCANCODE_LCTRL, KEY_LCONTROL },
{ SDL_SCANCODE_RCTRL, KEY_RCONTROL },
{ SDL_SCANCODE_LALT, KEY_LALT },
{ SDL_SCANCODE_RALT, KEY_RALT },
{ SDL_SCANCODE_SPACE, KEY_SPACE },
{ SDL_SCANCODE_0, KEY_0 },
{ SDL_SCANCODE_1, KEY_1 },
{ SDL_SCANCODE_2, KEY_2 },
{ SDL_SCANCODE_3, KEY_3 },
{ SDL_SCANCODE_4, KEY_4 },
{ SDL_SCANCODE_5, KEY_5 },
{ SDL_SCANCODE_6, KEY_6 },
{ SDL_SCANCODE_7, KEY_7 },
{ SDL_SCANCODE_8, KEY_8 },
{ SDL_SCANCODE_9, KEY_9 },
{ SDL_SCANCODE_A, KEY_A },
{ SDL_SCANCODE_B, KEY_B },
{ SDL_SCANCODE_C, KEY_C },
{ SDL_SCANCODE_D, KEY_D },
{ SDL_SCANCODE_E, KEY_E },
{ SDL_SCANCODE_F, KEY_F },
{ SDL_SCANCODE_G, KEY_G },
{ SDL_SCANCODE_H, KEY_H },
{ SDL_SCANCODE_I, KEY_I },
{ SDL_SCANCODE_J, KEY_J },
{ SDL_SCANCODE_K, KEY_K },
{ SDL_SCANCODE_L, KEY_L },
{ SDL_SCANCODE_M, KEY_M },
{ SDL_SCANCODE_N, KEY_N },
{ SDL_SCANCODE_O, KEY_O },
{ SDL_SCANCODE_P, KEY_P },
{ SDL_SCANCODE_Q, KEY_Q },
{ SDL_SCANCODE_R, KEY_R },
{ SDL_SCANCODE_S, KEY_S },
{ SDL_SCANCODE_T, KEY_T },
{ SDL_SCANCODE_U, KEY_U },
{ SDL_SCANCODE_V, KEY_V },
{ SDL_SCANCODE_W, KEY_W },
{ SDL_SCANCODE_X, KEY_X },
{ SDL_SCANCODE_Y, KEY_Y },
{ SDL_SCANCODE_Z, KEY_Z },
{ SDL_SCANCODE_GRAVE, KEY_TILDE },
{ SDL_SCANCODE_KP_0, KEY_NUMPAD0 },
{ SDL_SCANCODE_KP_1, KEY_NUMPAD1 },
{ SDL_SCANCODE_KP_2, KEY_NUMPAD2 },
{ SDL_SCANCODE_KP_3, KEY_NUMPAD3 },
{ SDL_SCANCODE_KP_4, KEY_NUMPAD4 },
{ SDL_SCANCODE_KP_5, KEY_NUMPAD5 },
{ SDL_SCANCODE_KP_6, KEY_NUMPAD6 },
{ SDL_SCANCODE_KP_7, KEY_NUMPAD7 },
{ SDL_SCANCODE_KP_8, KEY_NUMPAD8 },
{ SDL_SCANCODE_KP_9, KEY_NUMPAD9 },
{ SDL_SCANCODE_KP_PLUS, KEY_NUMPAD_PLUS },
{ SDL_SCANCODE_KP_MINUS, KEY_NUMPAD_MINUS },
{ SDL_SCANCODE_KP_MULTIPLY, KEY_NUMPAD_MULTIPLY },
{ SDL_SCANCODE_KP_DIVIDE, KEY_NUMPAD_DIVIDE },
{ SDL_SCANCODE_KP_DECIMAL, KEY_NUMPAD_DECIMAL },
{ SDL_SCANCODE_KP_EQUALS, KEY_NUMPAD_EQUALS },
{ SDL_SCANCODE_EQUALS, KEY_PLUS },
{ SDL_SCANCODE_MINUS, KEY_MINUS },
{ SDL_SCANCODE_LEFTBRACKET, KEY_BRACKET_OPEN },
{ SDL_SCANCODE_RIGHTBRACKET, KEY_BRACKET_CLOSE },
{ SDL_SCANCODE_SLASH, KEY_SLASH },
{ SDL_SCANCODE_BACKSLASH, KEY_BACKSLASH },
{ SDL_SCANCODE_SEMICOLON, KEY_SEMICOLON },
{ SDL_SCANCODE_APOSTROPHE, KEY_APOSTROPHE },
{ SDL_SCANCODE_COMMA, KEY_COMMA },
{ SDL_SCANCODE_PERIOD, KEY_PERIOD },
{ SDL_SCANCODE_ESCAPE, KEY_ESCAPE },
{ SDL_SCANCODE_RETURN, KEY_ENTER },
{ SDL_SCANCODE_BACKSPACE, KEY_BACKSPACE },
{ SDL_SCANCODE_TAB, KEY_TAB },
{ SDL_SCANCODE_LEFT, KEY_LEFT },
{ SDL_SCANCODE_UP, KEY_UP },
{ SDL_SCANCODE_RIGHT, KEY_RIGHT },
{ SDL_SCANCODE_DOWN, KEY_DOWN },
{ SDL_SCANCODE_INSERT, KEY_INSERT },
{ SDL_SCANCODE_DELETE, KEY_DELETE },
{ SDL_SCANCODE_HOME, KEY_HOME },
{ SDL_SCANCODE_END, KEY_END },
{ SDL_SCANCODE_PAGEUP, KEY_PAGEUP },
{ SDL_SCANCODE_PAGEDOWN, KEY_PAGEDOWN },
{ SDL_SCANCODE_CAPSLOCK, KEY_CAPSLOCK },
{ SDL_SCANCODE_NUMLOCKCLEAR, KEY_NUMLOCK },
{ SDL_SCANCODE_SCROLLLOCK, KEY_SCROLLLOCK },
{ SDL_SCANCODE_PAUSE, KEY_PAUSE },
{ SDL_SCANCODE_PRINTSCREEN, KEY_PRINTSCREEN },
{ SDL_SCANCODE_F1, KEY_F1 },
{ SDL_SCANCODE_F2, KEY_F2 },
{ SDL_SCANCODE_F3, KEY_F3 },
{ SDL_SCANCODE_F4, KEY_F4 },
{ SDL_SCANCODE_F5, KEY_F5 },
{ SDL_SCANCODE_F6, KEY_F6 },
{ SDL_SCANCODE_F7, KEY_F7 },
{ SDL_SCANCODE_F8, KEY_F8 },
{ SDL_SCANCODE_F9, KEY_F9 },
{ SDL_SCANCODE_F10, KEY_F10 },
{ SDL_SCANCODE_F11, KEY_F11 },
{ SDL_SCANCODE_F12, KEY_F12 },
{ SDL_SCANCODE_F13, KEY_F13 },
{ SDL_SCANCODE_F14, KEY_F14 },
{ SDL_SCANCODE_F15, KEY_F15 },
{ SDL_SCANCODE_F16, KEY_F16 },
{ SDL_SCANCODE_F17, KEY_F17 },
{ SDL_SCANCODE_F18, KEY_F18 },
{ SDL_SCANCODE_F19, KEY_F19 }
};
static MOUSEBUTTON s_buttonConversion[16] = {
MOUSE_BUTTON_NONE,
MOUSE_BUTTON_LEFT,
MOUSE_BUTTON_MIDDLE,
MOUSE_BUTTON_RIGHT,
MOUSE_BUTTON_XBUTTON1,
MOUSE_BUTTON_XBUTTON2,
MOUSE_BUTTON_XBUTTON3,
MOUSE_BUTTON_XBUTTON4,
MOUSE_BUTTON_XBUTTON5,
MOUSE_BUTTON_XBUTTON6,
MOUSE_BUTTON_XBUTTON7,
MOUSE_BUTTON_XBUTTON8,
MOUSE_BUTTON_XBUTTON9,
MOUSE_BUTTON_XBUTTON10,
MOUSE_BUTTON_XBUTTON11,
MOUSE_BUTTON_XBUTTON12
};
bool SDLInputActive() {
return OsGuiGetWindow(0) != nullptr && GxDevApi() == GxApi_GLSDL;
}
void SDLInputGetMousePosition(int32_t* x, int32_t *y) {
int mouseX;
int mouseY;
if (Input::s_osMouseMode == OS_MOUSE_MODE_RELATIVE) {
SDL_GetMouseState(&mouseX, &mouseY);
} else {
SDL_GetGlobalMouseState(&mouseX, &mouseY);
}
if (x) {
*x = static_cast<int32_t>(mouseX);
}
if (y) {
*y = static_cast<int32_t>(mouseY);
}
return;
}
bool ConvertScancode(SDL_Scancode scancode, KEY& key) {
// What key does this SDL scancode correspond to?
auto lookup = s_keyConversion.find(scancode);
if (lookup != s_keyConversion.end()) {
// Scancode was found
key = lookup->second;
return true;
}
return false;
}
int32_t SDLInputGet(OSINPUT* id, int32_t* param0, int32_t* param1, int32_t* param2, int32_t* param3) {
*id = static_cast<OSINPUT>(-1);
if (Input::s_queueTail != Input::s_queueHead) {
OsQueueGet(id, param0, param1, param2, param3);
return 1;
}
auto gxWindow = OsGuiGetWindow(0);
auto sdlWindow = static_cast<SDL_Window*>(gxWindow);
SDL_Event event;
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_KEYDOWN:
case SDL_KEYUP: {
KEY key;
if (ConvertScancode(event.key.keysym.scancode, key)) {
*id = event.type == SDL_KEYUP ? OS_INPUT_KEY_UP : OS_INPUT_KEY_DOWN;
*param0 = key;
return 1;
}
break;
}
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP: {
// Is this an up or down mouse click?
*id = event.type == SDL_MOUSEBUTTONUP ? OS_INPUT_MOUSE_UP : OS_INPUT_MOUSE_DOWN;
// XY click coordinates
auto x = static_cast<int32_t>(event.button.x);
auto y = static_cast<int32_t>(event.button.y);
// Convert SDL button index into internal MOUSEBUTTON ID
auto buttonIndex = event.button.button;
if (buttonIndex > 15) {
break;
}
auto button = s_buttonConversion[buttonIndex];
*param0 = button;
*param1 = x;
*param2 = y;
*param3 = 0;
return 1;
}
case SDL_MOUSEMOTION: {
auto x = static_cast<int32_t>(event.motion.x);
auto y = static_cast<int32_t>(event.motion.y);
*id = OS_INPUT_MOUSE_MOVE;
*param0 = 0;
*param1 = x;
*param2 = y;
*param3 = 0;
return 1;
}
case SDL_TEXTINPUT: {
// text input string holding one or more UTF-8 characters
auto text = reinterpret_cast<const uint8_t*>(event.text.text);
// Because SDL_TextInputEvent can hold multiple UTF-8 characters
// split into UTF-8 characters
while (*text != '\0') {
// byte size of current UTF-8 character
int32_t charactersize = 0;
// Read UTF-8 character
auto character = static_cast<int32_t>(SUniSGetUTF8(text, &charactersize));
if (character < 0) {
// Cancel in case of invalid input
break;
}
// Push character to input queue
OsQueuePut(OS_INPUT_CHAR, character, 1, 0, 0);
// Advance text pointer
text += charactersize;
}
// deque first character if any
if (Input::s_queueTail != Input::s_queueHead) {
OsQueueGet(id, param0, param1, param2, param3);
return 1;
}
// continue loop if there was not a single character in this event
break;
}
case SDL_WINDOWEVENT_RESIZED: {
auto width = static_cast<int32_t>(event.window.data1);
auto height = static_cast<int32_t>(event.window.data2);
// static_cast<CGxDeviceGLSDL*>(g_theGxDevicePtr)->Resize(width, height);
*id = OS_INPUT_SIZE;
*param0 = width;
*param1 = height;
auto bounds = GetSavedWindowBounds();
Rect newBounds = {
bounds->top,
bounds->left,
static_cast<int16_t>(bounds->top + height),
static_cast<int16_t>(bounds->left + width)
};
SetSavedWindowBounds(newBounds);
break;
}
case SDL_QUIT: {
*id = OS_INPUT_CLOSE;
return 1;
}
default:
break;
}
}
return 0;
}

View file

@ -1,12 +0,0 @@
#ifndef EVENT_SDL_INPUT_HPP
#define EVENT_SDL_INPUT_HPP
#include "event/Input.hpp"
bool SDLInputActive();
int32_t SDLInputGet(OSINPUT* id, int32_t* param0, int32_t* param1, int32_t* param2, int32_t* param3);
void SDLInputGetMousePosition(int32_t* x, int32_t *y);
#endif

View file

@ -1,767 +0,0 @@
#include "event/Input.hpp"
#include "client/Gui.hpp"
#include <storm/Error.hpp>
#include <tempest/Vector.hpp>
#include <windows.h>
#if defined(WHOA_BUILD_GLSDL)
#include "event/sdl/Input.hpp"
#endif
static const uint32_t s_latin5lookup[256] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11,
0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A,
0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23,
0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C,
0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35,
0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E,
0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50,
0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x62,
0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B,
0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74,
0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D,
0x7E, 0x7F, 0x20AC, 0x20, 0x201A, 0x192, 0x201E, 0x2026, 0x2020,
0x2021, 0x2C6, 0x2030, 0x160, 0x2039, 0x152, 0x20, 0x20, 0x20,
0x20, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, 0x2DC,
0x2122, 0x161, 0x203A, 0x153, 0x20, 0x20, 0x178, 0x0A0, 0x0A1,
0x0A2, 0x0A3, 0x0A4, 0x0A5, 0x0A6, 0x0A7, 0x0A8, 0x0A9, 0x0AA,
0x0AB, 0x0AC, 0x0AD, 0x0AE, 0x0AF, 0x0B0, 0x0B1, 0x0B2, 0x0B3,
0x0B4, 0x0B5, 0x0B6, 0x0B7, 0x0B8, 0x0B9, 0x0BA, 0x0BB, 0x0BC,
0x0BD, 0x0BE, 0x0BF, 0x0C0, 0x0C1, 0x0C2, 0x0C3, 0x0C4, 0x0C5,
0x0C6, 0x0C7, 0x0C8, 0x0C9, 0x0CA, 0x0CB, 0x0CC, 0x0CD, 0x0CE,
0x0CF, 0x11E, 0x0D1, 0x0D2, 0x0D3, 0x0D4, 0x0D5, 0x0D6, 0x0D7,
0x0D8, 0x0D9, 0x0DA, 0x0DB, 0x0DC, 0x130, 0x15E, 0x0DF, 0x0E0,
0x0E1, 0x0E2, 0x0E3, 0x0E4, 0x0E5, 0x0E6, 0x0E7, 0x0E8, 0x0E9,
0x0EA, 0x0EB, 0x0EC, 0x0ED, 0x0EE, 0x0EF, 0x11F, 0x0F1, 0x0F2,
0x0F3, 0x0F4, 0x0F5, 0x0F6, 0x0F7, 0x0F8, 0x0F9, 0x0FA, 0x0FB,
0x0FC, 0x131, 0x15F, 0x0FF
};
static const uint32_t s_latin1lookup[32] = {
0x0FFFE, 0x0FFFE, 0x201A, 0x192, 0x201E, 0x2026, 0x2020, 0x2021,
0x2C6, 0x2030, 0x160, 0x2039, 0x152, 0x0FFFE, 0x0FFFE, 0x0FFFE,
0x0FFFE, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
0x2DC, 0x2122, 0x161, 0x203A, 0x153, 0x0FFFE, 0x0FFFE, 0x178
};
static const uint32_t s_cyrilliclookup[256] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11,
0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A,
0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23,
0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C,
0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35,
0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E,
0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50,
0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x62,
0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B,
0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74,
0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D,
0x7E, 0x7F, 0x402, 0x403, 0x201A, 0x453, 0x201E, 0x2026, 0x2020,
0x2021, 0x20AC, 0x2030, 0x409, 0x2039, 0x40A, 0x40C, 0x40B, 0x40F,
0x452, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, 0x20,
0x2122, 0x459, 0x203A, 0x45A, 0x45C, 0x45B, 0x45F, 0x0A0, 0x40E,
0x45E, 0x408, 0x0A4, 0x490, 0x0A6, 0x0A7, 0x401, 0x0A9, 0x404,
0x0AB, 0x0AC, 0x0AD, 0x0AE, 0x407, 0x0B0, 0x0B1, 0x406, 0x456,
0x491, 0x0B5, 0x0B6, 0x0B7, 0x451, 0x2116, 0x454, 0x0BB, 0x458,
0x405, 0x455, 0x457, 0x410, 0x411, 0x412, 0x413, 0x414, 0x415,
0x416, 0x417, 0x418, 0x419, 0x41A, 0x41B, 0x41C, 0x41D, 0x41E,
0x41F, 0x420, 0x421, 0x422, 0x423, 0x424, 0x425, 0x426, 0x427,
0x428, 0x429, 0x42A, 0x42B, 0x42C, 0x42D, 0x42E, 0x42F, 0x430,
0x431, 0x432, 0x433, 0x434, 0x435, 0x436, 0x437, 0x438, 0x439,
0x43A, 0x43B, 0x43C, 0x43D, 0x43E, 0x43F, 0x440, 0x441, 0x442,
0x443, 0x444, 0x445, 0x446, 0x447, 0x448, 0x449, 0x44A, 0x44B,
0x44C, 0x44D, 0x44E, 0x44F
};
static const uint32_t s_latin2lookup[256] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11,
0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A,
0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23,
0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C,
0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35,
0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E,
0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50,
0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x62,
0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B,
0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74,
0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D,
0x7E, 0x7F, 0x20AC, 0x0FFFE, 0x201A, 0x0FFFE, 0x201E, 0x2026, 0x2020,
0x2021, 0x0FFFE, 0x2030, 0x160, 0x2039, 0x15A, 0x164, 0x17D, 0x179,
0x0FFFE, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, 0x0FFFE,
0x2122, 0x161, 0x203A, 0x15B, 0x165, 0x17E, 0x17A, 0x0A0, 0x2C7,
0x2D8, 0x141, 0x0A4, 0x104, 0x0A6, 0x0A7, 0x0A8, 0x0A9, 0x15E,
0x0AB, 0x0AC, 0x0AD, 0x0AE, 0x17B, 0x0B0, 0x0B1, 0x2DB, 0x142,
0x0B4, 0x0B5, 0x0B6, 0x0B7, 0x0B8, 0x105, 0x15F, 0x0BB, 0x13D,
0x2DD, 0x13E, 0x17C, 0x154, 0x0C1, 0x0C2, 0x102, 0x0C4, 0x139,
0x106, 0x0C7, 0x10C, 0x0C9, 0x118, 0x0CB, 0x11A, 0x0CD, 0x0CE,
0x10E, 0x110, 0x143, 0x147, 0x0D3, 0x0D4, 0x150, 0x0D6, 0x0D7,
0x158, 0x16E, 0x0DA, 0x170, 0x0DC, 0x0DD, 0x162, 0x0DF, 0x155,
0x0E1, 0x0E2, 0x103, 0x0E4, 0x13A, 0x107, 0x0E7, 0x10D, 0x0E9,
0x119, 0x0EB, 0x11B, 0x0ED, 0x0EE, 0x10F, 0x111, 0x144, 0x148,
0x0F3, 0x0F4, 0x151, 0x0F6, 0x0F7, 0x159, 0x16F, 0x0FA, 0x171,
0x0FC, 0x0FD, 0x163, 0x2D9
};
static const uint32_t s_thailookup[256] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11,
0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A,
0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23,
0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C,
0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35,
0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E,
0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50,
0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x62,
0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B,
0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74,
0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D,
0x7E, 0x7F, 0x20AC, 0x20, 0x20, 0x20, 0x20, 0x2026, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x0A0, 0x0E01,
0x0E02, 0x0E03, 0x0E04, 0x0E05, 0x0E06, 0x0E07, 0x0E08, 0x0E09, 0x0E0A,
0x0E0B, 0x0E0C, 0x0E0D, 0x0E0E, 0x0E0F, 0x0E10, 0x0E11, 0x0E12, 0x0E13,
0x0E14, 0x0E15, 0x0E16, 0x0E17, 0x0E18, 0x0E19, 0x0E1A, 0x0E1B, 0x0E1C,
0x0E1D, 0x0E1E, 0x0E1F, 0x0E20, 0x0E21, 0x0E22, 0x0E23, 0x0E24, 0x0E25,
0x0E26, 0x0E27, 0x0E28, 0x0E29, 0x0E2A, 0x0E2B, 0x0E2C, 0x0E2D, 0x0E2E,
0x0E2F, 0x0E30, 0x0E31, 0x0E32, 0x0E33, 0x0E34, 0x0E35, 0x0E36, 0x0E37,
0x0E38, 0x0E39, 0x0E3A, 0x20, 0x20, 0x20, 0x20, 0x0E3F, 0x0E40,
0x0E41, 0x0E42, 0x0E43, 0x0E44, 0x0E45, 0x0E46, 0x0E47, 0x0E48, 0x0E49,
0x0E4A, 0x0E4B, 0x0E4C, 0x0E4D, 0x0E4E, 0x0E4F, 0x0E50, 0x0E51, 0x0E52,
0x0E53, 0x0E54, 0x0E55, 0x0E56, 0x0E57, 0x0E58, 0x0E59, 0x0E5A, 0x0E5B,
0x20, 0x20, 0x20, 0x20
};
static RECT s_defaultWindowRect;
static int32_t s_savedResize;
static HWND s_mouseWnd;
static C2iVector s_mousePos;
void CenterMouse() {
// TODO
}
void RestoreMouse() {
// TODO
}
void SaveMouse(HWND window, const POINT& pt) {
s_mouseWnd = window;
s_mousePos.x = static_cast<int32_t>(pt.x);
s_mousePos.y = static_cast<int32_t>(pt.y);
}
int32_t ConvertButton(uint32_t message, uintptr_t wparam, MOUSEBUTTON* button) {
switch (message) {
case WM_NCLBUTTONDOWN:
case WM_NCLBUTTONUP:
case WM_NCLBUTTONDBLCLK:
case WM_LBUTTONDOWN:
case WM_LBUTTONUP: {
*button = MOUSE_BUTTON_LEFT;
return 1;
}
case WM_NCRBUTTONDOWN:
case WM_NCRBUTTONUP:
case WM_RBUTTONDOWN:
case WM_RBUTTONUP: {
*button = MOUSE_BUTTON_RIGHT;
return 1;
}
case WM_NCMBUTTONDOWN:
case WM_NCMBUTTONUP:
case WM_MBUTTONDOWN:
case WM_MBUTTONUP: {
*button = MOUSE_BUTTON_MIDDLE;
return 1;
}
case WM_NCXBUTTONDOWN:
case WM_NCXBUTTONUP:
case WM_XBUTTONDOWN:
case WM_XBUTTONUP: {
switch (GET_XBUTTON_WPARAM(wparam)) {
case XBUTTON1: {
*button = MOUSE_BUTTON_XBUTTON1;
return 1;
}
case XBUTTON2: {
*button = MOUSE_BUTTON_XBUTTON2;
return 1;
}
default: {
*button = MOUSE_BUTTON_NONE;
return 0;
}
}
}
default: {
*button = MOUSE_BUTTON_NONE;
return 0;
}
}
}
int32_t ConvertKeyCode(uint32_t vkey, KEY* key) {
if (vkey >= VK_F1 && vkey <= VK_F12) {
*key = static_cast<KEY>(KEY_F1 + (vkey - VK_F1));
return 1;
}
if (vkey >= 0x30 && vkey <= 0x39) {
*key = static_cast<KEY>(KEY_0 + (vkey - 0x30));
return 1;
}
switch (vkey) {
case VK_BACK: {
*key = KEY_BACKSPACE;
return 1;
}
case VK_TAB: {
*key = KEY_TAB;
return 1;
}
case VK_RETURN: {
*key = KEY_ENTER;
return 1;
}
case VK_PAUSE: {
*key = KEY_PAUSE;
return 1;
}
case VK_CAPITAL: {
*key = KEY_CAPSLOCK;
return 1;
}
case VK_ESCAPE: {
*key = KEY_ESCAPE;
return 1;
}
case VK_SPACE: {
*key = KEY_SPACE;
return 1;
}
case VK_PRIOR: {
*key = KEY_PAGEUP;
return 1;
}
case VK_NEXT: {
*key = KEY_PAGEDOWN;
return 1;
}
case VK_END: {
*key = KEY_END;
return 1;
}
case VK_HOME: {
*key = KEY_HOME;
return 1;
}
case VK_LEFT: {
*key = KEY_LEFT;
return 1;
}
case VK_UP: {
*key = KEY_UP;
return 1;
}
case VK_RIGHT: {
*key = KEY_RIGHT;
return 1;
}
case VK_DOWN: {
*key = KEY_DOWN;
return 1;
}
case VK_SNAPSHOT: {
*key = KEY_PRINTSCREEN;
return 1;
}
case VK_INSERT: {
*key = KEY_INSERT;
return 1;
}
case VK_DELETE: {
*key = KEY_DELETE;
return 1;
}
case VK_NUMPAD0:
case VK_NUMPAD1:
case VK_NUMPAD2:
case VK_NUMPAD3:
case VK_NUMPAD4:
case VK_NUMPAD5:
case VK_NUMPAD6:
case VK_NUMPAD7:
case VK_NUMPAD8:
case VK_NUMPAD9: {
*key = static_cast<KEY>(KEY_NUMPAD0 + (vkey - VK_NUMPAD0));
return 1;
}
case VK_MULTIPLY: {
*key = KEY_NUMPAD_MULTIPLY;
return 1;
}
case VK_ADD: {
*key = KEY_NUMPAD_PLUS;
return 1;
}
case VK_SUBTRACT: {
*key = KEY_NUMPAD_MINUS;
return 1;
}
case VK_DECIMAL: {
*key = KEY_NUMPAD_DECIMAL;
return 1;
}
case VK_DIVIDE: {
*key = KEY_NUMPAD_DIVIDE;
return 1;
}
case VK_NUMLOCK: {
*key = KEY_NUMLOCK;
return 1;
}
case VK_SCROLL: {
*key = KEY_SCROLLLOCK;
return 1;
}
case VK_LSHIFT: {
*key = KEY_LSHIFT;
return 1;
}
case VK_RSHIFT: {
*key = KEY_RSHIFT;
return 1;
}
case VK_LCONTROL: {
*key = KEY_LCONTROL;
return 1;
}
case VK_RCONTROL: {
*key = KEY_RCONTROL;
return 1;
}
case VK_LMENU: {
*key = KEY_LALT;
return 1;
}
case VK_RMENU: {
*key = KEY_RALT;
return 1;
}
default: {
auto character = MapVirtualKey(vkey, MAPVK_VK_TO_CHAR);
*key = static_cast<KEY>(character);
if (character && character <= 0xFF) {
return 1;
} else {
return 0;
}
}
}
}
bool ProcessMouseEvent(MOUSEBUTTON button, uint32_t message, HWND hwnd, OSINPUT id) {
POINT mousePos;
if (Input::s_osMouseMode == OS_MOUSE_MODE_RELATIVE) {
// TODO
} else {
GetCursorPos(&mousePos);
ScreenToClient(hwnd, &mousePos);
}
OsQueuePut(id, button, mousePos.x, mousePos.y, 0);
return message == WM_XBUTTONDOWN
|| message == WM_XBUTTONUP
|| message == WM_NCXBUTTONDOWN
|| message == WM_NCXBUTTONUP;
}
int32_t HandleMouseDown(uint32_t message, uintptr_t wparam, bool* xbutton, HWND hwnd) {
MOUSEBUTTON button;
if (!ConvertButton(message, wparam, &button)) {
return 0;
}
if (Input::s_osButtonState == 0) {
SetCapture(hwnd);
}
Input::s_osButtonState |= button;
auto xb = ProcessMouseEvent(button, message, hwnd, OS_INPUT_MOUSE_DOWN);
if (xbutton) {
*xbutton = xb;
}
return 1;
}
int32_t HandleMouseUp(uint32_t message, uintptr_t wparam, bool* xbutton, HWND hwnd) {
MOUSEBUTTON button;
if (!ConvertButton(message, wparam, &button)) {
return 0;
}
Input::s_osButtonState &= ~button;
if (Input::s_osButtonState == 0) {
// TODO
ReleaseCapture();
// TODO
}
auto xb = ProcessMouseEvent(button, message, hwnd, OS_INPUT_MOUSE_UP);
if (xbutton) {
*xbutton = xb;
}
return 1;
}
int32_t OsInputGet(OSINPUT* id, int32_t* param0, int32_t* param1, int32_t* param2, int32_t* param3) {
#if defined(WHOA_BUILD_GLSDL)
if (SDLInputActive()) {
// SDL handles input events for us
return SDLInputGet(id, param0, param1, param2, param3);
}
#endif
*id = static_cast<OSINPUT>(-1);
if (s_savedResize) {
auto hwnd = static_cast<HWND>(OsGuiGetWindow(0));
if (!IsIconic(hwnd)) {
s_savedResize = 0;
RECT windowRect;
GetWindowRect(hwnd, &windowRect);
auto style = GetWindowLong(hwnd, GWL_STYLE);
RECT clientArea = { 0, 0, 0, 0 };
AdjustWindowRectEx(&clientArea, style, false, 0);
auto width = windowRect.right - clientArea.right - (windowRect.left - clientArea.left);
auto height = windowRect.bottom - clientArea.bottom - (windowRect.top - clientArea.top);
if (s_defaultWindowRect.right != width || s_defaultWindowRect.bottom != height) {
s_defaultWindowRect.left = 0;
s_defaultWindowRect.top = 0;
s_defaultWindowRect.right = width;
s_defaultWindowRect.bottom = height;
*id = OS_INPUT_SIZE;
*param0 = width;
*param1 = height;
*param2 = 0;
*param3 = 0;
return 1;
}
}
}
if (Input::s_queueTail != Input::s_queueHead) {
OsQueueGet(id, param0, param1, param2, param3);
return 1;
}
// TODO Sub8714B0(dwordB1C220);
while (true) {
MSG msg;
auto peekResult = PeekMessage(&msg, nullptr, 0, 0, PM_NOREMOVE);
if (Input::s_queueTail != Input::s_queueHead) {
break;
}
if (!peekResult) {
return 0;
}
if (!GetMessage(&msg, nullptr, 0, 0)) {
*id = OS_INPUT_SHUTDOWN;
break;
}
if (OsGuiProcessMessage(&msg)) {
break;
}
if (Input::s_queueTail != Input::s_queueHead) {
break;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
if (Input::s_queueTail != Input::s_queueHead) {
break;
}
}
OsQueueGet(id, param0, param1, param2, param3);
return 1;
}
void OsInputSetMouseMode(OS_MOUSE_MODE mode) {
STORM_VALIDATE_BEGIN;
STORM_VALIDATE(mode < OS_MOUSE_MODES);
STORM_VALIDATE_END_VOID;
if (Input::s_osMouseMode == mode) {
return;
}
if (mode == OS_MOUSE_MODE_NORMAL) {
Input::s_osMouseMode = mode;
RestoreMouse();
} else if (mode == OS_MOUSE_MODE_RELATIVE) {
Input::s_osMouseMode = mode;
CenterMouse();
}
}
void OsInputGetMousePosition(int32_t* x, int32_t* y) {
#if defined(WHOA_BUILD_GLSDL)
if (SDLInputActive()) {
SDLInputGetMousePosition(x, y);
return;
}
#endif
// Get HWND created by CGxDevice
auto window = static_cast<HWND>(OsGuiGetWindow(0));
POINT pt;
GetCursorPos(&pt);
ScreenToClient(window, &pt);
if (Input::s_osMouseMode != OS_MOUSE_MODE_RELATIVE) {
SaveMouse(window, pt);
}
// Provide mouse position to caller
if (x) {
*x = static_cast<int32_t>(pt.x);
}
if (y) {
*y = static_cast<int32_t>(pt.y);
}
}
uint32_t OsInputGetCodePage() {
return ::GetACP();
}
int32_t OsWindowProc(void* window, uint32_t message, uintptr_t wparam, intptr_t lparam) {
static uint32_t s_codepage = 0;
auto hwnd = static_cast<HWND>(window);
// TODO
switch (message) {
// TODO handle remaining message types
case WM_SIZE:
case WM_DISPLAYCHANGE: {
s_savedResize = lparam;
break;
}
case WM_ACTIVATE: {
auto isMinimized = IsIconic(hwnd);
auto isActive = wparam != WA_INACTIVE;
Input::s_windowFocused = isActive && !isMinimized;
// TODO capture
// TODO mouse speed
OsQueuePut(OS_INPUT_FOCUS, Input::s_windowFocused != 0, 0, 0, 0);
break;
}
case WM_CLOSE: {
OsQueuePut(OS_INPUT_CLOSE, 0, 0, 0, 0);
return 0;
}
case WM_KEYDOWN:
case WM_KEYUP:
case WM_SYSKEYDOWN:
case WM_SYSKEYUP: {
auto keyDown = message == WM_KEYDOWN || message == WM_SYSKEYDOWN;
if (wparam == VK_SHIFT) {
// TODO
} else if (wparam == VK_CONTROL) {
// TODO
} else if (wparam == VK_MENU) {
// TODO
}
KEY key;
if (ConvertKeyCode(wparam, &key)) {
OsQueuePut(keyDown ? OS_INPUT_KEY_DOWN : OS_INPUT_KEY_UP, key, LOWORD(lparam), 0, 0);
// Alt + F4
if (key == KEY_F4 && OsGuiIsModifierKeyDown(2)) {
break;
}
return 0;
}
break;
}
case WM_CHAR: {
if (wparam < 32) {
break;
}
uint32_t character = wparam;
if (wparam >= 128) {
if (s_codepage == 0) {
s_codepage = OsInputGetCodePage();
}
if (s_codepage == 1254) {
// ANSI Turkish; Turkish (Windows)
character = s_latin5lookup[wparam % 256];
} else if (s_codepage == 1252 && wparam < 0xA0) {
// ANSI Latin 1; Western European (Windows)
character = s_latin1lookup[wparam % 32];
} else if (s_codepage == 1251) {
// ANSI Cyrillic; Cyrillic (Windows)
character = s_cyrilliclookup[wparam % 256];
} else if (s_codepage == 1250) {
// ANSI Central European; Central European (Windows)
character = s_latin2lookup[wparam % 256];
} else if (s_codepage == 874) {
// Thai (Windows)
character = s_thailookup[wparam % 256];
}
}
OsQueuePut(OS_INPUT_CHAR, character, LOWORD(lparam), 0, 0);
return 0;
}
case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_MBUTTONDOWN:
case WM_XBUTTONDOWN: {
bool xbutton;
if (HandleMouseDown(message, wparam, &xbutton, hwnd)) {
// Normally, a processed button down message should return 0
// In the case of xbuttons, a processed button down message should return 1
// See: https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-xbuttondown
return xbutton ? 1 : 0;
}
break;
}
case WM_LBUTTONUP:
case WM_RBUTTONUP:
case WM_MBUTTONUP:
case WM_XBUTTONUP: {
if (message == WM_LBUTTONUP) {
// TODO
}
bool xbutton;
if (HandleMouseUp(message, wparam, &xbutton, hwnd)) {
// Normally, a processed button down message should return 0
// In the case of xbuttons, a processed button down message should return 1
// See: https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-xbuttondown
return xbutton ? 1 : 0;
}
break;
}
case WM_MOUSEMOVE: {
// TODO
if (Input::s_osMouseMode == OS_MOUSE_MODE_RELATIVE) {
// TODO
} else {
POINT mousePos;
GetCursorPos(&mousePos);
ScreenToClient(hwnd, &mousePos);
OsQueuePut(OS_INPUT_MOUSE_MOVE, 0, mousePos.x, mousePos.y, 0);
SaveMouse(hwnd, mousePos);
}
break;
}
default:
break;
}
// TODO
return DefWindowProc(static_cast<HWND>(window), message, wparam, lparam);
}