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
|
package showimage
|
||||||
|
|
||||||
import "core:os"
|
import "core:os"
|
||||||
import s "core:strings"
|
import "core:strings"
|
||||||
import rl "vendor:raylib"
|
import rl "vendor:raylib"
|
||||||
|
|
||||||
path: string
|
|
||||||
tex: ^rl.Texture
|
tex: ^rl.Texture
|
||||||
zoom: f32 = 1
|
zoom: f32 = 1
|
||||||
offset: [2]f32
|
offset: [2]f32
|
||||||
|
|
||||||
main :: proc() {
|
main :: proc() {
|
||||||
config: rl.ConfigFlags = { .WINDOW_RESIZABLE }
|
|
||||||
rl.InitWindow(800, 600, "showimage")
|
rl.InitWindow(800, 600, "showimage")
|
||||||
rl.SetWindowState(config)
|
rl.SetWindowState({ .WINDOW_RESIZABLE })
|
||||||
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
if len(os.args) > 1 {
|
if len(os.args) > 1 {
|
||||||
path = os.args[1]
|
path := strings.clone_to_cstring(os.args[1])
|
||||||
t := rl.LoadTexture(s.clone_to_cstring(path))
|
tex = new_clone(rl.LoadTexture(path))
|
||||||
tex = &t
|
|
||||||
reset_zoom()
|
reset_zoom()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,20 +43,17 @@ main :: proc() {
|
||||||
rl.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
||||||
reset_zoom :: proc() {
|
zoom_to_power :: proc(size: i32, max: i32) -> i32 {
|
||||||
screen_width := rl.GetRenderWidth()
|
fit: i32 = 1
|
||||||
fit_x: i32 = 1
|
for fit * size < max {
|
||||||
for fit_x * tex.width < screen_width {
|
fit *= 2
|
||||||
fit_x *= 2
|
|
||||||
}
|
}
|
||||||
fit_x /= 2
|
return fit / 2
|
||||||
|
}
|
||||||
screen_height := rl.GetRenderHeight()
|
|
||||||
fit_y: i32 = 1
|
reset_zoom :: proc() {
|
||||||
for fit_y * tex.height < screen_height {
|
zoom = f32(min(
|
||||||
fit_y *= 2
|
zoom_to_power(tex.width, rl.GetRenderWidth()),
|
||||||
}
|
zoom_to_power(tex.height, rl.GetRenderHeight()),
|
||||||
fit_y /= 2
|
))
|
||||||
|
|
||||||
zoom = f32(min(fit_x, fit_y))
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue