aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.WinForms/LuaDesktop.cs
diff options
context:
space:
mode:
authorMichael <[email protected]>2017-02-18 10:37:11 -0500
committerMichael <[email protected]>2017-02-18 10:37:11 -0500
commit9b8d5861a954610713ae66a53d2ac067991d9b68 (patch)
treee550f758e52ec8ca12357d91c9fa13907e70c4f3 /ShiftOS.WinForms/LuaDesktop.cs
parent30823a0778614d0f9fd6f82b5d9eb03aab41280d (diff)
downloadshiftos_thereturn-9b8d5861a954610713ae66a53d2ac067991d9b68.tar.gz
shiftos_thereturn-9b8d5861a954610713ae66a53d2ac067991d9b68.tar.bz2
shiftos_thereturn-9b8d5861a954610713ae66a53d2ac067991d9b68.zip
WHOA LUA STUFF :dancer:
Diffstat (limited to 'ShiftOS.WinForms/LuaDesktop.cs')
-rw-r--r--ShiftOS.WinForms/LuaDesktop.cs158
1 files changed, 140 insertions, 18 deletions
diff --git a/ShiftOS.WinForms/LuaDesktop.cs b/ShiftOS.WinForms/LuaDesktop.cs
index 445a571..8fd5244 100644
--- a/ShiftOS.WinForms/LuaDesktop.cs
+++ b/ShiftOS.WinForms/LuaDesktop.cs
@@ -7,17 +7,35 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
-
+using Newtonsoft.Json;
using ShiftOS.Engine;
using ShiftOS.Engine.Scripting;
+using ShiftOS.Objects.ShiftFS;
+using static ShiftOS.Engine.SkinEngine;
+
namespace ShiftOS.WinForms
{
public partial class LuaDesktop : Form, IDesktop
{
- public LuaDesktop()
+ public LuaDesktop(string script)
{
InitializeComponent();
+ interpreter = new LuaInterpreter();
+ interpreter.Lua.getCanvas = new Func<Panel>(() =>
+ {
+ return this.pnlcanvas;
+ });
+ if (Utils.FileExists(script))
+ {
+ interpreter.ExecuteFile(script);
+ }
+ else
+ {
+ Desktop.Init(new WinformsDesktop(), true);
+ Infobox.Show("Script not found.", "Couldn't find a ShiftOS script to handle the desktop environment.");
+ this.Close();
+ }
}
private LuaInterpreter interpreter = null;
@@ -39,6 +57,8 @@ namespace ShiftOS.WinForms
}
}
+ private IWindowBorder focused = null;
+
public Size GetSize()
{
return this.Size;
@@ -49,44 +69,146 @@ namespace ShiftOS.WinForms
this.Invoke(act);
}
- public void KillWindow(IWindowBorder border)
+ public void PopulateAppLauncher(LauncherItem[] items)
{
- throw new NotImplementedException();
+ interpreter.Lua.populateAppLauncher(interpreter.Lua.totable(new List<LauncherItem>(items)));
}
- public void MaximizeWindow(IWindowBorder brdr)
+ public void PopulatePanelButtons()
{
- throw new NotImplementedException();
+ interpreter.Lua.populatePanelButtons();
}
- public void MinimizeWindow(IWindowBorder brdr)
+ public void SetupDesktop()
{
- throw new NotImplementedException();
+ try
+ {
+ interpreter.Lua.setupDesktop();
+ }
+ catch (Exception ex)
+ {
+ Infobox.Show("Desktop setup error", "The desktop environment threw an exception: \r\n\r\n\r\n" + ex.Message);
+ Desktop.Init(new WinformsDesktop(), true);
+ this.Close();
+ }
}
- public void PopulateAppLauncher(LauncherItem[] items)
+ public void ShowWindow(IWindowBorder border)
{
-
+ var brdr = border as Form;
+ focused = border;
+ brdr.GotFocus += (o, a) =>
+ {
+ focused = border;
+ };
+ brdr.FormBorderStyle = FormBorderStyle.None;
+ brdr.Show();
+ brdr.TopMost = true;
}
- public void PopulatePanelButtons()
+ /// <summary>
+ /// Kills the window.
+ /// </summary>
+ /// <returns>The window.</returns>
+ /// <param name="border">Border.</param>
+ public void KillWindow(IWindowBorder border)
{
- throw new NotImplementedException();
+ border.Close();
}
- public void RestoreWindow(IWindowBorder brdr)
+ /// <summary>
+ /// Minimizes the window.
+ /// </summary>
+ /// <param name="brdr">Brdr.</param>
+ public void MinimizeWindow(IWindowBorder brdr)
+ {
+ var loc = (brdr as WindowBorder).Location;
+ var sz = (brdr as WindowBorder).Size;
+ (brdr as WindowBorder).Tag = JsonConvert.SerializeObject(new
+ {
+ Size = sz,
+ Location = loc
+ });
+ (brdr as WindowBorder).Location = new Point(this.GetSize().Width * 2, this.GetSize().Height * 2);
+ }
+
+ /// <summary>
+ /// Maximizes the window.
+ /// </summary>
+ /// <returns>The window.</returns>
+ /// <param name="brdr">Brdr.</param>
+ public void MaximizeWindow(IWindowBorder brdr)
{
- throw new NotImplementedException();
+ int startY = (LoadedSkin.DesktopPanelPosition == 1) ? 0 : LoadedSkin.DesktopPanelHeight;
+ int h = this.GetSize().Height - LoadedSkin.DesktopPanelHeight;
+ var loc = (brdr as WindowBorder).Location;
+ var sz = (brdr as WindowBorder).Size;
+ (brdr as WindowBorder).Tag = JsonConvert.SerializeObject(new
+ {
+ Size = sz,
+ Location = loc
+ });
+ (brdr as WindowBorder).Location = new Point(0, startY);
+ (brdr as WindowBorder).Size = new Size(this.GetSize().Width, h);
+
}
- public void SetupDesktop()
+ /// <summary>
+ /// Restores the window.
+ /// </summary>
+ /// <returns>The window.</returns>
+ /// <param name="brdr">Brdr.</param>
+ public void RestoreWindow(IWindowBorder brdr)
{
- throw new NotImplementedException();
+ dynamic tag = JsonConvert.DeserializeObject<dynamic>((brdr as WindowBorder).Tag.ToString());
+ (brdr as WindowBorder).Location = tag.Location;
+ (brdr as WindowBorder).Size = tag.Size;
+
}
- public void ShowWindow(IWindowBorder border)
+ private void LuaDesktop_Load(object sender, EventArgs e)
{
- throw new NotImplementedException();
+ this.LocationChanged += (o, a) =>
+ {
+ if (this.Left != 0)
+ this.Left = 0;
+ if (this.Top != 0)
+ this.Top = 0;
+ };
+
+ this.SizeChanged += (o, a) =>
+ {
+ if(this.DisplayRectangle != Screen.PrimaryScreen.Bounds)
+ {
+ this.WindowState = FormWindowState.Maximized;
+ }
+ };
+
+ interpreter.Lua.onLoadDesktop();
+ SetupDesktop();
+ SaveSystem.GameReady += () =>
+ {
+ InvokeOnWorkerThread(new Action(() =>
+ {
+ SetupDesktop();
+ }));
+ };
+ SkinEngine.SkinLoaded += () =>
+ {
+ if(this.Visible == true)
+ {
+ SetupDesktop();
+ }
+ };
+ Shiftorium.Installed += () =>
+ {
+ if (this.Visible == true)
+ {
+ SetupDesktop();
+ }
+
+ };
+
}
}
}