gg: fix draw_image on macos native; vcreate: vweb template

This commit is contained in:
Alexander Medvednikov 2022-12-21 19:33:19 +03:00
parent ccbb8ab0ca
commit 88e33a83de
7 changed files with 128 additions and 24 deletions

View file

@ -109,23 +109,6 @@ pub fn (mut img Image) init_sokol_image() &Image {
// draw_image draws the provided image onto the screen.
pub fn (ctx &Context) draw_image(x f32, y f32, width f32, height f32, img_ &Image) {
$if macos {
if img_.id >= ctx.image_cache.len {
eprintln('gg: draw_image() bad img id ${img_.id} (img cache len = ${ctx.image_cache.len})')
return
}
if ctx.native_rendering {
if img_.width == 0 {
return
}
if !os.exists(img_.path) {
return
}
C.darwin_draw_image(x, ctx.height - (y + height), width, height, img_)
return
}
}
ctx.draw_image_with_config(
img: img_
img_rect: Rect{x, y, width, height}
@ -273,6 +256,41 @@ pub struct StreamingImageConfig {
// draw_image_with_config takes in a config that details how the
// provided image should be drawn onto the screen
pub fn (ctx &Context) draw_image_with_config(config DrawImageConfig) {
$if macos {
unsafe {
mut img := config.img
if config.img == nil {
// Get image by id
if config.img_id > 0 {
img = &ctx.image_cache[config.img_id]
} else {
eprintln('gg: failed to get image to draw natively')
return
}
}
if img.id >= ctx.image_cache.len {
eprintln('gg: draw_image() bad img id ${img.id} (img cache len = ${ctx.image_cache.len})')
return
}
if ctx.native_rendering {
if img.width == 0 {
println('w=0')
return
}
if !os.exists(img.path) {
println('not exist path')
return
}
x := config.img_rect.x
y := config.img_rect.y
C.darwin_draw_image(x, ctx.height - (y + config.img_rect.height), config.img_rect.width,
config.img_rect.height, img)
println('ok')
return
}
}
}
id := if !isnil(config.img) { config.img.id } else { config.img_id }
if id >= ctx.image_cache.len {
eprintln('gg: draw_image() bad img id ${id} (img cache len = ${ctx.image_cache.len})')