#include <stdio.h>
#include <allegro5/allegro5.h>
#include <allegro5/allegro_primitives.h>
#include <allegro5/allegro_font.h>
#include <allegro5/allegro_ttf.h>
#include <allegro5/mouse.h>
#include "buttons.h"

int main()
{
    al_init();
    al_init_primitives_addon();
    al_install_keyboard();
    al_install_mouse();
    al_init_font_addon();
    al_init_ttf_addon();

    int font_size = 30, done=false, d_text=false;

    ALLEGRO_DISPLAY *display = al_create_display(800, 600);
    ALLEGRO_EVENT_QUEUE *ev_queue = al_create_event_queue(), *ev_queue2 = al_create_event_queue();
    ALLEGRO_TIMER *timer = al_create_timer(60.0/1.0);
    ALLEGRO_COLOR ccolor = al_map_rgb(191, 255, 0);
    ALLEGRO_COLOR bcolor = al_map_rgb(0, 255, 0);
//    ALLEGRO_COLOR player = al_map_rgb(0, 0, 0);
    ALLEGRO_FONT *font1 = al_load_font("L.ttf", 30, 1);
    ALLEGRO_FONT *font2 = al_load_font("GoodDog.otf", font_size, 1);

    al_register_event_source(ev_queue, al_get_display_event_source(display));
    al_register_event_source(ev_queue, al_get_timer_event_source(timer));
    al_register_event_source(ev_queue, al_get_mouse_event_source());
    al_register_event_source(ev_queue2, al_get_keyboard_event_source());
    al_clear_to_color(al_map_rgb(255, 255, 255));
    al_flip_display();

    al_start_timer(timer);
    char* str = "This Text";
    while(!done)
    {
        ALLEGRO_EVENT event;
        al_wait_for_event(ev_queue, &event);
        al_draw_filled_rectangle(0, 0, 800, 50, ccolor);
        al_draw_filled_rectangle(0, 550, 800, 600, ccolor);
        button(100, 50, 400, 300, ccolor, 2, bcolor, font_size, "press it!", font2, al_map_rgb(0, 153, 0), event, &d_text, 1);
        bool_button(100, 50, 400, 400, ccolor, 2, bcolor, font_size, "Lai Chak!", font2, al_map_rgb(0, 200, 50), event ,&d_text);
        input_field(300 , 100, 500, 150, ccolor, 3, bcolor, font2, event, ev_queue);
        if(d_text)
        al_draw_text(font1, al_map_rgb(13, 40, 100),400, 150, 1, str);
        if(event.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
            done = true;


        al_flip_display();
        al_clear_to_color(al_map_rgb(255, 255, 255));
    }
    al_destroy_display(display);
    al_uninstall_keyboard();
    al_uninstall_mouse();
    return 0;
}

