commit e0dc2bd1acacc1d94108f838df7d2e5beb977005 Author: CrispyPin Date: Fri Oct 25 17:18:45 2024 +0200 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c89fbcd --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +showimage diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9faab64 --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +b: + odin build showimage.odin -file diff --git a/showimage.odin b/showimage.odin new file mode 100644 index 0000000..4c284b1 --- /dev/null +++ b/showimage.odin @@ -0,0 +1,64 @@ +package showimage + +import "core:os" +import s "core:strings" +import rl "vendor:raylib" + +path: string +tex: ^rl.Texture +zoom: f32 = 1 +offset: [2]f32 + +main :: proc() { + config: rl.ConfigFlags = { .WINDOW_RESIZABLE } + rl.InitWindow(800, 600, "showimage") + rl.SetWindowState(config) + + if len(os.args) > 1 { + path = os.args[1] + t := rl.LoadTexture(s.clone_to_cstring(path)) + tex = &t + reset_zoom() + } + + for !rl.WindowShouldClose() { + scroll := rl.GetMouseWheelMove() + if scroll > 0 { + zoom *= 2 + } else if scroll < 0 { + zoom /= 2 + } + if rl.IsMouseButtonDown(rl.MouseButton.LEFT) { + offset += rl.GetMouseDelta() + } + if rl.IsMouseButtonPressed(rl.MouseButton.RIGHT) { + offset = 0 + reset_zoom() + } + rl.BeginDrawing() + rl.ClearBackground({50, 50, 50, 255}) + if tex != nil { + rl.DrawTextureEx(tex^, offset, 0, zoom, rl.WHITE) + } + rl.EndDrawing() + } + rl.CloseWindow() +} + +reset_zoom :: proc() { + screen_width := rl.GetRenderWidth() + fit_x: i32 = 1 + for fit_x * tex.width < screen_width { + fit_x *= 2 + } + fit_x /= 2 + + screen_height := rl.GetRenderHeight() + fit_y: i32 = 1 + for fit_y * tex.height < screen_height { + fit_y *= 2 + } + fit_y /= 2 + + zoom = f32(min(fit_x, fit_y)) +} \ No newline at end of file