Skip to content

Commit

Permalink
[Wrapper] Added UTF-8 version of Set/GetWindowTitle functions to wrap…
Browse files Browse the repository at this point in the history
…pers.

This adds llglSetWindowTitleUTF8() and llglGetWindowTitleUTF8() as alternative to the wide-character version.
  • Loading branch information
LukasBanana committed Jun 2, 2024
1 parent f2b153b commit 3874cde
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/LLGL-C/Window.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ LLGL_C_EXPORT void llglGetWindowPosition(LLGLWindow window, LLGLOffset2D* outPos
LLGL_C_EXPORT void llglSetWindowSize(LLGLWindow window, const LLGLExtent2D* size, bool useClientArea);
LLGL_C_EXPORT void llglGetWindowSize(LLGLWindow window, LLGLExtent2D* outSize, bool useClientArea);
LLGL_C_EXPORT void llglSetWindowTitle(LLGLWindow window, const wchar_t* title);
LLGL_C_EXPORT void llglSetWindowTitleUTF8(LLGLWindow window, const char* title);
LLGL_C_EXPORT size_t llglGetWindowTitle(LLGLWindow window, size_t outTitleLength, wchar_t* outTitle LLGL_ANNOTATE(NULL));
LLGL_C_EXPORT size_t llglGetWindowTitleUTF8(LLGLWindow window, size_t outTitleLength, char* outTitle LLGL_ANNOTATE(NULL));
LLGL_C_EXPORT void llglShowWindow(LLGLWindow window, bool show);
LLGL_C_EXPORT bool llglIsWindowShown(LLGLWindow window);
LLGL_C_EXPORT void llglSetWindowDesc(LLGLWindow window, const LLGLWindowDescriptor* windowDesc);
Expand Down
16 changes: 16 additions & 0 deletions wrapper/C99/C99Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ LLGL_C_EXPORT void llglSetWindowTitle(LLGLWindow window, const wchar_t* title)
LLGL_PTR(Window, window)->SetTitle(title);
}

LLGL_C_EXPORT void llglSetWindowTitleUTF8(LLGLWindow window, const char* title)
{
LLGL_PTR(Window, window)->SetTitle(title);
}

LLGL_C_EXPORT size_t llglGetWindowTitle(LLGLWindow window, size_t outTitleLength, wchar_t* outTitle)
{
UTF8String title = LLGL_PTR(Window, window)->GetTitle();
Expand All @@ -227,6 +232,17 @@ LLGL_C_EXPORT size_t llglGetWindowTitle(LLGLWindow window, size_t outTitleLength
return titleUTF16.size();
}

LLGL_C_EXPORT size_t llglGetWindowTitleUTF8(LLGLWindow window, size_t outTitleLength, char* outTitle)
{
UTF8String title = LLGL_PTR(Window, window)->GetTitle();
if (outTitle != nullptr)
{
outTitleLength = std::min(outTitleLength, title.size() + 1);
::memcpy(outTitle, title.data(), outTitleLength * sizeof(char));
}
return title.size() + 1;
}

LLGL_C_EXPORT void llglShowWindow(LLGLWindow window, bool show)
{
LLGL_PTR(Window, window)->Show(show);
Expand Down
6 changes: 6 additions & 0 deletions wrapper/CSharp/LLGLWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4818,9 +4818,15 @@ public unsafe struct ShaderReflection
[DllImport(DllName, EntryPoint="llglSetWindowTitle", CallingConvention=CallingConvention.Cdecl)]
public static extern unsafe void SetWindowTitle(Window window, [MarshalAs(UnmanagedType.LPWStr)] string title);

[DllImport(DllName, EntryPoint="llglSetWindowTitleUTF8", CallingConvention=CallingConvention.Cdecl)]
public static extern unsafe void SetWindowTitleUTF8(Window window, [MarshalAs(UnmanagedType.LPStr)] string title);

[DllImport(DllName, EntryPoint="llglGetWindowTitle", CallingConvention=CallingConvention.Cdecl)]
public static extern unsafe IntPtr GetWindowTitle(Window window, IntPtr outTitleLength, char* outTitle);

[DllImport(DllName, EntryPoint="llglGetWindowTitleUTF8", CallingConvention=CallingConvention.Cdecl)]
public static extern unsafe IntPtr GetWindowTitleUTF8(Window window, IntPtr outTitleLength, byte* outTitle);

[DllImport(DllName, EntryPoint="llglShowWindow", CallingConvention=CallingConvention.Cdecl)]
public static extern unsafe void ShowWindow(Window window, [MarshalAs(UnmanagedType.I1)] bool show);

Expand Down

0 comments on commit 3874cde

Please sign in to comment.