diff --git a/src/toolkit.c b/src/toolkit.c index 5ce8b2d..41223aa 100644 --- a/src/toolkit.c +++ b/src/toolkit.c @@ -112,6 +112,8 @@ static void toolkit_drawOutline(double x, double y, double w, double h, double b, glColour* c, glColour* lc); static void toolkit_drawRect(double x, double y, double w, double h, glColour* c, glColour* lc); +// Misc. +static void toolkit_alertClose(char* str); // Add a button that when pressed will trigger call, passing it's name as the // only parameter. @@ -1060,6 +1062,36 @@ static Widget* toolkit_getFocus(void) { return &wdw->widgets[wdw->focus]; } +void toolkit_alert(const char* fmt, ...) { + char msg[256]; + va_list ap; + unsigned int wdw; + + if(window_exists("Warning")) return; + + if(fmt == NULL) return; + else { + // Get the message. + va_start(ap, fmt); + vsprintf(msg, fmt, ap); + va_end(ap); + } + + wdw = window_create("Warning", -1, -1, 300, 140); + + window_addText(wdw, 20, -30, 260, 70, 0, "txtAlert", + &gl_smallFont, &cBlack, msg); + + window_addButton(wdw, 135, 20, 50, 30, "btnOK", "OK", + toolkit_alertClose); +} + +static void toolkit_alertClose(char* str) { + (void)str; + if(window_exists("Warning")) + window_destroy(window_get("Warning")); +} + // Init. int toolkit_init(void) { windows = malloc(sizeof(Window)*MIN_WINDOWS); diff --git a/src/toolkit.h b/src/toolkit.h index a9faddf..e748c75 100644 --- a/src/toolkit.h +++ b/src/toolkit.h @@ -30,6 +30,9 @@ void window_addRect(const unsigned int wid, const int w, const int h, // size. char* name, glColour* colour, int border); // Properties. +// Popups and alerts. +void toolkit_alert(const char* fmt, ...); + // Modification void window_modifyText(const unsigned int wid, char* name, char* newstring); void window_modifyImage(const unsigned int wid, char* name, glTexture* image);