diff options
Diffstat (limited to 'ShiftOS.Frontend/Apps')
| -rw-r--r-- | ShiftOS.Frontend/Apps/ChatClient.cs | 14 | ||||
| -rw-r--r-- | ShiftOS.Frontend/Apps/CodeShop.cs | 6 | ||||
| -rw-r--r-- | ShiftOS.Frontend/Apps/Pong.cs | 8 | ||||
| -rw-r--r-- | ShiftOS.Frontend/Apps/SkinLoader.cs | 6 | ||||
| -rw-r--r-- | ShiftOS.Frontend/Apps/Terminal.cs | 44 |
5 files changed, 35 insertions, 43 deletions
diff --git a/ShiftOS.Frontend/Apps/ChatClient.cs b/ShiftOS.Frontend/Apps/ChatClient.cs index c57f2a3..efcce0e 100644 --- a/ShiftOS.Frontend/Apps/ChatClient.cs +++ b/ShiftOS.Frontend/Apps/ChatClient.cs @@ -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) diff --git a/ShiftOS.Frontend/Apps/CodeShop.cs b/ShiftOS.Frontend/Apps/CodeShop.cs index 009521c..46b1832 100644 --- a/ShiftOS.Frontend/Apps/CodeShop.cs +++ b/ShiftOS.Frontend/Apps/CodeShop.cs @@ -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); } } diff --git a/ShiftOS.Frontend/Apps/Pong.cs b/ShiftOS.Frontend/Apps/Pong.cs index 61b1dc9..7861c6c 100644 --- a/ShiftOS.Frontend/Apps/Pong.cs +++ b/ShiftOS.Frontend/Apps/Pong.cs @@ -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) diff --git a/ShiftOS.Frontend/Apps/SkinLoader.cs b/ShiftOS.Frontend/Apps/SkinLoader.cs index 8711d92..b89952e 100644 --- a/ShiftOS.Frontend/Apps/SkinLoader.cs +++ b/ShiftOS.Frontend/Apps/SkinLoader.cs @@ -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); diff --git a/ShiftOS.Frontend/Apps/Terminal.cs b/ShiftOS.Frontend/Apps/Terminal.cs index 6d01d9f..ee470ab 100644 --- a/ShiftOS.Frontend/Apps/Terminal.cs +++ b/ShiftOS.Frontend/Apps/Terminal.cs @@ -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); |
