diff options
| author | Pietro Gagliardi <[email protected]> | 2015-04-06 12:20:51 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2015-04-06 12:20:51 -0400 |
| commit | ee1653f542f0c070afb8310c9041267496bbdf05 (patch) | |
| tree | b18654d87e569457a61ad15d0955ad9c53efd0e7 /new/window_unix.c | |
| parent | 50577098478ed0e7cfb3f2a417bddb16187929f6 (diff) | |
Started doing the C rewrite. Defined the basic initialization and main loop and window API and implemented them on GTK+.
Diffstat (limited to 'new/window_unix.c')
| -rw-r--r-- | new/window_unix.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/new/window_unix.c b/new/window_unix.c new file mode 100644 index 0000000..5ace5a5 --- /dev/null +++ b/new/window_unix.c @@ -0,0 +1,59 @@ +// 6 april 2015 +#include "ui_unix.h" + +struct uiWindow { + GtkWidget *widget; + int (*onClosing)(uiWindow *, void *); + void *onClosingData; +}; + +uiWindow *uiNewWindow(char *title, int width, int height) +{ + uiWindow *w; + + w = g_new0(uiWindow, 1); + w->widget = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_window_set_title(GTK_WINDOW(w->widget), title); + gtk_window_resize(GTK_WINDOW(w->widget), width, height); + return w; +} + +void uiWindowDestroy(uiWindow *w) +{ + gtk_widget_destroy(w->widget); + g_free(w); +} + +uintptr_t uiWindowHandle(uiWindow *w) +{ + return (uintptr_t) (w->widget); +} + +// TODO titles + +void uiWindowShow(uiWindow *w) +{ + gtk_widget_show_all(w->widget); +} + +void uiWindowHide(uiWindow *w) +{ + gtk_widget_hide(w->widget); +} + +static gboolean onClosing(GtkWidget *win, GdkEvent *e, gpointer data) +{ + uiWindow *w = (uiWindow *) data; + + // return exact values just in case + if ((*(w->onClosing))(w, w->onClosingData)) + return FALSE; + return TRUE; +} + +void uiWindowOnClosing(uiWindow *w, int (*f)(uiWindow *, void *), void *data) +{ + w->onClosing = f; + w->onClosingData = data; + g_signal_connect(w->widget, "delete-event", G_CALLBACK(onClosing), w); +} |
