From d2c5b616600348b79f19324b4c36be1ed8e9d4c6 Mon Sep 17 00:00:00 2001 From: 4DBug <4DBug@github.com> Date: Sat, 17 Oct 2026 06:08:05 -0500 Subject: [PATCH] Raster: reversed rects (min>max) draw like upstream --- build/ImGui.linemap.json | 2 +- build/ImGui.luau | 6 ++ build/imgui_love.linemap.json | 2 +- build/imgui_love.lua | 6 ++ imgui_draw.lua | 6 ++ tools/test/check_all.sh | 1 + tools/test/scripts/t_rect_flip.luau | 89 +++++++++++++++++++++++++++++ 7 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 tools/test/scripts/t_rect_flip.luau diff --git a/build/ImGui.linemap.json b/build/ImGui.linemap.json index f24a439..9d2185c 100644 --- a/build/ImGui.linemap.json +++ b/build/ImGui.linemap.json @@ -1 +1 @@ -[[46, "imgui.lua"], [22648, "imgui_demo.lua"], [34505, "imgui_draw.lua"], [42829, "imgui_h.lua"], [45832, "roblox/raster.lua"], [46308, "roblox/textures.lua"], [46479, "roblox/layers.lua"], [46816, "roblox/overlays.lua"], [46897, "roblox/render.lua"], [47742, "roblox/parallel.lua"], [48141, "imgui_impl_roblox.lua"], [48630, "imgui_impl_roblox_fonts.lua"], [55033, "imgui_internal.lua"], [58999, "imgui_tables.lua"], [64091, "imgui_widgets.lua"], [76329, "imstb_rectpack.lua"], [76993, "imstb_textedit.lua"], [78535, "imstb_truetype.lua"], [81323, "imstd_minstdio.lua"]] \ No newline at end of file +[[46, "imgui.lua"], [22648, "imgui_demo.lua"], [34505, "imgui_draw.lua"], [42835, "imgui_h.lua"], [45838, "roblox/raster.lua"], [46314, "roblox/textures.lua"], [46485, "roblox/layers.lua"], [46822, "roblox/overlays.lua"], [46903, "roblox/render.lua"], [47748, "roblox/parallel.lua"], [48147, "imgui_impl_roblox.lua"], [48636, "imgui_impl_roblox_fonts.lua"], [55039, "imgui_internal.lua"], [59005, "imgui_tables.lua"], [64097, "imgui_widgets.lua"], [76335, "imstb_rectpack.lua"], [76999, "imstb_textedit.lua"], [78541, "imstb_truetype.lua"], [81329, "imstd_minstdio.lua"]] \ No newline at end of file diff --git a/build/ImGui.luau b/build/ImGui.luau index 510a5f8..3365e6c 100644 --- a/build/ImGui.luau +++ b/build/ImGui.luau @@ -40649,6 +40649,10 @@ function MT.ImDrawList:AddRect(p_min, p_max, col, rounding, thickness, flags) return end + -- [Port] reversed corners (min > max, e.g. a box selection dragged up/left): upstream's min_dim checks drop them, older ImGui drew them + if p_min.x > p_max.x or p_min.y > p_max.y then + p_min, p_max = ImVec2(ImMin(p_min.x, p_max.x), ImMin(p_min.y, p_max.y)), ImVec2(ImMax(p_min.x, p_max.x), ImMax(p_min.y, p_max.y)) + end flags = bit32.bor(flags, self.Flags) local stroke_pos = _GetStrokePos(flags, 131072 --[[ImDrawFlags.StrokeInside]]) if stroke_pos == 917504 --[[ImDrawFlags.StrokeLegacy]] then @@ -40866,6 +40870,8 @@ function MT.ImDrawList:AddRectFilled(p_min, p_max, col, rounding, flags) end local ax, ay, bx, by = p_min.x, p_min.y, p_max.x, p_max.y + if ax > bx then ax, bx = bx, ax end -- [Port] reversed corners: see AddRect + if ay > by then ay, by = by, ay end local width = bx - ax local height = by - ay local min_dim = ImMin(width, height) diff --git a/build/imgui_love.linemap.json b/build/imgui_love.linemap.json index 5889bd4..da1731b 100644 --- a/build/imgui_love.linemap.json +++ b/build/imgui_love.linemap.json @@ -1 +1 @@ -[[183, "imgui.lua"], [22785, "imgui_demo.lua"], [34642, "imgui_draw.lua"], [42966, "imgui_h.lua"], [45967, "imgui_impl_love.lua"], [46511, "imgui_internal.lua"], [50477, "imgui_tables.lua"], [55569, "imgui_widgets.lua"], [67807, "imstb_rectpack.lua"], [68471, "imstb_textedit.lua"], [70013, "imstb_truetype.lua"], [72801, "imstd_minstdio.lua"]] \ No newline at end of file +[[183, "imgui.lua"], [22785, "imgui_demo.lua"], [34642, "imgui_draw.lua"], [42972, "imgui_h.lua"], [45973, "imgui_impl_love.lua"], [46517, "imgui_internal.lua"], [50483, "imgui_tables.lua"], [55575, "imgui_widgets.lua"], [67813, "imstb_rectpack.lua"], [68477, "imstb_textedit.lua"], [70019, "imstb_truetype.lua"], [72807, "imstd_minstdio.lua"]] \ No newline at end of file diff --git a/build/imgui_love.lua b/build/imgui_love.lua index 8b97ee2..4359005 100644 --- a/build/imgui_love.lua +++ b/build/imgui_love.lua @@ -40786,6 +40786,10 @@ function MT.ImDrawList:AddRect(p_min, p_max, col, rounding, thickness, flags) return end + -- [Port] reversed corners (min > max, e.g. a box selection dragged up/left): upstream's min_dim checks drop them, older ImGui drew them + if p_min.x > p_max.x or p_min.y > p_max.y then + p_min, p_max = ImVec2(ImMin(p_min.x, p_max.x), ImMin(p_min.y, p_max.y)), ImVec2(ImMax(p_min.x, p_max.x), ImMax(p_min.y, p_max.y)) + end flags = bit32.bor(flags, self.Flags) local stroke_pos = _GetStrokePos(flags, 131072 --[[ImDrawFlags.StrokeInside]]) if stroke_pos == 917504 --[[ImDrawFlags.StrokeLegacy]] then @@ -41003,6 +41007,8 @@ function MT.ImDrawList:AddRectFilled(p_min, p_max, col, rounding, flags) end local ax, ay, bx, by = p_min.x, p_min.y, p_max.x, p_max.y + if ax > bx then ax, bx = bx, ax end -- [Port] reversed corners: see AddRect + if ay > by then ay, by = by, ay end local width = bx - ax local height = by - ay local min_dim = ImMin(width, height) diff --git a/imgui_draw.lua b/imgui_draw.lua index dd1fa3a..a7c0176 100644 --- a/imgui_draw.lua +++ b/imgui_draw.lua @@ -6145,6 +6145,10 @@ function MT.ImDrawList:AddRect(p_min, p_max, col, rounding, thickness, flags) return end + -- [Port] reversed corners (min > max, e.g. a box selection dragged up/left): upstream's min_dim checks drop them, older ImGui drew them + if p_min.x > p_max.x or p_min.y > p_max.y then + p_min, p_max = ImVec2(ImMin(p_min.x, p_max.x), ImMin(p_min.y, p_max.y)), ImVec2(ImMax(p_min.x, p_max.x), ImMax(p_min.y, p_max.y)) + end flags = bit32.bor(flags, self.Flags) local stroke_pos = _GetStrokePos(flags, ImDrawFlags.StrokeInside) if stroke_pos == ImDrawFlags.StrokeLegacy then @@ -6362,6 +6366,8 @@ function MT.ImDrawList:AddRectFilled(p_min, p_max, col, rounding, flags) end local ax, ay, bx, by = p_min.x, p_min.y, p_max.x, p_max.y + if ax > bx then ax, bx = bx, ax end -- [Port] reversed corners: see AddRect + if ay > by then ay, by = by, ay end local width = bx - ax local height = by - ay local min_dim = ImMin(width, height) diff --git a/tools/test/check_all.sh b/tools/test/check_all.sh index c10539f..f84a76e 100755 --- a/tools/test/check_all.sh +++ b/tools/test/check_all.sh @@ -39,6 +39,7 @@ CHECKS=( "demo_open|DRAWHASH|$R --main tools/test/scripts/t_drawhash.luau --frames 150 --open" "demo_random|^|python3 tools/test/run.py --roblox --timeout 600 --frames 400 --open" "pixels|PIXELS SAME|a=\$($R --main tools/test/scripts/t_pixels.luau --frames 600 | grep -P '^PIX\t'); b=\$(RUN_FLAGS=ARG_FORCE=true $R --main tools/test/scripts/t_pixels.luau --frames 600 | grep -P '^PIX\t'); [ -n \"\$a\" ] && [ \"\$a\" = \"\$b\" ] && echo PIXELS SAME" +"rect_flip|RECTFLIP OK|$R --main tools/test/scripts/t_rect_flip.luau --frames 30" "tile_bound|TILEBOUND OK|$R --main tools/test/scripts/t_tile_bound.luau --frames 200" "parallel|PARALLEL OK|$R --main tools/test/scripts/t_parallel.luau --frames 500" "pool_ctx|POOLCTX OK|$R --main tools/test/scripts/t_pool_ctx.luau --frames 60" diff --git a/tools/test/scripts/t_rect_flip.luau b/tools/test/scripts/t_rect_flip.luau new file mode 100644 index 0000000..993ca73 --- /dev/null +++ b/tools/test/scripts/t_rect_flip.luau @@ -0,0 +1,89 @@ +-- Reversed rects (min > max, e.g. box-select dragged up/left) must draw like upstream's GPU path: +-- AddRectFilled + AddRect from each of the 4 drag directions composite to identical, non-blank pixels. +local G = require(game:GetService("ReplicatedStorage"):WaitForChild("ImGui")) +local ImGui, ImVec2 = G.ImGui, G.ImVec2 +ImGui.CreateContext() +G.ImGui_ImplRoblox.Init() +G.ImGui_ImplRoblox.SetRenderRate(0) +local io = ImGui.GetIO() +local W, H = 1280, 760 +local function composite(gui) + local screen = buffer.create(W * H * 3) + local function walk(inst, ox, oy, kx0, ky0, kx1, ky1) + local kids = inst:GetChildren() + table.sort(kids, function(a, b) return (a.ZIndex or 1) < (b.ZIndex or 1) end) + for _, c in ipairs(kids) do + if c.Visible ~= false then + local x, y = ox + (c.Position and c.Position.X or 0), oy + (c.Position and c.Position.Y or 0) + local cx0, cy0, cx1, cy1 = kx0, ky0, kx1, ky1 + if c.ClipsDescendants then + cx0, cy0 = math.max(cx0, x), math.max(cy0, y) + cx1, cy1 = math.min(cx1, x + c.Size.X), math.min(cy1, y + c.Size.Y) + end + if c.ClassName == "ImageLabel" then + local img = c.ImageContent.Object + local px, sz = img.Pixels, img.Size.X + for ty = 0, sz - 1 do + local sy = y + ty + if sy >= cy0 and sy < cy1 then + for tx = 0, sz - 1 do + local sx = x + tx + if sx >= cx0 and sx < cx1 then + local o = (ty * sz + tx) * 4 + local a = buffer.readu8(px, o + 3) + if a > 0 then + local d = (sy * W + sx) * 3 + local fa = a / 255 + for ch = 0, 2 do + local v = buffer.readu8(px, o + ch) * fa + buffer.readu8(screen, d + ch) * (1 - fa) + buffer.writeu8(screen, d + ch, math.floor(v + 0.5)) + end + end + end + end + end + end + end + walk(c, x, y, cx0, cy0, cx1, cy1) + end + end + end + walk(gui, 0, 0, 0, 0, W, H) + local h = 0 + for i = 0, W * H * 3 - 4, 4 do h = (h * 31 + buffer.readu32(screen, i)) % 2147483647 end + return h +end + +local A, B = ImVec2(200, 150), ImVec2(520, 400) -- drag start/end, down-right +local DIRS = { "none", "dr", "ul", "ur", "dl" } +local CORNERS = { + dr = { A, B }, ul = { B, A }, + ur = { ImVec2(A.x, B.y), ImVec2(B.x, A.y) }, dl = { ImVec2(B.x, A.y), ImVec2(A.x, B.y) }, +} +local di, pf, res = 1, 0, {} +game:GetService("RunService").Stepped:Connect(function() + local d = DIRS[di] + if not d then return end + pf += 1 + G.ImGui_ImplRoblox.NewFrame() + io.DeltaTime = 1 / 60 + ImGui.NewFrame() + local c = CORNERS[d] + if c then + local dl = ImGui.GetForegroundDrawList() + dl:AddRectFilled(c[1], c[2], 0x6496FF32) + dl:AddRect(c[1], c[2], 0xFFFF9664, 0, 2) + dl:AddRectFilled(c[1], c[2], 0xFF00FF00, 12) -- rounded too + end + ImGui.Render() + G.ImGui_ImplRoblox.RenderDrawData(ImGui.GetDrawData()) + if pf == 4 then + res[d] = composite(game:GetService("Players").LocalPlayer.PlayerGui:FindFirstChild("ImGui")) + print("RECT", d, res[d]) + di += 1; pf = 0 + if not DIRS[di] then + local ok = res.dr ~= res.none and res.ul == res.dr and res.ur == res.dr and res.dl == res.dr + print(ok and "RECTFLIP OK" or "RECTFLIP MISMATCH") + end + end +end)