aboutsummaryrefslogtreecommitdiff
path: root/src/mgui/image.c
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-12-04 01:37:07 +0100
committerdec05eba <dec05eba@protonmail.com>2021-12-04 01:37:07 +0100
commitd3a5b3d579e30ce02afd5e270dfdd511af195c31 (patch)
tree7d5aaa9d8289e7f8af2d62f796336f207375b610 /src/mgui/image.c
parent9644f3c05b808a3cac3892aae36ffca2cce9357d (diff)
Add image
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 };
+}