Icon backend :D

This commit is contained in:
Michael 2017-02-06 20:15:22 -05:00
parent aa9234c681
commit 82de84638a
7 changed files with 104 additions and 24 deletions

View file

@ -43,12 +43,16 @@ namespace ShiftOS.WinForms.Applications
InitializeComponent();
}
public string Title { get; private set; }
public void OnLoad()
{
AppearanceManager.SetWindowTitle(this, this.Title);
}
public void OnSkinLoad()
{
AppearanceManager.SetWindowTitle(this, this.Title);
}
public bool OnUnload()
@ -63,7 +67,7 @@ namespace ShiftOS.WinForms.Applications
internal void OpenInternal(string title, string msg)
{
AppearanceManager.SetupWindow(this);
this.Parent.Text = title;
Title = title;
lbmessage.Text = msg;
txtinput.Hide();
flyesno.Hide();
@ -83,7 +87,7 @@ namespace ShiftOS.WinForms.Applications
public void PromptTextInternal(string title, string message, Action<string> callback)
{
AppearanceManager.SetupWindow(this);
this.Parent.Text = title;
Title = title;
lbmessage.Text = message;
txtinput.Show();
flyesno.Hide();
@ -119,7 +123,7 @@ namespace ShiftOS.WinForms.Applications
public void PromptYesNoInternal(string title, string message, Action<bool> callback)
{
AppearanceManager.SetupWindow(this);
this.Parent.Text = title;
Title = title;
lbmessage.Text = message;
txtinput.Hide();
flyesno.Show();

View file

@ -201,6 +201,12 @@
Description: "Use a fully customizable desktop in place of the terminal to control ShiftOS.",
Dependencies: "window_manager"
},
{
Name: "App Icons",
Cost: 100,
Description: "So you have a titlebar, well, let's add an icon to it to hopefully make it easier to tell which app is which.",
Dependencies: "wm_titlebar;skinning"
},
{
Name: "Close command",
Cost: 150,

View file

@ -56,11 +56,11 @@ namespace ShiftOS.WinForms
private void InitializeComponent()
{
this.pnltitle = new System.Windows.Forms.Panel();
this.pnltitleleft = new System.Windows.Forms.Panel();
this.pnltitleright = new System.Windows.Forms.Panel();
this.pnlminimize = new System.Windows.Forms.Panel();
this.pnlmaximize = new System.Windows.Forms.Panel();
this.pnlclose = new System.Windows.Forms.Panel();
this.pnltitleleft = new System.Windows.Forms.Panel();
this.pnltitleright = new System.Windows.Forms.Panel();
this.lbtitletext = new System.Windows.Forms.Label();
this.pnlbottom = new System.Windows.Forms.Panel();
this.pnlbottomr = new System.Windows.Forms.Panel();
@ -68,6 +68,7 @@ namespace ShiftOS.WinForms
this.pnlleft = new System.Windows.Forms.Panel();
this.pnlright = new System.Windows.Forms.Panel();
this.pnlcontents = new System.Windows.Forms.Panel();
this.pnlicon = new System.Windows.Forms.Panel();
this.pnltitle.SuspendLayout();
this.pnlbottom.SuspendLayout();
this.SuspendLayout();
@ -75,6 +76,7 @@ namespace ShiftOS.WinForms
// pnltitle
//
this.pnltitle.BackColor = System.Drawing.Color.Black;
this.pnltitle.Controls.Add(this.pnlicon);
this.pnltitle.Controls.Add(this.pnlminimize);
this.pnltitle.Controls.Add(this.pnlmaximize);
this.pnltitle.Controls.Add(this.pnlclose);
@ -89,22 +91,6 @@ namespace ShiftOS.WinForms
this.pnltitle.Paint += new System.Windows.Forms.PaintEventHandler(this.pnltitle_Paint);
this.pnltitle.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pnltitle_MouseMove);
//
// pnltitleleft
//
this.pnltitleleft.Dock = System.Windows.Forms.DockStyle.Left;
this.pnltitleleft.Location = new System.Drawing.Point(0, 0);
this.pnltitleleft.Name = "pnltitleleft";
this.pnltitleleft.Size = new System.Drawing.Size(2, 30);
this.pnltitleleft.TabIndex = 4;
//
// pnltitleright
//
this.pnltitleright.Dock = System.Windows.Forms.DockStyle.Right;
this.pnltitleright.Location = new System.Drawing.Point(728, 0);
this.pnltitleright.Name = "pnltitleright";
this.pnltitleright.Size = new System.Drawing.Size(2, 30);
this.pnltitleright.TabIndex = 5;
//
// pnlminimize
//
this.pnlminimize.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
@ -135,6 +121,22 @@ namespace ShiftOS.WinForms
this.pnlclose.TabIndex = 1;
this.pnlclose.Click += new System.EventHandler(this.pnlclose_Click);
//
// pnltitleleft
//
this.pnltitleleft.Dock = System.Windows.Forms.DockStyle.Left;
this.pnltitleleft.Location = new System.Drawing.Point(0, 0);
this.pnltitleleft.Name = "pnltitleleft";
this.pnltitleleft.Size = new System.Drawing.Size(2, 30);
this.pnltitleleft.TabIndex = 4;
//
// pnltitleright
//
this.pnltitleright.Dock = System.Windows.Forms.DockStyle.Right;
this.pnltitleright.Location = new System.Drawing.Point(728, 0);
this.pnltitleright.Name = "pnltitleright";
this.pnltitleright.Size = new System.Drawing.Size(2, 30);
this.pnltitleright.TabIndex = 5;
//
// lbtitletext
//
this.lbtitletext.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
@ -144,7 +146,7 @@ namespace ShiftOS.WinForms
this.lbtitletext.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.lbtitletext.Font = new System.Drawing.Font("Consolas", 9F, System.Drawing.FontStyle.Bold);
this.lbtitletext.ForeColor = System.Drawing.Color.White;
this.lbtitletext.Location = new System.Drawing.Point(4, 0);
this.lbtitletext.Location = new System.Drawing.Point(75, 9);
this.lbtitletext.Name = "lbtitletext";
this.lbtitletext.Size = new System.Drawing.Size(77, 14);
this.lbtitletext.TabIndex = 0;
@ -209,6 +211,13 @@ namespace ShiftOS.WinForms
this.pnlcontents.Size = new System.Drawing.Size(730, 463);
this.pnlcontents.TabIndex = 4;
//
// pnlicon
//
this.pnlicon.Location = new System.Drawing.Point(9, -76);
this.pnlicon.Name = "pnlicon";
this.pnlicon.Size = new System.Drawing.Size(200, 100);
this.pnlicon.TabIndex = 6;
//
// WindowBorder
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -243,5 +252,6 @@ namespace ShiftOS.WinForms
private System.Windows.Forms.Panel pnlcontents;
private System.Windows.Forms.Panel pnltitleright;
private System.Windows.Forms.Panel pnltitleleft;
private System.Windows.Forms.Panel pnlicon;
}
}

View file

@ -87,6 +87,11 @@ namespace ShiftOS.WinForms
}
}
internal void SetTitle(string title)
{
lbtitletext.Text = title;
}
/// <summary>
/// Initializes a new instance of the <see cref="ShiftOS.WinForms.WindowBorder"/> class.
/// </summary>
@ -305,13 +310,27 @@ namespace ShiftOS.WinForms
switch (LoadedSkin.TitleTextCentered)
{
case false:
lbtitletext.Location = LoadedSkin.TitleTextLeft;
lbtitletext.Location = new Point(16 + LoadedSkin.TitlebarIconFromSide.X + LoadedSkin.TitleTextLeft.X,
LoadedSkin.TitleTextLeft.Y);
break;
default:
lbtitletext.Left = (pnltitle.Width - lbtitletext.Width) / 2;
lbtitletext.Top = LoadedSkin.TitleTextLeft.Y;
break;
}
if (Shiftorium.UpgradeInstalled("app_icons"))
{
pnlicon.Show();
pnlicon.Size = new Size(16, 16);
pnlicon.BackgroundImage = GetIcon(this.ParentWindow.GetType().Name);
pnlicon.BackgroundImageLayout = ImageLayout.Stretch;
pnlicon.Location = LoadedSkin.TitlebarIconFromSide;
}
else
{
pnlicon.Hide();
}
}
/// <summary>

View file

@ -77,6 +77,12 @@ namespace ShiftOS.WinForms
catch { }
}
public override void SetTitle(IShiftOSWindow win, string title)
{
var wb = (win as UserControl).ParentForm as WindowBorder;
wb.SetTitle(title);
}
public override void SetupDialog(IShiftOSWindow form)
{
if (!Shiftorium.UpgradeAttributesUnlocked(form.GetType()))

View file

@ -76,6 +76,11 @@ namespace ShiftOS.Engine
}
}
public static void SetWindowTitle(IShiftOSWindow window, string title)
{
winmgr.SetTitle(window, title);
}
public static IEnumerable<Type> GetAllWindowTypes()
{
List<Type> types = new List<Type>();
@ -231,6 +236,8 @@ namespace ShiftOS.Engine
public abstract void SetupDialog(IShiftOSWindow win);
public abstract void InvokeAction(Action act);
public abstract void SetTitle(IShiftOSWindow win, string title);
}
public interface IWindowBorder

View file

@ -112,6 +112,23 @@ namespace ShiftOS.Engine {
public static void SaveSkin() {
Utils.WriteAllText(Paths.GetPath("skin.json"), JsonConvert.SerializeObject(LoadedSkin, Formatting.Indented));
}
public static Image GetIcon(string id)
{
if (!LoadedSkin.AppIcons.ContainsKey(id))
LoadedSkin.AppIcons.Add(id, null);
if (LoadedSkin.AppIcons[id] == null)
return new Bitmap(16, 16);
else
{
using (var sr = new MemoryStream(LoadedSkin.AppIcons[id]))
{
return Image.FromStream(sr);
}
}
}
}
public class Skin {
@ -138,7 +155,11 @@ namespace ShiftOS.Engine {
}
[ShifterHidden]
public Dictionary<string, string> AppNames = new Dictionary<string, string>();
public Dictionary<string, string> AppNames = new Dictionary<string, string>();
[ShifterHidden]
public Dictionary<string, byte[]> AppIcons = new Dictionary<string, byte[]>();
[ShifterMeta("Windows")]
[ShifterCategory("Titlebar")]
@ -914,6 +935,13 @@ namespace ShiftOS.Engine {
//we DO NOT want this showing in the shifter.
[ShifterHidden]
public Dictionary<string, ImageLayout> SkinImageLayouts = new Dictionary<string, ImageLayout>();
[ShifterMeta("Windows")]
[ShifterCategory("Titlebar")]
[ShifterName("App icon from side")]
[ShifterDescription("How far from the side should the icon be?")]
[RequiresUpgrade("shift_titlebar;app_icons")]
public Point TitlebarIconFromSide = new Point(4,4);
}
public class ShifterHiddenAttribute : Attribute {