aboutsummaryrefslogtreecommitdiff
path: root/src/mgui/mgui.c
blob: 3c1d955f43498f155122ebd365946fc76cbeee10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "../../include/mgui/mgui.h"
#include "../../include/mgui/widget.h"
#include <mgl/window/event.h>
#include <mgl/system/clock.h>

static mgl_clock global_timer;

void mgui_init() {
    mgl_clock_init(&global_timer);
}

void mgui_on_event(mgui_widget *root_widget, mgl_window *window, mgl_event *event) {
    if(event->type == MGL_EVENT_RESIZED)
        mgui_widget_set_size(root_widget, (mgl_vec2i){ event->size.width, event->size.height });
    mgui_widget_on_event(root_widget, window, event);
}

void mgui_draw(mgui_widget *root_widget, mgl_window *window) {
    /* TODO: Only do this if widget is dirty */
    mgui_widget_calculate_size(root_widget, root_widget->size);
    mgui_widget_draw(root_widget, window);
}

double mgui_get_seconds_since_last_update() {
    double elapsed_time_sec = mgl_clock_restart(&global_timer);
    if(elapsed_time_sec > 1.0)
        elapsed_time_sec = 1.0;
    return elapsed_time_sec;
}