Implement maximizing and minimizing

Fixes #24 and makes panel buttons useful.
This commit is contained in:
Michael 2017-02-04 13:21:38 -05:00
parent e92d575e62
commit 50971ea04e
5 changed files with 139 additions and 31 deletions

View file

@ -134,10 +134,13 @@ namespace ShiftOS.WinForms.Applications
TerminalBackend.PrefixEnabled = true;
TerminalBackend.InStory = false;
Console.Write($"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ");
if (SaveSystem.CurrentSave.StoryPosition == 6)
if (Shiftorium.UpgradeInstalled("wm_free_placement"))
{
Infobox.Show("Welcome to ShiftOS.", "Welcome to the ShiftOS multi-user domain. Your goal is to upgrade your system as much as possible, and gain as much wealth as possible. The first step is to get a feel for the environment. Go forth and explore, young Shifter.");
SaveSystem.CurrentSave.StoryPosition++;
this.ParentForm.Width = 640;
this.ParentForm.Height = 480;
this.ParentForm.Left = (Screen.PrimaryScreen.Bounds.Width - 640) / 2;
this.ParentForm.Top = (Screen.PrimaryScreen.Bounds.Height - 480) / 2;
}
}));
}

View file

@ -217,6 +217,12 @@
Name: "Minimize Command",
Cost: 1250,
Description: "Use the win.mini{id} command to minimize/restore windows.",
Dependencies: "useful_panel_buttons"
},
{
Name: "Useful Panel Buttons",
Cost: 250,
Description: "Minimize and restore windows by clicking their Panel Button!",
Dependencies: "desktop"
},
{

View file

@ -354,21 +354,49 @@ namespace ShiftOS.WinForms
/// <param name="e">E.</param>
private void pnlmaximize_Click(object sender, EventArgs e)
{
TerminalBackend.InvokeCommand($"win.max{{id:{this.ParentForm.GetHashCode()}}}");
if (maximized == false)
Desktop.MaximizeWindow(this);
else
Desktop.RestoreWindow(this);
maximized = !maximized;
}
/// <summary>
/// Pnlminimizes the click.
/// </summary>
/// <returns>The click.</returns>
/// <param name="sender">Sender.</param>
/// <param name="e">E.</param>
bool minimized = false;
bool maximized = false;
public bool IsMinimized
{
get
{
return minimized;
}
}
public bool IsMaximized
{
get
{
return maximized;
}
}
/// <summary>
/// Pnlminimizes the click.
/// </summary>
/// <returns>The click.</returns>
/// <param name="sender">Sender.</param>
/// <param name="e">E.</param>
private void pnlminimize_Click(object sender, EventArgs e)
{
TerminalBackend.InvokeCommand($"win.mini{{id:{this.ParentForm.GetHashCode()}}}");
if (minimized == false)
Desktop.MinimizeWindow(this);
else
Desktop.RestoreWindow(this);
minimized = !minimized;
}
/// <summary>
/// The W m NCLBUTTONDOW.
/// </summary>

View file

@ -35,6 +35,7 @@ using ShiftOS.Engine;
using static ShiftOS.Engine.SkinEngine;
using ShiftOS.WinForms.Tools;
using ShiftOS.WinForms.Applications;
using Newtonsoft.Json;
/// <summary>
/// Winforms desktop.
@ -125,6 +126,26 @@ namespace ShiftOS.WinForms
{
if (form.Visible == true)
{
EventHandler onClick = (o, a) =>
{
if(form == focused)
{
if (form.IsMinimized)
{
RestoreWindow(form);
}
else
{
MinimizeWindow(form);
}
}
else
{
form.BringToFront();
focused = form;
}
};
var pnlbtn = new Panel();
pnlbtn.Margin = new Padding(2, LoadedSkin.PanelButtonFromTop, 0, 0);
pnlbtn.BackColor = LoadedSkin.PanelButtonColor;
@ -151,6 +172,12 @@ namespace ShiftOS.WinForms
this.panelbuttonholder.Controls.Add(pnlbtn);
pnlbtn.Show();
pnlbtntext.Show();
if (Shiftorium.UpgradeInstalled("useful_panel_buttons"))
{
pnlbtn.Click += onClick;
pnlbtntext.Click += onClick;
}
}
}
}
@ -342,6 +369,11 @@ namespace ShiftOS.WinForms
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;
@ -354,17 +386,26 @@ namespace ShiftOS.WinForms
/// <param name="border">Border.</param>
public void KillWindow(IWindowBorder border)
{
throw new NotImplementedException();
border.Close();
}
/// <summary>
/// Minimizes the window.
/// </summary>
/// <returns>The window.</returns>
/// <param name="brdr">Brdr.</param>
private IWindowBorder focused = null;
/// <summary>
/// Minimizes the window.
/// </summary>
/// <param name="brdr">Brdr.</param>
public void MinimizeWindow(IWindowBorder brdr)
{
throw new NotImplementedException();
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>
@ -374,24 +415,38 @@ namespace ShiftOS.WinForms
/// <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);
}
/// <summary>
/// Restores the window.
/// </summary>
/// <returns>The window.</returns>
/// <param name="brdr">Brdr.</param>
/// <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;
}
/// <summary>
/// Invokes the on worker thread.
/// </summary>
/// <returns>The on worker thread.</returns>
/// <param name="act">Act.</param>
/// <summary>
/// Invokes the on worker thread.
/// </summary>
/// <returns>The on worker thread.</returns>
/// <param name="act">Act.</param>
public void InvokeOnWorkerThread(Action act)
{
this.Invoke(act);

View file

@ -99,6 +99,22 @@ namespace ShiftOS.Engine
_desktop = desk;
}
public static void MinimizeWindow(IWindowBorder brdr)
{
_desktop.MinimizeWindow(brdr);
}
public static void MaximizeWindow(IWindowBorder brdr)
{
_desktop.MaximizeWindow(brdr);
}
public static void RestoreWindow(IWindowBorder brdr)
{
_desktop.RestoreWindow(brdr);
}
public static void InvokeOnWorkerThread(Action act)
{
_desktop.InvokeOnWorkerThread(act);