abstract input into platform layer
This commit is contained in:
43
src/main.cpp
43
src/main.cpp
@@ -17,40 +17,6 @@
|
||||
#include "midi/midi_win32.cpp"
|
||||
#include "menus.cpp"
|
||||
|
||||
////////////////////////////////
|
||||
// Win32 input gathering
|
||||
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
#include <windows.h>
|
||||
|
||||
struct InputState {
|
||||
Vec2F32 mouse;
|
||||
Vec2F32 scroll_delta;
|
||||
B32 mouse_down;
|
||||
B32 was_mouse_down;
|
||||
};
|
||||
|
||||
static InputState g_input;
|
||||
|
||||
static void input_gather(void *window_handle) {
|
||||
HWND hwnd = (HWND)window_handle;
|
||||
|
||||
// Mouse position
|
||||
POINT cursor;
|
||||
GetCursorPos(&cursor);
|
||||
ScreenToClient(hwnd, &cursor);
|
||||
g_input.mouse = v2f32((F32)cursor.x, (F32)cursor.y);
|
||||
|
||||
// Mouse button
|
||||
g_input.was_mouse_down = g_input.mouse_down;
|
||||
g_input.mouse_down = (GetAsyncKeyState(VK_LBUTTON) & 0x8000) != 0;
|
||||
|
||||
// Scroll (TODO: hook WM_MOUSEWHEEL for real scroll deltas)
|
||||
g_input.scroll_delta = v2f32(0, 0);
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
// Clay text config helpers
|
||||
|
||||
@@ -430,13 +396,12 @@ static void do_frame(AppState *app) {
|
||||
return;
|
||||
|
||||
// Gather input
|
||||
input_gather(platform_get_native_handle(app->window));
|
||||
PlatformInputEvents input_events = platform_get_input_events(app->window);
|
||||
ui_widgets_begin_frame(input_events, g_input.mouse_down, g_input.was_mouse_down);
|
||||
PlatformInput input = platform_get_input(app->window);
|
||||
ui_widgets_begin_frame(input);
|
||||
|
||||
// Build UI with Clay
|
||||
ui_begin_frame(app->ui, (F32)w, (F32)h, g_input.mouse, g_input.mouse_down,
|
||||
g_input.scroll_delta, dt);
|
||||
ui_begin_frame(app->ui, (F32)w, (F32)h, input.mouse_pos, input.mouse_down,
|
||||
input.scroll_delta, dt);
|
||||
build_ui(app);
|
||||
Clay_RenderCommandArray render_commands = ui_end_frame(app->ui);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user