This commit is contained in:
Ryan Fleury
2025-03-25 16:21:51 -07:00
107 changed files with 25559 additions and 24722 deletions
+6
View File
@@ -443,6 +443,12 @@ os_copy_file_path(String8 dst, String8 src)
return result;
}
internal B32
os_move_file_path(String8 dst, String8 src)
{
// TODO(rjf)
}
internal String8
os_full_path_from_path(Arena *arena, String8 path)
{
+2
View File
@@ -202,6 +202,7 @@ internal void os_abort(S32 exit_code);
internal OS_Handle os_file_open(OS_AccessFlags flags, String8 path);
internal void os_file_close(OS_Handle file);
internal U64 os_file_read(OS_Handle file, Rng1U64 rng, void *out_data);
#define os_file_read_struct(f, off, ptr) os_file_read((f), r1u64((off), (off)+sizeof(*(ptr))), (ptr))
internal U64 os_file_write(OS_Handle file, Rng1U64 rng, void *data);
internal B32 os_file_set_times(OS_Handle file, DateTime time);
internal FileProperties os_properties_from_file(OS_Handle file);
@@ -209,6 +210,7 @@ internal OS_FileID os_id_from_file(OS_Handle file);
internal B32 os_file_reserve_size(OS_Handle file, U64 size);
internal B32 os_delete_file_at_path(String8 path);
internal B32 os_copy_file_path(String8 dst, String8 src);
internal B32 os_move_file_path(String8 dst, String8 src);
internal String8 os_full_path_from_path(Arena *arena, String8 path);
internal B32 os_file_path_exists(String8 path);
internal B32 os_folder_path_exists(String8 path);
+33
View File
@@ -503,6 +503,17 @@ os_copy_file_path(String8 dst, String8 src)
return result;
}
internal B32
os_move_file_path(String8 dst, String8 src)
{
Temp scratch = scratch_begin(0, 0);
String16 dst16 = str16_from_8(scratch.arena, dst);
String16 src16 = str16_from_8(scratch.arena, src);
B32 result = MoveFileW((WCHAR*)src16.str, (WCHAR*)dst16.str);
scratch_end(scratch);
return result;
}
internal String8
os_full_path_from_path(Arena *arena, String8 path)
{
@@ -560,6 +571,28 @@ os_properties_from_file_path(String8 path)
os_w32_dense_time_from_file_time(&props.modified, &find_data.ftLastWriteTime);
props.flags = os_w32_file_property_flags_from_dwFileAttributes(find_data.dwFileAttributes);
}
else
{
Temp scratch = scratch_begin(0, 0);
WCHAR buffer[512] = {0};
DWORD length = GetLogicalDriveStringsW(sizeof(buffer), buffer);
U64 last_slash_pos = 0;
for(;last_slash_pos < path.size; last_slash_pos = str8_find_needle(path, last_slash_pos+1, str8_lit("/"), StringMatchFlag_SlashInsensitive));
String8 path_trimmed = str8_prefix(path, last_slash_pos);
for(U64 off = 0; off < (U64)length;)
{
String16 next_drive_string_16 = str16_cstring((U16 *)buffer+off);
off += next_drive_string_16.size+1;
String8 next_drive_string = str8_from_16(scratch.arena, next_drive_string_16);
next_drive_string = str8_chop_last_slash(next_drive_string);
if(str8_match(path_trimmed, next_drive_string, StringMatchFlag_CaseInsensitive))
{
props.flags |= FilePropertyFlag_IsFolder;
break;
}
}
scratch_end(scratch);
}
FindClose(handle);
scratch_end(scratch);
return props;
+9 -1
View File
@@ -71,8 +71,10 @@ os_get_clipboard_text(Arena *arena)
//~ rjf: @os_hooks Windows (Implemented Per-OS)
internal OS_Handle
os_window_open(Vec2F32 resolution, OS_WindowFlags flags, String8 title)
os_window_open(Rng2F32 rect, OS_WindowFlags flags, String8 title)
{
Vec2F32 resolution = dim_2f32(rect);
//- rjf: allocate window
OS_LNX_Window *w = os_lnx_gfx_state->free_window;
if(w)
@@ -283,6 +285,12 @@ os_dim_from_monitor(OS_Handle monitor)
return v2f32(0, 0);
}
internal F32
os_dpi_from_monitor(OS_Handle monitor)
{
return 96.f;
}
////////////////////////////////
//~ rjf: @os_hooks Events (Implemented Per-OS)
+4 -2
View File
@@ -21,7 +21,8 @@ struct OS_GfxInfo
typedef U32 OS_WindowFlags;
enum
{
OS_WindowFlag_CustomBorder = (1<<0),
OS_WindowFlag_CustomBorder = (1<<0),
OS_WindowFlag_UseDefaultPosition = (1<<1),
};
////////////////////////////////
@@ -139,7 +140,7 @@ internal String8 os_get_clipboard_text(Arena *arena);
////////////////////////////////
//~ rjf: @os_hooks Windows (Implemented Per-OS)
internal OS_Handle os_window_open(Vec2F32 resolution, OS_WindowFlags flags, String8 title);
internal OS_Handle os_window_open(Rng2F32 rect, OS_WindowFlags flags, String8 title);
internal void os_window_close(OS_Handle window);
internal void os_window_first_paint(OS_Handle window);
internal void os_window_focus(OS_Handle window);
@@ -168,6 +169,7 @@ 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);
internal F32 os_dpi_from_monitor(OS_Handle monitor);
////////////////////////////////
//~ rjf: @os_hooks Events (Implemented Per-OS)
+7 -1
View File
@@ -34,7 +34,7 @@ os_get_clipboard_text(Arena *arena)
//~ rjf: @os_hooks Windows (Implemented Per-OS)
internal OS_Handle
os_window_open(Vec2F32 resolution, OS_WindowFlags flags, String8 title)
os_window_open(Rng2F32 rect, OS_WindowFlags flags, String8 title)
{
OS_Handle handle = {1};
return handle;
@@ -181,6 +181,12 @@ os_dim_from_monitor(OS_Handle monitor)
return v;
}
internal F32
os_dpi_from_monitor(OS_Handle monitor)
{
return 96.f;
}
////////////////////////////////
//~ rjf: @os_hooks Events (Implemented Per-OS)
+29 -6
View File
@@ -8,9 +8,11 @@
typedef BOOL w32_SetProcessDpiAwarenessContext_Type(void* value);
typedef UINT w32_GetDpiForWindow_Type(HWND hwnd);
typedef HRESULT w32_GetDpiForMonitor_Type(HMONITOR hmonitor, MONITOR_DPI_TYPE dpiType, UINT *dpiX, UINT *dpiY);
typedef int w32_GetSystemMetricsForDpi_Type(int nIndex, UINT dpi);
#define w32_DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 ((void*)-4)
global w32_GetDpiForWindow_Type *w32_GetDpiForWindow_func = 0;
global w32_GetDpiForMonitor_Type *w32_GetDpiForMonitor_func = 0;
global w32_GetSystemMetricsForDpi_Type *w32_GetSystemMetricsForDpi_func = 0;
////////////////////////////////
@@ -713,9 +715,10 @@ os_w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
// of the top hit area so manually checking that.
F32 dpi = w32_GetDpiForWindow_func ? (F32)w32_GetDpiForWindow_func(hwnd) : 96.f;
S32 frame_y = w32_GetSystemMetricsForDpi_func ? w32_GetSystemMetricsForDpi_func(SM_CYFRAME, dpi) : GetSystemMetrics(SM_CYFRAME);
S32 padding = w32_GetSystemMetricsForDpi_func ? w32_GetSystemMetricsForDpi_func(SM_CXPADDEDBORDER, dpi) : GetSystemMetrics(SM_CXPADDEDBORDER);
// NOTE(rjf): it seems incorrect to apply this padding here...
// S32 padding = w32_GetSystemMetricsForDpi_func ? w32_GetSystemMetricsForDpi_func(SM_CXPADDEDBORDER, dpi) : GetSystemMetrics(SM_CXPADDEDBORDER);
B32 is_over_top_resize = pos_client.y >= 0 && pos_client.y < frame_y + padding;
B32 is_over_top_resize = pos_client.y >= 0 && pos_client.y < frame_y; // + padding;
B32 is_over_title_bar = pos_client.y >= 0 && pos_client.y < window->custom_border_title_thickness;
//- rjf: check against title bar client areas
@@ -811,6 +814,7 @@ os_gfx_init(void)
(w32_SetProcessDpiAwarenessContext_Type*)GetProcAddress(module, "SetProcessDpiAwarenessContext");
w32_GetDpiForWindow_func =
(w32_GetDpiForWindow_Type*)GetProcAddress(module, "GetDpiForWindow");
w32_GetDpiForMonitor_func = (w32_GetDpiForMonitor_Type *)GetProcAddress(module, "GetDpiForMonitor");
w32_GetSystemMetricsForDpi_func = (w32_GetSystemMetricsForDpi_Type *)GetProcAddress(module, "GetSystemMetricsForDpi");
FreeLibrary(module);
}
@@ -1011,9 +1015,12 @@ os_get_clipboard_text(Arena *arena)
//~ rjf: @os_hooks Windows (Implemented Per-OS)
internal OS_Handle
os_window_open(Vec2F32 resolution, OS_WindowFlags flags, String8 title)
os_window_open(Rng2F32 rect, OS_WindowFlags flags, String8 title)
{
B32 custom_border = !!(flags & OS_WindowFlag_CustomBorder);
B32 use_default_position = !!(flags & OS_WindowFlag_UseDefaultPosition);
Vec2F32 pos = rect.p0;
Vec2F32 dim = dim_2f32(rect);
//- rjf: make hwnd
HWND hwnd = 0;
@@ -1025,9 +1032,10 @@ os_window_open(Vec2F32 resolution, OS_WindowFlags flags, String8 title)
L"graphical-window",
(WCHAR*)title16.str,
WS_OVERLAPPEDWINDOW | WS_SIZEBOX,
CW_USEDEFAULT, CW_USEDEFAULT,
(int)resolution.x,
(int)resolution.y,
use_default_position ? CW_USEDEFAULT : (S32)pos.x,
use_default_position ? CW_USEDEFAULT : (S32)pos.y,
(S32)dim.x,
(S32)dim.y,
0, 0,
os_w32_gfx_state->hInstance,
0);
@@ -1385,6 +1393,21 @@ os_dim_from_monitor(OS_Handle monitor)
return result;
}
internal F32
os_dpi_from_monitor(OS_Handle monitor)
{
F32 result = 96.f;
HMONITOR monitor_handle = (HMONITOR)monitor.u64[0];
if(w32_GetDpiForMonitor_func != 0)
{
UINT dpi_x = 0;
UINT dpi_y = 0;
HRESULT hr = w32_GetDpiForMonitor_func(monitor_handle, MDT_EFFECTIVE_DPI, &dpi_x, &dpi_y);
result = (F32)dpi_x;
}
return result;
}
////////////////////////////////
//~ rjf: @os_hooks Events (Implemented Per-OS)