aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.Frontend
diff options
context:
space:
mode:
Diffstat (limited to 'ShiftOS.Frontend')
-rw-r--r--ShiftOS.Frontend/Apps/Pong.cs8
-rw-r--r--ShiftOS.Frontend/Desktop/WindowManager.cs94
-rw-r--r--ShiftOS.Frontend/GUI/Button.cs18
-rw-r--r--ShiftOS.Frontend/GUI/Control.cs7
-rw-r--r--ShiftOS.Frontend/GUI/PictureBox.cs15
-rw-r--r--ShiftOS.Frontend/GraphicsSubsystem/GraphicsContext.cs8
-rw-r--r--ShiftOS.Frontend/GraphicsSubsystem/UIManager.cs32
-rw-r--r--ShiftOS.Frontend/Infobox.cs4
-rw-r--r--ShiftOS.Frontend/ShiftOS.cs23
9 files changed, 127 insertions, 82 deletions
diff --git a/ShiftOS.Frontend/Apps/Pong.cs b/ShiftOS.Frontend/Apps/Pong.cs
index 595f8ce..aed7cf1 100644
--- a/ShiftOS.Frontend/Apps/Pong.cs
+++ b/ShiftOS.Frontend/Apps/Pong.cs
@@ -73,12 +73,12 @@ namespace ShiftOS.Frontend.Apps
aiballYLocal -= ((double)paddleWidth / 2);
- gfx.Clear(SkinEngine.LoadedSkin.ControlColor.ToMonoColor());
+ base.OnPaint(gfx);
//draw the ball
if (doBallCalc)
{
- gfx.DrawRectangle((int)ballXLocal, (int)ballYLocal, paddleWidth, paddleWidth, SkinEngine.LoadedSkin.ControlTextColor.ToMonoColor());
+ gfx.DrawRectangle((int)ballXLocal, (int)ballYLocal, paddleWidth, paddleWidth, UIManager.SkinTextures["ControlTextColor"]);
}
double playerYLocal = linear(playerY, -1.0, 1.0, 0, Height);
double opponentYLocal = linear(opponentY, -1.0, 1.0, 0, Height);
@@ -88,11 +88,11 @@ namespace ShiftOS.Frontend.Apps
int paddleStart = paddleWidth;
//draw player paddle
- gfx.DrawRectangle(paddleWidth, (int)playerYLocal - (paddleHeight / 2), paddleWidth, paddleHeight, SkinEngine.LoadedSkin.ControlTextColor.ToMonoColor());
+ gfx.DrawRectangle(paddleWidth, (int)playerYLocal - (paddleHeight / 2), paddleWidth, paddleHeight, UIManager.SkinTextures["ControlTextColor"]);
//draw opponent
- gfx.DrawRectangle(Width - (paddleWidth*2), (int)opponentYLocal - (paddleHeight / 2), paddleWidth, paddleHeight, SkinEngine.LoadedSkin.ControlTextColor.ToMonoColor());
+ gfx.DrawRectangle(Width - (paddleWidth*2), (int)opponentYLocal - (paddleHeight / 2), paddleWidth, paddleHeight, UIManager.SkinTextures["ControlTextColor"]);
string cp_text = Localization.Parse("{PONG_STATUSCP}", new Dictionary<string, string>
{
diff --git a/ShiftOS.Frontend/Desktop/WindowManager.cs b/ShiftOS.Frontend/Desktop/WindowManager.cs
index e48ac7c..d89cbc2 100644
--- a/ShiftOS.Frontend/Desktop/WindowManager.cs
+++ b/ShiftOS.Frontend/Desktop/WindowManager.cs
@@ -149,8 +149,37 @@ namespace ShiftOS.Frontend.Desktop
{
X = 720;
Y = 480;
+ MouseDown += () =>
+ {
+ var scnloc = PointToScreen(MouseX, MouseY);
+ mouseprevx = scnloc.X;
+ mouseprevy = scnloc.Y;
+ moving = true;
+ };
+ MouseMove += (loc) =>
+ {
+ if (moving == true)
+ {
+ var scnloc = PointToScreen(MouseX, MouseY);
+ int differencex = scnloc.X - mouseprevx;
+ int differencey = scnloc.Y - mouseprevy;
+ X -= differencex;
+ Y -= differencey;
+ mouseprevx = scnloc.X;
+ mouseprevy = scnloc.Y;
+ }
+ };
+ MouseUp += () =>
+ {
+ moving = false;
+ };
}
+ private bool moving = false;
+ private int mouseprevx = 0;
+ private int mouseprevy = 0;
+
+
public IShiftOSWindow ParentWindow
{
get
@@ -210,59 +239,8 @@ namespace ShiftOS.Frontend.Desktop
Height = _hostedwindow.Y + _hostedwindow.Height + LoadedSkin.BottomBorderWidth;
}
- private bool moving = false;
- public override void MouseStateChanged()
- {
- if (Shiftorium.UpgradeInstalled("wm_titlebar"))
- {
- if (Shiftorium.UpgradeInstalled("close_button"))
- {
- var closebuttonsize = LoadedSkin.CloseButtonSize;
- var closebuttonloc = LoadedSkin.CloseButtonFromSide;
- if (LoadedSkin.TitleButtonPosition == 0)
- closebuttonloc = new Point(Width - closebuttonsize.Width - closebuttonloc.X, closebuttonloc.Y);
- if(MouseX > closebuttonloc.X && MouseY > closebuttonloc.Y && MouseX < closebuttonloc.X + closebuttonsize.Width && MouseY < closebuttonloc.Y + closebuttonsize.Height)
- {
- Close();
- }
- }
- if (Shiftorium.UpgradeInstalled("minimize_button"))
- {
- var closebuttonsize = LoadedSkin.MinimizeButtonSize;
- var closebuttonloc = LoadedSkin.MinimizeButtonFromSide;
- if (LoadedSkin.TitleButtonPosition == 0)
- closebuttonloc = new Point(Width - closebuttonsize.Width - closebuttonloc.X, closebuttonloc.Y);
- if (MouseX > closebuttonloc.X && MouseY > closebuttonloc.Y && MouseX < closebuttonloc.X + closebuttonsize.Width && MouseY < closebuttonloc.Y + closebuttonsize.Height)
- {
- if (IsFocusedControl || ContainsFocusedControl)
- UIManager.FocusedControl = null;
- Visible = false;
- }
- }
- if (Shiftorium.UpgradeInstalled("maximize_button"))
- {
- var closebuttonsize = LoadedSkin.MaximizeButtonSize;
- var closebuttonloc = LoadedSkin.MaximizeButtonFromSide;
- if (LoadedSkin.TitleButtonPosition == 0)
- closebuttonloc = new Point(Width - closebuttonsize.Width - closebuttonloc.X, closebuttonloc.Y);
- if (MouseX > closebuttonloc.X && MouseY > closebuttonloc.Y && MouseX < closebuttonloc.X + closebuttonsize.Width && MouseY < closebuttonloc.Y + closebuttonsize.Height)
- {
- AppearanceManager.Maximize(this);
- }
- }
- if (MouseY < LoadedSkin.TitlebarHeight)
- {
- var screenpoint = PointToScreen(MouseX, MouseY);
- lastmousex = this.X - screenpoint.X;
- lastmousey = this.Y - screenpoint.Y;
- moving = MouseLeftDown;
- CaptureMouse = moving;
- }
- }
- }
- [DebuggerStepThrough]
protected override void OnPaint(GraphicsContext gfx)
{
int titleheight = LoadedSkin.TitlebarHeight;
@@ -272,7 +250,7 @@ namespace ShiftOS.Frontend.Desktop
if (Shiftorium.UpgradeInstalled("wm_titlebar"))
{
- var titlebarcolor = LoadedSkin.TitleBackgroundColor;
+ var titlebarcolor = UIManager.SkinTextures["TitleBackgroundColor"];
var titlefont = LoadedSkin.TitleFont;
var titletextcolor = LoadedSkin.TitleTextColor;
var titletextleft = LoadedSkin.TitleTextLeft;
@@ -290,11 +268,9 @@ namespace ShiftOS.Frontend.Desktop
//Let's get the left and right images.
- var leftimage = GetImage("titleleft");
- var rightimage = GetImage("titleright");
//and the colors
- var leftcolor = LoadedSkin.TitleLeftCornerBackground;
- var rightcolor = LoadedSkin.TitleRightCornerBackground;
+ var leftcolor = UIManager.SkinTextures["TitleLeftCornerBackground"];
+ var rightcolor = UIManager.SkinTextures["TitleRightCornerBackground"];
//and the widths
var leftwidth = LoadedSkin.TitleLeftCornerWidth;
var rightwidth = LoadedSkin.TitleRightCornerWidth;
@@ -306,7 +282,7 @@ namespace ShiftOS.Frontend.Desktop
}
else
{
- gfx.DrawRectangle(0, 0, leftwidth, titleheight, leftcolor.ToMonoColor());
+ gfx.DrawRectangle(0, 0, leftwidth, titleheight, leftcolor);
}
//draw right corner
@@ -316,14 +292,14 @@ namespace ShiftOS.Frontend.Desktop
}
else
{
- gfx.DrawRectangle(titlebarleft + titlebarwidth, 0, rightwidth, titleheight, rightcolor.ToMonoColor());
+ gfx.DrawRectangle(titlebarleft + titlebarwidth, 0, rightwidth, titleheight, rightcolor);
}
}
if (!UIManager.SkinTextures.ContainsKey("titlebar"))
{
//draw the title bg
- gfx.DrawRectangle(titlebarleft, 0, titlebarwidth, titleheight, titlebarcolor.ToMonoColor());
+ gfx.DrawRectangle(titlebarleft, 0, titlebarwidth, titleheight, titlebarcolor);
}
else
diff --git a/ShiftOS.Frontend/GUI/Button.cs b/ShiftOS.Frontend/GUI/Button.cs
index 7d6804a..0a0376c 100644
--- a/ShiftOS.Frontend/GUI/Button.cs
+++ b/ShiftOS.Frontend/GUI/Button.cs
@@ -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.GraphicsSubsystem;
@@ -34,15 +35,22 @@ namespace ShiftOS.Frontend.GUI
protected override void OnPaint(GraphicsContext gfx)
{
- var bgCol = SkinEngine.LoadedSkin.ButtonBackgroundColor.ToMonoColor();
+ var bgCol = UIManager.SkinTextures["ButtonBackgroundColor"];
var fgCol = SkinEngine.LoadedSkin.ControlTextColor.ToMonoColor();
if (ContainsMouse)
- bgCol = SkinEngine.LoadedSkin.ButtonHoverColor.ToMonoColor();
+ bgCol = UIManager.SkinTextures["ButtonHoverColor"];
if (MouseLeftDown)
- bgCol = SkinEngine.LoadedSkin.ButtonPressedColor.ToMonoColor();
+ bgCol = UIManager.SkinTextures["ButtonPressedColor"];
+
+ gfx.DrawRectangle(0, 0, Width, Height, fgCol);
+ gfx.DrawRectangle(1, 1, Width - 2, Height - 2, bgCol);
+
+ var measure = gfx.MeasureString(Text, Font);
+
+ var loc = new Vector2((Width - measure.X) / 2, (Height - measure.Y) / 2);
+
+ gfx.DrawString(Text, (int)loc.X, (int)loc.Y, fgCol, Font);
- base.OnPaint(gfx);
- base.OnPaint(gfx);
}
}
}
diff --git a/ShiftOS.Frontend/GUI/Control.cs b/ShiftOS.Frontend/GUI/Control.cs
index 012b2ee..c16792b 100644
--- a/ShiftOS.Frontend/GUI/Control.cs
+++ b/ShiftOS.Frontend/GUI/Control.cs
@@ -364,7 +364,7 @@ namespace ShiftOS.Frontend.GUI
protected virtual void OnPaint(GraphicsContext gfx)
{
- gfx.Clear(Engine.SkinEngine.LoadedSkin.ControlColor.ToMonoColor());
+ gfx.DrawRectangle(0, 0, Width, Height, UIManager.SkinTextures["ControlColor"]);
}
public void SendToBack()
@@ -558,6 +558,7 @@ namespace ShiftOS.Frontend.GUI
{
Click?.Invoke();
Invalidate();
+ MouseUp?.Invoke();
}
if (_leftState == false && ld == true)
{
@@ -565,6 +566,8 @@ namespace ShiftOS.Frontend.GUI
UIManager.FocusedControl = this;
focused?.InvalidateTopLevel();
InvalidateTopLevel();
+ MouseDown?.Invoke();
+
}
_leftState = ld;
_middleState = md;
@@ -631,6 +634,8 @@ namespace ShiftOS.Frontend.GUI
public event Action MouseLeave;
public event Action Click;
public event Action<KeyEvent> KeyEvent;
+ public event Action MouseDown;
+ public event Action MouseUp;
}
public struct Point
diff --git a/ShiftOS.Frontend/GUI/PictureBox.cs b/ShiftOS.Frontend/GUI/PictureBox.cs
index 91735aa..6f60b29 100644
--- a/ShiftOS.Frontend/GUI/PictureBox.cs
+++ b/ShiftOS.Frontend/GUI/PictureBox.cs
@@ -8,12 +8,13 @@ using System.Threading.Tasks;
using ShiftOS.Engine;
using System.Drawing.Imaging;
using ShiftOS.Frontend.GraphicsSubsystem;
+using Microsoft.Xna.Framework.Graphics;
namespace ShiftOS.Frontend.GUI
{
public class PictureBox : Control
{
- private System.Drawing.Image img = null;
+ private Texture2D img = null;
private ImageLayout _layout = ImageLayout.Fit;
public ImageLayout ImageLayout
@@ -28,7 +29,7 @@ namespace ShiftOS.Frontend.GUI
}
}
- public System.Drawing.Image Image
+ public Texture2D Image
{
get
{
@@ -53,6 +54,16 @@ namespace ShiftOS.Frontend.GUI
protected override void OnPaint(GraphicsContext gfx)
{
+ switch (_layout)
+ {
+ case ImageLayout.Stretch:
+ gfx.DrawRectangle(0, 0, Width, Height, Image);
+ break;
+ case ImageLayout.None:
+ gfx.DrawRectangle(0, 0, Image.Width, Image.Height, Image);
+ break;
+ }
+
}
//Again, thanks StackOverflow
diff --git a/ShiftOS.Frontend/GraphicsSubsystem/GraphicsContext.cs b/ShiftOS.Frontend/GraphicsSubsystem/GraphicsContext.cs
index 43292c0..1ab45db 100644
--- a/ShiftOS.Frontend/GraphicsSubsystem/GraphicsContext.cs
+++ b/ShiftOS.Frontend/GraphicsSubsystem/GraphicsContext.cs
@@ -165,6 +165,14 @@ namespace ShiftOS.Frontend.GraphicsSubsystem
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)
+ {
+ 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);
}
diff --git a/ShiftOS.Frontend/GraphicsSubsystem/UIManager.cs b/ShiftOS.Frontend/GraphicsSubsystem/UIManager.cs
index fa17807..1157070 100644
--- a/ShiftOS.Frontend/GraphicsSubsystem/UIManager.cs
+++ b/ShiftOS.Frontend/GraphicsSubsystem/UIManager.cs
@@ -44,7 +44,7 @@ namespace ShiftOS.Frontend.GraphicsSubsystem
public static void DrawTArgets(SpriteBatch batch)
{
- foreach(var ctrl in topLevels)
+ foreach(var ctrl in topLevels.ToArray())
{
if (ctrl.Visible == true)
{
@@ -55,12 +55,13 @@ namespace ShiftOS.Frontend.GraphicsSubsystem
continue;
}
var _target = TextureCaches[hc];
- var gfxContext = new GraphicsContext(batch.GraphicsDevice, batch, ctrl.X, ctrl.Y, ctrl.Width + 5, ctrl.Height + 5);
- gfxContext.DrawRectangle(ctrl.Width, 0, 1, ctrl.Height, Color.Black);
- gfxContext.DrawRectangle(ctrl.Width + 1, 0, 1, ctrl.Height, Color.Black * 0.75f);
- gfxContext.DrawRectangle(ctrl.Width + 2, 0, 1, ctrl.Height, Color.Black * 0.5f);
- gfxContext.DrawRectangle(ctrl.Width + 3, 0, 1, ctrl.Height, Color.Black * 0.25f);
-
+ if (ExperimentalEffects)
+ {
+ 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, ctrl.Y, ctrl.Width, ctrl.Height), Color.White);
}
@@ -178,12 +179,21 @@ namespace ShiftOS.Frontend.GraphicsSubsystem
}
}
}
+
+ foreach(var colorfield in SkinEngine.LoadedSkin.GetType().GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance).Where(x=>x.FieldType == typeof(System.Drawing.Color)))
+ {
+ var color = (System.Drawing.Color)colorfield.GetValue(SkinEngine.LoadedSkin);
+ var tex2 = new Texture2D(graphics, 1, 1);
+ tex2.SetData<byte>(new[] { color.B, color.G, color.R, color.A });
+ SkinTextures.Add(colorfield.Name, tex2);
+ }
}
public static bool ExperimentalEffects = true;
public static Queue<Action> CrossThreadOperations = new Queue<Action>();
+ internal static GraphicsDevice GraphicsDevice;
public static void DrawBackgroundLayer(GraphicsDevice graphics, SpriteBatch batch, int width, int height)
{
@@ -205,6 +215,14 @@ namespace ShiftOS.Frontend.GraphicsSubsystem
{
if (topLevels.Contains(ctrl))
topLevels.Remove(ctrl);
+
+ int hc = ctrl.GetHashCode();
+ if (TextureCaches.ContainsKey(hc))
+ {
+ TextureCaches[hc].Dispose();
+ TextureCaches.Remove(hc);
+ }
+
ctrl = null;
}
}
diff --git a/ShiftOS.Frontend/Infobox.cs b/ShiftOS.Frontend/Infobox.cs
index 3f47b54..a71785b 100644
--- a/ShiftOS.Frontend/Infobox.cs
+++ b/ShiftOS.Frontend/Infobox.cs
@@ -4,6 +4,8 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ShiftOS.Engine;
+using ShiftOS.Frontend.Desktop;
+using ShiftOS.Frontend.GraphicsSubsystem;
using ShiftOS.Frontend.GUI;
namespace ShiftOS.Frontend
@@ -165,7 +167,7 @@ namespace ShiftOS.Frontend
this.pbicon.Y = 19;
this.pbicon.Width = 64;
this.pbicon.Height = 64;
- this.pbicon.Image = Properties.Resources.justthes;
+ this.pbicon.Image = Properties.Resources.justthes.ToTexture2D(UIManager.GraphicsDevice);
this.pbicon.ImageLayout = ImageLayout.Stretch;
//
// Dialog
diff --git a/ShiftOS.Frontend/ShiftOS.cs b/ShiftOS.Frontend/ShiftOS.cs
index df61b91..8f7c47b 100644
--- a/ShiftOS.Frontend/ShiftOS.cs
+++ b/ShiftOS.Frontend/ShiftOS.cs
@@ -65,6 +65,7 @@ namespace ShiftOS.Frontend
protected override void Initialize()
{
//Before we do ANYTHING, we've got to initiate the ShiftOS engine.
+ UIManager.GraphicsDevice = GraphicsDevice.GraphicsDevice;
//Let's get localization going.
Localization.RegisterProvider(new MonoGameLanguageProvider());
@@ -89,7 +90,7 @@ namespace ShiftOS.Frontend
};
//We'll use sandbox mode
- SaveSystem.IsSandbox = true;
+ SaveSystem.IsSandbox = false;
Engine.Infobox.Show("Test window", "This is a test window.");
SaveSystem.Begin(true);
@@ -191,8 +192,11 @@ namespace ShiftOS.Frontend
if (control && lastKey == Keys.D)
{
DisplayDebugInfo = !DisplayDebugInfo;
-
}
+ else if(control && lastKey == Keys.E)
+ {
+ UIManager.ExperimentalEffects = !UIManager.ExperimentalEffects;
+ }
else
{
var e = new KeyEvent(control, alt, shift, lastKey);
@@ -237,12 +241,25 @@ namespace ShiftOS.Frontend
var mousepos = Mouse.GetState(this.Window).Position;
+ spriteBatch.Draw(MouseTexture, new Rectangle(mousepos.X+1, mousepos.Y+1, MouseTexture.Width, MouseTexture.Height), Color.Black * 0.5f);
spriteBatch.Draw(MouseTexture, new Rectangle(mousepos.X, mousepos.Y, MouseTexture.Width, MouseTexture.Height), Color.White);
+
if (DisplayDebugInfo)
{
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));
+ 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)}
+
+UI render target count: {UIManager.TextureCaches.Count}
+Skin texture caches: {UIManager.SkinTextures.Count}
+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));
}
spriteBatch.End();