From 8a09bb8127a14abfa4d7f7d6923c3a562cba0971 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Tue, 4 Mar 2025 13:38:37 +0000 Subject: [PATCH] Fix #11226: Don't draw story page elements that won't be visible. (#13736) When drawing the story page elements, all of them were drawn even if they are not visible. This can be a significant performance hit for long strings. --- src/story_gui.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/story_gui.cpp b/src/story_gui.cpp index a9108508ea..1880f49730 100644 --- a/src/story_gui.cpp +++ b/src/story_gui.cpp @@ -706,7 +706,11 @@ public: /* Page elements */ this->EnsureStoryPageElementLayout(); for (const LayoutCacheElement &ce : this->layout_cache) { + if (ce.bounds.bottom - scrollpos < fr.top) continue; + y_offset = ce.bounds.top - scrollpos; + if (y_offset > fr.bottom) return; + switch (ce.pe->type) { case SPET_TEXT: y_offset = DrawStringMultiLine(ce.bounds.left, ce.bounds.right, ce.bounds.top - scrollpos, ce.bounds.bottom - scrollpos,