src/2d.c

changeset 244
ceab8a9f0366
parent 239
3b78ad115ccd
--- a/src/2d.c	Sat Aug 02 15:45:43 2025 +0200
+++ b/src/2d.c	Sat Aug 02 21:43:39 2025 +0200
@@ -29,6 +29,7 @@
 
 #include "ascension/constants.h"
 #include "ascension/shader.h"
+#include "ascension/util.h"
 
 #include <assert.h>
 
@@ -129,6 +130,7 @@
 
     float pos_x, pos_y;
     if (args.bounds.size.width + args.bounds.size.height > 0) {
+        // TODO: this is probably bugged, because it does not respect the origin
         pos_x = (float) args.bounds.pos.x;
         pos_y = (float) args.bounds.pos.y;
         rectangle->size.width = (float) args.bounds.size.width;
@@ -170,6 +172,27 @@
     return node;
 }
 
+void asc_rectangle_set_bounds(AscRectangle *rect, asc_rect bounds) {
+    // TODO: check how this harmonizes with a different origin
+    float x = (float) bounds.pos.x;
+    float y = (float) bounds.pos.y;
+    float width = (float) bounds.size.width;
+    float height = (float) bounds.size.height;
+    bool update_transform = false;
+    bool update_mesh = false;
+    update_transform |= asc_util_check_and_set(rect->node.position.x, x);
+    update_transform |= asc_util_check_and_set(rect->node.position.y, y);
+    update_mesh |= asc_util_check_and_set(rect->size.width, width);
+    update_mesh |= asc_util_check_and_set(rect->size.height, height);
+    if (update_mesh) {
+        asc_scene_node_update(&rect->node);
+    }
+    if (update_transform) {
+        asc_scene_node_update_transform(&rect->node);
+    }
+}
+
+
 static void asc_ellipsis_destroy(AscSceneNode *node) {
     asc_ptr_cast(AscEllipsis, ellipsis, node);
     asc_mesh_destroy(&ellipsis->mesh);

mercurial