GFont simply_res_add_custom_font(SimplyRes *self, uint32_t id) { SimplyFont *font = malloc(sizeof(*font)); if (!font) { return NULL; } ResHandle handle = resource_get_handle(id); if (!handle) { return NULL; } GFont custom_font = fonts_load_custom_font(handle); if (!custom_font) { free(font); return NULL; } font->font = custom_font; list1_prepend(&self->fonts, &font->node); window_stack_schedule_top_window_render(); return font->font; }
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); } }
static void add_image(SimplyRes *self, SimplyImage *image) { list1_prepend(&self->images, &image->node); setup_image(image); window_stack_schedule_top_window_render(); }
GBitmap *simply_res_add_bundled_image(SimplyRes *self, uint32_t id) { SimplyImage *image = malloc(sizeof(*image)); if (!image) { return NULL; } GBitmap *bitmap = gbitmap_create_with_resource(id); if (!bitmap) { free(image); return NULL; } *image = (SimplyImage) { .id = id, .bitmap = *bitmap, }; list1_prepend(&self->images, &image->node); window_stack_schedule_top_window_render(); return &image->bitmap; }