#pragma once
#include <SDL/SDL.h>
#include "opengl.h"
#include "font.h"

extern int toolkit;

/* Creation. */
unsigned int window_create(char* name, const int x, const int y,
                           const int w, const int h);

void window_addButton(const unsigned int wid, const int x, const int y,
                      const int w, const int h, char* name, char* display,
                      void(*call)(unsigned int, char*));

void window_addText(const unsigned int wid, const int x, const int y,
                    const int w, const int h, const int centered, char* name,
                    glFont* font, glColour* colour, char* string);

void window_addImage(const unsigned int wid, const int x, const int y,
                     char* name, glTexture* image, int border);

void window_addList(const unsigned int wid,
                    const int x, const int y, /* Position. */
                    const int w, const int h, /* Size. */
                    char* name, char** items, int nitems, int defitem,
                    void(*call)(unsigned int, char*));

void window_addRect(const unsigned int wid,
                    const int x, const int y, /* Position. */
                    const int w, const int h, /* size. */
                    char* name, glColour* colour, int border); /* Properties. */

void window_addCust(const unsigned int wid,
                    const int x, const int y, /* Position. */
                    const int w, const int h, /* Size. */
                    char* name, const int border,
                    void(*render) (double x, double y, double w, double h),
                    void(*mouse) (unsigned int wid, SDL_Event* event, double x, double y));

void window_addInput(const unsigned int wid,
                     const int x, const int y,
                     const int w, const int h,
                     char* name, const int max, const int oneline);

void window_addImageArray(const unsigned int wid,
                          const int x, const int y, /* Position. */
                          const int w, const int h, /* Size. */
                          char* name, const int iw, const int ih, /* Name and images sizes. */
                          glTexture** tex, char** caption, int nelem, /* Elements. */
                          void(*call)(unsigned int, char*));

void window_addFader(const unsigned int wid,
    const int x, const int y,   /* Position. */
    const int w, const int h,   /* Size, if w > h fader is horizontal, else vertical. */
    char* name, const double min, const double max, /* name, min * max values. */
    const double def, /* Default pos. */
    void(*call)(unsigned int, char*)); /* Function to call on value change. */

/* Modification. */
void window_setAccept(const unsigned int wid, void(*fptr)(unsigned int, char*));
void window_setCancel(const unsigned int wid, void(*cancel)(unsigned int, char*));
/* Text. */
void window_modifyText(const unsigned int wid, char* name, char* newstring);
/* Button. */
void window_disableButton(const unsigned int wid, char* name);
void window_enableButton(const unsigned int wid, char* name);
/* Image. */
void window_modifyImage(const unsigned int wid, char* name, glTexture* image);
void window_imgColour(const unsigned int wid, char* name, glColour* colour);
/* Fader. */
void faderValue(const unsigned int wid,
    char* name, double value);
void faderBounds(const unsigned int wid,
    char* name, double min, double max);

/* Get. */
/* Generic. */
int window_exists(const char* wdwname);
int widget_exists(const unsigned int wid, const char* wgtname);
unsigned int window_get(const char* wdwname);
char* window_getInput(const unsigned int wid, char* name);
void window_posWidget(const unsigned int wid,
                      char* name, int* x, int* y);
void window_moveWidget(const unsigned int wid,
                       char* name, int x, int y);
/* Specific. */
char* toolkit_getList(const unsigned int wid, char* name);
int toolkit_getListPos(const unsigned int wid, char* name);
glTexture* window_getImage(const unsigned int wid, char* name);

double window_getFaderValue(const unsigned wid, char* name);

/* Destroy window. */
void window_close(unsigned int wid, char* str);
void window_destroy(const unsigned int wid);
void window_destroyWidget(unsigned wid, const char* wgtname);

/* Render. */
void toolkit_render(void);

/* Input. */
int toolkit_input(SDL_Event* event);
void toolkit_update(void);

/* Init/Exit. */
int toolkit_init(void);
void toolkit_exit(void);