aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.Frontend/GraphicsSubsystem
diff options
context:
space:
mode:
authorMichael <[email protected]>2017-08-08 08:14:14 -0400
committerMichael <[email protected]>2017-08-08 08:14:14 -0400
commit950b31ace3b599b40528d7fc030dfb9d6a342932 (patch)
tree05a30be98d38f189524fb28afe93e91b12c23874 /ShiftOS.Frontend/GraphicsSubsystem
parent326d29db45b18a2d5c11012475c65b24e4c96d26 (diff)
downloadshiftos_thereturn-950b31ace3b599b40528d7fc030dfb9d6a342932.tar.gz
shiftos_thereturn-950b31ace3b599b40528d7fc030dfb9d6a342932.tar.bz2
shiftos_thereturn-950b31ace3b599b40528d7fc030dfb9d6a342932.zip
spam
Diffstat (limited to 'ShiftOS.Frontend/GraphicsSubsystem')
-rw-r--r--ShiftOS.Frontend/GraphicsSubsystem/GraphicsContext.cs15
1 files changed, 14 insertions, 1 deletions
diff --git a/ShiftOS.Frontend/GraphicsSubsystem/GraphicsContext.cs b/ShiftOS.Frontend/GraphicsSubsystem/GraphicsContext.cs
index 5b7a02e..e6479e9 100644
--- a/ShiftOS.Frontend/GraphicsSubsystem/GraphicsContext.cs
+++ b/ShiftOS.Frontend/GraphicsSubsystem/GraphicsContext.cs
@@ -147,6 +147,19 @@ namespace ShiftOS.Frontend.GraphicsSubsystem
public static List<TextCache> StringCaches = new List<TextCache>();
+ public TextCache GetCache(string text, System.Drawing.Font font, int wrapWidth)
+ {
+ //Don't use LINQ, it could be a performance bottleneck.
+ var caches = StringCaches.ToArray();
+ for (int i = 0; i < caches.Length; i++)
+ {
+ var cache = caches[i];
+ if (cache.Text == text && cache.FontFamily == font && cache.WrapWidth == wrapWidth)
+ return cache;
+ }
+ return null;
+ }
+
public void DrawString(string text, int x, int y, Color color, System.Drawing.Font font, int wrapWidth = 0)
{
if (string.IsNullOrEmpty(text))
@@ -154,7 +167,7 @@ namespace ShiftOS.Frontend.GraphicsSubsystem
x += _startx;
y += _starty;
var measure = MeasureString(text, font, wrapWidth);
- var cache = StringCaches.FirstOrDefault(z => z.Text == text && z.FontFamily == font && z.WrapWidth == wrapWidth);
+ var cache = GetCache(text, font, wrapWidth);
if (cache == null)
{
using (var bmp = new System.Drawing.Bitmap((int)measure.X, (int)measure.Y))