2017-07-03 22:03:58 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2017-07-04 09:52:49 -04:00
|
|
|
|
using System.Diagnostics;
|
2017-07-03 22:03:58 -04:00
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
2017-07-04 09:52:49 -04:00
|
|
|
|
using System.Text.RegularExpressions;
|
2017-07-03 22:03:58 -04:00
|
|
|
|
using System.Threading.Tasks;
|
2017-07-19 16:08:33 -04:00
|
|
|
|
using Microsoft.Xna.Framework;
|
2017-07-04 09:52:49 -04:00
|
|
|
|
using Microsoft.Xna.Framework.Input;
|
2017-07-03 22:03:58 -04:00
|
|
|
|
using ShiftOS.Engine;
|
|
|
|
|
using ShiftOS.Frontend.GraphicsSubsystem;
|
|
|
|
|
using static ShiftOS.Engine.SkinEngine;
|
|
|
|
|
|
|
|
|
|
namespace ShiftOS.Frontend.Apps
|
|
|
|
|
{
|
|
|
|
|
[FileHandler("Shell script", ".trm", "fileicontrm")]
|
|
|
|
|
[Launcher("{TITLE_TERMINAL}", false, null, "{AL_UTILITIES}")]
|
|
|
|
|
[WinOpen("{WO_TERMINAL}")]
|
|
|
|
|
[DefaultTitle("{TITLE_TERMINAL}")]
|
|
|
|
|
[DefaultIcon("iconTerminal")]
|
|
|
|
|
public class Terminal : GUI.Control, IShiftOSWindow
|
|
|
|
|
{
|
|
|
|
|
private TerminalControl _terminal = null;
|
|
|
|
|
|
|
|
|
|
public Terminal()
|
|
|
|
|
{
|
|
|
|
|
Width = 493;
|
|
|
|
|
Height = 295;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnLoad()
|
|
|
|
|
{
|
|
|
|
|
_terminal = new Apps.TerminalControl();
|
|
|
|
|
_terminal.Dock = GUI.DockStyle.Fill;
|
|
|
|
|
AddControl(_terminal);
|
|
|
|
|
AppearanceManager.ConsoleOut = _terminal;
|
|
|
|
|
AppearanceManager.StartConsoleOut();
|
2017-07-04 10:07:20 -04:00
|
|
|
|
TerminalBackend.PrintPrompt();
|
|
|
|
|
SaveSystem.GameReady += () =>
|
|
|
|
|
{
|
2017-07-13 08:40:47 -04:00
|
|
|
|
Console.WriteLine("[sessionmgr] Starting system UI...");
|
|
|
|
|
AppearanceManager.SetupWindow(new SystemStatus());
|
|
|
|
|
TerminalBackend.PrintPrompt();
|
2017-07-04 10:07:20 -04:00
|
|
|
|
};
|
2017-07-03 22:03:58 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-19 16:08:33 -04:00
|
|
|
|
protected override void OnLayout(GameTime gameTime)
|
2017-07-03 22:03:58 -04:00
|
|
|
|
{
|
|
|
|
|
if (ContainsFocusedControl || IsFocusedControl)
|
|
|
|
|
AppearanceManager.ConsoleOut = _terminal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnSkinLoad()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool OnUnload()
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnUpgrade()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class TerminalControl : GUI.TextInput, ITerminalWidget
|
|
|
|
|
{
|
2017-07-04 09:52:49 -04:00
|
|
|
|
public TerminalControl()
|
|
|
|
|
{
|
|
|
|
|
Dock = GUI.DockStyle.Fill;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-03 22:03:58 -04:00
|
|
|
|
public string[] Lines
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-07-04 09:52:49 -04:00
|
|
|
|
return Text.Split(new[] { "\r\n" }, StringSplitOptions.None);
|
2017-07-03 22:03:58 -04:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Clear()
|
|
|
|
|
{
|
|
|
|
|
Text = "";
|
|
|
|
|
Index = 0;
|
2017-07-04 17:57:29 -04:00
|
|
|
|
_vertOffset = 0;
|
2017-07-03 22:03:58 -04:00
|
|
|
|
Invalidate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SelectBottom()
|
|
|
|
|
{
|
|
|
|
|
Index = Text.Length - 1;
|
|
|
|
|
RecalculateLayout();
|
|
|
|
|
InvalidateTopLevel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Write(string text)
|
|
|
|
|
{
|
|
|
|
|
Engine.Desktop.InvokeOnWorkerThread(() =>
|
|
|
|
|
{
|
2017-07-04 17:57:29 -04:00
|
|
|
|
Text += Localization.Parse(text);
|
2017-07-03 22:03:58 -04:00
|
|
|
|
SelectBottom();
|
|
|
|
|
Index += text.Length;
|
|
|
|
|
RecalculateLayout();
|
|
|
|
|
InvalidateTopLevel();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void WriteLine(string text)
|
|
|
|
|
{
|
|
|
|
|
Write(text + Environment.NewLine);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public int GetCurrentLine()
|
|
|
|
|
{
|
|
|
|
|
int line = 0;
|
2017-07-19 13:06:39 -04:00
|
|
|
|
for(int i = 0; i < Index; i++)
|
2017-07-03 22:03:58 -04:00
|
|
|
|
{
|
|
|
|
|
if(Text[i]=='\n')
|
|
|
|
|
{
|
|
|
|
|
line++;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-07-19 13:06:39 -04:00
|
|
|
|
return line;
|
2017-07-03 22:03:58 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float _vertOffset = 0.0f;
|
|
|
|
|
|
|
|
|
|
protected void RecalculateLayout()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-19 16:08:33 -04:00
|
|
|
|
private bool blinkStatus = false;
|
|
|
|
|
private double blinkTime = 0.0;
|
|
|
|
|
|
|
|
|
|
protected override void OnLayout(GameTime gameTime)
|
2017-07-04 09:52:49 -04:00
|
|
|
|
{
|
2017-07-19 16:08:33 -04:00
|
|
|
|
blinkTime += gameTime.ElapsedGameTime.TotalMilliseconds;
|
|
|
|
|
if (blinkTime > 500.0)
|
|
|
|
|
blinkTime = 0;
|
|
|
|
|
bool prev = blinkStatus;
|
|
|
|
|
blinkStatus = blinkTime > 250.0;
|
|
|
|
|
if (prev != blinkStatus)
|
|
|
|
|
Invalidate();
|
2017-07-04 09:52:49 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-03 22:03:58 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the X and Y coordinates (in pixels) of the caret.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="gfx">A <see cref="System.Drawing.Graphics"/> object used for font measurements</param>
|
|
|
|
|
/// <returns>An absolute fucking mess. Seriously, can someone fix this method so it uhh WORKS PROPERLY?</returns>
|
2017-07-19 16:08:33 -04:00
|
|
|
|
public System.Drawing.Point GetPointAtIndex(Graphics gfx)
|
2017-07-03 22:03:58 -04:00
|
|
|
|
{
|
2017-07-04 09:52:49 -04:00
|
|
|
|
int vertMeasure = 2;
|
|
|
|
|
int horizMeasure = 2;
|
2017-07-04 17:57:29 -04:00
|
|
|
|
int lineindex = 0;
|
|
|
|
|
int line = GetCurrentLine();
|
|
|
|
|
for (int l = 0; l < line; l++)
|
2017-07-04 09:52:49 -04:00
|
|
|
|
{
|
2017-07-04 17:57:29 -04:00
|
|
|
|
lineindex += Lines[l].Length;
|
2017-07-05 08:43:35 -04:00
|
|
|
|
var stringMeasure = gfx.SmartMeasureString(Lines[l] == "\r" ? " " : Lines[l], LoadedSkin.TerminalFont, Width - 4);
|
2017-07-04 17:57:29 -04:00
|
|
|
|
vertMeasure += (int)stringMeasure.Height;
|
2017-07-04 09:52:49 -04:00
|
|
|
|
|
2017-07-03 22:03:58 -04:00
|
|
|
|
}
|
2017-07-04 17:57:29 -04:00
|
|
|
|
var lnMeasure = gfx.SmartMeasureString(Text.Substring(lineindex, Index - lineindex), LoadedSkin.TerminalFont);
|
|
|
|
|
int w = (int)Math.Floor(lnMeasure.Width);
|
2017-07-19 13:06:39 -04:00
|
|
|
|
while (w > Width - 4)
|
|
|
|
|
{
|
2017-07-04 17:57:29 -04:00
|
|
|
|
w = w - (Width - 4);
|
2017-07-19 13:06:39 -04:00
|
|
|
|
vertMeasure += (int)lnMeasure.Height;
|
|
|
|
|
}
|
|
|
|
|
horizMeasure += w;
|
2017-07-19 16:08:33 -04:00
|
|
|
|
return new System.Drawing.Point(horizMeasure, vertMeasure);
|
2017-07-03 22:03:58 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-04 17:57:29 -04:00
|
|
|
|
private PointF CaretPosition = new PointF(2, 2);
|
|
|
|
|
private Size CaretSize = new Size(2, 15);
|
|
|
|
|
|
2017-07-04 09:52:49 -04:00
|
|
|
|
protected override void OnKeyEvent(KeyEvent a)
|
2017-07-03 22:03:58 -04:00
|
|
|
|
{
|
2017-07-04 09:52:49 -04:00
|
|
|
|
if (a.Key == Keys.Enter)
|
2017-07-03 22:03:58 -04:00
|
|
|
|
{
|
2017-07-04 09:52:49 -04:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (!TerminalBackend.PrefixEnabled)
|
|
|
|
|
{
|
|
|
|
|
string textraw = Lines[Lines.Length - 1];
|
|
|
|
|
TerminalBackend.SendText(textraw);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var text = Lines;
|
|
|
|
|
var text2 = text[text.Length - 1];
|
|
|
|
|
var text3 = "";
|
|
|
|
|
var text4 = Regex.Replace(text2, @"\t|\n|\r", "");
|
2017-07-19 16:08:33 -04:00
|
|
|
|
WriteLine("");
|
|
|
|
|
|
2017-07-04 09:52:49 -04:00
|
|
|
|
if (TerminalBackend.PrefixEnabled)
|
|
|
|
|
{
|
2017-07-13 08:40:47 -04:00
|
|
|
|
text3 = text4.Remove(0, $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ".Length);
|
2017-07-04 09:52:49 -04:00
|
|
|
|
}
|
2017-07-19 16:08:33 -04:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(text3))
|
|
|
|
|
{
|
2017-07-04 09:52:49 -04:00
|
|
|
|
TerminalBackend.LastCommand = text3;
|
|
|
|
|
TerminalBackend.SendText(text4);
|
|
|
|
|
if (TerminalBackend.InStory == false)
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
var result = SkinEngine.LoadedSkin.CurrentParser.ParseCommand(text3);
|
|
|
|
|
|
|
|
|
|
if (result.Equals(default(KeyValuePair<string, Dictionary<string, string>>)))
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("{ERR_SYNTAXERROR}");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
TerminalBackend.InvokeCommand(result.Key, result.Value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
}
|
2017-07-19 16:08:33 -04:00
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
if (TerminalBackend.PrefixEnabled)
|
|
|
|
|
{
|
|
|
|
|
TerminalBackend.PrintPrompt();
|
|
|
|
|
}
|
|
|
|
|
AppearanceManager.CurrentPosition = 0;
|
|
|
|
|
|
|
|
|
|
}
|
2017-07-04 09:52:49 -04:00
|
|
|
|
}
|
|
|
|
|
else if (a.Key == Keys.Back)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var tostring3 = Lines[Lines.Length - 1];
|
|
|
|
|
var tostringlen = tostring3.Length + 1;
|
2017-07-13 08:40:47 -04:00
|
|
|
|
var workaround = $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ";
|
2017-07-04 09:52:49 -04:00
|
|
|
|
var derp = workaround.Length + 1;
|
|
|
|
|
if (tostringlen != derp)
|
|
|
|
|
{
|
|
|
|
|
AppearanceManager.CurrentPosition--;
|
|
|
|
|
base.OnKeyEvent(a);
|
|
|
|
|
RecalculateLayout();
|
|
|
|
|
InvalidateTopLevel();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
Debug.WriteLine("Drunky alert in terminal.");
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-07-17 14:34:59 -04:00
|
|
|
|
else if(a.Key == Keys.Right)
|
|
|
|
|
{
|
|
|
|
|
if(Index < Text.Length)
|
|
|
|
|
{
|
|
|
|
|
Index++;
|
|
|
|
|
AppearanceManager.CurrentPosition++;
|
|
|
|
|
RecalculateLayout();
|
|
|
|
|
InvalidateTopLevel();
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-07-04 09:52:49 -04:00
|
|
|
|
else if (a.Key == Keys.Left)
|
|
|
|
|
{
|
|
|
|
|
if (SaveSystem.CurrentSave != null)
|
|
|
|
|
{
|
|
|
|
|
var getstring = Lines[Lines.Length - 1];
|
|
|
|
|
var stringlen = getstring.Length + 1;
|
2017-07-13 08:40:47 -04:00
|
|
|
|
var header = $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ";
|
2017-07-04 09:52:49 -04:00
|
|
|
|
var headerlen = header.Length + 1;
|
|
|
|
|
var selstart = Index;
|
|
|
|
|
var remstrlen = Text.Length - stringlen;
|
|
|
|
|
var finalnum = selstart - remstrlen;
|
|
|
|
|
|
2017-07-17 14:34:59 -04:00
|
|
|
|
if (finalnum > headerlen)
|
2017-07-04 09:52:49 -04:00
|
|
|
|
{
|
|
|
|
|
AppearanceManager.CurrentPosition--;
|
|
|
|
|
base.OnKeyEvent(a);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (a.Key == Keys.Up)
|
|
|
|
|
{
|
|
|
|
|
var tostring3 = Lines[Lines.Length - 1];
|
2017-07-13 08:40:47 -04:00
|
|
|
|
if (tostring3 == $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ")
|
2017-07-04 09:52:49 -04:00
|
|
|
|
Console.Write(TerminalBackend.LastCommand);
|
|
|
|
|
ConsoleEx.OnFlush?.Invoke();
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (TerminalBackend.InStory)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (a.KeyChar != '\0')
|
|
|
|
|
{
|
2017-07-04 10:07:20 -04:00
|
|
|
|
Text = Text.Insert(Index, a.KeyChar.ToString());
|
|
|
|
|
Index++;
|
2017-07-04 09:52:49 -04:00
|
|
|
|
AppearanceManager.CurrentPosition++;
|
2017-07-04 17:57:29 -04:00
|
|
|
|
// RecalculateLayout();
|
2017-07-04 09:52:49 -04:00
|
|
|
|
InvalidateTopLevel();
|
|
|
|
|
}
|
2017-07-03 22:03:58 -04:00
|
|
|
|
}
|
2017-07-19 16:08:33 -04:00
|
|
|
|
blinkStatus = true;
|
|
|
|
|
blinkTime = 250;
|
2017-07-03 22:03:58 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-04 17:57:29 -04:00
|
|
|
|
protected override void OnPaint(GraphicsContext gfx)
|
2017-07-04 09:52:49 -04:00
|
|
|
|
{
|
2017-07-04 17:57:29 -04:00
|
|
|
|
gfx.Clear(LoadedSkin.TerminalBackColorCC.ToColor().ToMonoColor());
|
2017-07-03 22:03:58 -04:00
|
|
|
|
if (!string.IsNullOrEmpty(Text))
|
|
|
|
|
{
|
|
|
|
|
//Draw the caret.
|
2017-07-19 16:08:33 -04:00
|
|
|
|
if (blinkStatus == true)
|
2017-07-03 22:03:58 -04:00
|
|
|
|
{
|
2017-07-19 16:08:33 -04:00
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
var lineMeasure = gfx.MeasureString(Lines[GetCurrentLine()], LoadedSkin.TerminalFont);
|
|
|
|
|
if (cursorPos.X > lineMeasure.X)
|
|
|
|
|
{
|
|
|
|
|
cursorPos.X = lineMeasure.X;
|
|
|
|
|
}
|
2017-07-19 13:06:39 -04:00
|
|
|
|
|
2017-07-19 16:08:33 -04:00
|
|
|
|
gfx.DrawRectangle((int)cursorPos.X, (int)cursorPos.Y - (int)_vertOffset, (int)cursorSize.X, (int)cursorSize.Y, LoadedSkin.TerminalForeColorCC.ToColor().ToMonoColor());
|
2017-07-19 13:06:39 -04:00
|
|
|
|
}
|
|
|
|
|
//Draw the text
|
2017-07-03 22:03:58 -04:00
|
|
|
|
|
2017-07-04 17:57:29 -04:00
|
|
|
|
|
|
|
|
|
gfx.DrawString(Text, 2, 2 - (int)Math.Floor(_vertOffset), LoadedSkin.TerminalForeColorCC.ToColor().ToMonoColor(), LoadedSkin.TerminalFont, Width - 4);
|
2017-07-03 22:03:58 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class ConsoleColorExtensions
|
|
|
|
|
{
|
2017-07-19 16:08:33 -04:00
|
|
|
|
public static System.Drawing.Color ToColor(this ConsoleColor cc)
|
2017-07-03 22:03:58 -04:00
|
|
|
|
{
|
|
|
|
|
switch (cc)
|
|
|
|
|
{
|
|
|
|
|
case ConsoleColor.Black:
|
2017-07-19 16:08:33 -04:00
|
|
|
|
return System.Drawing.Color.Black;
|
2017-07-03 22:03:58 -04:00
|
|
|
|
case ConsoleColor.Blue:
|
2017-07-19 16:08:33 -04:00
|
|
|
|
return System.Drawing.Color.Blue;
|
2017-07-03 22:03:58 -04:00
|
|
|
|
case ConsoleColor.Cyan:
|
2017-07-19 16:08:33 -04:00
|
|
|
|
return System.Drawing.Color.Cyan;
|
2017-07-03 22:03:58 -04:00
|
|
|
|
case ConsoleColor.DarkBlue:
|
2017-07-19 16:08:33 -04:00
|
|
|
|
return System.Drawing.Color.DarkBlue;
|
2017-07-03 22:03:58 -04:00
|
|
|
|
case ConsoleColor.DarkCyan:
|
2017-07-19 16:08:33 -04:00
|
|
|
|
return System.Drawing.Color.DarkCyan;
|
2017-07-03 22:03:58 -04:00
|
|
|
|
case ConsoleColor.DarkGray:
|
2017-07-19 16:08:33 -04:00
|
|
|
|
return System.Drawing.Color.DarkGray;
|
2017-07-03 22:03:58 -04:00
|
|
|
|
case ConsoleColor.DarkGreen:
|
2017-07-19 16:08:33 -04:00
|
|
|
|
return System.Drawing.Color.DarkGreen;
|
2017-07-03 22:03:58 -04:00
|
|
|
|
case ConsoleColor.DarkMagenta:
|
2017-07-19 16:08:33 -04:00
|
|
|
|
return System.Drawing.Color.DarkMagenta;
|
2017-07-03 22:03:58 -04:00
|
|
|
|
case ConsoleColor.DarkRed:
|
2017-07-19 16:08:33 -04:00
|
|
|
|
return System.Drawing.Color.DarkRed;
|
2017-07-03 22:03:58 -04:00
|
|
|
|
case ConsoleColor.DarkYellow:
|
2017-07-19 16:08:33 -04:00
|
|
|
|
return System.Drawing.Color.Orange;
|
2017-07-03 22:03:58 -04:00
|
|
|
|
case ConsoleColor.Gray:
|
2017-07-19 16:08:33 -04:00
|
|
|
|
return System.Drawing.Color.Gray;
|
2017-07-03 22:03:58 -04:00
|
|
|
|
case ConsoleColor.Green:
|
2017-07-19 16:08:33 -04:00
|
|
|
|
return System.Drawing.Color.Green;
|
2017-07-03 22:03:58 -04:00
|
|
|
|
case ConsoleColor.Magenta:
|
2017-07-19 16:08:33 -04:00
|
|
|
|
return System.Drawing.Color.Magenta;
|
2017-07-03 22:03:58 -04:00
|
|
|
|
case ConsoleColor.Red:
|
2017-07-19 16:08:33 -04:00
|
|
|
|
return System.Drawing.Color.Red;
|
2017-07-03 22:03:58 -04:00
|
|
|
|
case ConsoleColor.White:
|
2017-07-19 16:08:33 -04:00
|
|
|
|
return System.Drawing.Color.White;
|
2017-07-03 22:03:58 -04:00
|
|
|
|
case ConsoleColor.Yellow:
|
2017-07-19 16:08:33 -04:00
|
|
|
|
return System.Drawing.Color.Yellow;
|
2017-07-03 22:03:58 -04:00
|
|
|
|
}
|
2017-07-19 16:08:33 -04:00
|
|
|
|
return System.Drawing.Color.Empty;
|
2017-07-03 22:03:58 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class GraphicsExtensions
|
|
|
|
|
{
|
|
|
|
|
public static SizeF SmartMeasureString(this Graphics gfx, string s, Font font, int width)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(s))
|
|
|
|
|
s = " ";
|
|
|
|
|
var textformat = new StringFormat(StringFormat.GenericTypographic);
|
2017-07-19 16:08:33 -04:00
|
|
|
|
textformat.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces;
|
|
|
|
|
//textformat.Trimming = StringTrimming.Character;
|
|
|
|
|
//textformat.FormatFlags |= StringFormatFlags.NoClip;
|
2017-07-05 08:43:35 -04:00
|
|
|
|
|
2017-07-19 16:08:33 -04:00
|
|
|
|
gfx.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
|
2017-07-04 09:52:49 -04:00
|
|
|
|
var measure = gfx.MeasureString(s, font, width, textformat);
|
2017-07-04 17:57:29 -04:00
|
|
|
|
return new SizeF((float)Math.Ceiling(measure.Width), (float)Math.Ceiling(measure.Height));
|
2017-07-03 22:03:58 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static SizeF SmartMeasureString(this Graphics gfx, string s, Font font)
|
|
|
|
|
{
|
2017-07-05 08:43:35 -04:00
|
|
|
|
return SmartMeasureString(gfx, s, font, int.MaxValue);
|
2017-07-03 22:03:58 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|