all the work I've done for the day

This commit is contained in:
Michael 2017-07-05 22:24:17 -04:00
parent de9bc8567b
commit 38774ba793
4 changed files with 51 additions and 22 deletions

View file

@ -141,7 +141,7 @@ namespace ShiftOS.Frontend.Desktop
else
{
//draw with a color
var color = LoadedSkin.DesktopPanelColor.ToMonoColor();
var color = UIManager.SkinTextures["DesktopPanelColor"];
gfx.DrawRectangle(0, dp_position, dp_width, dp_height, color);
}
@ -173,7 +173,7 @@ namespace ShiftOS.Frontend.Desktop
else
{
//draw using the bg color
var pcBGColor = LoadedSkin.DesktopPanelClockBackgroundColor.ToMonoColor();
var pcBGColor = UIManager.SkinTextures["DesktopPanelClockBackgroundColor"];
gfx.DrawRectangle(panelclockleft, dp_position, panelclockwidth, dp_height, pcBGColor);
}
@ -201,7 +201,7 @@ namespace ShiftOS.Frontend.Desktop
}
else
{
gfx.DrawRectangle(offset, dp_position + pbtnfromtop, pbtnwidth, pbtnheight, LoadedSkin.PanelButtonColor.ToMonoColor());
gfx.DrawRectangle(offset, dp_position + pbtnfromtop, pbtnwidth, pbtnheight, UIManager.SkinTextures["PanelButtonBackgroundColor"]);
}
//now we draw the text

View file

@ -148,33 +148,35 @@ namespace ShiftOS.Frontend.GraphicsSubsystem
measure = MeasureString(text, font);
else
measure = MeasureString(text, font, wrapWidth);
using(var bmp = new System.Drawing.Bitmap((int)measure.X, (int)measure.Y))
using (var bmp = new System.Drawing.Bitmap((int)measure.X, (int)measure.Y))
{
using(var gfx = System.Drawing.Graphics.FromImage(bmp))
using (var gfx = System.Drawing.Graphics.FromImage(bmp))
{
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.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel;
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];
System.Runtime.InteropServices.Marshal.Copy(lck.Scan0, data, 0, data.Length);
bmp.UnlockBits(lck);
var tex2 = new Texture2D(_graphicsDevice, bmp.Width, bmp.Height);
for(int i = 0; i < data.Length; i += 4)
using (var tex2 = new Texture2D(_graphicsDevice, bmp.Width, bmp.Height))
{
byte r = data[i];
byte b = data[i + 2];
data[i] = b;
data[i + 2] = r;
}
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);
_spritebatch.Draw(tex2, new Rectangle(x, y, bmp.Width, bmp.Height), Color.White);
tex2.SetData<byte>(data);
_spritebatch.Draw(tex2, new Rectangle(x, y, bmp.Width, bmp.Height), Color.White);
}
}
}

View file

@ -59,7 +59,7 @@ namespace ShiftOS.Frontend.GraphicsSubsystem
{
for (int i = 5; i > 0; i--)
{
batch.Draw(_target, new Rectangle(ctrl.X + i, ctrl.Y + i, ctrl.Width, ctrl.Height), new Color(Color.Black, 255 / (i * 2)));
batch.Draw(_target, new Rectangle(ctrl.X - i, ctrl.Y - i, ctrl.Width+(i*2), ctrl.Height+(i*2)), new Color(Color.Black, 255 / (i * 2)));
}
}
@ -69,7 +69,7 @@ namespace ShiftOS.Frontend.GraphicsSubsystem
}
public static void SendToBack(Control ctrl)
{
{
topLevels.Remove(ctrl);
topLevels.Insert(0, ctrl);
}
@ -171,6 +171,10 @@ namespace ShiftOS.Frontend.GraphicsSubsystem
{
byte r = data[i];
byte b = data[i + 2];
if (r == 1 && b == 1 && data[i + 1] == 1)
{
data[i + 3] = 0;
}
data[i] = b;
data[i + 2] = r;
}
@ -187,6 +191,9 @@ namespace ShiftOS.Frontend.GraphicsSubsystem
tex2.SetData<byte>(new[] { color.B, color.G, color.R, color.A });
SkinTextures.Add(colorfield.Name, tex2);
}
}

View file

@ -90,7 +90,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);
@ -227,9 +227,13 @@ namespace ShiftOS.Frontend
{
UIManager.DrawControlsToTargets(GraphicsDevice.GraphicsDevice, spriteBatch, 0, 0);
var rasterizerState = new RasterizerState();
rasterizerState.CullMode = CullMode.None;
rasterizerState.MultiSampleAntiAlias = true;
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied,
SamplerState.LinearClamp, DepthStencilState.Default,
RasterizerState.CullNone);
rasterizerState);
//Draw the desktop BG.
UIManager.DrawBackgroundLayer(GraphicsDevice.GraphicsDevice, spriteBatch, 640, 480);
@ -247,11 +251,27 @@ namespace ShiftOS.Frontend
if (DisplayDebugInfo)
{
var gfxContext = new GraphicsContext(GraphicsDevice.GraphicsDevice, spriteBatch, 0, 0, GraphicsDevice.PreferredBackBufferWidth, GraphicsDevice.PreferredBackBufferHeight);
var color = Color.White;
double fps = 1 / gameTime.ElapsedGameTime.TotalSeconds;
if (fps <= 20)
color = Color.Red;
gfxContext.DrawString($@"ShiftOS 1.0 Beta 4
Copyright (c) 2017 Michael VanOverbeek, Rylan Arbour, RogueAI
This is an unstable build.
FPS: {(1 / gameTime.ElapsedGameTime.TotalSeconds)}
FPS: {(fps)}
An FPS below 20 can cause glitches in keyboard and mouse handling. It is advised that if you are getting these
framerates, press CTRL+E to disable fancy effects, close any apps you are not using, and try running in windowed mode
or in a lower resolution.
If all else fails, you can set a breakpoint somewhere in the ShiftOS.Update() or ShiftOS.Draw() methods in the game's source
code and use Visual Studio's debugger to step through the code to find bottlenecks.
If a method takes more than 30 milliseconds to complete, that is a sign that it is bottlenecking the game and may need to be
optimized.
Try using the SkinTextures cache when rendering skin elements, and try using the GraphicsContext.DrawString() method when drawing
text. In this build, we are aware that this method causes bottlenecking, we are working on a caching system for fonts so we do not need to
use the System.Drawing.Graphics class to draw text.
UI render target count: {UIManager.TextureCaches.Count}
Skin texture caches: {UIManager.SkinTextures.Count}
@ -259,7 +279,7 @@ Open windows (excluding dialog boxes): {AppearanceManager.OpenForms.Count}
Experimental effects enabled: {UIManager.ExperimentalEffects}
Fullscreen: {GraphicsDevice.IsFullScreen}
Game resolution: {GraphicsDevice.PreferredBackBufferWidth}x{GraphicsDevice.PreferredBackBufferHeight}", 0, 0, Color.White, new System.Drawing.Font("Lucida Console", 9F, System.Drawing.FontStyle.Bold));
Game resolution: {GraphicsDevice.PreferredBackBufferWidth}x{GraphicsDevice.PreferredBackBufferHeight}", 0, 0, color, new System.Drawing.Font("Lucida Console", 9F, System.Drawing.FontStyle.Bold));
}
spriteBatch.End();