aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael <[email protected]>2017-07-10 20:55:24 -0400
committerMichael <[email protected]>2017-07-10 20:55:24 -0400
commit2f54ddc6b05d7f48d6a22735f08917fab1f96ba4 (patch)
treeb90cc117a2bb2906c7547ca33163084bc1181658
parentca339b2661ee565d55191d58ed40c2303f77c0b4 (diff)
downloadshiftos_thereturn-2f54ddc6b05d7f48d6a22735f08917fab1f96ba4.tar.gz
shiftos_thereturn-2f54ddc6b05d7f48d6a22735f08917fab1f96ba4.tar.bz2
shiftos_thereturn-2f54ddc6b05d7f48d6a22735f08917fab1f96ba4.zip
Attempt to get app launcher ui working
-rw-r--r--ShiftOS.Frontend/Desktop/Desktop.cs144
1 files changed, 141 insertions, 3 deletions
diff --git a/ShiftOS.Frontend/Desktop/Desktop.cs b/ShiftOS.Frontend/Desktop/Desktop.cs
index 46baf7f..cf3f2d1 100644
--- a/ShiftOS.Frontend/Desktop/Desktop.cs
+++ b/ShiftOS.Frontend/Desktop/Desktop.cs
@@ -5,6 +5,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ShiftOS.Engine;
+using ShiftOS.Frontend.Apps;
using ShiftOS.Frontend.GraphicsSubsystem;
using static ShiftOS.Engine.SkinEngine;
@@ -13,6 +14,10 @@ namespace ShiftOS.Frontend.Desktop
{
public class Desktop : GUI.Control, IDesktop
{
+ bool alOpen = false;
+ int alX = 0;
+ int alY = 0;
+
public Desktop()
{
SaveSystem.GameReady += () =>
@@ -20,6 +25,36 @@ namespace ShiftOS.Frontend.Desktop
Show();
SetupDesktop();
};
+
+ MouseMove += (loc) =>
+ {
+ if(alOpen == true)
+ {
+ if(loc.X >= alX && loc.Y >= alY)
+ {
+ int height = LauncherItems[0].Height * LauncherItems.Count;
+ int width = LauncherItems[0].Width;
+ if(loc.X <= alX + width && loc.Y <= alY + height)
+ {
+ foreach(var item in LauncherItems)
+ {
+ if(loc.X >= alX && loc.Y >= alY + item.Y && loc.X <= alX + width && loc.Y <= alY + item.Y + item.Height)
+ {
+ alSelectedItem = LauncherItems.IndexOf(item);
+ Invalidate();
+ return;
+ }
+ }
+ }
+ else
+ {
+ alSelectedItem = -1;
+ Invalidate();
+ return;
+ }
+ }
+ }
+ };
}
public string DesktopName
@@ -30,6 +65,8 @@ namespace ShiftOS.Frontend.Desktop
}
}
+ private int alSelectedItem = -1;
+
public void Close()
{
UIManager.StopHandling(this);
@@ -42,7 +79,8 @@ namespace ShiftOS.Frontend.Desktop
public void HideAppLauncher()
{
-
+ alOpen = false;
+ Invalidate();
}
public void InvokeOnWorkerThread(Action act)
@@ -64,10 +102,48 @@ namespace ShiftOS.Frontend.Desktop
public void OpenAppLauncher(Point loc)
{
+ alX = loc.X;
+ alY = loc.Y;
+ alOpen = true;
+ alSelectedItem = -1;
+ Invalidate();
}
public void PopulateAppLauncher(LauncherItem[] items)
{
+ int y = 0;
+ int height = 0;
+ int[] widths = new int[items.Length];
+ using(var gfx = System.Drawing.Graphics.FromImage(new System.Drawing.Bitmap(1, 1)))
+ {
+ LauncherItems.Clear();
+ for(int i = 0; i < items.Length; i++)
+ {
+ string name = Localization.Parse(items[i].DisplayData.Name);
+ var measure = gfx.SmartMeasureString(name, LoadedSkin.MainFont);
+ if (height < (int)measure.Height)
+ height = (int)measure.Height;
+ widths[i] = 120 + (int)measure.Width;
+
+ }
+
+ int width = widths.Max();
+
+ foreach(var aitem in items)
+ {
+ var item = new AppLauncherItem
+ {
+ Data = aitem,
+ X = 0,
+ Y = y,
+ Height = height,
+ Width = width
+ };
+ LauncherItems.Add(item);
+ y += item.Height;
+ }
+
+ }
Invalidate();
}
@@ -130,6 +206,41 @@ namespace ShiftOS.Frontend.Desktop
}
private List<PanelButtonData> PanelButtons = new List<PanelButtonData>();
+ private List<AppLauncherItem> LauncherItems = new List<AppLauncherItem>();
+
+ public override void MouseStateChanged()
+ {
+ //This statement closes the app launcher. If we do this after opening it, we can't open it at all as it instantly closes.
+ if (alOpen == true && MouseLeftDown == true)
+ {
+ alOpen = false;
+ Invalidate();
+ return;
+ }
+
+
+ var al_left = LoadedSkin.AppLauncherFromLeft;
+ var al_size = LoadedSkin.AppLauncherHolderSize;
+ if(MouseX >= al_left.X && MouseY >= al_left.Y && MouseX <= al_left.X + al_size.Width && MouseY <= al_left.Y + al_size.Height)
+ {
+ if(alOpen == false && MouseLeftDown == true)
+ {
+ alX = 0;
+ if(LoadedSkin.DesktopPanelPosition == 0)
+ {
+ alY = LoadedSkin.DesktopPanelHeight;
+ }
+ else
+ {
+ alY = (Height - LoadedSkin.DesktopPanelHeight) - (LauncherItems[0].Height * LauncherItems.Count);
+ }
+ alOpen = true;
+ Invalidate();
+ }
+
+ }
+
+ }
protected override void OnPaint(GraphicsContext gfx)
{
@@ -161,7 +272,10 @@ namespace ShiftOS.Frontend.Desktop
{
gfx.DrawRectangle(al_left.X, dp_position + al_left.Y, holderSize.Width, holderSize.Height, UIManager.SkinTextures["applauncher"]);
}
-
+ var altextmeasure = gfx.MeasureString(LoadedSkin.AppLauncherText, LoadedSkin.AppLauncherFont);
+ int altextx = (holderSize.Width - (int)altextmeasure.X) / 2;
+ int altexty = (holderSize.Height - (int)altextmeasure.Y) / 2;
+ gfx.DrawString(LoadedSkin.AppLauncherText, altextx, altexty, LoadedSkin.AppLauncherTextColor.ToMonoColor(), LoadedSkin.AppLauncherFont);
//Panel clock.
var panelClockRight = LoadedSkin.DesktopPanelClockFromRight;
@@ -209,7 +323,7 @@ namespace ShiftOS.Frontend.Desktop
}
else
{
- gfx.DrawRectangle(offset, dp_position + pbtnfromtop, pbtnwidth, pbtnheight, UIManager.SkinTextures["PanelButtonBackgroundColor"]);
+ gfx.DrawRectangle(offset, dp_position + pbtnfromtop, pbtnwidth, pbtnheight, UIManager.SkinTextures["PanelButtonColor"]);
}
//now we draw the text
@@ -219,7 +333,21 @@ namespace ShiftOS.Frontend.Desktop
offset += LoadedSkin.PanelButtonSize.Width;
}
+ if (alOpen)
+ {
+ int height = LauncherItems[0].Height * LauncherItems.Count;
+ int width = LauncherItems[0].Width;
+ gfx.DrawRectangle(alX, alY, width, height, UIManager.SkinTextures["Menu_ToolStripDropDownBackground"]);
+ foreach(var item in LauncherItems)
+ {
+ if(LauncherItems.IndexOf(item) == alSelectedItem)
+ {
+ gfx.DrawRectangle(alX, alY + item.Y, item.Width, item.Y, UIManager.SkinTextures["Menu_MenuItemSelected"]);
+ }
+ gfx.DrawString(Localization.Parse(item.Data.DisplayData.Name), alX + 20, alY + item.Y, LoadedSkin.Menu_TextColor.ToMonoColor(), LoadedSkin.MainFont);
+ }
+ }
}
}
@@ -236,4 +364,14 @@ namespace ShiftOS.Frontend.Desktop
}
}
}
+
+
+ public class AppLauncherItem
+ {
+ public Engine.LauncherItem Data { get; set; }
+ public int X { get; set; }
+ public int Y { get; set; }
+ public int Width { get; set; }
+ public int Height { get; set; }
+ }
}