Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ add_example(core_vsync_fullscreen)
add_example(core_msaa)
if(SUPPORT_SDL3 AND SUPPORT_GLFW AND SUPPORT_RGFW)
add_example(core_multiwindow_multiplatform)
add_example(core_windowtitle)
endif()
add_example(textures_generate)
add_example(core_camera2d)
Expand Down
70 changes: 70 additions & 0 deletions examples/core_windowtitle.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Test for SetWindowTitle and SetSubWindowTitle functions

#include <raygpu.h>
#include <stdio.h>

void DrawToWindow(SubWindow window, const char* text, int windowWidth, Color bgColor, Color textColor) {
if (window == NULL) {
BeginDrawing();
} else {
BeginWindowMode(window);
}

ClearBackground(bgColor);
int textWidth = MeasureText(text, 30);
DrawText(text, (windowWidth - textWidth) / 2, 180, 30, textColor);

if (window == NULL) {
EndDrawing();
} else {
EndWindowMode();
}
}

void UpdateWindowTitle(SubWindow window, const char* libraryName, int seconds) {
char titleBuffer[256];
snprintf(titleBuffer, sizeof(titleBuffer), "%s - %d", libraryName, seconds);

if (window == NULL) {
SetWindowTitle(titleBuffer);
} else {
SetSubWindowTitle(window, titleBuffer);
}
}

int main(void) {
// Initialize main window with resizable flag
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
InitWindow(800, 600, "Main Window");

// Create platform-specific sub-windows
SubWindow glfwWindow = OpenSubWindow_GLFW(600, 400, "GLFW");
SubWindow rgfwWindow = OpenSubWindow_RGFW(600, 400, "RGFW");
SubWindow sdl3Window = OpenSubWindow_SDL3(600, 400, "SDL3");

double lastUpdateTime = 0.0;

while (!WindowShouldClose()) {
double currentTime = GetTime();

// Update titles every second
if (currentTime - lastUpdateTime >= 1.0) {
lastUpdateTime = currentTime;
int seconds = (int)currentTime;

// Update all window titles
UpdateWindowTitle(NULL, "Main", seconds);
UpdateWindowTitle(glfwWindow, "GLFW", seconds);
UpdateWindowTitle(rgfwWindow, "RGFW", seconds);
UpdateWindowTitle(sdl3Window, "SDL3", seconds);
}

// Draw on all windows
DrawToWindow(NULL, "Main Window", 800, RAYWHITE, DARKGRAY);
DrawToWindow(glfwWindow, "GLFW Window", 600, SKYBLUE, DARKBLUE);
DrawToWindow(rgfwWindow, "RGFW Window", 600, LIME, DARKGREEN);
DrawToWindow(sdl3Window, "SDL3 Window", 600, ORANGE, RED);
}

return 0;
}
2 changes: 2 additions & 0 deletions include/raygpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -1357,6 +1357,8 @@ RGAPI void requestAnimationFrameLoopWithJSPIArg(void (*callback)(void*), void* u
RGAPI void SetWindowShouldClose(cwoid);
RGAPI void CloseProgram(cwoid);
RGAPI bool WindowShouldClose(cwoid);
RGAPI void SetWindowTitle(const char* title);
RGAPI void SetSubWindowTitle(SubWindow window, const char* title);
RGAPI SubWindow OpenSubWindow (int width, int height, const char* title);
RGAPI SubWindow OpenSubWindow_SDL3(int width, int height, const char* title);
RGAPI SubWindow OpenSubWindow_GLFW(int width, int height, const char* title);
Expand Down
37 changes: 36 additions & 1 deletion src/InitWindow.c
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,15 @@ RGAPI void CloseSubWindow(SubWindow window) {
CreatedWindowMap_erase(&g_renderstate.createdSubwindows, nativeHandle);
}

void SetWindowTitle(const char* title){
void* handle = GetActiveWindowHandle();
if(handle == NULL){
TRACELOG(LOG_WARNING, "SetWindowTitle: No active window");
return;
}
SetSubWindowTitle(CreatedWindowMap_get(&g_renderstate.createdSubwindows, handle), title);
}



size_t GetPixelSizeInBytes(PixelFormat format) {
Expand Down Expand Up @@ -688,7 +697,33 @@ size_t GetPixelSizeInBytes(PixelFormat format) {
#endif



void SetSubWindowTitle(SubWindow window, const char* title){
if(window == NULL || window->handle == NULL){
TRACELOG(LOG_WARNING, "SetSubWindowTitle: Invalid window");
return;
}

switch(window->type){
#if SUPPORT_GLFW == 1
case windowType_glfw:
glfwSetWindowTitle((GLFWwindow*)window->handle, title);
break;
#endif
#if SUPPORT_SDL3 == 1
case windowType_sdl3:
SDL_SetWindowTitle((SDL_Window*)window->handle, title);
break;
#endif
#if SUPPORT_RGFW == 1
case windowType_rgfw:
RGFW_window_setName((RGFW_window*)window->handle, (char*)title);
break;
#endif
default:
TRACELOG(LOG_WARNING, "SetSubWindowTitle: Unsupported window type");
break;
}
}


// end file src/InitWindow.c
3 changes: 3 additions & 0 deletions src/platform/InitWindow_GLFW.c
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,9 @@ bool WindowShouldClose_GLFW(GLFWwindow* win){
return glfwWindowShouldClose(win);
}

void SetWindowTitle_GLFW(GLFWwindow* window, const char* title) {
glfwSetWindowTitle(window, title);
}

int emscripten_to_glfw_key(const char *key_name) {
if (!key_name) return GLFW_KEY_UNKNOWN;
Expand Down
4 changes: 4 additions & 0 deletions src/platform/InitWindow_RGFW.c
Original file line number Diff line number Diff line change
Expand Up @@ -427,4 +427,8 @@ void DisableCursor_RGFW(void* window) {
HideCursor_RGFW((RGFW_window*)window);
}

void SetWindowTitle_RGFW(RGFW_window* window, const char* title) {
RGFW_window_setName(window, (char*)title);
}

// end file src/InitWindow_RGFW.cpp
4 changes: 4 additions & 0 deletions src/platform/InitWindow_SDL3.c
Original file line number Diff line number Diff line change
Expand Up @@ -696,4 +696,8 @@ float GetGamepadAxisMovement_SDL3(int gamepad, int axis) {
return g_renderstate.mainWindow->input_state.gamepads[gamepad].axis[axis];
}

void SetWindowTitle_SDL3(SDL_Window* window, const char* title) {
SDL_SetWindowTitle(window, title);
}

// end file src/InitWindow_SDL3.c