aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.Frontend/Apps/Terminal.cs
diff options
context:
space:
mode:
authorMichael <[email protected]>2017-07-05 08:43:35 -0400
committerMichael <[email protected]>2017-07-05 08:43:35 -0400
commit4f41f51267e04d752d3d438f70f06a7a37975f5d (patch)
tree22036cb834d9915d44c527da55adfdab58a3d529 /ShiftOS.Frontend/Apps/Terminal.cs
parent2adb8859edb95921e8f6d3cbb41fdc349825d6f8 (diff)
downloadshiftos_thereturn-4f41f51267e04d752d3d438f70f06a7a37975f5d.tar.gz
shiftos_thereturn-4f41f51267e04d752d3d438f70f06a7a37975f5d.tar.bz2
shiftos_thereturn-4f41f51267e04d752d3d438f70f06a7a37975f5d.zip
HEAVILY optimize skins
Diffstat (limited to 'ShiftOS.Frontend/Apps/Terminal.cs')
-rw-r--r--ShiftOS.Frontend/Apps/Terminal.cs48
1 files changed, 25 insertions, 23 deletions
diff --git a/ShiftOS.Frontend/Apps/Terminal.cs b/ShiftOS.Frontend/Apps/Terminal.cs
index a5d465e..67c7f7f 100644
--- a/ShiftOS.Frontend/Apps/Terminal.cs
+++ b/ShiftOS.Frontend/Apps/Terminal.cs
@@ -144,21 +144,19 @@ namespace ShiftOS.Frontend.Apps
if(!string.IsNullOrEmpty(Text))
using (var gfx = Graphics.FromImage(new Bitmap(1, 1)))
{
- var cursorpos = GetPointAtIndex(gfx);
- var caretSize = gfx.SmartMeasureString(Text.ToString(), LoadedSkin.TerminalFont, Width - 4);
- float initial = (((float)Math.Floor(caretSize.Height)) + cursorpos.Y) - _vertOffset;
- if (initial < 0)
- {
- float difference = initial - Height;
- _vertOffset = initial + difference;
- }
- if (initial > Height)
- {
- float difference = initial - Height;
- _vertOffset = initial - difference;
+ var textsize = gfx.SmartMeasureString(Text, LoadedSkin.TerminalFont, Width);
+ float initial = textsize.Height - _vertOffset;
+ if(initial > Height)
+ {
+ float difference = Height - initial;
+ _vertOffset = initial - difference;
+ }
+ else if(initial < 0)
+ {
+ float difference = Height - initial;
+ _vertOffset = initial + difference;
+ }
}
-
- }
}
protected override void OnLayout()
@@ -181,7 +179,7 @@ namespace ShiftOS.Frontend.Apps
for (int l = 0; l < line; l++)
{
lineindex += Lines[l].Length;
- var stringMeasure = gfx.SmartMeasureString(Lines[l], LoadedSkin.TerminalFont, Width - 4);
+ var stringMeasure = gfx.SmartMeasureString(Lines[l] == "\r" ? " " : Lines[l], LoadedSkin.TerminalFont, Width - 4);
vertMeasure += (int)stringMeasure.Height;
}
@@ -320,7 +318,14 @@ namespace ShiftOS.Frontend.Apps
//Draw the caret.
if (IsFocusedControl)
{
-// gfx.FillRectangle(new SolidBrush(LoadedSkin.TerminalForeColorCC.ToColor()), new RectangleF(new PointF(CaretPosition.X, CaretPosition.Y - _vertOffset), new SizeF(2, CaretSize.Height)));
+ PointF cursorPos;
+ using (var cgfx = System.Drawing.Graphics.FromImage(new System.Drawing.Bitmap(1, 1)))
+ {
+ cursorPos = GetPointAtIndex(cgfx);
+
+ }
+ var cursorSize = gfx.MeasureString(Text[Index-1].ToString(), LoadedSkin.TerminalFont);
+ gfx.DrawRectangle((int)cursorPos.X, (int)cursorPos.Y - (int)_vertOffset, (int)cursorSize.X, (int)cursorSize.Y, LoadedSkin.TerminalForeColorCC.ToColor().ToMonoColor());
}//Draw the text
@@ -382,19 +387,16 @@ namespace ShiftOS.Frontend.Apps
var textformat = new StringFormat(StringFormat.GenericTypographic);
textformat.FormatFlags = StringFormatFlags.MeasureTrailingSpaces;
textformat.Trimming = StringTrimming.None;
+ textformat.FormatFlags |= StringFormatFlags.NoClip;
+
+ gfx.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
var measure = gfx.MeasureString(s, font, width, textformat);
return new SizeF((float)Math.Ceiling(measure.Width), (float)Math.Ceiling(measure.Height));
}
public static SizeF SmartMeasureString(this Graphics gfx, string s, Font font)
{
- if (string.IsNullOrEmpty(s))
- s = " ";
- var textformat = new StringFormat(StringFormat.GenericTypographic);
- textformat.FormatFlags = StringFormatFlags.MeasureTrailingSpaces;
- textformat.Trimming = StringTrimming.None;
- var measure = gfx.MeasureString(s, font, int.MaxValue, textformat);
- return new SizeF((float)Math.Ceiling(measure.Width), (float)Math.Floor(measure.Height));
+ return SmartMeasureString(gfx, s, font, int.MaxValue);
}
}