From 592ee2f218f1886decc478c3353810c7c11b51d3 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Fri, 06 Aug 2021 01:35:30 -0400 Subject: tk: Add window object --- (limited to 'src/tk/window.c') diff --git a/src/tk/window.c b/src/tk/window.c new file mode 100644 index 0000000..532a2e4 --- /dev/null +++ b/src/tk/window.c @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2021 P. J. McDermott + * + * This file is part of Maze Fight + * + * Maze Fight is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Maze Fight is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Maze Fight. If not, see . + */ + +#include +#include +#include +#include +#include "../tk.h" +#include "widget.h" + +struct mftk_window { + struct mftk_widget *root; +}; + +struct mftk_window * +mftk_window_new(struct mftk_widget *root) +{ + struct mftk_window *w; + + w = calloc(1, sizeof(*w)); + if (w == NULL) { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, + "Couldn't create window: %s", + strerror(errno)); + return NULL; + } + + w->root = root; + + mftk_widget_layout(w->root); + + return w; +} + +int +mftk_window_event(struct mftk_window *w, SDL_Event *e) +{ + return mftk_widget_event(w->root, e, 0, 0); +} + +int +mftk_window_render(struct mftk_window *w, SDL_Renderer *renderer) +{ + return mftk_widget_render(w->root, renderer, 0, 0); +} + +void +mftk_window_destroy(struct mftk_window **w_p) +{ + struct mftk_window *w; + + if (w_p == NULL || *w_p == NULL) { + return; + } + w = *w_p; + + mftk_widget_destroy(&w->root); + free(w); + w = NULL; +} -- cgit v0.9.1