src/window.c

changeset 95
622887f7e954
parent 92
78ce93fb46e5
--- a/src/window.c	Thu Apr 24 18:41:42 2025 +0200
+++ b/src/window.c	Thu Apr 24 19:53:40 2025 +0200
@@ -27,8 +27,6 @@
 
 #include "ascension/window.h"
 #include "ascension/context.h"
-#include "ascension/error.h"
-#include "ascension/utils.h"
 
 #include <GL/glew.h>
 
@@ -53,10 +51,6 @@
         asc_error("Cannot create window - slot %u already occupied.", index);
         return;
     }
-    if (window->ui != NULL) {
-        asc_wprintf("Window with index %u has a dangling UI pointer", index);
-        asc_scene_node_free(window->ui);
-    }
 
     Uint32 flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN;
     flags |= settings->fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : SDL_WINDOW_RESIZABLE;
@@ -82,7 +76,7 @@
     window->resized = true; // count initial sizing as resize
 
     if (asc_gl_context_initialize(&window->glctx, window->window, &settings->glsettings)) {
-        window->ui = asc_scene_node_empty();
+        asc_scene_init(&window->ui);
         asc_dprintf("Window %u initialized", window->id);
         asc_context.active_window = index;
     } else {
@@ -110,8 +104,7 @@
     asc_gl_context_activate(&window->glctx);
 
     // destroy all scenes
-    asc_scene_node_free(window->ui);
-    window->ui = NULL;
+    asc_scene_destroy(&window->ui);
 
     // release context related data
     asc_gl_context_destroy(&window->glctx);
@@ -146,12 +139,12 @@
     int window_height = asc_active_window->dimensions.height;
     glViewport(0, 0, window_width, window_height);
     glClear(GL_COLOR_BUFFER_BIT);
-    asc_recti viewport = {0, 0, window_width, window_height};
 
     // Draw the UI
-    AscCamera ui_camera;
-    asc_camera_ortho(&ui_camera, viewport);
-    asc_scene_draw(asc_active_window->ui, viewport, &ui_camera);
+    AscScene *ui = &asc_active_window->ui;
+    asc_recti viewport = {0, 0, window_width, window_height};
+    asc_camera_ortho(&ui->camera, viewport);
+    asc_scene_draw(ui, viewport);
 
     // Swap Buffers
     SDL_GL_SwapWindow(asc_active_window->window);
@@ -176,3 +169,7 @@
     }
     return i;
 }
+
+void asc_add_ui_node(AscSceneNode *node) {
+    asc_scene_add_node(&asc_active_window->ui, node);
+}

mercurial