add c and jai

This commit is contained in:
2026-07-13 13:02:47 -04:00
parent cf8342f8d4
commit c5b14d7c41
33 changed files with 6306 additions and 0 deletions

130
c/platform/platform.h Normal file
View File

@@ -0,0 +1,130 @@
#pragma once
// platform.h — GUI windowing, input, and system services
//
// Provides window creation, keyboard/mouse input, clipboard access,
// and process spawning. Implementation: platform_win32.c.
#include "base/base_core.h"
#include "base/base_math.h"
////////////////////////////////
// Key codes (matching Windows VK codes)
enum {
PKEY_BACKSPACE = 0x08,
PKEY_TAB = 0x09,
PKEY_RETURN = 0x0D,
PKEY_ESCAPE = 0x1B,
PKEY_PAGEUP = 0x21,
PKEY_PAGEDOWN = 0x22,
PKEY_END = 0x23,
PKEY_HOME = 0x24,
PKEY_LEFT = 0x25,
PKEY_UP = 0x26,
PKEY_RIGHT = 0x27,
PKEY_DOWN = 0x28,
PKEY_DELETE = 0x2E,
PKEY_0 = 0x30,
PKEY_1 = 0x31,
PKEY_2 = 0x32,
PKEY_3 = 0x33,
PKEY_A = 0x41,
PKEY_B = 0x42,
PKEY_C = 0x43,
PKEY_E = 0x45,
PKEY_F = 0x46,
PKEY_G = 0x47,
PKEY_H = 0x48,
PKEY_J = 0x4A,
PKEY_K = 0x4B,
PKEY_L = 0x4C,
PKEY_N = 0x4E,
PKEY_O = 0x4F,
PKEY_P = 0x50,
PKEY_Q = 0x51,
PKEY_S = 0x53,
PKEY_V = 0x56,
PKEY_W = 0x57,
PKEY_X = 0x58,
PKEY_Y = 0x59,
PKEY_Z = 0x5A,
PKEY_F4 = 0x73,
PKEY_F8 = 0x77,
PKEY_EQUAL = 0xBB,
PKEY_MINUS = 0xBD,
PKEY_BACKSLASH = 0xDC,
};
////////////////////////////////
// Input accumulated per frame
#define PLATFORM_MAX_CHARS_PER_FRAME 64
#define PLATFORM_MAX_KEYS_PER_FRAME 32
// Editor-facing input (ASCII chars + key codes + modifiers)
typedef struct PlatformInput {
char chars[PLATFORM_MAX_CHARS_PER_FRAME];
S32 char_count;
U8 keys[PLATFORM_MAX_KEYS_PER_FRAME];
S32 key_count;
B32 ctrl_held;
B32 shift_held;
B32 alt_held;
} PlatformInput;
// Raw windowing input (UTF-16 chars + VK codes + mouse)
typedef struct PlatformRawInput {
U16 chars[PLATFORM_MAX_CHARS_PER_FRAME];
S32 char_count;
U8 keys[PLATFORM_MAX_KEYS_PER_FRAME];
S32 key_count;
B32 ctrl_held;
B32 shift_held;
Vec2F32 mouse_pos;
Vec2F32 scroll_delta;
B32 mouse_down;
B32 was_mouse_down;
} PlatformRawInput;
////////////////////////////////
// Window
typedef struct PlatformWindow PlatformWindow;
typedef struct PlatformWindowDesc {
const char *title;
S32 width;
S32 height;
} PlatformWindowDesc;
typedef void (*PlatformFrameCallback)(void *user_data);
////////////////////////////////
// Window API
PlatformWindow *platform_create_window(PlatformWindowDesc *desc);
void platform_destroy_window(PlatformWindow *window);
B32 platform_poll_events(PlatformWindow *window);
void platform_get_size(PlatformWindow *window, S32 *w, S32 *h);
void *platform_get_native_handle(PlatformWindow *window);
PlatformRawInput platform_get_input(PlatformWindow *window);
void platform_set_frame_callback(PlatformWindow *window, PlatformFrameCallback cb, void *user_data);
F32 platform_get_dpi_scale(PlatformWindow *window);
////////////////////////////////
// Input adapter — convert raw windowing input to editor input
PlatformInput platform_adapt_input(PlatformRawInput *raw);
////////////////////////////////
// Clipboard
void platform_clipboard_set(const char *text);
const char *platform_clipboard_get(void);
////////////////////////////////
// Process spawning
void platform_spawn_terminal(const char *command, const char *working_dir);