abstract input into platform layer

This commit is contained in:
2026-03-02 23:01:40 -05:00
parent 8d56ea7217
commit 46f636a9ac
5 changed files with 48 additions and 60 deletions

View File

@@ -2,10 +2,11 @@
#include <stdint.h>
#include <stdbool.h>
#include "base/base_core.h"
#include "base/base_math.h"
////////////////////////////////
// Input event buffer
// Accumulated per frame, consumed by the app each tick.
// Input — accumulated per frame, consumed by the app each tick.
#define PLATFORM_MAX_CHARS_PER_FRAME 64
#define PLATFORM_MAX_KEYS_PER_FRAME 32
@@ -29,7 +30,7 @@ enum {
PKEY_X = 0x58,
};
struct PlatformInputEvents {
struct PlatformInput {
// Typed characters (UTF-16 code units, printable only)
uint16_t chars[PLATFORM_MAX_CHARS_PER_FRAME];
int32_t char_count;
@@ -41,6 +42,12 @@ struct PlatformInputEvents {
// Modifier state at time of last key event
bool ctrl_held;
bool shift_held;
// Mouse state (polled per frame)
Vec2F32 mouse_pos;
Vec2F32 scroll_delta;
B32 mouse_down;
B32 was_mouse_down;
};
struct PlatformWindow;
@@ -77,8 +84,8 @@ void platform_set_frame_callback(PlatformWindow *window, PlatformFram
void platform_set_menu(PlatformWindow *window, PlatformMenu *menus, int32_t menu_count);
int32_t platform_poll_menu_command(PlatformWindow *window);
// Returns accumulated input events since last call, then clears the buffer.
PlatformInputEvents platform_get_input_events(PlatformWindow *window);
// Returns accumulated input since last call (keyboard events + polled mouse state), then clears the buffer.
PlatformInput platform_get_input(PlatformWindow *window);
// Clipboard operations (null-terminated UTF-8 strings).
// platform_clipboard_set copies text to the system clipboard.