aboutsummaryrefslogtreecommitdiff
path: root/src/mgui/image.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mgui/image.c')
-rw-r--r--src/mgui/image.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/mgui/image.c b/src/mgui/image.c
new file mode 100644
index 0000000..ad8a7d2
--- /dev/null
+++ b/src/mgui/image.c
@@ -0,0 +1,54 @@
+#include "../../include/mgui/image.h"
+#include "../../include/resource_loader.h"
+#include "../../include/common.h"
+#include "../../include/alloc.h"
+#include <mgl/mgl.h>
+#include <mgl/window/event.h>
+#include <mgl/graphics/texture.h>
+#include <assert.h>
+
+/* 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) {
+ (void)window;
+ mgl_sprite_draw(mgl_get_context(), &self->sprite);
+ if(self->sprite.texture)
+ return (mgl_vec2i){ self->sprite.texture->width, self->sprite.texture->height };
+ else
+ return (mgl_vec2i){ 0, 0 };
+}