From 087b407f468ba8647a94aad0c933825c2239b6d9 Mon Sep 17 00:00:00 2001 From: RoosterDragon Date: Fri, 10 Apr 2015 00:12:18 +0100 Subject: [PATCH] Avoid ScrollPanelWidget drawing invisible child items. If child items in a scroll panel will be outside the scissor area, then we can avoid drawing them at all. If a scroll panel has many items, this reduces to the draw cost closer to those visible in the panel, rather than costing for all the items. --- OpenRA.Mods.Common/Widgets/ScrollPanelWidget.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/OpenRA.Mods.Common/Widgets/ScrollPanelWidget.cs b/OpenRA.Mods.Common/Widgets/ScrollPanelWidget.cs index 41485f57e4..e0abd95317 100644 --- a/OpenRA.Mods.Common/Widgets/ScrollPanelWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ScrollPanelWidget.cs @@ -156,10 +156,13 @@ namespace OpenRA.Mods.Common.Widgets WidgetUtils.DrawRGBA(ChromeProvider.GetImage("scrollbar", downPressed || downDisabled ? "down_pressed" : "down_arrow"), new float2(downButtonRect.Left + downOffset, downButtonRect.Top + downOffset)); - Game.Renderer.EnableScissor(backgroundRect.InflateBy(-1, -1, -1, -1)); + var drawBounds = backgroundRect.InflateBy(-1, -1, -1, -1); + Game.Renderer.EnableScissor(drawBounds); + drawBounds.Offset((-ChildOrigin).ToPoint()); foreach (var child in Children) - child.DrawOuter(); + if (child.Bounds.IntersectsWith(drawBounds)) + child.DrawOuter(); Game.Renderer.DisableScissor(); }