This commit is contained in:
Michael 2017-08-09 14:17:51 -04:00
parent 72fe64f28d
commit cc6fc6c008
13 changed files with 59 additions and 75 deletions

View file

@ -70,11 +70,7 @@ namespace ShiftOS.Frontend.Apps
int inRight = (Width - _send.Width - 20);
_input.AutoSize = false;
_input.Width = inRight - _input.X;
if (requiresRepaint)
{
Invalidate();
requiresRepaint = false;
}
}
public bool ChannelConnected
@ -171,13 +167,13 @@ namespace ShiftOS.Frontend.Apps
break;
var tsProper = $"[{msg.Timestamp.Hour.ToString("##")}:{msg.Timestamp.Minute.ToString("##")}]";
var nnProper = $"<{msg.Author}>";
var tsMeasure = gfx.MeasureString(tsProper, LoadedSkin.TerminalFont);
var nnMeasure = gfx.MeasureString(nnProper, LoadedSkin.TerminalFont);
var tsMeasure = GraphicsContext.MeasureString(tsProper, LoadedSkin.TerminalFont);
var nnMeasure = GraphicsContext.MeasureString(nnProper, LoadedSkin.TerminalFont);
int old = vertSeparatorLeft;
vertSeparatorLeft = (int)Math.Round(Math.Max(vertSeparatorLeft, tsMeasure.X + nnGap + nnMeasure.X + 2));
if (old != vertSeparatorLeft)
requiresRepaint = true;
var msgMeasure = gfx.MeasureString(msg.Message, LoadedSkin.TerminalFont, (Width - vertSeparatorLeft - 4) - messagesFromRight);
var msgMeasure = GraphicsContext.MeasureString(msg.Message, LoadedSkin.TerminalFont, (Width - vertSeparatorLeft - 4) - messagesFromRight);
messagebottom -= (int)msgMeasure.Y;
gfx.DrawString(tsProper, 0, messagebottom, LoadedSkin.ControlTextColor.ToMonoColor(), LoadedSkin.TerminalFont);
var nnColor = Color.LightGreen;
@ -229,7 +225,7 @@ namespace ShiftOS.Frontend.Apps
int usersStartY = messagesTop;
foreach(var user in NetInfo.Channel.OnlineUsers.OrderBy(x=>x.Nickname))
{
var measure = gfx.MeasureString(user.Nickname, LoadedSkin.TerminalFont);
var measure = GraphicsContext.MeasureString(user.Nickname, LoadedSkin.TerminalFont);
var nnColor = Color.LightGreen;
if (user.Nickname == SaveSystem.CurrentSave.Username)

View file

@ -137,9 +137,9 @@ As you continue through your job, going further up the ranks, you will unlock ad
}
int wrapwidth = (Width - (upgradelist.X + upgradelist.Width)) - 45;
var titlemeasure = gfx.MeasureString(title, SkinEngine.LoadedSkin.Header2Font, wrapwidth);
var titlemeasure = GraphicsContext.MeasureString(title, SkinEngine.LoadedSkin.Header2Font, wrapwidth);
var descmeasure = gfx.MeasureString(desc, SkinEngine.LoadedSkin.MainFont, wrapwidth);
var descmeasure = GraphicsContext.MeasureString(desc, SkinEngine.LoadedSkin.MainFont, wrapwidth);
int availablewidth = Width - (upgradelist.X + upgradelist.Width);
int titlelocx = (availablewidth - (int)titlemeasure.X) / 2;
@ -152,7 +152,7 @@ As you continue through your job, going further up the ranks, you will unlock ad
gfx.DrawString(desc, desclocx, desclocy, SkinEngine.LoadedSkin.ControlTextColor.ToMonoColor(), SkinEngine.LoadedSkin.MainFont, wrapwidth);
string shiftorium = "Shiftorium";
var smeasure = gfx.MeasureString(shiftorium, SkinEngine.LoadedSkin.HeaderFont);
var smeasure = GraphicsContext.MeasureString(shiftorium, SkinEngine.LoadedSkin.HeaderFont);
gfx.DrawString(shiftorium, upgradelist.X + ((upgradelist.Width - (int)smeasure.X) / 2), 20, SkinEngine.LoadedSkin.ControlTextColor.ToMonoColor(), SkinEngine.LoadedSkin.HeaderFont);
}
}

View file

@ -100,7 +100,7 @@ namespace ShiftOS.Frontend.Apps
["%cp"] = codepointsToEarn.ToString()
});
var tSize = gfx.MeasureString(cp_text, SkinEngine.LoadedSkin.Header3Font);
var tSize = GraphicsContext.MeasureString(cp_text, SkinEngine.LoadedSkin.Header3Font);
var tLoc = new Vector2((Width - (int)tSize.X) / 2,
(Height - (int)tSize.Y)
@ -109,14 +109,14 @@ namespace ShiftOS.Frontend.Apps
gfx.DrawString(cp_text, (int)tLoc.X, (int)tLoc.Y, SkinEngine.LoadedSkin.ControlTextColor.ToMonoColor(), SkinEngine.LoadedSkin.Header3Font);
tSize = gfx.MeasureString(counter, SkinEngine.LoadedSkin.Header2Font);
tSize = GraphicsContext.MeasureString(counter, SkinEngine.LoadedSkin.Header2Font);
tLoc = new Vector2((Width - (int)tSize.X) / 2,
(Height - (int)tSize.Y) / 2
);
gfx.DrawString(counter, (int)tLoc.X, (int)tLoc.Y, SkinEngine.LoadedSkin.ControlTextColor.ToMonoColor(), SkinEngine.LoadedSkin.Header2Font);
tSize = gfx.MeasureString(header, SkinEngine.LoadedSkin.Header2Font);
tSize = GraphicsContext.MeasureString(header, SkinEngine.LoadedSkin.Header2Font);
tLoc = new Vector2((Width - (int)tSize.X) / 2,
(Height - (int)tSize.Y) / 4
@ -129,7 +129,7 @@ namespace ShiftOS.Frontend.Apps
["%level"] = level.ToString(),
["%time"] = secondsleft.ToString()
});
tSize = gfx.MeasureString(l, SkinEngine.LoadedSkin.Header3Font);
tSize = GraphicsContext.MeasureString(l, SkinEngine.LoadedSkin.Header3Font);
tLoc = new Vector2((Width - (int)tSize.X) / 2,
(tSize.Y)

View file

@ -93,7 +93,7 @@ namespace ShiftOS.Frontend.Apps
gfx.DrawRectangle(titlebarleft, _windowystart, titlebarwidth, titleheight, SkinTextures["titlebar"]);
}
//Now we draw the title text.
var textMeasure = gfx.MeasureString("Program window", titlefont);
var textMeasure = GraphicsContext.MeasureString("Program window", titlefont);
Vector2 textloc;
if (titletextcentered)
textloc = new Vector2((titlebarwidth - textMeasure.X) / 2,
@ -363,7 +363,7 @@ namespace ShiftOS.Frontend.Apps
{
gfx.DrawRectangle(al_left.X, dp_position + al_left.Y, holderSize.Width, holderSize.Height, SkinTextures["applauncher"]);
}
var altextmeasure = gfx.MeasureString(_skin.AppLauncherText, _skin.AppLauncherFont);
var altextmeasure = GraphicsContext.MeasureString(_skin.AppLauncherText, _skin.AppLauncherFont);
int altextx = _previewxstart + (holderSize.Width - (int)altextmeasure.X) / 2;
int altexty = _desktopystart + (holderSize.Height - (int)altextmeasure.Y) / 2;
gfx.DrawString(_skin.AppLauncherText, altextx, altexty, _skin.AppLauncherTextColor.ToMonoColor(), _skin.AppLauncherFont);
@ -373,7 +373,7 @@ namespace ShiftOS.Frontend.Apps
var panelClockTextColor = _skin.DesktopPanelClockColor.ToMonoColor();
string dateTimeString = "00:00:00 - localhost";
var measure = gfx.MeasureString(dateTimeString, _skin.DesktopPanelClockFont);
var measure = GraphicsContext.MeasureString(dateTimeString, _skin.DesktopPanelClockFont);
int panelclockleft = _previewxstart + (dp_width - (int)measure.X);
int panelclockwidth = (dp_width - panelclockleft);

View file

@ -140,18 +140,15 @@ namespace ShiftOS.Frontend.Apps
protected void RecalculateLayout()
{
using(var gfx = Graphics.FromImage(new Bitmap(1, 1)))
var cloc = GetPointAtIndex();
var csize = GraphicsContext.MeasureString("#", new Font(LoadedSkin.TerminalFont.Name, LoadedSkin.TerminalFont.Size * _zoomFactor, LoadedSkin.TerminalFont.Style));
if (cloc.Y - _vertOffset < 0)
{
var cloc = GetPointAtIndex(gfx);
var csize = gfx.MeasureString("#", new Font(LoadedSkin.TerminalFont.Name, LoadedSkin.TerminalFont.Size * _zoomFactor, LoadedSkin.TerminalFont.Style));
if(cloc.Y - _vertOffset < 0)
{
_vertOffset += cloc.Y - _vertOffset;
}
while((cloc.Y + csize.Height) - _vertOffset > Height)
{
_vertOffset += csize.Height;
}
_vertOffset += cloc.Y - _vertOffset;
}
while ((cloc.Y + csize.Y) - _vertOffset > Height)
{
_vertOffset += csize.Y;
}
}
@ -176,23 +173,23 @@ namespace ShiftOS.Frontend.Apps
/// </summary>
/// <param name="gfx">A <see cref="System.Drawing.Graphics"/> object used for font measurements</param>
/// <returns>the correct position of the d*ng caret. yw</returns>
public System.Drawing.Point GetPointAtIndex(Graphics gfx)
public System.Drawing.Point GetPointAtIndex()
{
if (string.IsNullOrEmpty(Text))
return new System.Drawing.Point(2, 2);
var font = new Font(LoadedSkin.TerminalFont.Name, LoadedSkin.TerminalFont.Size * _zoomFactor, LoadedSkin.TerminalFont.Style);
int currline = GetCurrentLine();
string substring = String.Join(Environment.NewLine, Lines.Take(currline + 1));
int h = (int)Math.Round(gfx.SmartMeasureString(substring, font, Width).Height - font.Height);
int h = (int)Math.Round(GraphicsContext.MeasureString(substring, font, Width).Y - font.Height);
int linestart = String.Join(Environment.NewLine, Lines.Take(GetCurrentLine())).Length;
var lineMeasure = gfx.SmartMeasureString(Text.Substring(linestart, Index - linestart), font);
int w = (int)Math.Floor(lineMeasure.Width);
var lineMeasure = GraphicsContext.MeasureString(Text.Substring(linestart, Index - linestart), font);
int w = (int)Math.Floor(lineMeasure.X);
while (w > Width)
{
w -= Width;
h += (int)lineMeasure.Height;
h += (int)lineMeasure.Y;
}
return new System.Drawing.Point(w, h);
}
@ -389,15 +386,11 @@ namespace ShiftOS.Frontend.Apps
//Draw the caret.
if (blinkStatus == true)
{
PointF cursorPos;
using (var cgfx = System.Drawing.Graphics.FromHwnd(IntPtr.Zero))
{
cursorPos = GetPointAtIndex(cgfx);
PointF cursorPos = GetPointAtIndex();
string caret = (Index < Text.Length) ? Text[Index].ToString() : " ";
var cursorSize = GraphicsContext.MeasureString(caret, font);
}
var cursorSize = gfx.MeasureString("#", font);
var lineMeasure = gfx.MeasureString(Lines[GetCurrentLine()], font);
var lineMeasure = GraphicsContext.MeasureString(Lines[GetCurrentLine()], font);
if (cursorPos.X > lineMeasure.X)
{
cursorPos.X = lineMeasure.X;
@ -465,12 +458,15 @@ namespace ShiftOS.Frontend.Apps
public static class GraphicsExtensions
{
[Obsolete("Use GraphicsContext.MeasureString instead")]
public static SizeF SmartMeasureString(this Graphics gfx, string s, Font font, int width)
{
var measure = System.Windows.Forms.TextRenderer.MeasureText(s, font, new Size(width, int.MaxValue));
return measure;
}
[Obsolete("Use GraphicsContext.MeasureString instead")]
public static SizeF SmartMeasureString(this Graphics gfx, string s, Font font)
{
return SmartMeasureString(gfx, s, font, int.MaxValue);

View file

@ -119,16 +119,14 @@ namespace ShiftOS.Frontend.Desktop
int y = 0;
int height = 0;
int[] widths = new int[items.Length];
using(var gfx = System.Drawing.Graphics.FromImage(new System.Drawing.Bitmap(1, 1)))
{
LauncherItems.Clear();
for(int i = 0; i < items.Length; i++)
{
string name = Localization.Parse(items[i].DisplayData.Name);
var measure = gfx.SmartMeasureString(name, LoadedSkin.MainFont);
if (height < (int)measure.Height)
height = (int)measure.Height;
widths[i] = 120 + (int)measure.Width;
var measure = GraphicsContext.MeasureString(name, LoadedSkin.MainFont);
if (height < (int)measure.Y)
height = (int)measure.Y;
widths[i] = 120 + (int)measure.X;
}
@ -148,7 +146,7 @@ namespace ShiftOS.Frontend.Desktop
y += item.Height;
}
}
Invalidate();
}
@ -297,7 +295,7 @@ namespace ShiftOS.Frontend.Desktop
{
gfx.DrawRectangle(al_left.X, dp_position + al_left.Y, holderSize.Width, holderSize.Height, UIManager.SkinTextures["applauncher"]);
}
var altextmeasure = gfx.MeasureString(LoadedSkin.AppLauncherText, LoadedSkin.AppLauncherFont);
var altextmeasure = GraphicsContext.MeasureString(LoadedSkin.AppLauncherText, LoadedSkin.AppLauncherFont);
int altextx = (holderSize.Width - (int)altextmeasure.X) / 2;
int altexty = (holderSize.Height - (int)altextmeasure.Y) / 2;
gfx.DrawString(LoadedSkin.AppLauncherText, altextx, altexty, LoadedSkin.AppLauncherTextColor.ToMonoColor(), LoadedSkin.AppLauncherFont);
@ -307,7 +305,7 @@ namespace ShiftOS.Frontend.Desktop
var panelClockTextColor = LoadedSkin.DesktopPanelClockColor.ToMonoColor();
var measure = gfx.MeasureString(dateTimeString, LoadedSkin.DesktopPanelClockFont);
var measure = GraphicsContext.MeasureString(dateTimeString, LoadedSkin.DesktopPanelClockFont);
int panelclockleft = Width - (int)measure.X;
int panelclockwidth = Width - panelclockleft;

View file

@ -348,7 +348,7 @@ namespace ShiftOS.Frontend.Desktop
gfx.DrawRectangle(titlebarleft, 0, titlebarwidth, titleheight, UIManager.SkinTextures["titlebar"]);
}
//Now we draw the title text.
var textMeasure = gfx.MeasureString(Text, titlefont);
var textMeasure = GraphicsContext.MeasureString(Text, titlefont);
PointF textloc;
if (titletextcentered)
textloc = new PointF((titlebarwidth - textMeasure.X) / 2,

View file

@ -20,16 +20,13 @@ namespace ShiftOS.Frontend.GUI
protected override void OnLayout(GameTime gameTime)
{
if(AutoSize == true)
if (AutoSize == true)
{
int borderwidth = SkinEngine.LoadedSkin.ButtonBorderWidth * 2;
using (var gfx = Graphics.FromImage(new Bitmap(1, 1)))
{
var measure = gfx.MeasureString(this.Text, this.Font);
Width = borderwidth + (int)measure.Width + 16;
Height = borderwidth + (int)measure.Height + 12;
}
var measure = GraphicsContext.MeasureString(this.Text, this.Font);
Width = borderwidth + (int)measure.X + 16;
Height = borderwidth + (int)measure.Y + 12;
}
}
@ -45,7 +42,7 @@ namespace ShiftOS.Frontend.GUI
gfx.DrawRectangle(0, 0, Width, Height, UIManager.SkinTextures["ControlTextColor"]);
gfx.DrawRectangle(1, 1, Width - 2, Height - 2, bgCol);
var measure = gfx.MeasureString(Text, Font);
var measure = GraphicsContext.MeasureString(Text, Font);
var loc = new Vector2((Width - measure.X) / 2, (Height - measure.Y) / 2);

View file

@ -163,7 +163,7 @@ namespace ShiftOS.Frontend.GUI
image = _images[item.ImageKey];
}
int textwidth = texwidth + (_itemimagemargin * 2);
var textmeasure = gfx.MeasureString(item.Text, LoadedSkin.MainFont, textwidth);
var textmeasure = GraphicsContext.MeasureString(item.Text, LoadedSkin.MainFont, textwidth);
yhelper = Math.Max(yhelper, _itemy + texheight + (int)textmeasure.Y);
if(image != null)

View file

@ -57,7 +57,7 @@ namespace ShiftOS.Frontend.GUI
protected override void OnPaint(GraphicsContext gfx)
{
var sMeasure = gfx.MeasureString(_text, _font, Width);
var sMeasure = GraphicsContext.MeasureString(_text, _font, Width);
PointF loc = new PointF(2, 2);
float centerH = (Width - sMeasure.X) / 2;
float centerV = (Height - sMeasure.Y) / 2;

View file

@ -136,13 +136,10 @@ namespace ShiftOS.Frontend.GraphicsSubsystem
_spritebatch.Draw(tex2, new Rectangle(x, y, width, height), tint);
}
public Vector2 MeasureString(string text, System.Drawing.Font font, int wrapWidth = int.MaxValue)
public static Vector2 MeasureString(string text, System.Drawing.Font font, int wrapWidth = int.MaxValue)
{
using(var gfx = System.Drawing.Graphics.FromHwnd(IntPtr.Zero))
{
var s = gfx.SmartMeasureString(text, font, wrapWidth);
return new Vector2((float)Math.Ceiling(s.Width), (float)Math.Ceiling(s.Height));
}
var measure = TextRenderer.MeasureText(text, font, new System.Drawing.Size(wrapWidth, int.MaxValue));
return new Vector2(measure.Width, measure.Height);
}
public static List<TextCache> StringCaches = new List<TextCache>();
@ -174,7 +171,7 @@ namespace ShiftOS.Frontend.GraphicsSubsystem
{
using (var gfx = System.Drawing.Graphics.FromImage(bmp))
{
TextRenderer.DrawText(gfx, text, font, new System.Drawing.Point(0, 0), System.Drawing.Color.White);
TextRenderer.DrawText(gfx, text, font, new System.Drawing.Rectangle(0,0,bmp.Width,bmp.Height), System.Drawing.Color.White);
}
var lck = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
var bytes = new byte[Math.Abs(lck.Stride) * lck.Height];

View file

@ -333,7 +333,7 @@ namespace ShiftOS.Frontend
gfx.DrawRectangle(0, 0, Width, Height, Color.Lerp(_redbg, _bluebg, _bglerp));
gfx.DrawRectangle(0, 0, Width / 4, Height, Color.White * 0.35F);
var measure = gfx.MeasureString(_tipText, _campaign.Font, (Width / 4) - 30);
var measure = GraphicsContext.MeasureString(_tipText, _campaign.Font, (Width / 4) - 30);
int _height = (Height - (int)measure.Y) - 30;
gfx.DrawString(_tipText, 30, _height, Color.White * _tipFade, _campaign.Font, (Width / 4) - 30);
}

View file

@ -363,9 +363,9 @@ namespace ShiftOS.Frontend
string objectiveFailed = "- OBJECTIVE FAILURE -";
string prompt = "[press any key to dismiss this message and return to your sentience]";
int textMaxWidth = UIManager.Viewport.Width / 3;
var topMeasure = gfx.MeasureString(objectiveFailed, SkinEngine.LoadedSkin.HeaderFont, textMaxWidth);
var msgMeasure = gfx.MeasureString(failMessage, SkinEngine.LoadedSkin.Header3Font, textMaxWidth);
var pMeasure = gfx.MeasureString(prompt, SkinEngine.LoadedSkin.MainFont, textMaxWidth);
var topMeasure = GraphicsContext.MeasureString(objectiveFailed, SkinEngine.LoadedSkin.HeaderFont, textMaxWidth);
var msgMeasure = GraphicsContext.MeasureString(failMessage, SkinEngine.LoadedSkin.Header3Font, textMaxWidth);
var pMeasure = GraphicsContext.MeasureString(prompt, SkinEngine.LoadedSkin.MainFont, textMaxWidth);
gfx.DrawString(objectiveFailed, (UIManager.Viewport.Width - (int)topMeasure.X) / 2, UIManager.Viewport.Height / 3, Color.White, SkinEngine.LoadedSkin.HeaderFont, textMaxWidth);
gfx.DrawString(failMessage, (UIManager.Viewport.Width - (int)msgMeasure.X) / 2, (UIManager.Viewport.Height - (int)msgMeasure.Y) / 2, Color.White, SkinEngine.LoadedSkin.Header3Font, textMaxWidth);
@ -378,7 +378,7 @@ namespace ShiftOS.Frontend
{
string str = $"Timeout in {(Hacking.CurrentHackable.MillisecondsCountdown / 1000).ToString("#.##")} seconds.";
var gfx = new GraphicsContext(GraphicsDevice, spriteBatch, 0, 0, UIManager.Viewport.Width, UIManager.Viewport.Height);
var measure = gfx.MeasureString(str, SkinEngine.LoadedSkin.HeaderFont);
var measure = GraphicsContext.MeasureString(str, SkinEngine.LoadedSkin.HeaderFont);
gfx.DrawString(str, 5, (gfx.Height - ((int)measure.Y) - 5), Color.Red, SkinEngine.LoadedSkin.HeaderFont);
}
}