2017-07-03 01:48:10 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using ShiftOS.Engine;
|
2017-07-04 02:03:58 +00:00
|
|
|
|
using ShiftOS.Frontend.GraphicsSubsystem;
|
2017-07-05 14:34:09 +00:00
|
|
|
|
using static ShiftOS.Engine.SkinEngine;
|
|
|
|
|
|
2017-07-03 01:48:10 +00:00
|
|
|
|
|
|
|
|
|
namespace ShiftOS.Frontend.Desktop
|
|
|
|
|
{
|
|
|
|
|
public class Desktop : GUI.Control, IDesktop
|
|
|
|
|
{
|
2017-07-05 14:34:09 +00:00
|
|
|
|
public Desktop()
|
|
|
|
|
{
|
|
|
|
|
SaveSystem.GameReady += () =>
|
|
|
|
|
{
|
|
|
|
|
Show();
|
|
|
|
|
SetupDesktop();
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-03 01:48:10 +00:00
|
|
|
|
public string DesktopName
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return "ShiftOS MonoGame Desktop";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Close()
|
|
|
|
|
{
|
2017-07-05 14:34:09 +00:00
|
|
|
|
UIManager.StopHandling(this);
|
2017-07-03 01:48:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Size GetSize()
|
|
|
|
|
{
|
2017-07-05 14:34:09 +00:00
|
|
|
|
return UIManager.Viewport;
|
2017-07-03 01:48:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void HideAppLauncher()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void InvokeOnWorkerThread(Action act)
|
|
|
|
|
{
|
2017-07-04 02:03:58 +00:00
|
|
|
|
UIManager.CrossThreadOperations.Enqueue(act);
|
2017-07-03 01:48:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void KillWindow(IWindowBorder border)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void MaximizeWindow(IWindowBorder brdr)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void MinimizeWindow(IWindowBorder brdr)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OpenAppLauncher(Point loc)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void PopulateAppLauncher(LauncherItem[] items)
|
|
|
|
|
{
|
2017-07-05 14:34:09 +00:00
|
|
|
|
Invalidate();
|
2017-07-03 01:48:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void PopulatePanelButtons()
|
|
|
|
|
{
|
2017-07-05 14:34:09 +00:00
|
|
|
|
PanelButtons.Clear();
|
|
|
|
|
foreach(var win in AppearanceManager.OpenForms)
|
|
|
|
|
{
|
|
|
|
|
var border = win as WindowBorder;
|
|
|
|
|
var pbtn = new PanelButtonData();
|
|
|
|
|
pbtn.Title = border.Text;
|
|
|
|
|
pbtn.Window = border;
|
|
|
|
|
PanelButtons.Add(pbtn);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Invalidate();
|
2017-07-03 01:48:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void PushNotification(string app, string title, string message)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RestoreWindow(IWindowBorder brdr)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetupDesktop()
|
|
|
|
|
{
|
2017-07-05 14:34:09 +00:00
|
|
|
|
Invalidate();
|
2017-07-03 01:48:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Show()
|
|
|
|
|
{
|
2017-07-05 14:34:09 +00:00
|
|
|
|
UIManager.AddTopLevel(this);
|
|
|
|
|
Visible = true;
|
|
|
|
|
Invalidate();
|
2017-07-03 01:48:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ShowWindow(IWindowBorder border)
|
|
|
|
|
{
|
|
|
|
|
}
|
2017-07-05 14:34:09 +00:00
|
|
|
|
|
|
|
|
|
protected override void OnLayout()
|
|
|
|
|
{
|
|
|
|
|
SendToBack();
|
|
|
|
|
X = 0;
|
|
|
|
|
Y = 0;
|
|
|
|
|
Width = GetSize().Width;
|
|
|
|
|
Height = GetSize().Height;
|
|
|
|
|
Invalidate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<PanelButtonData> PanelButtons = new List<PanelButtonData>();
|
|
|
|
|
|
|
|
|
|
protected override void OnPaint(GraphicsContext gfx)
|
|
|
|
|
{
|
|
|
|
|
//Let's get data for the desktop panel.
|
|
|
|
|
|
|
|
|
|
//We need the width and the height and the position.
|
|
|
|
|
|
|
|
|
|
int dp_height = LoadedSkin.DesktopPanelHeight;
|
|
|
|
|
int dp_position = (LoadedSkin.DesktopPanelPosition == 0) ? 0 : Height - dp_height;
|
|
|
|
|
int dp_width = Width;
|
|
|
|
|
|
|
|
|
|
//Alright, now we need to know if we should draw using a texture or a color
|
|
|
|
|
if (UIManager.SkinTextures.ContainsKey("desktoppanel"))
|
|
|
|
|
{
|
|
|
|
|
//Draw with the texture
|
|
|
|
|
gfx.DrawRectangle(0, dp_position, dp_width, dp_height, UIManager.SkinTextures["desktoppanel"]);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//draw with a color
|
|
|
|
|
var color = LoadedSkin.DesktopPanelColor.ToMonoColor();
|
|
|
|
|
gfx.DrawRectangle(0, dp_position, dp_width, dp_height, color);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Alright, now App Launcher.
|
|
|
|
|
var al_left = LoadedSkin.AppLauncherFromLeft;
|
|
|
|
|
var holderSize = LoadedSkin.AppLauncherHolderSize;
|
|
|
|
|
if (UIManager.SkinTextures.ContainsKey("applauncher"))
|
|
|
|
|
{
|
|
|
|
|
gfx.DrawRectangle(al_left.X, dp_position + al_left.Y, holderSize.Width, holderSize.Height, UIManager.SkinTextures["applauncher"]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Panel clock.
|
|
|
|
|
|
|
|
|
|
var panelClockRight = LoadedSkin.DesktopPanelClockFromRight;
|
|
|
|
|
var panelClockTextColor = LoadedSkin.DesktopPanelClockColor.ToMonoColor();
|
|
|
|
|
|
|
|
|
|
var dateTimeString = DateTime.Now.TimeOfDay.ToString();
|
|
|
|
|
|
|
|
|
|
var measure = gfx.MeasureString(dateTimeString, LoadedSkin.DesktopPanelClockFont);
|
|
|
|
|
|
|
|
|
|
int panelclockleft = Width - (int)measure.X;
|
|
|
|
|
int panelclockwidth = Width - panelclockleft;
|
|
|
|
|
|
|
|
|
|
if (UIManager.SkinTextures.ContainsKey("panelclockbg"))
|
|
|
|
|
{
|
|
|
|
|
//draw the background using panelclock texture
|
|
|
|
|
gfx.DrawRectangle(panelclockleft, dp_position, panelclockwidth, dp_height, UIManager.SkinTextures["panelclockbg"]);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//draw using the bg color
|
|
|
|
|
var pcBGColor = LoadedSkin.DesktopPanelClockBackgroundColor.ToMonoColor();
|
|
|
|
|
gfx.DrawRectangle(panelclockleft, dp_position, panelclockwidth, dp_height, pcBGColor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int text_left = (panelclockwidth - (int)measure.X) / 2;
|
|
|
|
|
int text_top = (dp_height - (int)measure.Y) / 2;
|
|
|
|
|
|
|
|
|
|
//draw string
|
|
|
|
|
gfx.DrawString(dateTimeString, panelclockleft + text_left, dp_position + text_top, panelClockTextColor, LoadedSkin.DesktopPanelClockFont);
|
|
|
|
|
|
|
|
|
|
int initialGap = LoadedSkin.PanelButtonHolderFromLeft;
|
|
|
|
|
int offset = initialGap;
|
|
|
|
|
|
|
|
|
|
foreach(var pbtn in PanelButtons)
|
|
|
|
|
{
|
|
|
|
|
offset += LoadedSkin.PanelButtonFromLeft.X;
|
|
|
|
|
|
|
|
|
|
int pbtnfromtop = LoadedSkin.PanelButtonFromTop;
|
|
|
|
|
int pbtnwidth = LoadedSkin.PanelButtonSize.Width;
|
|
|
|
|
int pbtnheight = LoadedSkin.PanelButtonSize.Height;
|
|
|
|
|
|
|
|
|
|
//Draw panel button background...
|
|
|
|
|
if (UIManager.SkinTextures.ContainsKey("panelbutton"))
|
|
|
|
|
{
|
|
|
|
|
gfx.DrawRectangle(offset, dp_position + pbtnfromtop, pbtnwidth, pbtnheight, UIManager.SkinTextures["panelbutton"]);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
gfx.DrawRectangle(offset, dp_position + pbtnfromtop, pbtnwidth, pbtnheight, LoadedSkin.PanelButtonColor.ToMonoColor());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//now we draw the text
|
|
|
|
|
|
|
|
|
|
gfx.DrawString(pbtn.Title, offset + 2, dp_position + pbtnfromtop + 2, LoadedSkin.PanelButtonTextColor.ToMonoColor(), LoadedSkin.PanelButtonFont);
|
|
|
|
|
|
|
|
|
|
offset += LoadedSkin.PanelButtonSize.Width;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class PanelButtonData
|
|
|
|
|
{
|
|
|
|
|
public string Title { get; set; }
|
|
|
|
|
public WindowBorder Window { get; set; }
|
|
|
|
|
|
|
|
|
|
public bool IsActive
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Window.IsFocusedControl || Window.ContainsFocusedControl;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-07-03 01:48:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|