# Conflicts:
#	code/win32_main.cpp
main
sixten.hugosson 2023-06-18 16:49:51 +02:00
commit d70b6db7af
5 changed files with 993 additions and 938 deletions

View File

@ -113,10 +113,10 @@ static glyph_atlas *CreateGlyphAtlas(vn_render_commands *RenderCommands,
Atlas->RenderCommands = RenderCommands;
Atlas->Texture = RenderCommands->AllocateTexture(V2S(BitmapSize, BitmapSize), Render_TextureFormat_R8, 0);
Atlas->Fonts[Font_Regular].Data = Platform_ReadEntireFile(&Atlas->Arena, StrLit("../fonts/Roboto-Regular.ttf"));
Atlas->Fonts[Font_Bold].Data = Platform_ReadEntireFile(&Atlas->Arena, StrLit("../fonts/Roboto-Bold.ttf"));
Atlas->Fonts[Font_Monospace].Data = Platform_ReadEntireFile(&Atlas->Arena, StrLit("../fonts/Liberation-Mono.ttf"));
Atlas->Fonts[Font_Icons].Data = Platform_ReadEntireFile(&Atlas->Arena, StrLit("../fonts/icons.ttf"));
Atlas->Fonts[Font_Regular].Data = Platform_ReadEntireFile(&Atlas->Arena, StrLit("fonts/Roboto-Regular.ttf"));
Atlas->Fonts[Font_Bold].Data = Platform_ReadEntireFile(&Atlas->Arena, StrLit("fonts/Roboto-Bold.ttf"));
Atlas->Fonts[Font_Monospace].Data = Platform_ReadEntireFile(&Atlas->Arena, StrLit("fonts/Liberation-Mono.ttf"));
Atlas->Fonts[Font_Icons].Data = Platform_ReadEntireFile(&Atlas->Arena, StrLit("fonts/icons.ttf"));
for(s32 FontIndex = 0;
FontIndex < Font_Count;

View File

@ -44,6 +44,28 @@ inline string MakeStringFromCString(char *Data)
return(Result);
}
inline b32 AreEqual(string A, string B)
{
b32 Result = false;
if(A.Count == B.Count)
{
Result = true;
for(s64 Index = 0;
Index < A.Count;
++Index)
{
if(A.Data[Index] != B.Data[Index])
{
Result = false;
break;
}
}
}
return(Result);
}
inline s64 FirstIndexOf(string String, char Char)
{
s64 Result = -1;
@ -76,25 +98,23 @@ inline s64 LastIndexOf(string String, char Char)
return(Result);
}
inline b32 AreEqual(string A, string B)
inline s64 LastIndexOf(string String, string Substring)
{
b32 Result = false;
if(A.Count == B.Count)
s64 Result = -1;
if(String.Count >= Substring.Count)
{
Result = true;
for(s64 Index = 0;
Index < A.Count;
++Index)
for(s64 Index = String.Count-Substring.Count;
Index >= 0;
--Index)
{
if(A.Data[Index] != B.Data[Index])
string ToCheck = MakeString((char *)String.Data + Index, Substring.Count);
if(AreEqual(ToCheck, Substring))
{
Result = false;
Result = Index;
break;
}
}
}
return(Result);
}

View File

@ -84,9 +84,12 @@ static PLATFORM_OPEN_FILE(Win32_OpenFile)
CreationAttributes = OPEN_EXISTING;
}
string FullPath = Path;
temporary_memory Scratch = GetScratch(0, 0);
HANDLE File = CreateFileA((char *)Path.Data, DesiredAccess, 0, 0, CreationAttributes, 0, 0);
string FullPath = PushFormat(Scratch.Arena, "%S\\%S", Global_Win32State.ContentsPath, Path);
HANDLE File = CreateFileA((char *)FullPath.Data, DesiredAccess, 0, 0, CreationAttributes, 0, 0);
ReleaseScratch(Scratch);
platform_file_handle Result = {};
Result.Platform = (u64)File;
@ -225,6 +228,11 @@ static PLATFORM_TOGGLE_FULLSCREEN(Win32_ToggleFullscreen)
DWORD Style = GetWindowLong(Window, GWL_STYLE);
if(Style & WS_OVERLAPPEDWINDOW)
{
MONITORINFO MonitorInfo = {sizeof(MonitorInfo)};
if(GetWindowPlacement(Window, &Global_WindowPosition) &&
GetMonitorInfo(MonitorFromWindow(Window, MONITOR_DEFAULTTOPRIMARY), &MonitorInfo))
{
<<<<<<< HEAD
MONITORINFO MonitorInfo = {sizeof(MonitorInfo)};
if(GetWindowPlacement(Window, &Global_WindowPosition) &&
GetMonitorInfo(MonitorFromWindow(Window, MONITOR_DEFAULTTOPRIMARY), &MonitorInfo))
@ -245,6 +253,20 @@ static PLATFORM_TOGGLE_FULLSCREEN(Win32_ToggleFullscreen)
SetWindowPlacement(Window, &Global_WindowPosition);
SetWindowPos(Window, 0, 0, 0, 0, 0,
SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_NOOWNERZORDER|SWP_FRAMECHANGED);
=======
SetWindowPos(Window, HWND_TOP,
MonitorInfo.rcMonitor.left, MonitorInfo.rcMonitor.top,
MonitorInfo.rcMonitor.right - MonitorInfo.rcMonitor.left,
MonitorInfo.rcMonitor.bottom - MonitorInfo.rcMonitor.top,
SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
>>>>>>> 376349b92227dcf5369dee77701a9ad8570ab639
}
}
else
{
SetWindowPlacement(Window, &Global_WindowPosition);
SetWindowPos(Window, 0, 0, 0, 0, 0,
SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_NOOWNERZORDER|SWP_FRAMECHANGED);
}
}
@ -561,7 +583,19 @@ inline void Win32_GetRelevantPaths(win32_state *State)
Win32_PlatformError("Path to executable is too long. Try running the game from another directory", true);
}
s64 OnePastLastSlash = LastIndexOf(MakeStringFromCString(State->EXEPath), '\\') + 1;
string EXEPathString = MakeStringFromCString(State->EXEPath);
s64 OnePastLastSlash = LastIndexOf(EXEPathString, '\\') + 1;
s64 BuildIndex = LastIndexOf(EXEPathString, StrLit("build"));
if(BuildIndex == -1)
{
State->ContentsPath = MakeString((char *)EXEPathString.Data, OnePastLastSlash);
}
else
{
State->ContentsPath = MakeString((char *)EXEPathString.Data, BuildIndex);
}
string DLLName = StrLit("vn.dll");
Copy(State->DLLPath, State->EXEPath, OnePastLastSlash);

View File

@ -30,6 +30,7 @@ struct win32_state
char EXEPath[512];
char DLLPath[512];
char TempDLLPath[512];
string ContentsPath;
platform_cursor Cursor;
};