Fix terminal and add support for animations

This commit is contained in:
Michael 2017-07-19 16:08:33 -04:00
parent 3fe1872f5f
commit b8eb7dccfd
17 changed files with 105 additions and 74 deletions

View file

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using ShiftOS.Engine;
using ShiftOS.Frontend.GraphicsSubsystem;
@ -24,7 +25,7 @@ namespace ShiftOS.Frontend.Apps
Height = 480;
}
protected override void OnLayout()
protected override void OnLayout(GameTime gameTime)
{
try
{

View file

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using ShiftOS.Engine;
using static ShiftOS.Objects.ShiftFS.Utils;
@ -133,11 +134,11 @@ namespace ShiftOS.Frontend.Apps
}
protected override void OnLayout()
protected override void OnLayout(GameTime gameTime)
{
try
{
_currentdirtext.Layout();
_currentdirtext.Layout(gameTime);
_fList.X = 0;
_fList.Y = 0;
_fList.Width = Width;

View file

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using ShiftOS.Engine;
using ShiftOS.Frontend.Desktop;
using ShiftOS.Frontend.GraphicsSubsystem;
@ -48,7 +49,7 @@ namespace ShiftOS.Frontend.Apps
{
}
protected override void OnLayout()
protected override void OnLayout(GameTime gameTime)
{
_header.Font = SkinEngine.LoadedSkin.HeaderFont;
_header.X = 20;

View file

@ -6,6 +6,7 @@ using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using ShiftOS.Engine;
using ShiftOS.Frontend.GraphicsSubsystem;
@ -33,7 +34,6 @@ namespace ShiftOS.Frontend.Apps
_terminal = new Apps.TerminalControl();
_terminal.Dock = GUI.DockStyle.Fill;
AddControl(_terminal);
_terminal.Layout();
AppearanceManager.ConsoleOut = _terminal;
AppearanceManager.StartConsoleOut();
TerminalBackend.PrintPrompt();
@ -45,7 +45,7 @@ namespace ShiftOS.Frontend.Apps
};
}
protected override void OnLayout()
protected override void OnLayout(GameTime gameTime)
{
if (ContainsFocusedControl || IsFocusedControl)
AppearanceManager.ConsoleOut = _terminal;
@ -138,9 +138,18 @@ namespace ShiftOS.Frontend.Apps
{
}
protected override void OnLayout()
private bool blinkStatus = false;
private double blinkTime = 0.0;
protected override void OnLayout(GameTime gameTime)
{
blinkTime += gameTime.ElapsedGameTime.TotalMilliseconds;
if (blinkTime > 500.0)
blinkTime = 0;
bool prev = blinkStatus;
blinkStatus = blinkTime > 250.0;
if (prev != blinkStatus)
Invalidate();
}
/// <summary>
@ -148,7 +157,7 @@ namespace ShiftOS.Frontend.Apps
/// </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>
public Point GetPointAtIndex(Graphics gfx)
public System.Drawing.Point GetPointAtIndex(Graphics gfx)
{
int vertMeasure = 2;
int horizMeasure = 2;
@ -169,7 +178,7 @@ namespace ShiftOS.Frontend.Apps
vertMeasure += (int)lnMeasure.Height;
}
horizMeasure += w;
return new Point(horizMeasure, vertMeasure);
return new System.Drawing.Point(horizMeasure, vertMeasure);
}
private PointF CaretPosition = new PointF(2, 2);
@ -191,12 +200,14 @@ namespace ShiftOS.Frontend.Apps
var text2 = text[text.Length - 1];
var text3 = "";
var text4 = Regex.Replace(text2, @"\t|\n|\r", "");
WriteLine("");
{
WriteLine("");
if (TerminalBackend.PrefixEnabled)
{
text3 = text4.Remove(0, $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ".Length);
}
if (!string.IsNullOrWhiteSpace(text3))
{
TerminalBackend.LastCommand = text3;
TerminalBackend.SendText(text4);
if (TerminalBackend.InStory == false)
@ -215,16 +226,20 @@ namespace ShiftOS.Frontend.Apps
}
}
if (TerminalBackend.PrefixEnabled)
{
TerminalBackend.PrintPrompt();
}
AppearanceManager.CurrentPosition = 0;
}
}
catch
{
}
finally
{
if (TerminalBackend.PrefixEnabled)
{
TerminalBackend.PrintPrompt();
}
AppearanceManager.CurrentPosition = 0;
}
}
else if (a.Key == Keys.Back)
{
@ -300,6 +315,8 @@ namespace ShiftOS.Frontend.Apps
InvalidateTopLevel();
}
}
blinkStatus = true;
blinkTime = 250;
}
protected override void OnPaint(GraphicsContext gfx)
@ -308,14 +325,24 @@ namespace ShiftOS.Frontend.Apps
if (!string.IsNullOrEmpty(Text))
{
//Draw the caret.
PointF cursorPos;
using (var cgfx = System.Drawing.Graphics.FromImage(new System.Drawing.Bitmap(1, 1)))
if (blinkStatus == true)
{
cursorPos = GetPointAtIndex(cgfx);
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;
}
gfx.DrawRectangle((int)cursorPos.X, (int)cursorPos.Y - (int)_vertOffset, (int)cursorSize.X, (int)cursorSize.Y, LoadedSkin.TerminalForeColorCC.ToColor().ToMonoColor());
}
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
@ -327,44 +354,44 @@ namespace ShiftOS.Frontend.Apps
public static class ConsoleColorExtensions
{
public static Color ToColor(this ConsoleColor cc)
public static System.Drawing.Color ToColor(this ConsoleColor cc)
{
switch (cc)
{
case ConsoleColor.Black:
return Color.Black;
return System.Drawing.Color.Black;
case ConsoleColor.Blue:
return Color.Blue;
return System.Drawing.Color.Blue;
case ConsoleColor.Cyan:
return Color.Cyan;
return System.Drawing.Color.Cyan;
case ConsoleColor.DarkBlue:
return Color.DarkBlue;
return System.Drawing.Color.DarkBlue;
case ConsoleColor.DarkCyan:
return Color.DarkCyan;
return System.Drawing.Color.DarkCyan;
case ConsoleColor.DarkGray:
return Color.DarkGray;
return System.Drawing.Color.DarkGray;
case ConsoleColor.DarkGreen:
return Color.DarkGreen;
return System.Drawing.Color.DarkGreen;
case ConsoleColor.DarkMagenta:
return Color.DarkMagenta;
return System.Drawing.Color.DarkMagenta;
case ConsoleColor.DarkRed:
return Color.DarkRed;
return System.Drawing.Color.DarkRed;
case ConsoleColor.DarkYellow:
return Color.Orange;
return System.Drawing.Color.Orange;
case ConsoleColor.Gray:
return Color.Gray;
return System.Drawing.Color.Gray;
case ConsoleColor.Green:
return Color.Green;
return System.Drawing.Color.Green;
case ConsoleColor.Magenta:
return Color.Magenta;
return System.Drawing.Color.Magenta;
case ConsoleColor.Red:
return Color.Red;
return System.Drawing.Color.Red;
case ConsoleColor.White:
return Color.White;
return System.Drawing.Color.White;
case ConsoleColor.Yellow:
return Color.Yellow;
return System.Drawing.Color.Yellow;
}
return Color.Empty;
return System.Drawing.Color.Empty;
}
}
@ -375,11 +402,11 @@ namespace ShiftOS.Frontend.Apps
if (string.IsNullOrEmpty(s))
s = " ";
var textformat = new StringFormat(StringFormat.GenericTypographic);
textformat.FormatFlags = StringFormatFlags.MeasureTrailingSpaces;
textformat.Trimming = StringTrimming.None;
textformat.FormatFlags |= StringFormatFlags.NoClip;
textformat.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces;
//textformat.Trimming = StringTrimming.Character;
//textformat.FormatFlags |= StringFormatFlags.NoClip;
gfx.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
gfx.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
var measure = gfx.MeasureString(s, font, width, textformat);
return new SizeF((float)Math.Ceiling(measure.Width), (float)Math.Ceiling(measure.Height));
}

View file

@ -4,6 +4,7 @@ using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using ShiftOS.Engine;
using ShiftOS.Frontend.Apps;
using ShiftOS.Frontend.GraphicsSubsystem;
@ -100,7 +101,7 @@ namespace ShiftOS.Frontend.Desktop
{
}
public void OpenAppLauncher(Point loc)
public void OpenAppLauncher(System.Drawing.Point loc)
{
alX = loc.X;
alY = loc.Y;
@ -188,7 +189,7 @@ namespace ShiftOS.Frontend.Desktop
private string dateTimeString = "";
protected override void OnLayout()
protected override void OnLayout(GameTime gameTime)
{
if (alOpen)
BringToFront();

View file

@ -6,6 +6,7 @@ using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using ShiftOS.Engine;
using ShiftOS.Frontend.GraphicsSubsystem;
@ -224,7 +225,7 @@ namespace ShiftOS.Frontend.Desktop
private int lastmousex, lastmousey = 0;
protected override void OnLayout()
protected override void OnLayout(GameTime gameTime)
{
int titlebarheight = LoadedSkin.TitlebarHeight;
int borderleft = LoadedSkin.LeftBorderWidth;
@ -318,7 +319,7 @@ namespace ShiftOS.Frontend.Desktop
var closebuttonsize = LoadedSkin.CloseButtonSize;
var closebuttonright = LoadedSkin.CloseButtonFromSide;
if (LoadedSkin.TitleButtonPosition == 0)
closebuttonright = new Point(Width - closebuttonsize.Width - closebuttonright.X, closebuttonright.Y);
closebuttonright = new System.Drawing.Point(Width - closebuttonsize.Width - closebuttonright.X, closebuttonright.Y);
if (!UIManager.SkinTextures.ContainsKey("closebutton"))
{
gfx.DrawRectangle(closebuttonright.X, closebuttonright.Y, closebuttonsize.Width, closebuttonsize.Height, UIManager.SkinTextures["CloseButtonColor"]);
@ -332,7 +333,7 @@ namespace ShiftOS.Frontend.Desktop
closebuttonsize = LoadedSkin.MaximizeButtonSize;
closebuttonright = LoadedSkin.MaximizeButtonFromSide;
if (LoadedSkin.TitleButtonPosition == 0)
closebuttonright = new Point(Width - closebuttonsize.Width - closebuttonright.X, closebuttonright.Y);
closebuttonright = new System.Drawing.Point(Width - closebuttonsize.Width - closebuttonright.X, closebuttonright.Y);
if (!UIManager.SkinTextures.ContainsKey("maximizebutton"))
{
@ -347,7 +348,7 @@ namespace ShiftOS.Frontend.Desktop
closebuttonsize = LoadedSkin.MinimizeButtonSize;
closebuttonright = LoadedSkin.MinimizeButtonFromSide;
if (LoadedSkin.TitleButtonPosition == 0)
closebuttonright = new Point(Width - closebuttonsize.Width - closebuttonright.X, closebuttonright.Y);
closebuttonright = new System.Drawing.Point(Width - closebuttonsize.Width - closebuttonright.X, closebuttonright.Y);
if (!UIManager.SkinTextures.ContainsKey("minimizebutton"))
{
gfx.DrawRectangle(closebuttonright.X, closebuttonright.Y, closebuttonsize.Width, closebuttonsize.Height, UIManager.SkinTextures["MinimizeButtonColor"]);
@ -441,7 +442,7 @@ namespace ShiftOS.Frontend.Desktop
public static Texture2D ToTexture2D(this Image image, GraphicsDevice device)
{
var bmp = (Bitmap)image;
var lck = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
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 data = new byte[Math.Abs(lck.Stride) * lck.Height];
Marshal.Copy(lck.Scan0, data, 0, data.Length);
bmp.UnlockBits(lck);

View file

@ -18,7 +18,7 @@ namespace ShiftOS.Frontend.GUI
Text = "Click me!";
}
protected override void OnLayout()
protected override void OnLayout(GameTime gameTime)
{
if(AutoSize == true)
{

View file

@ -429,7 +429,7 @@ namespace ShiftOS.Frontend.GUI
}
}
public void Layout()
public void Layout(GameTime gameTime)
{
//Dock style
if(_parent != null)
@ -469,12 +469,12 @@ namespace ShiftOS.Frontend.GUI
break;
}
}
OnLayout();
OnLayout(gameTime);
foreach (var child in _children)
child.Layout();
child.Layout(gameTime);
}
protected virtual void OnLayout()
protected virtual void OnLayout(GameTime gameTime)
{
//do nothing
}
@ -621,7 +621,6 @@ namespace ShiftOS.Frontend.GUI
{
_mouseX = coords.X;
_mouseY = coords.Y;
Layout();
_wasMouseInControl = true;
int newX = MathHelper.Clamp(state.X, X, X + Width);
int newY = MathHelper.Clamp(state.Y, Y, Y + Height);

View file

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
namespace ShiftOS.Frontend.GUI
{
@ -12,7 +13,7 @@ namespace ShiftOS.Frontend.GUI
private FlowDirection _flowDir = FlowDirection.LeftToRight;
private int _initialgap = 2;
protected override void OnLayout()
protected override void OnLayout(GameTime gameTime)
{
if (AutoSize)
{
@ -44,7 +45,6 @@ namespace ShiftOS.Frontend.GUI
ctrl.X = _x;
ctrl.Y = _y;
ctrl.Dock = DockStyle.None;
ctrl.Layout();
_x += ctrl.Width + _gap;
if (_maxYForRow < ctrl.Height + _gap)

View file

@ -168,14 +168,14 @@ namespace ShiftOS.Frontend.GUI
}
}
protected override void OnLayout()
protected override void OnLayout(GameTime gameTime)
{
if(fontheight != LoadedSkin.MainFont.Height)
{
fontheight = LoadedSkin.MainFont.Height;
Invalidate();
}
base.OnLayout();
base.OnLayout(gameTime);
}
public event Action SelectedIndexChanged;

View file

@ -9,6 +9,7 @@ using ShiftOS.Engine;
using System.Drawing.Imaging;
using ShiftOS.Frontend.GraphicsSubsystem;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
namespace ShiftOS.Frontend.GUI
{
@ -43,7 +44,7 @@ namespace ShiftOS.Frontend.GUI
}
}
protected override void OnLayout()
protected override void OnLayout(GameTime gameTime)
{
if (AutoSize)
{
@ -109,8 +110,8 @@ namespace ShiftOS.Frontend.GUI
InterpolationMode.HighQualityBicubic;
grPhoto.DrawImage(imgPhoto,
new Rectangle(destX, destY, destWidth, destHeight),
new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight),
new System.Drawing.Rectangle(destX, destY, destWidth, destHeight),
new System.Drawing.Rectangle(sourceX, sourceY, sourceWidth, sourceHeight),
GraphicsUnit.Pixel);
grPhoto.Dispose();

View file

@ -4,6 +4,7 @@ using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using ShiftOS.Frontend.GraphicsSubsystem;
namespace ShiftOS.Frontend.GUI
@ -14,7 +15,7 @@ namespace ShiftOS.Frontend.GUI
private TextAlign _textAlign = TextAlign.TopLeft;
private Font _font = new Font("Tahoma", 9f);
protected override void OnLayout()
protected override void OnLayout(GameTime gameTime)
{
if (AutoSize)
{

View file

@ -159,7 +159,7 @@ namespace ShiftOS.Frontend.GraphicsSubsystem
{
var sFormat = System.Drawing.StringFormat.GenericTypographic;
sFormat.FormatFlags |= System.Drawing.StringFormatFlags.NoClip;
sFormat.FormatFlags |= System.Drawing.StringFormatFlags.DisplayFormatControl;
gfx.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
gfx.DrawString(text, font, System.Drawing.Brushes.White, new System.Drawing.RectangleF(0, 0, bmp.Width, bmp.Height), sFormat);

View file

@ -25,10 +25,10 @@ namespace ShiftOS.Frontend.GraphicsSubsystem
topLevels.Add(ctrl);
}
public static void LayoutUpdate()
public static void LayoutUpdate(GameTime gameTime)
{
foreach (var toplevel in topLevels.ToArray())
toplevel.Layout();
toplevel.Layout(gameTime);
}
public static void Animate(object owner, System.Reflection.PropertyInfo prop, double from, double to, int timeMs)
@ -135,7 +135,7 @@ namespace ShiftOS.Frontend.GraphicsSubsystem
{
if (!topLevels.Contains(ctrl))
topLevels.Add(ctrl);
ctrl.Layout();
}
public static void InvalidateAll()

View file

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using ShiftOS.Engine;
using ShiftOS.Frontend.Desktop;
using ShiftOS.Frontend.GraphicsSubsystem;
@ -178,11 +179,9 @@ namespace ShiftOS.Frontend
this.AddControl(btnok);
this.AddControl(flyesno);
this.AddControl(lbmessage);
this.Layout();
}
protected override void OnLayout()
protected override void OnLayout(GameTime gameTime)
{
try
{

View file

@ -229,7 +229,7 @@ namespace ShiftOS.Frontend
}
//Cause layout update on all elements
UIManager.LayoutUpdate();
UIManager.LayoutUpdate(gameTime);
timeSinceLastPurge += gameTime.ElapsedGameTime.TotalSeconds;

View file

@ -476,7 +476,6 @@ namespace ShiftOS.Engine
/// </summary>
public static void PrintPrompt()
{
Console.WriteLine();
if (SaveSystem.CurrentSave != null)
{
ConsoleEx.BackgroundColor = SkinEngine.LoadedSkin.TerminalBackColorCC;