init
This commit is contained in:
commit
e0dc2bd1ac
3 changed files with 67 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
showimage
|
2
Makefile
Normal file
2
Makefile
Normal file
|
@ -0,0 +1,2 @@
|
|||
b:
|
||||
odin build showimage.odin -file
|
64
showimage.odin
Normal file
64
showimage.odin
Normal file
|
@ -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))
|
||||
}
|
Loading…
Reference in a new issue