#include "../../include/mgui/image.h" #include "../../include/resource_loader.h" #include "../../include/common.h" #include "../../include/alloc.h" #include #include #include #include /* TODO: Load image asynchronously and support network files */ mgui_image* mgui_image_create(const char *filepath) { mgui_image *image = mgui_alloc(sizeof(mgui_image)); mgui_widget_init(&image->widget, MGUI_WIDGET_IMAGE); (void)filepath; /* TODO: Use |filepath| */ mgl_sprite_init(&image->sprite, NULL); return image; } mgui_widget* mgui_image_to_widget(mgui_image *list) { return &list->widget; } mgui_image* mgui_widget_to_image(mgui_widget *widget) { assert(widget->type == MGUI_WIDGET_IMAGE); return (mgui_image*)widget; } void mgui_image_set_position(mgui_image *self, mgl_vec2i position) { mgl_sprite_set_position(&self->sprite, (mgl_vec2f){ position.x, position.y }); } void mgui_image_set_width(mgui_image *self, int width) { /* TODO: Implement */ (void)self; (void)width; } void mgui_image_on_event(mgui_image *self, mgl_window *window, mgl_event *event) { (void)self; (void)window; (void)event; /* TODO: Implement */ } mgl_vec2i mgui_image_draw(mgui_image *self, mgl_window *window) { if(self->sprite.texture) { const mgl_vec2i texture_size = (mgl_vec2i){ self->sprite.texture->width, self->sprite.texture->height }; if(mgui_rectangle_intersects_with_scissor((mgl_vec2i){ self->sprite.position.x, self->sprite.position.y }, texture_size, window)) mgl_sprite_draw(mgl_get_context(), &self->sprite); return texture_size; } else { return (mgl_vec2i){ 0, 0 }; } }