1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

gg: implement Android specific APK asset loading for the create_image function (#19015)

This commit is contained in:
Artem Yurchenko 2023-07-31 16:40:16 +02:00 committed by GitHub
parent 9750061d70
commit 0f861db9b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -25,15 +25,25 @@ pub mut:
} }
// create_image creates an `Image` from `file`. // create_image creates an `Image` from `file`.
pub fn (ctx &Context) create_image(file string) !Image { pub fn (mut ctx Context) create_image(file string) !Image {
// println('\ncreate_image("$file")')
if !os.exists(file) { if !os.exists(file) {
return error('image file "${file}" not found') $if android {
image_data := os.read_apk_asset(file)!
mut image := ctx.create_image_from_byte_array(image_data)!
image.path = file
return image
} $else {
return error('image file "${file}" not found')
}
} }
$if macos { $if macos {
if ctx.native_rendering { if ctx.native_rendering {
// return C.darwin_create_image(file) // return C.darwin_create_image(file)
mut img := C.darwin_create_image(file) mut img := C.darwin_create_image(file)
// println('created macos image: $img.path w=$img.width') // println('created macos image: $img.path w=$img.width')
// C.printf('p = %p\n', img.data) // C.printf('p = %p\n', img.data)
img.id = ctx.image_cache.len img.id = ctx.image_cache.len
@ -43,6 +53,7 @@ pub fn (ctx &Context) create_image(file string) !Image {
return img return img
} }
} }
if !gfx.is_valid() { if !gfx.is_valid() {
// Sokol is not initialized yet, add stbi object to a queue/cache // Sokol is not initialized yet, add stbi object to a queue/cache
// ctx.image_queue << file // ctx.image_queue << file