Skip to content

Commit af0cba6

Browse files
committed
Add core_windowtitle example as a test
1 parent 786f81d commit af0cba6

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

examples/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ add_example(core_vsync_fullscreen)
5858
add_example(core_msaa)
5959
if(SUPPORT_SDL3 AND SUPPORT_GLFW AND SUPPORT_RGFW)
6060
add_example(core_multiwindow_multiplatform)
61+
add_example(core_windowtitle)
6162
endif()
6263
add_example(textures_generate)
6364
add_example(core_camera2d)

examples/core_windowtitle.c

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Test for SetWindowTitle and SetSubWindowTitle functions
2+
3+
#include <raygpu.h>
4+
#include <stdio.h>
5+
6+
void DrawToWindow(SubWindow window, const char* text, int windowWidth, Color bgColor, Color textColor) {
7+
if (window == NULL) {
8+
BeginDrawing();
9+
} else {
10+
BeginWindowMode(window);
11+
}
12+
13+
ClearBackground(bgColor);
14+
int textWidth = MeasureText(text, 30);
15+
DrawText(text, (windowWidth - textWidth) / 2, 180, 30, textColor);
16+
17+
if (window == NULL) {
18+
EndDrawing();
19+
} else {
20+
EndWindowMode();
21+
}
22+
}
23+
24+
void UpdateWindowTitle(SubWindow window, const char* libraryName, int seconds) {
25+
char titleBuffer[256];
26+
snprintf(titleBuffer, sizeof(titleBuffer), "%s - %d", libraryName, seconds);
27+
28+
if (window == NULL) {
29+
SetWindowTitle(titleBuffer);
30+
} else {
31+
SetSubWindowTitle(window, titleBuffer);
32+
}
33+
}
34+
35+
int main(void) {
36+
// Initialize main window with resizable flag
37+
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
38+
InitWindow(800, 600, "Main Window");
39+
40+
// Create platform-specific sub-windows
41+
SubWindow glfwWindow = OpenSubWindow_GLFW(600, 400, "GLFW");
42+
SubWindow rgfwWindow = OpenSubWindow_RGFW(600, 400, "RGFW");
43+
SubWindow sdl3Window = OpenSubWindow_SDL3(600, 400, "SDL3");
44+
45+
double lastUpdateTime = 0.0;
46+
47+
while (!WindowShouldClose()) {
48+
double currentTime = GetTime();
49+
50+
// Update titles every second
51+
if (currentTime - lastUpdateTime >= 1.0) {
52+
lastUpdateTime = currentTime;
53+
int seconds = (int)currentTime;
54+
55+
// Update all window titles
56+
UpdateWindowTitle(NULL, "Main", seconds);
57+
UpdateWindowTitle(glfwWindow, "GLFW", seconds);
58+
UpdateWindowTitle(rgfwWindow, "RGFW", seconds);
59+
UpdateWindowTitle(sdl3Window, "SDL3", seconds);
60+
}
61+
62+
// Draw on all windows
63+
DrawToWindow(NULL, "Main Window", 800, RAYWHITE, DARKGRAY);
64+
DrawToWindow(glfwWindow, "GLFW Window", 600, SKYBLUE, DARKBLUE);
65+
DrawToWindow(rgfwWindow, "RGFW Window", 600, LIME, DARKGREEN);
66+
DrawToWindow(sdl3Window, "SDL3 Window", 600, ORANGE, RED);
67+
}
68+
69+
return 0;
70+
}

0 commit comments

Comments
 (0)