cleanup
This commit is contained in:
parent
e0dc2bd1ac
commit
3042fcb8cd
1 changed files with 18 additions and 23 deletions
|
@ -1,23 +1,21 @@
|
|||
package showimage
|
||||
|
||||
import "core:os"
|
||||
import s "core:strings"
|
||||
import "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)
|
||||
rl.SetWindowState({ .WINDOW_RESIZABLE })
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
if len(os.args) > 1 {
|
||||
path = os.args[1]
|
||||
t := rl.LoadTexture(s.clone_to_cstring(path))
|
||||
tex = &t
|
||||
path := strings.clone_to_cstring(os.args[1])
|
||||
tex = new_clone(rl.LoadTexture(path))
|
||||
reset_zoom()
|
||||
}
|
||||
|
||||
|
@ -45,20 +43,17 @@ main :: proc() {
|
|||
rl.CloseWindow()
|
||||
}
|
||||
|
||||
zoom_to_power :: proc(size: i32, max: i32) -> i32 {
|
||||
fit: i32 = 1
|
||||
for fit * size < max {
|
||||
fit *= 2
|
||||
}
|
||||
return fit / 2
|
||||
}
|
||||
|
||||
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))
|
||||
}
|
||||
zoom = f32(min(
|
||||
zoom_to_power(tex.width, rl.GetRenderWidth()),
|
||||
zoom_to_power(tex.height, rl.GetRenderHeight()),
|
||||
))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue