#ifndef __WINDOW_HPP_ #define __WINDOW_HPP_ #include class vkrenderer; #if defined(LINUX) #include #include #elif defined(WINDOWS) // #include typedef struct HWND__* HWND; typedef int64_t LRESULT; typedef int64_t LPARAM; typedef uint64_t WPARAM; typedef unsigned int UINT; typedef void* LPVOID; #define CALLBACK __stdcall #endif // enum MODIFIERS: uint32_t { // SHIFT = 1, // LOCK = 2, // CTRL = 4, // ALT = 8, // MOD2 = 16, // MOD3 = 32, // MOD4 = 64, // MOD5 = 128, // BUTTON1 = 256, // BUTTON2 = 512, // BUTTON3 = 1024, // BUTTON4 = 2048, // BUTTON5 = 4096, // }; // TODO improve this #if defined(WINDOWS) enum KEYS: uint32_t { LSHIFT = 0x10, RSHIFT = 0x10, LCTRL = 0x11, RCTRL = 0x11, ALT, SPACE = 0x20, A = 0x41, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, MAX_KEYS = 255 }; #else enum KEYS: uint32_t { SPACE = 32, A = 0x61, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, LSHIFT = 65505, RSHIFT, LCTRL, RCTRL, LALT = 65513, RALT, MAX_KEYS = 0xffff }; #endif enum BUTTONS: uint32_t { LEFT, RIGHT, MIDDLE, MAX_BUTTONS = 255 }; enum EVENT_TYPES: int32_t { QUIT, RESIZE, KEY_PRESS, KEY_RELEASE, BUTTON_PRESS, BUTTON_RELEASE, MOUSE_MOVE }; // struct event { // uint32_t width; // uint32_t height; // KEYS key; // BUTTONS button; // int32_t x; // int32_t y; // EVENT_TYPES type; // }; struct event { union { struct { uint32_t width; uint32_t height; } size; struct { int32_t x; int32_t y; } position; KEYS key; BUTTONS button; } data; EVENT_TYPES type; }; class window { public: window(uint32_t desired_width, uint32_t desired_height); ~window(); void poll_events(); #if defined(WINDOWS) void message_loop(); LRESULT message_handler(HWND hwnd, UINT umsg, WPARAM wparam, LPARAM lparam); static LRESULT CALLBACK window_procedure(HWND hwnd, UINT umsg, WPARAM wparam, LPARAM lparam); HWND handle {}; const char* window_class_name; LPVOID main_fiber; LPVOID message_loop_fiber; #elif defined(LINUX) xcb_connection_t* connection; xcb_window_t win; xcb_atom_t win_delete_atom; xkb_context* xkb_ctx; int32_t keyboard_device_id; xkb_keymap* keyboard_keymap; xkb_state* keyboard_state; #endif std::vector events; uint32_t width; uint32_t height; bool isOpen; bool keyboard[KEYS::MAX_KEYS] { false }; bool mouse[BUTTONS::MAX_BUTTONS] { false }; }; #endif // !__WINDOW_HPP_