Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

gg: Android specific asset load in create_image function #19015

Merged
merged 2 commits into from
Jul 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 14 additions & 3 deletions vlib/gg/image.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,25 @@ pub mut:
}

// create_image creates an `Image` from `file`.
pub fn (ctx &Context) create_image(file string) !Image {
// println('\ncreate_image("$file")')
pub fn (mut ctx Context) create_image(file string) !Image {
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 ctx.native_rendering {
// return C.darwin_create_image(file)
mut img := C.darwin_create_image(file)

// println('created macos image: $img.path w=$img.width')
// C.printf('p = %p\n', img.data)
img.id = ctx.image_cache.len
Expand All @@ -43,6 +53,7 @@ pub fn (ctx &Context) create_image(file string) !Image {
return img
}
}

if !gfx.is_valid() {
// Sokol is not initialized yet, add stbi object to a queue/cache
// ctx.image_queue << file
Expand Down