HEAVILY optimize skins
This commit is contained in:
parent
2adb8859ed
commit
4f41f51267
12 changed files with 1427 additions and 74 deletions
171
ShiftOS.Frontend/Apps/Pong.cs
Normal file
171
ShiftOS.Frontend/Apps/Pong.cs
Normal file
|
@ -0,0 +1,171 @@
|
|||
using System;
|
||||
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;
|
||||
|
||||
namespace ShiftOS.Frontend.Apps
|
||||
{
|
||||
[Launcher("{TITLE_PONG}", true, "al_pong", "{AL_GAMES}")]
|
||||
[WinOpen("{WO_PONG}")]
|
||||
[DefaultTitle("{TITLE_PONG}")]
|
||||
[DefaultIcon("iconPong")]
|
||||
public class Pong : GUI.Control, IShiftOSWindow
|
||||
{
|
||||
public Pong()
|
||||
{
|
||||
Width = 720;
|
||||
Height = 480;
|
||||
MouseMove += (loc) =>
|
||||
{
|
||||
double _y = linear(loc.Y, 0, Height, -1, 1);
|
||||
if(_y != playerY)
|
||||
{
|
||||
playerY = _y;
|
||||
Invalidate();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#region Private variables
|
||||
private double ballX = 0.0f;
|
||||
private double ballY = 0.0f;
|
||||
private double aiBallX = 0.0f;
|
||||
private double aiBallY = 0.0f;
|
||||
private double speedFactor = 0.0125;
|
||||
private double xVel = 1;
|
||||
private double yVel = 1;
|
||||
private double aiXVel = 1;
|
||||
private double aiYVel = 1;
|
||||
private int paddleWidth;
|
||||
private long codepointsToEarn = 0;
|
||||
private int level = 1;
|
||||
private double playerY = 0.0;
|
||||
private double opponentY = 0.0;
|
||||
private int secondsleft = 60;
|
||||
bool doAi = true;
|
||||
bool doBallCalc = true;
|
||||
private string header = "";
|
||||
private string counter = "";
|
||||
#endregion
|
||||
|
||||
#region Control behaviour overrides
|
||||
|
||||
protected override void OnPaint(GraphicsContext gfx)
|
||||
{
|
||||
//This is where we'll dump the winforms painting code
|
||||
//By now, Layout() would have calculated the game's state
|
||||
|
||||
paddleWidth = Width / 30;
|
||||
double ballXLocal = linear(ballX, -1.0, 1.0, 0, Width);
|
||||
double ballYLocal = linear(ballY, -1.0, 1.0, 0, Height);
|
||||
|
||||
ballXLocal -= ((double)paddleWidth / 2);
|
||||
ballYLocal -= ((double)paddleWidth / 2);
|
||||
|
||||
double aiballXLocal = linear(aiBallX, -1.0, 1.0, 0, Width);
|
||||
double aiballYLocal = linear(aiBallY, -1.0, 1.0, 0, Height);
|
||||
|
||||
aiballXLocal -= ((double)paddleWidth / 2);
|
||||
aiballYLocal -= ((double)paddleWidth / 2);
|
||||
|
||||
|
||||
gfx.Clear(SkinEngine.LoadedSkin.ControlColor.ToMonoColor());
|
||||
|
||||
//draw the ball
|
||||
if (doBallCalc)
|
||||
{
|
||||
gfx.DrawRectangle((int)ballXLocal, (int)ballYLocal, paddleWidth, paddleWidth, SkinEngine.LoadedSkin.ControlTextColor.ToMonoColor());
|
||||
}
|
||||
double playerYLocal = linear(playerY, -1.0, 1.0, 0, Height);
|
||||
double opponentYLocal = linear(opponentY, -1.0, 1.0, 0, Height);
|
||||
|
||||
int paddleHeight = Height / 5;
|
||||
|
||||
int paddleStart = paddleWidth;
|
||||
|
||||
//draw player paddle
|
||||
gfx.DrawRectangle(paddleWidth, (int)playerYLocal - (paddleHeight / 2), paddleWidth, paddleHeight, SkinEngine.LoadedSkin.ControlTextColor.ToMonoColor());
|
||||
|
||||
|
||||
//draw opponent
|
||||
gfx.DrawRectangle(Width - (paddleWidth*2), (int)opponentYLocal - (paddleHeight / 2), paddleWidth, paddleHeight, SkinEngine.LoadedSkin.ControlTextColor.ToMonoColor());
|
||||
|
||||
string cp_text = Localization.Parse("{PONG_STATUSCP}", new Dictionary<string, string>
|
||||
{
|
||||
["%cp"] = codepointsToEarn.ToString()
|
||||
});
|
||||
|
||||
var tSize = gfx.MeasureString(cp_text, SkinEngine.LoadedSkin.Header3Font);
|
||||
|
||||
var tLoc = new Vector2((Width - (int)tSize.X) / 2,
|
||||
(Height - (int)tSize.Y)
|
||||
|
||||
);
|
||||
|
||||
gfx.DrawString(cp_text, (int)tLoc.X, (int)tLoc.Y, SkinEngine.LoadedSkin.ControlTextColor.ToMonoColor(), SkinEngine.LoadedSkin.Header3Font);
|
||||
|
||||
tSize = gfx.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);
|
||||
|
||||
tLoc = new Vector2((Width - (int)tSize.X) / 2,
|
||||
(Height - (int)tSize.Y) / 4
|
||||
|
||||
);
|
||||
gfx.DrawString(header, (int)tLoc.X, (int)tLoc.Y, SkinEngine.LoadedSkin.ControlTextColor.ToMonoColor(), SkinEngine.LoadedSkin.Header2Font);
|
||||
|
||||
string l = Localization.Parse("{PONG_STATUSLEVEL}", new Dictionary<string, string>
|
||||
{
|
||||
["%level"] = level.ToString(),
|
||||
["%time"] = secondsleft.ToString()
|
||||
});
|
||||
tSize = gfx.MeasureString(l, SkinEngine.LoadedSkin.Header3Font);
|
||||
|
||||
tLoc = new Vector2((Width - (int)tSize.X) / 2,
|
||||
(tSize.Y)
|
||||
);
|
||||
gfx.DrawString(l, (int)tLoc.X, (int)tLoc.Y, SkinEngine.LoadedSkin.ControlTextColor.ToMonoColor(), SkinEngine.LoadedSkin.Header3Font);
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
static public double linear(double x, double x0, double x1, double y0, double y1)
|
||||
{
|
||||
if ((x1 - x0) == 0)
|
||||
{
|
||||
return (y0 + y1) / 2;
|
||||
}
|
||||
return y0 + (x - x0) * (y1 - y0) / (x1 - x0);
|
||||
}
|
||||
|
||||
public void OnLoad()
|
||||
{
|
||||
doBallCalc = true;
|
||||
}
|
||||
|
||||
public void OnSkinLoad()
|
||||
{
|
||||
}
|
||||
|
||||
public bool OnUnload()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void OnUpgrade()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
if (initial > Height)
|
||||
{
|
||||
float difference = initial - Height;
|
||||
_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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -84,7 +84,7 @@ namespace ShiftOS.Frontend.Desktop
|
|||
Console.WriteLine("Application not found on system.");
|
||||
return;
|
||||
}
|
||||
while(AppearanceManager.OpenForms.Count > MaxCount)
|
||||
while(AppearanceManager.OpenForms.Count >= MaxCount)
|
||||
{
|
||||
AppearanceManager.OpenForms[0].Close();
|
||||
AppearanceManager.OpenForms.RemoveAt(0);
|
||||
|
@ -132,7 +132,7 @@ namespace ShiftOS.Frontend.Desktop
|
|||
int bottomheight = Shiftorium.UpgradeInstalled("window_borders") ? LoadedSkin.BottomBorderWidth : 0;
|
||||
int rightwidth = Shiftorium.UpgradeInstalled("window_borders") ? LoadedSkin.RightBorderWidth : 0;
|
||||
_hostedwindow.Width = width - leftwidth - rightwidth;
|
||||
_hostedwindow.Height = width - bottomheight - titleheight;
|
||||
_hostedwindow.Height = height - bottomheight - titleheight;
|
||||
Width = width;
|
||||
Height = height;
|
||||
|
||||
|
@ -271,9 +271,6 @@ namespace ShiftOS.Frontend.Desktop
|
|||
var titletextleft = LoadedSkin.TitleTextLeft;
|
||||
bool titletextcentered = LoadedSkin.TitleTextCentered;
|
||||
|
||||
var titlebarbg = GetImage("titlebar");
|
||||
var titlebarlayout = GetImageLayout("titlebar");
|
||||
|
||||
var drawcorners = LoadedSkin.ShowTitleCorners;
|
||||
int titlebarleft = 0;
|
||||
int titlebarwidth = Width;
|
||||
|
@ -291,17 +288,14 @@ namespace ShiftOS.Frontend.Desktop
|
|||
//and the colors
|
||||
var leftcolor = LoadedSkin.TitleLeftCornerBackground;
|
||||
var rightcolor = LoadedSkin.TitleRightCornerBackground;
|
||||
//and the layouts...
|
||||
var leftlayout = GetImageLayout("titlebarleft");
|
||||
var rightlayout = GetImageLayout("titlebarright");
|
||||
//and the widths
|
||||
var leftwidth = LoadedSkin.TitleLeftCornerWidth;
|
||||
var rightwidth = LoadedSkin.TitleRightCornerWidth;
|
||||
|
||||
//draw left corner
|
||||
if(leftimage != null)
|
||||
if(UIManager.SkinTextures.ContainsKey("titleleft"))
|
||||
{
|
||||
gfx.DrawRectangle(0, 0, leftwidth, titleheight, leftimage.ToTexture2D(gfx.Device));
|
||||
gfx.DrawRectangle(0, 0, leftwidth, titleheight, UIManager.SkinTextures["titleleft"]);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -309,9 +303,9 @@ namespace ShiftOS.Frontend.Desktop
|
|||
}
|
||||
|
||||
//draw right corner
|
||||
if (rightimage != null)
|
||||
if (UIManager.SkinTextures.ContainsKey("titleright"))
|
||||
{
|
||||
gfx.DrawRectangle(titlebarleft + titlebarwidth, 0, rightwidth, titleheight, rightimage.ToTexture2D(gfx.Device));
|
||||
gfx.DrawRectangle(titlebarleft + titlebarwidth, 0, rightwidth, titleheight, UIManager.SkinTextures["titleright"]);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -319,7 +313,7 @@ namespace ShiftOS.Frontend.Desktop
|
|||
}
|
||||
}
|
||||
|
||||
if (titlebarbg == null)
|
||||
if (!UIManager.SkinTextures.ContainsKey("titlebar"))
|
||||
{
|
||||
//draw the title bg
|
||||
gfx.DrawRectangle(titlebarleft, 0, titlebarwidth, titleheight, titlebarcolor.ToMonoColor());
|
||||
|
@ -327,7 +321,7 @@ namespace ShiftOS.Frontend.Desktop
|
|||
}
|
||||
else
|
||||
{
|
||||
gfx.DrawRectangle(titlebarleft, 0, titlebarwidth, titleheight, titlebarbg.ToTexture2D(gfx.Device));
|
||||
gfx.DrawRectangle(titlebarleft, 0, titlebarwidth, titleheight, UIManager.SkinTextures["titlebar"]);
|
||||
}
|
||||
//Now we draw the title text.
|
||||
var textMeasure = gfx.MeasureString(_text, titlefont);
|
||||
|
@ -350,14 +344,13 @@ namespace ShiftOS.Frontend.Desktop
|
|||
var closebuttonright = LoadedSkin.CloseButtonFromSide;
|
||||
if (LoadedSkin.TitleButtonPosition == 0)
|
||||
closebuttonright = new Point(Width - closebuttonsize.Width - closebuttonright.X, closebuttonright.Y);
|
||||
var img = GetImage("closebutton");
|
||||
if (img == null)
|
||||
if (!UIManager.SkinTextures.ContainsKey("closebutton"))
|
||||
{
|
||||
gfx.DrawRectangle(closebuttonright.X, closebuttonright.Y, closebuttonsize.Width, closebuttonsize.Height, closebuttoncolor.ToMonoColor());
|
||||
}
|
||||
else
|
||||
{
|
||||
gfx.DrawRectangle(closebuttonright.X, closebuttonright.Y, closebuttonsize.Width, closebuttonsize.Height, img.ToTexture2D(gfx.Device));
|
||||
gfx.DrawRectangle(closebuttonright.X, closebuttonright.Y, closebuttonsize.Width, closebuttonsize.Height, UIManager.SkinTextures["closebutton"]);
|
||||
}
|
||||
}
|
||||
//Draw maximize button
|
||||
|
@ -369,16 +362,14 @@ namespace ShiftOS.Frontend.Desktop
|
|||
if (LoadedSkin.TitleButtonPosition == 0)
|
||||
closebuttonright = new Point(Width - closebuttonsize.Width - closebuttonright.X, closebuttonright.Y);
|
||||
|
||||
var img = GetImage("maximizebutton");
|
||||
if (img == null)
|
||||
if (!UIManager.SkinTextures.ContainsKey("maximizebutton"))
|
||||
{
|
||||
gfx.DrawRectangle(closebuttonright.X, closebuttonright.Y, closebuttonsize.Width, closebuttonsize.Height, closebuttoncolor.ToMonoColor());
|
||||
}
|
||||
else
|
||||
{
|
||||
gfx.DrawRectangle(closebuttonright.X, closebuttonright.Y, closebuttonsize.Width, closebuttonsize.Height, img.ToTexture2D(gfx.Device));
|
||||
gfx.DrawRectangle(closebuttonright.X, closebuttonright.Y, closebuttonsize.Width, closebuttonsize.Height, UIManager.SkinTextures["maximizebutton"]);
|
||||
}
|
||||
|
||||
}
|
||||
//Draw minimize button
|
||||
if (Shiftorium.UpgradeInstalled("minimize_button"))
|
||||
|
@ -388,17 +379,15 @@ namespace ShiftOS.Frontend.Desktop
|
|||
var closebuttonright = LoadedSkin.MinimizeButtonFromSide;
|
||||
if (LoadedSkin.TitleButtonPosition == 0)
|
||||
closebuttonright = new Point(Width - closebuttonsize.Width - closebuttonright.X, closebuttonright.Y);
|
||||
var img = GetImage("minimizebutton");
|
||||
if (img == null)
|
||||
if (!UIManager.SkinTextures.ContainsKey("minimizebutton"))
|
||||
{
|
||||
gfx.DrawRectangle(closebuttonright.X, closebuttonright.Y, closebuttonsize.Width, closebuttonsize.Height, closebuttoncolor.ToMonoColor());
|
||||
}
|
||||
else
|
||||
{
|
||||
gfx.DrawRectangle(closebuttonright.X, closebuttonright.Y, closebuttonsize.Width, closebuttonsize.Height, img.ToTexture2D(gfx.Device));
|
||||
gfx.DrawRectangle(closebuttonright.X, closebuttonright.Y, closebuttonsize.Width, closebuttonsize.Height, UIManager.SkinTextures["minimizebutton"]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -425,58 +414,53 @@ namespace ShiftOS.Frontend.Desktop
|
|||
|
||||
//draw border corners
|
||||
//BOTTOM LEFT
|
||||
var bottomlimg = GetImage("bottomlborder");
|
||||
if (bottomlimg == null)
|
||||
if (!UIManager.SkinTextures.ContainsKey("bottomlborder"))
|
||||
{
|
||||
gfx.DrawRectangle(0, bottomlocy, leftborderwidth, bottomborderwidth, borderbleftcolor.ToMonoColor());
|
||||
}
|
||||
else
|
||||
{
|
||||
gfx.DrawRectangle(0, bottomlocy, leftborderwidth, bottomborderwidth, bottomlimg.ToTexture2D(gfx.Device));
|
||||
gfx.DrawRectangle(0, bottomlocy, leftborderwidth, bottomborderwidth, UIManager.SkinTextures["bottomlborder"]);
|
||||
}
|
||||
|
||||
//BOTTOM RIGHT
|
||||
var bottomrimg = GetImage("bottomrborder");
|
||||
if (bottomrimg == null)
|
||||
if (!UIManager.SkinTextures.ContainsKey("bottomrborder"))
|
||||
{
|
||||
gfx.DrawRectangle(brightlocx, bottomlocy, rightborderwidth, bottomborderwidth, borderbrightcolor.ToMonoColor());
|
||||
}
|
||||
else
|
||||
{
|
||||
gfx.DrawRectangle(brightlocx, bottomlocy, rightborderwidth, bottomborderwidth, bottomrimg.ToTexture2D(gfx.Device));
|
||||
gfx.DrawRectangle(brightlocx, bottomlocy, rightborderwidth, bottomborderwidth, UIManager.SkinTextures["bottomrborder"]);
|
||||
}
|
||||
|
||||
//BOTTOM
|
||||
var bottomimg = GetImage("bottomborder");
|
||||
if (bottomimg == null)
|
||||
if (!UIManager.SkinTextures.ContainsKey("bottomborder"))
|
||||
{
|
||||
gfx.DrawRectangle(leftborderwidth, bottomlocy, bottomwidth, bottomborderwidth, borderbottomcolor.ToMonoColor());
|
||||
}
|
||||
else
|
||||
{
|
||||
gfx.DrawRectangle(leftborderwidth, bottomlocy, bottomwidth, bottomborderwidth, bottomimg.ToTexture2D(gfx.Device));
|
||||
gfx.DrawRectangle(leftborderwidth, bottomlocy, bottomwidth, bottomborderwidth, UIManager.SkinTextures["bottomborder"]);
|
||||
}
|
||||
|
||||
//LEFT
|
||||
var leftimg = GetImage("leftborder");
|
||||
if (leftimg == null)
|
||||
if (!UIManager.SkinTextures.ContainsKey("leftborder"))
|
||||
{
|
||||
gfx.DrawRectangle(0, titleheight, leftborderwidth, Height - titleheight - bottomborderwidth, borderleftcolor.ToMonoColor());
|
||||
}
|
||||
else
|
||||
{
|
||||
gfx.DrawRectangle(0, titleheight, leftborderwidth, Height - titleheight - bottomborderwidth, leftimg.ToTexture2D(gfx.Device));
|
||||
gfx.DrawRectangle(0, titleheight, leftborderwidth, Height - titleheight - bottomborderwidth, UIManager.SkinTextures["leftborder"]);
|
||||
}
|
||||
|
||||
//RIGHT
|
||||
var rightimg = GetImage("rightborder");
|
||||
if (rightimg == null)
|
||||
if (!UIManager.SkinTextures.ContainsKey("rightborder"))
|
||||
{
|
||||
gfx.DrawRectangle(brightlocx, titleheight, rightborderwidth, Height - titleheight - bottomborderwidth, borderrightcolor.ToMonoColor());
|
||||
}
|
||||
else
|
||||
{
|
||||
gfx.DrawRectangle(brightlocx, titleheight, rightborderwidth, Height - titleheight - bottomborderwidth, rightimg.ToTexture2D(gfx.Device));
|
||||
gfx.DrawRectangle(brightlocx, titleheight, rightborderwidth, Height - titleheight - bottomborderwidth, UIManager.SkinTextures["rightborder"]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -393,6 +393,8 @@ namespace ShiftOS.Frontend.GUI
|
|||
gfx.Width = ctrl.Width;
|
||||
gfx.Height = ctrl.Height;
|
||||
ctrl.Paint(gfx);
|
||||
gfx.X = draw_x;
|
||||
gfx.Y = draw_y;
|
||||
}
|
||||
gfx.Width = draw_width;
|
||||
gfx.Height = draw_height;
|
||||
|
|
|
@ -89,7 +89,7 @@ namespace ShiftOS.Frontend.GraphicsSubsystem
|
|||
|
||||
public void Clear(Color c)
|
||||
{
|
||||
DrawRectangle(_startx, _starty, _maxwidth, _maxheight, c);
|
||||
DrawRectangle(0, 0, _maxwidth, _maxheight, c);
|
||||
}
|
||||
|
||||
public void DrawLine(int x, int y, int x1, int y1, int thickness, Texture2D tex2)
|
||||
|
@ -152,7 +152,13 @@ namespace ShiftOS.Frontend.GraphicsSubsystem
|
|||
{
|
||||
using(var gfx = System.Drawing.Graphics.FromImage(bmp))
|
||||
{
|
||||
gfx.DrawString(text, font, new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(color.A, color.R, color.G, color.B)), 0, 0);
|
||||
var textformat = new System.Drawing.StringFormat(System.Drawing.StringFormat.GenericTypographic);
|
||||
textformat.FormatFlags = System.Drawing.StringFormatFlags.MeasureTrailingSpaces;
|
||||
textformat.Trimming = System.Drawing.StringTrimming.None;
|
||||
textformat.FormatFlags |= System.Drawing.StringFormatFlags.NoClip;
|
||||
|
||||
gfx.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
|
||||
gfx.DrawString(text, font, new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(color.A, color.R, color.G, color.B)), 0, 0, textformat);
|
||||
}
|
||||
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];
|
||||
|
|
|
@ -100,6 +100,14 @@ namespace ShiftOS.Frontend.GraphicsSubsystem
|
|||
ctrl.Layout();
|
||||
}
|
||||
|
||||
public static void InvalidateAll()
|
||||
{
|
||||
foreach(var ctrl in topLevels)
|
||||
{
|
||||
ctrl.Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public static void ProcessMouseState(MouseState state)
|
||||
{
|
||||
foreach(var ctrl in topLevels.ToArray())
|
||||
|
@ -110,11 +118,50 @@ namespace ShiftOS.Frontend.GraphicsSubsystem
|
|||
|
||||
public static void ProcessKeyEvent(KeyEvent e)
|
||||
{
|
||||
if (e.ControlDown && e.Key == Keys.T)
|
||||
{
|
||||
AppearanceManager.SetupWindow(new Apps.Terminal());
|
||||
return;
|
||||
}
|
||||
FocusedControl?.ProcessKeyEvent(e);
|
||||
}
|
||||
|
||||
private static Texture2D DesktopBackground = null;
|
||||
|
||||
public static Dictionary<string, Texture2D> SkinTextures = new Dictionary<string, Texture2D>();
|
||||
|
||||
public static void ResetSkinTextures(GraphicsDevice graphics)
|
||||
{
|
||||
SkinTextures.Clear();
|
||||
foreach(var byteArray in SkinEngine.LoadedSkin.GetType().GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance).Where(x=>x.FieldType == typeof(byte[])))
|
||||
{
|
||||
var imgAttrib = byteArray.GetCustomAttributes(false).FirstOrDefault(x => x is ImageAttribute) as ImageAttribute;
|
||||
if(imgAttrib != null)
|
||||
{
|
||||
var img = SkinEngine.GetImage(imgAttrib.Name);
|
||||
if(img != null)
|
||||
{
|
||||
var bmp = (System.Drawing.Bitmap)img;
|
||||
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);
|
||||
var tex2 = new Texture2D(graphics, bmp.Width, bmp.Height);
|
||||
for(int i = 0; i < data.Length; i += 4)
|
||||
{
|
||||
byte r = data[i];
|
||||
byte b = data[i + 2];
|
||||
data[i] = b;
|
||||
data[i + 2] = r;
|
||||
}
|
||||
tex2.SetData<byte>(data);
|
||||
SkinTextures.Add(imgAttrib.Name, tex2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static Queue<Action> CrossThreadOperations = new Queue<Action>();
|
||||
|
||||
public static void DrawBackgroundLayer(GraphicsDevice graphics, SpriteBatch batch, int width, int height)
|
||||
|
|
27
ShiftOS.Frontend/Properties/Resources.Designer.cs
generated
27
ShiftOS.Frontend/Properties/Resources.Designer.cs
generated
|
@ -80,6 +80,33 @@ namespace ShiftOS.Frontend.Properties {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to [
|
||||
/////Virus Scanner Grades
|
||||
/// {
|
||||
/// Name: "Virus Scanner Grade 2",
|
||||
/// Description: "Update the Virus Scanner database to include threatlevel 2 viruses.",
|
||||
/// Dependencies: "virus_scanner",
|
||||
/// Category: "Virus Scanner",
|
||||
/// Cost: 75
|
||||
/// },
|
||||
/// {
|
||||
/// Name: "Virus Scanner Grade 3",
|
||||
/// Description: "Update the Virus Scanner database to include threatlevel 3 viruses.",
|
||||
/// Dependencies: "virus_scanner_grade_2",
|
||||
/// Category: "Virus Scanner",
|
||||
/// Cost: 150
|
||||
/// },
|
||||
/// {
|
||||
/// Name: "Virus Scanner Grade 4",
|
||||
/// Description: "Update the [rest of string was truncated]";.
|
||||
/// </summary>
|
||||
internal static string Shiftorium {
|
||||
get {
|
||||
return ResourceManager.GetString("Shiftorium", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to {
|
||||
/// "{SUBMIT}":"Bestätigen",
|
||||
|
|
|
@ -124,6 +124,9 @@
|
|||
<data name="justthes" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\justthes.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="Shiftorium" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\Shiftorium.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
|
||||
</data>
|
||||
<data name="strings_de" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\strings_de.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
|
||||
</data>
|
||||
|
|
1089
ShiftOS.Frontend/Resources/Shiftorium.txt
Normal file
1089
ShiftOS.Frontend/Resources/Shiftorium.txt
Normal file
File diff suppressed because it is too large
Load diff
|
@ -42,6 +42,7 @@
|
|||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Apps\Pong.cs" />
|
||||
<Compile Include="Apps\Terminal.cs" />
|
||||
<Compile Include="Commands.cs" />
|
||||
<Compile Include="Desktop\Desktop.cs" />
|
||||
|
@ -163,6 +164,9 @@
|
|||
<ItemGroup>
|
||||
<None Include="Resources\strings_de.txt" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Resources\Shiftorium.txt" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="$(MSBuildExtensionsPath)\MonoGame\v3.0\MonoGame.Content.Builder.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using Newtonsoft.Json;
|
||||
using ShiftOS.Engine;
|
||||
using ShiftOS.Frontend.GraphicsSubsystem;
|
||||
|
||||
|
@ -22,6 +24,11 @@ namespace ShiftOS.Frontend
|
|||
GraphicsDevice = new GraphicsDeviceManager(this);
|
||||
GraphicsDevice.PreferredBackBufferHeight = 1080;
|
||||
GraphicsDevice.PreferredBackBufferWidth = 1920;
|
||||
SkinEngine.SkinLoaded += () =>
|
||||
{
|
||||
UIManager.ResetSkinTextures(GraphicsDevice.GraphicsDevice);
|
||||
UIManager.InvalidateAll();
|
||||
};
|
||||
UIManager.Viewport = new System.Drawing.Size(
|
||||
GraphicsDevice.PreferredBackBufferWidth,
|
||||
GraphicsDevice.PreferredBackBufferHeight
|
||||
|
@ -70,6 +77,7 @@ namespace ShiftOS.Frontend
|
|||
//Now we can initiate the Infobox subsystem
|
||||
Engine.Infobox.Init(new Infobox());
|
||||
|
||||
|
||||
|
||||
//Let's initiate the engine just for a ha.
|
||||
|
||||
|
@ -79,7 +87,7 @@ namespace ShiftOS.Frontend
|
|||
};
|
||||
|
||||
//We'll use sandbox mode
|
||||
SaveSystem.IsSandbox = false;
|
||||
SaveSystem.IsSandbox = true;
|
||||
Engine.Infobox.Show("Test window", "This is a test window.");
|
||||
SaveSystem.Begin(true);
|
||||
|
||||
|
@ -98,6 +106,9 @@ namespace ShiftOS.Frontend
|
|||
// Create a new SpriteBatch, which can be used to draw textures.
|
||||
this.spriteBatch = new SpriteBatch(base.GraphicsDevice);
|
||||
|
||||
UIManager.ResetSkinTextures(GraphicsDevice.GraphicsDevice);
|
||||
|
||||
|
||||
// TODO: use this.Content to load your game content here
|
||||
var bmp = Properties.Resources.cursor_9x_pointer;
|
||||
var _lock = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
|
||||
|
@ -137,12 +148,9 @@ namespace ShiftOS.Frontend
|
|||
|
||||
//Let's get the mouse state
|
||||
var mouseState = Mouse.GetState(this.Window);
|
||||
if(LastMouseState != mouseState)
|
||||
{
|
||||
LastMouseState = mouseState;
|
||||
UIManager.ProcessMouseState(LastMouseState);
|
||||
}
|
||||
|
||||
|
||||
//So we have mouse input, and the UI layout system working...
|
||||
|
||||
//But an OS isn't useful without the keyboard!
|
||||
|
@ -219,10 +227,22 @@ namespace ShiftOS.Frontend
|
|||
var mousepos = Mouse.GetState(this.Window).Position;
|
||||
spriteBatch.Draw(MouseTexture, new Rectangle(mousepos.X, mousepos.Y, MouseTexture.Width, MouseTexture.Height), Color.White);
|
||||
|
||||
var gfxContext = new GraphicsContext(GraphicsDevice.GraphicsDevice, spriteBatch, 0,0, GraphicsDevice.PreferredBackBufferWidth, GraphicsDevice.PreferredBackBufferHeight);
|
||||
|
||||
gfxContext.DrawString("ShiftOS 1.0 Beta 4\r\nCopyright (c) 2017 Michael VanOverbeek, Rylan Arbour, RogueAI\r\nThis is an unstable build.\r\nFPS: " + (1 / gameTime.ElapsedGameTime.TotalSeconds).ToString(), 0, 0, Color.White, new System.Drawing.Font("Lucida Console", 9F, System.Drawing.FontStyle.Bold));
|
||||
|
||||
|
||||
spriteBatch.End();
|
||||
base.Draw(gameTime);
|
||||
}
|
||||
}
|
||||
|
||||
[ShiftoriumProvider]
|
||||
public class MonoGameShiftoriumProvider : IShiftoriumProvider
|
||||
{
|
||||
public List<ShiftoriumUpgrade> GetDefaults()
|
||||
{
|
||||
return JsonConvert.DeserializeObject<List<ShiftoriumUpgrade>>(Properties.Resources.Shiftorium);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -203,10 +203,8 @@ namespace ShiftOS.Engine
|
|||
{
|
||||
LoadSkin();
|
||||
}
|
||||
if (SaveSystem.CurrentSave != null)
|
||||
{
|
||||
SkinLoaded?.Invoke();
|
||||
}
|
||||
SkinLoaded?.Invoke();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
Reference in a new issue