Created
November 29, 2024 21:24
-
-
Save nahuakang/735f7f1267e69a24006a0230c59b86be to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package msms | |
import "core:c" | |
import "core:fmt" | |
import rl "vendor:raylib" | |
TARGET_FPS :: 60 | |
TARGET_SCREEN_WIDTH: c.int = 1270 | |
TARGET_SCREEN_HEIGHT: c.int = 720 | |
get_display_width :: proc() -> c.int { | |
if rl.IsWindowFullscreen() { | |
monitor := rl.GetCurrentMonitor() | |
return rl.GetMonitorWidth(monitor) | |
} | |
return rl.GetScreenWidth() | |
} | |
get_display_height :: proc() -> c.int { | |
if rl.IsWindowFullscreen() { | |
monitor := rl.GetCurrentMonitor() | |
return rl.GetMonitorHeight(monitor) | |
} | |
return rl.GetScreenHeight() | |
} | |
toggle_fullscreen :: proc(w: c.int, h: c.int) { | |
if !rl.IsWindowFullscreen() { | |
monitor := rl.GetCurrentMonitor() | |
rl.SetWindowSize(rl.GetMonitorWidth(monitor), rl.GetMonitorHeight(monitor)) | |
rl.ToggleFullscreen() | |
} else { | |
rl.ToggleFullscreen() | |
rl.SetWindowSize(w, h) | |
} | |
} | |
main :: proc() { | |
rl.SetConfigFlags({.WINDOW_RESIZABLE}) // Set before rl.InitWindow | |
rl.InitWindow(TARGET_SCREEN_WIDTH, TARGET_SCREEN_HEIGHT, "Quit Window") | |
rl.InitAudioDevice() | |
rl.SetTargetFPS(TARGET_FPS) | |
office_texture := rl.LoadTexture("assets/graphics/office.png") | |
show := false | |
for !rl.WindowShouldClose() { | |
if rl.IsKeyPressed(.SPACE) { | |
toggle_fullscreen(TARGET_SCREEN_WIDTH, TARGET_SCREEN_HEIGHT) | |
} | |
scale: f32 = max( | |
f32(get_display_width()) / f32(office_texture.width), | |
f32(get_display_height()) / f32(office_texture.height), | |
) | |
camera := rl.Camera2D { | |
offset = {f32(get_display_width()) / 2.0, f32(get_display_height()) / 2.0}, | |
target = {f32(office_texture.width) / 2.0, f32(office_texture.height) / 2.0}, | |
zoom = scale, | |
} | |
rl.BeginDrawing() | |
rl.ClearBackground(rl.RAYWHITE) | |
rl.BeginMode2D(camera) | |
rl.DrawTextureV(office_texture, {0, 0}, rl.WHITE) | |
rl.EndMode2D() | |
if (rl.GuiButton(rl.Rectangle{24, 24, 120, 30}, "#191#Show Message")) { | |
show = true | |
} | |
if (show) { | |
result := rl.GuiMessageBox( | |
rl.Rectangle{85, 70, 250, 100}, | |
"#191#Message Box", | |
"Hi! This is a message!", | |
"Nice;Cool", | |
) | |
if (result >= 0) { | |
show = false | |
} | |
} | |
rl.EndDrawing() | |
free_all(context.temp_allocator) | |
} | |
rl.CloseAudioDevice() | |
rl.CloseWindow() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment