Procházet zdrojové kódy

Fix microui demo rect rendering with tigr

tigr's tigrFillRect only fills the interior of a rectangle (it does
x+=1, y+=1, w-=2, h-=2), so drawing microui's COMMAND_RECT with it alone
made every rectangle one pixel too small and removed all 1px-high/wide
rectangles - i.e. the window and control borders - which made the top of
the window look "eaten" by the title bar.

Draw each rectangle as tigrRect (1px outline) followed by tigrFillRect
(interior) instead, so the exact rect is filled with clipping/blending and
single-pixel rects still render. Applied to both microui-demo and
microui-headless; regenerate microui-demo.png and document the gotcha in
ANALYSIS.md / MICROUI-PORT.md.
Eric Streit před 3 týdny
rodič
revize
821f32a3f9

+ 9 - 1
modula2/ANALYSIS.md

@@ -336,4 +336,12 @@ The demo is rendered by tigr (not SDL): `COMMAND_RECT` -> `tigrFillRect`,
   the pointer; they now hash `ADR(pointer)` like the C.
   the pointer; they now hash `ADR(pointer)` like the C.
 - `RealToStr` (added for the port) was rewritten to round correctly and to
 - `RealToStr` (added for the port) was rewritten to round correctly and to
   format `%f` / `%g` faithfully (fixed an off-by-one zero-pad and a lost
   format `%f` / `%g` faithfully (fixed an off-by-one zero-pad and a lost
-  minus sign in `%g`), and no longer relies on the broken `SHORTREAL(int)`.
+  minus sign in `%g`), and no longer relies on the broken `SHORTREAL(int)`.
+- The tigr renderer used `tigrFillRect` alone to paint microui rectangles.
+  tigr's `tigrFillRect` fills only the *interior* of a rectangle (it does
+  `x+=1; y+=1; w-=2; h-=2`), so every rectangle was shrunk by one pixel and
+  all 1px-high/wide rectangles (the control and window borders) disappeared -
+  which showed up as the top of the window being "eaten" by the title bar.
+  The fix is to draw `tigrRect` (1px outline) followed by `tigrFillRect`
+  (interior): together they fill the exact rectangle, with clipping and
+  alpha blending, and single-pixel rects still show.

+ 5 - 0
modula2/MICROUI-PORT.md

@@ -53,6 +53,11 @@ was run under X11 and the headless test renders an identical layout to PNG.
 - Callbacks are invoked through one-argument records (`TextWidthArgs`,
 - Callbacks are invoked through one-argument records (`TextWidthArgs`,
   `TextHeightArgs`, `FrameArgs`).
   `TextHeightArgs`, `FrameArgs`).
 - `drawText` takes an `ADDRESS` + length so substrings need no copy.
 - `drawText` takes an `ADDRESS` + length so substrings need no copy.
+- tigr's `tigrFillRect` fills only the *interior* of a rectangle
+  (`x+1, y+1, w-2, h-2`); a filled microui rectangle is therefore drawn as
+  `tigrRect` (1px outline) + `tigrFillRect` (interior). Using `tigrFillRect`
+  alone shrinks every rect by one pixel and makes all 1px borders (window and
+  control outlines) disappear.
 
 
 ## GNU Modula-2 16.0.1 issues worked around
 ## GNU Modula-2 16.0.1 issues worked around
 
 

binární
modula2/examples/microui-demo/microui-demo


+ 6 - 1
modula2/examples/microui-demo/microui-demo.mod

@@ -15,7 +15,7 @@ MODULE microuiDemo;
 FROM SYSTEM IMPORT ADDRESS, ADR, CAST, ADDADR, BYTE;
 FROM SYSTEM IMPORT ADDRESS, ADR, CAST, ADDADR, BYTE;
 FROM tigr IMPORT TigrPtr, tigrWindow, tigrFree, tigrClosed, tigrClear,
 FROM tigr IMPORT TigrPtr, tigrWindow, tigrFree, tigrClosed, tigrClear,
                  tigrUpdate, TPixelType, tfont, tigrPrint, tigrFillRect,
                  tigrUpdate, TPixelType, tfont, tigrPrint, tigrFillRect,
-                 tigrLine, tigrTextWidth, tigrTextHeight, tigrMouse,
+                 tigrRect, tigrLine, tigrTextWidth, tigrTextHeight, tigrMouse,
                  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,
@@ -131,6 +131,11 @@ BEGIN
     x1 := MinI(x + w, bw);
     x1 := MinI(x + w, bw);
     y1 := MinI(y + h, bh);
     y1 := MinI(y + h, bh);
     IF (x1 > x0) AND (y1 > y0) THEN
     IF (x1 > x0) AND (y1 > y0) THEN
+        (* tigrFillRect only fills the *interior* of a rect (it does
+           x+1, y+1, w-2, h-2), so pair it with tigrRect to fill the whole
+           rectangle - and to keep 1px-high/wide rects (microui borders). *)
+        tigrRect(bmp, VAL(CARDINAL, x0), VAL(CARDINAL, y0),
+                 VAL(CARDINAL, x1 - x0), VAL(CARDINAL, y1 - y0), Pix(c));
         tigrFillRect(bmp, VAL(CARDINAL, x0), VAL(CARDINAL, y0),
         tigrFillRect(bmp, VAL(CARDINAL, x0), VAL(CARDINAL, y0),
                      VAL(CARDINAL, x1 - x0), VAL(CARDINAL, y1 - y0), Pix(c))
                      VAL(CARDINAL, x1 - x0), VAL(CARDINAL, y1 - y0), Pix(c))
     END
     END

binární
modula2/examples/microui-demo/microui-demo.png


binární
modula2/examples/microui-demo/microui-headless


+ 5 - 1
modula2/examples/microui-demo/microui-headless.mod

@@ -13,7 +13,7 @@ MODULE microuiHeadless;
 
 
 FROM SYSTEM IMPORT ADDRESS, ADR, CAST, ADDADR, BYTE;
 FROM SYSTEM IMPORT ADDRESS, ADR, CAST, ADDADR, BYTE;
 FROM tigr IMPORT TigrPtr, tigrBitmap, tigrClear, tigrPrint, tigrSaveImage,
 FROM tigr IMPORT TigrPtr, tigrBitmap, tigrClear, tigrPrint, tigrSaveImage,
-                 tigrFree, tigrFillRect, tigrTextWidth, tigrTextHeight,
+                 tigrFree, tigrFillRect, tigrRect, tigrTextWidth, tigrTextHeight,
                  tfont, TPixelType;
                  tfont, TPixelType;
 FROM microuiHelpers IMPORT BITAND;
 FROM microuiHelpers IMPORT BITAND;
 FROM helper IMPORT tigrRGB;
 FROM helper IMPORT tigrRGB;
@@ -82,6 +82,10 @@ BEGIN
     x1 := MinI(x + w, WIN_W);
     x1 := MinI(x + w, WIN_W);
     y1 := MinI(y + h, WIN_H);
     y1 := MinI(y + h, WIN_H);
     IF (x1 > x0) AND (y1 > y0) THEN
     IF (x1 > x0) AND (y1 > y0) THEN
+        (* tigrFillRect only fills the interior; pair it with tigrRect so the
+           whole rect (including 1px borders) is drawn, with clipping/blending *)
+        tigrRect(bmp, VAL(CARDINAL, x0), VAL(CARDINAL, y0),
+                 VAL(CARDINAL, x1 - x0), VAL(CARDINAL, y1 - y0), Pix(c));
         tigrFillRect(bmp, VAL(CARDINAL, x0), VAL(CARDINAL, y0),
         tigrFillRect(bmp, VAL(CARDINAL, x0), VAL(CARDINAL, y0),
                      VAL(CARDINAL, x1 - x0), VAL(CARDINAL, y1 - y0), Pix(c))
                      VAL(CARDINAL, x1 - x0), VAL(CARDINAL, y1 - y0), Pix(c))
     END
     END