Pārlūkot izejas kodu

Make the microui demo window properly resizable (TIGR_AUTO)

TIGR_FIXED kept the bitmap at a fixed size and letterboxed it, so resizing
the window just recentred the same-size UI and stepped between integer
scales. TIGR_2X cropped the bitmap when 2X did not fit the screen (the eaten
title).

Use TIGR_AUTO so tigr resizes the bitmap to match the window (1:1); the UI
is drawn on the full canvas and resizing behaves like a normal resizable
window. Render now clips/clears using bmp^.w / bmp^.h instead of the
compile-time size. Verified by resizing the live X11 window to 1200x820.
Eric Streit 3 nedēļas atpakaļ
vecāks
revīzija
ad62e8dca3

+ 7 - 4
modula2/ANALYSIS.md

@@ -348,7 +348,10 @@ The demo is rendered by tigr (not SDL): `COMMAND_RECT` -> `tigrFillRect`,
 - The demo created its window with `TIGR_2X`, which forces a 2X scale
 - The demo created its window with `TIGR_2X`, which forces a 2X scale
   (1600x1200 for the 800x600 bitmap). On a screen whose client area is
   (1600x1200 for the 800x600 bitmap). On a screen whose client area is
   shorter than that, tigr crops the bitmap, cutting off the top rows of the
   shorter than that, tigr crops the bitmap, cutting off the top rows of the
-  framebuffer - which is what "ate" the window title. `TIGR_FIXED` is used
-  instead: tigr then picks the largest integer scale that fits the display,
-  so nothing is ever cropped (on a 1080p screen it settles on 1X, on larger
-  screens on 2X or more).
+  framebuffer - which is what "ate" the window title. `TIGR_FIXED` avoided
+  the crop but letterboxes the fixed bitmap (resizing just recentres it and
+  jumps between integer scales). The demo now uses `TIGR_AUTO`: tigr resizes
+  the bitmap to match the window (1:1), so the UI draws on the full, growing
+  canvas and resizing behaves like a normal resizable window. The renderer
+  must use `bmp^.w` / `bmp^.h` (not the compile-time size) for its clip and
+  clear.

+ 6 - 3
modula2/MICROUI-PORT.md

@@ -58,9 +58,12 @@ was run under X11 and the headless test renders an identical layout to PNG.
   `tigrRect` (1px outline) + `tigrFillRect` (interior). Using `tigrFillRect`
   `tigrRect` (1px outline) + `tigrFillRect` (interior). Using `tigrFillRect`
   alone shrinks every rect by one pixel and makes all 1px borders (window and
   alone shrinks every rect by one pixel and makes all 1px borders (window and
   control outlines) disappear.
   control outlines) disappear.
-- The demo window uses `TIGR_FIXED`, not `TIGR_2X`: forcing a scale larger
-  than the screen makes tigr crop the framebuffer (which cuts the title row).
-  `TIGR_FIXED` lets tigr choose the largest integer scale that fits.
+- The demo window uses `TIGR_AUTO`: tigr resizes the bitmap to match the
+  window (1:1), so the framebuffer is never cropped or letterboxed and
+  resizing works like a normal resizable window. Forcing a scale with
+  `TIGR_2X` crops the bitmap when it doesn't fit the screen (that cut the
+  window title row), and `TIGR_FIXED` letterboxes it. The renderer uses
+  `bmp^.w`/`bmp^.h` for its clip and clear.
 
 
 ## GNU Modula-2 16.0.1 issues worked around
 ## GNU Modula-2 16.0.1 issues worked around
 
 

BIN
modula2/examples/microui-demo/microui-demo


+ 4 - 4
modula2/examples/microui-demo/microui-demo.mod

@@ -19,7 +19,7 @@ FROM tigr IMPORT TigrPtr, tigrWindow, tigrFree, tigrClosed, tigrClear,
                  tigrKeyDown, tigrKeyHeld, tigrReadChar, tigrTime,
                  tigrKeyDown, tigrKeyHeld, tigrReadChar, tigrTime,
                  tigrEncodeUTF8, tigrClip, tigrError,
                  tigrEncodeUTF8, tigrClip, tigrError,
                  TK_ESCAPE, TK_LSHIFT, TK_RSHIFT, TK_LCONTROL, TK_RCONTROL,
                  TK_ESCAPE, TK_LSHIFT, TK_RSHIFT, TK_LCONTROL, TK_RCONTROL,
-                 TK_LALT, TK_RALT, TK_RETURN, TK_BACKSPACE, TIGR_FIXED;
+                 TK_LALT, TK_RALT, TK_RETURN, TK_BACKSPACE, TIGR_AUTO;
 FROM helper IMPORT tigrRGB, tigrRGBA;
 FROM helper IMPORT tigrRGB, tigrRGBA;
 FROM microuiHelpers IMPORT BITAND, IntToStr, HexByte;
 FROM microuiHelpers IMPORT BITAND, IntToStr, HexByte;
 IMPORT microui;
 IMPORT microui;
@@ -205,7 +205,7 @@ PROCEDURE Render;
         icp : IconCommandPtr;
         icp : IconCommandPtr;
         ccp : ClipCommandPtr;
         ccp : ClipCommandPtr;
 BEGIN
 BEGIN
-    tigrClip(bmp, 0, 0, VAL(CARDINAL, WIN_W), VAL(CARDINAL, WIN_H));
+    tigrClip(bmp, 0, 0, bmp^.w, bmp^.h);
     tigrClear(bmp, tigrRGBA(ClampByte(bg[0]), ClampByte(bg[1]),
     tigrClear(bmp, tigrRGBA(ClampByte(bg[0]), ClampByte(bg[1]),
                             ClampByte(bg[2]), VAL(BYTE, 255)));
                             ClampByte(bg[2]), VAL(BYTE, 255)));
     cmd := NIL;
     cmd := NIL;
@@ -225,7 +225,7 @@ BEGIN
             SetClipI(ccp^.rect)
             SetClipI(ccp^.rect)
         END
         END
     END;
     END;
-    tigrClip(bmp, 0, 0, VAL(CARDINAL, WIN_W), VAL(CARDINAL, WIN_H))
+    tigrClip(bmp, 0, 0, bmp^.w, bmp^.h)
 END Render;
 END Render;
 
 
 (*========================================================================*)
 (*========================================================================*)
@@ -544,7 +544,7 @@ END LogWindow;
 (*========================================================================*)
 (*========================================================================*)
 
 
 BEGIN
 BEGIN
-    bmp := tigrWindow(WIN_W, WIN_H, "microui + tigr (Modula-2)", TIGR_FIXED);
+    bmp := tigrWindow(WIN_W, WIN_H, "microui + tigr (Modula-2)", TIGR_AUTO);
     IF bmp = NIL THEN
     IF bmp = NIL THEN
         tigrError(NIL, "Cannot create window")
         tigrError(NIL, "Cannot create window")
     END;
     END;