initial upload

This commit is contained in:
Ryan Fleury
2024-01-10 19:57:50 -08:00
commit a42ec6aeff
308 changed files with 162362 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
//- GENERATED CODE
+452
View File
@@ -0,0 +1,452 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
//- GENERATED CODE
#ifndef OS_GFX_META_H
#define OS_GFX_META_H
typedef enum OS_Key
{
OS_Key_Null,
OS_Key_Esc,
OS_Key_F1,
OS_Key_F2,
OS_Key_F3,
OS_Key_F4,
OS_Key_F5,
OS_Key_F6,
OS_Key_F7,
OS_Key_F8,
OS_Key_F9,
OS_Key_F10,
OS_Key_F11,
OS_Key_F12,
OS_Key_F13,
OS_Key_F14,
OS_Key_F15,
OS_Key_F16,
OS_Key_F17,
OS_Key_F18,
OS_Key_F19,
OS_Key_F20,
OS_Key_F21,
OS_Key_F22,
OS_Key_F23,
OS_Key_F24,
OS_Key_Tick,
OS_Key_0,
OS_Key_1,
OS_Key_2,
OS_Key_3,
OS_Key_4,
OS_Key_5,
OS_Key_6,
OS_Key_7,
OS_Key_8,
OS_Key_9,
OS_Key_Minus,
OS_Key_Equal,
OS_Key_Backspace,
OS_Key_Tab,
OS_Key_Q,
OS_Key_W,
OS_Key_E,
OS_Key_R,
OS_Key_T,
OS_Key_Y,
OS_Key_U,
OS_Key_I,
OS_Key_O,
OS_Key_P,
OS_Key_LeftBracket,
OS_Key_RightBracket,
OS_Key_BackSlash,
OS_Key_CapsLock,
OS_Key_A,
OS_Key_S,
OS_Key_D,
OS_Key_F,
OS_Key_G,
OS_Key_H,
OS_Key_J,
OS_Key_K,
OS_Key_L,
OS_Key_Semicolon,
OS_Key_Quote,
OS_Key_Return,
OS_Key_Shift,
OS_Key_Z,
OS_Key_X,
OS_Key_C,
OS_Key_V,
OS_Key_B,
OS_Key_N,
OS_Key_M,
OS_Key_Comma,
OS_Key_Period,
OS_Key_Slash,
OS_Key_Ctrl,
OS_Key_Alt,
OS_Key_Space,
OS_Key_Menu,
OS_Key_ScrollLock,
OS_Key_Pause,
OS_Key_Insert,
OS_Key_Home,
OS_Key_PageUp,
OS_Key_Delete,
OS_Key_End,
OS_Key_PageDown,
OS_Key_Up,
OS_Key_Left,
OS_Key_Down,
OS_Key_Right,
OS_Key_Ex0,
OS_Key_Ex1,
OS_Key_Ex2,
OS_Key_Ex3,
OS_Key_Ex4,
OS_Key_Ex5,
OS_Key_Ex6,
OS_Key_Ex7,
OS_Key_Ex8,
OS_Key_Ex9,
OS_Key_Ex10,
OS_Key_Ex11,
OS_Key_Ex12,
OS_Key_Ex13,
OS_Key_Ex14,
OS_Key_Ex15,
OS_Key_Ex16,
OS_Key_Ex17,
OS_Key_Ex18,
OS_Key_Ex19,
OS_Key_Ex20,
OS_Key_Ex21,
OS_Key_Ex22,
OS_Key_Ex23,
OS_Key_Ex24,
OS_Key_Ex25,
OS_Key_Ex26,
OS_Key_Ex27,
OS_Key_Ex28,
OS_Key_Ex29,
OS_Key_NumLock,
OS_Key_NumSlash,
OS_Key_NumStar,
OS_Key_NumMinus,
OS_Key_NumPlus,
OS_Key_NumPeriod,
OS_Key_Num0,
OS_Key_Num1,
OS_Key_Num2,
OS_Key_Num3,
OS_Key_Num4,
OS_Key_Num5,
OS_Key_Num6,
OS_Key_Num7,
OS_Key_Num8,
OS_Key_Num9,
OS_Key_LeftMouseButton,
OS_Key_MiddleMouseButton,
OS_Key_RightMouseButton,
OS_Key_COUNT
} OS_Key;
String8 os_g_key_display_string_table[] =
{
str8_lit_comp("Invalid Key"),
str8_lit_comp("Escape"),
str8_lit_comp("F1"),
str8_lit_comp("F2"),
str8_lit_comp("F3"),
str8_lit_comp("F4"),
str8_lit_comp("F5"),
str8_lit_comp("F6"),
str8_lit_comp("F7"),
str8_lit_comp("F8"),
str8_lit_comp("F9"),
str8_lit_comp("F10"),
str8_lit_comp("F11"),
str8_lit_comp("F12"),
str8_lit_comp("F13"),
str8_lit_comp("F14"),
str8_lit_comp("F15"),
str8_lit_comp("F16"),
str8_lit_comp("F17"),
str8_lit_comp("F18"),
str8_lit_comp("F19"),
str8_lit_comp("F20"),
str8_lit_comp("F21"),
str8_lit_comp("F22"),
str8_lit_comp("F23"),
str8_lit_comp("F24"),
str8_lit_comp("Tick"),
str8_lit_comp("0"),
str8_lit_comp("1"),
str8_lit_comp("2"),
str8_lit_comp("3"),
str8_lit_comp("4"),
str8_lit_comp("5"),
str8_lit_comp("6"),
str8_lit_comp("7"),
str8_lit_comp("8"),
str8_lit_comp("9"),
str8_lit_comp("Minus"),
str8_lit_comp("Equal"),
str8_lit_comp("Backspace"),
str8_lit_comp("Tab"),
str8_lit_comp("Q"),
str8_lit_comp("W"),
str8_lit_comp("E"),
str8_lit_comp("R"),
str8_lit_comp("T"),
str8_lit_comp("Y"),
str8_lit_comp("U"),
str8_lit_comp("I"),
str8_lit_comp("O"),
str8_lit_comp("P"),
str8_lit_comp("Left Bracket"),
str8_lit_comp("Right Bracket"),
str8_lit_comp("Back Slash"),
str8_lit_comp("Caps Lock"),
str8_lit_comp("A"),
str8_lit_comp("S"),
str8_lit_comp("D"),
str8_lit_comp("F"),
str8_lit_comp("G"),
str8_lit_comp("H"),
str8_lit_comp("J"),
str8_lit_comp("K"),
str8_lit_comp("L"),
str8_lit_comp("Semicolon"),
str8_lit_comp("Quote"),
str8_lit_comp("Return"),
str8_lit_comp("Shift"),
str8_lit_comp("Z"),
str8_lit_comp("X"),
str8_lit_comp("C"),
str8_lit_comp("V"),
str8_lit_comp("B"),
str8_lit_comp("N"),
str8_lit_comp("M"),
str8_lit_comp("Comma"),
str8_lit_comp("Period"),
str8_lit_comp("Slash"),
str8_lit_comp("Ctrl"),
str8_lit_comp("Alt"),
str8_lit_comp("Space"),
str8_lit_comp("Menu"),
str8_lit_comp("Scroll Lock"),
str8_lit_comp("Pause"),
str8_lit_comp("Insert"),
str8_lit_comp("Home"),
str8_lit_comp("Page Up"),
str8_lit_comp("Delete"),
str8_lit_comp("End"),
str8_lit_comp("Page Down"),
str8_lit_comp("Up"),
str8_lit_comp("Left"),
str8_lit_comp("Down"),
str8_lit_comp("Right"),
str8_lit_comp("Ex0"),
str8_lit_comp("Ex1"),
str8_lit_comp("Ex2"),
str8_lit_comp("Ex3"),
str8_lit_comp("Ex4"),
str8_lit_comp("Ex5"),
str8_lit_comp("Ex6"),
str8_lit_comp("Ex7"),
str8_lit_comp("Ex8"),
str8_lit_comp("Ex9"),
str8_lit_comp("Ex10"),
str8_lit_comp("Ex11"),
str8_lit_comp("Ex12"),
str8_lit_comp("Ex13"),
str8_lit_comp("Ex14"),
str8_lit_comp("Ex15"),
str8_lit_comp("Ex16"),
str8_lit_comp("Ex17"),
str8_lit_comp("Ex18"),
str8_lit_comp("Ex19"),
str8_lit_comp("Ex20"),
str8_lit_comp("Ex21"),
str8_lit_comp("Ex22"),
str8_lit_comp("Ex23"),
str8_lit_comp("Ex24"),
str8_lit_comp("Ex25"),
str8_lit_comp("Ex26"),
str8_lit_comp("Ex27"),
str8_lit_comp("Ex28"),
str8_lit_comp("Ex29"),
str8_lit_comp("Num Lock"),
str8_lit_comp("Numpad Slash"),
str8_lit_comp("Numpad Star"),
str8_lit_comp("Numpad Minus"),
str8_lit_comp("Numpad Plus"),
str8_lit_comp("Numpad Period"),
str8_lit_comp("Numpad 0"),
str8_lit_comp("Numpad 1"),
str8_lit_comp("Numpad 2"),
str8_lit_comp("Numpad 3"),
str8_lit_comp("Numpad 4"),
str8_lit_comp("Numpad 5"),
str8_lit_comp("Numpad 6"),
str8_lit_comp("Numpad 7"),
str8_lit_comp("Numpad 8"),
str8_lit_comp("Numpad 9"),
str8_lit_comp("Left Mouse Button"),
str8_lit_comp("Middle Mouse Button"),
str8_lit_comp("Right Mouse Button"),
};
String8 os_g_key_cfg_string_table[] =
{
str8_lit_comp("null"),
str8_lit_comp("esc"),
str8_lit_comp("f1"),
str8_lit_comp("f2"),
str8_lit_comp("f3"),
str8_lit_comp("f4"),
str8_lit_comp("f5"),
str8_lit_comp("f6"),
str8_lit_comp("f7"),
str8_lit_comp("f8"),
str8_lit_comp("f9"),
str8_lit_comp("f10"),
str8_lit_comp("f11"),
str8_lit_comp("f12"),
str8_lit_comp("f13"),
str8_lit_comp("f14"),
str8_lit_comp("f15"),
str8_lit_comp("f16"),
str8_lit_comp("f17"),
str8_lit_comp("f18"),
str8_lit_comp("f19"),
str8_lit_comp("f20"),
str8_lit_comp("f21"),
str8_lit_comp("f22"),
str8_lit_comp("f23"),
str8_lit_comp("f24"),
str8_lit_comp("tick"),
str8_lit_comp("0"),
str8_lit_comp("1"),
str8_lit_comp("2"),
str8_lit_comp("3"),
str8_lit_comp("4"),
str8_lit_comp("5"),
str8_lit_comp("6"),
str8_lit_comp("7"),
str8_lit_comp("8"),
str8_lit_comp("9"),
str8_lit_comp("minus"),
str8_lit_comp("equal"),
str8_lit_comp("backspace"),
str8_lit_comp("tab"),
str8_lit_comp("q"),
str8_lit_comp("w"),
str8_lit_comp("e"),
str8_lit_comp("r"),
str8_lit_comp("t"),
str8_lit_comp("y"),
str8_lit_comp("u"),
str8_lit_comp("i"),
str8_lit_comp("o"),
str8_lit_comp("p"),
str8_lit_comp("left_bracket"),
str8_lit_comp("right_bracket"),
str8_lit_comp("backslash"),
str8_lit_comp("caps_lock"),
str8_lit_comp("a"),
str8_lit_comp("s"),
str8_lit_comp("d"),
str8_lit_comp("f"),
str8_lit_comp("g"),
str8_lit_comp("h"),
str8_lit_comp("j"),
str8_lit_comp("k"),
str8_lit_comp("l"),
str8_lit_comp("semicolon"),
str8_lit_comp("quote"),
str8_lit_comp("return"),
str8_lit_comp("shift"),
str8_lit_comp("z"),
str8_lit_comp("x"),
str8_lit_comp("c"),
str8_lit_comp("v"),
str8_lit_comp("b"),
str8_lit_comp("n"),
str8_lit_comp("m"),
str8_lit_comp("comma"),
str8_lit_comp("period"),
str8_lit_comp("slash"),
str8_lit_comp("ctrl"),
str8_lit_comp("alt"),
str8_lit_comp("space"),
str8_lit_comp("menu"),
str8_lit_comp("scroll_lock"),
str8_lit_comp("pause"),
str8_lit_comp("insert"),
str8_lit_comp("home"),
str8_lit_comp("page_up"),
str8_lit_comp("delete"),
str8_lit_comp("end"),
str8_lit_comp("page_down"),
str8_lit_comp("up"),
str8_lit_comp("left"),
str8_lit_comp("down"),
str8_lit_comp("right"),
str8_lit_comp("ex0"),
str8_lit_comp("ex1"),
str8_lit_comp("ex2"),
str8_lit_comp("ex3"),
str8_lit_comp("ex4"),
str8_lit_comp("ex5"),
str8_lit_comp("ex6"),
str8_lit_comp("ex7"),
str8_lit_comp("ex8"),
str8_lit_comp("ex9"),
str8_lit_comp("ex10"),
str8_lit_comp("ex11"),
str8_lit_comp("ex12"),
str8_lit_comp("ex13"),
str8_lit_comp("ex14"),
str8_lit_comp("ex15"),
str8_lit_comp("ex16"),
str8_lit_comp("ex17"),
str8_lit_comp("ex18"),
str8_lit_comp("ex19"),
str8_lit_comp("ex20"),
str8_lit_comp("ex21"),
str8_lit_comp("ex22"),
str8_lit_comp("ex23"),
str8_lit_comp("ex24"),
str8_lit_comp("ex25"),
str8_lit_comp("ex26"),
str8_lit_comp("ex27"),
str8_lit_comp("ex28"),
str8_lit_comp("ex29"),
str8_lit_comp("num_lock"),
str8_lit_comp("numpad_slash"),
str8_lit_comp("numpad_star"),
str8_lit_comp("numpad_minus"),
str8_lit_comp("numpad_plus"),
str8_lit_comp("numpad_period"),
str8_lit_comp("numpad_0"),
str8_lit_comp("numpad_1"),
str8_lit_comp("numpad_2"),
str8_lit_comp("numpad_3"),
str8_lit_comp("numpad_4"),
str8_lit_comp("numpad_5"),
str8_lit_comp("numpad_6"),
str8_lit_comp("numpad_7"),
str8_lit_comp("numpad_8"),
str8_lit_comp("numpad_9"),
str8_lit_comp("left_mouse"),
str8_lit_comp("middle_mouse"),
str8_lit_comp("right_mouse"),
};
#endif // OS_GFX_META_H
+191
View File
@@ -0,0 +1,191 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
//~ rjf: Event Functions (Helpers, Implemented Once)
internal String8List
os_string_list_from_event_flags(Arena *arena, OS_EventFlags flags)
{
String8List result = {0};
String8 flag_strs[] =
{
str8_lit("Ctrl"),
str8_lit("Shift"),
str8_lit("Alt"),
};
str8_list_from_flags(arena, &result, flags, flag_strs, ArrayCount(flag_strs));
return result;
}
internal U32
os_codepoint_from_event_flags_and_key(OS_EventFlags flags, OS_Key key)
{
U32 result = 0;
// rjf: special-case map
local_persist read_only struct {U32 character; OS_Key key; OS_EventFlags flags;} map[] =
{
{'!', OS_Key_1, OS_EventFlag_Shift},
{'@', OS_Key_2, OS_EventFlag_Shift},
{'#', OS_Key_3, OS_EventFlag_Shift},
{'$', OS_Key_4, OS_EventFlag_Shift},
{'%', OS_Key_5, OS_EventFlag_Shift},
{'^', OS_Key_6, OS_EventFlag_Shift},
{'&', OS_Key_7, OS_EventFlag_Shift},
{'*', OS_Key_8, OS_EventFlag_Shift},
{'(', OS_Key_9, OS_EventFlag_Shift},
{')', OS_Key_0, OS_EventFlag_Shift},
{'_', OS_Key_Minus, OS_EventFlag_Shift},
{'_', OS_Key_Minus, OS_EventFlag_Shift},
{'-', OS_Key_Minus, 0},
{'=', OS_Key_Equal, 0},
{'+', OS_Key_Equal, OS_EventFlag_Shift},
{'`', OS_Key_Tick, 0},
{'~', OS_Key_Tick, OS_EventFlag_Shift},
{'[', OS_Key_LeftBracket, 0},
{']', OS_Key_RightBracket, 0},
{'{', OS_Key_LeftBracket, OS_EventFlag_Shift},
{'}', OS_Key_RightBracket, OS_EventFlag_Shift},
{'\\', OS_Key_BackSlash, 0},
{'|', OS_Key_BackSlash, OS_EventFlag_Shift},
{';', OS_Key_Semicolon, 0},
{':', OS_Key_Semicolon, OS_EventFlag_Shift},
{'\'', OS_Key_Quote, 0},
{'"', OS_Key_Quote, OS_EventFlag_Shift},
{'.', OS_Key_Period, 0},
{',', OS_Key_Comma, 0},
{'<', OS_Key_Period, OS_EventFlag_Shift},
{'>', OS_Key_Comma, OS_EventFlag_Shift},
{'/', OS_Key_Slash, 0},
{'?', OS_Key_Slash, OS_EventFlag_Shift},
{'a', OS_Key_A, 0},
{'b', OS_Key_B, 0},
{'c', OS_Key_C, 0},
{'d', OS_Key_D, 0},
{'e', OS_Key_E, 0},
{'f', OS_Key_F, 0},
{'g', OS_Key_G, 0},
{'h', OS_Key_H, 0},
{'i', OS_Key_I, 0},
{'j', OS_Key_J, 0},
{'k', OS_Key_K, 0},
{'l', OS_Key_L, 0},
{'m', OS_Key_M, 0},
{'n', OS_Key_N, 0},
{'o', OS_Key_O, 0},
{'p', OS_Key_P, 0},
{'q', OS_Key_Q, 0},
{'r', OS_Key_R, 0},
{'s', OS_Key_S, 0},
{'t', OS_Key_T, 0},
{'u', OS_Key_U, 0},
{'v', OS_Key_V, 0},
{'w', OS_Key_W, 0},
{'x', OS_Key_X, 0},
{'y', OS_Key_Y, 0},
{'z', OS_Key_Z, 0},
{'A', OS_Key_A, OS_EventFlag_Shift},
{'B', OS_Key_B, OS_EventFlag_Shift},
{'C', OS_Key_C, OS_EventFlag_Shift},
{'D', OS_Key_D, OS_EventFlag_Shift},
{'E', OS_Key_E, OS_EventFlag_Shift},
{'F', OS_Key_F, OS_EventFlag_Shift},
{'G', OS_Key_G, OS_EventFlag_Shift},
{'H', OS_Key_H, OS_EventFlag_Shift},
{'I', OS_Key_I, OS_EventFlag_Shift},
{'J', OS_Key_J, OS_EventFlag_Shift},
{'K', OS_Key_K, OS_EventFlag_Shift},
{'L', OS_Key_L, OS_EventFlag_Shift},
{'M', OS_Key_M, OS_EventFlag_Shift},
{'N', OS_Key_N, OS_EventFlag_Shift},
{'O', OS_Key_O, OS_EventFlag_Shift},
{'P', OS_Key_P, OS_EventFlag_Shift},
{'Q', OS_Key_Q, OS_EventFlag_Shift},
{'R', OS_Key_R, OS_EventFlag_Shift},
{'S', OS_Key_S, OS_EventFlag_Shift},
{'T', OS_Key_T, OS_EventFlag_Shift},
{'U', OS_Key_U, OS_EventFlag_Shift},
{'V', OS_Key_V, OS_EventFlag_Shift},
{'W', OS_Key_W, OS_EventFlag_Shift},
{'X', OS_Key_X, OS_EventFlag_Shift},
{'Y', OS_Key_Y, OS_EventFlag_Shift},
{'Z', OS_Key_Z, OS_EventFlag_Shift},
};
// rjf: check numeric
if(OS_Key_0 <= key && key <= OS_Key_9)
{
result = '0' + (key - OS_Key_0);
}
// rjf: check special-case map
for(U64 idx = 0; idx < ArrayCount(map); idx += 1)
{
if(map[idx].key == key && map[idx].flags == flags)
{
result = map[idx].character;
break;
}
}
return result;
}
internal void
os_eat_event(OS_EventList *events, OS_Event *event)
{
DLLRemove(events->first, events->last, event);
events->count -= 1;
}
internal B32
os_key_press(OS_EventList *events, OS_Handle window, OS_EventFlags flags, OS_Key key)
{
B32 result = 0;
for(OS_Event *event = events->first; event != 0; event = event->next)
{
if((os_handle_match(event->window, window) || os_handle_match(window, os_handle_zero())) &&
event->kind == OS_EventKind_Press && event->key == key && event->flags == flags)
{
result = 1;
os_eat_event(events, event);
break;
}
}
return result;
}
internal B32
os_key_release(OS_EventList *events, OS_Handle window, OS_EventFlags flags, OS_Key key)
{
B32 result = 0;
for(OS_Event *event = events->first; event != 0; event = event->next)
{
if((os_handle_match(event->window, window) || os_handle_match(window, os_handle_zero())) &&
event->kind == OS_EventKind_Release && event->key == key && event->flags == flags)
{
result = 1;
os_eat_event(events, event);
break;
}
}
return result;
}
internal B32
os_text(OS_EventList *events, OS_Handle window, U32 character)
{
B32 result = 0;
for(OS_Event *event = events->first; event != 0; event = event->next)
{
if((os_handle_match(event->window, window) || os_handle_match(window, os_handle_zero())) &&
event->kind == OS_EventKind_Text && event->character == character)
{
result = 1;
os_eat_event(events, event);
break;
}
}
return result;
}
+162
View File
@@ -0,0 +1,162 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef OS_GRAPHICAL_H
#define OS_GRAPHICAL_H
////////////////////////////////
//~ rjf: Window Types
typedef void OS_WindowRepaintFunctionType(OS_Handle window, void *user_data);
////////////////////////////////
//~ rjf: Cursor Types
typedef enum OS_Cursor
{
OS_Cursor_Pointer,
OS_Cursor_IBar,
OS_Cursor_LeftRight,
OS_Cursor_UpDown,
OS_Cursor_DownRight,
OS_Cursor_UpRight,
OS_Cursor_UpDownLeftRight,
OS_Cursor_HandPoint,
OS_Cursor_Disabled,
OS_Cursor_COUNT,
}
OS_Cursor;
////////////////////////////////
//~ rjf: Generated Code
#include "os/gfx/generated/os_gfx.meta.h"
////////////////////////////////
//~ rjf: Event Types
typedef enum OS_EventKind
{
OS_EventKind_Null,
OS_EventKind_Press,
OS_EventKind_Release,
OS_EventKind_Text,
OS_EventKind_Scroll,
OS_EventKind_WindowLoseFocus,
OS_EventKind_WindowClose,
OS_EventKind_FileDrop,
OS_EventKind_Wakeup,
OS_EventKind_COUNT
}
OS_EventKind;
typedef U32 OS_EventFlags;
enum
{
OS_EventFlag_Ctrl = (1<<0),
OS_EventFlag_Shift = (1<<1),
OS_EventFlag_Alt = (1<<2),
};
typedef struct OS_Event OS_Event;
struct OS_Event
{
OS_Event *next;
OS_Event *prev;
OS_Handle window;
OS_EventKind kind;
OS_EventFlags flags;
OS_Key key;
B32 is_repeat;
B32 right_sided;
U32 character;
U32 repeat_count;
Vec2F32 delta;
String8List strings;
};
typedef struct OS_EventList OS_EventList;
struct OS_EventList
{
U64 count;
OS_Event *first;
OS_Event *last;
};
////////////////////////////////
//~ rjf: Event Functions (Helpers, Implemented Once)
internal String8List os_string_list_from_event_flags(Arena *arena, OS_EventFlags flags);
internal U32 os_codepoint_from_event_flags_and_key(OS_EventFlags flags, OS_Key key);
internal void os_eat_event(OS_EventList *events, OS_Event *event);
internal B32 os_key_press(OS_EventList *events, OS_Handle window, OS_EventFlags flags, OS_Key key);
internal B32 os_key_release(OS_EventList *events, OS_Handle window, OS_EventFlags flags, OS_Key key);
internal B32 os_text(OS_EventList *events, OS_Handle window, U32 character);
////////////////////////////////
//~ rjf: @os_hooks Main Initialization API (Implemented Per-OS)
internal void os_graphical_init(void);
////////////////////////////////
//~ rjf: @os_hooks Clipboards (Implemented Per-OS)
internal void os_set_clipboard_text(String8 string);
internal String8 os_get_clipboard_text(Arena *arena);
////////////////////////////////
//~ rjf: @os_hooks Windows (Implemented Per-OS)
internal OS_Handle os_window_open(Vec2F32 resolution, String8 title);
internal void os_window_close(OS_Handle window);
internal void os_window_first_paint(OS_Handle window);
internal void os_window_equip_repaint(OS_Handle window, OS_WindowRepaintFunctionType *repaint, void *user_data);
internal void os_window_focus(OS_Handle window);
internal B32 os_window_is_focused(OS_Handle window);
internal B32 os_window_is_fullscreen(OS_Handle window);
internal void os_window_set_fullscreen(OS_Handle window, B32 fullscreen);
internal B32 os_window_is_maximized(OS_Handle window);
internal void os_window_set_maximized(OS_Handle window, B32 maximized);
internal void os_window_bring_to_front(OS_Handle window);
internal void os_window_set_monitor(OS_Handle window, OS_Handle monitor);
internal Rng2F32 os_rect_from_window(OS_Handle window);
internal Rng2F32 os_client_rect_from_window(OS_Handle window);
internal F32 os_dpi_from_window(OS_Handle window);
////////////////////////////////
//~ rjf: @os_hooks Monitors (Implemented Per-OS)
internal OS_HandleArray os_push_monitors_array(Arena *arena);
internal OS_Handle os_primary_monitor(void);
internal OS_Handle os_monitor_from_window(OS_Handle window);
internal String8 os_name_from_monitor(Arena *arena, OS_Handle monitor);
internal Vec2F32 os_dim_from_monitor(OS_Handle monitor);
////////////////////////////////
//~ rjf: @os_hooks Events (Implemented Per-OS)
internal void os_send_wakeup_event(void);
internal OS_EventList os_get_events(Arena *arena, B32 wait);
internal OS_EventFlags os_get_event_flags(void);
internal B32 os_key_is_down(OS_Key key);
internal Vec2F32 os_mouse_from_window(OS_Handle window);
////////////////////////////////
//~ rjf: @os_hooks Cursors (Implemented Per-OS)
internal void os_set_cursor(OS_Cursor cursor);
////////////////////////////////
//~ rjf: @os_hooks System Properties (Implemented Per-OS)
internal F32 os_double_click_time(void);
internal F32 os_caret_blink_time(void);
internal F32 os_default_refresh_rate(void);
internal B32 os_granular_sleep_enabled(void);
////////////////////////////////
//~ rjf: @os_hooks Native Messages & Panics (Implemented Per-OS)
internal void os_graphical_message(B32 error, String8 title, String8 message);
#endif // OS_GRAPHICAL_H
+175
View File
@@ -0,0 +1,175 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
//~ rjf: Tables
@table(name, display_string, cfg_string)
OS_KeyTable:
{
{Null "Invalid Key" "null" }
{Esc "Escape" "esc" }
{F1 "F1" "f1" }
{F2 "F2" "f2" }
{F3 "F3" "f3" }
{F4 "F4" "f4" }
{F5 "F5" "f5" }
{F6 "F6" "f6" }
{F7 "F7" "f7" }
{F8 "F8" "f8" }
{F9 "F9" "f9" }
{F10 "F10" "f10" }
{F11 "F11" "f11" }
{F12 "F12" "f12" }
{F13 "F13" "f13" }
{F14 "F14" "f14" }
{F15 "F15" "f15" }
{F16 "F16" "f16" }
{F17 "F17" "f17" }
{F18 "F18" "f18" }
{F19 "F19" "f19" }
{F20 "F20" "f20" }
{F21 "F21" "f21" }
{F22 "F22" "f22" }
{F23 "F23" "f23" }
{F24 "F24" "f24" }
{Tick "Tick" "tick" }
{0 "0" "0" }
{1 "1" "1" }
{2 "2" "2" }
{3 "3" "3" }
{4 "4" "4" }
{5 "5" "5" }
{6 "6" "6" }
{7 "7" "7" }
{8 "8" "8" }
{9 "9" "9" }
{Minus "Minus" "minus" }
{Equal "Equal" "equal" }
{Backspace "Backspace" "backspace" }
{Tab "Tab" "tab" }
{Q "Q" "q" }
{W "W" "w" }
{E "E" "e" }
{R "R" "r" }
{T "T" "t" }
{Y "Y" "y" }
{U "U" "u" }
{I "I" "i" }
{O "O" "o" }
{P "P" "p" }
{LeftBracket "Left Bracket" "left_bracket" }
{RightBracket "Right Bracket" "right_bracket" }
{BackSlash "Back Slash" "backslash" }
{CapsLock "Caps Lock" "caps_lock" }
{A "A" "a" }
{S "S" "s" }
{D "D" "d" }
{F "F" "f" }
{G "G" "g" }
{H "H" "h" }
{J "J" "j" }
{K "K" "k" }
{L "L" "l" }
{Semicolon "Semicolon" "semicolon" }
{Quote "Quote" "quote" }
{Return "Return" "return" }
{Shift "Shift" "shift" }
{Z "Z" "z" }
{X "X" "x" }
{C "C" "c" }
{V "V" "v" }
{B "B" "b" }
{N "N" "n" }
{M "M" "m" }
{Comma "Comma" "comma" }
{Period "Period" "period" }
{Slash "Slash" "slash" }
{Ctrl "Ctrl" "ctrl" }
{Alt "Alt" "alt" }
{Space "Space" "space" }
{Menu "Menu" "menu" }
{ScrollLock "Scroll Lock" "scroll_lock" }
{Pause "Pause" "pause" }
{Insert "Insert" "insert" }
{Home "Home" "home" }
{PageUp "Page Up" "page_up" }
{Delete "Delete" "delete" }
{End "End" "end" }
{PageDown "Page Down" "page_down" }
{Up "Up" "up" }
{Left "Left" "left" }
{Down "Down" "down" }
{Right "Right" "right" }
{Ex0 "Ex0" "ex0" }
{Ex1 "Ex1" "ex1" }
{Ex2 "Ex2" "ex2" }
{Ex3 "Ex3" "ex3" }
{Ex4 "Ex4" "ex4" }
{Ex5 "Ex5" "ex5" }
{Ex6 "Ex6" "ex6" }
{Ex7 "Ex7" "ex7" }
{Ex8 "Ex8" "ex8" }
{Ex9 "Ex9" "ex9" }
{Ex10 "Ex10" "ex10" }
{Ex11 "Ex11" "ex11" }
{Ex12 "Ex12" "ex12" }
{Ex13 "Ex13" "ex13" }
{Ex14 "Ex14" "ex14" }
{Ex15 "Ex15" "ex15" }
{Ex16 "Ex16" "ex16" }
{Ex17 "Ex17" "ex17" }
{Ex18 "Ex18" "ex18" }
{Ex19 "Ex19" "ex19" }
{Ex20 "Ex20" "ex20" }
{Ex21 "Ex21" "ex21" }
{Ex22 "Ex22" "ex22" }
{Ex23 "Ex23" "ex23" }
{Ex24 "Ex24" "ex24" }
{Ex25 "Ex25" "ex25" }
{Ex26 "Ex26" "ex26" }
{Ex27 "Ex27" "ex27" }
{Ex28 "Ex28" "ex28" }
{Ex29 "Ex29" "ex29" }
{NumLock "Num Lock" "num_lock" }
{NumSlash "Numpad Slash" "numpad_slash" }
{NumStar "Numpad Star" "numpad_star" }
{NumMinus "Numpad Minus" "numpad_minus" }
{NumPlus "Numpad Plus" "numpad_plus" }
{NumPeriod "Numpad Period" "numpad_period" }
{Num0 "Numpad 0" "numpad_0" }
{Num1 "Numpad 1" "numpad_1" }
{Num2 "Numpad 2" "numpad_2" }
{Num3 "Numpad 3" "numpad_3" }
{Num4 "Numpad 4" "numpad_4" }
{Num5 "Numpad 5" "numpad_5" }
{Num6 "Numpad 6" "numpad_6" }
{Num7 "Numpad 7" "numpad_7" }
{Num8 "Numpad 8" "numpad_8" }
{Num9 "Numpad 9" "numpad_9" }
{LeftMouseButton "Left Mouse Button" "left_mouse" }
{MiddleMouseButton "Middle Mouse Button" "middle_mouse" }
{RightMouseButton "Right Mouse Button" "right_mouse" }
}
////////////////////////////////
//~ rjf: Generators
@table_gen_enum
OS_Key:
{
@expand(OS_KeyTable a) `OS_Key_$(a.name),`;
`OS_Key_COUNT`;
}
@table_gen_data(type: String8, fallback:`{0}`)
os_g_key_display_string_table:
{
@expand(OS_KeyTable a) `str8_lit_comp("$(a.display_string)"),`;
}
@table_gen_data(type: String8, fallback:`{0}`)
os_g_key_cfg_string_table:
{
@expand(OS_KeyTable a) `str8_lit_comp("$(a.cfg_string)"),`;
}
File diff suppressed because it is too large Load Diff
+62
View File
@@ -0,0 +1,62 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef WIN32_GRAPHICAL_H
#define WIN32_GRAPHICAL_H
#pragma comment(lib, "user32")
#pragma comment(lib, "gdi32")
#pragma comment(lib, "winmm")
////////////////////////////////
//~ rjf: Windows
typedef struct W32_Window W32_Window;
struct W32_Window
{
W32_Window *next;
W32_Window *prev;
HWND hwnd;
WINDOWPLACEMENT last_window_placement;
OS_WindowRepaintFunctionType *repaint;
void *repaint_user_data;
F32 dpi;
B32 first_paint_done;
B32 maximized;
};
////////////////////////////////
//~ rjf: Monitor Gathering Bundle
typedef struct W32_MonitorGatherBundle W32_MonitorGatherBundle;
struct W32_MonitorGatherBundle
{
Arena *arena;
OS_HandleList *list;
};
////////////////////////////////
//~ rjf: Basic Helpers
internal Rng2F32 w32_base_rect_from_win32_rect(RECT rect);
////////////////////////////////
//~ rjf: Windows
internal OS_Handle os_window_from_w32_window(W32_Window *window);
internal W32_Window * w32_window_from_os_window(OS_Handle window);
internal W32_Window * w32_window_from_hwnd(HWND hwnd);
internal HWND w32_hwnd_from_window(W32_Window *window);
internal W32_Window * w32_allocate_window(void);
internal void w32_free_window(W32_Window *window);
internal OS_Event * w32_push_event(OS_EventKind kind, W32_Window *window);
internal OS_Key w32_os_key_from_vkey(WPARAM vkey);
internal WPARAM w32_vkey_from_os_key(OS_Key key);
internal LRESULT w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
////////////////////////////////
//~ rjf: Monitors
internal BOOL w32_monitor_gather_enum_proc(HMONITOR monitor, HDC hdc, LPRECT rect, LPARAM bundle_ptr);
#endif // WIN32_GRAPHICAL_H