test/snake/snake.c

changeset 229
5c05b5164a16
parent 227
a5775e8dbc13
child 230
02090b2d147e
--- a/test/snake/snake.c	Sun Jul 27 23:34:19 2025 +0200
+++ b/test/snake/snake.c	Sun Jul 27 23:44:14 2025 +0200
@@ -230,6 +230,18 @@
 }
 
 static asc_rect update_viewport_for_window_resize(asc_vec2u window_size) {
+
+    // TODO: special case: window is SO small that nothing would be rendered
+
+    // remove margins
+    const unsigned margin = 10;
+    window_size.width -= 2*margin;
+    window_size.height -= 2*margin;
+
+    // remove space for score, power-ups, etc.
+    const unsigned left_area = (unsigned) (asc_active_window->ui_scale*200);
+    window_size.width -= left_area;
+
     // Compute scaling and offsets
     unsigned viewport_size, offset_x = 0, offset_y = 0;
     if (window_size.width > window_size.height) {
@@ -241,6 +253,8 @@
         offset_y = (window_size.height - window_size.width) / 2;
         viewport_size = window_size.width;
     }
+    offset_x += left_area + margin;
+    offset_y += margin;
 
     // Set the viewport to the scaled and centered region
     return ASC_RECT(offset_x, offset_y, viewport_size, viewport_size);
@@ -261,7 +275,8 @@
     AscWindowSettings settings;
     asc_window_settings_init_defaults(&settings);
     settings.title = "Snake";
-    settings.dimensions = ASC_VEC2U(800, 800);
+    settings.dimensions = ASC_VEC2U(900, 600);
+    // TODO: resize window depending on ui scale factor
     asc_window_initialize(0, &settings);
     asc_ui_scale_auto();
 

mercurial