Histacom2/Histacom2.Engine/WindowManager.cs

188 lines
8 KiB
C#
Raw Normal View History

using System;
using System.Windows.Forms;
2017-03-26 19:56:21 -04:00
using System.Drawing;
2017-08-23 13:38:40 -04:00
using Histacom2.Engine.Template;
2017-04-28 13:48:46 -04:00
using System.Media;
2017-08-23 13:38:40 -04:00
namespace Histacom2.Engine
{
public class WindowManager
{
2017-03-28 21:53:18 -04:00
public static System.Drawing.Text.PrivateFontCollection pfc = new System.Drawing.Text.PrivateFontCollection();
2017-10-24 19:21:45 -04:00
/// <summary>
/// Creates and returns a WinClassic window.
/// </summary>
/// <param name="content">The UserControl to put inside the window.</param>
/// <param name="title">The name of the window.</param>
/// <param name="icon">The window's icon. If set to null, then the title moves over to compensate.</param>
/// <param name="MaxButton">Whether or not the maximize button is shown.</param>
/// <param name="MinButton">Whether or not the minimize button is shown.</param>
/// <param name="ShowApplicationAsDialog">Whether or not to interrupt all other processes while this window is open.</param>
/// <param name="resize">Whether or not this window is resizable.</param>
/// <returns></returns>
public WinClassic Init(UserControl content, string title, Image icon, bool MaxButton, bool MinButton, bool ShowApplicationAsDialog = false, bool resize = true)
{
2017-10-24 19:21:45 -04:00
WinClassic app = new WinClassic();
2017-03-27 15:32:59 -04:00
app.Text = title;
app.Title.Text = title;
app.Width = content.Width + 8;
app.Height = content.Height + 26;
2017-03-28 21:53:18 -04:00
// Initialize Font
2017-06-14 20:22:37 -04:00
pfc.AddFontFile(SaveSystem.GameDirectory + "\\Data\\LeviWindows.ttf");
2017-04-09 12:31:17 -04:00
Font fnt = new Font(pfc.Families[0], 16F, FontStyle.Regular, GraphicsUnit.Point, ((0)));
2017-03-27 10:53:12 -04:00
app.fnt = fnt;
2017-04-01 18:44:31 -04:00
app.Title.Font = new Font(pfc.Families[0], 16F, FontStyle.Bold, GraphicsUnit.Point, ((0)));
2017-03-28 21:53:18 -04:00
// Setup UC
content.Parent = app.programContent;
content.BringToFront();
content.Dock = DockStyle.Fill;
2017-09-05 21:13:06 -04:00
app.progContent = content;
2017-03-28 21:53:18 -04:00
// Check if icon is null
2017-04-09 19:38:33 -04:00
if (icon == null)
{
app.programIcon.Hide();
app.programIcon.Image = Engine.Properties.Resources.nullIcon;
app.Title.Location = new Point(2, 1);
}
2017-04-09 14:05:04 -04:00
else app.programIcon.Image = icon;
2017-03-26 19:56:21 -04:00
// Check if Max button is enabled and set proper X for Min button
if (!MaxButton)
{
app.maximizebutton.Visible = false;
2017-03-27 15:32:59 -04:00
app.minimizebutton.Location = new Point(app.closebutton.Location.X - 14, app.minimizebutton.Location.Y);
}
// Check if Min button is enabled
if (!MinButton)
{
app.minimizebutton.Visible = false;
2017-03-26 19:56:21 -04:00
app.minimizebutton.Location = new Point(app.minimizebutton.Location.X, app.minimizebutton.Location.Y);
}
2017-07-31 23:14:24 -04:00
//Resize
app.resizable = resize;
2017-07-31 15:40:59 -04:00
// Time for the colors
app.programtopbar.BackColor = SaveSystem.currentTheme.activeTitleBarColor;
2017-07-31 15:46:27 -04:00
app.Title.ForeColor = SaveSystem.currentTheme.activeTitleTextColor;
2017-04-30 10:46:36 -04:00
2017-05-01 04:54:13 -04:00
// Convert an image to an icon (for the taskbar)
if (icon != null)
{
Bitmap theBitmap = new Bitmap(icon, new Size(icon.Width, icon.Height));
IntPtr Hicon = theBitmap.GetHicon(); // Get an Hicon for myBitmap.
Icon newIcon = Icon.FromHandle(Hicon); // Create a new icon from the handle.
app.Icon = newIcon;
}
2017-04-30 10:46:36 -04:00
2017-05-01 04:54:13 -04:00
// Set some values (for the taskbar)
2017-04-30 10:46:36 -04:00
app.Tag = TaskBarController.AvalibleApplicationID;
2017-05-19 16:01:07 -04:00
app.Text = title;
2017-04-30 10:46:36 -04:00
// Show the app
app.TopMost = true;
if (!ShowApplicationAsDialog) { app.Show(); } else { app.ShowDialog(); }
2017-03-27 17:42:35 -04:00
return app;
}
2017-10-23 12:01:44 -04:00
public WinXP InitXP(UserControl content, string title, Image icon, bool MaxButton, bool MinButton, bool ShowApplicationAsDialog = false, bool resize = true)
{
WinXP app = new WinXP();
app.Text = title;
app.programname.Text = title;
app.Width = content.Width + 8;
app.Height = content.Height + 26;
// Initialize Font
pfc.AddFontFile(SaveSystem.GameDirectory + "\\Data\\LeviWindows.ttf");
Font fnt = new Font(pfc.Families[0], 16F, FontStyle.Regular, GraphicsUnit.Point, ((0)));
app.fnt = fnt;
// Setup UC
2017-10-23 16:49:06 -04:00
content.Parent = app.flowLayoutPanel1;
2017-10-23 12:01:44 -04:00
content.BringToFront();
content.Dock = DockStyle.Fill;
app.progContent = content;
// Check if icon is null
if (icon == null)
{
app.programIcon.Hide();
2017-10-24 19:21:45 -04:00
app.programIcon.Image = Properties.Resources.nullIcon;
2017-10-26 00:03:57 -04:00
app.programname.Location = new Point(3, 6);
2017-10-23 12:01:44 -04:00
}
else app.programIcon.Image = icon;
// Check if Max button is enabled and set proper X for Min button
if (!MaxButton)
2017-10-23 12:01:44 -04:00
{
app.maximizebutton.Visible = false;
app.minimizebutton.Location = new Point(app.closebutton.Location.X - 14, app.minimizebutton.Location.Y);
}
// Check if Min button is enabled
if (!MinButton)
2017-10-23 12:01:44 -04:00
{
app.minimizebutton.Visible = false;
app.minimizebutton.Location = new Point(app.minimizebutton.Location.X, app.minimizebutton.Location.Y);
}
//Resize
app.resizable = resize;
// Convert an image to an icon (for the taskbar)
if (icon != null)
{
Bitmap theBitmap = new Bitmap(icon, new Size(icon.Width, icon.Height));
IntPtr Hicon = theBitmap.GetHicon(); // Get an Hicon for myBitmap.
Icon newIcon = Icon.FromHandle(Hicon); // Create a new icon from the handle.
app.Icon = newIcon;
}
2017-10-23 12:01:44 -04:00
// Set some values (for the taskbar)
app.Tag = TaskBarController.AvalibleApplicationID;
app.Text = title;
// Show the app
app.TopMost = true;
if (!ShowApplicationAsDialog) { app.Show(); } else { app.ShowDialog(); }
2017-10-23 12:01:44 -04:00
return app;
}
2017-07-30 00:10:22 -04:00
public WinClassic StartInfobox95(string title, string text, InfoboxType type, InfoboxButtons btns)
{
2017-07-30 00:10:22 -04:00
pfc.AddFontFile(SaveSystem.GameDirectory + "\\Data\\LeviWindows.ttf");
Infobox95 app = new Infobox95(type, btns);
app.infoText.Text = text;
2017-07-30 00:10:22 -04:00
app.infoText.Font = new Font(pfc.Families[0], 16F, FontStyle.Regular, GraphicsUnit.Point, ((0)));
return Init(app, title, null, false, false, resize: false);
}
2017-04-09 19:38:33 -04:00
public WinClassic StartAboutBox95(string shortname, string longname, Image appicon)
2017-04-09 19:38:33 -04:00
{
AboutBox95 uc = new AboutBox95();
uc.pictureBox1.Image = appicon;
2017-04-10 11:51:00 -04:00
uc.textBox1.Text = longname + "\r\nWindows 95\r\nCopyright © 1981-1995 Microsoft Corp.";
uc.textBox1.Font = new Font(pfc.Families[0], 16F, FontStyle.Regular, GraphicsUnit.Point, ((0)));
uc.textBox2.Font = new Font(pfc.Families[0], 16F, FontStyle.Regular, GraphicsUnit.Point, ((0)));
return Init(uc, "About " + shortname, null, false, false, resize: false);
}
public WinClassic StartAboutBox98(string shortname, string longname, Image appicon)
{
AboutBox98 uc = new AboutBox98();
uc.pictureBox1.Image = appicon;
uc.textBox1.Text = longname + "\r\nWindows 98\r\nCopyright © 1981-1997 Microsoft Corp.";
uc.textBox1.Font = new Font(pfc.Families[0], 16F, FontStyle.Regular, GraphicsUnit.Point, ((0)));
uc.textBox2.Font = new Font(pfc.Families[0], 16F, FontStyle.Regular, GraphicsUnit.Point, ((0)));
2017-04-09 19:38:33 -04:00
return Init(uc, "About " + shortname, null, false, false, resize: false);
2017-04-09 19:38:33 -04:00
}
}
}