GBitmap *simply_res_add_image(SimplyRes *self, uint32_t id, int16_t width, int16_t height, uint32_t *pixels) { SimplyImage *image = (SimplyImage*) list1_find(self->images, id_filter, (void*)(uintptr_t) id); if (image) { free(image->bitmap.addr); image->bitmap.addr = NULL; } else { image = malloc(sizeof(*image)); if (!image) { return NULL; } *image = (SimplyImage) { .id = id }; list1_prepend(&self->images, &image->node); } uint16_t row_size_bytes = (1 + (width - 1) / 32) * 4; size_t pixels_size = height * row_size_bytes; image->bitmap = (GBitmap) { .row_size_bytes = row_size_bytes, .bounds.size = { width, height }, }; image->bitmap.addr = malloc(pixels_size); memcpy(image->bitmap.addr, pixels, pixels_size); window_stack_schedule_top_window_render(); return &image->bitmap; } void simply_res_remove_image(SimplyRes *self, uint32_t id) { SimplyImage *image = (SimplyImage*) list1_find(self->images, id_filter, (void*)(uintptr_t) id); if (image) { destroy_image(self, image); } }
SimplyImage *simply_res_add_image(SimplyRes *self, uint32_t id, int16_t width, int16_t height, uint8_t *pixels, uint16_t pixels_length) { SimplyImage *image = (SimplyImage*) list1_find(self->images, id_filter, (void*)(uintptr_t) id); if (image) { destroy_image(self, image); } CreateDataContext context = { .size = GSize(width, height), .data_length = pixels_length, .data = pixels, }; image = IF_SDK_3_ELSE(create_image(self, create_bitmap_with_png_data, &context), create_image(self, create_bitmap_with_data, &context)); if (image) { image->id = id; add_image(self, image); } return image; } void simply_res_remove_image(SimplyRes *self, uint32_t id) { SimplyImage *image = (SimplyImage*) list1_find(self->images, id_filter, (void*)(uintptr_t) id); if (image) { destroy_image(self, image); } }
GFont simply_res_auto_font(SimplyRes *self, uint32_t id) { if (!id) { return NULL; } SimplyFont *font = (SimplyFont*) list1_find(self->fonts, id_filter, (void*)(uintptr_t) id); if (font) { return font->font; } if (id <= ARRAY_LENGTH(resource_crc_table)) { return simply_res_add_custom_font(self, id); } return NULL; }
GFont simply_res_auto_font(SimplyRes *self, uint32_t id) { if (!id) { return NULL; } SimplyFont *font = (SimplyFont*) list1_find(self->fonts, id_filter, (void*)(uintptr_t) id); if (font) { return font->font; } if (id <= self->num_bundled_res) { return simply_res_add_custom_font(self, id); } return NULL; }
GBitmap *simply_res_auto_image(SimplyRes *self, uint32_t id, bool is_placeholder) { if (!id) { return NULL; } SimplyImage *image = (SimplyImage*) list1_find(self->images, id_filter, (void*)(uintptr_t) id); if (image) { return &image->bitmap; } if (id <= ARRAY_LENGTH(resource_crc_table)) { return simply_res_add_bundled_image(self, id); } if (!image && is_placeholder) { return simply_res_add_image(self, id, 0, 0, NULL); } return NULL; }
SimplyImage *simply_res_auto_image(SimplyRes *self, uint32_t id, bool is_placeholder) { if (!id) { return NULL; } SimplyImage *image = (SimplyImage*) list1_find(self->images, id_filter, (void*)(uintptr_t) id); if (image) { return image; } if (id <= self->num_bundled_res) { return simply_res_add_bundled_image(self, id); } if (is_placeholder) { return simply_res_add_image(self, id, 0, 0, NULL, 0); } return NULL; }