progress towards opening a window; minor fixes here and there;
added base_math
This commit is contained in:
parent
79b6e83147
commit
404ec22e57
@ -168,7 +168,7 @@ global const u32 bit32 = (1 << 31);
|
|||||||
|
|
||||||
// Helpers
|
// Helpers
|
||||||
// ??(tijani): the calculation of how this works breaks my brain, need to bust out the pen and paper to figure it out.
|
// ??(tijani): the calculation of how this works breaks my brain, need to bust out the pen and paper to figure it out.
|
||||||
#define AlignPow2(x, b) (((x) + (b) - 1) & (~((b) - 1)))
|
#define AlignPow2(x, b) (((x) + (b)-1) & (~((b)-1)))
|
||||||
|
|
||||||
// Linkedlist building macros
|
// Linkedlist building macros
|
||||||
|
|
||||||
|
38
src/base/base_math.h
Normal file
38
src/base/base_math.h
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#ifndef BASE_MATH_H
|
||||||
|
#define BASE_MATH_H
|
||||||
|
|
||||||
|
// Vector Types
|
||||||
|
typedef Vec2F32 Vec2F32;
|
||||||
|
union Vec2F32 {
|
||||||
|
struct {
|
||||||
|
f32 x;
|
||||||
|
f32 y;
|
||||||
|
};
|
||||||
|
f32 v[2];
|
||||||
|
};
|
||||||
|
|
||||||
|
// Range Types
|
||||||
|
// Range 2 (forms a rectangle)
|
||||||
|
typedef union Rng2F32 Rng2F32;
|
||||||
|
union Rng2F32 {
|
||||||
|
struct {
|
||||||
|
Vec2F32 min;
|
||||||
|
Vec2F32 Max;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct {
|
||||||
|
Vec2F32 pos0;
|
||||||
|
Vec2F32 pos1;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct {
|
||||||
|
f32 x0;
|
||||||
|
f32 y0;
|
||||||
|
|
||||||
|
f32 x1;
|
||||||
|
f32 y1;
|
||||||
|
};
|
||||||
|
Vec2F32 v[2];
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // BASE_MATH_H
|
@ -19,7 +19,7 @@ internal void entry_point() {
|
|||||||
// {
|
// {
|
||||||
// df_core_init();
|
// df_core_init();
|
||||||
// df_gfx_init();
|
// df_gfx_init();
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Main application loop
|
// Main application loop
|
||||||
{
|
{
|
||||||
|
@ -15,7 +15,7 @@ struct OS_SystemInfo {
|
|||||||
typedef struct OS_Handle OS_Handle;
|
typedef struct OS_Handle OS_Handle;
|
||||||
struct OS_Handle {
|
struct OS_Handle {
|
||||||
u64 l_u64[1];
|
u64 l_u64[1];
|
||||||
}
|
};
|
||||||
|
|
||||||
// Process Information
|
// Process Information
|
||||||
typedef struct OS_ProcessInfo OS_ProcessInfo;
|
typedef struct OS_ProcessInfo OS_ProcessInfo;
|
||||||
|
@ -1,33 +1,120 @@
|
|||||||
#ifndefine OS_GFX_H
|
#ifndefine OS_GFX_H
|
||||||
#define OS_GFX_H
|
#define OS_GFX_H
|
||||||
|
|
||||||
|
// Graphics system information
|
||||||
|
typedef struct OS_GfxInfo OS_GfxInfo;
|
||||||
|
struct OS_GfxInfo {
|
||||||
|
f32 double_click_time;
|
||||||
|
f32 caret_blink_time;
|
||||||
|
f32 default_referesh_rate;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Window Types
|
||||||
|
typedef u32 OS_WindowFlags;
|
||||||
|
enum { OS_WindowFlag_CustomBorder = (1 << 0); };
|
||||||
|
|
||||||
typedef void OS_WindowRepaintFunctionType(OS_Handle window, void *user_data);
|
typedef void OS_WindowRepaintFunctionType(OS_Handle window, void *user_data);
|
||||||
|
|
||||||
ty
|
// 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;
|
||||||
|
|
||||||
|
typedef enum OS_EventKind {
|
||||||
|
OS_EvenKind_NULL,
|
||||||
|
OS_EventKind_Press,
|
||||||
|
OS_EventKind_Release,
|
||||||
|
OS_EventKind_MouseMove,
|
||||||
|
OS_EventKind_Text,
|
||||||
|
OS_EventKind_Scroll,
|
||||||
|
OS_EventKind_WindowLoseFocus,
|
||||||
|
OS_EventKind_WindowClose,
|
||||||
|
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;
|
typedef struct OS_Event OS_Event;
|
||||||
struct OS_Event {
|
struct OS_Event {
|
||||||
OS_Event *next;
|
OS_Event *next;
|
||||||
OS_Event *previous;
|
OS_Event *previous;
|
||||||
u64 timestamp_us;
|
u64 timestamp_us;
|
||||||
OS_Handle window;
|
OS_Handle window;
|
||||||
OS_EventKind kind;
|
OS_EventKind kind;
|
||||||
OS_EventFlag flags;
|
OS_EventFlag flags;
|
||||||
OS_Key key;
|
OS_Key key;
|
||||||
b32 is_repeat;
|
b32 is_repeat;
|
||||||
b32 right_sided;
|
b32 right_sided;
|
||||||
u32 character;
|
u32 character;
|
||||||
u32 repeat_count;
|
u32 repeat_count;
|
||||||
Vec2F32 position;
|
Vec2F32 position;
|
||||||
Vec2F32 delta;
|
Vec2F32 delta;
|
||||||
String8List strings;
|
String8List strings;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct OS_EventList OS_EventList;
|
typedef struct OS_EventList OS_EventList;
|
||||||
struct OS_EventList {
|
struct OS_EventList {
|
||||||
u64 count;
|
u64 count;
|
||||||
OS_Event *first;
|
OS_Event *first;
|
||||||
OS_Event *last;
|
OS_Event *last;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// %os_hooks Event function helpers (Implementd Per-OS)
|
||||||
|
internal 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 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);
|
||||||
|
|
||||||
|
// %os_hooks Main initialization API (Implemented Per-OS)
|
||||||
|
internal void os_gfx_init(void);
|
||||||
|
|
||||||
|
// %os_Hooks Graphics System Info (Implemented Per-OS)
|
||||||
|
internal OS_GfxInfo *os_get_gfx_info(void);
|
||||||
|
|
||||||
|
// %os_hooks Windows (Implemented Per-OS)
|
||||||
|
intarnal OS_Handle os_window_open(Vec2F32 resolution, OS_WindowsFlags flags, String8 title);
|
||||||
|
internal void os_window_close(OS_Handle handle);
|
||||||
|
internal void os_window_first_paint(OS_Handle window_handle);
|
||||||
|
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_minimize(OS_Handle window);
|
||||||
|
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);
|
||||||
|
|
||||||
|
// %os_hooks Events (Implemented Per-OS)
|
||||||
|
internal void os_send_wakeup_event(void);
|
||||||
|
internal EventList os_get_events(Arena *arena, b32 wait);
|
||||||
|
internal OS_EventFlags os_get_event_flags(void);
|
||||||
|
internal Vec2F32 os_mouse_from_window(OS_Handle window);
|
||||||
|
|
||||||
|
// %os_hooks Cursors (Implemented Per-OS)
|
||||||
|
internal void os_set_cursor(OS_Cursr cursor);
|
||||||
|
|
||||||
|
// %os_hooks Native user facing graphical message (Implemented Per-OS)
|
||||||
|
internal void os_graphical_message(b32 error, String8 title, String8 message);
|
||||||
|
|
||||||
|
// %os_hooks Shell Operations ??
|
||||||
|
internal void os_show_in_filesystem_ui(String8 path);
|
||||||
|
|
||||||
#endif // OS_GFX_H
|
#endif // OS_GFX_H
|
||||||
|
@ -1,4 +1,151 @@
|
|||||||
internal void os_gfx_init(void) {
|
// Windows
|
||||||
Arena *arena = arena_alloc();
|
internal OS_Handle os_w32_handle_from_window(OS_W32_Window *window) {}
|
||||||
os_w32_gfx_state =
|
internal OS_W32_Window *os_w32_window_from_handle(OS_Handle window) {}
|
||||||
|
internal OS_W32_Window *os_w32_window_from_hwnd(HWND hwnd) {}
|
||||||
|
internal HWND os_w32_hwnd_from_window(OS_W32_Window *window) {}
|
||||||
|
internal OS_W32_Window *os_w32_window_alloc(void) {}
|
||||||
|
internal void os_w32_window_release(OS_W32_Window *window) {}
|
||||||
|
internal OS_Event *os_w32_push_event(OS_EventKind kind, OS_W32_Window *window) {}
|
||||||
|
internal OS_Key os_w32_os_key_from_vkey(WPARAM vkey) {}
|
||||||
|
internal WPARAM os_w32_vkey_from_os_key(OS_Key key) {}
|
||||||
|
|
||||||
|
internal LRESULT os_w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
|
||||||
|
// Start profilling??
|
||||||
|
LRESULT result = 0;
|
||||||
|
b23 good = 1; // ??
|
||||||
|
|
||||||
|
if (os_w32_event_arena == 0) {
|
||||||
|
result = DefWindowProcW(hwnd, uMsg, wParam, lParam);
|
||||||
|
good = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (good) {
|
||||||
|
OS_W32_Window *window = os_w32_window_from_hwnd(hwnd);
|
||||||
|
OS_Handle window_handle = os_w32_handle_from_window(window);
|
||||||
|
b32 release = 0; // ??
|
||||||
|
|
||||||
|
switch (uMsg) {
|
||||||
|
default: {
|
||||||
|
result = DefWindowProcW(hwnd, uMsg, wParam, lParam);
|
||||||
|
} break;
|
||||||
|
case WM_SIZE:
|
||||||
|
case WM_PAINT {
|
||||||
|
if (window->repaint != 0) {
|
||||||
|
PAINTSTRUCT pain_struct = {0}; BeginPaint(hwnd, &paint_struct);
|
||||||
|
window->repaint(os_w32_handle_from_window(window), window->repaint_user_data);
|
||||||
|
EndPaint(hwnd, &paint_struct);
|
||||||
|
} else {
|
||||||
|
result = DefWindowProcW(hwnd, uMsg, wParam, lParam);
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
case WM_CLOSE: {
|
||||||
|
os_w32_push_event(OS_EventKind_WindowClose, window);
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case WM_DPICHANGED: {
|
||||||
|
f32 new_dpi = (f32)(wParam & 0xffff);
|
||||||
|
window->dpi = new_dpi;
|
||||||
|
} break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// End profiling
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal void os_gfx_init(void) {
|
||||||
|
Arena *arena = arena_alloc();
|
||||||
|
os_w32_gfx_state->arena = push_array(arena, OS_W32_GfxState, 1);
|
||||||
|
os_w32_gfx_satte->gfx_thread_tid = (u32)GetCurrentThreadId();
|
||||||
|
os_w32_gfx_state->hInstance = GetModuleHandle(0);
|
||||||
|
|
||||||
|
// Set DPI Awareness
|
||||||
|
|
||||||
|
// Register grahical window
|
||||||
|
{
|
||||||
|
WNDCLASSEXW wndclass = {sizeof(wndclass)};
|
||||||
|
wndclass.lpfnWndProc = os_w32_wnd_proc;
|
||||||
|
wndclass.hInstance = os_w32_gfx_state->hInstance;
|
||||||
|
wndclass.lpszClassName = L"goff-graphical-window";
|
||||||
|
wndclass.hCursor = LoadCursor(0, IDC_ARROW);
|
||||||
|
wndclass.hIcon = LoadIcon(os_w32_gfx_state->hInstance, MAKEINTRESOURCE(1));
|
||||||
|
wndclass.style = CS_VREDRAW | CS_HREDRAW;
|
||||||
|
ATOM wndatom = RegisterClassEXW(&wndclass);
|
||||||
|
(void)wndatom;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get graphics system info
|
||||||
|
|
||||||
|
// Set initial cursor
|
||||||
|
|
||||||
|
// Fill vkeys -> OS_KEY table
|
||||||
|
}
|
||||||
|
|
||||||
|
// %os_Hooks Graphics System Info (Implemented Per-OS)
|
||||||
|
internal OS_GfxInfo *os_get_gfx_info(void) { return &os_w32_gfx_state->gfx_info; }
|
||||||
|
|
||||||
|
// %os_hooks Windows (Implemented Per-OS)
|
||||||
|
intarnal OS_Handle os_window_open(Vec2F32 resolution, OS_WindowsFlags flags, String8 title) {
|
||||||
|
// make HWND
|
||||||
|
HWND hwnd = 0;
|
||||||
|
|
||||||
|
{
|
||||||
|
Temp scratch = scratch_begin(0, 0);
|
||||||
|
String16 title16 = str16_from_8(scratch.arena, title);
|
||||||
|
hwnd = CreateWindowExW(WS_EX_APPWINDOW, L"goff-graphical-window", (WCHAR *)title16.str,
|
||||||
|
WS_OVERLAPPEDWINDOW | WS_SIZEBOX, CW_USEDEFAULT, CW_USEDEFAULT, (int)resolution.x,
|
||||||
|
(int)resolution.y, 0, 0, os_w32_gfx_state->hInstance, 0);
|
||||||
|
scratch_end(scratch);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make/fill window
|
||||||
|
OS_W32_Window *window = os_w32_window_alloc();
|
||||||
|
{
|
||||||
|
window->hwnd = hwnd;
|
||||||
|
// Set DPI
|
||||||
|
}
|
||||||
|
|
||||||
|
OS_Handle handle = os_w32_handle_from_window(window);
|
||||||
|
return handle;
|
||||||
|
}
|
||||||
|
internal void os_window_close(OS_Handle handle) {
|
||||||
|
OS_W32_Window *window = os_w32_window_from_handle(handle);
|
||||||
|
os_w32_window_release(window);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void os_window_first_paint(OS_Handle window_handle) {
|
||||||
|
OS_W32_Window *window = os_w32_window_from_handle(window_handle);
|
||||||
|
window->filst_paint_done = 1;
|
||||||
|
ShowWindow(window->handle, SW_SHOW);
|
||||||
|
if (window->maximized) {
|
||||||
|
ShowWindow(window - hwnd, SW_MAXIMIZE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
internal void os_window_equip_repaint(OS_Handle handle, OS_WindowRepaintFunctionType *repaint, void *user_data) {
|
||||||
|
OS_W32_Window *window = os_w32_window_from_handle(handle);
|
||||||
|
window->repaint = repaint;
|
||||||
|
window->repaint_user_data = user_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal Rng2F32 os_rect_from_window(OS_Handle handle) {
|
||||||
|
Rng2F32 range = {0};
|
||||||
|
OS_W32_Window *window = os_w32_window_fram_handle(handle);
|
||||||
|
if (window) {
|
||||||
|
RECT rect = {0};
|
||||||
|
GetWindowRect(os_w32_hwnd_from_window(window), &rect);
|
||||||
|
range = os_w32_rng2f32_from_rect(rect);
|
||||||
|
}
|
||||||
|
return range;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal Rng2F32 os_client_rect_from_window(OS_Handle handle) {
|
||||||
|
Rng2f32 range = {0};
|
||||||
|
OS_W32_Window *window = os_w32_window_fram_handle(handle);
|
||||||
|
if (window) {
|
||||||
|
RECT = {0};
|
||||||
|
GetClientRect(os_w32_hwnd_from_window(window), &rect);
|
||||||
|
range = os_w32_rng2f32_from_rect(rect);
|
||||||
|
}
|
||||||
|
return range;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal f32 os_dpi_from_window(OS_Handle window) {}
|
||||||
|
@ -2,6 +2,11 @@
|
|||||||
#define OS_GFX_WIN32_H
|
#define OS_GFX_WIN32_H
|
||||||
|
|
||||||
// Windows
|
// Windows
|
||||||
|
typedef struct OS_W32_TitleBarClientArea OS_W32_TitleBarClientArean;
|
||||||
|
struct OS_W32_TitleBarClientArea {
|
||||||
|
OS_W32_TitleBarClientArea *next;
|
||||||
|
Rng2F32 rect;
|
||||||
|
};
|
||||||
typedef struct OS_W32_Window OS_W32_Window;
|
typedef struct OS_W32_Window OS_W32_Window;
|
||||||
struct OS_W32_Window {
|
struct OS_W32_Window {
|
||||||
OS_W32_Window *next;
|
OS_W32_Window *next;
|
||||||
@ -13,7 +18,13 @@ struct OS_W32_Window {
|
|||||||
f32 dpi;
|
f32 dpi;
|
||||||
b32 first_paint_done;
|
b32 first_paint_done;
|
||||||
b32 maximized;
|
b32 maximized;
|
||||||
|
b32 custome_border;
|
||||||
|
f32 custom_border_title_thickness;
|
||||||
|
f32 custom_border_edge_thickness;
|
||||||
|
b32 custom_border_composition_enabled;
|
||||||
Arena *pain_arena;
|
Arena *pain_arena;
|
||||||
|
OS_W32_TitleBarClientArea *first_title_bar_client_area;
|
||||||
|
OS_W32_TitleBarClientArea *last_title_bar_client_area;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Global State
|
// Global State
|
||||||
|
Loading…
Reference in New Issue
Block a user